• 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.

Research: Pokémon Data Structures (Firered)

redriders180

Mastermind of Pokemon Glazed
314
Posts
13
Years
Time for me to appeal to the researchers of Pokecommunity in order to help with some things that might be interesting to do in a Rom Hack. Mainly, I'm talking about taking the Pokémon data structures, and modifying them to allow more useful things to be done with that data. To save you the trouble, I've copied the current data structures of the Gen III games:

Spoiler:


and the encrypted data:

Spoiler:

The above being copied from Bulbapedia.

Glancing at the above, there are many slots in the data that aren't used in Firered. Additionally, there are a few bytes that might not serve a purpose in a ROM hack, specifically language, which serves a purpose I currently don't know. I've heard that Pokerus in Firered is nonexistant as well, and the byte is basically unused. The six contest stats, and ribbons are also sitting unused. This unused data could be useful in porting over functions from Gen IV and V into Gen III. The "Pokerus Remaining" byte is the only unencrypted value I'm comfortable hacking, unless I receive confirmation that the language half-word is essentially unused.

The main function I have in mind for this byte is to breathe new life into a thread that seems to have hit a dead end: Hidden abilities. After browsing that thread, it seems most people were hung on the fact that abilities are controlled by a single bit, meaning two is the max. If we could somehow redirect the code to this byte, instead of to the bit that determines ability, we could easily figure out a way to unlock hidden abilities.

Gen IV also uses a byte for forme determination. I believe Jambo51 and Chaos Rush have been working on a method for enabling forme changes in their 649 Patches, and they probably use a different method to achieve it, this could be an alternate way. The Gen I and II games have a section of data in their Pokemon data structures that accounts for both primary and secondary typing. If we could use the Pokerus Remaining byte, as well as the language half-word, formes with different types could become more feasible.

The data structure could be used in plenty of other ways not mentioned, but I can't currently think of. I was hoping to collaborate to see if anyone has any info on how these structures are stored and modified, in addition to info that could be used for anything else I might've mentioned. If anything, I hope I set the wheels turning for someone out there :)
 
Last edited:
150
Posts
15
Years
but doesn't the pokerus remaining byte get removed if u box a pokemon? i'm not really sure if it will save that value and load it or randomize it when u take it out.

