core/gamedll_bridge.cpp
author Scott Ehlert <ds@alliedmods.net>
Mon Nov 24 07:25:46 2008 -0600 (2008-11-24)
changeset 601 bfbed17a3375
parent 589 8e97a1e960a5
child 608 30b546cc4e03
permissions -rw-r--r--
The 'meta refresh' command now handles plugins loaded via VDF files.
     1 #include <assert.h>
     2 #include "metamod.h"
     3 #include "metamod_plugins.h"
     4 #include "metamod_util.h"
     5 #include <loader_bridge.h>
     6 #include "provider/provider_ep2.h"
     7 
     8 using namespace SourceMM;
     9 
    10 class GameDllBridge : public IGameDllBridge
    11 {
    12 public:
    13 	virtual bool DLLInit_Pre(const gamedll_bridge_info *info, char *buffer, size_t maxlength)
    14 	{
    15 		if (!mm_DetectGameInformation())
    16 		{
    17 			UTIL_Format(buffer, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
    18 			return false;
    19 		}
    20 
    21 		server = (IServerGameDLL *)info->isgd;
    22 		g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory,
    23 								 info->dllVersion,
    24 								 true);
    25 		mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
    26 							 (CreateInterfaceFn)info->physicsFactory,
    27 							 (CreateInterfaceFn)info->fsFactory,
    28 							 (CGlobalVars*)info->pGlobals);
    29 		mm_InitializeForLoad();
    30 		mm_StartupMetamod(false);
    31 
    32 		return true;
    33 	}
    34 	virtual void DLLInit_Post(int *isgdUnload)
    35 	{
    36 		SourceHook::MemFuncInfo mfi;
    37 
    38 		mfi.isVirtual = false;
    39 		SourceHook::GetFuncInfo(&IServerGameDLL::DLLShutdown, mfi);
    40 		assert(mfi.isVirtual);
    41 		assert(mfi.vtbloffs == 0);
    42 		assert(mfi.thisptroffs == 0);
    43 		*isgdUnload = mfi.vtblindex;
    44 
    45 		g_PluginMngr.SetAllLoaded();
    46 	}
    47 	virtual void *QueryInterface(const char *iface, int *ret)
    48 	{
    49 		return g_Metamod.GetServerFactory(true)(iface, ret);
    50 	}
    51 	virtual void Unload()
    52 	{
    53 		mm_UnloadMetamod();
    54 	}
    55 };
    56 
    57 GameDllBridge mm16_gamedll_bridge;
    58 
    59 SMM_API IGameDllBridge *
    60 GetGameDllBridge()
    61 {
    62 	return &mm16_gamedll_bridge;
    63 }
    64