• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Forum moderator applications are now open! Click here for details.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[FireRed] Expand Max # of Trainers

52
Posts
14
Years
  • Seen Jul 30, 2023
Hello!

While trying to make my own hack, I ran out of trainer slots. (Yes, all 743 trainer slots. That's a lot.)
So I started looking for an answer to that here. But my searches turned up empty. Not one to be deterred, I kept working at it until I found my solution. And after rigorous testing to make sure it worked, I have decided to share how I did it.

DISCLAIMERS
1.While this is for FireRed, it can absolutely be done in Emerald, the offsets will be different, however.

2.As always, BACKUP BACKUP BACKUP. Do not complain to me I screwed up your ROM.

3. Every number I will be mentioning is in hex unless otherwise specified. so if I say 0x50, I don't mean 50. I mean 80.

Step One

So first thing's first, you're going to need a hex editor. (I personally like HxD, but to each their own)
You're also going to need Free Space Finder.

Navigate to 0x823EAC8
This is where the Trainer Table starts. It is 0x7418 bytes in length. So you're going to want to select it all.
If you don't end at 0x8245EE0, you've selected the wrong amount.

Now we are going to move the table. So open up Free Space Finder. Here's where we have to do a bit of math.

So the table is the exact size of 29,720 bytes. (<---This isn't hex)
Each trainer requires 40 more bytes. (Again not hex.)
So to figure out how much space you need, we need to do the following:

29720 + (# of new trainers * 40) = Free Space Needed

For my own hack, I added 257 trainers just to make it an even 1000. So...

29720 + (257 * 40) = 40,000

So in Free Space Finder, I would enter 40,000.
The offset it gives you is important, write it down, we'll need it.

Now copy the old trainer table to the new offset FSF has given you.
(At this stage, you can replace all the values at the original trainer table location with FFs to free up space, as this is a lot of space we're taking up already and you won't need the old table anyway.)

Step Two

Now, at the end of the new table, is just a bunch of FFs. This WOULD be fine, if it were not for the fact that at the end of each trainer's 0x28 bytes long section is an offset pointing to a place in the ROM. So if you opened up a trainer editor and it tried to look for FF FF FF FF, it would produce an error because that is outside the ROM area. So these all have to be changed to 00.

I created 257 trainers, so 257 * 0x28 (<--- Doing hex again) is 10,280 bytes. Converting THAT to hex, is 0x2828. So I need to select 0x2828 of the FF, and change them to 00.

Step Three

Now you have to go to 0x800FC00.
This is the offset that points to the location of the trainer table.
The value should be C8 EA 23 08. Which means it's still pointing to 0x823EAC8, the original trainer table.
We are going to change it to the starting location of our new trainer table.
For example, I placed mine at 0x8855DC0, so I enter C0 5D 85 08.

Step Four

The next step (Props to SBird for pointing this out) is to change where the trainer flags start so as not to overlap with existing game flags.
Now if you want to have over 1,000 trainers, then you will have to tweak the table SBird left in the comments below to your needs. (The values need to change, not the offsets)

You will also need to expand the number of 'safe flags'. There is a tutorial on doing so HERE, I recommend doing this first before continuing.

Now that we've taken care of that, and if you're doing 1,000 like myself, the steps are as follows:

At 0x8080382, replace A0 21 with 80 21.
At 0x80800BA, replace A0 22 D2 00 with 80 22 52 01.
At 0x8080428, replace A0 21 with 80 21.
At 0x8080440, replace A0 21 with 80 21.
At 0x8080454, replace A0 21 C9 04 with 80 21 49 05.

You can now save and close your Hex Editor.

Step Five

The last step is to go to your trainer editor's folder. There should be an .ini file. I use Hopeless Trainer Editor, but this should apply to A-Trainer as well.

Inside should be a line with "NumberOfTrainers". (It may be called something else in A-Trainer)
Change the value to the amount of trainers + the amount you added. So for me, it was 1000. (<---Not Hex!)

And that should be it!
You should be able to open your trainer editor and have new trainers at the end of the list.
 
Last edited:
794
Posts
10
Years

You're missing one thing here. Each trainer has a flag attached to him, so the game knows whether you beat them or not. Now, the number of trainer flags is equal to the number of trainers. What you're doing is overwriting other flags or maybe even vars.
 

jiangzhengwenjzw

now working on katam
181
Posts
11
Years
  • Seen today
I don't think it will work, as the trainer flags are not handled correctly. The flags will conflict with menu flags, etc
 
52
Posts
14
Years
  • Seen Jul 30, 2023
You're missing one thing here. Each trainer has a flag attached to him, so the game knows whether you beat them or not. Now, the number of trainer flags is equal to the number of trainers. What you're doing is overwriting other flags or maybe even vars.

Did not think of that...

Welp, now I have to think of a way around that.
 
91
Posts
14
Years
  • Seen Feb 22, 2023
The trainerflags are handled just as normal flags, and are hardcoded to have a range starting at 0x500. So if you have expanded your flags already all you would want to do is twist and tweak the region, so they don't collide with internal flags (Menu Entries etc.)

I set them to begin at 0x1000, just because it is easier to handle with binary operations, since 0x500 is also easy to calculate using binary operations, the numbers are all calculated with shifts. The respective calculations are (FRE) as follows if you want to use 0x1000 as your new base for flags:

Code:
.org 0x08080382                       	mov r1, #0x80                       	lsl r1, #0x15                        
                      .org 0x080800BA                       	mov r2, #0x80                       	lsl r2, #0x5                        
                      .org 0x08080428                           mov r1, #0x80                           lsl r1, #0x15                        
                      .org 0x08080440                           mov r1, #0x80                           lsl r1, #0x15                        
                      .org 0x08080454                           mov r1, #0x80                           lsl r1, #0x15

Happy Hacking!

~SBird
 
52
Posts
14
Years
  • Seen Jul 30, 2023
The trainerflags are handled just as normal flags, and are hardcoded to have a range starting at 0x500. So if you have expanded your flags already all you would want to do is twist and tweak the region, so they don't collide with internal flags (Menu Entries etc.)

I set them to begin at 0x1000, just because it is easier to handle with binary operations, since 0x500 is also easy to calculate using binary operations, the numbers are all calculated with shifts. The respective calculations are (FRE) as follows if you want to use 0x1000 as your new base for flags:

Code:
.org 0x08080382                       	mov r1, #0x80                       	lsl r1, #0x15                        
                      .org 0x080800BA                       	mov r2, #0x80                       	lsl r2, #0x5                        
                      .org 0x08080428                           mov r1, #0x80                           lsl r1, #0x15                        
                      .org 0x08080440                           mov r1, #0x80                           lsl r1, #0x15                        
                      .org 0x08080454                           mov r1, #0x80                           lsl r1, #0x15

Happy Hacking!

~SBird

Wow, I wasn't expecting to wake up this morning to a solution!
I am very grateful. I'm going to add this to the OP. (With credit of course)
 
91
Posts
14
Years
  • Seen Feb 22, 2023
Feel free to use of course, but note that as long as you don't have your flags expanded this will definitely not work. All those routines (As far as I remember) work as follows:

get the trainer flag ID (= Trainer ID)
add a constant C to it (0x500)
call the flag handler, to set / clear a flag

So you will need to have a dedicated region of memory for your flags (> 0x1000 if you use my version) and hack the flag handler to accept those flags, as well as link them to the allocated memory region.

Otherwise, what will happen is: The game will try to call set_flag(0x1000+) and the internal boundary check will invalidate the call, so set_flag and clear_flag wont work, and check_flag will always return false, resulting in trainerbattles with those trainers won't work.

Also note, that it would be a waste of space if you relocate all trainer flags like this, because it will leave the flag region [0x500; ORIGINAL_TRAINER_MAX + 0x500] blank, you could simply use them as internal script flags in order to have a "save space".

It all comes down to expanding your flags though, there is a tutorial from jambo51 I think if you are not able to figure it out on your own.

~SBird
 

Shogun

I'll be back
527
Posts
10
Years
If I want to increase the max amount to 1200 and not 1000, what souhld I changed in SBird's script?
Is there something that I should change here :
Spoiler:
 
22
Posts
15
Years
  • Age 37
  • Seen Sep 15, 2021
Okay, this confuses me to no end. I've been working on a romhack of Fire Red for about a month, and this is the second thread that purports hex editing well past the final offset. What sort of rom do these guys have that 0x823EAC8 is actually a valid offset? I try to go to that offset, and since it does not exist, I cannot go to it. What the ever-loving krobgobb am I missing?

Oh, by the way: I'd like this so I can manually make modified versions of trainers based on the number of badges you have. I settled on 3 additional trainerIDs per trainer, and I'll use custom scripting to start the battle with whichever ID is appropriate for the number of badges. No additional flags needed.
 

Delta231

A noob
681
Posts
7
Years
How would I go about expanding the max # of trainers in Emerald or pokeemerald?

For EM you need to be find the right offset by copying bytes from that address in FR and search them in EM.


For PokeEM just look through all trainer related files.
 
81
Posts
7
Years
  • Age 30
  • Seen Mar 23, 2024
For Ruby:


Ruby

At 0x808250E, replace A0 21 with 80 21.
At 0x8082266, replace A0 22 D2 00 with 80 22 52 01.
At 0x80825A8, replace A0 21 with 80 21.
At 0x80825C0, replace A0 21 with 80 21.
At 0x80825D4, replace A0 21 C9 04 with 80 21 49 05.
 

Zeta Sukuna

Descendant of the Inchlings
1,726
Posts
16
Years
Does that flag solution actually work for Emerald? I've been trying to implement it, and all I've gotten was trainers simply looping after battles, and the trainer flags not being repointed.

I've used Sierraffinity's port of JPAN's Save Block Hack detailed in this post: https://www.pokecommunity.com/showthread.php?t=324892

And Starfall321's port of Jambo51's extra flags ASM found here: https://www.pokecommunity.com/showpost.php?p=9280649&postcount=946

For transparency's sake, and for the sake of giving people a direction, these are the values I found that seem similar enough:

B16C2 - 1st change (A0 21)
B127A - 2nd change (A0 22 D2 00)
B17A4 - 3rd change (A0 21)
B17BC - 4th change (A0 21)
B17D0 - 5th change (A0 21 C9 04)
 
Last edited:
Back
Top