sourcemm/sourcemm.cpp
changeset 296 ba7337defd34
parent 287 0492209c065f
child 313 297482d07c85
     1.1 --- a/sourcemm/sourcemm.cpp	Sat Mar 03 06:57:30 2007 +0000
     1.2 +++ b/sourcemm/sourcemm.cpp	Wed Mar 21 17:45:28 2007 +0000
     1.3 @@ -12,6 +12,7 @@
     1.4  
     1.5  #include <interface.h>
     1.6  #include <eiface.h>
     1.7 +#include <tier0/icommandline.h>
     1.8  #include "sourcemm.h"
     1.9  #include "concommands.h"
    1.10  #include "CSmmAPI.h"
    1.11 @@ -26,6 +27,9 @@
    1.12   * @file sourcemm.cpp
    1.13   */
    1.14  
    1.15 +#undef CommandLine
    1.16 +DLL_IMPORT ICommandLine *CommandLine();
    1.17 +
    1.18  SH_DECL_HOOK4(IServerGameDLL, DLLInit, SH_NOATTRIB, false, bool, CreateInterfaceFn, CreateInterfaceFn, CreateInterfaceFn, CGlobalVars *);
    1.19  SH_DECL_HOOK0_void(IServerGameDLL, DLLShutdown, SH_NOATTRIB, false);
    1.20  SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
    1.21 @@ -46,17 +50,19 @@
    1.22  SourceHook::ISourceHook *g_SHPtr = &g_SourceHook;
    1.23  SourceHook::String g_ModPath;
    1.24  SourceHook::String g_BinPath;
    1.25 -PluginId g_PLID = Pl_Console;		//Technically, SourceMM is the "Console" plugin... :p
    1.26 +PluginId g_PLID = Pl_Console;			/* Technically, SourceMM is the "Console" plugin... :p */
    1.27  bool bInFirstLevel = true;
    1.28  bool gParsedGameInfo = false;
    1.29  bool bGameInit = false;
    1.30  SourceHook::List<GameDllInfo *> gamedll_list;
    1.31  SourceHook::CallClass<IServerGameDLL> *g_GameDllPatch;
    1.32  int g_GameDllVersion = 0;
    1.33 +const char VSPIFACE[] = "ISERVERPLUGINS";
    1.34 +const char GAMEINFO_PATH[] = "|gameinfo_path|";
    1.35  
    1.36  void ClearGamedllList();
    1.37  
    1.38 -//helper macro
    1.39 +/* Helper Macro */
    1.40  #define	IFACE_MACRO(orig,nam) \
    1.41  	CPluginManager::CPlugin *pl; \
    1.42  	SourceHook::List<IMetamodListener *>::iterator event; \
    1.43 @@ -92,16 +98,17 @@
    1.44  // Main code for HL2 Interaction //
    1.45  ///////////////////////////////////
    1.46  
    1.47 -//Initialize everything here
    1.48 +/* Initialize everything here */
    1.49  void InitMainStates()
    1.50  {
    1.51 -	char full_path[260] = {0};
    1.52 -	GetFileOfAddress((void *)g_GameDll.factory, full_path, sizeof(full_path)-1);
    1.53 +	char full_path[PATH_SIZE] = {0};
    1.54 +	GetFileOfAddress((void *)g_GameDll.factory, full_path, sizeof(full_path));
    1.55  	g_BinPath.assign(full_path);
    1.56  
    1.57 -	//Like metamod, reload plugins at the end of the map.
    1.58 -	//This is so plugins can hook everything on load, BUT, new plugins will be reloaded
    1.59 -	// if the server is shut down (silly, but rare case).
    1.60 +	/* Like Metamod, reload plugins at the end of the map.
    1.61 +	 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
    1.62 +	 * if the server is shut down (silly, but rare case).
    1.63 +	 */
    1.64  	bInFirstLevel = true;
    1.65  
    1.66  	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLInit, g_GameDll.pGameDLL, DLLInit, false);
    1.67 @@ -115,7 +122,7 @@
    1.68  	{
    1.69  		SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, g_GameDll.pGameClients, ClientCommand_handler, false);
    1.70  	} else {
    1.71 -		// If IServerGameClients isn't found, this really isn't a fatal error so...
    1.72 +		/* If IServerGameClients isn't found, this really isn't a fatal error so... */
    1.73  		LogMessage("[META] Warning: Could not find IServerGameClients!");
    1.74  		LogMessage("[META] Warning: The 'meta' command will not be available to clients.");
    1.75  	}
    1.76 @@ -143,7 +150,7 @@
    1.77  
    1.78  	g_Engine.loaded = true;
    1.79  
    1.80 -	//Initialize our console hooks
    1.81 +	/* Initialize our console hooks */
    1.82  	ConCommandBaseMgr::OneTimeInit(static_cast<IConCommandBaseAccessor *>(&g_SMConVarAccessor));
    1.83  
    1.84  	g_GameDllPatch = SH_GET_CALLCLASS(g_GameDll.pGameDLL);
    1.85 @@ -157,7 +164,8 @@
    1.86  	if (!g_SmmAPI.CacheUserMessages())
    1.87  	{
    1.88  		/* Don't know of a mod that has stripped out user messages completely, 
    1.89 -			but perhaps should do something different here? */
    1.90 +		 * but perhaps should do something different here?
    1.91 +		 */
    1.92  		LogMessage("[META] Warning: Failed to get list of user messages.");
    1.93  		LogMessage("[META] Warning: The 'meta game' command will not display user messages.");
    1.94  	}
    1.95 @@ -169,7 +177,7 @@
    1.96  	}
    1.97  
    1.98  	char full_path[260];
    1.99 -	g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s", g_ModPath.c_str(), pluginFile);
   1.100 +	g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), pluginFile);
   1.101  
   1.102  	LoadPluginsFromFile(full_path);
   1.103  
   1.104 @@ -201,11 +209,10 @@
   1.105  	RETURN_META_VALUE(MRES_IGNORED, true);
   1.106  }
   1.107  
   1.108 -//This is where the magic happens
   1.109 +/* This is where the magic happens */
   1.110  SMM_API void *CreateInterface(const char *iface, int *ret)
   1.111  {
   1.112 -	// Prevent loading of self as a SourceMM plugin or Valve server plugin :x
   1.113 -	const char *vspIface = "ISERVERPLUGINCALLBACKS";
   1.114 +	/* Prevent loading of self as a SourceMM plugin or Valve server plugin :x */
   1.115  	if (strcmp(iface, PLAPI_NAME) == 0)
   1.116  	{
   1.117  		Warning("Do not try loading Metamod:Source as a SourceMM or Valve server plugin.\n");
   1.118 @@ -218,7 +225,7 @@
   1.119  		return NULL;
   1.120  	}
   1.121  
   1.122 -	if (strncmp(iface, vspIface, 22) == 0)
   1.123 +	if (strncmp(iface, VSPIFACE, sizeof(VSPIFACE) - 1) == 0)
   1.124  	{
   1.125  		if (ret)
   1.126  		{
   1.127 @@ -231,127 +238,52 @@
   1.128  	if (!gParsedGameInfo)
   1.129  	{
   1.130  		gParsedGameInfo = true;
   1.131 -		char curpath[260] = {0};
   1.132 -		char dllpath[260] = {0};
   1.133 -		getcwd(curpath, sizeof(curpath)-1);
   1.134 -		if (!GetFileOfAddress((void *)CreateInterface, dllpath, sizeof(dllpath)-1))
   1.135 +		const char *gameDir = NULL;
   1.136 +		char gamePath[PATH_SIZE];
   1.137 +		char smmPath[PATH_SIZE];
   1.138 +
   1.139 +		/* Get path to SourceMM DLL */
   1.140 +		if (!GetFileOfAddress((void *)CreateInterface, smmPath, sizeof(smmPath)))
   1.141  		{
   1.142  			Error("GetFileOfAddress() failed! Metamod cannot load.\n");
   1.143  			return NULL;
   1.144  		}
   1.145 -		SourceHook::String s_dllpath(dllpath);
   1.146 -		//begin the heuristics for searching for the mod path (these are quite ugly).
   1.147 -		//for OS compatibility purposes, we're going to do case insensitivity on windows.
   1.148 -		size_t path_len = strlen(curpath);
   1.149 -		size_t dll_len = strlen(dllpath);
   1.150 +
   1.151 +		/* Get value of -game from command line, defaulting to hl2 as engine seems to do */
   1.152 +		gameDir = CommandLine()->ParmValue("-game", "hl2");
   1.153 +
   1.154 +		/* Get absolute path */
   1.155 +		abspath(gamePath, gameDir);
   1.156 +		g_ModPath.assign(gamePath);
   1.157  
   1.158 -		//strip the dll path off
   1.159 -		//:TODO: with path stuff - in Linux, \ can exist in a file path as a non-seperator!
   1.160 -		for (size_t i=dll_len-1; i>0; i--)
   1.161 +		char tempPath[PATH_SIZE];
   1.162 +
   1.163 +		/* Path to gameinfo.txt */
   1.164 +		g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s", g_ModPath.c_str(), "gameinfo.txt");
   1.165 +
   1.166 +		FILE *fp = fopen(tempPath, "rt");
   1.167 +
   1.168 +		if (!fp)
   1.169  		{
   1.170 -			if (dllpath[i] == '\\' || dllpath[i] == '/')
   1.171 -			{
   1.172 -				if (i == dll_len-1)
   1.173 -					break;
   1.174 -				//save path by stripping off file name and ending terminator
   1.175 -				dllpath[i] = '\0';
   1.176 -				dll_len = i;
   1.177 -				break;
   1.178 -			}
   1.179 -		}
   1.180 -
   1.181 -		//strip absolute path terminators if any!
   1.182 -		if (curpath[path_len-1] == '/' || curpath[path_len-1] == '\\')
   1.183 -			curpath[--path_len] = '\0';
   1.184 -
   1.185 -		//if the base path doesn't fit into the module path, something is wrong!
   1.186 -		// ex: c:\games\srcds
   1.187 -		//     c:\gaben.dll
   1.188 -		if (path_len > dll_len)
   1.189 -		{
   1.190 -			Error("Could not detect GameDLL path! Metamod cannot load[1].\n");
   1.191 +			Error("Unable to open gameinfo.txt!  Metamod cannot load.\n");
   1.192  			return NULL;
   1.193  		}
   1.194  
   1.195 -		//we are now in such a position that the two dir names SHOULD MATCH!
   1.196 -		typedef int (*STRNCMP)(const char *str1, const char *str2, size_t n);
   1.197 -		STRNCMP cmp = 
   1.198 -#ifdef WIN32
   1.199 -			strnicmp;
   1.200 -#else
   1.201 -			strncmp;
   1.202 -#endif
   1.203 -		//are they equal?
   1.204 -		if ( ((cmp)(curpath, dllpath, path_len)) != 0 )
   1.205 -		{
   1.206 -			//:TODO: In this case, we should read /proc/self/maps and find srcds!
   1.207 -			Error("Could not detect GameDLL path! Metamod cannot load[2].\n");
   1.208 -			return NULL;
   1.209 -		}
   1.210 -		//this will skip past the dir and its separator char
   1.211 -		char *ptr = &(dllpath[path_len+1]);
   1.212 -		path_len = strlen(ptr);
   1.213 -		for (size_t i=0; i<path_len; i++)
   1.214 -		{
   1.215 -			if (ptr[i] == '/' || ptr[i] == '\\')
   1.216 -			{
   1.217 -				if (i == 0)
   1.218 -				{
   1.219 -					Error("Could not detect GameDLL path! Metamod cannot load[3].\n");
   1.220 -					return NULL;
   1.221 -				} else {
   1.222 -					ptr[i] = '\0';
   1.223 -					path_len = i+1;
   1.224 -					break;
   1.225 -				}
   1.226 -			}
   1.227 -		}
   1.228 -		//WE NOW HAVE A GUESS AT THE MOD DIR.  OH MY GOD.
   1.229 -		char temp_path[260];
   1.230 -		snprintf(temp_path, sizeof(temp_path)-1, 
   1.231 -			"%s%s%s", 
   1.232 -			curpath, 
   1.233 -			PATH_SEP_STR, 
   1.234 -			ptr);
   1.235 -
   1.236 -		g_ModPath.assign(temp_path);
   1.237 -
   1.238 -		snprintf(temp_path, sizeof(temp_path)-1, 
   1.239 -			"%s%s%s", 
   1.240 -			g_ModPath.c_str(),
   1.241 -			PATH_SEP_STR,
   1.242 -			"gameinfo.txt");
   1.243 -
   1.244 -		FILE *fp = fopen(temp_path, "rt");
   1.245 -		if (!fp)
   1.246 -		{
   1.247 -			/* Do not error out here! It's possible the mod exists in the root directory, i.e.
   1.248 -			 * Dark Messiah.  Let's check that just in case!
   1.249 -			 */
   1.250 -			g_SmmAPI.PathFormat(temp_path, sizeof(temp_path)-1, "%s", curpath);
   1.251 -			g_ModPath.assign(temp_path);
   1.252 -			g_SmmAPI.PathFormat(temp_path, sizeof(temp_path)-1, "%s/%s", g_ModPath.c_str(), "gameinfo.txt");
   1.253 -
   1.254 -			fp = fopen(temp_path, "rt");
   1.255 -			if (!fp)
   1.256 -			{
   1.257 -				/* Okay, we have to concede here. */
   1.258 -				Error("Unable to open gameinfo.txt!  Metamod cannot load.\n");
   1.259 -				return NULL;
   1.260 -			}
   1.261 -		}
   1.262  		char buffer[255];
   1.263  		char key[128], val[128];
   1.264  		size_t len = 0;
   1.265 -		const char *gameinfo = "|gameinfo_path|";
   1.266 -		size_t gameinfo_len = strlen(gameinfo);
   1.267  		bool search = false;
   1.268  		bool gamebin = false;
   1.269 +		char *ptr;
   1.270  		const char *lptr;
   1.271 +		char curPath[PATH_SIZE];
   1.272 +
   1.273 +		getcwd(curPath, PATH_SIZE);
   1.274 +
   1.275  		while (!feof(fp))
   1.276  		{
   1.277  			buffer[0] = '\0';
   1.278 -			fgets(buffer, sizeof(buffer)-1, fp);
   1.279 +			fgets(buffer, sizeof(buffer), fp);
   1.280  			len = strlen(buffer);
   1.281  			if (buffer[len-1] == '\n')
   1.282  				buffer[--len] = '\0';
   1.283 @@ -362,7 +294,7 @@
   1.284  				search = true;
   1.285  			if (!search)
   1.286  				continue;
   1.287 -			UTIL_KeySplit(buffer, key, sizeof(key)-1, val, sizeof(val)-1);
   1.288 +			UTIL_KeySplit(buffer, key, sizeof(key) - 1, val, sizeof(val) - 1);
   1.289  			if (stricmp(key, "Game") == 0 || stricmp(key, "GameBin") == 0)
   1.290  			{
   1.291  				if (stricmp(key, "Game") == 0)
   1.292 @@ -370,32 +302,35 @@
   1.293  				else
   1.294  					gamebin = true;
   1.295  
   1.296 -				if (strncmp(val, gameinfo, gameinfo_len) == 0)
   1.297 +				if (strncmp(val, GAMEINFO_PATH, sizeof(GAMEINFO_PATH) - 1) == 0)
   1.298  				{
   1.299 -					ptr = &(val[gameinfo_len]);
   1.300 +					ptr = &(val[sizeof(GAMEINFO_PATH) - 1]);
   1.301  					if (ptr[0] == '.')
   1.302  						ptr++;
   1.303  					lptr = g_ModPath.c_str();
   1.304  				} else {
   1.305 -					lptr = curpath;
   1.306  					ptr = val;
   1.307 +					lptr = curPath;
   1.308  				}
   1.309 +
   1.310  				size_t ptr_len = strlen(ptr);
   1.311  				if (ptr[ptr_len] == '/' || ptr[ptr_len] == '\\')
   1.312  					ptr[--ptr_len] = '\0';
   1.313  
   1.314 -				//no need to append "bin"
   1.315 +				/* No need to append "bin" if key is GameBin */
   1.316  				if (gamebin)
   1.317  				{
   1.318 -					g_SmmAPI.PathFormat(temp_path, sizeof(temp_path)-1, "%s/%s/%s", lptr, ptr, SERVER_DLL);
   1.319 +					g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s/%s", lptr, ptr, SERVER_DLL);
   1.320  				} else if (!ptr[0]) {
   1.321 -					g_SmmAPI.PathFormat(temp_path, sizeof(temp_path)-1, "%s/%s/%s", lptr, "bin", SERVER_DLL);
   1.322 +					g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s/%s", lptr, "bin", SERVER_DLL);
   1.323  				} else {
   1.324 -					g_SmmAPI.PathFormat(temp_path, sizeof(temp_path)-1, "%s/%s/%s/%s", lptr, ptr, "bin", SERVER_DLL);
   1.325 +					g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s/%s/%s", lptr, ptr, "bin", SERVER_DLL);
   1.326  				}
   1.327 -				if (!UTIL_PathCmp(s_dllpath.c_str(), temp_path))
   1.328 +
   1.329 +				/* If not path to SourceMM... */
   1.330 +				if (!UTIL_PathCmp(smmPath, tempPath))
   1.331  				{
   1.332 -					FILE *fp = fopen(temp_path, "rb");
   1.333 +					FILE *fp = fopen(tempPath, "rb");
   1.334  					if (!fp)
   1.335  						continue;
   1.336  					//:TODO: Optimize this a bit!
   1.337 @@ -405,9 +340,9 @@
   1.338  					for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
   1.339  					{
   1.340  						pCheck = (*iter);
   1.341 -						if (GetFileOfAddress((void *)pCheck->factory, buffer, sizeof(buffer)-1))
   1.342 +						if (GetFileOfAddress((void *)pCheck->factory, buffer, sizeof(buffer)))
   1.343  						{
   1.344 -							if (UTIL_PathCmp(temp_path, buffer))
   1.345 +							if (UTIL_PathCmp(tempPath, buffer))
   1.346  							{
   1.347  								found = true;
   1.348  								break;
   1.349 @@ -417,7 +352,7 @@
   1.350  					if (found)
   1.351  						continue;
   1.352  					fclose(fp);
   1.353 -					HINSTANCE gamedll = dlmount(temp_path);
   1.354 +					HINSTANCE gamedll = dlmount(tempPath);
   1.355  					if (gamedll == NULL)
   1.356  						continue;
   1.357  					CreateInterfaceFn fn = (CreateInterfaceFn)dlsym(gamedll, "CreateInterface");
   1.358 @@ -447,12 +382,12 @@
   1.359  
   1.360  		if (strncmp(iface, str, len) == 0)
   1.361  		{
   1.362 -			//This is the interface we want!  Right now we support versions 3 through 5.
   1.363 +			/* This is the interface we want!  Right now we support versions 3 through 8 */
   1.364  			g_GameDllVersion = atoi(&(iface[len]));
   1.365  			int sizeTooBig = 0;	//rename this to sizeWrong in the future!
   1.366  			if (g_GameDllVersion < MIN_GAMEDLL_VERSION || g_GameDllVersion > MAX_GAMEDLL_VERSION)
   1.367  			{
   1.368 -				//maybe this will get used in the future
   1.369 +				/* Maybe this will get used in the future */
   1.370  				sizeTooBig = g_GameDllVersion;
   1.371  				if (ret)
   1.372  				{
   1.373 @@ -468,7 +403,7 @@
   1.374  				ptr = (pInfo->factory)(iface, ret);
   1.375  				if (ptr)
   1.376  				{
   1.377 -					//this is our gamedll.  unload the others.
   1.378 +					/* This is our GameDLL. Unload the others. */
   1.379  					gamedll_list.erase(iter);
   1.380  					ClearGamedllList();
   1.381  					pInfo->pGameDLL = static_cast<IServerGameDLL *>(ptr);
   1.382 @@ -497,14 +432,14 @@
   1.383  				return NULL;
   1.384  			}
   1.385  		} else {
   1.386 -			//wtf do we do...
   1.387 -			//:TODO: .. something a bit more intelligent?
   1.388 +			/* wtf do we do... */
   1.389 +			/* :TODO: .. something a bit more intelligent? */
   1.390  			Error("Engine requested unknown interface before GameDLL was known!\n");
   1.391  			return NULL;
   1.392  		}
   1.393  	}
   1.394  
   1.395 -	//if we got here, there's definitely a gamedll.
   1.396 +	/* If we got here, there's definitely a GameDLL */
   1.397  	IFACE_MACRO(g_GameDll.factory, GameDLL);
   1.398  }
   1.399  
   1.400 @@ -525,10 +460,10 @@
   1.401  
   1.402  void DLLShutdown_handler()
   1.403  {
   1.404 -	//Unload plugins
   1.405 +	/* Unload plugins */
   1.406  	g_PluginMngr.UnloadAll();
   1.407  
   1.408 -	// Add the FCVAR_GAMEDLL flag to our cvars so the engine removes them properly
   1.409 +	/* Add the FCVAR_GAMEDLL flag to our cvars so the engine removes them properly */
   1.410  	g_SMConVarAccessor.MarkCommandsAsGameDLL();
   1.411  	g_SMConVarAccessor.UnregisterGameDLLCommands();
   1.412  
   1.413 @@ -566,7 +501,7 @@
   1.414  	while (!feof(fp))
   1.415  	{
   1.416  		buffer[0] = '\0';
   1.417 -		fgets(buffer, sizeof(buffer)-1, fp);
   1.418 +		fgets(buffer, sizeof(buffer), fp);
   1.419  		length = strlen(buffer);
   1.420  		if (!length)
   1.421  			continue;
   1.422 @@ -618,11 +553,11 @@
   1.423  		{
   1.424  			continue;
   1.425  		}
   1.426 -		//First find if it's an absolute path or not...
   1.427 +		/* First find if it's an absolute path or not... */
   1.428  		if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
   1.429  		{
   1.430 -			//If we're in an absolute path, ignore our normal heuristics
   1.431 -			id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error)-1);
   1.432 +			/* If we're in an absolute path, ignore our normal heuristics */
   1.433 +			id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
   1.434  			if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
   1.435  			{
   1.436  				LogMessage("[META] Failed to load plugin %s.  %s", buffer, error);
   1.437 @@ -633,9 +568,9 @@
   1.438  					total++;
   1.439  			}
   1.440  		} else {
   1.441 -			//Attempt to find a file extension
   1.442 +			/* Attempt to find a file extension */
   1.443  			ptr = UTIL_GetExtension(file);
   1.444 -			//Add an extension if there's none there
   1.445 +			/* Add an extension if there's none there */
   1.446  			if (!ptr)
   1.447  			{
   1.448  #if defined WIN32 || defined _WIN32
   1.449 @@ -646,9 +581,9 @@
   1.450  			} else {
   1.451  				ext = "";
   1.452  			}
   1.453 -			//Format the new path
   1.454 -			g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), file, ext);
   1.455 -			id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error)-1);
   1.456 +			/* Format the new path */
   1.457 +			g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s%s", g_ModPath.c_str(), file, ext);
   1.458 +			id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
   1.459  			if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
   1.460  			{
   1.461  				LogMessage("[META] Failed to load plugin %s.  %s", buffer, error);
   1.462 @@ -672,22 +607,25 @@
   1.463  	return total;
   1.464  }
   1.465  
   1.466 -//Wrapper function.  This is called when the GameDLL thinks it's using
   1.467 -// the engine's real engineFactory.
   1.468 +/* Wrapper function.  This is called when the GameDLL thinks it's using
   1.469 + * the engine's real engineFactory.
   1.470 + */
   1.471  void *EngineFactory(const char *iface, int *ret)
   1.472  {
   1.473  	IFACE_MACRO(g_Engine.engineFactory, Engine);
   1.474  }
   1.475  
   1.476 -//Wrapper function.  This is called when the GameDLL thinks it's using
   1.477 -// the engine's real physicsFactory.
   1.478 +/* Wrapper function.  This is called when the GameDLL thinks it's using
   1.479 + * the engine's real physicsFactory.
   1.480 + */
   1.481  void *PhysicsFactory(const char *iface, int *ret)
   1.482  {
   1.483  	IFACE_MACRO(g_Engine.physicsFactory, Physics);
   1.484  }
   1.485  
   1.486 -//Wrapper function.  This is called when the GameDLL thinks it's using
   1.487 -// the engine's real fileSystemFactory.
   1.488 +/* Wrapper function.  This is called when the GameDLL thinks it's using
   1.489 + * the engine's real fileSystemFactory.
   1.490 + */
   1.491  void *FileSystemFactory(const char *iface, int *ret)
   1.492  {
   1.493  	IFACE_MACRO(g_Engine.fileSystemFactory, FileSystem);
   1.494 @@ -698,12 +636,12 @@
   1.495  	va_list ap;
   1.496  	static char buffer[2048];
   1.497  
   1.498 -	buffer[0] = '\0';
   1.499 +	va_start(ap, msg);
   1.500 +	size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
   1.501 +	va_end(ap);
   1.502  
   1.503 -	va_start(ap, msg);
   1.504 -	vsnprintf(buffer, sizeof(buffer)-5, msg, ap);
   1.505 -	strcat(buffer, "\n");
   1.506 -	va_end(ap);
   1.507 +	buffer[len++] = '\n';
   1.508 +	buffer[len] = '\0';
   1.509  
   1.510  	if (!g_Engine.engine)
   1.511  	{
   1.512 @@ -718,7 +656,7 @@
   1.513  	if (!bInFirstLevel)
   1.514  	{
   1.515  		char full_path[255];
   1.516 -		g_SmmAPI.PathFormat(full_path, sizeof(full_path) - 1, "%s/%s", g_ModPath.c_str(), GetPluginsFile());
   1.517 +		g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), GetPluginsFile());
   1.518  
   1.519  		LoadPluginsFromFile(full_path);
   1.520  	} else {