Pokémon Emerald Real 512Kb Flash Memory Patch

Discussion in '3DS - ROM Hacking, Translations and Utilities' started by Pikachu025, Apr 19, 2017.

  1. Pikachu025
    OP

    Pikachu025 GBAtemp Advanced Fan

    Member
    969
    35
    May 3, 2006
    Australia
    Austria
    I was unsatisfied with the somewhat hacky state of the Pokémon games running in AGB_FIRM on the 3DS, so I modified Pokémon Emerald to save to a 512Kb Flash Memory, which AGB_FIRM supports correctly, and I figured some other people would enjoy it too.

    This was somewhat involved, but the gist of it is that my patch makes the game not save a backup save file, and redirects the saves to the Hall of Fame and Battle Frontier Battle Recording to fit in the remaining space of the flash memory.

    You can download the patch here:
    Version 1.1: https://filetrip.net/dl?oI4BtX1Bdu
    Version 1.0: https://filetrip.net/dl?wMMydqqNLW

    Instructions, checksums, and technical details can be found in the included readme. I also included a tool to convert saves from the traditional 1Mb save to the smaller 512Kb save and vice-versa.

    This patch is only for the English version of Pokémon Emerald. The same method can probably be applied to other games and language versions too, though, so if there's interest and I can find the time I may make other patches too.

    If you run into any issues, please report them with exact details. I've played around with this for a while and it seems to work fine, but it's always possible I missed something somewhere. Keep save backups just in case, too.
     
    Last edited by Pikachu025, Apr 29, 2017
    Ricken, kineticUk, NotABot and 11 others like this.


  2. Asia81

    Asia81 In my Ecchi World <3

    Member
    5,042
    2,488
    Nov 15, 2014
    France
    Albi
    Interesting.
    So there is no anymore problems with the hall of fame and saves? Saves are correctly saved?
    If so, I could be interested in other versions/languages, I will see if I can manage to do it after read your readme on the process.
     
    noctis90210 likes this.
  3. Pikachu025
    OP

    Pikachu025 GBAtemp Advanced Fan

    Member
    969
    35
    May 3, 2006
    Australia
    Austria
    That's the idea, yeah. I didn't have the time yet to play through the whole game on my 3DS yet, but it saves correctly after the Elite 4 in no$gba when the save type is set to 64KB, so I'm pretty confident.
     
  4. Pikachu025
    OP

    Pikachu025 GBAtemp Advanced Fan

    Member
    969
    35
    May 3, 2006
    Australia
    Austria
    Updated the patch to version 1.1: https://filetrip.net/dl?oI4BtX1Bdu

    If you're using this for 3DS injection this should make no difference, but I've improved compatibility with emulators and flash cards by supporting more types of flash memory.
     
    awtgrduzwt5r9 and Asia81 like this.
  5. noctis90210

    noctis90210 GBAtemp Advanced Fan

    Member
    738
    108
    Dec 24, 2013
    @Pikachu025
    thanks for this workaround...
    just want to clarify some things:

    it will work if:
    unpatched save only compatible on unpached rom?
    patched save only compatible on patched rom?

    it will not work if:
    unpatched save injected to patched rom?
    patched save injected to unpatched rom?

    just correct me if one of my statement is wrong...
     
  6. Pikachu025
    OP

    Pikachu025 GBAtemp Advanced Fan

    Member
    969
    35
    May 3, 2006
    Australia
    Austria
    Yes, that's correct. There is a save conversion tool included though.
     
  7. noctis90210

    noctis90210 GBAtemp Advanced Fan

    Member
    738
    108
    Dec 24, 2013
    oh yeah, i just downloaded the file...

    so it will convert normal save to trimmed save?
    and trimmed save to normal save?
     
  8. Pikachu025
    OP

    Pikachu025 GBAtemp Advanced Fan

    Member
    969
    35
    May 3, 2006
    Australia
    Austria
    Yes, it can do both directions.
     
    noctis90210 likes this.
  9. noctis90210

    noctis90210 GBAtemp Advanced Fan

    Member
    738
    108
    Dec 24, 2013
    sorry if i have a lots of questions...
    but thanks for answering all of those :-)

    so what im going to do is just drag and drop tha save on the .exe?

    i jut read that 1mb->512 conversion is lossy.
    what to you mean by lossy?
     
  10. Pikachu025
    OP

    Pikachu025 GBAtemp Advanced Fan

    Member
    969
    35
    May 3, 2006
    Australia
    Austria
    It's intended as a command-line tool, but drag&drop should work too.

    It means that you lose some information converting that way. You lose the backup save, and if you have over 32 Hall of Fame entries you only keep the newest 32.
     
    noctis90210 likes this.
  11. noctis90210

    noctis90210 GBAtemp Advanced Fan

    Member
    738
    108
    Dec 24, 2013
    but the vital parts of the game wont be affected right?
    i hope you could also make patches for Ruby/sapphire/firered/leafgreen/and mystery dungeon red...

    and oh im just curious whats the difference between 1.0 and 1.1?
     
  12. Pikachu025
    OP

    Pikachu025 GBAtemp Advanced Fan

    Member
    969
    35
    May 3, 2006
    Australia
    Austria
    Yeah, you're not losing anything important, that's the point!

    The only difference is the types of (emulated) flash hardware supported. If you're using this for 3DS injection don't worry about it, it's only really of interest if you want to use the patch on an old GBA flashcard.
     
    noctis90210 likes this.
  13. noctis90210

    noctis90210 GBAtemp Advanced Fan

    Member
    738
    108
    Dec 24, 2013
    thanks a lot sir... hope to see your future releases soon :-)
     
  14. Cralex

    Cralex GBAtemp Regular

    Member
    112
    44
    Jul 29, 2016
    United States
    So, if I'm understanding the current way that things are done, the current hacks just drop the backup save and disable the corruption message, right? Would such a simpler hack, such as the one installed on my 3ds right now, produce a corrupted save if you do the wrong thing?
     
  15. Pony1993

    Pony1993 Member

    Newcomer
    38
    0
    Nov 21, 2016
    United States
    Pokemon mystery dungeon
     
  16. Pikachu025
    OP

    Pikachu025 GBAtemp Advanced Fan

    Member
    969
    35
    May 3, 2006
    Australia
    Austria
    If by 'current hack' you mean this one, it does the following, if I'm reading those changes correctly:
    - dummies out the 'save file corrupted, previous save will be loaded' message window
    - dummies out the flash chip identification (by always just taking the first known one)
    - dummies out some check in the berry fix program sent to RS, for some reason?

    And that's it. Most crucially, the game still thinks that it has a full 1M flash to write to and will attempt to do so, but due to the way 1M Flash works on GBA (it's two banks of 512K flash that need to be switched between) the write succeeds and overwrites data from the other bank. Effectively, the two banks end up shadowing each other and the last write wins at any given time. This would be mostly harmless if we only had the two save files in there, but we also have some extra data, the Hall of Fame and the Battle Frontier Battle Recording, so a poor combination of what the game thinks as current save slot and writes to that extra data will just corrupt the save.

    More illustratively, a real save looks like this:

    [​IMG]

    If the two banks shadow each other, we have the following setup, where only one of the two horizontal sectors can ever exist at the same time.

    [​IMG]

    Before beating the Elite 4, this ends up working okay; a new save ends up corrupting the one in the other slot, but one complete save always exists:

    [​IMG]

    But after the Elite 4, one of the two possible setups breaks both slots, since the game first writes the regular save and then writes the Hall of Fame afterwards:

    [​IMG]

    A similar thing can occur for the Battle Recording, but that's not as critical since recording a battle doesn't reset the game, so you always have the chance to just save again. It's not safe either though.

    My patch removes the second save slot, the second Hall of Fame sector, and the unused Trainer Hill eCard sector, and rearranges the remaining sectors so they don't shadow eachother, so all combinations of saving just work fine.
     
  17. noctis90210

    noctis90210 GBAtemp Advanced Fan

    Member
    738
    108
    Dec 24, 2013
    @Pikachu025
    pls make paches for other GBA pokemon games too.
    RS/FRLG
    would happy to see all pokemon games on 3ds home menu working without any errors... :-)
     
    NotABot and Cralex like this.
  18. Cralex

    Cralex GBAtemp Regular

    Member
    112
    44
    Jul 29, 2016
    United States
    @Pikachu025 Yes, that's what I was asking about, although what I've been seeing in the GBA injector thread generally amounts to something like "change these values in a hex editor and it'll magically just work."

    Thanks for such a detailed explanation and such a thorough fix. Thankfully, I never got around to playing much of Emerald on my 3DS.

    Also, wow. Makes me wonder what it was like for the developers to try cramming in more features without running out of save space.
     
    Last edited by Cralex, May 1, 2017
  19. Wanderer0891

    Wanderer0891 Advanced Member

    Newcomer
    58
    7
    Dec 18, 2008
    United States
    @Pikachu025

    Out of curiosity would it be possible to make a similar patch for Super Mario Advance 4 as its another game with a 128Kb Flash Memory that doesn't work quite right on AGB_FIRM.
     
  20. MajinCubyan

    MajinCubyan The Funky Super Saiyan

    Member
    588
    943
    Nov 24, 2014
    United States
    Orre
    Just seen this on romhacking.net and it totally slipped under my radar. Fantastic job, now I can finally play this game, cause I want to play it on my 3ds. o3o

    Quick question; Is this patch compatible with romhacks, such has the Complete Hoenn/National Dex hacks?