From 749f6d8623ae4e753cc6fbcc6dbad79c7ba829a2 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Thu, 17 Oct 2019 10:29:58 +0200 Subject: [PATCH] common.hpp and include refactor --- include/angles.hpp | 77 +---- include/common.hpp | 26 -- include/entitycache.hpp | 2 - include/entityhitboxcache.hpp | 4 +- include/hooks/HookTools.hpp | 1 - include/navparser.hpp | 5 +- include/visual/fidgetspinner.hpp | 15 - src/angles.cpp | 72 ++++ src/conditions.cpp | 1 + src/hack.cpp | 20 +- src/hacks/Aimbot.cpp | 7 + src/hacks/AntiCheat.cpp | 1 + src/hacks/Misc.cpp | 2 - src/hacks/ac/aimbot.cpp | 1 + src/hacks/ac/antiaim.cpp | 1 + src/hooks/DispatchUserMessage.cpp | 2 + src/hooks/LevelShutdown.cpp | 4 - src/hooks/Paint.cpp | 1 + src/hooks/Shutdown.cpp | 1 + src/hooks/visual/SDL_GL_SwapWindow.cpp | 1 + src/navparser.cpp | 458 ++++++++++++------------- src/visual/EffectChams.cpp | 10 + src/visual/EffectGlow.cpp | 11 + src/visual/drawmgr.cpp | 4 +- src/visual/fidgetspinner.cpp | 6 +- src/votelogger.cpp | 1 + 26 files changed, 358 insertions(+), 376 deletions(-) delete mode 100755 include/visual/fidgetspinner.hpp diff --git a/include/angles.hpp b/include/angles.hpp index 305b9828..a61b9020 100644 --- a/include/angles.hpp +++ b/include/angles.hpp @@ -7,69 +7,16 @@ #pragma once -#include "common.hpp" -#include +#include "mathlib/vector.h" +#include "entitycache.hpp" namespace angles { struct angle_data_s { static constexpr size_t count = 16; - inline void push(const Vector &angle) - { - if (not angle.x and not angle.y) - return; - good = true; - angles[angle_index] = angle; - if (++angle_index >= count) - { - angle_index = 0; - } - /*if (angle_count > 0) { - int ai = angle_index - 2; - if (ai < 0) ai = count - 1; - float dx = std::abs(angles[ai].x - angle.x); - float dy = std::abs(angles[ai].y - angle.y); - if (sqrt(dx * dx + dy * dy) > 45.0f) { - //logging::Info("%.2f %.2f %.2f", dx, dy, sqrt(dx * dx + dy * - dy)); - } - }*/ - if (angle_count < count) - { - angle_count++; - } - } - inline float deviation(int steps) const - { - int j = angle_index - 2; - int k = j + 1; - float hx = 0, hy = 0; - for (int i = 0; i < steps && i < angle_count; i++) - { - if (j < 0) - j = count + j; - if (k < 0) - k = count + k; - - float dev_x = std::abs(angles[k].x - angles[j].x); - float dev_y = std::abs(angles[k].y - angles[j].y); - if (dev_x > hx) - hx = dev_x; - if (dev_y > hy) - hy = dev_y; - - // logging::Info("1: %.2f %.2f | 2: %.2f %.2f | dev: %.2f", - // angles[k].x, angles[k].y, angles[j].x, angles[j].y, sqrt(dev_x * - // dev_x + dev_y * dev_y)); - - --j; - --k; - } - if (hy > 180) - hy = 360 - hy; - return sqrt(hx * hx + hy * hy); - } + void push(const Vector &angle); + float deviation(int steps) const; Vector angles[count]{}; bool good{ false }; @@ -80,18 +27,6 @@ struct angle_data_s extern angle_data_s data_[32]; void Update(); - -inline angle_data_s &data_idx(int index) -{ - if (index < 1 || index > 32) - { - throw std::out_of_range("Angle table entity index out of range"); - } - return data_[index - 1]; -} - -inline angle_data_s &data(const CachedEntity *entity) -{ - return data_idx(entity->m_IDX); -} +angle_data_s &data_idx(int index); +angle_data_s &data(const CachedEntity *entity); } // namespace angles diff --git a/include/common.hpp b/include/common.hpp index f77473bb..25597002 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -11,52 +11,31 @@ #include "config.h" -#include #include -#include #include #include -#include -#include #include -#include #include #include -#include -#include #include -#include #include #include -#include -#include #include #include #include -#include -#include -#include #include #include #include -#include #include -#include -#include #include "timer.hpp" -#include "averager.hpp" #include "core/macros.hpp" #if ENABLE_VISUALS #include #include -#include "visual/fidgetspinner.hpp" -#include #include -#include -#include #endif #include "core/profiler.hpp" @@ -66,8 +45,6 @@ #include #include "projlogging.hpp" #include "velocity.hpp" -#include "angles.hpp" -#include "entityhitboxcache.hpp" #include "globals.h" #include #include "playerlist.hpp" @@ -75,7 +52,6 @@ #include #include #include -#include #include "playerresource.h" #include "sdk/usercmd.hpp" #include "trace.hpp" @@ -84,7 +60,6 @@ #include "core/vfunc.hpp" #include "hooks.hpp" #include -#include #include #include #include "textfile.hpp" @@ -92,7 +67,6 @@ #include "tfmm.hpp" #include "hooks/HookedMethods.hpp" #include "classinfo/classinfo.hpp" -#include "votelogger.hpp" #include "crits.hpp" #include "textmode.hpp" #include "core/sharedobj.hpp" diff --git a/include/entitycache.hpp b/include/entitycache.hpp index 882c20dd..fe2c6ae1 100644 --- a/include/entitycache.hpp +++ b/include/entitycache.hpp @@ -10,7 +10,6 @@ #include "entityhitboxcache.hpp" #include "averager.hpp" #include -#include #include #include #include @@ -22,7 +21,6 @@ #include "playerresource.h" #include "globals.h" #include "classinfo/classinfo.hpp" -#include "classinfo/tf2.gen.hpp" #include "client_class.h" struct matrix3x4_t; diff --git a/include/entityhitboxcache.hpp b/include/entityhitboxcache.hpp index 049bfd67..9e9e028f 100644 --- a/include/entityhitboxcache.hpp +++ b/include/entityhitboxcache.hpp @@ -7,13 +7,11 @@ #pragma once -#include -#include #include -#include #include #include +// Forward declaration from entitycache.hpp class CachedEntity; #define CACHE_MAX_HITBOXES 64 diff --git a/include/hooks/HookTools.hpp b/include/hooks/HookTools.hpp index 93c5d1b6..a5c33506 100644 --- a/include/hooks/HookTools.hpp +++ b/include/hooks/HookTools.hpp @@ -2,7 +2,6 @@ #include "core/profiler.hpp" #include "functional" -#include #include namespace EC diff --git a/include/navparser.hpp b/include/navparser.hpp index 3fd75d01..238035c6 100644 --- a/include/navparser.hpp +++ b/include/navparser.hpp @@ -1,7 +1,10 @@ #pragma once #include -#include +#include "mathlib/vector.h" + +class CNavFile; +class CNavArea; namespace nav { diff --git a/include/visual/fidgetspinner.hpp b/include/visual/fidgetspinner.hpp deleted file mode 100755 index dbb81b9a..00000000 --- a/include/visual/fidgetspinner.hpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * fidgetspinner.hpp - * - * Created on: Jul 4, 2017 - * Author: nullifiedcat - */ - -#pragma once - -#include -#include "common.hpp" - -extern std::array spinner_states; -void InitSpinner(); -void DrawSpinner(); diff --git a/src/angles.cpp b/src/angles.cpp index a97322a3..fd0403c3 100644 --- a/src/angles.cpp +++ b/src/angles.cpp @@ -4,6 +4,7 @@ * Created on: Jun 5, 2017 * Author: nullifiedcat */ +#include "common.hpp" #include "angles.hpp" namespace angles @@ -11,6 +12,77 @@ namespace angles angle_data_s data_[32]; +void angle_data_s::push(const Vector &angle) +{ + if (not angle.x and not angle.y) + return; + good = true; + angles[angle_index] = angle; + if (++angle_index >= count) + { + angle_index = 0; + } + /*if (angle_count > 0) { + int ai = angle_index - 2; + if (ai < 0) ai = count - 1; + float dx = std::abs(angles[ai].x - angle.x); + float dy = std::abs(angles[ai].y - angle.y); + if (sqrt(dx * dx + dy * dy) > 45.0f) { + //logging::Info("%.2f %.2f %.2f", dx, dy, sqrt(dx * dx + dy * + dy)); + } + }*/ + if (angle_count < count) + { + angle_count++; + } +} + +float angle_data_s::deviation(int steps) const +{ + int j = angle_index - 2; + int k = j + 1; + float hx = 0, hy = 0; + for (int i = 0; i < steps && i < angle_count; i++) + { + if (j < 0) + j = count + j; + if (k < 0) + k = count + k; + + float dev_x = std::abs(angles[k].x - angles[j].x); + float dev_y = std::abs(angles[k].y - angles[j].y); + if (dev_x > hx) + hx = dev_x; + if (dev_y > hy) + hy = dev_y; + + // logging::Info("1: %.2f %.2f | 2: %.2f %.2f | dev: %.2f", + // angles[k].x, angles[k].y, angles[j].x, angles[j].y, sqrt(dev_x * + // dev_x + dev_y * dev_y)); + + --j; + --k; + } + if (hy > 180) + hy = 360 - hy; + return sqrt(hx * hx + hy * hy); +} + +angle_data_s &data_idx(int index) +{ + if (index < 1 || index > 32) + { + throw std::out_of_range("Angle table entity index out of range"); + } + return data_[index - 1]; +} + +angle_data_s &data(const CachedEntity *entity) +{ + return data_idx(entity->m_IDX); +} + void Update() { for (int i = 1; i < 33; i++) diff --git a/src/conditions.cpp b/src/conditions.cpp index b370d673..5bb951db 100644 --- a/src/conditions.cpp +++ b/src/conditions.cpp @@ -6,6 +6,7 @@ */ #include "common.hpp" +#include static CatCommand dump_conditions("debug_conditions", "Shows conditions for entity #", [](const CCommand &args) { int id = atoi(args.Arg(1)); diff --git a/src/hack.cpp b/src/hack.cpp index 32b43389..9115024d 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -17,6 +17,8 @@ #include "hack.hpp" #include "common.hpp" #include "MiscTemporary.hpp" +#include +#include #include #if EXTERNAL_DRAWING @@ -354,26 +356,8 @@ free(logname);*/ playerlist::Load(); #if ENABLE_VISUALS - InitStrings(); -#ifndef FEATURE_EFFECTS_DISABLED - if (g_ppScreenSpaceRegistrationHead && g_pScreenSpaceEffects) - { - effect_chams::g_pEffectChams = new CScreenSpaceEffectRegistration("_cathook_chams", &effect_chams::g_EffectChams); - g_pScreenSpaceEffects->EnableScreenSpaceEffect("_cathook_chams"); - effect_glow::g_pEffectGlow = new CScreenSpaceEffectRegistration("_cathook_glow", &effect_glow::g_EffectGlow); - g_pScreenSpaceEffects->EnableScreenSpaceEffect("_cathook_glow"); - } - logging::Info("SSE enabled.."); -#endif - #endif /* TEXTMODE */ -#if ENABLE_VISUALS -#ifndef FEATURE_FIDGET_SPINNER_ENABLED - InitSpinner(); - logging::Info("Initialized Fidget Spinner"); -#endif -#endif logging::Info("Clearing initializer stack"); while (!init_stack().empty()) { diff --git a/src/hacks/Aimbot.cpp b/src/hacks/Aimbot.cpp index a04c290f..b13e337c 100644 --- a/src/hacks/Aimbot.cpp +++ b/src/hacks/Aimbot.cpp @@ -14,6 +14,13 @@ #include #include "common.hpp" #include "MiscTemporary.hpp" +#include + +#if ENABLE_VISUALS +#ifndef FEATURE_EFFECTS_DISABLED +#include "EffectChams.hpp" +#endif +#endif namespace hacks::shared::aimbot { diff --git a/src/hacks/AntiCheat.cpp b/src/hacks/AntiCheat.cpp index 237bec87..d478de08 100644 --- a/src/hacks/AntiCheat.cpp +++ b/src/hacks/AntiCheat.cpp @@ -12,6 +12,7 @@ #include "common.hpp" #include "PlayerTools.hpp" #include "hack.hpp" +#include "angles.hpp" namespace hacks::shared::anticheat { diff --git a/src/hacks/Misc.cpp b/src/hacks/Misc.cpp index 7661b7ce..81dbebab 100644 --- a/src/hacks/Misc.cpp +++ b/src/hacks/Misc.cpp @@ -9,10 +9,8 @@ #include #include #include -#include #include #include -#include #include #include diff --git a/src/hacks/ac/aimbot.cpp b/src/hacks/ac/aimbot.cpp index f1af837c..8db383e3 100644 --- a/src/hacks/ac/aimbot.cpp +++ b/src/hacks/ac/aimbot.cpp @@ -9,6 +9,7 @@ #include #include #include "common.hpp" +#include "angles.hpp" namespace ac::aimbot { diff --git a/src/hacks/ac/antiaim.cpp b/src/hacks/ac/antiaim.cpp index 6eb780f9..395f8cb3 100644 --- a/src/hacks/ac/antiaim.cpp +++ b/src/hacks/ac/antiaim.cpp @@ -8,6 +8,7 @@ #include #include #include "common.hpp" +#include "angles.hpp" namespace ac::antiaim { diff --git a/src/hooks/DispatchUserMessage.cpp b/src/hooks/DispatchUserMessage.cpp index 0dae677d..75c8cf19 100644 --- a/src/hooks/DispatchUserMessage.cpp +++ b/src/hooks/DispatchUserMessage.cpp @@ -13,6 +13,8 @@ #include "CatBot.hpp" #include "ChatCommands.hpp" #include "MiscTemporary.hpp" +#include +#include "votelogger.hpp" static settings::Boolean dispatch_log{ "debug.log-dispatch-user-msg", "false" }; static settings::Boolean chat_filter_enable{ "chat.censor.enable", "false" }; diff --git a/src/hooks/LevelShutdown.cpp b/src/hooks/LevelShutdown.cpp index 6ba48141..54117a77 100644 --- a/src/hooks/LevelShutdown.cpp +++ b/src/hooks/LevelShutdown.cpp @@ -16,10 +16,6 @@ DEFINE_HOOKED_METHOD(LevelShutdown, void, void *this_) playerlist::Save(); g_Settings.bInvalid = true; chat_stack::Reset(); -#if ENABLE_VISUALS - effect_glow::g_EffectGlow.Shutdown(); - effect_chams::g_EffectChams.Shutdown(); -#endif EC::run(EC::LevelShutdown); #if ENABLE_IPC if (ipc::peer) diff --git a/src/hooks/Paint.cpp b/src/hooks/Paint.cpp index a44a1a3b..d0f349a9 100644 --- a/src/hooks/Paint.cpp +++ b/src/hooks/Paint.cpp @@ -11,6 +11,7 @@ #include "common.hpp" #include "hitrate.hpp" #include "hack.hpp" +#include "drawmgr.hpp" extern settings::Boolean die_if_vac; static Timer checkmmban{}; namespace hooked_methods diff --git a/src/hooks/Shutdown.cpp b/src/hooks/Shutdown.cpp index b64f5834..70b80a42 100644 --- a/src/hooks/Shutdown.cpp +++ b/src/hooks/Shutdown.cpp @@ -7,6 +7,7 @@ #include #include "HookedMethods.hpp" #include "MiscTemporary.hpp" +#include "votelogger.hpp" settings::Boolean die_if_vac{ "misc.die-if-vac", "false" }; static settings::Boolean autoabandon{ "misc.auto-abandon", "false" }; diff --git a/src/hooks/visual/SDL_GL_SwapWindow.cpp b/src/hooks/visual/SDL_GL_SwapWindow.cpp index 49932dff..0d5d5c29 100644 --- a/src/hooks/visual/SDL_GL_SwapWindow.cpp +++ b/src/hooks/visual/SDL_GL_SwapWindow.cpp @@ -10,6 +10,7 @@ #include #include #include "clip.h" +#include "drawmgr.hpp" static bool swapwindow_init{ false }; static bool init_wminfo{ false }; diff --git a/src/navparser.cpp b/src/navparser.cpp index 64baf4ce..c6b177e3 100644 --- a/src/navparser.cpp +++ b/src/navparser.cpp @@ -8,6 +8,7 @@ #include #include "soundcache.hpp" #include "MiscTemporary.hpp" +#include namespace nav { @@ -21,7 +22,7 @@ static settings::Boolean look{ "misc.pathing.look-at-path", "false" }; static settings::Int stuck_time{ "misc.pathing.stuck-time", "4000" }; static settings::Int unreachable_time{ "misc.pathing.unreachable-time", "1000" }; -static std::vector crumbs; +static std::vector crumbs; static Vector startPoint, endPoint; enum ignore_status : uint8_t @@ -54,10 +55,10 @@ struct ignoredata Vector GetClosestCornerToArea(CNavArea *CornerOf, const Vector &target) { std::array corners{ - CornerOf->m_nwCorner, // NW - CornerOf->m_seCorner, // SE - { CornerOf->m_seCorner.x, CornerOf->m_nwCorner.y, CornerOf->m_nwCorner.z },// NE - { CornerOf->m_nwCorner.x, CornerOf->m_seCorner.y, CornerOf->m_seCorner.z } // SW + CornerOf->m_nwCorner, // NW + CornerOf->m_seCorner, // SE + { CornerOf->m_seCorner.x, CornerOf->m_nwCorner.y, CornerOf->m_nwCorner.z }, // NE + { CornerOf->m_nwCorner.x, CornerOf->m_seCorner.y, CornerOf->m_seCorner.z } // SW }; Vector *bestVec = &corners[0], *bestVec2 = bestVec; @@ -91,243 +92,245 @@ float getZBetweenAreas(CNavArea *start, CNavArea *end) return z2 - z1; } - static std::unordered_map, ignoredata, boost::hash>> ignores; namespace ignoremanager { - static bool vischeck(CNavArea *begin, CNavArea *end) +static bool vischeck(CNavArea *begin, CNavArea *end) +{ + Vector first = begin->m_center; + Vector second = end->m_center; + first.z += 42; + second.z += 42; + return IsVectorVisible(first, second, true, LOCAL_E, MASK_PLAYERSOLID); +} +static ignore_status runIgnoreChecks(CNavArea *begin, CNavArea *end) +{ + if (getZBetweenAreas(begin, end) > 42) + return const_ignored; + if (!vischecks) + return vischeck_success; + if (vischeck(begin, end)) + return vischeck_success; + else + return vischeck_failed; +} +static void updateDanger() +{ + for (size_t i = 0; i <= HIGHEST_ENTITY; i++) { - Vector first = begin->m_center; - Vector second = end->m_center; - first.z += 42; - second.z += 42; - return IsVectorVisible(first, second, true, LOCAL_E, MASK_PLAYERSOLID); - } - static ignore_status runIgnoreChecks(CNavArea *begin, CNavArea *end) - { - if (getZBetweenAreas(begin, end) > 42) - return const_ignored; - if (!vischecks) - return vischeck_success; - if (vischeck(begin, end)) - return vischeck_success; - else - return vischeck_failed; - } - static void updateDanger() - { - for (size_t i = 0; i <= HIGHEST_ENTITY; i++) + CachedEntity *ent = ENTITY(i); + if (CE_INVALID(ent)) + continue; + if (ent->m_iClassID() == CL_CLASS(CObjectSentrygun)) { - CachedEntity *ent = ENTITY(i); - if (CE_INVALID(ent)) + if (!ent->m_bEnemy()) continue; - if (ent->m_iClassID() == CL_CLASS(CObjectSentrygun)) - { - if (!ent->m_bEnemy()) - continue; - if (HasCondition(LOCAL_E)) - continue; - Vector loc = GetBuildingPosition(ent); - if (RAW_ENT(ent)->IsDormant()) - { - auto vec = ent->m_vecDormantOrigin(); - if (vec) - { - loc -= RAW_ENT(ent)->GetCollideable()->GetCollisionOrigin(); - loc += *vec; - } - else - continue; - } - for (auto &i : navfile->m_areas) - { - Vector area = i.m_center; - area.z += 41.5f; - if (loc.DistTo(area) > 1100) - continue; - // Check if sentry can see us - if (!IsVectorVisible(loc, area, true)) - continue; - ignoredata &data = ignores[{ &i, nullptr }]; - data.status = danger_found; - data.ignoreTimeout.update(); - data.ignoreTimeout.last -= std::chrono::seconds(17); - } - } - else if (ent->m_iClassID() == CL_CLASS(CTFGrenadePipebombProjectile)) - { - if (!ent->m_bEnemy()) - continue; - if (CE_INT(ent, netvar.iPipeType) == 1) - continue; - Vector loc = ent->m_vecOrigin(); - for (auto &i : navfile->m_areas) - { - Vector area = i.m_center; - if (loc.DistTo(area) > 130) - continue; - area.z += 41.5f; - // Check if We can see stickies - if (!IsVectorVisible(loc, area, true)) - continue; - ignoredata &data = ignores[{ &i, nullptr }]; - data.status = danger_found; - data.ignoreTimeout.update(); - data.ignoreTimeout.last -= std::chrono::seconds(17); - } - } - } - } - - static void checkPath() - { - bool perform_repath = false; - // Vischecks - for (size_t i = 0; i < crumbs.size() - 1; i++) - { - CNavArea *begin = crumbs[i]; - CNavArea *end = crumbs[i + 1]; - if (!begin || !end) + if (HasCondition(LOCAL_E)) continue; - ignoredata &data = ignores[{ begin, end }]; - if (data.status == vischeck_failed) - return; - if (!vischeck(begin, end)) + Vector loc = GetBuildingPosition(ent); + if (RAW_ENT(ent)->IsDormant()) { - data.status = vischeck_failed; + auto vec = ent->m_vecDormantOrigin(); + if (vec) + { + loc -= RAW_ENT(ent)->GetCollideable()->GetCollisionOrigin(); + loc += *vec; + } + else + continue; + } + for (auto &i : navfile->m_areas) + { + Vector area = i.m_center; + area.z += 41.5f; + if (loc.DistTo(area) > 1100) + continue; + // Check if sentry can see us + if (!IsVectorVisible(loc, area, true)) + continue; + ignoredata &data = ignores[{ &i, nullptr }]; + data.status = danger_found; data.ignoreTimeout.update(); - perform_repath = true; - } - else if (ignores[{ end, nullptr }].status == danger_found) - { - perform_repath = true; + data.ignoreTimeout.last -= std::chrono::seconds(17); + } + } + else if (ent->m_iClassID() == CL_CLASS(CTFGrenadePipebombProjectile)) + { + if (!ent->m_bEnemy()) + continue; + if (CE_INT(ent, netvar.iPipeType) == 1) + continue; + Vector loc = ent->m_vecOrigin(); + for (auto &i : navfile->m_areas) + { + Vector area = i.m_center; + if (loc.DistTo(area) > 130) + continue; + area.z += 41.5f; + // Check if We can see stickies + if (!IsVectorVisible(loc, area, true)) + continue; + ignoredata &data = ignores[{ &i, nullptr }]; + data.status = danger_found; + data.ignoreTimeout.update(); + data.ignoreTimeout.last -= std::chrono::seconds(17); } } - if (perform_repath) - repath(); } - // 0 = Not ignored, 1 = low priority, 2 = ignored - static int isIgnored(CNavArea *begin, CNavArea *end) - { - if (ignores[{ end, nullptr }].status == danger_found) - return 2; - ignore_status status = ignores[{ begin, end }].status; - if (status == unknown) - status = runIgnoreChecks(begin, end); - if (status == vischeck_success) - return 0; - else if (status == vischeck_failed) - return 1; - else - return 2; - } - static bool addTime(ignoredata &connection, ignore_status status) - { - connection.status = status; - connection.ignoreTimeout.update(); +} +static void checkPath() +{ + bool perform_repath = false; + // Vischecks + for (size_t i = 0; i < crumbs.size() - 1; i++) + { + CNavArea *begin = crumbs[i]; + CNavArea *end = crumbs[i + 1]; + if (!begin || !end) + continue; + ignoredata &data = ignores[{ begin, end }]; + if (data.status == vischeck_failed) + return; + if (!vischeck(begin, end)) + { + data.status = vischeck_failed; + data.ignoreTimeout.update(); + perform_repath = true; + } + else if (ignores[{ end, nullptr }].status == danger_found) + { + perform_repath = true; + } + } + if (perform_repath) + repath(); +} +// 0 = Not ignored, 1 = low priority, 2 = ignored +static int isIgnored(CNavArea *begin, CNavArea *end) +{ + if (ignores[{ end, nullptr }].status == danger_found) + return 2; + ignore_status status = ignores[{ begin, end }].status; + if (status == unknown) + status = runIgnoreChecks(begin, end); + if (status == vischeck_success) + return 0; + else if (status == vischeck_failed) + return 1; + else + return 2; +} +static bool addTime(ignoredata &connection, ignore_status status) +{ + connection.status = status; + connection.ignoreTimeout.update(); + + return true; +} +static bool addTime(CNavArea *begin, CNavArea *end, ignore_status status) +{ + logging::Info("Ignored Connection %i-%i", begin->m_id, end->m_id); + return addTime(ignores[{ begin, end }], status); +} +static bool addTime(CNavArea *begin, CNavArea *end, Timer &time) +{ + if (!begin || !end) + { + // We can't reach the destination vector. Destination vector might + // be out of bounds/reach. + clearInstructions(); return true; } - static bool addTime(CNavArea *begin, CNavArea *end, ignore_status status) + using namespace std::chrono; + // Check if connection is already known + if (ignores.find({ begin, end }) == ignores.end()) + { + ignores[{ begin, end }] = {}; + } + ignoredata &connection = ignores[{ begin, end }]; + connection.stucktime += duration_cast(system_clock::now() - time.last).count(); + if (connection.stucktime >= *stuck_time) { logging::Info("Ignored Connection %i-%i", begin->m_id, end->m_id); - return addTime(ignores[{ begin, end }], status); + return addTime(connection, explicit_ignored); } - static bool addTime(CNavArea *begin, CNavArea *end, Timer &time) + return false; +} +static void reset() +{ + ignores.clear(); + ResetPather(); +} +static void updateIgnores() +{ + static Timer update{}; + static Timer last_pather_reset{}; + static bool reset_pather = false; + if (!update.test_and_set(500)) + return; + updateDanger(); + if (crumbs.empty()) { - if (!begin || !end) + for (auto &i : ignores) { - // We can't reach the destination vector. Destination vector might - // be out of bounds/reach. - clearInstructions(); - return true; - } - using namespace std::chrono; - // Check if connection is already known - if (ignores.find({ begin, end }) == ignores.end()) - { - ignores[{ begin, end }] = {}; - } - ignoredata &connection = ignores[{ begin, end }]; - connection.stucktime += duration_cast(system_clock::now() - time.last).count(); - if (connection.stucktime >= *stuck_time) - { - logging::Info("Ignored Connection %i-%i", begin->m_id, end->m_id); - return addTime(connection, explicit_ignored); - } - return false; - } - static void reset() - { - ignores.clear(); - ResetPather(); - } - static void updateIgnores() - { - static Timer update{}; - static Timer last_pather_reset{}; - static bool reset_pather = false; - if (!update.test_and_set(500)) - return; - updateDanger(); - if (crumbs.empty()) - { - for (auto &i : ignores) + switch (i.second.status) { - switch (i.second.status) + case explicit_ignored: + if (i.second.ignoreTimeout.check(60000)) { - case explicit_ignored: - if (i.second.ignoreTimeout.check(60000)) - { - i.second.status = unknown; - i.second.stucktime = 0; - reset_pather = true; - } - break; - case unknown: - break; - case danger_found: - if (i.second.ignoreTimeout.check(20000)) - { - i.second.status = unknown; - reset_pather = true; - } - break; - case vischeck_failed: - case vischeck_success: - default: - if (i.second.ignoreTimeout.check(30000)) - { - i.second.status = unknown; - i.second.stucktime = 0; - reset_pather = true; - } - break; + i.second.status = unknown; + i.second.stucktime = 0; + reset_pather = true; } + break; + case unknown: + break; + case danger_found: + if (i.second.ignoreTimeout.check(20000)) + { + i.second.status = unknown; + reset_pather = true; + } + break; + case vischeck_failed: + case vischeck_success: + default: + if (i.second.ignoreTimeout.check(30000)) + { + i.second.status = unknown; + i.second.stucktime = 0; + reset_pather = true; + } + break; } } - else - checkPath(); - if (reset_pather && last_pather_reset.test_and_set(10000)) - { - reset_pather = false; - ResetPather(); - } } - static bool isSafe(CNavArea *area) + else + checkPath(); + if (reset_pather && last_pather_reset.test_and_set(10000)) { - return !(ignores[{ area, nullptr }].status == danger_found); + reset_pather = false; + ResetPather(); } -}; +} +static bool isSafe(CNavArea *area) +{ + return !(ignores[{ area, nullptr }].status == danger_found); +} +}; // namespace ignoremanager struct Graph : public micropather::Graph { std::unique_ptr pather; - Graph() { + Graph() + { pather = std::make_unique(this, 3000, 6, true); } - ~Graph() override {} + ~Graph() override + { + } void AdjacentCost(void *state, MP_VECTOR *adjacent) override { CNavArea *center = static_cast(state); @@ -338,7 +341,8 @@ struct Graph : public micropather::Graph if (isIgnored == 2) continue; float distance = center->m_center.DistTo(i.area->m_center); - if (isIgnored == 1) { + if (isIgnored == 1) + { if (*vischeckBlock) continue; distance += 50000; @@ -352,7 +356,9 @@ struct Graph : public micropather::Graph CNavArea *end = reinterpret_cast(stateEnd); return start->m_center.DistTo(end->m_center); } - void PrintStateInfo(void *) override {} + void PrintStateInfo(void *) override + { + } }; // Navfile containing areas @@ -435,8 +441,7 @@ CNavArea *findClosestNavSquare(const Vector &vec) for (auto &i : navfile->m_areas) { // Make sure we're not stuck on the same area for too long - if (isLocal && std::count(findClosestNavSquare_localAreas.begin(), - findClosestNavSquare_localAreas.end(), &i) >= 3) + if (isLocal && std::count(findClosestNavSquare_localAreas.begin(), findClosestNavSquare_localAreas.end(), &i) >= 3) { continue; } @@ -447,8 +452,7 @@ CNavArea *findClosestNavSquare(const Vector &vec) bestSquare = &i; } // Check if we are within x and y bounds of an area - if (ovBestDist >= dist || !i.IsOverlapping(vec) || - !IsVectorVisible(vec, i.m_center, true, LOCAL_E, MASK_PLAYERSOLID)) + if (ovBestDist >= dist || !i.IsOverlapping(vec) || !IsVectorVisible(vec, i.m_center, true, LOCAL_E, MASK_PLAYERSOLID)) { continue; } @@ -464,7 +468,7 @@ CNavArea *findClosestNavSquare(const Vector &vec) return ovBestSquare; } -std::vector findPath(const Vector &start, const Vector &end) +std::vector findPath(const Vector &start, const Vector &end) { using namespace std::chrono; @@ -478,13 +482,11 @@ std::vector findPath(const Vector &start, const Vector &end) logging::Info("Start: (%f,%f,%f)", local->m_center.x, local->m_center.y, local->m_center.z); logging::Info("End: (%f,%f,%f)", dest->m_center.x, dest->m_center.y, dest->m_center.z); float cost; - std::vector pathNodes; + std::vector pathNodes; time_point begin_pathing = high_resolution_clock::now(); - int result = Map.pather->Solve(reinterpret_cast(local), - reinterpret_cast(dest), - reinterpret_cast*>(&pathNodes), &cost); - long long timetaken = duration_cast(high_resolution_clock::now() - begin_pathing).count(); + int result = Map.pather->Solve(reinterpret_cast(local), reinterpret_cast(dest), reinterpret_cast *>(&pathNodes), &cost); + long long timetaken = duration_cast(high_resolution_clock::now() - begin_pathing).count(); logging::Info("Pathing: Pather result: %i. Time taken (NS): %lld", result, timetaken); // If no result found, return empty Vector if (result == micropather::MicroPather::NO_SOLUTION) @@ -495,7 +497,7 @@ std::vector findPath(const Vector &start, const Vector &end) static Vector loc(0.0f, 0.0f, 0.0f); static CNavArea *last_area = nullptr; -bool ReadyForCommands = true; +bool ReadyForCommands = true; static Timer inactivity{}; int curr_priority = 0; static bool ensureArrival = false; @@ -611,15 +613,13 @@ static void cm() } if (look && LookAtPathTimer.check(1000)) { - Vector next{crumb_vec->x, crumb_vec->y, g_pLocalPlayer->v_Eye.z}; + Vector next{ crumb_vec->x, crumb_vec->y, g_pLocalPlayer->v_Eye.z }; next = GetAimAtAngles(g_pLocalPlayer->v_Eye, next); DoSlowAim(next); current_user_cmd->viewangles = next; } // Detect when jumping is necessary - if ((!(g_pLocalPlayer->holding_sniper_rifle && g_pLocalPlayer->bZoomed) && - crumb_vec->z - g_pLocalPlayer->v_Origin.z > 18 && last_jump.test_and_set(200)) || - (last_jump.test_and_set(200) && inactivity.check(*stuck_time / 2))) + if ((!(g_pLocalPlayer->holding_sniper_rifle && g_pLocalPlayer->bZoomed) && crumb_vec->z - g_pLocalPlayer->v_Origin.z > 18 && last_jump.test_and_set(200)) || (last_jump.test_and_set(200) && inactivity.check(*stuck_time / 2))) { current_user_cmd->buttons |= IN_JUMP; } @@ -629,9 +629,7 @@ static void cm() * ignore that connection * Or if inactive for too long */ - if (inactivity.check(*stuck_time) || (inactivity.check(*unreachable_time) && - !IsVectorVisible(g_pLocalPlayer->v_Origin, *crumb_vec + Vector(.0f, .0f, 41.5f), - false, LOCAL_E, MASK_PLAYERSOLID))) + if (inactivity.check(*stuck_time) || (inactivity.check(*unreachable_time) && !IsVectorVisible(g_pLocalPlayer->v_Origin, *crumb_vec + Vector(.0f, .0f, 41.5f), false, LOCAL_E, MASK_PLAYERSOLID))) { /* crumb is invalid if endPoint is used */ if (crumb_vec != &endPoint) @@ -656,12 +654,14 @@ static void drawcrumbs() for (size_t i = 0; i < crumbs.size(); i++) { Vector wts1, wts2, *o1, *o2; - if (crumbs.size() - 1 == i) { + if (crumbs.size() - 1 == i) + { if (!endPoint.IsValid()) break; o2 = &endPoint; - } else + } + else o2 = &crumbs[i + 1]->m_center; o1 = &crumbs[i]->m_center; diff --git a/src/visual/EffectChams.cpp b/src/visual/EffectChams.cpp index 1d9b2f61..30e491e6 100644 --- a/src/visual/EffectChams.cpp +++ b/src/visual/EffectChams.cpp @@ -368,4 +368,14 @@ void EffectChams::Render(int x, int y, int w, int h) } EffectChams g_EffectChams; CScreenSpaceEffectRegistration *g_pEffectChams = nullptr; + +static InitRoutine init([]() { + EC::Register( + EC::LevelShutdown, []() { g_EffectChams.Shutdown(); }, "chams"); + if (g_ppScreenSpaceRegistrationHead && g_pScreenSpaceEffects) + { + effect_chams::g_pEffectChams = new CScreenSpaceEffectRegistration("_cathook_chams", &effect_chams::g_EffectChams); + g_pScreenSpaceEffects->EnableScreenSpaceEffect("_cathook_chams"); + } +}); } // namespace effect_chams diff --git a/src/visual/EffectGlow.cpp b/src/visual/EffectGlow.cpp index 61228311..902a5906 100644 --- a/src/visual/EffectGlow.cpp +++ b/src/visual/EffectGlow.cpp @@ -509,4 +509,15 @@ void EffectGlow::Render(int x, int y, int w, int h) EffectGlow g_EffectGlow; CScreenSpaceEffectRegistration *g_pEffectGlow = nullptr; + +static InitRoutine init([]() { + EC::Register( + EC::LevelShutdown, []() { g_EffectGlow.Shutdown(); }, "glow"); + if (g_ppScreenSpaceRegistrationHead && g_pScreenSpaceEffects) + { + effect_glow::g_pEffectGlow = new CScreenSpaceEffectRegistration("_cathook_glow", &effect_glow::g_EffectGlow); + g_pScreenSpaceEffects->EnableScreenSpaceEffect("_cathook_glow"); + } +} // namespace effect_glow +); } // namespace effect_glow diff --git a/src/visual/drawmgr.cpp b/src/visual/drawmgr.cpp index 59bc4473..ee620dbb 100644 --- a/src/visual/drawmgr.cpp +++ b/src/visual/drawmgr.cpp @@ -22,6 +22,7 @@ #include "visual/drawing.hpp" #include "hack.hpp" #include "menu/menu/Menu.hpp" +#include "drawmgr.hpp" static settings::Boolean info_text{ "hack-info.enable", "true" }; static settings::Boolean info_text_min{ "hack-info.minimal", "false" }; @@ -108,9 +109,6 @@ void DrawCheatVisuals() PROF_SECTION(DRAW_skinchanger); hacks::tf2::skinchanger::DrawText(); } -#ifndef FEATURE_FIDGET_SPINNER_ENABLED - DrawSpinner(); -#endif Prediction_PaintTraverse(); } { diff --git a/src/visual/fidgetspinner.cpp b/src/visual/fidgetspinner.cpp index 1d24aaa3..3002f5cb 100644 --- a/src/visual/fidgetspinner.cpp +++ b/src/visual/fidgetspinner.cpp @@ -5,7 +5,6 @@ * Author: nullifiedcat */ -#include "visual/fidgetspinner.hpp" #include "common.hpp" #include "../../external/libglez/ftgl/freetype-gl.h" @@ -87,4 +86,9 @@ void DrawSpinner() angle -= PI * 4; } +static InitRoutine init([]() { + InitSpinner(); + EC::Register(EC::Draw, DrawSpinner, "spinner"); +}); + #endif diff --git a/src/votelogger.cpp b/src/votelogger.cpp index 6291d291..1627e359 100644 --- a/src/votelogger.cpp +++ b/src/votelogger.cpp @@ -9,6 +9,7 @@ #include #include #include "CatBot.hpp" +#include "votelogger.hpp" static settings::Boolean vote_kicky{ "votelogger.autovote.yes", "false" }; static settings::Boolean vote_kickn{ "votelogger.autovote.no", "false" };