From b070ac2f6bdf89729074ac8f64ff2c976bd432be Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Sat, 18 Feb 2017 10:23:59 -0500 Subject: [PATCH] [Dota] Fix for getting INetworkGameServer after factory removal. --- core/metamod.cpp | 40 +++++----------------------------- core/metamod_provider.h | 1 - core/provider/provider_ep2.cpp | 10 ++++++--- 3 files changed, 12 insertions(+), 39 deletions(-) diff --git a/core/metamod.cpp b/core/metamod.cpp index 4f85537..67679ba 100644 --- a/core/metamod.cpp +++ b/core/metamod.cpp @@ -55,23 +55,16 @@ using namespace SourceHook::Impl; // (we have class structure but it requires protobuf which we don't want to include here) class GameSessionConfiguration_t { }; -SH_DECL_MANUALHOOK4_void(SGD_StartupServer, 0, 0, 0, const GameSessionConfiguration_t &, INetworkGameServerFactory *, ISource2WorldSession *, const char *); +SH_DECL_MANUALHOOK3_void(SGD_StartupServer, 0, 0, 0, const GameSessionConfiguration_t &, ISource2WorldSession *, const char *); SH_DECL_MANUALHOOK2_void(SGD_Init, 0, 0, 0, GameSessionConfiguration_t *, const char *); SH_DECL_MANUALHOOK3(SGD_StartChangeLevel, 0, 0, 0, CUtlVector *, const char *, const char *, void *); SH_DECL_MANUALHOOK5_void(SGD_SwitchToLoop, 0, 0, 0, const char *, KeyValues *, uint32, const char *, bool); -SH_DECL_MANUALHOOK3(SGD_AllocateServer, 0, 0, 0, INetworkGameServer *, int, INetworkServerService *, ISource2WorldSession *); - -static INetworkGameServer * -Handler_AllocateServer(int, INetworkServerService *, ISource2WorldSession *); static void Handler_SwitchToLoop(const char *, KeyValues *, uint32, const char *, bool); static void -Handler_StartupServer(const GameSessionConfiguration_t &, INetworkGameServerFactory *, ISource2WorldSession *, const char *); - -static void -Handler_StartupServer_Post(const GameSessionConfiguration_t &, INetworkGameServerFactory *, ISource2WorldSession *, const char *); +Handler_StartupServer_Post(const GameSessionConfiguration_t &, ISource2WorldSession *, const char *); static void Handler_Init(GameSessionConfiguration_t *, const char *); @@ -199,7 +192,6 @@ mm_InitializeForLoad() provider->DisplayError("Metamod:Source could not find a valid hook for INetworkServerService::StartupServer"); } SH_MANUALHOOK_RECONFIGURE(SGD_StartupServer, info.vtblindex, info.vtbloffs, info.thisptroffs); - SH_ADD_MANUALHOOK(SGD_StartupServer, netservice, SH_STATIC(Handler_StartupServer), false); SH_ADD_MANUALHOOK(SGD_StartupServer, netservice, SH_STATIC(Handler_StartupServer_Post), true); if (!provider->GetHookInfo(ProvidedHook_SwitchToLoop, &info)) @@ -623,34 +615,12 @@ Handler_SwitchToLoop(const char *pszLoopName, KeyValues *pKV, uint32 nId, const } static void -Handler_StartupServer(const GameSessionConfiguration_t &config, INetworkGameServerFactory *pFactory, ISource2WorldSession *, const char *) -{ - SourceHook::MemFuncInfo info; - if (!provider->GetHookInfo(ProvidedHook_AllocateServer, &info)) - { - provider->DisplayError("Metamod:Source could not find a valid hook for INetworkGameServerFactory::Allocate"); - } - SH_MANUALHOOK_RECONFIGURE(SGD_AllocateServer, info.vtblindex, info.vtbloffs, info.thisptroffs); - SH_ADD_MANUALHOOK(SGD_AllocateServer, pFactory, SH_STATIC(Handler_AllocateServer), true); - - RETURN_META(MRES_IGNORED); -} - -static void -Handler_StartupServer_Post(const GameSessionConfiguration_t &config, INetworkGameServerFactory *pFactory, ISource2WorldSession *, const char *) -{ - SH_REMOVE_MANUALHOOK(SGD_AllocateServer, pFactory, SH_STATIC(Handler_AllocateServer), true); - - RETURN_META(MRES_IGNORED); -} - -static INetworkGameServer * -Handler_AllocateServer(int, INetworkServerService *, ISource2WorldSession *) +Handler_StartupServer_Post(const GameSessionConfiguration_t &config, ISource2WorldSession *, const char *) { static bool bGameServerHooked = false; if (!bGameServerHooked) { - INetworkGameServer *netserver = META_RESULT_ORIG_RET(INetworkGameServer *); + INetworkGameServer *netserver = (META_IFACEPTR(INetworkServerService))->GetIGameServer(); SourceHook::MemFuncInfo info; if (!provider->GetHookInfo(ProvidedHook_Init, &info)) @@ -670,7 +640,7 @@ Handler_AllocateServer(int, INetworkServerService *, ISource2WorldSession *) bGameServerHooked = true; } - RETURN_META_VALUE(MRES_IGNORED, nullptr); + RETURN_META(MRES_IGNORED); } static void diff --git a/core/metamod_provider.h b/core/metamod_provider.h index 408fd48..913d416 100644 --- a/core/metamod_provider.h +++ b/core/metamod_provider.h @@ -42,7 +42,6 @@ namespace SourceMM ProvidedHook_Init = 1, ProvidedHook_StartupServer = 2, ProvidedHook_SwitchToLoop = 3, - ProvidedHook_AllocateServer = 4, #else ProvidedHook_LevelInit = 0, /**< IServerGameDLL::LevelInit */ ProvidedHook_LevelShutdown = 1, /**< IServerGameDLL::LevelShutdown */ diff --git a/core/provider/provider_ep2.cpp b/core/provider/provider_ep2.cpp index 6ccdef3..d5ae7ee 100644 --- a/core/provider/provider_ep2.cpp +++ b/core/provider/provider_ep2.cpp @@ -221,6 +221,10 @@ void BaseProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, g_pCVar = icvar; #endif +#if SOURCE_ENGINE == SE_DOTA + ConVar_Register(0, &g_SMConVarAccessor); +#endif + g_SMConVarAccessor.RegisterConCommandBase(&meta_local_cmd); CacheUserMessages(); @@ -246,6 +250,9 @@ void BaseProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, void BaseProvider::Notify_DLLShutdown_Pre() { +#if SOURCE_ENGINE == SE_DOTA + ConVar_Unregister(); +#endif g_SMConVarAccessor.RemoveMetamodCommands(); @@ -365,9 +372,6 @@ bool BaseProvider::GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInf case ProvidedHook_SwitchToLoop: SourceHook::GetFuncInfo(&IEngineServiceMgr::SwitchToLoop, mfi); break; - case ProvidedHook_AllocateServer: - SourceHook::GetFuncInfo(&INetworkGameServerFactory::Allocate, mfi); - break; default: return false; }