sourcemm/sourcemm.cpp
changeset 205 08964c08d894
parent 192 47649a1d49e3
child 215 e3b5d251a9dd
     1.1 --- a/sourcemm/sourcemm.cpp	Fri May 19 13:57:04 2006 +0000
     1.2 +++ b/sourcemm/sourcemm.cpp	Thu May 25 04:49:47 2006 +0000
     1.3 @@ -376,10 +376,13 @@
     1.4  		{
     1.5  			//This is the interface we want!  Right now we support versions 3 and 4.
     1.6  			int version = atoi(&(iface[len]));
     1.7 +			int sizeTooBig = 0;	//rename this to sizeWrong in the future!
     1.8  			if (version < MIN_GAMEDLL_VERSION || version > MAX_GAMEDLL_VERSION)
     1.9  			{
    1.10 -				Error("GameDLL version %d is not supported by Metamod!", version);
    1.11 -				return NULL;
    1.12 +				//maybe this will get used in the future
    1.13 +				sizeTooBig = version;
    1.14 +				if (ret)
    1.15 +					*ret = IFACE_FAILED;
    1.16  			}
    1.17  			SourceHook::List<GameDllInfo *>::iterator iter;
    1.18  			GameDllInfo *pInfo = NULL;
    1.19 @@ -401,8 +404,17 @@
    1.20  			}
    1.21  			if (g_GameDll.loaded)
    1.22  			{
    1.23 -				InitMainStates();
    1.24 +				if (sizeTooBig)
    1.25 +				{
    1.26 +					Error("This mod version requires a SourceMM update (ServerGameDLL%03d)!", sizeTooBig);
    1.27 +					if (ret)
    1.28 +						*ret = IFACE_FAILED;
    1.29 +					return NULL;
    1.30 +				} else {
    1.31 +					InitMainStates();
    1.32 +				}
    1.33  			} else {
    1.34 +				sizeTooBig = 0;
    1.35  				if (ret)
    1.36  					*ret = IFACE_FAILED;
    1.37  				return NULL;
    1.38 @@ -457,22 +469,22 @@
    1.39  	RETURN_META(MRES_SUPERCEDE);
    1.40  }
    1.41  
    1.42 -int LoadPluginsFromFile(const char *file)
    1.43 +int LoadPluginsFromFile(const char *_file)
    1.44  {
    1.45  	FILE *fp;
    1.46  	int total = 0, skipped=0;
    1.47  	PluginId id;
    1.48  	bool already;
    1.49  
    1.50 -	fp = fopen(file, "rt");
    1.51 +	fp = fopen(_file, "rt");
    1.52  	if (!fp)
    1.53  	{
    1.54 -		LogMessage("[META] Could not open plugins file %s\n", file);
    1.55 +		LogMessage("[META] Could not open plugins file %s\n", _file);
    1.56  		return -1;
    1.57  	}
    1.58  
    1.59  	char buffer[255], error[255], full_path[128];
    1.60 -	const char *ptr, *ext;
    1.61 +	const char *ptr, *ext, *file;
    1.62  	size_t length;
    1.63  	while (!feof(fp))
    1.64  	{
    1.65 @@ -482,18 +494,58 @@
    1.66  		if (!length)
    1.67  			continue;
    1.68  		if (buffer[length-1] == '\n')
    1.69 -			buffer[length-1] = '\0';
    1.70 +			buffer[--length] = '\0';
    1.71  
    1.72  		UTIL_TrimLeft(buffer);
    1.73  		UTIL_TrimRight(buffer);
    1.74  
    1.75  		if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
    1.76  			continue;
    1.77 +		file = buffer;
    1.78 +		if (buffer[0] == '"')
    1.79 +		{
    1.80 +			char *cptr = buffer;
    1.81 +			file = ++cptr;
    1.82 +
    1.83 +			while (*cptr)
    1.84 +			{
    1.85 +				if (*cptr == '"')
    1.86 +				{
    1.87 +					*cptr = '\0';
    1.88 +					break;
    1.89 +				}
    1.90 +				cptr++;
    1.91 +			}
    1.92 +		} else {
    1.93 +			char *cptr = buffer;
    1.94 +			while (*cptr)
    1.95 +			{
    1.96 +				if (isspace(*cptr))
    1.97 +				{
    1.98 +					char *optr = cptr;
    1.99 +					while (*cptr && isspace(*cptr))
   1.100 +						cptr++;
   1.101 +					*optr = '\0';
   1.102 +					UTIL_TrimRight(cptr);
   1.103 +					if (*cptr && isalpha(*cptr))
   1.104 +					{
   1.105 +						g_PluginMngr.SetAlias(buffer, cptr);
   1.106 +						file = cptr;
   1.107 +					}
   1.108 +					break;
   1.109 +				}
   1.110 +				cptr++;
   1.111 +			}
   1.112 +		}
   1.113 +		if (!file[0])
   1.114 +		{
   1.115 +			continue;
   1.116 +		}
   1.117  		//First find if it's an absolute path or not...
   1.118 -		if (buffer[0] == '/' || strncmp(&(buffer[1]), ":\\", 2) == 0)
   1.119 +		if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
   1.120  		{
   1.121  			//If we're in an absolute path, ignore our normal heuristics
   1.122 -			id = g_PluginMngr.Load(buffer, Pl_File, already, error, sizeof(error)-1);
   1.123 +			id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error)-1);
   1.124  			if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
   1.125  			{
   1.126  				LogMessage("[META] Failed to load plugin %s.  %s", buffer, error);
   1.127 @@ -505,7 +557,7 @@
   1.128  			}
   1.129  		} else {
   1.130  			//Attempt to find a file extension
   1.131 -			ptr = UTIL_GetExtension(buffer);
   1.132 +			ptr = UTIL_GetExtension(file);
   1.133  			//Add an extension if there's none there
   1.134  			if (!ptr)
   1.135  			{
   1.136 @@ -518,7 +570,7 @@
   1.137  				ext = "";
   1.138  			}
   1.139  			//Format the new path
   1.140 -			g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), buffer, ext);
   1.141 +			g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), file, ext);
   1.142  			id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error)-1);
   1.143  			if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
   1.144  			{