From b727c5455e353dbde9987ed3d538c796a0da4a79 Mon Sep 17 00:00:00 2001 From: Nick Hastings Date: Sun, 2 Apr 2023 10:13:21 -0400 Subject: [PATCH] Remove ClientCommand Source 2 hacks from outside of provider --- core/metamod.cpp | 19 +++----- core/metamod_console.cpp | 16 ------- core/metamod_console.h | 4 -- core/metamod_provider.h | 51 ++++++++++++---------- core/provider/source/provider_source.cpp | 6 ++- core/provider/source2/provider_source2.cpp | 7 ++- 6 files changed, 44 insertions(+), 59 deletions(-) diff --git a/core/metamod.cpp b/core/metamod.cpp index 4234dca..c21729c 100644 --- a/core/metamod.cpp +++ b/core/metamod.cpp @@ -194,6 +194,11 @@ static class ProviderCallbacks : public IMetamodSourceProviderCallbacks ITER_EVENT(OnLevelShutdown, ()); } + + virtual bool OnCommand_ClientMeta(edict_t* client, IMetamodSourceCommandInfo* info) override + { + return Command_ClientMeta(client, info); + } } s_ProviderCallbacks; /* Initialize everything here */ @@ -740,20 +745,6 @@ size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...) return mylen; } -#if SOURCE_ENGINE == SE_DOTA -void MetamodSource::ClientConPrintf(int clientIndex, const char *fmt, ...) -{ - va_list ap; - char buffer[2048]; - - va_start(ap, fmt); - UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap); - va_end(ap); - - ClientConPrintf((edict_t *)(gpGlobals->pEdicts + clientIndex), "%s", buffer); -} -#endif - void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...) { va_list ap; diff --git a/core/metamod_console.cpp b/core/metamod_console.cpp index 61aa480..28effa8 100644 --- a/core/metamod_console.cpp +++ b/core/metamod_console.cpp @@ -44,11 +44,7 @@ using namespace SourceHook; #define CLIENT_CONMSG g_Metamod.ClientConPrintf template -#if SOURCE_ENGINE == SE_DOTA -void CMDMSG(int client, const char *pMsg, Ts ... ts) -#else void CMDMSG(edict_t *client, const char *pMsg, Ts ... ts) -#endif { if (client) { @@ -60,11 +56,7 @@ void CMDMSG(edict_t *client, const char *pMsg, Ts ... ts) } } -#if SOURCE_ENGINE == SE_DOTA -static void ReplyCredits(int client = 0) -#else static void ReplyCredits(edict_t *client = nullptr) -#endif { CMDMSG(client, "Metamod:Source was developed by:\n"); CMDMSG(client, " SourceHook: Pavol \"PM OnoTo\" Marko\n"); @@ -74,11 +66,7 @@ static void ReplyCredits(edict_t *client = nullptr) CMDMSG(client, "http://www.metamodsource.net/\n"); } -#if SOURCE_ENGINE == SE_DOTA -static void ReplyVersion(int client = 0) -#else static void ReplyVersion(edict_t *client = nullptr) -#endif { CMDMSG(client, " Metamod:Source Version Information\n"); CMDMSG(client, " Metamod:Source version %s\n", METAMOD_VERSION); @@ -654,11 +642,7 @@ bool Command_Meta(IMetamodSourceCommandInfo *info) return true; } -#if SOURCE_ENGINE == SE_DOTA -bool Command_ClientMeta(int client, IMetamodSourceCommandInfo *info) -#else bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info) -#endif { const char *cmd = info->GetArg(0); diff --git a/core/metamod_console.h b/core/metamod_console.h index ef3d529..6b3e278 100644 --- a/core/metamod_console.h +++ b/core/metamod_console.h @@ -31,10 +31,6 @@ #include "metamod_provider.h" bool Command_Meta(IMetamodSourceCommandInfo *info); -#if SOURCE_ENGINE == SE_DOTA -bool Command_ClientMeta(int client, IMetamodSourceCommandInfo *info); -#else bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info); -#endif #endif //_INCLUDE_CONCOMMANDS_H diff --git a/core/metamod_provider.h b/core/metamod_provider.h index b7fdebd..b44e61f 100644 --- a/core/metamod_provider.h +++ b/core/metamod_provider.h @@ -51,29 +51,6 @@ namespace SourceMM #endif }; - /** - * @brief Interface for Metamod:Source to provide callbacks to the - * provider. - */ - class IMetamodSourceProviderCallbacks - { - public: - /** - * @brief Called before the server DLL handles game initialization. - */ - virtual void OnGameInit() = 0; - - /** - * @brief Called after the server DLL has completed handling level/map initialization. - */ - virtual void OnLevelInit(char const* pMapName, char const* pMapEntities, char const* pOldLevel, char const* pLandmarkName, bool loadGame, bool background) = 0; - - /** - * @brief Called after the server DLL has completed handling level/map shut down. - */ - virtual void OnLevelShutdown() = 0; - }; - /** * @brief Abstracts command information, since the new engine fixes the * re-entrancy problems in the tokenization system. @@ -105,6 +82,34 @@ namespace SourceMM virtual const char *GetArgString() =0; }; + /** + * @brief Interface for Metamod:Source to provide callbacks to the + * provider. + */ + class IMetamodSourceProviderCallbacks + { + public: + /** + * @brief Called before the server DLL handles game initialization. + */ + virtual void OnGameInit() = 0; + + /** + * @brief Called after the server DLL has completed handling level/map initialization. + */ + virtual void OnLevelInit(char const* pMapName, char const* pMapEntities, char const* pOldLevel, char const* pLandmarkName, bool loadGame, bool background) = 0; + + /** + * @brief Called after the server DLL has completed handling level/map shut down. + */ + virtual void OnLevelShutdown() = 0; + + /** + * @brief Called when a client executes "meta" as a ClientCommand + */ + virtual bool OnCommand_ClientMeta(edict_t* client, IMetamodSourceCommandInfo* info) = 0; + }; + class IMetamodSourceProvider { public: diff --git a/core/provider/source/provider_source.cpp b/core/provider/source/provider_source.cpp index 9742841..c678eef 100644 --- a/core/provider/source/provider_source.cpp +++ b/core/provider/source/provider_source.cpp @@ -631,7 +631,11 @@ void SourceProvider::Hook_ClientCommand(edict_t * client) #endif if (strcmp(cmd.GetArg(0), "meta") == 0) { - Command_ClientMeta(client, &cmd); + if (nullptr != m_pCallbacks) + { + m_pCallbacks->OnCommand_ClientMeta(client, &cmd); + } + RETURN_META(MRES_SUPERCEDE); } diff --git a/core/provider/source2/provider_source2.cpp b/core/provider/source2/provider_source2.cpp index fcb8f26..d6dd8cd 100644 --- a/core/provider/source2/provider_source2.cpp +++ b/core/provider/source2/provider_source2.cpp @@ -431,7 +431,12 @@ void Source2Provider::Hook_ClientCommand(CEntityIndex index, const CCommand& _cm if (strcmp(cmd.GetArg(0), "meta") == 0) { - Command_ClientMeta(client, &cmd); + if (nullptr != m_pCallbacks) + { + auto pEdict = reinterpret_cast(gpGlobals->pEdicts + (intp)client); + m_pCallbacks->OnCommand_ClientMeta(pEdict, &cmd); + } + RETURN_META(MRES_SUPERCEDE); }