Hacking GBA Pokémon Batteryless Save Patcher & Repacker

  • Thread starter Thread starter DanOl98
  • Start date Start date
  • Views Views 2,632
  • Replies Replies 19
  • Likes Likes 6

DanOl98

Member
Newcomer
Joined
Feb 24, 2019
Messages
21
Reaction score
25
Trophies
0
Age
27
XP
247
Country
Italy
Batteryless Save Patcher & Repacker for GBA Pokémon games

Based on AliExpress Bootleg Patch


A week ago I said “let’s put a few of my favorites hackroms on bootleg cartridges”, but then I found out about.. well, everything about SRAM batteryless patches etc.
I patched the games with gbata, and tried to use the batteryless patches I found… some almost worked, other didn’t work at all.
But the bootleg cartridges I had? They worked perfectly. So I dumped them, compared them with the original ROMs, and figured out exactly how they were patched.

And here we are with the result

1764170313498.png


What this tool does:

This tool is a fully automated and relocatable batteryless save patcher for Pokémon GBA games, based on the patch reverse-engineered from the bootleg Pokémon cartridges sold on AliExpress, it:

1 (OPTIONAL, ONLY IF NEEDED BECAUSE OF FREE SPACE OR FORCED) Repacks the ROM by moving all the LZ blocks and repoints them, in order to make free space at the end of the ROM to have enough to put the blob and the save area. WARNING!!! on heavily modified ROMs, relocating could break something, since LZ blocks detection isn't 100% reliable (even though in my experience it actually fixed a ROM which had broken images by relocating them to correct offsets)
2 Applies SRAM patches, no need to use external tools like GBATA
3 Applies the same patches found on the Aliexpress cartridges
4 Copies the patch blob found on the Aliexpress cartridges
5 Repoints all the references to that relocated blob
6 Edits that blob to relocate the save area to wherever there is free space on the ROM
7 (OPTIONAL) Inject save data if selected


Tested Working On (as of now):


🟢 Pokémon Ruby / Sapphire based ROMS (Tried with both USA and localized versions)


🟢 Pokémon FireRed / LeafGreen based ROMS (Tried with both USA and localized versions)


Issues:

🟡 Some heavily modified HACK Roms have problems with repacking.
It has something to do with some data (scripts, code etc) placed far in the game data and incorrectly being identified as LZ blocks.
Avoid repacking if possible.

🟡 LZ blocks detection (and the detection of the pointers to those blocks) isn't 100% reliable and could break games.
Avoid repacking if possible, even though in my experience it actually fixed a ROM which had broken images by relocating them to correct offsets, but that isn't always the case.


Download & Source:

https://github.com/DanOl98/pkmn_gba_batteryless_patcher


Let me know about your results, and if you find some bugs or if something doesn’t work

Keep in mind that as of now the patched ROMS haven’t been texted extensively (but I’ve tested first save, multiple save overwrites etc)
 
Last edited by DanOl98,
Nice work!
Thanks! Unfortunately this batteryless patch isn't as fancy as your patch, which is built from ground up, but it's just a dirty port of the one found in aliexpress cartridges, but since they apparently built it around specific pokémon save functions it looks like it works perfectly with any pokémon based ROM

I should probably refine the repacker tho, since LZ blocks detection isn't 100% reliable, but it looks like it works well with most of the 16MB ROMS I tried (in my experience it actually fixed a ROM which had broken images by relocating them to correct offsets)
 
Last edited by DanOl98,
  • Like
Reactions: metroid maniac
I tried this, and unfortunately it didn't work with half the hack roms I tried, that's why I reverse engineered the aliexpress one, which isn't generic but is built around pokémon specifically
ah ok, maybe you could compare how @metroid maniac has done theirs, maybe also see if you make it a CLI application also for the people that no longer use windows :)
 
