From d90a1ba34b815ce288e7452610dc8fd1c6741d14 Mon Sep 17 00:00:00 2001 From: Adrian Cirstea <54354938+ShadowsAdi@users.noreply.github.com> Date: Thu, 22 Feb 2024 02:34:27 +0200 Subject: [PATCH 1/2] Add `PF_Message(Begin|End)_I`, `PF_Write*_I` hooks --- .../scripting/include/reapi_engine_const.inc | 61 +++++++++++ reapi/include/cssdk/engine/rehlds_api.h | 50 +++++++++ reapi/src/hook_callback.cpp | 100 ++++++++++++++++++ reapi/src/hook_callback.h | 11 +- reapi/src/hook_list.cpp | 10 ++ reapi/src/hook_list.h | 10 ++ 6 files changed, 241 insertions(+), 1 deletion(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index 2302d05b..4f8f9791 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -183,6 +183,67 @@ enum EngineFunc * Params: (const cmd[], source, id) */ RH_ExecuteServerStringCmd, + + /* + * Description: Called when a message is being sent. + * Params: (msg_dest, msg_type, const float fOrigin[3], const entity) + */ + RH_PF_MessageBegin_I, + + /* + * Description: Called when a message is done sending. + * Params: () + */ + RH_PF_MessageEnd_I, + + /* + * Description: Called when a byte is being write to message buffer. + * Params: (iValue) + */ + RH_PF_WriteByte_I, + + /* + * Description: Called when a char is being write to message buffer. + * Params: (iValue) + */ + RH_PF_WriteChar_I, + + /* + * Description: Called when a short int is being write to message buffer. + * Params: (iValue) + */ + RH_PF_WriteShort_I, + + /* + * Description: Called when a long int is being write to message buffer. + * Params: (iValue) + */ + RH_PF_WriteLong_I, + + /* + * Description: Called when an angle is being write to message buffer. + * Params: (Float:flValue) + */ + RH_PF_WriteAngle_I, + + /* + * Description: Called when a coord is being write to message buffer. + * Params: (Float:flValue) + */ + RH_PF_WriteCoord_I, + + /* + * Description: Called when a string is being write to message buffer. + * Params: (const sz[]) + */ + RH_PF_WriteString_I, + + /* + * Description: Called when an entity is being write to message buffer. + * Params: (iValue) + */ + RH_PF_WriteEntity_I + }; diff --git a/reapi/include/cssdk/engine/rehlds_api.h b/reapi/include/cssdk/engine/rehlds_api.h index 3e2b4ecc..0c53f180 100644 --- a/reapi/include/cssdk/engine/rehlds_api.h +++ b/reapi/include/cssdk/engine/rehlds_api.h @@ -258,6 +258,46 @@ typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_ClientPrintf typedef IHookChain IRehldsHook_SV_AllowPhysent; typedef IHookChainRegistry IRehldsHookRegistry_SV_AllowPhysent; +//PF_MessageBegin_I hook +typedef IVoidHookChain IRehldsHook_PF_MessageBegin_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_MessageBegin_I; + +//PF_MessageEnd_I hook +typedef IVoidHookChain<> IRehldsHook_PF_MessageEnd_I; +typedef IVoidHookChainRegistry<> IRehldsHookRegistry_PF_MessageEnd_I; + +//PF_WriteByte_I hook +typedef IVoidHookChain IRehldsHook_PF_WriteByte_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_WriteByte_I; + +//PF_WriteChar_I hook +typedef IVoidHookChain IRehldsHook_PF_WriteChar_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_WriteChar_I; + +//PF_WriteShort_I hook +typedef IVoidHookChain IRehldsHook_PF_WriteShort_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_WriteShort_I; + +//PF_WriteLong_I hook +typedef IVoidHookChain IRehldsHook_PF_WriteLong_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_WriteLong_I; + +//PF_WriteAngle_I hook +typedef IVoidHookChain IRehldsHook_PF_WriteAngle_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_WriteAngle_I; + +//PF_WriteCoord_I hook +typedef IVoidHookChain IRehldsHook_PF_WriteCoord_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_WriteCoord_I; + +//PF_WriteString_I hook +typedef IVoidHookChain IRehldsHook_PF_WriteString_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_WriteString_I; + +//PF_WriteEntity_I hook +typedef IVoidHookChain IRehldsHook_PF_WriteEntity_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_WriteEntity_I; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -317,6 +357,16 @@ class IRehldsHookchains { virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource() = 0; virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf() = 0; virtual IRehldsHookRegistry_SV_AllowPhysent* SV_AllowPhysent() = 0; + virtual IRehldsHookRegistry_PF_MessageBegin_I* PF_MessageBegin_I() = 0; + virtual IRehldsHookRegistry_PF_MessageEnd_I* PF_MessageEnd_I() = 0; + virtual IRehldsHookRegistry_PF_WriteByte_I* PF_WriteByte_I() = 0; + virtual IRehldsHookRegistry_PF_WriteChar_I* PF_WriteChar_I() = 0; + virtual IRehldsHookRegistry_PF_WriteShort_I* PF_WriteShort_I() = 0; + virtual IRehldsHookRegistry_PF_WriteLong_I* PF_WriteLong_I() = 0; + virtual IRehldsHookRegistry_PF_WriteAngle_I* PF_WriteAngle_I() = 0; + virtual IRehldsHookRegistry_PF_WriteCoord_I* PF_WriteCoord_I() = 0; + virtual IRehldsHookRegistry_PF_WriteString_I* PF_WriteString_I() = 0; + virtual IRehldsHookRegistry_PF_WriteEntity_I* PF_WriteEntity_I() = 0; }; struct RehldsFuncs_t { diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 669ea8ed..10a53362 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -242,6 +242,106 @@ void ExecuteServerStringCmd(IRehldsHook_ExecuteServerStringCmd* chain, const cha callVoidForward(RH_ExecuteServerStringCmd, original, cmdName, cmdSrc, cmdSrc == src_client ? cl->GetId() + 1 : AMX_NULLENT); } +void PF_MessageBegin_I(IRehldsHook_PF_MessageBegin_I* chain, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) +{ + auto original = [chain](int _msg_dest, int _msg_type, const float *_pOrigin, int _entity) + { + chain->callNext(_msg_dest, _msg_type, _pOrigin, edictByIndexAmx(_entity)); + }; + + callVoidForward(RH_PF_MessageBegin_I, original, msg_dest, msg_type, pOrigin, indexOfEdictAmx(ed)); +} + +void PF_MessageEnd_I(IRehldsHook_PF_MessageEnd_I *chain) +{ + auto original = [chain]() + { + chain->callNext(); + }; + + callVoidForward(RH_PF_MessageEnd_I, original); +} + +void PF_WriteByte_I(IRehldsHook_PF_WriteByte_I *chain, int iValue) +{ + auto original = [chain](int _value) + { + chain->callNext(_value); + }; + + callVoidForward(RH_PF_WriteByte_I, original, iValue); +} + +void PF_WriteChar_I(IRehldsHook_PF_WriteChar_I *chain, int iValue) +{ + auto original = [chain](int _value) + { + chain->callNext(_value); + }; + + callVoidForward(RH_PF_WriteChar_I, original, iValue); +} + +void PF_WriteShort_I(IRehldsHook_PF_WriteShort_I *chain, int iValue) +{ + auto original = [chain](int _value) + { + chain->callNext(_value); + }; + + callVoidForward(RH_PF_WriteShort_I, original, iValue); +} + +void PF_WriteLong_I(IRehldsHook_PF_WriteLong_I *chain, int iValue) +{ + auto original = [chain](int _value) + { + chain->callNext(_value); + }; + + callVoidForward(RH_PF_WriteLong_I, original, iValue); +} + +void PF_WriteAngle_I(IRehldsHook_PF_WriteAngle_I *chain, float flValue) +{ + auto original = [chain](float _fvalue) + { + chain->callNext(_fvalue); + }; + + callVoidForward(RH_PF_WriteAngle_I, original, flValue); +} + +void PF_WriteCoord_I(IRehldsHook_PF_WriteCoord_I *chain, float flValue) +{ + auto original = [chain](float _fvalue) + { + chain->callNext(_fvalue); + }; + + callVoidForward(RH_PF_WriteCoord_I, original, flValue); +} + +void PF_WriteString_I(IRehldsHook_PF_WriteString_I *chain, const char * sz) +{ + auto original = [chain](const char *_sz) + { + chain->callNext(_sz); + }; + + callVoidForward(RH_PF_WriteString_I, original, sz); +} + +void PF_WriteEntity_I(IRehldsHook_PF_WriteEntity_I *chain, int iValue) +{ + auto original = [chain](int _value) + { + chain->callNext(_value); + }; + + callVoidForward(RH_PF_WriteEntity_I, original, iValue); +} + /* * ReGameDLL functions */ diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index ede4ad76..ddcadd95 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -385,7 +385,16 @@ edict_t *ED_Alloc(IRehldsHook_ED_Alloc* chain); void ED_Free(IRehldsHook_ED_Free* chain, edict_t *entity); void SV_ClientPrintf(IRehldsHook_SV_ClientPrintf* chain, const char *string); bool SV_AllowPhysent(IRehldsHook_SV_AllowPhysent* chain, edict_t* check, edict_t* sv_player); - +void PF_MessageBegin_I(IRehldsHook_PF_MessageBegin_I* chain, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed); +void PF_MessageEnd_I(IRehldsHook_PF_MessageEnd_I* chain); +void PF_WriteByte_I(IRehldsHook_PF_WriteByte_I* chain, int iValue); +void PF_WriteChar_I(IRehldsHook_PF_WriteChar_I* chain, int iValue); +void PF_WriteShort_I(IRehldsHook_PF_WriteShort_I* chain, int iValue); +void PF_WriteLong_I(IRehldsHook_PF_WriteLong_I* chain, int iValue); +void PF_WriteAngle_I(IRehldsHook_PF_WriteAngle_I* chain, float flValue); +void PF_WriteCoord_I(IRehldsHook_PF_WriteCoord_I* chain, float flValue); +void PF_WriteString_I(IRehldsHook_PF_WriteString_I* chain, const char *sz); +void PF_WriteEntity_I(IRehldsHook_PF_WriteEntity_I* chain, int iValue); /* * ReGameDLL functions */ diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 8f5bf54a..3ebe38a9 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -108,6 +108,16 @@ hook_t hooklist_engine[] = { ENG(SV_ClientPrintf), ENG(SV_AllowPhysent), ENG(ExecuteServerStringCmd), + ENG(PF_MessageBegin_I), + ENG(PF_MessageEnd_I), + ENG(PF_WriteByte_I), + ENG(PF_WriteChar_I), + ENG(PF_WriteShort_I), + ENG(PF_WriteLong_I), + ENG(PF_WriteAngle_I), + ENG(PF_WriteCoord_I), + ENG(PF_WriteString_I), + ENG(PF_WriteEntity_I), }; diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 6e6d9da7..46c83c7e 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -117,6 +117,16 @@ enum EngineFunc RH_SV_ClientPrintf, RH_SV_AllowPhysent, RH_ExecuteServerStringCmd, + RH_PF_MessageBegin_I, + RH_PF_MessageEnd_I, + RH_PF_WriteByte_I, + RH_PF_WriteChar_I, + RH_PF_WriteShort_I, + RH_PF_WriteLong_I, + RH_PF_WriteAngle_I, + RH_PF_WriteCoord_I, + RH_PF_WriteString_I, + RH_PF_WriteEntity_I, // [...] }; From 959873d77f26b21c00685dd26416987197043854 Mon Sep 17 00:00:00 2001 From: Adrian Cirstea <54354938+ShadowsAdi@users.noreply.github.com> Date: Thu, 22 Feb 2024 13:30:32 +0200 Subject: [PATCH 2/2] Update reapi_engine_const.inc --- reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index 4f8f9791..e73c2371 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -186,7 +186,7 @@ enum EngineFunc /* * Description: Called when a message is being sent. - * Params: (msg_dest, msg_type, const float fOrigin[3], const entity) + * Params: (msg_dest, msg_type, const Float:fOrigin[3], const entity) */ RH_PF_MessageBegin_I,