core/gamedll_bridge.cpp
author Scott Ehlert <ds@alliedmods.net>
Sat Nov 14 00:49:35 2009 -0600 (2009-11-14)
changeset 680 39d0803bdb6e
parent 608 30b546cc4e03
child 683 b507295429f9
permissions -rw-r--r--
Fixed issue with vsnprintf macro being defined under MSVC 9/2008 (bug 3887, r=dvander).
     1 /**
     2  * vim: set ts=4 :
     3  * ======================================================
     4  * Metamod:Source
     5  * Copyright (C) 2004-2008 AlliedModders LLC and authors.
     6  * All rights reserved.
     7  * ======================================================
     8  *
     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.
    12  * 
    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:
    16  *
    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.
    24  *
    25  * Version: $Id$
    26  */
    27 
    28 #include <assert.h>
    29 #include "metamod.h"
    30 #include "metamod_plugins.h"
    31 #include "metamod_util.h"
    32 #include <loader_bridge.h>
    33 #include "provider/provider_ep2.h"
    34 
    35 using namespace SourceMM;
    36 
    37 class GameDllBridge : public IGameDllBridge
    38 {
    39 public:
    40 	virtual bool DLLInit_Pre(const gamedll_bridge_info *info, char *buffer, size_t maxlength)
    41 	{
    42 		if (!mm_DetectGameInformation())
    43 		{
    44 			UTIL_Format(buffer, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
    45 			return false;
    46 		}
    47 
    48 		server = (IServerGameDLL *)info->isgd;
    49 		g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory,
    50 								 info->dllVersion,
    51 								 true);
    52 		mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
    53 							 (CreateInterfaceFn)info->physicsFactory,
    54 							 (CreateInterfaceFn)info->fsFactory,
    55 							 (CGlobalVars*)info->pGlobals);
    56 		mm_InitializeForLoad();
    57 		mm_StartupMetamod(false);
    58 
    59 		return true;
    60 	}
    61 	virtual void DLLInit_Post(int *isgdUnload)
    62 	{
    63 		SourceHook::MemFuncInfo mfi;
    64 
    65 		mfi.isVirtual = false;
    66 		SourceHook::GetFuncInfo(&IServerGameDLL::DLLShutdown, mfi);
    67 		assert(mfi.isVirtual);
    68 		assert(mfi.vtbloffs == 0);
    69 		assert(mfi.thisptroffs == 0);
    70 		*isgdUnload = mfi.vtblindex;
    71 
    72 		g_PluginMngr.SetAllLoaded();
    73 	}
    74 	virtual void *QueryInterface(const char *iface, int *ret)
    75 	{
    76 		return g_Metamod.GetServerFactory(true)(iface, ret);
    77 	}
    78 	virtual void Unload()
    79 	{
    80 		mm_UnloadMetamod();
    81 	}
    82 };
    83 
    84 GameDllBridge mm16_gamedll_bridge;
    85 
    86 SMM_API IGameDllBridge *
    87 GetGameDllBridge()
    88 {
    89 	return &mm16_gamedll_bridge;
    90 }
    91