Skip to content
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

Crowbar is not shown in weapon list if there are empty weapon slots with a lower id #3181

Open
SamVanheer opened this issue Dec 2, 2021 · 0 comments

Comments

@SamVanheer
Copy link

SamVanheer commented Dec 2, 2021

The crowbar is not shown in the hud weapon list if there are empty weapon slots with a lower id in the client's weapon list.

The cause of this bug is here:

halflife/cl_dll/ammo.cpp

Lines 355 to 366 in c7240b9

for (int i = MAX_WEAPONS-1; i > 0; i-- )
{
WEAPON *p = gWR.GetWeapon(i);
if ( p )
{
if ( gHUD.m_iWeaponBits & ( 1 << p->iId ) )
gWR.PickupWeapon( p );
else
gWR.DropWeapon( p );
}
}

The crowbar has id 1 so it's the last weapon to be processed. But if the crowbar, or whichever weapon is in bucket 0, slot 0 has an id greater than that, and if there is an unused id lower than that then it will still process that unused weapon and "drop" the weapon, removing whichever weapon is in bucket 0, slot 0.

This happens because unused weapon slots default to bucket 0, slot 0, so whichever weapon is in that position is removed from the list.

To reproduce this, change the WEAPON_CROWBAR value from 1 to 30. You will no longer see the crowbar in the weapon list.

To fix this the code has to check if the weapon has a valid id:

for (int i = MAX_WEAPONS-1; i > 0; i-- )
{
	WEAPON *p = gWR.GetWeapon(i);

	if ( p && 0 != p->iId )
	{
		if ( gHUD.m_iWeaponBits & ( 1 << p->iId ) )
			gWR.PickupWeapon( p );
		else
			gWR.DropWeapon( p );
	}
}

This bug is probably why this for loop goes from back to front, and why WEAPON_SUIT is 31 instead of 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants