Remove ClientCommand Source 2 hacks from outside of provider

This commit is contained in:
Nick Hastings 2023-04-02 10:13:21 -04:00
parent ebf79cf73d
commit b727c5455e
6 changed files with 44 additions and 59 deletions

View File

@ -194,6 +194,11 @@ static class ProviderCallbacks : public IMetamodSourceProviderCallbacks
ITER_EVENT(OnLevelShutdown, ()); ITER_EVENT(OnLevelShutdown, ());
} }
virtual bool OnCommand_ClientMeta(edict_t* client, IMetamodSourceCommandInfo* info) override
{
return Command_ClientMeta(client, info);
}
} s_ProviderCallbacks; } s_ProviderCallbacks;
/* Initialize everything here */ /* Initialize everything here */
@ -740,20 +745,6 @@ size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
return mylen; 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, ...) void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
{ {
va_list ap; va_list ap;

View File

@ -44,11 +44,7 @@ using namespace SourceHook;
#define CLIENT_CONMSG g_Metamod.ClientConPrintf #define CLIENT_CONMSG g_Metamod.ClientConPrintf
template <typename ... Ts> template <typename ... Ts>
#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) void CMDMSG(edict_t *client, const char *pMsg, Ts ... ts)
#endif
{ {
if (client) 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) static void ReplyCredits(edict_t *client = nullptr)
#endif
{ {
CMDMSG(client, "Metamod:Source was developed by:\n"); CMDMSG(client, "Metamod:Source was developed by:\n");
CMDMSG(client, " SourceHook: Pavol \"PM OnoTo\" Marko\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"); 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) static void ReplyVersion(edict_t *client = nullptr)
#endif
{ {
CMDMSG(client, " Metamod:Source Version Information\n"); CMDMSG(client, " Metamod:Source Version Information\n");
CMDMSG(client, " Metamod:Source version %s\n", METAMOD_VERSION); CMDMSG(client, " Metamod:Source version %s\n", METAMOD_VERSION);
@ -654,11 +642,7 @@ bool Command_Meta(IMetamodSourceCommandInfo *info)
return true; return true;
} }
#if SOURCE_ENGINE == SE_DOTA
bool Command_ClientMeta(int client, IMetamodSourceCommandInfo *info)
#else
bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info) bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info)
#endif
{ {
const char *cmd = info->GetArg(0); const char *cmd = info->GetArg(0);

View File

@ -31,10 +31,6 @@
#include "metamod_provider.h" #include "metamod_provider.h"
bool Command_Meta(IMetamodSourceCommandInfo *info); 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); bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info);
#endif
#endif //_INCLUDE_CONCOMMANDS_H #endif //_INCLUDE_CONCOMMANDS_H

View File

@ -51,29 +51,6 @@ namespace SourceMM
#endif #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 * @brief Abstracts command information, since the new engine fixes the
* re-entrancy problems in the tokenization system. * re-entrancy problems in the tokenization system.
@ -105,6 +82,34 @@ namespace SourceMM
virtual const char *GetArgString() =0; 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 class IMetamodSourceProvider
{ {
public: public:

View File

@ -631,7 +631,11 @@ void SourceProvider::Hook_ClientCommand(edict_t * client)
#endif #endif
if (strcmp(cmd.GetArg(0), "meta") == 0) 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); RETURN_META(MRES_SUPERCEDE);
} }

View File

@ -431,7 +431,12 @@ void Source2Provider::Hook_ClientCommand(CEntityIndex index, const CCommand& _cm
if (strcmp(cmd.GetArg(0), "meta") == 0) if (strcmp(cmd.GetArg(0), "meta") == 0)
{ {
Command_ClientMeta(client, &cmd); if (nullptr != m_pCallbacks)
{
auto pEdict = reinterpret_cast<edict_t *>(gpGlobals->pEdicts + (intp)client);
m_pCallbacks->OnCommand_ClientMeta(pEdict, &cmd);
}
RETURN_META(MRES_SUPERCEDE); RETURN_META(MRES_SUPERCEDE);
} }