Fix item amount underflow on item deflect
This fixes an underflow issue when a player uses an item within the same time they get hurt by that same item.
Bug in question:
What causes the underflow? The following happens in the same tic:
- Within K_MoveKartPlayer's itemtype switch (L12767 onwards), player uses their item, calling
K_ThrowKartItem
. - Item spawns, which gets deflected immediately through
K_BubbleShieldReflect
transfering ownership (makingthreshold
or leniency frames not apply anymore). - This hits the player back, which runs
K_DropHnextList
. This sets the player's item amount to zero and their item type to none. - We didn't decrease the item amount yet, so we set item amount - 1.
- This underflows into having 255 of an empty item.
The fix here is to apply the item amount reduction before calling K_ThrowKartItem in any applicable cases, which makes the underflow not happen.
Fix applied:
Attached is a reproduction script, 255repro.lua, which loads a test case where P1 gets their Orbinaut reflected by P2. It will automatically run after a second and can be repeated by calling the performsetup
command in the developer console.
Changelog: Fixed an issue where a player could have 255 of an empty item in specific circumstances, which would prevent picking up Item Boxes or dropped items.
Edited by JugadorXEI