Skip to content

Fix magic being zeroed out when using fast file select#3389

Merged
briaguya0 merged 3 commits intoHarbourMasters:develop-macreadyfrom
jbodner09:fix-magic-for-reals
Nov 14, 2023
Merged

Fix magic being zeroed out when using fast file select#3389
briaguya0 merged 3 commits intoHarbourMasters:develop-macreadyfrom
jbodner09:fix-magic-for-reals

Conversation

@jbodner09
Copy link
Contributor

@jbodner09 jbodner09 commented Nov 13, 2023

Closes #1187 for good. After spending 2 hours stepping through the application starting up line by line, I determined that since the file select screen rework was done in #1854, there was no point at which play state was valid AND the save context didn't have a file selected when fast file select is turned on, which is what the old fix used to determine when we were exiting the title screen.

The old fix specifically set gPlayState->gameplayFrames to 0 when exiting the title screen, which is why it didn't cover when fast file select was used. That frame counter is used in vanilla gameplay for animation timing, which means it's usually masked off/modulused down/used in a trig function for the timing of a specific animation, so its full value was never important. The important exceptions to that appear to be:

  • In Dark Link's code, which may explain some of his differences here compared to console
  • A flame damage counter that appears to still be functional
  • A timer for one of Twinrova's cutscenes (specifically the "FlyKidnapCutscene")

Because the variable was uninitialized, it was just incrementing starting at the garbage value 0xabababab, which meant the trigger not to autosave during the first few seconds of gameplay wasn't happening, causing the described behavior of magic being zeroed out on first load via autosave triggering while the value is at 0 before the fill-up animation plays.

Given how many checks in vanilla code appear to want a counter value of 0, I suspect this variable was originally zeroed by the hardware. It's possible it even was zeroed on every play initialization like play->state->frames is, so if we're still looking for effects that aren't triggering like they should, this is a likely culprit.

This fix uses the classic "set a variable to say we've set a variable" to set the frame counter the first time play is initialized, and it also resets the counter when the in-game Reset is triggered. The old fix to reset the counter when leaving the title screen is retained so that title screen time doesn't count towards the counter, meaning the counter can now be used as an accurate counter of play time elapsed since last reset (gameover also counts as a reset).

Build Artifacts

@briaguya0 briaguya0 merged commit fb45b66 into HarbourMasters:develop-macready Nov 14, 2023
@jbodner09 jbodner09 deleted the fix-magic-for-reals branch November 14, 2023 23:51
This was referenced Feb 2, 2025
@briaguya0 briaguya0 mentioned this pull request Feb 14, 2025
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

Successfully merging this pull request may close these issues.

3 participants