core/vsp_bridge.cpp
author David Anderson <dvander@alliedmods.net>
Tue Nov 18 04:57:10 2008 -0600 (2008-11-18)
changeset 574 edb3ced430ac
parent 558 0ed2a4a6e31d
child 576 fc3600fed257
permissions -rw-r--r--
Another version.rc bug.
     1 #include "metamod.h"
     2 #include "metamod_util.h"
     3 #include <interface.h>
     4 #include <eiface.h>
     5 #include <iplayerinfo.h>
     6 #include <assert.h>
     7 #include <loader_bridge.h>
     8 #include "provider/provider_ep2.h"
     9 
    10 SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
    11 
    12 ConCommand *g_plugin_unload = NULL;
    13 bool g_bIsTryingToUnload;
    14 
    15 void InterceptPluginUnloads(const CCommand &args)
    16 {
    17 	g_bIsTryingToUnload = true;
    18 }
    19 
    20 void InterceptPluginUnloads_Post(const CCommand &args)
    21 {
    22 	g_bIsTryingToUnload = false;
    23 }
    24 
    25 class VspBridge : public IVspBridge
    26 {
    27 public:
    28 	virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
    29 	{
    30 		assert(!g_Metamod.IsLoadedAsGameDLL());
    31 
    32 		CGlobalVars *pGlobals;
    33 		IPlayerInfoManager *playerInfoManager;
    34 
    35 		playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
    36 		if (playerInfoManager == NULL)
    37 		{
    38 			UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
    39 			return false;
    40 		}
    41 
    42 		pGlobals = playerInfoManager->GetGlobalVars();
    43 
    44 		char gamedll_iface[] = "ServerGameDLL000";
    45 		for (unsigned int i = 5; i <= 50; i++)
    46 		{
    47 			gamedll_iface[15] = '0' + i;
    48 			if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
    49 			{
    50 				g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i);
    51 				break;
    52 			}
    53 		}
    54 
    55 		if (server == NULL)
    56 		{
    57 			UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
    58 			return false;
    59 		}
    60 
    61 		char gameclients_iface[] = "ServerGameClients000";
    62 		for (unsigned int i = 3; i <= 4; i++)
    63 		{
    64 			gameclients_iface[19] = '0' + i;
    65 			if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
    66 				break;
    67 		}
    68 
    69 		if (!mm_DetectGameInformation())
    70 		{
    71 			UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
    72 			return false;
    73 		}
    74 
    75 		mm_InitializeForLoad();
    76 		mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
    77 							 (CreateInterfaceFn)info->engineFactory,
    78 							 (CreateInterfaceFn)info->engineFactory,
    79 							 pGlobals);
    80 		mm_StartupMetamod(true);
    81 		
    82 		g_plugin_unload = icvar->FindCommand("plugin_unload");
    83 
    84 		if (g_plugin_unload != NULL)
    85 		{
    86 			SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
    87 			SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
    88 		}
    89 
    90 		return true;
    91 	}
    92 
    93 	virtual void Unload()
    94 	{
    95 	}
    96 
    97 	virtual const char *GetDescription()
    98 	{
    99 		return "Metamod:Source " SVN_FULL_VERSION;
   100 	}
   101 };
   102 
   103 VspBridge mm16_vsp_bridge;
   104 
   105 SMM_API IVspBridge *
   106 GetVspBridge()
   107 {
   108 	return &mm16_vsp_bridge;
   109 }
   110