dvander@608: /** ds@683: * vim: set ts=4 sw=4 tw=99 noet : dvander@608: * ====================================================== dvander@608: * Metamod:Source ds@683: * Copyright (C) 2004-2009 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: dvander@589: #include dvander@589: #include "metamod.h" dvander@589: #include "metamod_plugins.h" dvander@589: #include "metamod_util.h" dvander@589: #include dvander@589: #include "provider/provider_ep2.h" dvander@589: dvander@589: using namespace SourceMM; dvander@589: dvander@589: class GameDllBridge : public IGameDllBridge dvander@589: { dvander@589: public: dvander@589: virtual bool DLLInit_Pre(const gamedll_bridge_info *info, char *buffer, size_t maxlength) dvander@589: { dvander@589: if (!mm_DetectGameInformation()) dvander@589: { dvander@589: UTIL_Format(buffer, maxlength, "Metamod:Source failed to detect game paths; cannot load."); dvander@589: return false; dvander@589: } dvander@589: dvander@589: server = (IServerGameDLL *)info->isgd; dvander@589: g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, dvander@589: info->dllVersion, dvander@589: true); ds@683: g_Metamod.SetVSPListener(info->vsp_listener_path); dvander@589: mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory, dvander@589: (CreateInterfaceFn)info->physicsFactory, dvander@589: (CreateInterfaceFn)info->fsFactory, dvander@589: (CGlobalVars*)info->pGlobals); dvander@589: mm_InitializeForLoad(); dvander@589: mm_StartupMetamod(false); dvander@589: dvander@589: return true; dvander@589: } dvander@589: virtual void DLLInit_Post(int *isgdUnload) dvander@589: { dvander@589: SourceHook::MemFuncInfo mfi; dvander@589: dvander@589: mfi.isVirtual = false; dvander@589: SourceHook::GetFuncInfo(&IServerGameDLL::DLLShutdown, mfi); dvander@589: assert(mfi.isVirtual); dvander@589: assert(mfi.vtbloffs == 0); dvander@589: assert(mfi.thisptroffs == 0); dvander@589: *isgdUnload = mfi.vtblindex; dvander@589: dvander@589: g_PluginMngr.SetAllLoaded(); dvander@589: } dvander@589: virtual void *QueryInterface(const char *iface, int *ret) dvander@589: { dvander@589: return g_Metamod.GetServerFactory(true)(iface, ret); dvander@589: } dvander@589: virtual void Unload() dvander@589: { dvander@589: mm_UnloadMetamod(); dvander@589: } dvander@589: }; dvander@589: dvander@589: GameDllBridge mm16_gamedll_bridge; dvander@589: dvander@589: SMM_API IGameDllBridge * dvander@589: GetGameDllBridge() dvander@589: { dvander@589: return &mm16_gamedll_bridge; dvander@589: } dvander@589: