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

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

Merged

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

@briaguya-ai briaguya-ai merged commit fb45b66 into HarbourMasters:develop-macready Nov 14, 2023
8 checks passed
@jbodner09 jbodner09 deleted the fix-magic-for-reals branch November 14, 2023 23:51
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