float AimbotFunction::getScanDamage(Entity* entity, const Vector& destination, const WeaponInfo* weaponData, int minDamage, bool allowFriendlyFire) noexcept
{
// Initialize key variables outside of loop for performance
Vector start = localPlayer->getEyePosition();
Vector direction = (destination - start).normalized();
float maxDistance = (destination - start).length();
float damage = weaponData->damage;
int hitsLeft = 4;
// Trace rays to destination
while (damage >= 1.0f && hitsLeft > 0) {
code
// Do trace
Trace trace;
interfaces->engineTrace->traceRay({start, destination}, 0x4600400B, localPlayer.get(), trace);
// Check for friendly fire
if (!allowFriendlyFire && IsFriendlyEntity(trace.entity))
return 0.f;
// Check for hit target
if (trace.entity == entity && IsValidHitgroup(trace)) {
damage = CalculateHitgroupDamage(trace, weaponData);
if (damage >= minDamage)
return damage;
else
return 0.f;
}
// Handle penetration
damage = HandlePenetration(trace, direction, start, weaponData, damage);
hitsLeft--;
}
return 0.f;
}
// Summary:
// - Initialize variables outside loop for performance
// - Trace rays to destination with max hits
// - Check for friendly fire and valid hitgroup
// - Calculate damage for valid hitgroup
// - Handle penetration on each trace
// - Loop until damage too low or max hits reached
// - Return damage if valid hit, otherwise 0