From ffd7603b17cf9ab6225f5319f0f97ebb8f1abb77 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Sun, 23 Dec 2012 16:59:50 -0500 Subject: [PATCH] Added support in TF2 ext for detection of player conds >= 64 (bug 5565, r=asherkin). --- extensions/tf2/conditions.cpp | 105 ++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 44 deletions(-) diff --git a/extensions/tf2/conditions.cpp b/extensions/tf2/conditions.cpp index 9a2e5543..523f1907 100644 --- a/extensions/tf2/conditions.cpp +++ b/extensions/tf2/conditions.cpp @@ -33,33 +33,35 @@ #include "conditions.h" #include "util.h" +#include "bitvec.h" + #include -typedef uint64_t condflags_t; +typedef CBitVec<96> condbits_t; -condflags_t g_PlayerConds[MAXPLAYERS+1]; +condbits_t g_PlayerConds[MAXPLAYERS+1]; IForward *g_addCondForward = NULL; IForward *g_removeCondForward = NULL; int playerCondOffset = -1; int playerCondExOffset = -1; +int playerCondEx2Offset = -1; int conditionBitsOffset = -1; bool g_bIgnoreRemove; -#define MAX_CONDS (sizeof(uint64_t) * 8) - -inline condflags_t GetPlayerConds(CBaseEntity *pPlayer) +inline void GetPlayerConds(CBaseEntity *pPlayer, condbits_t *pOut) { - uint32_t playerCond = *(uint32_t *)((intptr_t)pPlayer + playerCondOffset); - uint32_t condBits = *(uint32_t *)((intptr_t)pPlayer + conditionBitsOffset); - uint32_t playerCondEx = *(uint32_t *)((intptr_t)pPlayer + playerCondExOffset); + uint32_t playerCond = *(uint32_t *)((intptr_t)pPlayer + playerCondOffset); + uint32_t condBits = *(uint32_t *)((intptr_t)pPlayer + conditionBitsOffset); + uint32_t playerCondEx = *(uint32_t *)((intptr_t)pPlayer + playerCondExOffset); + uint32_t playerCondEx2 = *(uint32_t *)((intptr_t)pPlayer + playerCondEx2Offset); - uint64_t playerCondExAdj = playerCondEx; - playerCondExAdj <<= 32; - - return playerCond|condBits|playerCondExAdj; + pOut->SetDWord(0, playerCond); + pOut->Set(0u, condBits); + pOut->SetDWord(1, playerCondEx); + pOut->SetDWord(2, playerCondEx2); } void Conditions_OnGameFrame(bool simulating) @@ -67,14 +69,16 @@ void Conditions_OnGameFrame(bool simulating) if (!simulating) return; - condflags_t oldconds; - condflags_t newconds; + condbits_t *oldconds; + condbits_t newconds; - condflags_t addedconds; - condflags_t removedconds; + condbits_t *addedconds; + condbits_t *removedconds; + + int i, j; int maxClients = gpGlobals->maxClients; - for (int i = 1; i <= maxClients; i++) + for (i = 1; i <= maxClients; i++) { IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i); if (!pPlayer || !pPlayer->IsInGame()) @@ -85,39 +89,39 @@ void Conditions_OnGameFrame(bool simulating) continue; CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(i); - oldconds = g_PlayerConds[i]; - newconds = GetPlayerConds(pEntity); + oldconds = &g_PlayerConds[i]; + GetPlayerConds(pEntity, &newconds); - if (oldconds == newconds) + if (*oldconds == newconds) continue; - addedconds = newconds &~ oldconds; - removedconds = oldconds &~ newconds; - - uint64_t j; - condflags_t bit; - - for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= addedconds; j++) + addedconds = &newconds; + for (j = 0; j < addedconds->GetNumDWords(); ++j) { - if ((addedconds & bit) == bit) - { - g_addCondForward->PushCell(i); - g_addCondForward->PushCell(j & 0xFFFFFFFF); - g_addCondForward->Execute(NULL, NULL); - } + addedconds->Clear(j * sizeof(int), oldconds->GetDWord(j)); } - for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= removedconds; j++) + removedconds = oldconds; + for (j = 0; j < removedconds->GetNumDWords(); ++j) { - if ((removedconds & bit) == bit) - { - g_removeCondForward->PushCell(i); - g_removeCondForward->PushCell(j & 0xFFFFFFFF); - g_removeCondForward->Execute(NULL, NULL); - } + removedconds->Clear(j * sizeof(int), newconds.GetDWord(j)); } - g_PlayerConds[i] = newconds; + for (j = 0; (j = addedconds->FindNextSetBit( j )) != -1; ++j) + { + g_addCondForward->PushCell(i); + g_addCondForward->PushCell(j); + g_addCondForward->Execute(NULL, NULL); + } + + for (j = 0; (j = addedconds->FindNextSetBit( j )) != -1; ++j) + { + g_removeCondForward->PushCell(i); + g_removeCondForward->PushCell(j); + g_removeCondForward->Execute(NULL, NULL); + } + + g_PlayerConds[i].Copy( newconds ); } } @@ -148,8 +152,21 @@ bool InitialiseConditionChecks() playerCondExOffset = prop.actual_offset; - if (playerCondOffset == -1 || playerCondExOffset == -1 || conditionBitsOffset == -1) + if (!gamehelpers->FindSendPropInfo("CTFPlayer", "m_nPlayerCondEx2", &prop)) + { + g_pSM->LogError(myself, "Failed to find m_nPlayerCondEx2 prop offset"); return false; + } + + playerCondEx2Offset = prop.actual_offset; + + if (playerCondOffset == -1 + || playerCondExOffset == -1 + || playerCondEx2Offset == -1 + || conditionBitsOffset == -1) + { + return false; + } int maxClients = gpGlobals->maxClients; for (int i = 1; i <= maxClients; i++) @@ -158,7 +175,7 @@ bool InitialiseConditionChecks() if (!pPlayer || !pPlayer->IsInGame()) continue; - g_PlayerConds[i] = GetPlayerConds(gamehelpers->ReferenceToEntity(i)); + GetPlayerConds(gamehelpers->ReferenceToEntity(i), &g_PlayerConds[i]); } g_pSM->AddGameFrameHook(Conditions_OnGameFrame); @@ -168,7 +185,7 @@ bool InitialiseConditionChecks() void Conditions_OnClientPutInServer(int client) { - g_PlayerConds[client] = 0; + g_PlayerConds[client].Init(); } void RemoveConditionChecks()