Interrupt / systemshock

Shockolate - A minimalist and cross platform System Shock source port.
GNU General Public License v3.0
801 stars 62 forks source link

Using Reload hotkey with weapons that don't have mags causes some memory corruption #384

Open bangstk opened 2 years ago

bangstk commented 2 years ago

If a weapon doesn't use ammo (such as melee weapons or beam weapons like the Sparq) it seems that random things will happen if the player uses the reload hotkey with it selected.

The reload sound plays, and then for example, with the Sparq Beam selected, STAMUP patches start disappearing from your inventory every time the reload hotkey is pressed. Other weapons have different effects. Maybe it's writing out of bounds on other memory areas due to undefined ammo.

icosahedral-dragon commented 2 years ago

The reload weapon hotkey function does not check if the current weapon uses ammo before attempting to reload it.

The number of clips the player has for each ammo type is stored in an array. The code looks up the clip count by taking the base ammo type (which will be zero for an ammoless weapon) and adding the current ammo type. But the current ammo type field is shared with the intensity setting for beam weapons. The default intensity for the sparq is 30, causing the code to look past the ammo count array and end up in the drugs/patches list. Hence using the STAMUP patch as "clips" for the sparq. If you change the intensity setting it will have different effects.

This bug doesn't show up in the enhanced edition on Steam, but it may be something that Night Dive have already patched. It looks like we inherited it from the Mac code, anyway.