Skip to content

Commit

Permalink
Fix crash by delaying ped recreation (PR #3914, Fixes #472)
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX authored Jan 1, 2025
1 parent e831f62 commit 2d3397d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
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

0 comments on commit 2d3397d

Please sign in to comment.