diff --git a/include/helpers.hpp b/include/helpers.hpp index 3eda33e7..effb9db3 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -21,7 +21,7 @@ void SetCVarInterface(ICvar *iface); constexpr float PI = 3.14159265358979323846f; constexpr float RADPI = 57.295779513082f; -//#define DEG2RAD(x) (float)(x) * (float)(PI / 180.0f) +// #define DEG2RAD(x) (float)(x) * (float)(PI / 180.0f) #include #include @@ -143,7 +143,7 @@ bool IsVectorVisible(Vector a, Vector b, bool enviroment_only = false, CachedEnt // A Special function for navparser to check if a Vector is visible. bool IsVectorVisibleNavigation(Vector a, Vector b, unsigned int mask = MASK_SHOT_HULL); float ProjGravMult(int class_id, float x_speed); -bool didProjectileHit(Vector start_point, Vector end_point, CachedEntity *entity, float projectile_size, bool grav_comp); +bool didProjectileHit(Vector start_point, Vector end_point, CachedEntity *entity, float projectile_size, bool grav_comp, trace_t* tracer = nullptr); Vector getShootPos(Vector angle); Vector GetForwardVector(Vector origin, Vector viewangles, float distance, CachedEntity *punch_entity = nullptr); Vector GetForwardVector(float distance, CachedEntity *punch_entity = nullptr); diff --git a/src/entitycache.cpp b/src/entitycache.cpp index f0e6f851..d7cad92d 100644 --- a/src/entitycache.cpp +++ b/src/entitycache.cpp @@ -33,11 +33,8 @@ inline CachedEntity::CachedEntity(u_int16_t idx) : m_IDX(idx), hitboxes(hitbox_c } inline CachedEntity::~CachedEntity() { - if (player_info) - { - delete player_info; - player_info = 0; - } + delete player_info; + player_info = 0; } static settings::Float ve_window{ "debug.ve.window", "0" }; static settings::Boolean ve_smooth{ "debug.ve.smooth", "true" }; diff --git a/src/hacks/Aimbot.cpp b/src/hacks/Aimbot.cpp index 44aa5a9a..fb935c80 100644 --- a/src/hacks/Aimbot.cpp +++ b/src/hacks/Aimbot.cpp @@ -19,7 +19,6 @@ #include "FollowBot.hpp" #include "Warp.hpp" #include "AntiCheatBypass.hpp" - namespace hacks::shared::aimbot { static settings::Boolean normal_enable{ "aimbot.enable", "false" }; @@ -1169,6 +1168,8 @@ bool IsTargetStateGood(CachedEntity *entity) } // A function to aim at a specific entitiy +// __attribute__ has to be ontop of the function, since we ned to check for nans +__attribute__((optimize("-fno-finite-math-only"))) bool Aim(CachedEntity *entity) { if (*miss_chance > 0 && UniformRandomInt(0, 99) < *miss_chance) @@ -1188,44 +1189,45 @@ bool Aim(CachedEntity *entity) 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)) + const QAngle &angl = VectorToQAngle(angles); + Vector end_targ; + if (entity->hitboxes.GetHitbox(cd.hitbox)) + end_targ = entity->hitboxes.GetHitbox(cd.hitbox)->center; + else + end_targ = entity->m_vecOrigin(); + Vector fwd; + AngleVectors2(angl, &fwd); + fwd.NormalizeInPlace(); + fwd *= cur_proj_speed; + Vector dist_between = (end_targ - orig) / fwd; + const float gravity = cur_proj_grav * g_ICvar->FindVar("sv_gravity")->GetFloat() * -1.0f; + float z_diff = (end_targ.z - orig.z); + const float sol_1 = ((fwd.z + std::sqrt(fwd.z * fwd.z + 2.0f * gravity * (z_diff))) / (-1.0f * gravity)); + if (std::isnan(sol_1)) + dist_between.z = ((fwd.z - std::sqrt(fwd.z * fwd.z + 2.0f * gravity * (z_diff))) / (-1.0f * gravity)); + else + dist_between.z = sol_1; + float maxTime = dist_between.Length(); + if (!std::isnan(maxTime)) { - float time = -1.0f * ((z_vel + sqrt(z_vel * z_vel + 2.0f * diff * grav)) / grav); - if (!time) - time = -1.0f * ((z_vel * sqrt(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) + + const float timeStep = maxTime * 0.1f; + Vector curr_pos = orig; + trace_t ptr_trace; + Vector last_pos = orig; + const IClientEntity *rawest_ent = RAW_ENT(entity); + for (float t = 0.0f; t < maxTime; t += timeStep, last_pos = curr_pos) { - 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 + sqrt(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; + curr_pos.x = orig.x + fwd.x * t; + curr_pos.y = orig.y + fwd.y * t; + curr_pos.z = orig.z + fwd.z * t + 0.5f * gravity * t * t; + if (!didProjectileHit(last_pos, curr_pos, entity, projectileHitboxSize(LOCAL_W->m_iClassID()), true, &ptr_trace) || (IClientEntity *) ptr_trace.m_pEnt == rawest_ent) + break; } - else if (!didProjectileHit(orig, is_it_good, entity, projectileHitboxSize(LOCAL_W->m_iClassID()), true)) + if (!didProjectileHit(ptr_trace.endpos, end_targ, entity, projectileHitboxSize(LOCAL_W->m_iClassID()), true, &ptr_trace)) + return false; + + if (200.0f < curr_pos.DistTo(end_targ)) return false; } else if (!didProjectileHit(orig, is_it_good, entity, projectileHitboxSize(LOCAL_W->m_iClassID()), true)) diff --git a/src/hacks/Radar.cpp b/src/hacks/Radar.cpp index 8180aaf0..5534343c 100644 --- a/src/hacks/Radar.cpp +++ b/src/hacks/Radar.cpp @@ -101,12 +101,8 @@ void DrawEntity(int x, int y, CachedEntity *ent) rgba_t clr; float healthp = 0.0f; - if (CE_VALID(ent)) - { if (ent->m_Type() == ENTITY_PLAYER) { - if (!ent->m_bAlivePlayer()) - return; // DEAD. not big surprise. if (hide_invis && IsPlayerInvisible(ent)) return; const int &clazz = CE_INT(ent, netvar.iClass); @@ -201,7 +197,7 @@ void DrawEntity(int x, int y, CachedEntity *ent) tx_items[1].draw(x + wtr.first + sz, y + wtr.second + sz, sz2, sz2, colors::white); } } - } + } void Draw() @@ -241,8 +237,6 @@ void Draw() std::vector sentries; for (auto const &ent : entity_cache::valid_ents) { - if (CE_INVALID(ent)) - continue; if (ent->m_iTeam() == 0) continue; if (!ent->m_bAlivePlayer()) diff --git a/src/helpers.cpp b/src/helpers.cpp index e05ae60b..66ce9534 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -651,15 +651,19 @@ powerup_type GetPowerupOnPlayer(CachedEntity *player) return powerup_type::supernova; return powerup_type::not_powerup; } -bool didProjectileHit(Vector start_point, Vector end_point, CachedEntity *entity, float projectile_size, bool grav_comp) +bool didProjectileHit(Vector start_point, Vector end_point, CachedEntity *entity, float projectile_size, bool grav_comp, trace_t *tracer) { trace::filter_default.SetSelf(RAW_ENT(g_pLocalPlayer->entity)); Ray_t ray; - trace_t trace_obj; + trace_t *trace_obj; + if (tracer) + trace_obj = tracer; + else + trace_obj = new trace_t; ray.Init(start_point, end_point, Vector(0, -projectile_size, -projectile_size), Vector(0, projectile_size, projectile_size)); - g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_default, &trace_obj); - return (((IClientEntity *) trace_obj.m_pEnt) == RAW_ENT(entity) || (grav_comp ? !trace_obj.DidHit() : false)); + g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_default, trace_obj); + return (((IClientEntity *) trace_obj->m_pEnt) == RAW_ENT(entity) || (grav_comp ? !trace_obj->DidHit() : false)); } // A function to find a weapon by WeaponID