core/vsp_bridge.cpp
changeset 556 b37a142ba881
child 558 0ed2a4a6e31d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/vsp_bridge.cpp	Sun Nov 16 22:33:16 2008 -0600
     1.3 @@ -0,0 +1,110 @@
     1.4 +#include "metamod.h"
     1.5 +#include "metamod_util.h"
     1.6 +#include <interface.h>
     1.7 +#include <eiface.h>
     1.8 +#include <iplayerinfo.h>
     1.9 +#include <assert.h>
    1.10 +#include <loader_bridge.h>
    1.11 +#include "provider/provider_ep2.h"
    1.12 +
    1.13 +SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
    1.14 +
    1.15 +ConCommand *g_plugin_unload = NULL;
    1.16 +bool g_bIsTryingToUnload;
    1.17 +
    1.18 +void InterceptPluginUnloads(const CCommand &args)
    1.19 +{
    1.20 +	g_bIsTryingToUnload = true;
    1.21 +}
    1.22 +
    1.23 +void InterceptPluginUnloads_Post(const CCommand &args)
    1.24 +{
    1.25 +	g_bIsTryingToUnload = false;
    1.26 +}
    1.27 +
    1.28 +class VspBridge : public IVspBridge
    1.29 +{
    1.30 +public:
    1.31 +	virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
    1.32 +	{
    1.33 +		assert(!g_Metamod.IsLoadedAsGameDLL());
    1.34 +
    1.35 +		CGlobalVars *pGlobals;
    1.36 +		IPlayerInfoManager *playerInfoManager;
    1.37 +
    1.38 +		playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
    1.39 +		if (playerInfoManager == NULL)
    1.40 +		{
    1.41 +			UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
    1.42 +			return false;
    1.43 +		}
    1.44 +
    1.45 +		pGlobals = playerInfoManager->GetGlobalVars();
    1.46 +
    1.47 +		char gamedll_iface[] = "ServerGameDLL000";
    1.48 +		for (unsigned int i = 5; i <= 50; i++)
    1.49 +		{
    1.50 +			gamedll_iface[15] = '0' + i;
    1.51 +			if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
    1.52 +			{
    1.53 +				g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i);
    1.54 +				break;
    1.55 +			}
    1.56 +		}
    1.57 +
    1.58 +		if (server == NULL)
    1.59 +		{
    1.60 +			UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
    1.61 +			return false;
    1.62 +		}
    1.63 +
    1.64 +		char gameclients_iface[] = "ServerGameClients000";
    1.65 +		for (unsigned int i = 3; i <= 4; i++)
    1.66 +		{
    1.67 +			gameclients_iface[19] = '0' + i;
    1.68 +			if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
    1.69 +				break;
    1.70 +		}
    1.71 +
    1.72 +		if (!mm_DetectGameInformation())
    1.73 +		{
    1.74 +			UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
    1.75 +			return false;
    1.76 +		}
    1.77 +
    1.78 +		mm_InitializeForLoad();
    1.79 +		mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
    1.80 +							 (CreateInterfaceFn)info->engineFactory,
    1.81 +							 (CreateInterfaceFn)info->engineFactory,
    1.82 +							 pGlobals);
    1.83 +		mm_StartupMetamod(true);
    1.84 +		
    1.85 +		g_plugin_unload = icvar->FindCommand("plugin_unload");
    1.86 +
    1.87 +		if (g_plugin_unload != NULL)
    1.88 +		{
    1.89 +			SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
    1.90 +			SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
    1.91 +		}
    1.92 +
    1.93 +		return true;
    1.94 +	}
    1.95 +
    1.96 +	virtual void Unload()
    1.97 +	{
    1.98 +	}
    1.99 +
   1.100 +	virtual const char *GetDescription()
   1.101 +	{
   1.102 +		return "Metamod:Source " SOURCEMM_VERSION;
   1.103 +	}
   1.104 +};
   1.105 +
   1.106 +VspBridge mm16_vsp_bridge;
   1.107 +
   1.108 +SMM_API IVspBridge *
   1.109 +GetVspBridge()
   1.110 +{
   1.111 +	return &mm16_vsp_bridge;
   1.112 +}
   1.113 +