Push build.
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>
32 SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
34 ConCommand *g_plugin_unload = NULL;
35 bool g_bIsTryingToUnload;
36 bool g_bIsBridgedAsVsp;
37 const char *vsp_desc = "Metamod:Source " MMS_FULL_VERSION;
39 void InterceptPluginUnloads()
41 g_bIsTryingToUnload = true;
44 void InterceptPluginUnloads_Post()
46 g_bIsTryingToUnload = false;
49 class VspBridge : public IVspBridge
51 virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
53 assert(!g_bIsBridgedAsVsp);
55 if (!g_GameDll.loaded)
57 CreateInterfaceFn engineFactory = (CreateInterfaceFn)info->engineFactory;
58 CreateInterfaceFn gsFactory = (CreateInterfaceFn)info->gsFactory;
60 if (!AlternatelyLoadMetamod(engineFactory, gsFactory))
63 extern ConVar metamod_version;
66 UTIL_Format(buffer, sizeof(buffer), "%sV", metamod_version.GetString());
67 metamod_version.SetValue(buffer);
71 vsp_desc = "Metamod:Source Interface " MMS_FULL_VERSION;
74 ConCommandBase *pBase = g_Engine.icvar->GetCommands();
77 if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0)
79 g_plugin_unload = (ConCommand *)pBase;
82 pBase = const_cast<ConCommandBase *>(pBase->GetNext());
85 if (g_plugin_unload != NULL)
87 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
88 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
91 g_bIsBridgedAsVsp = true;
92 g_pRealVspCallbacks = info->vsp_callbacks;
93 g_vsp_version = info->vsp_version;
95 g_PluginMngr.SetVSPAsLoaded();
100 virtual void Unload()
102 if (g_bIsTryingToUnload)
104 Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n");
107 if (g_plugin_unload != NULL)
109 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
110 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
111 g_plugin_unload = NULL;
113 if (!g_GameDll.loaded)
115 g_SMConVarAccessor.UnloadMetamodCommands();
116 UnloadMetamod(false);
120 virtual const char *GetDescription()
126 VspBridge mm14_vsp_bridge;
131 return &mm14_vsp_bridge;