#1
November 15th, 2016 (9:39 AM). Edited December 3rd, 2016 by esipode.
 esipode Join Date: Feb 2010 Posts: 47
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.

#2
November 15th, 2016 (2:16 PM).
 DizzyEgg Join Date: Feb 2014 Location: Poland Age: 20 Gender: Male Nature: Quiet Posts: 715
Quote:
 Originally Posted by esipode Tut
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.
__________________
#3
November 15th, 2016 (6:27 PM).
 Crizzle Legend Join Date: Apr 2015 Location: USA Age: 22 Gender: Male Posts: 945
How is 743 trainer battles not enough for a hack!?
__________________
Pokemon Savage Silver hopefully coming out before rom hacking dies! Check out the trailer!

Check out the great completed hacks that I made:

Credit to Corazon(or whatever he calls himself now) for banner.
Pokemon CAWPS
Pokemon Outlaw
#4
November 15th, 2016 (7:37 PM).
 jiangzhengwenjzw You can (not) redo. Join Date: Sep 2012 Gender: Male Posts: 147
I don't think it will work, as the trainer flags are not handled correctly. The flags will conflict with menu flags, etc
__________________
My Github Page
#5
November 15th, 2016 (9:37 PM).
 esipode Join Date: Feb 2010 Posts: 47
Quote:
 Originally Posted by DizzyEgg 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.
#6
November 16th, 2016 (4:10 AM).
 SBird Join Date: Aug 2009 Gender: Male Posts: 83
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
#7
November 16th, 2016 (9:17 AM).
 esipode Join Date: Feb 2010 Posts: 47
Quote:
 Originally Posted by SBird 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)
#8
November 17th, 2016 (12:42 AM).
 SBird Join Date: Aug 2009 Gender: Male Posts: 83
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

# Join the conversation!

Create an account to post a reply in this thread, participate in other discussions, and more!