From a546997723a0d3eb18820999804042fde8588cfd Mon Sep 17 00:00:00 2001 From: s1lentq Date: Sun, 31 Mar 2024 22:46:06 +0700 Subject: [PATCH] CWeaponBox::Touch: Fixed a hang when touching a weaponbox if multiple items are packed in a slot --- regamedll/dlls/weapons.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/regamedll/dlls/weapons.cpp b/regamedll/dlls/weapons.cpp index 2c035c74..b44b288d 100644 --- a/regamedll/dlls/weapons.cpp +++ b/regamedll/dlls/weapons.cpp @@ -1974,6 +1974,7 @@ void CWeaponBox::Touch(CBaseEntity *pOther) if (!m_rgpPlayerItems[i]) continue; + CBasePlayerItem *pPrev = NULL; CBasePlayerItem *pItem = m_rgpPlayerItems[i]; // have at least one weapon in this slot @@ -2070,13 +2071,13 @@ void CWeaponBox::Touch(CBaseEntity *pOther) } else if (i == GRENADE_SLOT) { - CBasePlayerWeapon *pGrenade = static_cast(m_rgpPlayerItems[i]); + CBasePlayerWeapon *pGrenade = static_cast(pItem); if (pGrenade && pGrenade->IsWeapon()) { int playerGrenades = pPlayer->m_rgAmmo[pGrenade->m_iPrimaryAmmoType]; #ifdef REGAMEDLL_FIXES - CBasePlayerItem *pNext = m_rgpPlayerItems[i]->m_pNext; + CBasePlayerItem *pNext = pItem->m_pNext; // Determine the max ammo capacity for the picked-up grenade int iMaxPickupAmmo = pGrenade->iMaxAmmo1(); @@ -2094,7 +2095,11 @@ void CWeaponBox::Touch(CBaseEntity *pOther) playerGrenades, pGrenade->pszAmmo1(), iMaxPickupAmmo, &givenItem)) { // unlink this weapon from the box - m_rgpPlayerItems[i] = pItem = pNext; + if (pPrev) + pPrev->m_pNext = pItem = pNext; + else + m_rgpPlayerItems[i] = pItem = pNext; + continue; } #else @@ -2143,7 +2148,8 @@ void CWeaponBox::Touch(CBaseEntity *pOther) } else { - auto pNext = m_rgpPlayerItems[i]->m_pNext; + CBasePlayerItem *pNext = pItem->m_pNext; + if (pPlayer->AddPlayerItem(pItem)) { pItem->AttachToPlayer(pPlayer); @@ -2155,12 +2161,17 @@ void CWeaponBox::Touch(CBaseEntity *pOther) } // unlink this weapon from the box - m_rgpPlayerItems[i] = pItem = pNext; + if (pPrev) + pPrev->m_pNext = pNext; + else + m_rgpPlayerItems[i] = pItem = pNext; + continue; } bRemove = false; - pItem = m_rgpPlayerItems[i]->m_pNext; + pPrev = pItem; + pItem = pItem->m_pNext; } }