From de26345d27bb25bf8f0badf212b87b1313892e2b Mon Sep 17 00:00:00 2001 From: Sergey Shorokhov Date: Sat, 23 Oct 2021 12:54:44 +0300 Subject: [PATCH] Add `pr_dlls.h` & fix `GetEntityInit()` return type (#228) * Add pr_dlls.h * fix GetEntityInit hook return type * add getApiType(ENTITYINIT) type cast * remove extra cast from callNext() * indent fix --- reapi/include/cssdk/engine/pr_dlls.h | 51 +++++++++++++++++++++++++ reapi/include/cssdk/engine/rehlds_api.h | 5 ++- reapi/src/hook_callback.cpp | 6 +-- reapi/src/hook_callback.h | 23 +++++------ 4 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 reapi/include/cssdk/engine/pr_dlls.h diff --git a/reapi/include/cssdk/engine/pr_dlls.h b/reapi/include/cssdk/engine/pr_dlls.h new file mode 100644 index 0000000..d7b72c1 --- /dev/null +++ b/reapi/include/cssdk/engine/pr_dlls.h @@ -0,0 +1,51 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#pragma once + +#include "maintypes.h" +#include "eiface.h" + +const int MAX_EXTENSION_DLL = 50; + +typedef struct functiontable_s +{ + uint32 pFunction; + char *pFunctionName; +} functiontable_t; + +typedef struct extensiondll_s +{ + void *lDLLHandle; + functiontable_t *functionTable; + int functionCount; +} extensiondll_t; + +typedef void(*ENTITYINIT)(struct entvars_s *); +typedef void(*DISPATCHFUNCTION)(struct entvars_s *, void *); +typedef void(*FIELDIOFUNCTION)(SAVERESTOREDATA *, const char *, void *, TYPEDESCRIPTION *, int); diff --git a/reapi/include/cssdk/engine/rehlds_api.h b/reapi/include/cssdk/engine/rehlds_api.h index 202319d..5a9a78f 100644 --- a/reapi/include/cssdk/engine/rehlds_api.h +++ b/reapi/include/cssdk/engine/rehlds_api.h @@ -33,6 +33,7 @@ #include "FlightRecorder.h" #include "interface.h" #include "model.h" +#include "pr_dlls.h" #define REHLDS_API_VERSION_MAJOR 3 #define REHLDS_API_VERSION_MINOR 11 @@ -206,8 +207,8 @@ typedef IHookChain IRehldsHook_SV_ShouldSendConsistenc typedef IHookChainRegistry IRehldsHookRegistry_SV_ShouldSendConsistencyList; //GetEntityInit hook -typedef IHookChain IRehldsHook_GetEntityInit; -typedef IHookChainRegistry IRehldsHookRegistry_GetEntityInit; +typedef IHookChain IRehldsHook_GetEntityInit; +typedef IHookChainRegistry IRehldsHookRegistry_GetEntityInit; //SV_EmitPings hook typedef IHookChain IRehldsHook_SV_EmitPings; diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index ef1a65b..3ea6dac 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -63,14 +63,14 @@ 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) +ENTITYINIT GetEntityInit(IRehldsHook_GetEntityInit *chain, char *classname) { auto original = [chain](char *_classname) { - return (entvars_t *)chain->callNext(_classname); + return chain->callNext(_classname); }; - return callForward(RH_GetEntityInit, original, classname); + return callForward(RH_GetEntityInit, original, classname); } void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl) diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index cee403b..2889321 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -41,17 +41,18 @@ struct retval_t }; }; -inline AType getApiType(int) { return ATYPE_INTEGER; } -inline AType getApiType(unsigned) { return ATYPE_INTEGER; } -inline AType getApiType(ULONG) { return ATYPE_INTEGER; } -inline AType getApiType(float) { return ATYPE_FLOAT; } -inline AType getApiType(const char *) { return ATYPE_STRING; } -inline AType getApiType(char[]) { return ATYPE_STRING; } -inline AType getApiType(CBaseEntity *) { return ATYPE_CLASSPTR; } -inline AType getApiType(edict_t *) { return ATYPE_EDICT; } -inline AType getApiType(entvars_t *) { return ATYPE_EVARS; } -inline AType getApiType(bool) { return ATYPE_BOOL; } +inline AType getApiType(int) { return ATYPE_INTEGER; } +inline AType getApiType(unsigned) { return ATYPE_INTEGER; } +inline AType getApiType(ULONG) { return ATYPE_INTEGER; } +inline AType getApiType(float) { return ATYPE_FLOAT; } +inline AType getApiType(const char *) { return ATYPE_STRING; } +inline AType getApiType(char[]) { return ATYPE_STRING; } +inline AType getApiType(CBaseEntity *) { return ATYPE_CLASSPTR; } +inline AType getApiType(edict_t *) { return ATYPE_EDICT; } +inline AType getApiType(entvars_t *) { return ATYPE_EVARS; } +inline AType getApiType(bool) { return ATYPE_BOOL; } inline AType getApiType(Vector) { return ATYPE_VECTOR; } +inline AType getApiType(ENTITYINIT) { return ATYPE_INTEGER; } template inline AType getApiType(T *) { return ATYPE_INTEGER; } @@ -344,7 +345,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); +ENTITYINIT GetEntityInit(IRehldsHook_GetEntityInit *chain, char *classname); struct SV_EmitPings_args_t {