From 6c6ff95e9baad6a2f34729f8a6373e2dc15a51c0 Mon Sep 17 00:00:00 2001 From: Adrian Cirstea <54354938+ShadowsAdi@users.noreply.github.com> Date: Mon, 13 May 2024 16:06:11 +0300 Subject: [PATCH] Implement `RH_SV_SendResources` hook (#308) --- .../scripting/include/reapi_engine_const.inc | 9 ++++++++- reapi/include/cssdk/engine/rehlds_api.h | 5 +++++ reapi/src/hook_callback.cpp | 16 ++++++++++++++++ reapi/src/hook_callback.h | 4 ++++ reapi/src/hook_list.cpp | 2 +- reapi/src/hook_list.h | 1 + 6 files changed, 35 insertions(+), 2 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index 2302d05..a2e47f9 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -100,9 +100,10 @@ enum EngineFunc /* * Description: Called when client it's in the scoreboard - * Params: (const this) + * Params: (const client) */ RH_SV_EmitPings, + /* * Description: Called when an entity is created. * Return type: Edict * (Entity index) @@ -184,6 +185,12 @@ enum EngineFunc */ RH_ExecuteServerStringCmd, + /* + * Description: Called when server sends resources list and location. + * Params: (const client) + */ + RH_SV_SendResources, + }; /** diff --git a/reapi/include/cssdk/engine/rehlds_api.h b/reapi/include/cssdk/engine/rehlds_api.h index 3e2b4ec..28f41a1 100644 --- a/reapi/include/cssdk/engine/rehlds_api.h +++ b/reapi/include/cssdk/engine/rehlds_api.h @@ -258,6 +258,10 @@ typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_ClientPrintf typedef IHookChain IRehldsHook_SV_AllowPhysent; typedef IHookChainRegistry IRehldsHookRegistry_SV_AllowPhysent; +//SV_SendResources hook +typedef IVoidHookChain IRehldsHook_SV_SendResources; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_SendResources; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -317,6 +321,7 @@ public: virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource() = 0; virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf() = 0; virtual IRehldsHookRegistry_SV_AllowPhysent* SV_AllowPhysent() = 0; + virtual IRehldsHookRegistry_SV_SendResources* SV_SendResources() = 0; }; struct RehldsFuncs_t { diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 06e0900..c37f1d9 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -242,6 +242,22 @@ void ExecuteServerStringCmd(IRehldsHook_ExecuteServerStringCmd* chain, const cha callVoidForward(RH_ExecuteServerStringCmd, original, cmdName, cmdSrc, cmdSrc == src_client ? cl->GetId() + 1 : AMX_NULLENT); } +void SV_SendResources_AMXX(SV_SendResources_t *data, IGameClient *cl) +{ + auto original = [data](int _cl) + { + data->m_chain->callNext(data->m_args); + }; + + callVoidForward(RH_SV_SendResources, original, cl ? cl->GetId() + 1 : AMX_NULLENT); +} + +void SV_SendResources(IRehldsHook_SV_SendResources *chain, sizebuf_t *msg) +{ + SV_SendResources_t data(chain, msg); + SV_SendResources_AMXX(&data, g_RehldsFuncs->GetHostClient()); +} + /* * ReGameDLL functions */ diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 8bdc9c7..9e18c3e 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -371,6 +371,10 @@ int PF_precache_generic_I(IRehldsHook_PF_precache_generic_I *chain, const char * int PF_precache_model_I(IRehldsHook_PF_precache_model_I *chain, char *s); int PF_precache_sound_I(IRehldsHook_PF_precache_sound_I *chain, const char *s); +using SV_SendResources_t = hookdata_t; +void SV_SendResources_AMXX(SV_SendResources_t *data, IGameClient *cl); +void SV_SendResources(IRehldsHook_SV_SendResources *chain, sizebuf_t *msg); + struct EventPrecache_args_t { EventPrecache_args_t(int _type) : type(_type) {} diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 26e054d..df09450 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -108,7 +108,7 @@ hook_t hooklist_engine[] = { ENG(SV_ClientPrintf), ENG(SV_AllowPhysent), ENG(ExecuteServerStringCmd), - + ENG(SV_SendResources, _AMXX), }; #define DLL(h,...) { {}, {}, #h, "ReGameDLL", [](){ return api_cfg.hasReGameDLL(); }, ((!(RG_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RG_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h##__VA_ARGS__) : regfunc(#h#__VA_ARGS__), [](){ g_ReGameHookchains->h()->registerHook(&h); }, [](){ g_ReGameHookchains->h()->unregisterHook(&h); }, false} diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 02cabe3..1618afd 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -117,6 +117,7 @@ enum EngineFunc RH_SV_ClientPrintf, RH_SV_AllowPhysent, RH_ExecuteServerStringCmd, + RH_SV_SendResources, // [...] };