Also unless i'm mistaken, isn't the bit that controls ablility the last bit in the 'personality' dword? this word controls every random attribute a pokemon has when its first met (i think neway...), and theres no other check for ability otherwise. So in this case, in order for a hidden ability to exist, the game would have to run a check to see if the byte for the hidden ability (in the pokemon data structure) was set and load the hidden ability, and run the normal ability check if its not present (because that byte wouldn't exist for wild pokemon). Which could be done, i guess, but would take a lot of work to make it work. [I might be totally wrong about this tho XD]

And i'm not totally sure of this, but the language word might be used in a check somewhere when trading pokemon between different language versions? i dunno... bulbapedia has given a list of valid values, so i guess there must be a check somewhere....

newayz... sorry i'm such a wet blanket :P... but i guess if we could find some use for it, it could lead to some pretty cool new features :)
 

NarutoActor

The rocks cry out to me
1,974
Posts
15
Years
Pokerus is only in FireRed for compatibility with the other games. But since it lacks a RTC, it is unlimited if a pokemon already has it, and imposable without trading/cheating.
 

redriders180

Mastermind of Pokemon Glazed
314
Posts
13
Years
but doesn't the pokerus remaining byte get removed if u box a pokemon? i'm not really sure if it will save that value and load it or randomize it when u take it out.

Also unless i'm mistaken, isn't the bit that controls ablility the last bit in the 'personality' dword? this word controls every random attribute a pokemon has when its first met (i think neway...), and theres no other check for ability otherwise. So in this case, in order for a hidden ability to exist, the game would have to run a check to see if the byte for the hidden ability (in the pokemon data structure) was set and load the hidden ability, and run the normal ability check if its not present (because that byte wouldn't exist for wild pokemon). Which could be done, i guess, but would take a lot of work to make it work. [I might be totally wrong about this tho XD]

And i'm not totally sure of this, but the language word might be used in a check somewhere when trading pokemon between different language versions? i dunno... bulbapedia has given a list of valid values, so i guess there must be a check somewhere....

newayz... sorry i'm such a wet blanket :P... but i guess if we could find some use for it, it could lead to some pretty cool new features :)

Well, according to my research, it seems that this byte isn't affected at all during Firered. Pokerus is actually preserved when you store the Pokemon in the PC. Pokerus is designed to end at midnight, and due to Firered's lack of a RTC, it just stays on a Pokemon indefinately. I don't believe you can even find it in the wild in the Firered games...the byte is only there to allow for compatability between RSE, which DO use that byte.

My idea would require the code that generates Pokemon to be modified somewhat. Currently, ability is decided whether or not the personality value is odd or even. We could modify that code to instead use the pRNG (another source of randomness in-game), see if it's even or odd, and then load the byte value of the corresponding ability into the newly-made "ability" byte. We would also need to modify how an ability is read, by making it use that byte instead of the original way.

Since most hacks are designed as a stand-alone game, trading between games isn't foremost on my mind. I thought it might have something to do with an experience boost, but foreign language trades don't get a boost until Gen IV.

I also neglected to mention...some people might want to use the Pokerus byte for what it was actually intended for, to give someone Pokerus that actually does expire and is generated.

Thanks for everyone's support so far :)
 
150
Posts
15
Years
Well, according to my research, it seems that this byte isn't affected at all during Firered. Pokerus is actually preserved when you store the Pokemon in the PC. Pokerus is designed to end at midnight, and due to Firered's lack of a RTC, it just stays on a Pokemon indefinately. I don't believe you can even find it in the wild in the Firered games...the byte is only there to allow for compatability between RSE, which DO use that byte.

no what i meant was when u store a pokemon in the box, the data for the pokerus remaining byte gets erased, since only 80 bytes of data are stored for each pokemon in the boxes. What i'm not sure of is what happens to the pokerus byte tho... does that value get saved somewhere? or does the pokemon get re-infected when it gets taken out?

My idea would require the code that generates Pokemon to be modified somewhat. Currently, ability is decided whether or not the personality value is odd or even. We could modify that code to instead use the pRNG (another source of randomness in-game), see if it's even or odd, and then load the byte value of the corresponding ability into the newly-made "ability" byte. We would also need to modify how an ability is read, by making it use that byte instead of the original way.

but again, this would only apply to pokemon in the party or pokemon the player owns (depending on using the 'language' or the 'pokerus rmn' data we use) cuz I dont think wild pokemon and enemy pokemon have this data...


Newayz... I'm not gonna pretend I kno everything about the game, mechanics or otherwise, as I've only played these games very casually (gen 1-3... no 4+). I'm just going by what i read on bulbapedia about how this stuff works, so feel free to correct me if I'm wrong
 

redriders180

Mastermind of Pokemon Glazed
314
Posts
13
Years
no what i meant was when u store a pokemon in the box, the data for the pokerus remaining byte gets erased, since only 80 bytes of data are stored for each pokemon in the boxes. What i'm not sure of is what happens to the pokerus byte tho... does that value get saved somewhere? or does the pokemon get re-infected when it gets taken out?



but again, this would only apply to pokemon in the party or pokemon the player owns (depending on using the 'language' or the 'pokerus rmn' data we use) cuz I dont think wild pokemon and enemy pokemon have this data...


Newayz... I'm not gonna pretend I kno everything about the game, mechanics or otherwise, as I've only played these games very casually (gen 1-3... no 4+). I'm just going by what i read on bulbapedia about how this stuff works, so feel free to correct me if I'm wrong

I thought the Pokerus byte was saved higher up, but the last 20 bytes are recalculated when a Pokemon is taken out of the PC.

Bulbapedia said:
Pokémon that are put into the PC will keep the status indefinitely.

I think I realize why this is. The Pokerus "flag" is part of the encrypted data subsection of the Pokemon's data. It doesn't get erased when the Pokemon is put in the PC. I assume that, when a Pokerus'd Pokemon is taken out of the PC, it checks if the Pokerus flag is set, and if it is, it'll reset the "Pokerus Remaining" byte.

That's not to say this is a dead end...the Pokerus "flag" could be used as a "Hidden Ability flag", and when the Pokemon is taken out of the PC, it'll recalculate what the hidden ability is supposed to be.

Enemy Pokemon are stored in the same format as the team. There are 600 Bytes for the party Pokemon, and 600 bytes reserved for enemy Pokemon. In reality, you could make a "settrainerbattle" script, modify the data in it with writebytetooffset, and then use "repeattrainerbattle" to activate it.

Edit:
Bulbapedia said:
Pokérus status is stored in a single byte. The lower 4 bits represents the number of units of time left until the virus wears away. If any bit in the upper 4 bits is set, the Pokémon is immune to Pokérus, indicated a small black dot appears on the Pokémon's status screen. Both values are completely random when caught, leading to the fact that not all Pokémon contract the virus for the same amount of time and some are able to catch it again.

I'm going to need to do some research, to see if these bytes are actually used in the Firered games.

Double Edit: At least with givepokemon, these bytes are zero, which means that they shouldn't be an issue.
 
Last edited:

Jambo51

Glory To Arstotzka
736
Posts
14
Years
  • Seen Jan 28, 2018
You need to tidy up the list of unencrypted data, it's very hard to read in the format you have it in.

Anyway - For the creation of formes in FR, I actually used the upper half of the mark byte as storage for the forme ID. There are 4 marks, which can be set to on or off, which is, of course, a binary setting, which means they use a bit each.

This leaves 4 bits in the upper half of that byte which are unused. After a minor rewrite of the decrypter and encrypter, I was able to gain these bits for my own use.

4 bits allows for 16 possible combinations, which is actually quite a lot in terms of formes.

The "upper half" of the byte refers to the leftmost bits in binary:

128 64 32 16 8 4 2 1

In more ROM hacking orientated terms, it means that of a mark byte 0x32, the 0x30 stands for the forme the Pokémon is currently in while the 0x2 stands for which marks is has assigned to it.
 

redriders180

Mastermind of Pokemon Glazed
314
Posts
13
Years
You need to tidy up the list of unencrypted data, it's very hard to read in the format you have it in.

Anyway - For the creation of formes in FR, I actually used the upper half of the mark byte as storage for the forme ID. There are 4 marks, which can be set to on or off, which is, of course, a binary setting, which means they use a bit each.

This leaves 4 bits in the upper half of that byte which are unused. After a minor rewrite of the decrypter and encrypter, I was able to gain these bits for my own use.

4 bits allows for 16 possible combinations, which is actually quite a lot in terms of formes.

The "upper half" of the byte refers to the leftmost bits in binary:

128 64 32 16 8 4 2 1

In more ROM hacking orientated terms, it means that of a mark byte 0x32, the 0x30 stands for the forme the Pokémon is currently in while the 0x2 stands for which marks is has assigned to it.

Heh, I guess it would be a good idea to proofread before I post...I'll tidy that up after I do this post.

I had noticed the marks that are used for boxes, and I thought it could be useful, since I don't really know anyone who uses them, except that they're modifiable on a whim. That was a good idea for the formes, though! Maybe we could use a similar method for abilities, or other things.

If it's not too much to ask, would you share your routine for decrypting the "data" subsection? :)
 
Last edited:
150
Posts
15
Years
I think I realize why this is. The Pokerus "flag" is part of the encrypted data subsection of the Pokemon's data. It doesn't get erased when the Pokemon is put in the PC. I assume that, when a Pokerus'd Pokemon is taken out of the PC, it checks if the Pokerus flag is set, and if it is, it'll reset the "Pokerus Remaining" byte.

That's not to say this is a dead end...the Pokerus "flag" could be used as a "Hidden Ability flag", and when the Pokemon is taken out of the PC, it'll recalculate what the hidden ability is supposed to be.


Edit:

I'm going to need to do some research, to see if these bytes are actually used in the Firered games.

Double Edit: At least with givepokemon, these bytes are zero, which means that they shouldn't be an issue.

ah... haha ur right... it would make sense for it to reset it based on the flag and not randomly :P... I dont know where my brain was when i was thinking that... but then we wouldn't be able to see the ability unless it was in our party, right? or is that how hidden abilites are supposed to work? Like ur not supposed to see em, they just work?

Wouldn't it just be easier to use the pokerus flag itself? like if we use the upper 4 bits while keeping the lower 4 bits 0, then the pokemon would never contract pokerus (cuz i believe pokerus is coded in the game, it just is never used), and the upper 4 bits can be put to use.

Enemy Pokemon are stored in the same format as the team. There are 600 Bytes for the party Pokemon, and 600 bytes reserved for enemy Pokemon. In reality, you could make a "settrainerbattle" script, modify the data in it with writebytetooffset, and then use "repeattrainerbattle" to activate it.

ah k... i didn't kno that... so when u encounter a pokemon (trainer or wild) the entire 100 bytes for the pokemon gets generated?

If it's not too much to ask, would you share your routine for decrypting the "data" subsection?

doesnt JPAN have a routine that decrypts it as part of his hacked engine? u could use that as a base...

You need to tidy up the list of unencrypted data, it's very hard to read in the format you have it in.

Anyway - For the creation of formes in FR, I actually used the upper half of the mark byte as storage for the forme ID. There are 4 marks, which can be set to on or off, which is, of course, a binary setting, which means they use a bit each.

This leaves 4 bits in the upper half of that byte which are unused. After a minor rewrite of the decrypter and encrypter, I was able to gain these bits for my own use.

4 bits allows for 16 possible combinations, which is actually quite a lot in terms of formes.

The "upper half" of the byte refers to the leftmost bits in binary:

128 64 32 16 8 4 2 1

In more ROM hacking orientated terms, it means that of a mark byte 0x32, the 0x30 stands for the forme the Pokémon is currently in while the 0x2 stands for which marks is has assigned to it.

With the forms, the routine your using loads all the pokemon data, right? like type and stats and stuff and not only graphics? So then a branch could be made in that routine using the pokerus data as a check to determine if a pokemon has a hidden ability as well?


--------------------------------------------------------------------------

sorry bout all this, but i figured the easiest way to learn is just by asking you guys :P
 

redriders180

Mastermind of Pokemon Glazed
314
Posts
13
Years
ah... haha ur right... it would make sense for it to reset it based on the flag and not randomly :P... I dont know where my brain was when i was thinking that... but then we wouldn't be able to see the ability unless it was in our party, right? or is that how hidden abilites are supposed to work? Like ur not supposed to see em, they just work?

Wouldn't it just be easier to use the pokerus flag itself? like if we use the upper 4 bits while keeping the lower 4 bits 0, then the pokemon would never contract pokerus (cuz i believe pokerus is coded in the game, it just is never used), and the upper 4 bits can be put to use.
This would also serve a nifty dual-purpose...the little dot that indicates that a Pokemon has had Pokerus before could be repurposed as a "Dream World" indicator.

If anything, we'd still have to rework fair amounts of the code, such as the code that displays which ability a Pokemon'd have. It would have to display by reading the "Ability" byte, and then displaying whatever ability corresponds with that byte. Just another thing to modify...


ah k... i didn't kno that... so when u encounter a pokemon (trainer or wild) the entire 100 bytes for the pokemon gets generated?
Yep!


doesnt JPAN have a routine that decrypts it as part of his hacked engine? u could use that as a base...
I was hoping to not have to mess around with trying to find the ASM of the original special, and even then, try to decipher it. I do know that his decryption formula is a little different...it stores the unencrypted data in one spot, and each different data section in one of four locations. I don't know whether that makes it easier or harder to work with, though...I was hoping to maybe get some other input on the subject.

For the formes, I've got a small idea about how they might work, at least, graphically speaking. One could make a larger-than-usual Pokemon sprite, similar to the ones in Emerald. You could then read the Forme Change byte, and depending on its value, shift up the image to display one of the other frames. This would just require a small addition to the graphics display code that draws the Front sprite of the opponent, Back sprite of your team, the preview in the PC, the party summary, and possibly the "ShowPokemonPic" command.
 
Back
Top