dvander@608: /** dvander@608: * vim: set ts=4 : dvander@608: * ====================================================== dvander@608: * Metamod:Source dvander@608: * Copyright (C) 2004-2008 AlliedModders LLC and authors. dvander@608: * All rights reserved. dvander@608: * ====================================================== dvander@608: * dvander@608: * This software is provided 'as-is', without any express or implied warranty. dvander@608: * In no event will the authors be held liable for any damages arising from dvander@608: * the use of this software. dvander@608: * dvander@608: * Permission is granted to anyone to use this software for any purpose, dvander@608: * including commercial applications, and to alter it and redistribute it dvander@608: * freely, subject to the following restrictions: dvander@608: * dvander@608: * 1. The origin of this software must not be misrepresented; you must not dvander@608: * claim that you wrote the original software. If you use this software in a dvander@608: * product, an acknowledgment in the product documentation would be dvander@608: * appreciated but is not required. dvander@608: * 2. Altered source versions must be plainly marked as such, and must not be dvander@608: * misrepresented as being the original software. dvander@608: * 3. This notice may not be removed or altered from any source distribution. dvander@608: * dvander@608: * Version: $Id$ dvander@608: */ dvander@608: ds@599: #include ds@599: #include "sourcemm.h" ds@599: #include "concommands.h" ds@599: #include ds@599: ds@599: SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false); ds@599: ds@599: ConCommand *g_plugin_unload = NULL; ds@599: bool g_bIsTryingToUnload; ds@599: bool g_bIsBridgedAsVsp; ds@599: ds@599: void InterceptPluginUnloads() ds@599: { ds@599: g_bIsTryingToUnload = true; ds@599: } ds@599: ds@599: void InterceptPluginUnloads_Post() ds@599: { ds@599: g_bIsTryingToUnload = false; ds@599: } ds@599: ds@599: class VspBridge : public IVspBridge ds@599: { ds@599: virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength) ds@599: { ds@599: assert(!g_GameDll.loaded && !g_bIsBridgedAsVsp); ds@599: ds@599: CreateInterfaceFn engineFactory = (CreateInterfaceFn)info->engineFactory; ds@599: CreateInterfaceFn gsFactory = (CreateInterfaceFn)info->gsFactory; ds@599: ds@599: if (!AlternatelyLoadMetamod(engineFactory, gsFactory)) ds@599: return false; ds@599: ds@599: ConCommandBase *pBase = g_Engine.icvar->GetCommands(); ds@599: while (pBase != NULL) ds@599: { ds@599: if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0) ds@599: { ds@599: g_plugin_unload = (ConCommand *)pBase; ds@599: break; ds@599: } ds@599: pBase = const_cast(pBase->GetNext()); ds@599: } ds@599: ds@599: if (g_plugin_unload != NULL) ds@599: { ds@599: SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); ds@599: SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); ds@599: } ds@599: ds@599: extern ConVar metamod_version; ds@599: char buffer[255]; ds@599: ds@599: UTIL_Format(buffer, sizeof(buffer), "%sV", metamod_version.GetString()); ds@599: metamod_version.SetValue(buffer); ds@599: ds@599: g_bIsBridgedAsVsp = true; ds@599: g_pRealVspCallbacks = info->vsp_callbacks; ds@599: ds@599: g_PluginMngr.SetVSPAsLoaded(); ds@599: ds@599: return true; ds@599: } ds@599: ds@599: virtual void Unload() ds@599: { ds@576: if (g_bIsTryingToUnload) ds@576: { ds@576: Error("Metamod:Source cannot be unloaded from VSP mode. Use \"meta unload\" to unload specific plugins.\n"); ds@576: return; ds@576: } ds@576: if (g_plugin_unload != NULL) ds@576: { ds@576: SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); ds@576: SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); ds@576: g_plugin_unload = NULL; ds@599: } ds@599: g_SMConVarAccessor.UnloadMetamodCommands(); ds@599: UnloadMetamod(false); ds@599: } ds@599: ds@599: virtual const char *GetDescription() ds@599: { ds@599: return "Metamod:Source " MMS_FULL_VERSION; ds@599: } ds@599: }; ds@599: ds@599: VspBridge mm14_vsp_bridge; ds@599: ds@599: SMM_API IVspBridge * ds@599: GetVspBridge() ds@599: { ds@599: return &mm14_vsp_bridge; ds@599: }