Skip to content
Browse files

Don't apply damage to peds without a game entity

Also remove the assertion in ApplyPedDamageFromGame
  • Loading branch information...
botder committed Sep 6, 2019
1 parent a53e021 commit 632130e36a96071290593fc3c677a536f7b19e1f
Showing with 10 additions and 21 deletions.
  1. +10 −21 Client/mods/deathmatch/logic/CClientGame.cpp
@@ -4273,13 +4273,20 @@ bool CClientGame::DamageHandler(CPed* pDamagePed, CEventDamage* pEvent)
CPools* pPools = g_pGame->GetPools();

// Grab the damaged ped
CClientPed* pDamagedPed = NULL;
CClientPed* pDamagedPed = nullptr;

if (pDamagePed)
SClientEntity<CPedSA>* pPedClientEntity = pPools->GetPed((DWORD*)pDamagePed->GetInterface());
SClientEntity<CPedSA>* pPedClientEntity = pPools->GetPed(reinterpret_cast<DWORD*>(pDamagePed->GetInterface()));

if (pPedClientEntity)
pDamagedPed = reinterpret_cast<CClientPed*>(pPedClientEntity->pClientEntity);
// NOTE(botder): Don't use the damaged ped if the associated game entity doesn't exist to avoid a crash
// in the function ApplyPedDamageFromGame
if (pPedClientEntity->pClientEntity && pPedClientEntity->pClientEntity->GetGameEntity() != nullptr)
pDamagedPed = reinterpret_cast<CClientPed*>(pPedClientEntity->pClientEntity);

@@ -4415,24 +4422,6 @@ bool CClientGame::DamageHandler(CPed* pDamagePed, CEventDamage* pEvent)
bool CClientGame::ApplyPedDamageFromGame(eWeaponType weaponUsed, float fDamage, uchar hitZone, CClientPed* pDamagedPed, CClientEntity* pInflictingEntity,
CEventDamage* pEvent)
if (pDamagedPed->GetGamePlayer() == nullptr)
// Shouldn't happen, but it does anyway. Log some information about the damaged ped and the ped pool; and then crash optionally
auto entityType = static_cast<int>(pDamagedPed->GetType());
bool isInVehicle = pDamagedPed->IsInVehicle();
bool isDead = pDamagedPed->IsDead();
bool isLocalPlayer = pDamagedPed->IsLocalPlayer();
unsigned long pedCount = g_pGame->GetPools()->GetPedCount();

SString("CClientGame::ApplyPedDamageFromGame: GetGamePlayer() == nullptr (type: %d, inVehicle: %d, isDead: %d, isLocalPlayer: %d, pedCount: %lu)",
entityType, isInVehicle, isDead, isLocalPlayer, pedCount));

// Crash on purpose to gather crash information for this offset and not somewhere else
return false;

float fPreviousHealth = pDamagedPed->m_fHealth;
float fCurrentHealth = pDamagedPed->GetGamePlayer()->GetHealth();
float fPreviousArmor = pDamagedPed->m_fArmor;

0 comments on commit 632130e

Please sign in to comment.
You can’t perform that action at this time.