d0k3 / GodMode9

GodMode9 Explorer - A full access file browser for the Nintendo 3DS console :godmode:
GNU General Public License v3.0
2.16k stars 194 forks source link

[FEATURE REQUEST] Add a cartridge fixer #812

Open Adamillo opened 1 year ago

Adamillo commented 1 year ago

As of late 3DS cartridges are starting to become corrupted, but someone called Skawo made a fork of GM9 that adds a feature called "Fix cartridge corruption". What it does is that it tries to restore the files of the game back to it's original good state. It would be great if this feature was in a mainline GM9 build. More info in how this feature works is in the fork itself: https://github.com/skawo/GodMode9-with-Cartridge-Fixer

d0k3 commented 1 year ago

Not a bad idea. Can we get @skawo on board for discussing a possible pull request? I first need to fully understand the issue, though. Carts should not be writeable (except for card2 saves...), So something like that shouldn't even happen.

Adamillo commented 1 year ago

It is read only, but also not, it's a little complicated. Here's more info with the lifespan of 3DS/Switch cartridges. Both of those consoles use the same cartridge technology: https://gbatemp.net/threads/nintendo-switch-3ds-cartridge-lifespan.591607/

skawo commented 1 year ago

While it would be awesome to add this to the main GodMode9 repo, I think you should probably rewrite the code, as mine is not great.

All my code does is essentially run the 'Verify NCCH' function, but instead of stopping as soon as it finds a mismatched hash, it sends the CTR Refresh function over and over until either the hash matches, the hash gets stuck on the same value, or the user skips that particular block.

It appears that the refresh function only affects the data that has last been read. Reading the data in smaller chunks might help, as then the refresh command is working on those smaller chunks.

As far as I understand, the refresh function is doing something akin to the following: https://www.researchgate.net/figure/n-Place-Reprogramming-Flash-Correct-and-Refresh-Technique_fig5_351061393

The refresh function is typically run by the 3DS every time you insert a cartridge, every 10000 reads and every time the system is shut down. Godmode9 runs the function every 10000 reads, as seen here: https://github.com/d0k3/GodMode9/blob/master/arm9/source/gamecart/command_ctr.c#L19-L23

From what has been tested, it is safe to run this function more frequently than usual - one user with a particularly bad Smash Bros. cartridge let the tool run for nearly a week, getting to 531 million refresh calls - and his cartridge still got better after the process (it was too corrupted to recover completely, but at least it managed to get into the menu, whereas before it would crash immediately). No one has yet to report that their cartridge got worse after running this process.

I have been keeping a tally of how many cartridges have been fixed using this method in this thread: https://gbatemp.net/threads/corrupted-cartridge-fixer-release.628539/

Adamillo commented 1 year ago

@d0k3 any updates on this?