Save data structure (Generation II): Difference between revisions

From Bulbapedia, the community-driven Pokémon encyclopedia.
Jump to navigationJump to search
Line 410: Line 410:
| Money
| Money
|- style="background: #eeeeee; text-align: center;"
|- style="background: #eeeeee; text-align: center;"
| ?
| 0xD57C
| 0x23E5
| 0x23E5
| 1
| 1

Revision as of 08:31, 2 April 2016

292Shedinja.png The contents of this article have been suggested to be split into Character encoding in Generation II.
Please discuss it on the talk page for this article.
050Diglett.png This article is incomplete.
Please feel free to edit this article to add missing information and complete it.

0572Minccino.png This article does not yet meet the quality standards of Bulbapedia. Please feel free to edit this article to make it conform to Bulbapedia norms and conventions.

The save data structure for Generation II is stored in the cartridge's battery-backed RAM chip (SRAM), or as a ".sav" file from most emulators. The structure consists of 32 KB of data, though not every byte is used. Emulators may append additional data for the purposes of maintaining real-time clock operations.

Two regions of the save data have their integrity validated via checksums. These region contain all of the information that directly pertains to the player and his or her Pokémon. Additional information pertinent to the save file is also present in the other regions of the data.

Data types

Unless otherwise noted, integer values occupy the specified number of bytes, and are big-endian and either unsigned or two's complement.

Text data

Technically, all characters before 0x60 function as control characters. An asterisk (*) denotes a character that is explained in the control characters section below.

English

Only a few control characters below 0x50 are actually used in the English games, all of which are ones marked below with an asterisk (for more, see the control characters section further down where they are explained). The sub-0x50 characters that are not marked with an asterisk are artifacts of the Japanese control characters that print other characters with a diacritic.

