core/vsp_bridge.cpp
changeset 576 fc3600fed257
parent 558 0ed2a4a6e31d
child 589 8e97a1e960a5
     1.1 --- a/core/vsp_bridge.cpp	Tue Nov 18 05:23:58 2008 -0600
     1.2 +++ b/core/vsp_bridge.cpp	Tue Nov 18 07:20:38 2008 -0600
     1.3 @@ -1,110 +1,122 @@
     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 " SVN_FULL_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 -
   1.114 +#include "metamod.h"
   1.115 +#include "metamod_util.h"
   1.116 +#include <interface.h>
   1.117 +#include <eiface.h>
   1.118 +#include <iplayerinfo.h>
   1.119 +#include <assert.h>
   1.120 +#include <loader_bridge.h>
   1.121 +#include "provider/provider_ep2.h"
   1.122 +
   1.123 +SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
   1.124 +
   1.125 +ConCommand *g_plugin_unload = NULL;
   1.126 +bool g_bIsTryingToUnload;
   1.127 +
   1.128 +void InterceptPluginUnloads(const CCommand &args)
   1.129 +{
   1.130 +	g_bIsTryingToUnload = true;
   1.131 +}
   1.132 +
   1.133 +void InterceptPluginUnloads_Post(const CCommand &args)
   1.134 +{
   1.135 +	g_bIsTryingToUnload = false;
   1.136 +}
   1.137 +
   1.138 +class VspBridge : public IVspBridge
   1.139 +{
   1.140 +public:
   1.141 +	virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
   1.142 +	{
   1.143 +		assert(!g_Metamod.IsLoadedAsGameDLL());
   1.144 +
   1.145 +		CGlobalVars *pGlobals;
   1.146 +		IPlayerInfoManager *playerInfoManager;
   1.147 +
   1.148 +		playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
   1.149 +		if (playerInfoManager == NULL)
   1.150 +		{
   1.151 +			UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
   1.152 +			return false;
   1.153 +		}
   1.154 +
   1.155 +		pGlobals = playerInfoManager->GetGlobalVars();
   1.156 +
   1.157 +		char gamedll_iface[] = "ServerGameDLL000";
   1.158 +		for (unsigned int i = 5; i <= 50; i++)
   1.159 +		{
   1.160 +			gamedll_iface[15] = '0' + i;
   1.161 +			if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
   1.162 +			{
   1.163 +				g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i);
   1.164 +				break;
   1.165 +			}
   1.166 +		}
   1.167 +
   1.168 +		if (server == NULL)
   1.169 +		{
   1.170 +			UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
   1.171 +			return false;
   1.172 +		}
   1.173 +
   1.174 +		char gameclients_iface[] = "ServerGameClients000";
   1.175 +		for (unsigned int i = 3; i <= 4; i++)
   1.176 +		{
   1.177 +			gameclients_iface[19] = '0' + i;
   1.178 +			if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
   1.179 +				break;
   1.180 +		}
   1.181 +
   1.182 +		if (!mm_DetectGameInformation())
   1.183 +		{
   1.184 +			UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
   1.185 +			return false;
   1.186 +		}
   1.187 +
   1.188 +		mm_InitializeForLoad();
   1.189 +		mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
   1.190 +							 (CreateInterfaceFn)info->engineFactory,
   1.191 +							 (CreateInterfaceFn)info->engineFactory,
   1.192 +							 pGlobals);
   1.193 +		mm_StartupMetamod(true);
   1.194 +		
   1.195 +		g_plugin_unload = icvar->FindCommand("plugin_unload");
   1.196 +
   1.197 +		if (g_plugin_unload != NULL)
   1.198 +		{
   1.199 +			SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
   1.200 +			SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
   1.201 +		}
   1.202 +
   1.203 +		return true;
   1.204 +	}
   1.205 +
   1.206 +	virtual void Unload()
   1.207 +	{
   1.208 +		if (g_bIsTryingToUnload)
   1.209 +		{
   1.210 +			Error("Metamod:Source cannot be unloaded from VSP mode.  Use \"meta unload\" to unload specific plugins.\n");
   1.211 +			return;
   1.212 +		}
   1.213 +		if (g_plugin_unload != NULL)
   1.214 +		{
   1.215 +			SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
   1.216 +			SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
   1.217 +			g_plugin_unload = NULL;
   1.218 +		}
   1.219 +		mm_UnloadMetamod();
   1.220 +	}
   1.221 +
   1.222 +	virtual const char *GetDescription()
   1.223 +	{
   1.224 +		return "Metamod:Source " SVN_FULL_VERSION;
   1.225 +	}
   1.226 +};
   1.227 +
   1.228 +VspBridge mm16_vsp_bridge;
   1.229 +
   1.230 +SMM_API IVspBridge *
   1.231 +GetVspBridge()
   1.232 +{
   1.233 +	return &mm16_vsp_bridge;
   1.234 +}
   1.235 +