Fix for SDKTools TeamScore natives crash on CS:GO (bug 5319, r=psychonic).
authorDrifter <rgr_02@comcast.net>
Wed May 30 23:00:16 2012 -0400 (2012-05-30)
changeset 35439287a18e9a33
parent 3542 b5825b6f43ed
child 3544 517507b8a2a8
Fix for SDKTools TeamScore natives crash on CS:GO (bug 5319, r=psychonic).
extensions/sdktools/teamnatives.cpp
gamedata/sdktools.games/common.games.txt
gamedata/sdktools.games/engine.csgo.txt
     1.1 --- a/extensions/sdktools/teamnatives.cpp	Wed May 30 22:37:41 2012 -0400
     1.2 +++ b/extensions/sdktools/teamnatives.cpp	Wed May 30 23:00:16 2012 -0400
     1.3 @@ -38,6 +38,8 @@
     1.4  	CBaseEntity *pEnt;
     1.5  };
     1.6  
     1.7 +const char *m_iScore;
     1.8 +
     1.9  SourceHook::CVector<TeamInfo> g_Teams;
    1.10  
    1.11  bool FindTeamEntities(SendTable *pTable, const char *name)
    1.12 @@ -157,7 +159,27 @@
    1.13  		return pContext->ThrowNativeError("Team index %d is invalid", teamindex);
    1.14  	}
    1.15  
    1.16 -	static int offset = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_iScore")->GetOffset();
    1.17 +	if (!m_iScore)
    1.18 +	{
    1.19 +		m_iScore = g_pGameConf->GetKeyValue("m_iScore");
    1.20 +		if (!m_iScore)
    1.21 +		{
    1.22 +			return pContext->ThrowNativeError("Failed to get m_iScore key");
    1.23 +		}
    1.24 +	}
    1.25 +
    1.26 +	static int offset = -1;
    1.27 +
    1.28 +	if (offset == -1)
    1.29 +	{
    1.30 +		SendProp *prop = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, m_iScore);
    1.31 +		if (!prop)
    1.32 +		{
    1.33 +			return pContext->ThrowNativeError("Failed to get m_iScore prop");
    1.34 +		}
    1.35 +		offset = prop->GetOffset();
    1.36 +	}
    1.37 +
    1.38  
    1.39  	return *(int *)((unsigned char *)g_Teams[teamindex].pEnt + offset);
    1.40  }
    1.41 @@ -170,7 +192,26 @@
    1.42  		return pContext->ThrowNativeError("Team index %d is invalid", teamindex);
    1.43  	}
    1.44  
    1.45 -	static int offset = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_iScore")->GetOffset();
    1.46 +	if (m_iScore == NULL)
    1.47 +	{
    1.48 +		m_iScore = g_pGameConf->GetKeyValue("m_iScore");
    1.49 +		if (m_iScore == NULL)
    1.50 +		{
    1.51 +			return pContext->ThrowNativeError("Failed to get m_iScore key");
    1.52 +		}
    1.53 +	}
    1.54 +
    1.55 +	static int offset = -1;
    1.56 +
    1.57 +	if (offset == -1)
    1.58 +	{
    1.59 +		SendProp *prop = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, m_iScore);
    1.60 +		if (!prop)
    1.61 +		{
    1.62 +			return pContext->ThrowNativeError("Failed to get m_iScore prop");
    1.63 +		}
    1.64 +		offset = prop->GetOffset();
    1.65 +	}
    1.66  
    1.67  	CBaseEntity *pTeam = g_Teams[teamindex].pEnt;
    1.68  	*(int *)((unsigned char *)pTeam + offset) = params[2];
     2.1 --- a/gamedata/sdktools.games/common.games.txt	Wed May 30 22:37:41 2012 -0400
     2.2 +++ b/gamedata/sdktools.games/common.games.txt	Wed May 30 23:00:16 2012 -0400
     2.3 @@ -18,6 +18,8 @@
     2.4  		"Keys"
     2.5  		{
     2.6  			"m_iFrags"		"m_iFrags"
     2.7 +			// Netprop on the team entity for team score
     2.8 +			"m_iScore"		"m_iScore"
     2.9  		}
    2.10  		
    2.11  		"Offsets"
     3.1 --- a/gamedata/sdktools.games/engine.csgo.txt	Wed May 30 22:37:41 2012 -0400
     3.2 +++ b/gamedata/sdktools.games/engine.csgo.txt	Wed May 30 23:00:16 2012 -0400
     3.3 @@ -225,6 +225,11 @@
     3.4  	
     3.5  	"csgo"
     3.6  	{
     3.7 +		"Keys"
     3.8 +		{
     3.9 +			// Netprop on the team entity for team score
    3.10 +			"m_iScore"		"m_scoreTotal"
    3.11 +		}
    3.12  		"Offsets"
    3.13  		{
    3.14  			"GiveNamedItem"