From ae2e3feff6b31c1e5f28adf15bcca69a648b7e53 Mon Sep 17 00:00:00 2001 From: Stephen Date: Sun, 12 Feb 2023 20:40:17 -0500 Subject: [PATCH] Projectile fix --- include/helpers.hpp | 13 ++++++++++- src/hacks/Aimbot.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++- src/helpers.cpp | 14 +----------- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index e7618611..3eda33e7 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -94,7 +94,18 @@ weaponmode GetWeaponMode(CachedEntity *ent); void FixMovement(CUserCmd &cmd, Vector &viewangles); void VectorAngles(Vector &forward, Vector &angles); -void AngleVectors2(const QAngle &angles, Vector *forward); +// Get forward vector +inline void AngleVectors2(const QAngle &angles, Vector *forward) +{ + float sp, sy, cp, cy; + + SinCos(DEG2RAD(angles[YAW]), &sy, &cy); + SinCos(DEG2RAD(angles[PITCH]), &sp, &cp); + + forward->x = cp * cy; + forward->y = cp * sy; + forward->z = -sp; +} void AngleVectors3(const QAngle &angles, Vector *forward, Vector *right, Vector *up); bool isRapidFire(IClientEntity *wep); void fClampAngle(Vector &qaAng); diff --git a/src/hacks/Aimbot.cpp b/src/hacks/Aimbot.cpp index 8b7ee1f6..c55bbaf4 100644 --- a/src/hacks/Aimbot.cpp +++ b/src/hacks/Aimbot.cpp @@ -1183,8 +1183,57 @@ bool Aim(CachedEntity *entity) Vector angles = GetAimAtAngles(g_pLocalPlayer->v_Eye, is_it_good, LOCAL_E); if (projectileAimbotRequired) // unfortunately you have to check this twice, otherwise you'd have to run GetAimAtAngles far too early - if (!didProjectileHit(getShootPos(angles), is_it_good, entity, projectileHitboxSize(LOCAL_W->m_iClassID()), (0.01f < cur_proj_grav))) + { + const Vector &orig = getShootPos(angles); + const bool grav_comp = (0.01f < cur_proj_grav); + if (grav_comp) + { + Vector direction_vec; + const QAngle &ang = VectorToQAngle(angles); + AngleVectors2(ang, &direction_vec); + + direction_vec *= cur_proj_speed; + float grav = cur_proj_grav * g_ICvar->FindVar("sv_gravity")->GetFloat() * -1.0f; + float diff = (entity->m_vecOrigin().z - orig.z); + float z_vel = direction_vec.z; + // Direct shots should just use normal vischeck + if (30.0f < abs(z_vel)) + { + float time = -1.0f * ((z_vel + fsqrt(z_vel * z_vel + 2.0f * diff * grav)) / grav); + if (!time) + time = -1.0f * ((z_vel * fsqrt(z_vel * z_vel + 2 * (LOCAL_E->hitboxes.GetHitbox(14)->center.z - orig.z) * grav)) / grav); + direction_vec *= time; + direction_vec.z = z_vel * time + 0.5f * grav * time * time; + if (direction_vec.Length() * 1.2f < (orig.DistTo(entity->m_vecOrigin()))) + return false; + AngleVectors2(ang, &direction_vec); + direction_vec *= cur_proj_speed; + // Don't check the middle of the arc if they're close to us. + if (1.0f < time) + { + float pitch = ang.x * -1.0f; + float max_height = -1.0f * direction_vec.z * direction_vec.z * (sin(pitch) * sin(pitch)) / (2.0f * grav); + float time_2 = -1.0f * ((direction_vec.z + fsqrt(direction_vec.z * direction_vec.z + 2.0f * max_height * grav)) / grav); + if (!time_2) + return false; + Vector res = direction_vec * time_2 + orig; + res.z = z_vel * time_2 + 0.5f * grav * time_2 * time_2; + res.z += orig.z; + // Checking the end of the arc doesn't matter for close range + if (!didProjectileHit(res, is_it_good, entity, projectileHitboxSize(LOCAL_W->m_iClassID()), true)) + return false; + if (!didProjectileHit(orig, res, entity, projectileHitboxSize(LOCAL_W->m_iClassID()), true)) + return false; + } + else if (!didProjectileHit(orig, is_it_good, entity, projectileHitboxSize(LOCAL_W->m_iClassID()), true)) + return false; + } + else if (!didProjectileHit(orig, is_it_good, entity, projectileHitboxSize(LOCAL_W->m_iClassID()), true)) + return false; + } + else if (!didProjectileHit(orig, is_it_good, entity, projectileHitboxSize(LOCAL_W->m_iClassID()), grav_comp)) return false; + } if (fov > 0 && cd.fov > fov) return false; // Slow aim diff --git a/src/helpers.cpp b/src/helpers.cpp index 3246ba64..30c87016 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -880,18 +880,6 @@ bool isRapidFire(IClientEntity *wep) return ret || wep->GetClientClass()->m_ClassID == CL_CLASS(CTFMinigun); } -// Get forward vector -void AngleVectors2(const QAngle &angles, Vector *forward) -{ - float sp, sy, cp, cy; - - SinCos(DEG2RAD(angles[YAW]), &sy, &cy); - SinCos(DEG2RAD(angles[PITCH]), &sp, &cp); - - forward->x = cp * cy; - forward->y = cp * sy; - forward->z = -sp; -} char GetUpperChar(ButtonCode_t button) { @@ -1892,7 +1880,7 @@ Vector getShootPos(Vector angle) // Huntsman case CL_CLASS(CTFCompoundBow): - vecOffset = Vector(23.5f, -8.0f, -3.0f); + vecOffset = Vector(23.5f, -4.0f, -3.0f); break; default: