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.
28 #include "concommands.h"
30 #include <loader_bridge.h>
31 #include <sh_string.h>
32 #include <versionlib.h>
34 SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
36 ConCommand *g_plugin_unload = NULL;
37 bool g_bIsTryingToUnload;
38 bool g_bIsBridgedAsVsp;
39 SourceHook::String vsp_desc("Metamod:Source");
41 void InterceptPluginUnloads()
43 g_bIsTryingToUnload = true;
46 void InterceptPluginUnloads_Post()
48 g_bIsTryingToUnload = false;
51 class VspBridge : public IVspBridge
53 virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
55 assert(!g_bIsBridgedAsVsp);
57 if (!g_GameDll.loaded)
60 vsp_desc.append(METAMOD_VERSION);
62 CreateInterfaceFn engineFactory = (CreateInterfaceFn)info->engineFactory;
63 CreateInterfaceFn gsFactory = (CreateInterfaceFn)info->gsFactory;
65 if (!AlternatelyLoadMetamod(engineFactory, gsFactory))
68 extern ConVar metamod_version;
71 UTIL_Format(buffer, sizeof(buffer), "%sV", metamod_version.GetString());
72 metamod_version.SetValue(buffer);
76 vsp_desc.append(" Interface ");
77 vsp_desc.append(METAMOD_VERSION);
80 ConCommandBase *pBase = g_Engine.icvar->GetCommands();
83 if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0)
85 g_plugin_unload = (ConCommand *)pBase;
88 pBase = const_cast<ConCommandBase *>(pBase->GetNext());
91 if (g_plugin_unload != NULL)
93 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
94 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
97 g_bIsBridgedAsVsp = true;
98 g_pRealVspCallbacks = info->vsp_callbacks;
99 g_vsp_version = info->vsp_version;
101 g_PluginMngr.SetVSPAsLoaded();
106 virtual void Unload()
108 if (g_bIsTryingToUnload)
110 Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n");
113 if (g_plugin_unload != NULL)
115 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
116 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
117 g_plugin_unload = NULL;
119 if (!g_GameDll.loaded)
121 g_SMConVarAccessor.UnloadMetamodCommands();
122 UnloadMetamod(false);
126 virtual const char *GetDescription()
128 return vsp_desc.c_str();
132 VspBridge mm14_vsp_bridge;
137 return &mm14_vsp_bridge;