Clean hooks.c

Organize includes
Add comments
Rename clmove_data -> detour_data_clmove
Rename clmove_t -> clmove_type_t
This commit is contained in:
8dcc 2023-07-25 23:03:04 +02:00
parent 7a2d7b9377
commit 684f950509
1 changed files with 15 additions and 13 deletions

View File

@ -4,22 +4,24 @@
#include "include/globals.h" #include "include/globals.h"
#include "include/util.h" #include "include/util.h"
#include "include/cvars.h" #include "include/cvars.h"
#include "include/detour.h" /* 8dcc/detour-lib */ #include "include/detour.h" /* 8dcc/detour-lib */
#include "features/features.h" /* bhop(), esp(), etc. */
/* bhop(), esp(), etc. */
#include "features/features.h"
/* Normal VMT hooks */
DECL_HOOK(CL_CreateMove); DECL_HOOK(CL_CreateMove);
DECL_HOOK(HUD_Redraw); DECL_HOOK(HUD_Redraw);
DECL_HOOK(StudioRenderModel); DECL_HOOK(StudioRenderModel);
/* OpenGL hooks */
DECL_HOOK(glColor4f); DECL_HOOK(glColor4f);
/* For detour hooking CL_Move */ /* Detour hooks */
static detour_data_t clmove_data; static detour_data_t detour_data_clmove;
DECL_DETOUR_TYPE(void, clmove); DECL_DETOUR_TYPE(void, clmove_type);
DECL_HOOK(CL_Move); DECL_HOOK(CL_Move);
/*----------------------------------------------------------------------------*/
bool hooks_init(void) { bool hooks_init(void) {
HOOK(i_client, CL_CreateMove); HOOK(i_client, CL_CreateMove);
HOOK(i_client, HUD_Redraw); HOOK(i_client, HUD_Redraw);
@ -31,15 +33,15 @@ bool hooks_init(void) {
if (!clmove_ptr) if (!clmove_ptr)
return false; return false;
/* Initialize clmove_data struct for detour, and add the hook */ /* Initialize detour_data_clmove struct for detour, and add the hook */
detour_init(&clmove_data, clmove_ptr, (void*)h_CL_Move); detour_init(&detour_data_clmove, clmove_ptr, (void*)h_CL_Move);
detour_add(&clmove_data); detour_add(&detour_data_clmove);
return true; return true;
} }
void hooks_restore(void) { void hooks_restore(void) {
detour_del(&clmove_data); detour_del(&detour_data_clmove);
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -110,8 +112,8 @@ void h_glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
void h_CL_Move() { void h_CL_Move() {
if (cv_clmove->value != 0) { if (cv_clmove->value != 0) {
for (int i = 0; i < (int)cv_clmove->value; i++) for (int i = 0; i < (int)cv_clmove->value; i++)
CALL_ORIGINAL(clmove_data, clmove); CALL_ORIGINAL(detour_data_clmove, clmove_type);
} }
CALL_ORIGINAL(clmove_data, clmove); CALL_ORIGINAL(detour_data_clmove, clmove_type);
} }