mirror of
https://github.com/s1lentq/ReGameDLL_CS.git
synced 2024-12-27 07:05:38 +03:00
try fix a crash due to the deletion of an item in an unusual way
related #870, #752, #924, #957
This commit is contained in:
parent
279799bff9
commit
77a3f2b25b
@ -1598,6 +1598,30 @@ void OnFreeEntPrivateData(edict_t *pEnt)
|
|||||||
if (!pEntity)
|
if (!pEntity)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifdef REGAMEDLL_FIXES
|
||||||
|
// FIXED: Ensure this item will be removed from the owner player's inventory 'm_rgpPlayerItems[]'
|
||||||
|
// to avoid dangling pointers
|
||||||
|
CBasePlayerItem *pItem = dynamic_cast<CBasePlayerItem *>(pEntity);
|
||||||
|
if (pItem)
|
||||||
|
{
|
||||||
|
CBasePlayer *pOwner = GET_PRIVATE<CBasePlayer>(pItem->pev->owner);
|
||||||
|
if (pOwner && pOwner->IsPlayer())
|
||||||
|
{
|
||||||
|
if (pOwner->m_pActiveItem == pItem && pItem->IsWeapon())
|
||||||
|
((CBasePlayerWeapon *)pItem)->RetireWeapon();
|
||||||
|
|
||||||
|
if (pOwner->RemovePlayerItem(pItem))
|
||||||
|
{
|
||||||
|
// Ammo must be dropped, otherwise grenades cannot be buy or picked up
|
||||||
|
if (IsGrenadeWeapon(pItem->m_iId) || pItem->m_iId == WEAPON_C4)
|
||||||
|
pOwner->m_rgAmmo[pItem->PrimaryAmmoIndex()] = 0;
|
||||||
|
|
||||||
|
pOwner->pev->weapons &= ~(1 << pItem->m_iId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef REGAMEDLL_API
|
#ifdef REGAMEDLL_API
|
||||||
pEntity->OnDestroy();
|
pEntity->OnDestroy();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user