bool Aimbot::CheckHitchance(Player* player, const ang_t& angle, float chance) {
if (chance < 1)
return true;
vec3_t forward, right, up;
vec3_t src = g_cl.m_shoot_pos;
math::AngleVectors(angle, &forward, &right, &up);
CGameTrace tr;
int cHits = 0;
int cNeededHits = static_cast<int>(255 * (chance / 78));
g_cl.m_weapon->UpdateAccuracyPenalty();
float weap_spread = g_cl.m_weapon->GetSpread();
float weap_inaccuracy = g_cl.m_weapon->GetInaccuracy();
float weapon_range = g_cl.m_weapon->GetWpnData()->m_range;
for (int i = 0; i < 255; i++)
{
math::random_seed(i);
float a = math::random_float(0.f, 1.f);
float b = math::random_float(0.f, 2.f * M_PI);
float c = math::random_float(0.f, 1.f);
float d = math::random_float(0.f, 2.f * M_PI);
float inaccuracy = a * weap_inaccuracy;
float spread = c * weap_spread;
vec3_t spreadView((cos(b) * inaccuracy) + (cos(d) * spread), (sin(b) * inaccuracy) + (sin(d) * spread), 0), direction;
direction.x = forward.x + (spreadView.x * right.x) + (spreadView.y * up.x);
direction.y = forward.y + (spreadView.x * right.y) + (spreadView.y * up.y);
direction.z = forward.z + (spreadView.x * right.z) + (spreadView.y * up.z);
direction.normalized();
ang_t viewAnglesSpread;
math::VectorAngles3(direction, up, viewAnglesSpread);
math::Normalize(viewAnglesSpread);
vec3_t viewForward;
math::AngleVectors69(viewAnglesSpread, viewForward);
viewForward.normalize();
viewForward = src + (viewForward * weapon_range);
g_csgo.m_engine_trace->ClipRayToEntity(Ray(src, viewForward), MASK_SHOT, player, &tr);
if (tr.m_entity == player && game::IsValidHitgroup(tr.m_hitgroup))
cHits++;
if (static_cast<int>((static_cast<float>(cHits) / 255.f) * 78.f) >= chance)
return true;
if ((255 - i + cHits) < cNeededHits)
return false;
}
return false;
}