Added gamedll bridging to ep2/l4d provider (
bug 3412).
2 #include "metamod_util.h"
5 #include <iplayerinfo.h>
7 #include <loader_bridge.h>
8 #include "provider/provider_ep2.h"
10 SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
12 ConCommand *g_plugin_unload = NULL;
13 bool g_bIsTryingToUnload;
15 void InterceptPluginUnloads(const CCommand &args)
17 g_bIsTryingToUnload = true;
20 void InterceptPluginUnloads_Post(const CCommand &args)
22 g_bIsTryingToUnload = false;
25 class VspBridge : public IVspBridge
28 virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
30 assert(!g_Metamod.IsLoadedAsGameDLL());
32 CGlobalVars *pGlobals;
33 IPlayerInfoManager *playerInfoManager;
35 playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
36 if (playerInfoManager == NULL)
38 UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
42 pGlobals = playerInfoManager->GetGlobalVars();
44 char gamedll_iface[] = "ServerGameDLL000";
45 for (unsigned int i = 5; i <= 50; i++)
47 gamedll_iface[15] = '0' + i;
48 if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
50 g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false);
57 UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
61 char gameclients_iface[] = "ServerGameClients000";
62 for (unsigned int i = 3; i <= 4; i++)
64 gameclients_iface[19] = '0' + i;
65 if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
69 if (!mm_DetectGameInformation())
71 UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
75 mm_InitializeForLoad();
76 mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
77 (CreateInterfaceFn)info->engineFactory,
78 (CreateInterfaceFn)info->engineFactory,
80 mm_StartupMetamod(true);
82 g_plugin_unload = icvar->FindCommand("plugin_unload");
84 if (g_plugin_unload != NULL)
86 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
87 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
95 if (g_bIsTryingToUnload)
97 Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n");
100 if (g_plugin_unload != NULL)
102 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
103 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
104 g_plugin_unload = NULL;
109 virtual const char *GetDescription()
111 return "Metamod:Source " SVN_FULL_VERSION;
115 VspBridge mm16_vsp_bridge;
120 return &mm16_vsp_bridge;