Use Linux game data for offsets and signatures/symbols on OS X if Mac-specific data is not available (bug 6056, r=dvander).
authorScott Ehlert <ds@alliedmods.net>
Sat Feb 15 23:23:53 2014 -0600 (2014-02-15)
changeset 4254614308e8e6c8
parent 4253 b9d5c01a5a3b
child 4255 dbfcf51478ee
Use Linux game data for offsets and signatures/symbols on OS X if Mac-specific data is not available (bug 6056, r=dvander).

Although unlikely, OS X game data can also be used on Linux if Linux-specfic data is missing.
core/logic/GameConfigs.cpp
core/logic/GameConfigs.h
     1.1 --- a/core/logic/GameConfigs.cpp	Sat Feb 15 17:13:13 2014 -0800
     1.2 +++ b/core/logic/GameConfigs.cpp	Sat Feb 15 23:23:53 2014 -0600
     1.3 @@ -77,10 +77,12 @@
     1.4  #define PLATFORM_SERVER_BINARY		"server.dll"
     1.5  #elif defined PLATFORM_LINUX
     1.6  #define PLATFORM_NAME				"linux"
     1.7 +#define PLATFORM_COMPAT_ALT			"mac"				/* Alternate platform name if game data is missing for primary one */
     1.8  #define PLATFORM_SERVER_BINARY		"server_i486.so"
     1.9  #elif defined PLATFORM_APPLE
    1.10 -#define PLATFORM_NAME               "mac"
    1.11 -#define PLATFORM_SERVER_BINARY      "server.dylib"
    1.12 +#define PLATFORM_NAME				"mac"
    1.13 +#define PLATFORM_COMPAT_ALT			"linux"
    1.14 +#define PLATFORM_SERVER_BINARY		"server.dylib"
    1.15  #endif
    1.16  
    1.17  struct TempSigInfo
    1.18 @@ -116,6 +118,30 @@
    1.19  	return strcmp(value, g_pParseEngine) == 0;
    1.20  }
    1.21  
    1.22 +static inline bool DoesPlatformMatch(const char *platform)
    1.23 +{
    1.24 +	return strcmp(platform, PLATFORM_NAME) == 0;
    1.25 +}
    1.26 +
    1.27 +static inline bool IsPlatformCompatible(const char *platform, bool *hadPrimaryMatch)
    1.28 +{
    1.29 +	if (DoesPlatformMatch(platform))
    1.30 +	{
    1.31 +#if defined PLATFORM_COMPAT_ALT
    1.32 +		*hadPrimaryMatch = true;
    1.33 +#endif
    1.34 +		return true;
    1.35 +	}
    1.36 +
    1.37 +#if defined PLATFORM_COMPAT_ALT
    1.38 +	/* If entry hasn't been found for the primary platform name, check for compatible alternate */
    1.39 +	if (!*hadPrimaryMatch)
    1.40 +		return strcmp(platform, PLATFORM_COMPAT_ALT) == 0;
    1.41 +#endif
    1.42 +
    1.43 +	return false;
    1.44 +}
    1.45 +
    1.46  CGameConfig::CGameConfig(const char *file, const char *engine)
    1.47  {
    1.48  	strncopy(m_File, file, sizeof(m_File));
    1.49 @@ -228,6 +254,7 @@
    1.50  			m_Class[0] = '\0';
    1.51  			strncopy(m_offset, name, sizeof(m_offset));
    1.52  			m_ParseState = PSTATE_GAMEDEFS_OFFSETS_OFFSET;
    1.53 +			matched_platform = false;
    1.54  			break;
    1.55  		}
    1.56  	case PSTATE_GAMEDEFS_SIGNATURES:
    1.57 @@ -235,6 +262,7 @@
    1.58  			strncopy(m_offset, name, sizeof(m_offset));
    1.59  			s_TempSig.Reset();
    1.60  			m_ParseState = PSTATE_GAMEDEFS_SIGNATURES_SIG;
    1.61 +			matched_platform = false;
    1.62  			break;
    1.63  		}
    1.64  	case PSTATE_GAMEDEFS_CRC:
    1.65 @@ -299,7 +327,7 @@
    1.66  		}
    1.67  	case PSTATE_GAMEDEFS_ADDRESSES_ADDRESS:
    1.68  		{
    1.69 -			if (strcmp(name, PLATFORM_NAME) == 0)
    1.70 +			if (DoesPlatformMatch(name))
    1.71  			{
    1.72  				m_ParseState = PSTATE_GAMEDEFS_ADDRESSES_ADDRESS_READ;
    1.73  			}
    1.74 @@ -347,7 +375,7 @@
    1.75  			strncopy(m_Class, value, sizeof(m_Class));
    1.76  		} else if (strcmp(key, "prop") == 0) {
    1.77  			strncopy(m_Prop, value, sizeof(m_Prop));
    1.78 -		} else if (strcmp(key, PLATFORM_NAME) == 0) {
    1.79 +		} else if (IsPlatformCompatible(key, &matched_platform)) {
    1.80  			m_Offsets.replace(m_offset, atoi(value));
    1.81  		}
    1.82  	} else if (m_ParseState == PSTATE_GAMEDEFS_KEYS) {
    1.83 @@ -379,14 +407,14 @@
    1.84  			}
    1.85  		}
    1.86  	} else if (m_ParseState == PSTATE_GAMEDEFS_SIGNATURES_SIG) {
    1.87 -		if (strcmp(key, PLATFORM_NAME) == 0)
    1.88 +		if (IsPlatformCompatible(key, &matched_platform))
    1.89  		{
    1.90  			strncopy(s_TempSig.sig, value, sizeof(s_TempSig.sig));
    1.91  		} else if (strcmp(key, "library") == 0) {
    1.92  			strncopy(s_TempSig.library, value, sizeof(s_TempSig.library));
    1.93  		}
    1.94  	} else if (m_ParseState == PSTATE_GAMEDEFS_CRC_BINARY) {
    1.95 -		if (strcmp(key, PLATFORM_NAME) == 0 
    1.96 +		if (DoesPlatformMatch(key)
    1.97  			&& s_ServerBinCRC_Ok
    1.98  			&& !bShouldBeReadingDefault)
    1.99  		{
     2.1 --- a/core/logic/GameConfigs.h	Sat Feb 15 17:13:13 2014 -0800
     2.2 +++ b/core/logic/GameConfigs.h	Sat Feb 15 23:23:53 2014 -0600
     2.3 @@ -92,6 +92,7 @@
     2.4  	bool matched_game;
     2.5  	bool had_engine;
     2.6  	bool matched_engine;
     2.7 +	bool matched_platform;
     2.8  
     2.9  	/* Custom Sections */
    2.10  	unsigned int m_CustomLevel;