Skip to content

Fix #472 setElementHealth in onClientPedDamage can cause crash #3914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4404,12 +4404,9 @@ bool CClientGame::ApplyPedDamageFromGame(eWeaponType weaponUsed, float fDamage,
return false;
}

if (pDamagedPed->IsLocalPlayer())
{
// Reget values in case they have been changed during onClientPlayerDamage event (Avoid AC#1 kick)
fCurrentHealth = pDamagedPed->GetGamePlayer()->GetHealth();
fCurrentArmor = pDamagedPed->GetGamePlayer()->GetArmor();
}
// Reget values in case they have been changed during onClientPlayerDamage/onClientPedDamage event (Avoid AC#1 kick)
fCurrentHealth = pDamagedPed->GetGamePlayer()->GetHealth();
fCurrentArmor = pDamagedPed->GetGamePlayer()->GetArmor();

bool bIsBeingShotWhilstAiming = (weaponUsed >= WEAPONTYPE_PISTOL && weaponUsed <= WEAPONTYPE_MINIGUN && pDamagedPed->IsUsingGun());
bool bOldBehaviour = !IsGlitchEnabled(GLITCH_HITANIM);
Expand Down
30 changes: 20 additions & 10 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2705,6 +2705,10 @@ void CClientPed::StreamedInPulse(bool bDoStandardPulses)
return;
}

// Re-create ped
if (m_shouldRecreate)
ReCreateGameEntity();

// Grab some vars here, saves getting them twice
CClientVehicle* pVehicle = GetOccupiedVehicle();

Expand Down Expand Up @@ -3974,11 +3978,7 @@ void CClientPed::_ChangeModel()
{
// ChrML: Changing the skin in certain cases causes player sliding. So we recreate instead.

// Kill the old player
_DestroyModel();

// Create the new with the new skin
_CreateModel();
m_shouldRecreate = true;
}

// ReAttach satchels
Expand Down Expand Up @@ -4012,11 +4012,7 @@ void CClientPed::ReCreateModel()
m_pLoadedModelInfo->ModelAddRef(BLOCKING, "CClientPed::ReCreateModel");
}

// Destroy the old model
_DestroyModel();

// Create the new model
_CreateModel();
m_shouldRecreate = true;

// Remove the reference we temporarily added again
if (bSameModel)
Expand All @@ -4026,6 +4022,20 @@ void CClientPed::ReCreateModel()
}
}

void CClientPed::ReCreateGameEntity()
{
if (!m_shouldRecreate || !m_pPlayerPed)
return;

// Destroy current game entity
_DestroyModel();

// Create the new game entity
_CreateModel();

m_shouldRecreate = false;
}

void CClientPed::ModelRequestCallback(CModelInfo* pModelInfo)
{
// If we have a player loaded
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

// Used to destroy the current game ped and create a new one in the same state.
void ReCreateModel();
void ReCreateGameEntity();

void _CreateModel();
void _CreateLocalModel();
Expand Down Expand Up @@ -725,6 +726,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
bool m_bPendingRebuildPlayer;
uint m_uiFrameLastRebuildPlayer;
bool m_bIsSyncing;
bool m_shouldRecreate{false};

bool m_bBulletImpactData;
CClientEntityPtr m_pBulletImpactEntity;
Expand Down
Loading