d0k3 / Decrypt9WIP

Multipurpose content dumper and decryptor for the Nintendo 3DS
GNU General Public License v2.0
404 stars 59 forks source link

GBA Save Dump/Inject #165

Closed Sonlen1414 closed 7 years ago

Sonlen1414 commented 7 years ago

I have been working on dumping, more importantly, replacing a few GBA saves I have converted, most notable at the moment Megaman Battle Network 1 and 2, after about 20 or so tries I finally got the 1st game to accept my save, but the 2nd one won't, and it is dumping blank .savs with the header and footer only.

d0k3 commented 7 years ago

Try it in GodMode9, too (the gbavc.sav file is in the S:/ drive), then tell me if you still have the same problems.

Sonlen1414 commented 7 years ago

I took the backup and injected by copying over the gbavc.sav in the S:/ Drive and it didn't do anything, tried it 2 or 3 times after restarting with HBL to keep ram intact and nothing changed, I will be continuing to try, but so far nothing.

I just want to add that Godmode9 had less of a decent inject rate unless I did something wrong, that being said, I kept on using Decrypt9 because at least it worked some times, and as far as I can tell, it seems to have a 50/50 of detecting the gbavc.sav that was stored in ram by the GBA VC itself. If there is any testing you want me to help with feel free to let me know.

d0k3 commented 7 years ago

This is not stored in RAM, @Sonlen1414, but rather on a specific partition in NAND. What do you mean by restarting with HBL? Do you have A9LH installed? The prefered method is to run GM9 via a chainloader like Luma3DS.

Sonlen1414 commented 7 years ago

I was given the understand that restarting using System Settings or HBL and then immediately booting into Decrypt9 saved the last GBA game into RAM, maybe it just means that restarting saves the last GBA game to that specific part of the NAND. I have the latest A9LH and Luma installed yes (well Luma is a hourly/nightly(forget which) maybe that is the issue?), and Godmode9 didn't work at all for injecting after trying 5 times, 1 or 2 times is all it took me with the HBL reboot into Decrypt9, probably just coincidence, but Godmode9 just would not work for me.

d0k3 commented 7 years ago

Well, your understanding is wrong. The AGBSAVE partition will always contain the savegame for the last GBA game you ran, regardless of what you did in between. You tried to inject by copying the gbavc.sav file back to S:/, right?

Try this when injecting: (1) make a copy of the agbsave.bin before injecting (2) make a copy of the agbsave.bin after injecting (name it something else, ofc) (3) compare these two files (1&2), just do the GM9 SHA calculation on both (4) if these files are different, reboot, check if the save has been taken over (5) if it has not, reboot to GM9, then make another copy of agbsave.bin (6) does agbsave.bin match the file from (1) or the file from (2) (or, none?)? Tell me.

Sonlen1414 commented 7 years ago

Alright, I see what I was doing wrong and I understand I was mislead with the whole saving the game into ram blah blah blah, I tested with D9 and got a successful inject with a normal reboot. Now onto GM9, I actually see what it is doing, and what D9 does, and it appears that without realizing, the agbsave.bin is actually a different file size then the emulators make on PC, which would make D9 injection MUCH more viable, BUT, with what I was working on, moving WiiU to 3DS saves, it appears they both use different file formats, I did get the agbsave.bin to backup, but restoring it didn't work. The files are almost identical except a few small exceptions it appears.

Here is the original gbavc.sav that works in D9 for injection for comparison just in case you want it. Here is the backup I made and tried to re-inject using the method you mentioned before deleting the first save slot. Here is the backup I made after deleting the first save slot in the game.

But long story short, Link 2 was made with GM9 after successfully injecting Link 1 using D9. I went into The Legend of Zelda - The Minish Cap and deleted the first save slot so I had 3 empty slots. Then I went into GM9, backed up the agbsave.bin, which I linked with Link 3, then tried to overwrite the agbsave.bin in the S:/ Directory with Link 2, but it did not take, and extraction led to the exact same file as Link 3 has.

In all honesty though, I don't see why GM9s mode of extraction would ever be more useful then D9 since D9 just extracts the raw save that can be used elsewhere without any modifications.

Sorry for the long reply, I just wanted to be thorough in case I missed something or maybe something I did is helpful.

d0k3 commented 7 years ago

Thanks for providing these files, I'll have a more thorough look tomorrow. You did get another thing wrong, though. You see that the S:/ drive also contains a gbavc.sav? That's what you're supposed to inject into. Not agbsave.bin. agbsave.bin is the full partition, and gbavc.sav is a file on it.

Sonlen1414 commented 7 years ago

You mentioned agbsave.bin so I tried that, I also tried the gbavc.sav originally and it didn't work either, that was actually the first thing I tried and assumed it was right, but that didn't work on injecting either, I will provide files for those dumps asap.

Edit: No need to provide a file, the gbavc.sav in S:/ is actually showing identical, meaning it must be the right file (obviously) but overwriting it never seemed to work.

d0k3 commented 7 years ago

Okay, I see what's going wrong in GM9. You absolutely have to inject to gbavc.sav. Injecting to agbsave.bin won't take over the save.

Now... you say overwriting does not work? What do you mean by that? Do you get an error message? Or, does it seem to work, but doesn't have any effect after?

You know, you can confirm by... (1) Calculating the SHA for S:/gbavc.sav (2) Overwriting it with a different gbavc.sav file (calculate the SHA on that first, too, to be safe) (3) Calculating the SHA for S:/gbavc.sav again Now, does the SHA match the file you copied over in (2)? If so, it worked, and it should be taken over.

Sonlen1414 commented 7 years ago

So I did exactly as you said, I calculated the SHA on the S:/gbavc.sav, then I went to the one I wanted to overwrite on my SD, calculated the SHA there, they did not match. Copied that and pasted, overwriting the gbavc.sav in S:/, calculated the SHA again and it did in fact overwrite, so now both the original save on the SD and the one in S:/ have the exact same SHA. I went to boot up the game and the save did not take, still a blank save when there should be 1 save slot used and 2 blank ones.

d0k3 commented 7 years ago

Okay, let's try soemthing else...

This test build has debug ouput right before shutdown / reboot: https://transfer.sh/6agFJ/GodMode9-20170323-121908.zip

Can you try again (to inject a gbavc.sav via GM9) and tell me what it says for you?

Sonlen1414 commented 7 years ago

I have 2 things to reply with here actually.

  1. I got CFG_BOOTENV: 7 - And it did not inject at all.
  2. I forgot to try out the new version of GM9 you released, since it came out after I opened this, and it worked flawlessly multiple attempts in a row, so whatever the issue is/was, it works with the new release.
d0k3 commented 7 years ago

This sounds great! So, considering this solved?

Sonlen1414 commented 7 years ago

Most certainly solved unless you wanted to dig deeper into an outdated version lol, thanks!