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@576: #include "metamod.h" ds@576: #include "metamod_util.h" ds@576: #include ds@576: #include ds@576: #include ds@576: #include ds@576: #include ds@576: #include "provider/provider_ep2.h" ds@576: ds@576: SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); ds@576: ds@576: ConCommand *g_plugin_unload = NULL; ds@576: bool g_bIsTryingToUnload; ds@576: ds@576: void InterceptPluginUnloads(const CCommand &args) ds@576: { ds@576: g_bIsTryingToUnload = true; ds@576: } ds@576: ds@576: void InterceptPluginUnloads_Post(const CCommand &args) ds@576: { ds@576: g_bIsTryingToUnload = false; ds@576: } ds@576: ds@576: class VspBridge : public IVspBridge ds@576: { ds@576: public: ds@576: virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength) ds@576: { ds@576: assert(!g_Metamod.IsLoadedAsGameDLL()); ds@576: ds@576: CGlobalVars *pGlobals; ds@576: IPlayerInfoManager *playerInfoManager; ds@576: ds@576: playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL); ds@576: if (playerInfoManager == NULL) ds@576: { ds@576: UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game"); ds@576: return false; ds@576: } ds@576: ds@576: pGlobals = playerInfoManager->GetGlobalVars(); ds@576: ds@576: char gamedll_iface[] = "ServerGameDLL000"; ds@576: for (unsigned int i = 5; i <= 50; i++) ds@576: { ds@576: gamedll_iface[15] = '0' + i; ds@576: if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL) ds@576: { dvander@589: g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false); ds@576: break; ds@576: } ds@576: } ds@576: ds@576: if (server == NULL) ds@576: { ds@576: UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible)."); ds@576: return false; ds@576: } ds@576: ds@576: char gameclients_iface[] = "ServerGameClients000"; ds@576: for (unsigned int i = 3; i <= 4; i++) ds@576: { ds@576: gameclients_iface[19] = '0' + i; ds@576: if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL) ds@576: break; ds@576: } ds@576: ds@576: if (!mm_DetectGameInformation()) ds@576: { ds@576: UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load."); ds@576: return false; ds@576: } ds@576: ds@576: mm_InitializeForLoad(); ds@576: mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory, ds@576: (CreateInterfaceFn)info->engineFactory, ds@576: (CreateInterfaceFn)info->engineFactory, ds@576: pGlobals); dvander@592: g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version); ds@576: mm_StartupMetamod(true); ds@576: ds@576: g_plugin_unload = icvar->FindCommand("plugin_unload"); ds@576: ds@576: if (g_plugin_unload != NULL) ds@576: { ds@576: SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); ds@576: SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); ds@576: } ds@576: ds@576: return true; ds@576: } ds@576: ds@576: virtual void Unload() ds@576: { 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@576: } ds@576: mm_UnloadMetamod(); ds@576: } ds@576: ds@576: virtual const char *GetDescription() ds@576: { ds@599: return "Metamod:Source " MMS_FULL_VERSION; ds@576: } ds@576: }; ds@576: ds@576: VspBridge mm16_vsp_bridge; ds@576: ds@576: SMM_API IVspBridge * ds@576: GetVspBridge() ds@576: { ds@576: return &mm16_vsp_bridge; ds@576: } ds@576: