Added support in TF2 ext for detection of player conds >= 64 (bug 5565, r=asherkin).

This commit is contained in:
Nicholas Hastings 2012-12-23 16:59:50 -05:00
parent 329616c029
commit ffd7603b17

View File

@ -33,33 +33,35 @@
#include "conditions.h" #include "conditions.h"
#include "util.h" #include "util.h"
#include "bitvec.h"
#include <iplayerinfo.h> #include <iplayerinfo.h>
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_addCondForward = NULL;
IForward *g_removeCondForward = NULL; IForward *g_removeCondForward = NULL;
int playerCondOffset = -1; int playerCondOffset = -1;
int playerCondExOffset = -1; int playerCondExOffset = -1;
int playerCondEx2Offset = -1;
int conditionBitsOffset = -1; int conditionBitsOffset = -1;
bool g_bIgnoreRemove; bool g_bIgnoreRemove;
#define MAX_CONDS (sizeof(uint64_t) * 8) inline void GetPlayerConds(CBaseEntity *pPlayer, condbits_t *pOut)
inline condflags_t GetPlayerConds(CBaseEntity *pPlayer)
{ {
uint32_t playerCond = *(uint32_t *)((intptr_t)pPlayer + playerCondOffset); uint32_t playerCond = *(uint32_t *)((intptr_t)pPlayer + playerCondOffset);
uint32_t condBits = *(uint32_t *)((intptr_t)pPlayer + conditionBitsOffset); uint32_t condBits = *(uint32_t *)((intptr_t)pPlayer + conditionBitsOffset);
uint32_t playerCondEx = *(uint32_t *)((intptr_t)pPlayer + playerCondExOffset); uint32_t playerCondEx = *(uint32_t *)((intptr_t)pPlayer + playerCondExOffset);
uint32_t playerCondEx2 = *(uint32_t *)((intptr_t)pPlayer + playerCondEx2Offset);
uint64_t playerCondExAdj = playerCondEx; pOut->SetDWord(0, playerCond);
playerCondExAdj <<= 32; pOut->Set(0u, condBits);
pOut->SetDWord(1, playerCondEx);
return playerCond|condBits|playerCondExAdj; pOut->SetDWord(2, playerCondEx2);
} }
void Conditions_OnGameFrame(bool simulating) void Conditions_OnGameFrame(bool simulating)
@ -67,14 +69,16 @@ void Conditions_OnGameFrame(bool simulating)
if (!simulating) if (!simulating)
return; return;
condflags_t oldconds; condbits_t *oldconds;
condflags_t newconds; condbits_t newconds;
condflags_t addedconds; condbits_t *addedconds;
condflags_t removedconds; condbits_t *removedconds;
int i, j;
int maxClients = gpGlobals->maxClients; int maxClients = gpGlobals->maxClients;
for (int i = 1; i <= maxClients; i++) for (i = 1; i <= maxClients; i++)
{ {
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i); IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i);
if (!pPlayer || !pPlayer->IsInGame()) if (!pPlayer || !pPlayer->IsInGame())
@ -85,39 +89,39 @@ void Conditions_OnGameFrame(bool simulating)
continue; continue;
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(i); CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(i);
oldconds = g_PlayerConds[i]; oldconds = &g_PlayerConds[i];
newconds = GetPlayerConds(pEntity); GetPlayerConds(pEntity, &newconds);
if (oldconds == newconds) if (*oldconds == newconds)
continue; continue;
addedconds = newconds &~ oldconds; addedconds = &newconds;
removedconds = oldconds &~ newconds; for (j = 0; j < addedconds->GetNumDWords(); ++j)
uint64_t j;
condflags_t bit;
for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= addedconds; j++)
{ {
if ((addedconds & bit) == bit) addedconds->Clear(j * sizeof(int), oldconds->GetDWord(j));
{
g_addCondForward->PushCell(i);
g_addCondForward->PushCell(j & 0xFFFFFFFF);
g_addCondForward->Execute(NULL, NULL);
}
} }
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) removedconds->Clear(j * sizeof(int), newconds.GetDWord(j));
{
g_removeCondForward->PushCell(i);
g_removeCondForward->PushCell(j & 0xFFFFFFFF);
g_removeCondForward->Execute(NULL, NULL);
}
} }
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; 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; return false;
}
playerCondEx2Offset = prop.actual_offset;
if (playerCondOffset == -1
|| playerCondExOffset == -1
|| playerCondEx2Offset == -1
|| conditionBitsOffset == -1)
{
return false;
}
int maxClients = gpGlobals->maxClients; int maxClients = gpGlobals->maxClients;
for (int i = 1; i <= maxClients; i++) for (int i = 1; i <= maxClients; i++)
@ -158,7 +175,7 @@ bool InitialiseConditionChecks()
if (!pPlayer || !pPlayer->IsInGame()) if (!pPlayer || !pPlayer->IsInGame())
continue; continue;
g_PlayerConds[i] = GetPlayerConds(gamehelpers->ReferenceToEntity(i)); GetPlayerConds(gamehelpers->ReferenceToEntity(i), &g_PlayerConds[i]);
} }
g_pSM->AddGameFrameHook(Conditions_OnGameFrame); g_pSM->AddGameFrameHook(Conditions_OnGameFrame);
@ -168,7 +185,7 @@ bool InitialiseConditionChecks()
void Conditions_OnClientPutInServer(int client) void Conditions_OnClientPutInServer(int client)
{ {
g_PlayerConds[client] = 0; g_PlayerConds[client].Init();
} }
void RemoveConditionChecks() void RemoveConditionChecks()