Added support for Dark Messiah engine and game. (no bug, r=me).
The development of this feature would not be possible without the support of the following people from the game's community:
Dylan Riggs, Carl Pettengill, Ed Moreland, and Christian.
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 #if SOURCE_ENGINE >= SE_ORANGEBOX
38 SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
40 SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
43 ConCommand *g_plugin_unload = NULL;
44 bool g_bIsTryingToUnload;
46 #if SOURCE_ENGINE >= SE_ORANGEBOX
47 void InterceptPluginUnloads(const CCommand &args)
49 void InterceptPluginUnloads()
52 g_bIsTryingToUnload = true;
55 #if SOURCE_ENGINE >= SE_ORANGEBOX
56 void InterceptPluginUnloads_Post(const CCommand &args)
58 void InterceptPluginUnloads_Post()
61 g_bIsTryingToUnload = false;
64 class VspBridge : public IVspBridge
67 virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
69 assert(!g_Metamod.IsLoadedAsGameDLL());
71 CGlobalVars *pGlobals;
72 IPlayerInfoManager *playerInfoManager;
74 playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
75 if (playerInfoManager == NULL)
77 UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
81 pGlobals = playerInfoManager->GetGlobalVars();
83 char gamedll_iface[] = "ServerGameDLL000";
84 for (unsigned int i = 3; i <= 50; i++)
86 gamedll_iface[15] = '0' + i;
87 if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
89 g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false);
96 UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
100 char gameclients_iface[] = "ServerGameClients000";
101 for (unsigned int i = 3; i <= 4; i++)
103 gameclients_iface[19] = '0' + i;
104 if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
108 if (!mm_DetectGameInformation())
110 UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
114 mm_InitializeForLoad();
115 mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
116 (CreateInterfaceFn)info->engineFactory,
117 (CreateInterfaceFn)info->engineFactory,
119 g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
120 mm_StartupMetamod(true);
122 #if SOURCE_ENGINE >= SE_ORANGEBOX
123 g_plugin_unload = icvar->FindCommand("plugin_unload");
125 const ConCommandBase *pBase = icvar->GetCommands();
126 while (pBase != NULL)
128 if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0)
130 g_plugin_unload = (ConCommand *)pBase;
133 pBase = pBase->GetNext();
137 if (g_plugin_unload != NULL)
139 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
140 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
146 virtual void Unload()
148 if (g_bIsTryingToUnload)
150 Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n");
153 if (g_plugin_unload != NULL)
155 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
156 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
157 g_plugin_unload = NULL;
162 virtual const char *GetDescription()
164 return "Metamod:Source " MMS_FULL_VERSION;
168 VspBridge mm16_vsp_bridge;
173 return &mm16_vsp_bridge;