From 90f24f0413c90f7a9f8229e5089ba9f5b03decc1 Mon Sep 17 00:00:00 2001 From: dreamstalker Date: Tue, 23 Jun 2015 00:15:27 +0400 Subject: [PATCH] ReHLDS API: Added interceptor for string commands handled by the engine Mark rehlds_syserror() as noreturn Added missing includes in ReHLDS API --- rehlds/engine/cmd.cpp | 36 ++++++++++++++++------------- rehlds/public/rehlds/osconfig.h | 2 +- rehlds/public/rehlds/rehlds_api.h | 5 ++++ rehlds/public/rehlds/sys_shared.cpp | 4 ++++ rehlds/public/rehlds/sys_shared.h | 2 ++ rehlds/rehlds/platform.cpp | 2 +- rehlds/rehlds/rehlds_api_impl.cpp | 4 ++++ rehlds/rehlds/rehlds_api_impl.h | 6 +++++ 8 files changed, 43 insertions(+), 18 deletions(-) diff --git a/rehlds/engine/cmd.cpp b/rehlds/engine/cmd.cpp index f62ed79..06743f5 100644 --- a/rehlds/engine/cmd.cpp +++ b/rehlds/engine/cmd.cpp @@ -944,21 +944,7 @@ bool ValidateCmd_API(const char* cmd, cmd_source_t src, IGameClient* client) { return true; } -/* <5d4e> ../engine/cmd.c:1133 */ -void Cmd_ExecuteString(char *text, cmd_source_t src) -{ - cmd_source = src; - Cmd_TokenizeString(text); - - if (!Cmd_Argc()) - { - return; - } - - IGameClient* cl = (src == src_client) ? GetRehldsApiClient(host_client) : NULL; - if (!g_RehldsHookchains.m_ValidateCommand.callChain(ValidateCmd_API, cmd_argv[0], src, cl)) - return; - +void Cmd_ExecuteString_internal(const char* cmdName, cmd_source_t src, IGameClient* client) { // Search in functions cmd_function_t *cmd = cmd_functions; while (cmd) @@ -984,7 +970,7 @@ void Cmd_ExecuteString(char *text, cmd_source_t src) { if (!Q_stricmp(cmd_argv[0], a->name)) { - + Cbuf_InsertText(a->value); return; } @@ -1000,6 +986,24 @@ void Cmd_ExecuteString(char *text, cmd_source_t src) } } +/* <5d4e> ../engine/cmd.c:1133 */ +void Cmd_ExecuteString(char *text, cmd_source_t src) +{ + cmd_source = src; + Cmd_TokenizeString(text); + + if (!Cmd_Argc()) + { + return; + } + + IGameClient* cl = (src == src_client) ? GetRehldsApiClient(host_client) : NULL; + if (!g_RehldsHookchains.m_ValidateCommand.callChain(ValidateCmd_API, cmd_argv[0], src, cl)) + return; + + g_RehldsHookchains.m_ExecuteServerStringCmd.callChain(Cmd_ExecuteString_internal, cmd_argv[0], src, cl); +} + /* <5c15> ../engine/cmd.c:1181 */ qboolean Cmd_ForwardToServerInternal(sizebuf_t *pBuf) { diff --git a/rehlds/public/rehlds/osconfig.h b/rehlds/public/rehlds/osconfig.h index da499b2..0e647bd 100644 --- a/rehlds/public/rehlds/osconfig.h +++ b/rehlds/public/rehlds/osconfig.h @@ -175,6 +175,6 @@ static const bool __isLinux = true; #endif -extern void rehlds_syserror(const char* fmt, ...); +extern void __declspec(noreturn) rehlds_syserror(const char* fmt, ...); #endif // _OSCONFIG_H diff --git a/rehlds/public/rehlds/rehlds_api.h b/rehlds/public/rehlds/rehlds_api.h index 8930a8c..9cc3a45 100644 --- a/rehlds/public/rehlds/rehlds_api.h +++ b/rehlds/public/rehlds/rehlds_api.h @@ -97,6 +97,10 @@ typedef IHookChainRegistry IRehldsH typedef IHookChain IRehldsHook_ValidateCommand; typedef IHookChainRegistry IRehldsHookRegistry_ValidateCommand; +//ExecuteServerStringCmd +typedef IVoidHookChain IRehldsHook_ExecuteServerStringCmd; +typedef IVoidHookChainRegistry IRehldsHookRegistry_ExecuteServerStringCmd; + //ClientConnected typedef IVoidHookChain IRehldsHook_ClientConnected; typedef IVoidHookChainRegistry IRehldsHookRegistry_ClientConnected; @@ -136,6 +140,7 @@ public: virtual IRehldsHookRegistry_HandleNetCommand* HandleNetCommand() = 0; virtual IRehldsHookRegistry_Mod_LoadBrushModel* Mod_LoadBrushModel() = 0; virtual IRehldsHookRegistry_Mod_LoadStudioModel* Mod_LoadStudioModel() = 0; + virtual IRehldsHookRegistry_ExecuteServerStringCmd* ExecuteServerStringCmd() = 0; }; struct RehldsFuncs_t { diff --git a/rehlds/public/rehlds/sys_shared.cpp b/rehlds/public/rehlds/sys_shared.cpp index 0f56b2e..f39b79a 100644 --- a/rehlds/public/rehlds/sys_shared.cpp +++ b/rehlds/public/rehlds/sys_shared.cpp @@ -27,6 +27,10 @@ */ #include "sys_shared.h" +#if defined(__GNUC__) +#include +#endif + #define SSE3_FLAG (1<<0) #define SSSE3_FLAG (1<<9) #define SSE4_1_FLAG (1<<19) diff --git a/rehlds/public/rehlds/sys_shared.h b/rehlds/public/rehlds/sys_shared.h index 54c608b..cc9ed72 100644 --- a/rehlds/public/rehlds/sys_shared.h +++ b/rehlds/public/rehlds/sys_shared.h @@ -27,6 +27,8 @@ */ #pragma once +#include + typedef struct cpuinfo_s { uint8 sse3, ssse3, sse4_1, sse4_2, avx, avx2; diff --git a/rehlds/rehlds/platform.cpp b/rehlds/rehlds/platform.cpp index 9420ae2..1d01106 100644 --- a/rehlds/rehlds/platform.cpp +++ b/rehlds/rehlds/platform.cpp @@ -191,7 +191,7 @@ void CSimplePlatform::SteamAPI_UnregisterCallback(CCallbackBase *pCallback) ::SteamAPI_UnregisterCallback(pCallback); } -void rehlds_syserror(const char* fmt, ...) { +void __declspec(noreturn) rehlds_syserror(const char* fmt, ...) { va_list argptr; static char string[8192]; diff --git a/rehlds/rehlds/rehlds_api_impl.cpp b/rehlds/rehlds/rehlds_api_impl.cpp index 236d9e3..04864a4 100644 --- a/rehlds/rehlds/rehlds_api_impl.cpp +++ b/rehlds/rehlds/rehlds_api_impl.cpp @@ -185,6 +185,10 @@ IRehldsHookRegistry_Mod_LoadStudioModel* CRehldsHookchains::Mod_LoadStudioModel( return &m_Mod_LoadStudioModel; } +IRehldsHookRegistry_ExecuteServerStringCmd* CRehldsHookchains::ExecuteServerStringCmd() { + return &m_ExecuteServerStringCmd; +} + int CRehldsApi::GetMajorVersion() { return REHLDS_API_VERSION_MAJOR; diff --git a/rehlds/rehlds/rehlds_api_impl.h b/rehlds/rehlds/rehlds_api_impl.h index 7e3e34a..95304b3 100644 --- a/rehlds/rehlds/rehlds_api_impl.h +++ b/rehlds/rehlds/rehlds_api_impl.h @@ -91,6 +91,10 @@ typedef IHookChainRegistryImpl CReh typedef IHookChainImpl CRehldsHook_ValidateCommand; typedef IHookChainRegistryImpl CRehldsHookRegistry_ValidateCommand; +//ExecuteServerStringCmd +typedef IVoidHookChainImpl CRehldsHook_ExecuteServerStringCmd; +typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_ExecuteServerStringCmd; + //ClientConnected typedef IVoidHookChainImpl CRehldsHook_ClientConnected; typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_ClientConnected; @@ -128,6 +132,7 @@ public: CRehldsHookRegistry_HandleNetCommand m_HandleNetCommand; CRehldsHookRegistry_Mod_LoadBrushModel m_Mod_LoadBrushModel; CRehldsHookRegistry_Mod_LoadStudioModel m_Mod_LoadStudioModel; + CRehldsHookRegistry_ExecuteServerStringCmd m_ExecuteServerStringCmd; public: virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect(); @@ -149,6 +154,7 @@ public: virtual IRehldsHookRegistry_HandleNetCommand* HandleNetCommand(); virtual IRehldsHookRegistry_Mod_LoadBrushModel* Mod_LoadBrushModel(); virtual IRehldsHookRegistry_Mod_LoadStudioModel* Mod_LoadStudioModel(); + virtual IRehldsHookRegistry_ExecuteServerStringCmd* ExecuteServerStringCmd(); }; extern CRehldsHookchains g_RehldsHookchains;