deal with instant respawn damage desync better

This commit is contained in:
rei-2
2025-11-17 20:44:10 -05:00
parent 007e9b67f2
commit 5c07aa1283
2 changed files with 18 additions and 4 deletions
+16 -3
View File
@@ -433,7 +433,10 @@ void CCritHack::Event(IGameEvent* pEvent, uint32_t uHash, CTFPlayer* pLocal)
auto pVictim = I::ClientEntityList->GetClientEntity(iVictim)->As<CTFPlayer>();
if (!iHealth)
{
iDamage = std::clamp(iDamage, 0, tHistory.m_iNewHealth);
tHistory.m_iSpawnCounter = -1;
}
else if (pVictim && (pVictim->m_bFeignDeathReady() || pVictim->InCond(TF_COND_FEIGN_DEATH))) // damage number is spoofed upon sending, correct it
{
int iOldHealth = (tHistory.m_mHistory.contains(iHealth) ? tHistory.m_mHistory[iHealth].m_iOldHealth : tHistory.m_iNewHealth) % 32768;
@@ -514,20 +517,30 @@ void CCritHack::Store()
{
auto pPlayer = I::ClientEntityList->GetClientEntity(n)->As<CTFPlayer>();
if (pPlayer && pPlayer->IsAlive() && !pPlayer->IsAGhost())
StoreHealthHistory(pPlayer->entindex(), pPlayer->m_iHealth());
StoreHealthHistory(n, pPlayer->m_iHealth(), pPlayer);
}
}
void CCritHack::StoreHealthHistory(int iIndex, int iHealth, bool bDamage)
void CCritHack::StoreHealthHistory(int iIndex, int iHealth, CTFPlayer* pPlayer)
{
bool bContains = m_mHealthHistory.contains(iIndex);
auto& tHistory = m_mHealthHistory[iIndex];
if (bContains && pPlayer)
{ // deal with instant respawn damage desync better
if (pPlayer->IsDormant())
tHistory.m_iSpawnCounter = -1;
else if (tHistory.m_iSpawnCounter == -1)
tHistory.m_iSpawnCounter = pPlayer->m_iSpawnCounter();
else if (tHistory.m_iSpawnCounter != pPlayer->m_iSpawnCounter())
return; // wait for event
}
if (!bContains)
tHistory = { iHealth, iHealth };
else if (iHealth != tHistory.m_iNewHealth)
{
tHistory.m_iOldHealth = std::max(bDamage && tHistory.m_mHistory.contains(iHealth % 32768) ? tHistory.m_mHistory[iHealth % 32768].m_iOldHealth : tHistory.m_iNewHealth, iHealth);
tHistory.m_iOldHealth = std::max(tHistory.m_iNewHealth, iHealth);
tHistory.m_iNewHealth = iHealth;
}
+2 -1
View File
@@ -7,6 +7,7 @@ struct HealthHistory_t
{
int m_iNewHealth = 0;
int m_iOldHealth = 0;
int m_iSpawnCounter = -1;
struct HealthStorage_t
{
@@ -29,7 +30,7 @@ private:
int GetCritRequest(CUserCmd* pCmd, CTFWeaponBase* pWeapon);
void Reset();
void StoreHealthHistory(int iIndex, int iHealth, bool bDamage = false);
void StoreHealthHistory(int iIndex, int iHealth, CTFPlayer* pPlayer = nullptr);
int m_iCritDamage = 0;
int m_iRangedDamage = 0;