Jump to content

Recommended Posts

Posted

Pokémon Structure in RAM
Due to a lack of documentation regarding how Pokémon are stored in RAM during battle of the generation 4 games I have taken it upon myself to document how they are structured and how to extract them. I've found that the Pokémon data is stored around the addresses 002C0BC2 to 002D5780 when a RAM dump is viewed in a hex editor. The length of the data is of 128 bytes (decimal value) or 80 bytes (hexadecimal value) per Pokémon. With that the following is the structure of Pokémon data in the RAM of generation 4 main line games if the relevant 128 bytes were extracted from the RAM; therefore, I'll be starting at address 0x00. Please note that for all values that use 2 or more bytes the values are stored in little-endian format.

Offset   Content
0x00-0x01 National Pokédex identification number.
0x02-0x0B

0x02-0x03 = Attack stat

0x04-0x05 = Defense stat

0x06-0x07 = Speed stat

0x08-0x09 = Special attack stat

0x0A-0x0B = Special defense stat

0x0C-0x13 The moves known by the Pokémon with every two bytes corresponding to the move index.
0x0C-0x0D = Move 1
0x0E-0x0F = Move 2
0x10-0x11 = Move 3
0x12-0x13 = Move 4
0x14-0x17

IVs, IsEgg Flag, IsNicknamed Flag.  Same as in Block B of PKM Structure for Gen 4 found in the tech documents.

 

0x18-0x1F

This set of bytes start at 06 and keeps track of the how the stats of the Pokémon have increased or decreased during the battle.  Example 00 = a decrease in a stat by -6 stages and 0C = an increase in a stat by +6 stages.
 

0x20-0x21

These bytes are linked to the species of the Pokémon in some way.  As such a byte combination of 70 0B will be set there if the opposing Pokémon is a Lugia.

0x22-0x23 Unused, in all tests. All bytes have been 00 and after many tests these bytes did not change.
0x24-0x25

These bytes are linked to the species of the Pokémon in some way.  As such a byte combination of 0E 02 will be set there if the opposing Pokémon is a Lugia.

0x26 Pokémon form index. If the Pokémon does not have more than one form or the Pokémon is in its base form this value will be 00. Note form and evolution stage are different concepts.
0x27 Ability index
0x28 Unused, in all tests. All bytes have been 00 and after many tests these bytes did not change.
0x29

Appears to change if the Pokémon has a blanket ability activated.  00 = no blanket ability and 04 = the Pressure ability.  It is unclear if this byte can have a value other than 00 or 04 depending on the ability.

0x2A-0x2B Unused, in all tests. All bytes have been 00 and after many tests these bytes did not change.
0x2C-0x2F Current Power Points of moves.
0x2C = Power Points Remaining for move 1
0x2D = Power Points Remaining for move 2
0x2E = Power Points Remaining for move 3
0x2F = Power Points Remaining for move 4
0x30-0x33 Number of PP UPs used for each move.
0x30 = Number of PP Ups used on move 1
0x31 = Number of PP Ups used on move 2
0x32 = Number of PP Ups used on move 3
0x33 = Number of PP Ups used on move 4
Values cannot exceed hexadecimal value 03.
0x34 Current level of Pokémon. Value cannot exceed hexadecimal value 64.
0x35 Happiness of Pokémon.
0x36-0x4B

Pokémon nickname.  If no nickname is set the Pokémon species name will be stored here with a terminating FF value. Note this is a character array; therefore, little-endian formatting does not apply here.

0x4C-0x4D The current Hit Point value of the Pokémon.
0x4E-0x4F Unused, in all tests. All bytes have been 00 and after many tests these bytes did not change.
0x50

The max Hit Point value of the Pokémon.

0x51-0x53 Unused, in all tests. All bytes have been 00 and after many tests these bytes did not change.
0x54-0x63 Original trainer (OT) name.  If the Pokémon belongs to a non-playable character (NPC) all bytes will be 00 with a terminating FF. Note this is a character array; therefore, little-endian formatting does not apply here.
0x64-0x67 Current EXP.  If the Pokémon belongs to a NPC all bytes will be 00.
0x68-0x6B Pokémon personality identification number (PID).
0x6C This byte gets set if the Pokémon is affected with a status condition that is not temporary such as burn or poison.
0x6D-0x73

Each byte correlates with a temporary status condition.  For example the byte set for confusion is the counter for how many turns is remaining before the confusion status effect wears off.

0x74-0x75 Trainer identification number (ID).
0x76-0x77 Trainer secret identification number (SID).
0x78-0x79 The index of the item that the Pokémon is holding.
0x7A-0x7D

Each byte correlates with a status condition that is not temporary.  The byte set for sleep is the counter for how many turns is remaining before the wakes up.

0x7E

This byte is the gender of the Pokémon.  00 = male, 01 = female, 02 = genderless.

0x7F

This byte is the type of Poke Ball that the Pokémon is in.  If it is in a special ball from Pokémon Heart Gold or Pokémon Soul Silver this byte will be 04 which is the same as the Poke Ball.

--footer--

Pokémon Extraction
In order to easily extract a Pokémon from RAM I recommend dumping the RAM as soon as the Pokémon that you want to extract is sent into battle.  This is done so when viewing the RAM in a hex editor you can find a string of bytes that is both unique enough that it will not appear multiple times in the RAM and consistent with any Pokémon currently in the RAM. With that said the string of bytes that meets both of these conditions in most cases is the stat increase/decrease values with would be 06 06 06 06 06 06 06 06. Please note if an ability such as Intimidate or Download actives before dumping the RAM you will have to adjust the string of bytes accordingly. In a standard 1 vs 1 battle the first Pokémon that will appear in the RAM will be yours and the second one will be your opponents. From there follow how a Pokémon is stored in the save file in order to rearrange the data to create a valid PK4 file.
Update:
I have developed an application that can find and extract Pokémon from a generation 4 RAM dump file. Application can be downloaded from here


Additional Reading

Spoiler

Generation three Pokemon mapping in RAM:

How to Extract Pokémon from Gen 5 RAM:
https://projectpokemon.org/home/forums/topic/56963-extracting-pokemon-from-generation-5-ram/?tab=comments#comment-256555

RAM to PKX Rip (Pokémon from RAM extractor):
https://projectpokemon.org/home/files/file/4187-ram-to-pkx-rip/

 

  • Like 2
Posted

Now that I'm done school for the semester I figured that I would finish conducting tests to try and fill in the missing data in the structure, as well update the data that I was unsure about.  Therefore, the original post has been updated to reflect my most recent tests and now I feel relatively certain that the presented data is accurate.  I most likely will not be making any changes to the above table or carry out further tests on this subject.

  • Like 1
  • 3 weeks later...
  • Poke J changed the title to Structure of Pokémon in RAM from Generation 4 Games
  • 5 months later...
Posted
13 minutes ago, shadowfrogtommy said:

I don't know if you are still doing tests and updating this table but you should try testing things like spikes, stealth rocks, and toxic spikes.

I’m currently not testing since I’ve found the information that I needed for my application and interests. Maybe some day down the road I’ll look at this again.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...