Some more hookedfunction stuff

This commit is contained in:
TotallyNotElite 2018-09-10 17:46:18 +02:00
parent bd6f5f53ce
commit c8118344a1
5 changed files with 29 additions and 40 deletions

View File

@ -97,7 +97,7 @@
#include "init.hpp" #include "init.hpp"
#include "reclasses/reclasses.hpp" #include "reclasses/reclasses.hpp"
#include <CNavFile.h> #include <CNavFile.h>
//#include "HookTools.hpp" #include "HookTools.hpp"
#include "copypasted/Netvar.h" #include "copypasted/Netvar.h"
#include "copypasted/CSignature.h" #include "copypasted/CSignature.h"

View File

@ -4,41 +4,37 @@
#include <init.hpp> #include <init.hpp>
#include "core/logging.hpp" #include "core/logging.hpp"
#include <string> #include <string>
#include "core/profiler.hpp"
#include <string>
#include "config.h"
class HookedFunction; class HookedFunction;
namespace HookTools namespace HookTools
{ {
std::vector<HookedFunction*> &GetHookedFunctions(); std::vector<HookedFunction*> &GetHookedFunctions();
enum types void CM();
} // namespace HookTools
enum HookedFunctions_types
{ {
CreateMove = 0, HF_CreateMove = 0,
Painttraverse HF_Painttraverse
}; };
void CM();
// struct HookedBase
//{
// int m_priority;
// std::string m_name;
// std::function<void()> m_func;
// HookTools::types m_type;
//};
} // namespace HookTools
class HookedFunction class HookedFunction
{ {
std::string m_name; std::string m_name;
std::function<void()> m_func; std::function<void()> m_func;
HookTools::types m_type; HookedFunctions_types m_type;
void init(HookTools::types type, std::string name, int priority, std::function<void()> func) void init(HookedFunctions_types type, std::string name, int priority, std::function<void()> func)
{ {
switch (type) switch (type)
{ {
case HookTools::CreateMove: case HF_CreateMove:
m_name = "CM_"; m_name = "CM_";
break; break;
case HookTools::Painttraverse: case HF_Painttraverse:
m_name = "PT_"; m_name = "PT_";
break; break;
} }
@ -50,30 +46,34 @@ class HookedFunction
} }
public: public:
int m_priority; int m_priority;
void run(HookTools::types type) void run(HookedFunctions_types type)
{ {
if (m_type == type) if (m_type == type)
{ {
#if ENABLE_PROFILER
static ProfilerSection section(m_name);
ProfilerNode node(section);
#endif
m_func(); m_func();
} }
} }
HookedFunction(HookTools::types type, std::string name, int priority, std::function<void()> func) HookedFunction(HookedFunctions_types type, std::string name, int priority, std::function<void()> func)
{ {
init(type, name, priority, func); init(type, name, priority, func);
} }
HookedFunction(HookTools::types type, int priority, std::function<void()> func) HookedFunction(HookedFunctions_types type, int priority, std::function<void()> func)
{ {
std::string name("UNNAMED_FUNCTION"); static const std::string name("UNNAMED_FUNCTIONS");
init(type, name, priority, func); init(type, name, priority, func);
} }
HookedFunction(HookTools::types type, std::string name, std::function<void()> func) HookedFunction(HookedFunctions_types type, std::string name, std::function<void()> func)
{ {
int priority = 5; int priority = 5;
init(type, name, priority, func); init(type, name, priority, func);
} }
HookedFunction(HookTools::types type, std::function<void()> func) HookedFunction(HookedFunctions_types type, std::function<void()> func)
{ {
std::string name("UNNAMED_FUNCTION"); static const std::string name("UNNAMED_FUNCTIONS");
int priority = 5; int priority = 5;
init(type, name, priority, func); init(type, name, priority, func);
} }

View File

@ -9,7 +9,6 @@
#include "common.hpp" #include "common.hpp"
#include "hack.hpp" #include "hack.hpp"
#include "PlayerTools.hpp" #include "PlayerTools.hpp"
#include "HookTools.hpp"
static settings::Bool enable{ "cat-bot.enable", "false" }; static settings::Bool enable{ "cat-bot.enable", "false" };
@ -287,7 +286,7 @@ void smart_crouch()
} }
// TODO: add more stuffs // TODO: add more stuffs
static HookedFunction cm(HookTools::CreateMove, 5, []() static HookedFunction cm(HF_CreateMove, "catbot", 5, []()
{ {
if (!*enable) if (!*enable)
return; return;

View File

@ -3,7 +3,6 @@
#include <glez/draw.hpp> #include <glez/draw.hpp>
#endif #endif
#include <settings/Bool.hpp> #include <settings/Bool.hpp>
#include "HookTools.hpp"
static settings::Bool enable{ "lightesp.enable", "false" }; static settings::Bool enable{ "lightesp.enable", "false" };
@ -16,9 +15,8 @@ Vector maxp[32];
bool drawEsp[32]; bool drawEsp[32];
#if ENABLE_VISUALS #if ENABLE_VISUALS
static HookedFunction cm(HookTools::CreateMove, 5, [](){ static HookedFunction cm(HF_CreateMove, "lightesp", 5, [](){
//PROF_SECTION(CM_lightesp); if (!*enable)
if (!enable)
return; return;
for (int i = 1; i < g_IEngine->GetMaxClients(); i++) for (int i = 1; i < g_IEngine->GetMaxClients(); i++)
{ {

View File

@ -6,21 +6,13 @@ std::vector<HookedFunction*> &HookTools::GetHookedFunctions()
return CreateMoves; return CreateMoves;
} }
//CreateMove::CreateMove(int priority, std::function<void()> func)
//{
// auto &CreateMoves = GetCreateMoves();
// CreateMoves.emplace_back(priority, func);
//}
// ----------------------------------------------------------- // -----------------------------------------------------------
void HookTools::CM() void HookTools::CM()
{ {
for (auto i : GetHookedFunctions()) for (auto i : GetHookedFunctions())
{ {
i->run(HookTools::CreateMove); i->run(HF_CreateMove);
} }
} }