-0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -A -B -C -D -E -F
0- ? B C D E F G H I J K L M N O P
1- Q R S T * * * X Y Z ( ) : ; [ *
2- q r * * * * w x y z            
3- Ä Ö Ü ä ö * * * * *           *
4- Z ( ) ":"           * * * * 'r * *
5- * * * * * * * * * * * * * * * *
6- Character 0x62 ii.png D E F G H I V S L M :
7- PO Ké text box borders  
8- A B C D E F G H I J K L M N O P
9- Q R S T U V W X Y Z ( ) : ; [ ]
A- a b c d e f g h i j k l m n o p
B- q r s t u v w x y z            
C- Ä Ö Ü ä ö ü                    
D- 'd 'l 'm 'r 's 't 'v                
E- ' PK MN -     ? ! . & é
F- $ × . / , 0 1 2 3 4 5 6 7 8 9

Japanese

-0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -A -B -C -D -E -F
0- ? イ゛ エ゛ オ゛
1- * * * ネ゛ ノ゛ * * *
2- ィ゛ あ゛ * * * *
3- * * * * * *
4- * * * * も゜ * *
5- * * * * * * * * * * * * * * * *
6- Character 0x62 ii.png D E F G H I V S L M :
7- ・・・ text box borders  
8-
9-
A-
B-
C-
D-
E- ? !
F- × . / 0 1 2 3 4 5 6 7 8 9

Control characters

050Diglett.png This section is incomplete.
Please feel free to edit this section to add missing information and complete it.
Reason: Any alternate defaults or functions in Gold and Silver or in other languages

The characters on a gray background below are not naturally used in the games.

Character Japanese English
0x14 Prints the player's name, including a gendered honorific in Japanese (adds くん for male, ちゃん for female).
0x15 Nothing. May break.
0x16 Nothing. May break.
0x1D Prints . Prints ;.
0x1E Prints って. Prints [.
0x1F Prints . Prints  .
0x22 Prints た!. A "half" line break (moves the print position to the place one tile below the start of the current line).
0x23 Prints こうげき. Prints tzx, but this appears to be junk data.
0x24 Prints は . Prints POKé.
0x25 Prints の . Nothing.
0x35 Prints ばん どうろ. Nothing.
0x36 Prints わたし. Nothing.
0x37 Prints ここは . Nothing.
0x38 Prints レッド. Prints RED.
0x39 Prints グリーン. Prints GREEN.
0x3F Prints the opposing Trainer's name (including their Trainer class). (Outside of battle, this may not terminate properly.)
0x49 Prints おかあさん. Prints MOM.
0x4A Prints . Prints PKMN.
0x4B Appears to be the same as 0x55
0x4C Appears to be the same as 0x55 except without any prompt or pause (immediately shifting the dialogue box's lines upwards)
0x4E Line break (moves the print position to the space two tiles below the start of the current line (as defined by explicit placements of the print position); mostly used in move descriptions and Pokédex entries).
0x4F Dialogue line break (moves the print position to the expected start of the second line in a standard dialogue box).
0x50 String terminator.
0x51 Prompts the player to press a button, after which the text window is cleared to make way for the following text.
0x52 Prints the player's name without an honorific.
0x53 Prints the rival's name.
0x54 Prints ポケモン. Prints POKé.
0x55 Prompts the player to press a button, after which the top line of the text window is replaced by the bottom, the bottom line is cleared, and the print position moves to the start of the bottom line.
0x56 Prints ...... (in the middle of the line in Japanese).
0x57 Marks the end of dialogue, without a visual prompt to the player.
0x58 Marks the end of dialogue, with a visual prompt to the player.
0x59 Prints the inactive* Pokémon's name in battle. (Outside of battle, this may not terminate properly.)
0x5A Prints the active* Pokémon's name in battle.
0x5B Prints パソコン. Prints PC.
0x5C Prints わざマシン. Prints TM.
0x5D Prints トレーナー. Prints TRAINER.
0x5E Prints ロケットだん Prints ROCKET.
0x5F Prints a period (0xE8) and simultaneously functions as a string terminator. (Only used in Japanese Pokédex entries.)

Item lists

Lists of items in the save data follow a particular format.

Lists have entries of 2 bytes each, and a capacity. The total size of the list data, in bytes, is:

Capacity * 2 + 2

For example, your pocket inventory can hold 20 item entries, so the size of that list is 20 * 2 + 2 = 42 bytes.

Offset Size Contents
0x00 1 Count
0x01 2 * Capacity Entries
... +0x00 1 Terminator

Count

The number of item entries actually being represented in the list.

Entries

The exact data for each item entry in the list. For more information, see below.

Terminator

The byte following the last item entry, according to Count, must always be a terminator, which is byte value 0xFF.

This spare byte is present at the end of the list data for the event when the list is filled to capacity.

Entry format

The Entry record has the following format:

Offset Size Contents
0x00 1 Count
0x01 1 Index

Count

The number of that particular item. Must be 1 to 99, inclusive.

Index

The item's index.

Pokémon lists

Lists of Pokémon in the save data follow a particular format.

Lists have entries of varying sizes, and a capacity. The total size of the list data, in bytes, is:

Capacity * (Size + 23) + 2

For example, your Pokémon team contains 6 entries and each entry is 48 bytes in size, so the size of that list is 6 * (48 + 23) + 2 = 428 bytes.

Offset Size Contents
0x0000 1 Count
0x0001 Capacity + 1 Species
... + 0x0000 Capacity * Size Pokémon
... + 0x0000 Capacity * 11 OT Names
... + 0x0000 Capacity * 11 Names

Count

The number of Pokémon entries actually being represented in the list.

Species

A list of species indexes, one for each Pokémon in the list. This is used by the team menu as well as the PC management interface.

The byte following the last species entry, according to Count, must always be a terminator, which is byte value 0xFF.

If an entry in this field is set to 0xFD, then the corresponding Pokémon is still in its egg.

Pokémon

The exact data for each Pokémon entry in the list. For the format, please refer to: Pokémon data structure in Generation II

  • For team Pokémon, the entry size is the full 48 bytes as documented in that article.
  • For PC Pokémon, only the first 32 bytes are used, meaning everything after Level is not included. Instead, those values are regenerated upon withdrawing a Pokémon from the PC. This is the basis of the Box trick.

OT names

Text strings representing the names of the original Trainers for each Pokémon entry. Each name can contain from 1 to 10 characters.

Names

Text strings representing the names for each Pokémon entry. Each name can contain from 1 to 10 characters.

A name is considered a "nickname" if it does not perfectly match the default name for a Pokémon. The default name follows these rules:

  • The first however many characters must match the species name exactly. This is typically all-uppercase.
  • The remainder of the string must be all terminator characters, aka 0x50.

Therefore, if a Pokémon with a 9- or 10-letter species name, such as Charmander, is given a nickname that matches the species name, the nickname will not be retained should that Pokémon evolve.

File structure

Known data within the save file can be found at the following offsets within the data, such that offset 0 is the first byte of the emulator ".sav" file.

Although all data appears twice in the save file, only the primary copy is documented below. For more information, see the Checksums section.

Editor's Note: This applies to the English Gold, Silver and Crystal for sure, but whether any of it is different in Japanese and/or other languages is yet to be seen.

OffsetGS OffsetC Size Contents
0x2000 0x2000 8 Options
0x2009 0x2009 2 Player Trainer ID
0x200B 0x200B 11 Player name
0x2013 0x2013 11 Unused (Player's mom name)
0x2021 0x2021 11 Rival name
0x201C 0x201C 11 Unused (Red's name)
0x2013 0x2013 11 Unused (Blue's name)
0x2037 0x2037 1 Daylight savings
0x2053 0x2054 4 Time played
0x206B 0x206A 1 Player palette
0x23DB 0x23DC 3 Money
0xD57C 0x23E5 1 Johto Badges
0x23E6 0x23E7 57 TM pocket
0x241F 0x2420 42 Item pocket item list
0x2449 0x244A 54 Key item pocket item list
0x2464 0x2465 26 Ball pocket item list
0x247E 0x247F 102 PC item list
0x2724 0x2700 1 Current PC Box
0x2727 0x2703 126 PC Box names
0x288A 0x2865 428 Team Pokémon list
0x2A4C 0x2A27 32 Pokédex owned
0x2A6C 0x2A47 32 Pokédex seen
0x2D6C 0x2D10 1102 Current Box Pokémon list
N/A 0x3E3D 1 Player gender
0x4000 0x4000 1102 PC Box 1 Pokémon list
0x4450 0x4450 1102 PC Box 2 Pokémon list
0x48A0 0x48A0 1102 PC Box 3 Pokémon list
0x4CF0 0x4CF0 1102 PC Box 4 Pokémon list
0x5140 0x5140 1102 PC Box 5 Pokémon list
0x5590 0x5590 1102 PC Box 6 Pokémon list
0x59E0 0x59E0 1102 PC Box 7 Pokémon list
0x6000 0x6000 1102 PC Box 8 Pokémon list
0x6450 0x6450 1102 PC Box 9 Pokémon list
0x68A0 0x68A0 1102 PC Box 10 Pokémon list
0x6CF0 0x6CF0 1102 PC Box 11 Pokémon list
0x7140 0x7140 1102 PC Box 12 Pokémon list
0x7590 0x7590 1102 PC Box 13 Pokémon list
0x79E0 0x79E0 1102 PC Box 14 Pokémon list
0x2D69 0x2D0D 2 Checksum 1
0x7E6D 0x1F0D 2 Checksum 2

Player name

Represents text strings that can be from 1 to 7 characters in length, although the save structure allocates 11 bytes for the name.

The first 8 bytes contain the name with any leftover equal to 0x50.

Since the name can be 7 bytes at most, the eighth byte will always be 0x50.

The remaining 3 bytes are all 0x00.

Rival name

Represents text strings that can be from 1 to 7 characters in length, although the save structure allocates 11 bytes for the name.

The first 8 bytes contain the name with any leftover equal to 0x50.

Since the name can be 7 bytes at most, the eighth byte will always be 0x50.

The remaining 9th, 10th, and 11th bytes are equal to 0x86, 0x91, 0x84 respectively.

Daylight savings

Specifies whether daylight savings time (DST) is in effect.

The highest bit of this field is set to indicate DST is in effect.

The lower 7 bits of this field have unknown significance.

Time played

Specifies how much time has elapsed during gameplay.

This value is actually 4 1-byte values representing, in this order: the hours, minutes, seconds and "frames" that have elapsed. A frame is 1/60th of a second.

This timer is not halted when the game is paused, and also counts up on the main menu before selecting to continue a saved game.

Player palette

Specifies the colors of the player character.

From a technical standpoint, the lowest 3 bits of this field are transferred to OAM to select the colors when drawing the player character. This means that there are a total of 8 possible palettes:

  • Red, 0x00
  • Blue, 0x01
  • Green, 0x02
  • Brown, 0x03
  • Orange, 0x04
  • Gray, 0x05
  • Dark Green, 0x06
  • Dark Red, 0x07

From a practical standpoint, this value is set by the game depending on whether the player character is a boy or a girl:

  • For boy characters, this is set to 0x00 (red)
  • For girl characters, this is set to 0x01 (blue)

Despite only being able to make boy characters in Gold and Silver, this field is still present and functional.

Johto Badges

The eight badges are stored on eight bits, one bit for each badge; '1' means the badge is acquired, '0' otherwise.

From MSB to LSB, badges are in this order: Zephyr, Insect, Plain, Fog, Storm, Mineral, Galcier, Rising.

TM pocket

The items that the player has in his or her TM Pocket inventory.

Offset Size Contents
0x00 50 TMs list
0x32 7 HMs list

TMs list

Each byte specifies the quantity of the corresponding TM that the player is holding. Should be 0 to 99.

Indexes match item numbers, meaning 0 corresponds with TM01 and 49 corresponds with TM50.

HMs list

Each byte specifies the quantity of the corresponding HM that the player is holding. Should be 0 to 1.

Indexes match item numbers, meaning 0 corresponds with HM01 and 6 corresponds with HM07.

Item pocket item list

The items that the player has in his or her item pocket inventory.

Stored as an Item list with a capacity of 20.

Key item pocket item list

The items that the player has in his or her Key Item Pocket inventory.

Stored as an Item list with a capacity of 26.

Ball pocket item list

The items that the player has in his or her Ball Pocket inventory.

Stored as an Item list with a capacity of 12.

PC item list

The items that the player has stored in the PC.

Stored as an Item list with a capacity of 50.

Current PC Box

Indicates which PC box is currently selected, minus 1. That is to say, box 1 is represented as 0, and box 14 is represented as 13.

The lowest 4 bits of this value are the box index.

PC Box names

The 14 box names, 9 bytes apart. Represent strings that can be from 1 to 8 characters in length.

Team Pokémon list

The Pokémon that the player has in his or her team.

Stored as a Pokemon list with a capacity of 6 and an entry size of 48 bytes.

Pokédex owned, Pokédex seen

Represents the specific Pokédex entries that have been either seen or owned during gameplay.

Pokémon are indexed by their usual Pokédex order, meaning the order is the same as in the National Pokédex. However, indexes begin counting at 0, rather than 1.

1 bit is used to represent whether a given Pokémon has been seen/owned. Bits are ordered within bytes from lowest to highest, starting with the first byte. Therefore, the exact bit can be extracted from the list using the following formula:

Bit = ( Data[ RoundDown(PokeNum / 8) ] / 2 ^ (PokeNum Mod 8) ) AND 1

Or in C-style code (shift occurs before other bitwise operations):

Bit = Data[PokeNum >> 3] >> (PokeNum & 7) & 1;

Example

Let us say that we want to know whether #120 Staryu has been seen/owned:

  • PokeNum becomes 119, since it is 0-based.
  • The byte of the list in which bit 119 is located is = 119 / 8 = 14
  • The bit within that byte is = 119 Mod 8 = 7
  • Dividing the byte value by 2 ^ Bit, or shifting right by Bit, moves the bit to the least-significant position
  • Performing a bitwise AND with 1 will remove all but the least-significant bit

PC Box Pokémon lists

The Pokémon that the player has stored in PC boxes.

Stored as Pokemon lists with a capacity of 20 and an entry size of 32 bytes.

Normally, Pokémon are deposited and withdrawn from the Current Box list, which is within the checksum-validated region of the save data. When switching boxes, the data from the Current Box is copied to the corresponding PC Box data, then the data from the switched-to PC Box is transferred into the Current Box data.

Player gender

Specifies the gender of the player character:

  • For boy characters, this is set to 0x00
  • For girl characters, this is set to 0x01

This field is not within the checksum-validated region.

Checksums

Used to validate the integrity of saved data.

Player data in Generation II is stored in the save file twice. The primary copy is located at 0x2009, and a secondary copy is stored elsewhere in the file. Checksums are performed on both copies and stored in the data.

  • If only one checksum is correct, then the information from that copy of the data will be used.
  • If both values are incorrect, the player will be forced to start a new game.

The checksums are simply the 16-bit sum of all byte values of the corresponding byte regions. Checksums are stored as little-endian.

Gold and Silver

The secondary data copy in Gold and Silver is not contiguous like the primary copy is. Instead, it is split across 5 sections and stored at different locations in the save file. The following table shows which sections of the primary copy are relocated for the secondary copy:

Primary Secondary
0x2009 to 0x222E 0x15C7 to 0x17EC
0x222F to 0x23D8 0x3D96 to 0x3F3F
0x23D9 to 0x2855 0x0C6B to 0x10E7
0x2856 to 0x2889 0x7E39 to 0x7E6C
0x288A to 0x2D68 0x10E8 to 0x15C6

Calculating the checksums, therefore, can be done as follows:

  • Sum the bytes from 0x2009 to 0x2D68 and store the result at 0x2D69
  • Sum the bytes from 0x0C6B to 0x17EC, 0x3D96 to 0x3F3F and 0x7E39 to 7E6C, and store the result at 0x7E6D

Crystal

The secondary data copy in Crystal is a byte-for-byte match of the primary copy. The following table shows which regions of the save file are occupied by each copy:

Primary Secondary
0x2009 to 0x2B82 0x1209 to 0x1D82

Calculating the checksums, therefore, can be done as follows:

  • Sum the bytes from 0x2009 to 0x2B82 and store the result at 0x2D0D
  • Sum the bytes from 0x1209 to 0x1D82 and store the result at 0x1F0D


Data structure in the Pokémon games
Generation I Pokémon speciesPokémonPoké MartCharacter encodingSave
Generation II Pokémon speciesPokémonTrainerCharacter encoding (Korean) • Save
Generation III Pokémon species (Pokémon evolutionPokédexType chart)
Pokémon (substructures) • MoveContestContest moveItem
Trainer TowerBattle FrontierCharacter encodingSave
Generation IV Pokémon species (Pokémon evolutionLearnsets)
PokémonSaveCharacter encoding
Generation V-present Character encoding
TCG GB and GB2 Character encoding


Project Games logo.png This data structure article is part of Project Games, a Bulbapedia project that aims to write comprehensive articles on the Pokémon games.