Backported GetVSPInfo from new API to legacy API (
bug 4079, r=ds).
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.
30 #include "concommands.h"
32 #include <loader_bridge.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;
40 void InterceptPluginUnloads()
42 g_bIsTryingToUnload = true;
45 void InterceptPluginUnloads_Post()
47 g_bIsTryingToUnload = false;
50 class VspBridge : public IVspBridge
52 virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
54 assert(!g_GameDll.loaded && !g_bIsBridgedAsVsp);
56 CreateInterfaceFn engineFactory = (CreateInterfaceFn)info->engineFactory;
57 CreateInterfaceFn gsFactory = (CreateInterfaceFn)info->gsFactory;
59 if (!AlternatelyLoadMetamod(engineFactory, gsFactory))
62 ConCommandBase *pBase = g_Engine.icvar->GetCommands();
65 if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0)
67 g_plugin_unload = (ConCommand *)pBase;
70 pBase = const_cast<ConCommandBase *>(pBase->GetNext());
73 if (g_plugin_unload != NULL)
75 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
76 SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
79 extern ConVar metamod_version;
82 UTIL_Format(buffer, sizeof(buffer), "%sV", metamod_version.GetString());
83 metamod_version.SetValue(buffer);
85 g_bIsBridgedAsVsp = true;
86 g_pRealVspCallbacks = info->vsp_callbacks;
87 g_vsp_version = info->vsp_version;
89 g_PluginMngr.SetVSPAsLoaded();
96 if (g_bIsTryingToUnload)
98 Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n");
101 if (g_plugin_unload != NULL)
103 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
104 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
105 g_plugin_unload = NULL;
107 g_SMConVarAccessor.UnloadMetamodCommands();
108 UnloadMetamod(false);
111 virtual const char *GetDescription()
113 return "Metamod:Source " MMS_FULL_VERSION;
117 VspBridge mm14_vsp_bridge;
122 return &mm14_vsp_bridge;