Skip to content

Commit

Permalink
CWeaponBox::Touch: Fixed a hang when touching a weaponbox if multiple…
Browse files Browse the repository at this point in the history
… items are packed in a slot
  • Loading branch information
s1lentq committed Mar 31, 2024
1 parent 9277582 commit a546997
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2070,13 +2071,13 @@ void CWeaponBox::Touch(CBaseEntity *pOther)
}
else if (i == GRENADE_SLOT)
{
CBasePlayerWeapon *pGrenade = static_cast<CBasePlayerWeapon *>(m_rgpPlayerItems[i]);
CBasePlayerWeapon *pGrenade = static_cast<CBasePlayerWeapon *>(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();
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}

Expand Down

0 comments on commit a546997

Please sign in to comment.