diff --git a/data/menu/nullifiedcat/warp.xml b/data/menu/nullifiedcat/warp.xml index 4244304c..c51f31b3 100644 --- a/data/menu/nullifiedcat/warp.xml +++ b/data/menu/nullifiedcat/warp.xml @@ -28,6 +28,7 @@ + diff --git a/include/helpers.hpp b/include/helpers.hpp index 5a6638d6..99474f0b 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -121,6 +121,7 @@ Vector getShootPos(Vector angle); Vector GetForwardVector(Vector origin, Vector viewangles, float distance, CachedEntity *punch_entity = nullptr); Vector GetForwardVector(float distance, CachedEntity *punch_entity = nullptr); CachedEntity *getClosestEntity(Vector vec); +CachedEntity *getClosestNonlocalEntity(Vector vec); bool IsSentryBuster(CachedEntity *ent); std::unique_ptr strfmt(const char *fmt, ...); // TODO move that to weaponid.h @@ -218,7 +219,7 @@ template void format_internal(std::stringstream stream << value; format_internal(stream, args...); } -template std::string format(const Args &... args) +template std::string format(const Args &...args) { std::stringstream stream; format_internal(stream, args...); diff --git a/src/hacks/Warp.cpp b/src/hacks/Warp.cpp index de72b4b4..871a9c83 100644 --- a/src/hacks/Warp.cpp +++ b/src/hacks/Warp.cpp @@ -21,6 +21,7 @@ namespace hacks::tf2::warp static settings::Boolean enabled{ "warp.enabled", "false" }; static settings::Boolean no_movement{ "warp.rapidfire.no-movement", "true" }; static settings::Boolean rapidfire{ "warp.rapidfire", "false" }; +static settings::Int distance{ "warp.rapidfire.distance", "0" }; static settings::Boolean rapidfire_zoom{ "warp.rapidfire.zoom", "true" }; static settings::Boolean wait_full{ "warp.rapidfire.wait-full", "true" }; static settings::Button rapidfire_key{ "warp.rapidfire.key", "" }; @@ -206,6 +207,14 @@ bool shouldRapidfire() if (LOCAL_W->m_iClassID() == CL_CLASS(CTFMinigun) && CE_INT(LOCAL_W, netvar.iWeaponState) != 3 && CE_INT(LOCAL_W, netvar.iWeaponState) != 2) return false; + // Check if enemies are close enough + if (distance) + { + auto closest = getClosestNonlocalEntity(LOCAL_E->m_vecOrigin()); + if (!closest || closest->m_flDistance() > *distance) + return false; + } + // We do not have the amount of ticks needed, don't try it if (warp_amount < TIME_TO_TICKS(getFireDelay()) && (TIME_TO_TICKS(getFireDelay()) < *maxusrcmdprocessticks - 1 || (wait_full && warp_amount != GetMaxWarpTicks()))) return false; diff --git a/src/helpers.cpp b/src/helpers.cpp index 3529113d..5bf7a776 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -705,6 +705,22 @@ CachedEntity *getClosestEntity(Vector vec) return best_ent; } +CachedEntity *getClosestNonlocalEntity(Vector vec) +{ + float distance = FLT_MAX; + CachedEntity *best_ent = nullptr; + for (int i = 1; i <= g_IEngine->GetMaxClients(); i++) + { + CachedEntity *ent = ENTITY(i); + if (CE_VALID(ent) && ent->m_IDX != g_pLocalPlayer->entity_idx && ent->m_vecDormantOrigin() && ent->m_bAlivePlayer() && ent->m_bEnemy() && vec.DistTo(ent->m_vecOrigin()) < distance) + { + distance = vec.DistTo(*ent->m_vecDormantOrigin()); + best_ent = ent; + } + } + return best_ent; +} + void VectorTransform(const float *in1, const matrix3x4_t &in2, float *out) { out[0] = (in1[0] * in2[0][0] + in1[1] * in2[0][1] + in1[2] * in2[0][2]) + in2[0][3];