From cd3fde56a3a2b97417d2bf8ee4f9f4d1b8ef6998 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Mon, 31 Jul 2023 15:36:41 +0200 Subject: [PATCH] Hook HUD_PostRunCmd and store NextAttacks --- src/hooks.c | 19 +++++++++++++++++++ src/include/hooks.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/hooks.c b/src/hooks.c index 192e1ef..affa7e4 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -12,6 +12,7 @@ DECL_HOOK(CL_CreateMove); DECL_HOOK(HUD_Redraw); DECL_HOOK(StudioRenderModel); DECL_HOOK(CalcRefdef); +DECL_HOOK(HUD_PostRunCmd); /* OpenGL hooks */ DECL_HOOK(glColor4f); @@ -29,6 +30,7 @@ bool hooks_init(void) { HOOK(i_client, HUD_Redraw); HOOK(i_studiomodelrenderer, StudioRenderModel); HOOK(i_client, CalcRefdef); + HOOK(i_client, HUD_PostRunCmd); /* OpenGL hooks */ GL_HOOK(glColor4f); @@ -87,6 +89,8 @@ void h_StudioRenderModel(void* this_ptr) { ORIGINAL(StudioRenderModel, this_ptr); } +/*----------------------------------------------------------------------------*/ + void h_CalcRefdef(ref_params_t* params) { /* Store punch angles for CreateMove */ vec_copy(g_punchAngles, params->punchangle); @@ -96,6 +100,21 @@ void h_CalcRefdef(ref_params_t* params) { /*----------------------------------------------------------------------------*/ +void h_HUD_PostRunCmd(struct local_state_s* from, struct local_state_s* to, + struct usercmd_s* cmd, int runfuncs, double time, + unsigned int random_seed) { + ORIGINAL(HUD_PostRunCmd, from, to, cmd, runfuncs, time, random_seed); + + /* Store attack information to check if we can shoot */ + if (runfuncs) { + g_flNextAttack = to->client.m_flNextAttack; + g_flNextPrimaryAttack = + to->weapondata[to->client.m_iId].m_flNextPrimaryAttack; + } +} + +/*----------------------------------------------------------------------------*/ + void h_glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { /* This visible_mode variable is changed inside the chams() function, which * is called from the StudioRenderModel hook. diff --git a/src/include/hooks.h b/src/include/hooks.h index 5106775..564b1b9 100644 --- a/src/include/hooks.h +++ b/src/include/hooks.h @@ -96,6 +96,9 @@ DECL_HOOK_EXTERN(void, CL_CreateMove, float, usercmd_t*, int); DECL_HOOK_EXTERN(int, HUD_Redraw, float, int); DECL_HOOK_EXTERN(void, StudioRenderModel, void*); DECL_HOOK_EXTERN(void, CalcRefdef, ref_params_t*); +DECL_HOOK_EXTERN(void, HUD_PostRunCmd, struct local_state_s*, + struct local_state_s*, struct usercmd_s*, int, double, + unsigned int); /* OpenGL hooks */ DECL_HOOK_EXTERN(void, glColor4f, GLfloat, GLfloat, GLfloat, GLfloat);