ah ok, maybe you could compare how @metroid maniac has done theirs, maybe also see if you make it a CLI application also for the people that no longer use windows :)
This tool will only work for Pokemon because of how it has been made. But it should be much more stable for those games. Because my tool is more generic, it can cause more problems.
Not sure yet, but as of now I've observed this behavior only on 32mb roms, which cannot be patched anyway since as far as I know (correct me if I'm wrong) bootleg cartridges use addresses 0x09000000 to write on the SRAM so they wouldn't work anyway.
But, If by repacking the size went down to 16mb (doubt it, anyway), they could theoretically work.
This shouldn't be a problem. On bootleg carts with banked 1M SRAM, writes to 0x09000000 will access both the SRAM bank register and the ROM flash.
 
This shouldn't be a problem. On bootleg carts with banked 1M SRAM, writes to 0x09000000 will access both the SRAM bank register and the ROM flash.
Don't the 32MB flashcarts use another offset for that? I mean, those 0x09000000 addresses would be in conflict, how would it know whether to write/read on the SRAM or to the actual ROM flash?

maybe also see if you make it a CLI application also for the people that no longer use windows :)
That was already planned, I've just published the new version, which includes a new console version (and a linux build of that console version.

Also, the new version has .SAV savedata injection, I've tried that with a few ROMs and it looks like it works properly
 
Don't the 32MB flashcarts use another offset for that? I mean, those 0x09000000 addresses would be in conflict, how would it know whether to write/read on the SRAM or to the actual ROM flash?
0x09000000 is used to select an SRAM bank. The SRAM banks themselves are still accessed as normal at 0x0E000000.
So it causes no problems that this address is used for this purpose as well as writing to ROM flash.
 
0x09000000 is used to select an SRAM bank. The SRAM banks themselves are still accessed as normal at 0x0E000000.
So it causes no problems that this address is used for this purpose as well as writing to ROM flash.
My bad then, since I haven't actually touched the save logic itself I mistakenly thought that it was simply that 0x09000000 addresses were redirected to the SRAM, I didn't know that there was some kind of selection before that.

I'll definitely unlock the ability to patch 32MB ROMs too, but as of now I do not have any 32MB bootleg cartridge to try if the patch works (I'll order one from AliExpress tho, since now I definitely want to try 32MB ROMs too)
 
  • Like
Reactions: metroid maniac
Batteryless Save Patcher & Repacker for GBA Pokémon games

Based on AliExpress Bootleg Patch


A week ago I said “let’s put a few of my favorites hackroms on bootleg cartridges”, but then I found out about.. well, everything about SRAM batteryless patches etc.
I patched the games with gbata, and tried to use the batteryless patches I found… some almost worked, other didn’t work at all.
But the bootleg cartridges I had? They worked perfectly. So I dumped them, compared them with the original ROMs, and figured out exactly how they were patched.

And here we are with the result

View attachment 541571

What this tool does:

This tool is a fully automated and relocatable batteryless save patcher for Pokémon GBA games, based on the patch reverse-engineered from the bootleg Pokémon cartridges sold on AliExpress, it:

1 (OPTIONAL, ONLY IF NEEDED BECAUSE OF FREE SPACE OR FORCED) Repacks the ROM by moving all the LZ blocks and repoints them, in order to make free space at the end of the ROM to have enough to put the blob and the save area. WARNING!!! on heavily modified ROMs, relocating could break something, since LZ blocks detection isn't 100% reliable (even though in my experience it actually fixed a ROM which had broken images by relocating them to correct offsets)
2 Applies SRAM patches, no need to use external tools like GBATA
3 Applies the same patches found on the Aliexpress cartridges
4 Copies the patch blob found on the Aliexpress cartridges
5 Repoints all the references to that relocated blob
6 Edits that blob to relocate the save area to wherever there is free space on the ROM
7 (OPTIONAL) Inject save data if selected


Tested Working On (as of now):


🟢 Pokémon Ruby / Sapphire based ROMS (Tried with both USA and localized versions)


🟢 Pokémon FireRed / LeafGreen based ROMS (Tried with both USA and localized versions)


Issues:

🟡 Some heavily modified HACK Roms have problems with repacking.
It has something to do with some data (scripts, code etc) placed far in the game data and incorrectly being identified as LZ blocks.
Avoid repacking if possible.

