From bd6f5f53ce5c4e436ba7c97d8f4e3577b2eecab6 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 9 Sep 2018 16:12:54 +0200 Subject: [PATCH] Fixed insta crash and created hookedfunction class --- include/common.hpp | 2 +- include/hacks/CatBot.hpp | 1 - include/hooks/HookTools.hpp | 82 ++++++++++++++++++++++++++++++++++--- src/hacks/CatBot.cpp | 3 +- src/hacks/LightESP.cpp | 5 ++- src/hooks/CreateMove.cpp | 6 +-- src/hooks/HookTools.cpp | 35 ++++++++-------- 7 files changed, 102 insertions(+), 32 deletions(-) diff --git a/include/common.hpp b/include/common.hpp index 95819b26..3151f230 100755 --- a/include/common.hpp +++ b/include/common.hpp @@ -97,7 +97,7 @@ #include "init.hpp" #include "reclasses/reclasses.hpp" #include -#include "HookTools.hpp" +//#include "HookTools.hpp" #include "copypasted/Netvar.h" #include "copypasted/CSignature.h" diff --git a/include/hacks/CatBot.hpp b/include/hacks/CatBot.hpp index 14e332a1..87deafdf 100644 --- a/include/hacks/CatBot.hpp +++ b/include/hacks/CatBot.hpp @@ -16,7 +16,6 @@ bool is_a_catbot(unsigned steamID); bool should_ignore_player(CachedEntity *player); void update(); void init(); -void CreateMove(); void level_init(); #if ENABLE_IPC diff --git a/include/hooks/HookTools.hpp b/include/hooks/HookTools.hpp index 80acf5d9..249d9c2a 100644 --- a/include/hooks/HookTools.hpp +++ b/include/hooks/HookTools.hpp @@ -3,13 +3,85 @@ #include #include #include "core/logging.hpp" +#include +class HookedFunction; namespace HookTools { -void CreateMove(); -} - -struct CreateMove +std::vector &GetHookedFunctions(); +enum types { - CreateMove(int priority = 5, std::function func = []() {}); + CreateMove = 0, + Painttraverse + }; +void CM(); + +// struct HookedBase +//{ +// int m_priority; +// std::string m_name; +// std::function m_func; +// HookTools::types m_type; +//}; +} // namespace HookTools + +class HookedFunction +{ + std::string m_name; + std::function m_func; + HookTools::types m_type; + void init(HookTools::types type, std::string name, int priority, std::function func) + { + switch (type) + { + case HookTools::CreateMove: + m_name = "CM_"; + break; + case HookTools::Painttraverse: + m_name = "PT_"; + break; + } + m_name.append(name); + m_priority = priority; + m_func = func; + m_type = type; + HookTools::GetHookedFunctions().push_back(this); + } +public: + int m_priority; + void run(HookTools::types type) + { + if (m_type == type) + { + m_func(); + } + } + HookedFunction(HookTools::types type, std::string name, int priority, std::function func) + { + init(type, name, priority, func); + } + HookedFunction(HookTools::types type, int priority, std::function func) + { + std::string name("UNNAMED_FUNCTION"); + init(type, name, priority, func); + } + HookedFunction(HookTools::types type, std::string name, std::function func) + { + int priority = 5; + init(type, name, priority, func); + } + HookedFunction(HookTools::types type, std::function func) + { + std::string name("UNNAMED_FUNCTION"); + int priority = 5; + init(type, name, priority, func); + } +}; + +// struct CreateMove +//{ +// int priority = 0; +// CreateMove(int priority, std::function func); +// CreateMove(std::function func); +//}; diff --git a/src/hacks/CatBot.cpp b/src/hacks/CatBot.cpp index ecb3ba87..efa6bf51 100644 --- a/src/hacks/CatBot.cpp +++ b/src/hacks/CatBot.cpp @@ -9,6 +9,7 @@ #include "common.hpp" #include "hack.hpp" #include "PlayerTools.hpp" +#include "HookTools.hpp" static settings::Bool enable{ "cat-bot.enable", "false" }; @@ -286,7 +287,7 @@ void smart_crouch() } // TODO: add more stuffs -static CreateMove cm(5, []() +static HookedFunction cm(HookTools::CreateMove, 5, []() { if (!*enable) return; diff --git a/src/hacks/LightESP.cpp b/src/hacks/LightESP.cpp index 7e2f16cc..d3db8f29 100644 --- a/src/hacks/LightESP.cpp +++ b/src/hacks/LightESP.cpp @@ -3,6 +3,7 @@ #include #endif #include +#include "HookTools.hpp" static settings::Bool enable{ "lightesp.enable", "false" }; @@ -15,8 +16,8 @@ Vector maxp[32]; bool drawEsp[32]; #if ENABLE_VISUALS -static CreateMove run(5, []() { - PROF_SECTION(CM_lightesp); +static HookedFunction cm(HookTools::CreateMove, 5, [](){ + //PROF_SECTION(CM_lightesp); if (!enable) return; for (int i = 1; i < g_IEngine->GetMaxClients(); i++) diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index fe099b0e..3a2654e7 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -258,7 +258,7 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, { PROF_SECTION(CM_WRAPPER); - HookTools::CreateMove(); + HookTools::CM(); } #if ENABLE_IPC @@ -277,10 +277,6 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, UpdateHoovyList(); } g_pLocalPlayer->v_OrigViewangles = cmd->viewangles; - { - PROF_SECTION(CM_catbot) - hacks::shared::catbot::CreateMove(); - } #if ENABLE_VISUALS { PROF_SECTION(CM_esp); diff --git a/src/hooks/HookTools.cpp b/src/hooks/HookTools.cpp index 2608a0d6..3fe0965d 100644 --- a/src/hooks/HookTools.cpp +++ b/src/hooks/HookTools.cpp @@ -1,33 +1,34 @@ #include "HookTools.hpp" -std::vector>> &GetCreateMoves() +std::vector &HookTools::GetHookedFunctions() { - static std::vector>> CreateMoves; + static std::vector CreateMoves{}; return CreateMoves; } -CreateMove::CreateMove(int priority, std::function func) -{ - auto &CreateMoves = GetCreateMoves(); - CreateMoves.emplace_back(priority, func); -} +//CreateMove::CreateMove(int priority, std::function func) +//{ +// auto &CreateMoves = GetCreateMoves(); +// CreateMoves.emplace_back(priority, func); +//} + + // ----------------------------------------------------------- -void HookTools::CreateMove() +void HookTools::CM() { - for (auto i : GetCreateMoves()) + for (auto i : GetHookedFunctions()) { - i.second(); + i->run(HookTools::CreateMove); } } static InitRoutine init([]() { - auto &CreateMoves = GetCreateMoves(); - std::sort(CreateMoves.begin(), CreateMoves.end(), - [](std::pair> a, - std::pair> b) { - return a.first > b.first; - }); - logging::Info("Sorted CreateMove functions: %i", CreateMoves.size()); + auto &HookedFunctions = HookTools::GetHookedFunctions(); + std::sort(HookedFunctions.begin(), HookedFunctions.end(), + [](HookedFunction *a, HookedFunction *b){ + return a->m_priority > b->m_priority; + }); + logging::Info("Sorted Hooked Functions: %i", HookedFunctions.size()); });