Hook CL_Move

Cheers, @Lak3!

Also add hooks_restore()
This commit is contained in:
8dcc 2023-07-25 20:36:44 +02:00
parent a103a53fda
commit 74f222c1db
2 changed files with 29 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include "include/sdk.h" #include "include/sdk.h"
#include "include/globals.h" #include "include/globals.h"
#include "include/util.h" #include "include/util.h"
#include "include/detour.h" /* 8dcc/detour-lib */
/* bhop(), esp(), etc. */ /* bhop(), esp(), etc. */
#include "features/features.h" #include "features/features.h"
@ -13,6 +14,11 @@ DECL_HOOK(StudioRenderModel);
DECL_HOOK(glColor4f); DECL_HOOK(glColor4f);
/* For detour hooking CL_Move */
static detour_data_t clmove_data;
DECL_DETOUR_TYPE(void, clmove);
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);
@ -20,9 +26,21 @@ bool hooks_init(void) {
GL_HOOK(glColor4f); GL_HOOK(glColor4f);
void* clmove_ptr = dlsym(hw, "CL_Move");
if (!clmove_ptr)
return false;
/* Initialize clmove_data struct for detour, and add the hook */
detour_init(&clmove_data, clmove_ptr, (void*)h_CL_Move);
detour_add(&clmove_data);
return true; return true;
} }
void hooks_restore(void) {
detour_del(&clmove_data);
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
void h_CL_CreateMove(float frametime, usercmd_t* cmd, int active) { void h_CL_CreateMove(float frametime, usercmd_t* cmd, int active) {
@ -95,3 +113,10 @@ void h_glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
ORIGINAL(glColor4f, r, g, b, a); ORIGINAL(glColor4f, r, g, b, a);
} }
/*----------------------------------------------------------------------------*/
void h_CL_Move() {
/* printf("Hello from CL_Move!\n"); */
CALL_ORIGINAL(clmove_data, clmove);
}

View File

@ -89,10 +89,14 @@
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
bool hooks_init(void); bool hooks_init(void);
void hooks_restore(void);
DECL_HOOK_EXTERN(void, CL_CreateMove, float, usercmd_t*, int); DECL_HOOK_EXTERN(void, CL_CreateMove, float, usercmd_t*, int);
DECL_HOOK_EXTERN(int, HUD_Redraw, float, int); DECL_HOOK_EXTERN(int, HUD_Redraw, float, int);
DECL_HOOK_EXTERN(void, StudioRenderModel, void* this_ptr); DECL_HOOK_EXTERN(void, StudioRenderModel, void* this_ptr);
DECL_HOOK_EXTERN(void, glColor4f, GLfloat r, GLfloat g, GLfloat b, GLfloat a); DECL_HOOK_EXTERN(void, glColor4f, GLfloat r, GLfloat g, GLfloat b, GLfloat a);
DECL_HOOK_EXTERN(void, CL_Move);
#endif /* HOOKS_H_ */ #endif /* HOOKS_H_ */