sourcemm/sourcemm.cpp
changeset 282 7a237e9ea5a1
parent 278 614ea295cd25
child 287 0492209c065f
     1.1 --- a/sourcemm/sourcemm.cpp	Thu Feb 08 11:44:11 2007 +0000
     1.2 +++ b/sourcemm/sourcemm.cpp	Sat Feb 10 00:31:34 2007 +0000
     1.3 @@ -1,14 +1,14 @@
     1.4  /* ======== SourceMM ========
     1.5 -* Copyright (C) 2004-2006 Metamod:Source Development Team
     1.6 -* No warranties of any kind
     1.7 -*
     1.8 -* License: zlib/libpng
     1.9 -*
    1.10 -* Author(s): David "BAILOPAN" Anderson
    1.11 -* Contributor(s): Scott "Damaged Soul" Ehlert
    1.12 -*				: Pavol "PM OnoTo" Marko
    1.13 -* ============================
    1.14 -*/
    1.15 + * Copyright (C) 2004-2007 Metamod:Source Development Team
    1.16 + * No warranties of any kind
    1.17 + *
    1.18 + * License: zlib/libpng
    1.19 + *
    1.20 + * Author(s): David "BAILOPAN" Anderson
    1.21 + * Contributor(s): Scott "Damaged Soul" Ehlert
    1.22 + *				: Pavol "PM OnoTo" Marko
    1.23 + * ============================
    1.24 + */
    1.25  
    1.26  #include <interface.h>
    1.27  #include <eiface.h>
    1.28 @@ -17,6 +17,7 @@
    1.29  #include "CSmmAPI.h"
    1.30  #include "CPlugin.h"
    1.31  #include "util.h"
    1.32 +#include "vsp_listener.h"
    1.33  
    1.34  using namespace SourceMM;
    1.35  
    1.36 @@ -30,11 +31,13 @@
    1.37  SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
    1.38  SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
    1.39  SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
    1.40 +SH_DECL_HOOK0(IServerGameDLL, GameInit, SH_NOATTRIB, false, bool);
    1.41  bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
    1.42  bool DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
    1.43  void DLLShutdown_handler();
    1.44  void LevelShutdown_handler();
    1.45  bool LevelInit_handler(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
    1.46 +bool GameInit_handler();
    1.47  
    1.48  GameDllInfo g_GameDll = {false, NULL, NULL, NULL, NULL};
    1.49  EngineInfo g_Engine;
    1.50 @@ -45,6 +48,7 @@
    1.51  PluginId g_PLID = Pl_Console;		//Technically, SourceMM is the "Console" plugin... :p
    1.52  bool bInFirstLevel = true;
    1.53  bool gParsedGameInfo = false;
    1.54 +bool bGameInit = false;
    1.55  SourceHook::List<GameDllInfo *> gamedll_list;
    1.56  SourceHook::CallClass<IServerGameDLL> *dllExec;
    1.57  int g_GameDllVersion = 0;
    1.58 @@ -104,11 +108,12 @@
    1.59  	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLShutdown, g_GameDll.pGameDLL, DLLShutdown_handler, false);
    1.60  	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelShutdown, g_GameDll.pGameDLL, LevelShutdown_handler, true);
    1.61  	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelInit, g_GameDll.pGameDLL, LevelInit_handler, true);
    1.62 +	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, GameInit, g_GameDll.pGameDLL, GameInit_handler, false);
    1.63  
    1.64  	if (g_GameDll.pGameClients)
    1.65 +	{
    1.66  		SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, g_GameDll.pGameClients, ClientCommand_handler, false);
    1.67 -	else
    1.68 -	{
    1.69 +	} else {
    1.70  		// If IServerGameClients isn't found, this really isn't a fatal error so...
    1.71  		LogMessage("[META] Warning: Could not find IServerGameClients!");
    1.72  		LogMessage("[META] Warning: The 'meta' command will not be available to clients.");
    1.73 @@ -149,7 +154,9 @@
    1.74  
    1.75  	const char *pluginFile = g_Engine.icvar->GetCommandLineValue("mm_pluginsfile");
    1.76  	if (!pluginFile) 
    1.77 +	{
    1.78  		pluginFile = GetPluginsFile();
    1.79 +	}
    1.80  
    1.81  	char full_path[260];
    1.82  	g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s", g_ModPath.c_str(), pluginFile);
    1.83 @@ -163,6 +170,23 @@
    1.84  	RETURN_META_VALUE(MRES_IGNORED, true);
    1.85  }
    1.86  
    1.87 +bool GameInit_handler()
    1.88 +{
    1.89 +	if (bGameInit)
    1.90 +	{
    1.91 +		return true;
    1.92 +	}
    1.93 +
    1.94 +	if (g_SmmAPI.VSPEnabled())
    1.95 +	{
    1.96 +		g_SmmAPI.LoadAsVSP();
    1.97 +	}
    1.98 +
    1.99 +	bGameInit = true;
   1.100 +
   1.101 +	return true;
   1.102 +}
   1.103 +
   1.104  bool DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
   1.105  {
   1.106  	g_PluginMngr.SetAllLoaded();
   1.107 @@ -174,15 +198,28 @@
   1.108  {
   1.109  	// Prevent loading of self as a SourceMM plugin or Valve server plugin :x
   1.110  	const char *vspIface = "ISERVERPLUGINCALLBACKS";
   1.111 -	if (strcmp(iface, PLAPI_NAME) == 0 || strnicmp(iface, vspIface, strlen(vspIface)) == 0)
   1.112 +	if (strcmp(iface, PLAPI_NAME) == 0)
   1.113  	{
   1.114  		Warning("Do not try loading Metamod:Source as a SourceMM or Valve server plugin.\n");
   1.115  
   1.116  		if (ret)
   1.117 +		{
   1.118  			*ret = IFACE_FAILED;
   1.119 +		}
   1.120 +
   1.121  		return NULL;
   1.122  	}
   1.123  
   1.124 +	if (strncmp(iface, vspIface, 22) == 0)
   1.125 +	{
   1.126 +		if (ret)
   1.127 +		{
   1.128 +			*ret = IFACE_OK;
   1.129 +		}
   1.130 +
   1.131 +		return &g_VspListener;
   1.132 +	}
   1.133 +
   1.134  	if (!gParsedGameInfo)
   1.135  	{
   1.136  		gParsedGameInfo = true;
   1.137 @@ -410,7 +447,9 @@
   1.138  				//maybe this will get used in the future
   1.139  				sizeTooBig = g_GameDllVersion;
   1.140  				if (ret)
   1.141 +				{
   1.142  					*ret = IFACE_FAILED;
   1.143 +				}
   1.144  			}
   1.145  			SourceHook::List<GameDllInfo *>::iterator iter;
   1.146  			GameDllInfo *pInfo = NULL;
   1.147 @@ -436,7 +475,9 @@
   1.148  				{
   1.149  					Error("This mod version requires a SourceMM update (ServerGameDLL%03d)!\n", sizeTooBig);
   1.150  					if (ret)
   1.151 +					{
   1.152  						*ret = IFACE_FAILED;
   1.153 +					}
   1.154  					return NULL;
   1.155  				} else {
   1.156  					InitMainStates();
   1.157 @@ -689,10 +730,6 @@
   1.158  		LogMessage("[META] Warning: Console messages will not be redirected to rcon console.");
   1.159  	}
   1.160  
   1.161 -#if (defined _DEBUG || defined DEBUG) && (defined OS_WIN32)
   1.162 -    SetUnhandledExceptionFilter(NULL);
   1.163 -#endif
   1.164 -
   1.165  	ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
   1.166  
   1.167  	RETURN_META_VALUE(MRES_IGNORED, false);