🟡 LZ blocks detection (and the detection of the pointers to those blocks) isn't 100% reliable and could break games.
Avoid repacking if possible, even though in my experience it actually fixed a ROM which had broken images by relocating them to correct offsets, but that isn't always the case.


Download & Source:

https://github.com/DanOl98/pkmn_gba_batteryless_patcher


Let me know about your results, and if you find some bugs or if something doesn’t work

Keep in mind that as of now the patched ROMS haven’t been texted extensively (but I’ve tested first save, multiple save overwrites etc)
Yo, I just tried this with my aliexpress cart (accidentally flashed a save over address 00) but I got a white screen unfortunately. Not sure if I did something wrong?
EDIT Got it working THANK YOU SO MUCH!!!
Edit 2: Fire Red save gets deleted when I open the game :( any way to fix?
 
Last edited by Kirblinkness,
Yo, I just tried this with my aliexpress cart (accidentally flashed a save over address 00) but I got a white screen unfortunately. Not sure if I did something wrong?
EDIT Got it working THANK YOU SO MUCH!!!
Edit 2: Fire Red save gets deleted when I open the game :( any way to fix?
Which ROM did you try? The standard clean (with no other patches applied) fire red rom? I'll try that as soon as I get home but I've tried many ROMs based on fire red and they work, that's weird
The white screen usually happens when the ROM is unpatched, so I guess the first time you tried to flash the original file to the cartridge, but the second time that it worked and didn't save is really weird.
What kind of cartridge is that?

EDIT: I confirm patched clean USA fire red ROM works and saves flawlessly for me, maybe it's a cartridge incompatibility? The cartridges I use are recognized by gbabf as MSP128

1764862588224.png
1764862754222.png
 
Last edited by DanOl98,
Which ROM did you try? The standard clean (with no other patches applied) fire red rom? I'll try that as soon as I get home but I've tried many ROMs based on fire red and they work, that's weird
The white screen usually happens when the ROM is unpatched, so I guess the first time you tried to flash the original file to the cartridge, but the second time that it worked and didn't save is really weird.
What kind of cartridge is that?

EDIT: I confirm patched clean USA fire red ROM works and saves flawlessly for me, maybe it's a cartridge incompatibility? The cartridges I use are recognized by gbabf as MSP128

View attachment 543140 View attachment 543142
Apparently mine doesn’t have SRAM bank switching, could that be why? My cartridge is a MSP128 and I’m pretty sure I had a clean Fire Red since I got it from Vimms.
Post automatically merged:

Apparently mine doesn’t have SRAM bank switching, could that be why? My cartridge is a MSP128 and I’m pretty sure I had a clean Fire Red since I got it from Vimms.
I just tried to make a new save and now everytime I open the game it gives me “The save is corrupted, The previous save file will be loaded”
Post automatically merged:

Apparently mine doesn’t have SRAM bank switching, could that be why? My cartridge is a MSP128 and I’m pretty sure I had a clean Fire Red since I got it from Vimms.
Post automatically merged:


I just tried to make a new save and now everytime I open the game it gives me “The save is corrupted, The previous save file will be loaded”
Is there any way you can send me the link to the Aliexpress listing you bought for fire red? I think this cart is just crappy lol. I'm guessing based on what I've looked up that I definitely need SRAM bank switching to do this.
 
Last edited by Kirblinkness,
I would love if someone made a bootleg cartridge of Pokemon Lazarus! Awesome work hopefully this encourages people to put there rom hacks on cartridges.
 
Apparently mine doesn’t have SRAM bank switching, could that be why? My cartridge is a MSP128 and I’m pretty sure I had a clean Fire Red since I got it from Vimms.

Honestly, I thought that all the (or at least the recent ones) low-cost batteryless bootleg pokémon cartridges used SRAM bank switching.
Unfortunately, I don't have enough experience in how these cartridges work and how many different types exist, since I only ported the pre-made patch for these cartridges, maybe soneone else could shine a light on this though

I would love if someone made a bootleg cartridge of Pokemon Lazarus! Awesome work hopefully this encourages people to put there rom hacks on cartridges.
Well as @metroid maniac said, the patch could theoretically work on 32MB cartridges too, I'll test it as soon as the one I ordered arrives
 
Honestly, I thought that all the (or at least the recent ones) low-cost batteryless bootleg pokémon cartridges used SRAM bank switching.
Unfortunately, I don't have enough experience in how these cartridges work and how many different types exist, since I only ported the pre-made patch for these cartridges, maybe soneone else could shine a light on this though


Well as @metroid maniac said, the patch could theoretically work on 32MB cartridges too, I'll test it as soon as the one I ordered arrives
I hope it works lol.
 
Honestly, I thought that all the (or at least the recent ones) low-cost batteryless bootleg pokémon cartridges used SRAM bank switching.
Unfortunately, I don't have enough experience in how these cartridges work and how many different types exist, since I only ported the pre-made patch for these cartridges, maybe soneone else could shine a light on this though


Well as @metroid maniac said, the patch could theoretically work on 32MB cartridges too, I'll test it as soon as the one I ordered arrives
The seller accidentally sent me 2 copies of each GBA game in my package I just got
Honestly, I thought that all the (or at least the recent ones) low-cost batteryless bootleg pokémon cartridges used SRAM bank switching.
Unfortunately, I don't have enough experience in how these cartridges work and how many different types exist, since I only ported the pre-made patch for these cartridges, maybe soneone else could shine a light on this though


Well as @metroid maniac said, the patch could theoretically work on 32MB cartridges too, I'll test it as soon as the one I ordered arrives
It’s weird but by absolute coincidence they accidentally sent me another copy of Fire Red in my Pokémon Ruby package today, and it has SRAM bank switching enabled!!! My save works and everything so I think it was just a crappy chip.
 
Whoa, I was reading up on how to do this. I went so far as to get CMAKE installed and learnt how to use it vaguely from the help menu, then I installed VIsual Studio...and somehow stumbled upon this thread in the process. It made what seemed like a large task, into a simple click and okay process. Thank you!

I got Pokemon - Ash Gray (ROM hack) working on a cheap little 2 dollar Emeral cart I ordered from Aliexpress.

It says that the save is corrupted and the previous load will be loaded, but that's what the Chinese roms say too with a modified message.

My cart has a 16 MB ROM, and a 512K save. So I was thinking it wouldn't be possible after the first time I loaded the clean Fire Red ROMhack it said that the 1M sub board was not installed and it gave me a could not save error. Thanks for this. You made it easy to do the task that I'm sure a lot of people did over and over again in a tedious manner, possibly even tearing their hair out. You.
 
Whoa, I was reading up on how to do this. I went so far as to get CMAKE installed and learnt how to use it vaguely from the help menu, then I installed VIsual Studio...and somehow stumbled upon this thread in the process. It made what seemed like a large task, into a simple click and okay process. Thank you!

I got Pokemon - Ash Gray (ROM hack) working on a cheap little 2 dollar Emeral cart I ordered from Aliexpress.

It says that the save is corrupted and the previous load will be loaded, but that's what the Chinese roms say too with a modified message.

My cart has a 16 MB ROM, and a 512K save. So I was thinking it wouldn't be possible after the first time I loaded the clean Fire Red ROMhack it said that the 1M sub board was not installed and it gave me a could not save error. Thanks for this. You made it easy to do the task that I'm sure a lot of people did over and over again in a tedious manner, possibly even tearing their hair out. You.
Well, I'm happy to know my efforts are useful to someone! That's the reason I published this instead of just keeping it to myself.

Btw, in my case, the ashgray rom works perfectly without giving me any warning/error, maybe your cartridge doesn't have dual banking? If that's the case, let me know if there are any side effects in using this patch with a cartridge like that, since the patch comes from a cartridge with dual banking. I use cheap 2/3 eur cartridges too (the ones I got the patch from), but mine have dual banking
 

Site & Scene News

Popular threads in this forum