Add support for tracking player conditions >= 64. (bug 5565, r=asherkin)
authorFlaminSarge <flaminsarge@gmail.com>
Mon Aug 12 01:11:11 2013 +0100 (2013-08-12)
changeset 4000da351d296ff8
parent 3999 02b80e8be3e3
child 4001 608bc5be1ef0
Add support for tracking player conditions >= 64. (bug 5565, r=asherkin)
extensions/tf2/conditions.cpp
     1.1 --- a/extensions/tf2/conditions.cpp	Mon Aug 12 00:58:43 2013 +0100
     1.2 +++ b/extensions/tf2/conditions.cpp	Mon Aug 12 01:11:11 2013 +0100
     1.3 @@ -35,7 +35,11 @@
     1.4  
     1.5  #include <iplayerinfo.h>
     1.6  
     1.7 -typedef uint64_t condflags_t;
     1.8 +typedef struct condflags_s {
     1.9 +	uint64_t upper;
    1.10 +	uint64_t lower;
    1.11 +} condflags_t;
    1.12 +condflags_t condflags_empty = { 0, 0 };
    1.13  
    1.14  condflags_t g_PlayerConds[MAXPLAYERS+1];
    1.15  
    1.16 @@ -44,6 +48,7 @@
    1.17  
    1.18  int playerCondOffset = -1;
    1.19  int playerCondExOffset = -1;
    1.20 +int playerCondEx2Offset = -1;
    1.21  int conditionBitsOffset = -1;
    1.22  
    1.23  bool g_bIgnoreRemove;
    1.24 @@ -52,14 +57,18 @@
    1.25  
    1.26  inline condflags_t GetPlayerConds(CBaseEntity *pPlayer)
    1.27  {
    1.28 -	uint32_t playerCond   =  *(uint32_t *)((intptr_t)pPlayer + playerCondOffset);
    1.29 -	uint32_t condBits     =  *(uint32_t *)((intptr_t)pPlayer + conditionBitsOffset);
    1.30 -	uint32_t playerCondEx =  *(uint32_t *)((intptr_t)pPlayer + playerCondExOffset);
    1.31 +	condflags_t result;
    1.32 +	uint32_t playerCond    =  *(uint32_t *)((intptr_t)pPlayer + playerCondOffset);
    1.33 +	uint32_t condBits      =  *(uint32_t *)((intptr_t)pPlayer + conditionBitsOffset);
    1.34 +	uint32_t playerCondEx  =  *(uint32_t *)((intptr_t)pPlayer + playerCondExOffset);
    1.35 +	uint32_t playerCondEx2 =  *(uint32_t *)((intptr_t)pPlayer + playerCondEx2Offset);
    1.36  
    1.37  	uint64_t playerCondExAdj = playerCondEx;
    1.38  	playerCondExAdj <<= 32;
    1.39  
    1.40 -	return playerCond|condBits|playerCondExAdj;
    1.41 +	result.lower = playerCond|condBits|playerCondExAdj;
    1.42 +	result.upper = playerCondEx2;
    1.43 +	return result;
    1.44  }
    1.45  
    1.46  void Conditions_OnGameFrame(bool simulating)
    1.47 @@ -88,33 +97,49 @@
    1.48  		oldconds = g_PlayerConds[i];
    1.49  		newconds = GetPlayerConds(pEntity);
    1.50  
    1.51 -		if (oldconds == newconds)
    1.52 +		if (oldconds.lower == newconds.lower && oldconds.upper == newconds.upper)
    1.53  			continue;
    1.54  
    1.55 -		addedconds = newconds &~ oldconds;
    1.56 -		removedconds = oldconds &~ newconds;
    1.57 +		addedconds.lower = newconds.lower &~ oldconds.lower;
    1.58 +		removedconds.lower = oldconds.lower &~ newconds.lower;
    1.59 +		addedconds.upper = newconds.upper &~ oldconds.upper;
    1.60 +		removedconds.upper = oldconds.upper &~ newconds.upper;
    1.61  
    1.62  		uint64_t j;
    1.63 -		condflags_t bit;
    1.64 +		uint64_t bit;
    1.65  
    1.66 -		for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= addedconds; j++)
    1.67 +		uint64_t maxbit = max(addedconds.lower, addedconds.upper);
    1.68 +		for (j = 0; j < MAX_CONDS && (bit = ((uint64_t)1 << j)) <= maxbit; j++)
    1.69  		{
    1.70 -			if ((addedconds & bit) == bit)
    1.71 +			if ((addedconds.lower & bit) == bit)
    1.72  			{
    1.73  				g_addCondForward->PushCell(i);
    1.74  				g_addCondForward->PushCell(j & 0xFFFFFFFF);
    1.75  				g_addCondForward->Execute(NULL, NULL);
    1.76  			}
    1.77 +			if ((addedconds.upper & bit) == bit)
    1.78 +			{
    1.79 +				g_addCondForward->PushCell(i);
    1.80 +				g_addCondForward->PushCell((j+64) & 0xFFFFFFFF);
    1.81 +				g_addCondForward->Execute(NULL, NULL);
    1.82 +			}
    1.83  		}
    1.84  
    1.85 -		for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= removedconds; j++)
    1.86 +		maxbit = max(removedconds.lower, removedconds.upper);
    1.87 +		for (j = 0; j < MAX_CONDS && (bit = ((uint64_t)1 << j)) <= maxbit; j++)
    1.88  		{
    1.89 -			if ((removedconds & bit) == bit)
    1.90 +			if ((removedconds.lower & bit) == bit)
    1.91  			{
    1.92  				g_removeCondForward->PushCell(i);
    1.93  				g_removeCondForward->PushCell(j & 0xFFFFFFFF);
    1.94  				g_removeCondForward->Execute(NULL, NULL);
    1.95  			}
    1.96 +			if ((removedconds.upper & bit) == bit)
    1.97 +			{
    1.98 +				g_removeCondForward->PushCell(i);
    1.99 +				g_removeCondForward->PushCell((j+64) & 0xFFFFFFFF);
   1.100 +				g_removeCondForward->Execute(NULL, NULL);
   1.101 +			}
   1.102  		}
   1.103  
   1.104  		g_PlayerConds[i] = newconds;
   1.105 @@ -148,7 +173,15 @@
   1.106  	
   1.107  	playerCondExOffset = prop.actual_offset;
   1.108  
   1.109 -	if (playerCondOffset == -1 || playerCondExOffset == -1 || conditionBitsOffset == -1)
   1.110 +	if (!gamehelpers->FindSendPropInfo("CTFPlayer", "m_nPlayerCondEx2", &prop))
   1.111 +	{
   1.112 +		g_pSM->LogError(myself, "Failed to find m_nPlayerCondEx2 prop offset");
   1.113 +		return false;
   1.114 +	}
   1.115 +	
   1.116 +	playerCondEx2Offset = prop.actual_offset;
   1.117 +
   1.118 +	if (playerCondOffset == -1 || playerCondExOffset == -1 || conditionBitsOffset == -1 || playerCondEx2Offset == -1)
   1.119  		return false;
   1.120  	
   1.121  	int maxClients = gpGlobals->maxClients;
   1.122 @@ -168,7 +201,7 @@
   1.123  
   1.124  void Conditions_OnClientPutInServer(int client)
   1.125  {
   1.126 -	g_PlayerConds[client] = 0;
   1.127 +	g_PlayerConds[client] = condflags_empty;
   1.128  }
   1.129  
   1.130  void RemoveConditionChecks()