1.1 --- a/core/vsp_bridge.cpp Tue Nov 17 04:49:17 2009 -0500
1.2 +++ b/core/vsp_bridge.cpp Sun Nov 22 23:54:55 2009 -0600
1.3 @@ -1,8 +1,8 @@
1.4 /**
1.5 - * vim: set ts=4 :
1.6 + * vim: set ts=4 sw=4 tw=99 noet :
1.7 * ======================================================
1.8 * Metamod:Source
1.9 - * Copyright (C) 2004-2008 AlliedModders LLC and authors.
1.10 + * Copyright (C) 2004-2009 AlliedModders LLC and authors.
1.11 * All rights reserved.
1.12 * ======================================================
1.13 *
1.14 @@ -21,8 +21,6 @@
1.15 * 2. Altered source versions must be plainly marked as such, and must not be
1.16 * misrepresented as being the original software.
1.17 * 3. This notice may not be removed or altered from any source distribution.
1.18 - *
1.19 - * Version: $Id$
1.20 */
1.21
1.22 #include "metamod.h"
1.23 @@ -42,6 +40,7 @@
1.24
1.25 ConCommand *g_plugin_unload = NULL;
1.26 bool g_bIsTryingToUnload;
1.27 +const char *vsp_desc = "Metamod:Source " MMS_FULL_VERSION;
1.28
1.29 #if SOURCE_ENGINE >= SE_ORANGEBOX
1.30 void InterceptPluginUnloads(const CCommand &args)
1.31 @@ -66,59 +65,65 @@
1.32 public:
1.33 virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
1.34 {
1.35 - assert(!g_Metamod.IsLoadedAsGameDLL());
1.36 + if (!g_Metamod.IsLoadedAsGameDLL())
1.37 + {
1.38 + CGlobalVars *pGlobals;
1.39 + IPlayerInfoManager *playerInfoManager;
1.40
1.41 - CGlobalVars *pGlobals;
1.42 - IPlayerInfoManager *playerInfoManager;
1.43 + playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
1.44 + if (playerInfoManager == NULL)
1.45 + {
1.46 + UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
1.47 + return false;
1.48 + }
1.49
1.50 - playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
1.51 - if (playerInfoManager == NULL)
1.52 - {
1.53 - UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
1.54 - return false;
1.55 - }
1.56 + pGlobals = playerInfoManager->GetGlobalVars();
1.57 +
1.58 + char gamedll_iface[] = "ServerGameDLL000";
1.59 + for (unsigned int i = 3; i <= 50; i++)
1.60 + {
1.61 + gamedll_iface[15] = '0' + i;
1.62 + if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
1.63 + {
1.64 + g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false);
1.65 + break;
1.66 + }
1.67 + }
1.68
1.69 - pGlobals = playerInfoManager->GetGlobalVars();
1.70 + if (server == NULL)
1.71 + {
1.72 + UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
1.73 + return false;
1.74 + }
1.75 +
1.76 + char gameclients_iface[] = "ServerGameClients000";
1.77 + for (unsigned int i = 3; i <= 4; i++)
1.78 + {
1.79 + gameclients_iface[19] = '0' + i;
1.80 + if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
1.81 + break;
1.82 + }
1.83
1.84 - char gamedll_iface[] = "ServerGameDLL000";
1.85 - for (unsigned int i = 3; i <= 50; i++)
1.86 + if (!mm_DetectGameInformation())
1.87 + {
1.88 + UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
1.89 + return false;
1.90 + }
1.91 +
1.92 + mm_InitializeForLoad();
1.93 + mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
1.94 + (CreateInterfaceFn)info->engineFactory,
1.95 + (CreateInterfaceFn)info->engineFactory,
1.96 + pGlobals);
1.97 + g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
1.98 + mm_StartupMetamod(true);
1.99 + }
1.100 + else
1.101 {
1.102 - gamedll_iface[15] = '0' + i;
1.103 - if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
1.104 - {
1.105 - g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false);
1.106 - break;
1.107 - }
1.108 + vsp_desc = "Metamod:Source Interface " MMS_FULL_VERSION;
1.109 + g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
1.110 }
1.111
1.112 - if (server == NULL)
1.113 - {
1.114 - UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
1.115 - return false;
1.116 - }
1.117 -
1.118 - char gameclients_iface[] = "ServerGameClients000";
1.119 - for (unsigned int i = 3; i <= 4; i++)
1.120 - {
1.121 - gameclients_iface[19] = '0' + i;
1.122 - if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
1.123 - break;
1.124 - }
1.125 -
1.126 - if (!mm_DetectGameInformation())
1.127 - {
1.128 - UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
1.129 - return false;
1.130 - }
1.131 -
1.132 - mm_InitializeForLoad();
1.133 - mm_InitializeGlobals((CreateInterfaceFn)info->engineFactory,
1.134 - (CreateInterfaceFn)info->engineFactory,
1.135 - (CreateInterfaceFn)info->engineFactory,
1.136 - pGlobals);
1.137 - g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
1.138 - mm_StartupMetamod(true);
1.139 -
1.140 #if SOURCE_ENGINE >= SE_ORANGEBOX
1.141 g_plugin_unload = icvar->FindCommand("plugin_unload");
1.142 #else
1.143 @@ -156,12 +161,15 @@
1.144 SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
1.145 g_plugin_unload = NULL;
1.146 }
1.147 - mm_UnloadMetamod();
1.148 + if (!g_Metamod.IsLoadedAsGameDLL())
1.149 + {
1.150 + mm_UnloadMetamod();
1.151 + }
1.152 }
1.153
1.154 virtual const char *GetDescription()
1.155 {
1.156 - return "Metamod:Source " MMS_FULL_VERSION;
1.157 + return vsp_desc;
1.158 }
1.159 };
1.160