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

CBasePlayerWeapon::SecondaryAmmoIndex should always return m_iSecondaryAmmoType #3029

Open
SamVanheer opened this issue Jan 31, 2021 · 0 comments

Comments

@SamVanheer
Copy link

The method CBasePlayerWeapon::SecondaryAmmoIndexshould always returnm_iSecondaryAmmoType`.

Currently this returns -1, and the MP5 overrides it to return m_iSecondaryAmmoType.

For all other weapons m_iSecondaryAmmoType is initialized to -1 anyway:

m_iSecondaryAmmoType = pPlayer->GetAmmoIndex( pszAmmo2() );

Changing it to return m_iSecondaryAmmoType does not change the value returned in vanilla Half-Life code.

This can result in inconsistent behavior when making custom weapons. A modder that is unaware of this could end up with bugs and even crashes if the index is used to get the player's current remaining ammo since -1 is out of bounds.

With this change, if pszAmmo2() returns a non-null pointer it is safe to assume that SecondaryAmmoIndex also returns a valid index.

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

No branches or pull requests

1 participant