1.1 --- a/extensions/tf2/conditions.cpp Thu Dec 27 16:38:49 2012 -0500
1.2 +++ b/extensions/tf2/conditions.cpp Thu Dec 27 16:39:04 2012 -0500
1.3 @@ -33,35 +33,33 @@
1.4 #include "conditions.h"
1.5 #include "util.h"
1.6
1.7 -#include "bitvec.h"
1.8 -
1.9 #include <iplayerinfo.h>
1.10
1.11 -typedef CBitVec<96> condbits_t;
1.12 +typedef uint64_t condflags_t;
1.13
1.14 -condbits_t g_PlayerConds[MAXPLAYERS+1];
1.15 +condflags_t g_PlayerConds[MAXPLAYERS+1];
1.16
1.17 IForward *g_addCondForward = NULL;
1.18 IForward *g_removeCondForward = NULL;
1.19
1.20 int playerCondOffset = -1;
1.21 int playerCondExOffset = -1;
1.22 -int playerCondEx2Offset = -1;
1.23 int conditionBitsOffset = -1;
1.24
1.25 bool g_bIgnoreRemove;
1.26
1.27 -inline void GetPlayerConds(CBaseEntity *pPlayer, condbits_t *pOut)
1.28 +#define MAX_CONDS (sizeof(uint64_t) * 8)
1.29 +
1.30 +inline condflags_t GetPlayerConds(CBaseEntity *pPlayer)
1.31 {
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 + uint32_t playerCond = *(uint32_t *)((intptr_t)pPlayer + playerCondOffset);
1.37 + uint32_t condBits = *(uint32_t *)((intptr_t)pPlayer + conditionBitsOffset);
1.38 + uint32_t playerCondEx = *(uint32_t *)((intptr_t)pPlayer + playerCondExOffset);
1.39
1.40 - pOut->SetDWord(0, playerCond);
1.41 - pOut->Set(0u, condBits);
1.42 - pOut->SetDWord(1, playerCondEx);
1.43 - pOut->SetDWord(2, playerCondEx2);
1.44 + uint64_t playerCondExAdj = playerCondEx;
1.45 + playerCondExAdj <<= 32;
1.46 +
1.47 + return playerCond|condBits|playerCondExAdj;
1.48 }
1.49
1.50 void Conditions_OnGameFrame(bool simulating)
1.51 @@ -69,16 +67,14 @@
1.52 if (!simulating)
1.53 return;
1.54
1.55 - condbits_t *oldconds;
1.56 - condbits_t newconds;
1.57 + condflags_t oldconds;
1.58 + condflags_t newconds;
1.59
1.60 - condbits_t *addedconds;
1.61 - condbits_t *removedconds;
1.62 -
1.63 - int i, j;
1.64 + condflags_t addedconds;
1.65 + condflags_t removedconds;
1.66
1.67 int maxClients = gpGlobals->maxClients;
1.68 - for (i = 1; i <= maxClients; i++)
1.69 + for (int i = 1; i <= maxClients; i++)
1.70 {
1.71 IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i);
1.72 if (!pPlayer || !pPlayer->IsInGame())
1.73 @@ -89,39 +85,39 @@
1.74 continue;
1.75
1.76 CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(i);
1.77 - oldconds = &g_PlayerConds[i];
1.78 - GetPlayerConds(pEntity, &newconds);
1.79 + oldconds = g_PlayerConds[i];
1.80 + newconds = GetPlayerConds(pEntity);
1.81
1.82 - if (*oldconds == newconds)
1.83 + if (oldconds == newconds)
1.84 continue;
1.85
1.86 - addedconds = &newconds;
1.87 - for (j = 0; j < addedconds->GetNumDWords(); ++j)
1.88 + addedconds = newconds &~ oldconds;
1.89 + removedconds = oldconds &~ newconds;
1.90 +
1.91 + uint64_t j;
1.92 + condflags_t bit;
1.93 +
1.94 + for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= addedconds; j++)
1.95 {
1.96 - addedconds->Clear(j * sizeof(int), oldconds->GetDWord(j));
1.97 + if ((addedconds & bit) == bit)
1.98 + {
1.99 + g_addCondForward->PushCell(i);
1.100 + g_addCondForward->PushCell(j & 0xFFFFFFFF);
1.101 + g_addCondForward->Execute(NULL, NULL);
1.102 + }
1.103 }
1.104
1.105 - removedconds = oldconds;
1.106 - for (j = 0; j < removedconds->GetNumDWords(); ++j)
1.107 + for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= removedconds; j++)
1.108 {
1.109 - removedconds->Clear(j * sizeof(int), newconds.GetDWord(j));
1.110 + if ((removedconds & bit) == bit)
1.111 + {
1.112 + g_removeCondForward->PushCell(i);
1.113 + g_removeCondForward->PushCell(j & 0xFFFFFFFF);
1.114 + g_removeCondForward->Execute(NULL, NULL);
1.115 + }
1.116 }
1.117
1.118 - for (j = 0; (j = addedconds->FindNextSetBit( j )) != -1; ++j)
1.119 - {
1.120 - g_addCondForward->PushCell(i);
1.121 - g_addCondForward->PushCell(j);
1.122 - g_addCondForward->Execute(NULL, NULL);
1.123 - }
1.124 -
1.125 - for (j = 0; (j = addedconds->FindNextSetBit( j )) != -1; ++j)
1.126 - {
1.127 - g_removeCondForward->PushCell(i);
1.128 - g_removeCondForward->PushCell(j);
1.129 - g_removeCondForward->Execute(NULL, NULL);
1.130 - }
1.131 -
1.132 - g_PlayerConds[i].Copy( newconds );
1.133 + g_PlayerConds[i] = newconds;
1.134 }
1.135 }
1.136
1.137 @@ -152,21 +148,8 @@
1.138
1.139 playerCondExOffset = prop.actual_offset;
1.140
1.141 - if (!gamehelpers->FindSendPropInfo("CTFPlayer", "m_nPlayerCondEx2", &prop))
1.142 - {
1.143 - g_pSM->LogError(myself, "Failed to find m_nPlayerCondEx2 prop offset");
1.144 + if (playerCondOffset == -1 || playerCondExOffset == -1 || conditionBitsOffset == -1)
1.145 return false;
1.146 - }
1.147 -
1.148 - playerCondEx2Offset = prop.actual_offset;
1.149 -
1.150 - if (playerCondOffset == -1
1.151 - || playerCondExOffset == -1
1.152 - || playerCondEx2Offset == -1
1.153 - || conditionBitsOffset == -1)
1.154 - {
1.155 - return false;
1.156 - }
1.157
1.158 int maxClients = gpGlobals->maxClients;
1.159 for (int i = 1; i <= maxClients; i++)
1.160 @@ -175,7 +158,7 @@
1.161 if (!pPlayer || !pPlayer->IsInGame())
1.162 continue;
1.163
1.164 - GetPlayerConds(gamehelpers->ReferenceToEntity(i), &g_PlayerConds[i]);
1.165 + g_PlayerConds[i] = GetPlayerConds(gamehelpers->ReferenceToEntity(i));
1.166 }
1.167
1.168 g_pSM->AddGameFrameHook(Conditions_OnGameFrame);
1.169 @@ -185,7 +168,7 @@
1.170
1.171 void Conditions_OnClientPutInServer(int client)
1.172 {
1.173 - g_PlayerConds[client].Init();
1.174 + g_PlayerConds[client] = 0;
1.175 }
1.176
1.177 void RemoveConditionChecks()