RSDKModding / Sonic-Mania-Decompilation

A complete decompilation of Sonic Mania (2017)
Other
614 stars 118 forks source link

Crash when breaking random item box with no sidekick or stocks in Encore Mode #283

Closed MegAmi24 closed 2 weeks ago

MegAmi24 commented 2 months ago

Steps to reproduce:

  1. Boot up game, start a new game in Encore Mode
  2. When you get to GHZ, die as one of the characters, don't get any new stocks before or afterwards
  3. Break a random item box

https://github.com/user-attachments/assets/913ff3c8-417e-4afc-836f-df4b3d5c61f9

MegAmi24 commented 2 months ago

Looked in VS Debugger, there are two things causing this:

  1. The game is supposed to play the swap fail sfx when there is no P2, but for some reason the check for it always returns false. My guess is there's an error in HUD_CharacterIndexFromID. https://github.com/RSDKModding/Sonic-Mania-Decompilation/blob/75b3784141d89668eaabce5173862993cecb8d53/SonicMania/Objects/Global/ItemBox.c#L591-L596

  2. There's an infinite loop in the randomizing code, with the if ((1 << newPlayerIDs[p]) & globals->characterFlags) check always returning false and p never incrementing. This was also reported in #264. https://github.com/RSDKModding/Sonic-Mania-Decompilation/blob/75b3784141d89668eaabce5173862993cecb8d53/SonicMania/Objects/Global/ItemBox.c#L607-L614

Mefiresu commented 2 weeks ago

Fixed by https://github.com/RSDKModding/RSDKv5-Decompilation/commit/a80e2ba8600b210f79208bf5d3bd357627f5d63d

Explanation:

In Encore mode, when you die, the game will swap your current character with the sidekick, and then reset the dead character's entity. The random item box tries to check for the characterID of the sidekick, but since it has been reset, we actually expect 0. The part of memory that was storing the characterID never got erased because of the smaller DefaultObject size, so it returned the old value, causing a softlock.