From 3543e90fdf2a53261f8c332e8b9713e3d7d1d571 Mon Sep 17 00:00:00 2001 From: Franco Romaniello Date: Wed, 20 Oct 2021 18:51:07 +0200 Subject: [PATCH] Implement GetEntityInit hook (#215) Co-authored-by: Sergey Shorokhov --- .../scripting/include/reapi_engine_const.inc | 5 ++++ reapi/include/cssdk/engine/rehlds_api.h | 25 +++++++++++++++++++ reapi/src/hook_callback.cpp | 10 ++++++++ reapi/src/hook_callback.h | 1 + reapi/src/hook_list.cpp | 1 + reapi/src/hook_list.h | 1 + 6 files changed, 43 insertions(+) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index c9cd95f..39a8d2a 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -55,6 +55,11 @@ enum EngineFunc RH_SV_WriteFullClientUpdate, /* + * Description: - + * Params: (const classname[]) + */ + RH_GetEntityInit, + * Description: Called after processing a client connection request. * Params: (const client) */ diff --git a/reapi/include/cssdk/engine/rehlds_api.h b/reapi/include/cssdk/engine/rehlds_api.h index 2f4a115..960b57d 100644 --- a/reapi/include/cssdk/engine/rehlds_api.h +++ b/reapi/include/cssdk/engine/rehlds_api.h @@ -189,6 +189,26 @@ typedef IHookChainRegistry IRehldsHook_SV_EmitSound2; typedef IHookChainRegistry IRehldsHookRegistry_SV_EmitSound2; +//CreateFakeClient hook +typedef IHookChain IRehldsHook_CreateFakeClient; +typedef IHookChainRegistry IRehldsHookRegistry_CreateFakeClient; + +//SV_CheckConnectionLessRateLimits +typedef IHookChain IRehldsHook_SV_CheckConnectionLessRateLimits; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CheckConnectionLessRateLimits; + +//SV_Frame hook +typedef IVoidHookChain<> IRehldsHook_SV_Frame; +typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_Frame; + +//SV_ShouldSendConsistencyList hook +typedef IHookChain IRehldsHook_SV_ShouldSendConsistencyList; +typedef IHookChainRegistry IRehldsHookRegistry_SV_ShouldSendConsistencyList; + +//GetEntityInit hook +typedef IHookChain IRehldsHook_GetEntityInit; +typedef IHookChainRegistry IRehldsHookRegistry_GetEntityInit; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -231,6 +251,11 @@ public: virtual IRehldsHookRegistry_SV_Spawn_f* SV_Spawn_f() = 0; virtual IRehldsHookRegistry_SV_CreatePacketEntities* SV_CreatePacketEntities() = 0; virtual IRehldsHookRegistry_SV_EmitSound2* SV_EmitSound2() = 0; + virtual IRehldsHookRegistry_CreateFakeClient* CreateFakeClient() = 0; + virtual IRehldsHookRegistry_SV_CheckConnectionLessRateLimits* SV_CheckConnectionLessRateLimits() = 0; + virtual IRehldsHookRegistry_SV_Frame* SV_Frame() = 0; + virtual IRehldsHookRegistry_SV_ShouldSendConsistencyList* SV_ShouldSendConsistencyList() = 0; + virtual IRehldsHookRegistry_GetEntityInit* GetEntityInit() = 0; }; struct RehldsFuncs_t { diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 6d9c697..a807d57 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -63,6 +63,16 @@ void SV_WriteFullClientUpdate(IRehldsHook_SV_WriteFullClientUpdate *chain, IGame SV_WriteFullClientUpdate_AMXX(&data, client, (size_t)buffer, receiver); } +entvars_t *GetEntityInit(IRehldsHook_GetEntityInit *chain, char *classname) +{ + auto original = [chain](char *_classname) + { + return (entvars_t *)chain->callNext(_classname); + }; + + return callForward(RH_GetEntityInit, original, classname); +} + void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl) { auto original = [chain](int client) diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 88154e9..7f73ba7 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -344,6 +344,7 @@ struct SV_WriteFullClientUpdate_args_t using SV_WriteFullClientUpdate_t = hookdata_t; void SV_WriteFullClientUpdate_AMXX(SV_WriteFullClientUpdate_t *data, IGameClient *client, size_t buffer, IGameClient *receiver); void SV_WriteFullClientUpdate(IRehldsHook_SV_WriteFullClientUpdate *chain, IGameClient *client, char *buffer, size_t maxlen, sizebuf_t *sb, IGameClient *receiver); +entvars_s *GetEntityInit(IRehldsHook_GetEntityInit *chain, char *classname); // regamedll functions int GetForceCamera(IReGameHook_GetForceCamera *chain, CBasePlayer *pObserver); diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 5d7a436..8993e2d 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -87,6 +87,7 @@ hook_t hooklist_engine[] = { ENG(SV_ActivateServer), ENG(Cvar_DirectSet), ENG(SV_WriteFullClientUpdate, _AMXX), + ENG(GetEntityInit), ENG(ClientConnected) }; diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 8f2039e..2d8cc14 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -98,6 +98,7 @@ enum EngineFunc RH_SV_ActivateServer, RH_Cvar_DirectSet, RH_SV_WriteFullClientUpdate, + RH_GetEntityInit, RH_ClientConnected // [...]