Fixed insta crash and created hookedfunction class

This commit is contained in:
TotallyNotElite 2018-09-09 16:12:54 +02:00
parent c5e39e330c
commit bd6f5f53ce
7 changed files with 102 additions and 32 deletions

View File

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

View File

@ -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

View File

@ -3,13 +3,85 @@
#include <functional>
#include <init.hpp>
#include "core/logging.hpp"
#include <string>
class HookedFunction;
namespace HookTools
{
void CreateMove();
}
struct CreateMove
std::vector<HookedFunction*> &GetHookedFunctions();
enum types
{
CreateMove(int priority = 5, std::function<void()> func = []() {});
CreateMove = 0,
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
{
std::string m_name;
std::function<void()> m_func;
HookTools::types m_type;
void init(HookTools::types type, std::string name, int priority, std::function<void()> 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<void()> func)
{
init(type, name, priority, func);
}
HookedFunction(HookTools::types type, int priority, std::function<void()> func)
{
std::string name("UNNAMED_FUNCTION");
init(type, name, priority, func);
}
HookedFunction(HookTools::types type, std::string name, std::function<void()> func)
{
int priority = 5;
init(type, name, priority, func);
}
HookedFunction(HookTools::types type, std::function<void()> func)
{
std::string name("UNNAMED_FUNCTION");
int priority = 5;
init(type, name, priority, func);
}
};
// struct CreateMove
//{
// int priority = 0;
// CreateMove(int priority, std::function<void()> func);
// CreateMove(std::function<void()> func);
//};

View File

@ -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;

View File

@ -3,6 +3,7 @@
#include <glez/draw.hpp>
#endif
#include <settings/Bool.hpp>
#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++)

View File

@ -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);

View File

@ -1,33 +1,34 @@
#include "HookTools.hpp"
std::vector<std::pair<int, std::function<void()>>> &GetCreateMoves()
std::vector<HookedFunction*> &HookTools::GetHookedFunctions()
{
static std::vector<std::pair<int, std::function<void()>>> CreateMoves;
static std::vector<HookedFunction*> CreateMoves{};
return CreateMoves;
}
CreateMove::CreateMove(int priority, std::function<void()> func)
{
auto &CreateMoves = GetCreateMoves();
CreateMoves.emplace_back(priority, func);
}
//CreateMove::CreateMove(int priority, std::function<void()> 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<int, std::function<void()>> a,
std::pair<int, std::function<void()>> 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());
});