Triggering build... again.
2 * vim: set ts=4 sw=4 tw=99 noet :
3 * ======================================================
5 * Copyright (C) 2004-2009 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.
27 #include "metamod_util.h"
28 #include <interface.h>
30 #include <iplayerinfo.h>
32 #include <loader_bridge.h>
33 #include "provider/provider_ep2.h"
35 #if SOURCE_ENGINE >= SE_ORANGEBOX
36 SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
38 SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
41 ConCommand *g_plugin_unload = NULL;
42 bool g_bIsTryingToUnload;
43 const char *vsp_desc = "Metamod:Source " MMS_FULL_VERSION;
45 #if SOURCE_ENGINE >= SE_ORANGEBOX
46 void InterceptPluginUnloads(const CCommand &args)
48 void InterceptPluginUnloads()
51 g_bIsTryingToUnload = true;
54 #if SOURCE_ENGINE >= SE_ORANGEBOX
55 void InterceptPluginUnloads_Post(const CCommand &args)
57 void InterceptPluginUnloads_Post()
60 g_bIsTryingToUnload = false;
63 class VspBridge : public IVspBridge
66 virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
68 if (!g_Metamod.IsLoadedAsGameDLL())
70 CGlobalVars *pGlobals;
71 IPlayerInfoManager *playerInfoManager;
73 playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
74 if (playerInfoManager == NULL)
76 UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
80 pGlobals = playerInfoManager->GetGlobalVars();
82 char gamedll_iface[] = "ServerGameDLL000";
83 for (unsigned int i = 3; i <= 50; i++)
85 gamedll_iface[15] = '0' + i;
86 if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
88 g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false);
95 UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
99 char gameclients_iface[] = "ServerGameClients000";
100 for (unsigned int i = 3; i <= 4; i++)
102 gameclients_iface[19] = '0' + i;
103 if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
107 if (!mm_DetectGameInformation())
109 UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
113 mm_InitializeForLoad();
114 mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
115 (CreateInterfaceFn)info->engineFactory,
116 (CreateInterfaceFn)info->engineFactory,
118 g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
119 mm_StartupMetamod(true);
123 vsp_desc = "Metamod:Source Interface " MMS_FULL_VERSION;
124 g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
127 #if SOURCE_ENGINE >= SE_ORANGEBOX
128 g_plugin_unload = icvar->FindCommand("plugin_unload");
130 const ConCommandBase *pBase = icvar->GetCommands();
131 while (pBase != NULL)
133 if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0)
135 g_plugin_unload = (ConCommand *)pBase;
138 pBase = pBase->GetNext();
142 if (g_plugin_unload != NULL)
144 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
145 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
151 virtual void Unload()
153 if (g_bIsTryingToUnload)
155 Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n");
158 if (g_plugin_unload != NULL)
160 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
161 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
162 g_plugin_unload = NULL;
164 if (!g_Metamod.IsLoadedAsGameDLL())
170 virtual const char *GetDescription()
176 VspBridge mm16_vsp_bridge;
181 return &mm16_vsp_bridge;