bool c_aimbot::calculate_hitchance( Vector& aim_angle, int& final_hitchance ) {
const auto weapon_info = globals::weapon->get_cs_weapon_info( );
if ( !weapon_info )
return false;
const auto hitchance_cfg = g_cfg.ragebot.hitchance_amount;
auto forward = Vector( 0, 0, 0 );
auto right = Vector( 0, 0, 0 );
auto up = Vector( 0, 0, 0 );
Math::AngleVectors( aim_angle, &forward, &right, &up );
Math::FastVecNormalize( forward );
Math::FastVecNormalize( right );
Math::FastVecNormalize( up );
auto total_hits = 0;
float spread_value, inaccuracy_value;
Vector spread_view, direction, end;
for (auto i = 0; i < 256; i++) {
float a = Math::RandomFloat(0.f, 1.f);
float b = Math::RandomFloat(0.f, M_PI * 2.f);
float c = Math::RandomFloat(0.f, 1.f);
float d = Math::RandomFloat(0.f, M_PI * 2.f);
inaccuracy_value = a * globals::inaccuracy;
spread_value = c * globals::spread;
spread_view = ( ( cos( b ) * inaccuracy_value ) + ( cos ( d ) * spread_value ), ( sin ( b ) * inaccuracy_value ) + ( sin ( d ) * spread_value ), 0 );
direction.x = forward.x + ( spread_view.x * right.x ) + ( spread_view.y * up.x );
direction.y = forward.y + ( spread_view.x * right.y ) + ( spread_view.y * up.y );
direction.z = forward.z + ( spread_view.x * right.z ) + ( spread_view.y * up.z );
end = globals::shoot_position + ( direction * 8192.f );
if ( HitboxIntersection( final_target.record->player, final_target.record->MainMatrix, final_target.hitbox, globals::shoot_position, end ) )
++total_hits;
if ( ( static_cast< float >( total_hits ) / 256.f ) * 100.f >= hitchance_cfg )
return true;
}
return false;
}