Updated changelog, added license headers.
3 * ======================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC and authors.
7 * ======================================================
9 * This software is provided 'as-is', without any express or implied warranty.
10 * In no event will the authors be held liable for any damages arising from
11 * the use of this software.
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software in a
19 * product, an acknowledgment in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
29 #include "metamod_util.h"
30 #include <interface.h>
32 #include <iplayerinfo.h>
34 #include <loader_bridge.h>
35 #include "provider/provider_ep2.h"
37 SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
39 ConCommand *g_plugin_unload = NULL;
40 bool g_bIsTryingToUnload;
42 void InterceptPluginUnloads(const CCommand &args)
44 g_bIsTryingToUnload = true;
47 void InterceptPluginUnloads_Post(const CCommand &args)
49 g_bIsTryingToUnload = false;
52 class VspBridge : public IVspBridge
55 virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
57 assert(!g_Metamod.IsLoadedAsGameDLL());
59 CGlobalVars *pGlobals;
60 IPlayerInfoManager *playerInfoManager;
62 playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
63 if (playerInfoManager == NULL)
65 UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
69 pGlobals = playerInfoManager->GetGlobalVars();
71 char gamedll_iface[] = "ServerGameDLL000";
72 for (unsigned int i = 5; i <= 50; i++)
74 gamedll_iface[15] = '0' + i;
75 if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
77 g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false);
84 UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
88 char gameclients_iface[] = "ServerGameClients000";
89 for (unsigned int i = 3; i <= 4; i++)
91 gameclients_iface[19] = '0' + i;
92 if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
96 if (!mm_DetectGameInformation())
98 UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
102 mm_InitializeForLoad();
103 mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
104 (CreateInterfaceFn)info->engineFactory,
105 (CreateInterfaceFn)info->engineFactory,
107 g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
108 mm_StartupMetamod(true);
110 g_plugin_unload = icvar->FindCommand("plugin_unload");
112 if (g_plugin_unload != NULL)
114 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
115 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
121 virtual void Unload()
123 if (g_bIsTryingToUnload)
125 Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n");
128 if (g_plugin_unload != NULL)
130 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
131 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
132 g_plugin_unload = NULL;
137 virtual const char *GetDescription()
139 return "Metamod:Source " MMS_FULL_VERSION;
143 VspBridge mm16_vsp_bridge;
148 return &mm16_vsp_bridge;