DS-Homebrew / TWiLightMenu

DSi Menu replacement for DS/DSi/3DS/2DS
https://wiki.ds-homebrew.com/twilightmenu/
GNU General Public License v3.0
3.17k stars 199 forks source link

[3in1] Corrupted save data after loading the game to NOR #1260

Open andrebrait opened 3 years ago

andrebrait commented 3 years ago

Console Configuration: DS Lite + R4 + EZFlash 3in1 TWiLight Menu++ Version: 17.2.1 TWiLight Menu++ Theme: DSi

Expected behaviour

After writing the ROM to NOR, the .sav file's contents should be flashed to the SRAM and everything should work normally.

Actual behaviour

After rebooting into GBA mode, sava data is corrupt (TLoZ:ALLTP (US) shows a message saying File N is corrupt for each file)

Steps to reproduce

  1. Grab my save file here (just because I know this one is working and the first file has a saved game).
  2. Try to flash TLoZ:ALTTP (US) to NOR along with this save file
  3. Upon rebooting into GBA mode, the game will display the message reporting that the save data is corrupt, on the save file selection screen.

Context

I know the save file is fine because I can switch between games using GBAExploader and loading it does restore my saves just fine. I think Twilight Menu is writing to the SRAM (because the game will complain about corrupted save files even if I had the same, working game before), but it's probably doing something bad there. The game itself boots and plays just fine.

RocketRobz commented 3 years ago

Unfortunately, I'm lost on how to fix this. :P

If any developer who owns an EZ-Flash Slot-2 card can help, I'd greatly appreciate it.

andrebrait commented 3 years ago

I'm not an expert in C but I can give a try. Maybe I'll try to check the state of SRAM after flashing with GBAExploader and after flashing with Twilight Menu and see what changes between them.

RocketRobz commented 3 years ago

You're welcome to try. :)

RocketRobz commented 3 years ago

Please install this nightly build, and see if that fixes the issue.

andrebrait commented 3 years ago

Ok, the feedback so far:

  1. The progress bar seems to only account for the game being loaded, not the erasure of the NOR
  2. SRAM data still corrupt. I double-checked the .sav file and I deleted all settings to make sure it would not overwrite the file on startup
  3. I'm checking what will happen to the sav file after a reboot and how it compares to the original file.
andrebrait commented 3 years ago

I noticed it doesn't get the SRAM data into the .sav file after the reboot. Is that normal? I turned off my DS, removed the sav file, touched it again just so there would be something there, and booted up again. It was not overwritten after booting up.

andrebrait commented 3 years ago

So, a few notes:

  1. I wrote the SRAM to a file using GBAExploader. I'm uploading the original file (which should have been written to the SRAM) as well as the one I got using GBAExploader. They're not the same for some reason. I can confirm I can use GBAExploader to write to SRAM and also get stuff from SRAM with exactly the same checksums, so I trust that this is what really was in the SRAM. The sav file is the original one. The sv4 file is what I got from SRAM after it was written by TwlilightMenu: here.

  2. Using GBAExploader to write to SRAM doesn't fix the issue. I re-wrote the original sav file and it didn't work. The game still says it's corrupt. Loading both the game and the SRAM file using GBAExploader makes it work again.

  3. Loading the SRAM from what TwilightMenu wrote (i.e. loading the sv4 file into SRAM) just gives me an empty game, but no corruption message.

My guess is that the corruption message comes from some sort divergence between the expected save type and the actual one? Maybe GBAExploader is patching the game in some way?

My second guess is that the SRAM data is not being written correctly. Perhaps an offset issue?

Kalanyr commented 3 years ago

The SV4 is just completely blank (its the same thing you get if the battery in an Ezy Flash save battery is dead), not sure if that means the cart wipes the save if it detects corruption (but you could test by starting a new game and saving after you get the corrupt message if the game can continue) or if the save data just isn't being written in the first place (maybe the code isn't writing correctly?)

Kalanyr commented 3 years ago

Maybe if you could write the save data to the cart, then dump it using ExpLoader without starting the game if that's possible ?

Kalanyr commented 3 years ago

~Okay, checked this on the latest nightly ( https://github.com/DS-Homebrew/TWiLightMenu/commit/a5cc19e664ee716eec924b5b62740777d016902a ) , with a DSTWO / 3in1+ , Compared to Exploader the SAV is written to PSRAM and GBA is written to NOR byte for byte identically (the Twilight version even boots if you reset the console you can even boot it as a NOR game), the issue seems to be with the way Twilight is attempting to launch the ROM. I used a dump of Fire Red to verify this and a new save.~

(Just need to confirm that this isn't an artifact of using Exploader/Twilight for the same ROM / Sav )

The above was an artifact. Twilight isn't writing to NOR or the save data to PSRAM at all. (I used Exploader to copy Lufia to NOR and made a save, then used Twilight to launch Fire Red with a Save present. Normal launch fail happened and when I reset I could launch Lufia from the NOR and the Lufia save was still fully present.