Fix provider reaching calling directly outside for "meta" ConCommand

This commit is contained in:
Nick Hastings 2023-04-02 12:08:28 -04:00
parent 15c84495cb
commit acd8644688
6 changed files with 38 additions and 18 deletions

View File

@ -195,6 +195,11 @@ static class ProviderCallbacks : public IMetamodSourceProviderCallbacks
ITER_EVENT(OnLevelShutdown, ()); ITER_EVENT(OnLevelShutdown, ());
} }
virtual bool OnCommand_Meta(IMetamodSourceCommandInfo* info) override
{
return Command_Meta(info);
}
virtual bool OnCommand_ClientMeta(edict_t* client, IMetamodSourceCommandInfo* info) override virtual bool OnCommand_ClientMeta(edict_t* client, IMetamodSourceCommandInfo* info) override
{ {
return Command_ClientMeta(client, info); return Command_ClientMeta(client, info);

View File

@ -90,6 +90,11 @@ namespace SourceMM
*/ */
virtual void OnLevelShutdown() = 0; virtual void OnLevelShutdown() = 0;
/**
* @brief Called when the ConCommand "meta" is executed
*/
virtual bool OnCommand_Meta(IMetamodSourceCommandInfo* info) = 0;
/** /**
* @brief Called when a client executes "meta" as a ClientCommand * @brief Called when a client executes "meta" as a ClientCommand
*/ */

View File

@ -30,14 +30,12 @@
#include <KeyValues.h> #include <KeyValues.h>
#include <filesystem.h> #include <filesystem.h>
#if SOURCE_ENGINE >= SE_ORANGEBOX
void LocalCommand_Meta(const CCommand& args);
#else
void LocalCommand_Meta();
#endif
ConCommand meta_local_cmd("meta", LocalCommand_Meta, "Metamod:Source control options"); ConCommand meta_local_cmd("meta", LocalCommand_Meta, "Metamod:Source control options");
static SourceProvider g_SourceProvider;
IMetamodSourceProvider* provider = &g_SourceProvider;
SH_DECL_HOOK0(IServerGameDLL, GameInit, SH_NOATTRIB, 0, bool); SH_DECL_HOOK0(IServerGameDLL, GameInit, SH_NOATTRIB, 0, bool);
SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, 0, bool, const char*, const char*, const char*, const char*, bool, bool); SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, 0, bool, const char*, const char*, const char*, const char*, bool, bool);
SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, 0); SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, 0);
@ -466,7 +464,12 @@ void LocalCommand_Meta()
{ {
GlobCommand cmd; GlobCommand cmd;
#endif #endif
Command_Meta(&cmd);
if (nullptr != g_SourceProvider.m_pCallbacks)
{
GlobCommand cmd(&args);
g_SourceProvider.m_pCallbacks->OnCommand_Meta(&cmd);
}
} }
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
@ -661,7 +664,3 @@ void SourceProvider::Hook_ClientCommand(edict_t * client)
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
static SourceProvider g_SourceProvider;
IMetamodSourceProvider* provider = &g_SourceProvider;

View File

@ -115,6 +115,12 @@ private:
IFileSystem* baseFs = nullptr; IFileSystem* baseFs = nullptr;
std::vector<UsrMsgInfo> usermsgs_list; std::vector<UsrMsgInfo> usermsgs_list;
bool bOriginalEngine = false; bool bOriginalEngine = false;
#if SOURCE_ENGINE >= SE_ORANGEBOX
friend void LocalCommand_Meta(const CCommand& args);
#else
friend void LocalCommand_Meta();
#endif
}; };
#endif #endif

View File

@ -33,7 +33,11 @@
#include <filesystem.h> #include <filesystem.h>
#include <iserver.h> #include <iserver.h>
void LocalCommand_Meta(const CCommand& args);
static Source2Provider g_Source2Provider;
IMetamodSourceProvider* provider = &g_Source2Provider;
ConCommand meta_local_cmd("meta", LocalCommand_Meta, "Metamod:Source control options"); ConCommand meta_local_cmd("meta", LocalCommand_Meta, "Metamod:Source control options");
@ -346,8 +350,11 @@ private:
void LocalCommand_Meta(const CCommand& args) void LocalCommand_Meta(const CCommand& args)
{ {
GlobCommand cmd(&args); if (nullptr != g_Source2Provider.m_pCallbacks)
Command_Meta(&cmd); {
GlobCommand cmd(&args);
g_Source2Provider.m_pCallbacks->OnCommand_Meta(&cmd);
}
} }
bool Source2Provider::KVLoadFromFile(KeyValues* kv, IFileSystem* filesystem, const char* resourceName, const char* pathID) bool Source2Provider::KVLoadFromFile(KeyValues* kv, IFileSystem* filesystem, const char* resourceName, const char* pathID)
@ -447,7 +454,3 @@ void Source2Provider::Hook_ClientCommand(CEntityIndex index, const CCommand& _cm
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
static Source2Provider g_Source2Provider;
IMetamodSourceProvider* provider = &g_Source2Provider;

View File

@ -77,6 +77,8 @@ private:
private: private:
IFileSystem* baseFs = nullptr; IFileSystem* baseFs = nullptr;
std::string sLastMap; std::string sLastMap;
friend void LocalCommand_Meta(const CCommand& args);
}; };
#endif #endif