Trigger build for hl2sdk-l4d changes.
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 <versionlib.h>
34 #include <sh_string.h>
35 #include "provider/provider_ep2.h"
37 #if SOURCE_ENGINE == SE_DOTA
38 SH_DECL_HOOK2_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommandContext &, const CCommand &);
39 #elif SOURCE_ENGINE >= SE_ORANGEBOX
40 SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
42 SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
45 ConCommand *g_plugin_unload = NULL;
46 bool g_bIsTryingToUnload;
47 SourceHook::String vsp_desc("Metamod:Source");
49 #if SOURCE_ENGINE == SE_DOTA
50 void InterceptPluginUnloads(const CCommandContext &context, const CCommand &args)
51 #elif SOURCE_ENGINE >= SE_ORANGEBOX
52 void InterceptPluginUnloads(const CCommand &args)
54 void InterceptPluginUnloads()
57 g_bIsTryingToUnload = true;
60 #if SOURCE_ENGINE == SE_DOTA
61 void InterceptPluginUnloads_Post(const CCommandContext &context, const CCommand &args)
62 #elif SOURCE_ENGINE >= SE_ORANGEBOX
63 void InterceptPluginUnloads_Post(const CCommand &args)
65 void InterceptPluginUnloads_Post()
68 g_bIsTryingToUnload = false;
71 class VspBridge : public IVspBridge
74 virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
76 if (!g_Metamod.IsLoadedAsGameDLL())
79 vsp_desc.append(METAMOD_VERSION);
81 CGlobalVars *pGlobals;
82 IPlayerInfoManager *playerInfoManager;
84 playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
85 if (playerInfoManager == NULL)
87 UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
91 pGlobals = playerInfoManager->GetGlobalVars();
93 char gamedll_iface[] = "ServerGameDLL000";
94 for (unsigned int i = 3; i <= 50; i++)
96 gamedll_iface[15] = '0' + i;
97 if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
99 g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false);
106 UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
110 char gameclients_iface[] = "ServerGameClients000";
111 for (unsigned int i = 3; i <= 4; i++)
113 gameclients_iface[19] = '0' + i;
114 if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
118 if (!mm_DetectGameInformation())
120 UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
124 mm_InitializeForLoad();
125 mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
126 (CreateInterfaceFn)info->engineFactory,
127 (CreateInterfaceFn)info->engineFactory,
129 g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
130 mm_StartupMetamod(true);
134 vsp_desc.append(" Interface ");
135 vsp_desc.append(METAMOD_VERSION);
137 g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
140 #if SOURCE_ENGINE >= SE_ORANGEBOX
141 g_plugin_unload = icvar->FindCommand("plugin_unload");
143 const ConCommandBase *pBase = icvar->GetCommands();
144 while (pBase != NULL)
146 if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0)
148 g_plugin_unload = (ConCommand *)pBase;
151 pBase = pBase->GetNext();
155 if (g_plugin_unload != NULL)
157 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
158 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
164 virtual void Unload()
166 if (g_bIsTryingToUnload)
168 Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n");
171 if (g_plugin_unload != NULL)
173 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
174 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
175 g_plugin_unload = NULL;
177 if (!g_Metamod.IsLoadedAsGameDLL())
183 virtual const char *GetDescription()
185 return vsp_desc.c_str();
189 VspBridge mm16_vsp_bridge;
194 return &mm16_vsp_bridge;