libSPEC
Pokemon Save Editing Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Pages
Data Structures | Enumerations | Functions
game_gba.h File Reference

Contains the structures and functions for editing GBA pokemon save games. More...

#include <stdlib.h>
#include <stdint.h>

Data Structures

struct  gba_save_t
 A structure used for handling gba save types. More...
 
struct  pk3_marking_t
 The pokemon's markings that you see in the party or box. Used for searching. More...
 
struct  pk3_effort_t
 The pokemon's effort values. More...
 
struct  pk3_contest_t
 The pokemon's contest stats. More...
 
struct  pk3_pokerus_t
 The pokemon's pokerus infection/strain. More...
 
struct  pk3_pp_up_t
 The ppup of each move of the pokemon. More...
 
struct  pk3_genes_t
 The pokemon's individual values. It's unchangable genes. More...
 
struct  pk3_ribbon_t
 The pokemon's ribbon data. More...
 
struct  pk3_box_t
 A GBA pokemon's box data. 80 bytes in size. More...
 
struct  pk3_stats_t
 
struct  pk3_status_t
 
struct  pk3_party_t
 
struct  pk3_t
 A GBA pokemon's box and party data. 100 bytes in size. More...
 
struct  gba_party_t
 GBA Party Structure. More...
 
struct  gba_pc_box_t
 GBA PC Box Structure. More...
 
struct  gba_pc_t
 GBA PC Pokemon Storage Structure. More...
 
struct  gba_item_slot_t
 GBA Item Slot Structure. More...
 
struct  gba_rs_storage_t
 Ruby/Sapphire Item Storage. More...
 
union  gba_e_storage_t
 Emerald Item Storage. More...
 
union  gba_frlg_storage_t
 Fire Red/Leaf Green Item Storage. More...
 
struct  gba_storage_t
 
struct  gba_time_t
 GBA Time Played Structure. More...
 
struct  gba_trainer_t
 GBA Trainer Data Structure. More...
 

Enumerations

enum  gba_savetype_t {
  GBA_TYPE_UNKNOWN,
  GBA_TYPE_RS,
  GBA_TYPE_E,
  GBA_TYPE_FRLG
}
 Enum containing the different gba game types. More...
 
enum  {
  GBA_SAVE_SIZE = 0x20000,
  GBA_UNPACKED_SIZE = 0xD900
}
 
enum  {
  PK3_BLOCK_SIZE = 0xC,
  PK3_BOX_SIZE = 0x50,
  PK3_PARTY_SIZE = 0x64,
  PK3_NICKNAME_LENGTH = 10,
  PK3_OT_NAME_LENGTH = 7
}
 Defines constants related to the GBA pokemon structure. More...
 
enum  {
  GBA_BOX_COUNT = 14,
  GBA_POKEMON_IN_BOX = 30,
  GBA_BOX_NAME_LENGTH = 9
}
 Defines constants related to GBA pokemon storage. More...
 
enum  {
  GBA_RS_ITEM_COUNT = 216,
  GBA_E_ITEM_COUNT = 236,
  GBA_FRLG_ITEM_COUNT = 216
}
 

Functions

void gba_text_to_ucs2 (char16_t *dst, char8_t *src, size_t size)
 Converts GBA encoded text into UCS2 encoded text. More...
 
void ucs2_to_gba_text (char8_t *dst, char16_t *src, size_t size)
 Converts UCS2 encoded text into GBA encoded text. More...
 
gba_save_tgba_read_main_save (const uint8_t *)
 Reads the main save from the given save pointer. More...
 
gba_save_tgba_read_backup_save (const uint8_t *)
 Reads the backup save from the given save pointer. More...
 
void gba_write_main_save (uint8_t *, const gba_save_t *)
 Writes the save to the main slot of the given dst file. More...
 
void gba_write_backup_save (uint8_t *, const gba_save_t *)
 Writes the save to the backup slot of the given dst file. More...
 
void gba_save_game (uint8_t *, gba_save_t *)
 Writes the save to the dst similar to how the game would do it. More...
 
void gba_free_save (gba_save_t *)
 Frees the gba save made for the user. More...
 
uint8_t * gba_create_data ()
 Creates a data block of exactly GBA_SAVE_SIZE bytes in size, for loading save data into. You should free this data with free(). More...
 
void pk3_decrypt (pk3_box_t *)
 Decrypts the given PK3 structure. More...
 
void pk3_encrypt (pk3_box_t *)
 Encrypts the given PK3 structure. More...
 
gba_storage_tgba_get_storage (gba_save_t *)
 
gba_trainer_tgba_get_trainer (gba_save_t *)
 Calculates the pointer to the saves trainer data. More...
 
gba_party_tgba_get_party (gba_save_t *)
 Calculates the pointer to the saves party data. More...
 
gba_pc_tgba_get_pc (gba_save_t *)
 Calculates the pointer to the saves pc data. More...
 
bool gba_pokedex_get_national (gba_save_t *)
 Determines the national pokedex is owned. More...
 
void gba_pokedex_set_national (gba_save_t *, bool)
 Sets if the national pokedex is owned. More...
 
bool gba_pokedex_get_owned (gba_save_t *, size_t)
 Determines if the given pokemon is owned. More...
 
void gba_pokedex_set_owned (gba_save_t *, size_t, bool)
 
bool gba_pokedex_get_seen (gba_save_t *, size_t)
 Determines if the given pokemon has been seen. More...
 
void gba_pokedex_set_seen (gba_save_t *, size_t, bool)
 Sets if the given pokemon is seen. More...
 

Detailed Description

Contains the structures and functions for editing GBA pokemon save games.

The GBA games, Generation 3 games. These games include Ruby, Sapphire, Emerald, Fire Red and Leaf Green.

Enumeration Type Documentation

Enum containing the different gba game types.

Enumerator
GBA_TYPE_UNKNOWN 

An unknown GBA game, no functions will work on this save type.

GBA_TYPE_RS 

Pokemon Ruby and Pokemon Sapphire

GBA_TYPE_E 

Pokemon Emerald

GBA_TYPE_FRLG 

Pokemon Fire Red and Pokemon Leaf Green

anonymous enum
Enumerator
GBA_SAVE_SIZE 

The size in bytes of the GBA save we expect.

GBA_UNPACKED_SIZE 

The unpacked size of a GBA save slot.

anonymous enum

Defines constants related to the GBA pokemon structure.

Enumerator
PK3_BLOCK_SIZE 

The size of an individual block in the pokemon structure.

PK3_BOX_SIZE 

The size of the pk3_box_t structure, the box storage structure.

PK3_PARTY_SIZE 

The size of the pk3_t structure, the party storage structure.

PK3_NICKNAME_LENGTH 

The length of a pokemons nickname.

PK3_OT_NAME_LENGTH 

The length of a pokemon's original trainers name.

anonymous enum

Defines constants related to GBA pokemon storage.

Enumerator
GBA_BOX_COUNT 

The number of boxes in the PC.

GBA_POKEMON_IN_BOX 

The number of pokemon in a box.

GBA_BOX_NAME_LENGTH 

The length of a pc box's name.

Function Documentation

void gba_text_to_ucs2 ( char16_t dst,
char8_t src,
size_t  size 
)

Converts GBA encoded text into UCS2 encoded text.

Parameters
dstPointer to destination.
srcPointer to source.
sizeNumber of bytes to convert.
void ucs2_to_gba_text ( char8_t dst,
char16_t src,
size_t  size 
)

Converts UCS2 encoded text into GBA encoded text.

Parameters
dstPointer to destination.
srcPointer to source.
sizeNumber of bytes to convert.
gba_save_t* gba_read_main_save ( const uint8_t *  ptr)

Reads the main save from the given save pointer.

Parameters
ptrThe pointer to read from.
Returns
The main save for this GBA game.
gba_save_t* gba_read_backup_save ( const uint8_t *  ptr)

Reads the backup save from the given save pointer.

Parameters
ptrThe pointer to read from.
Returns
The backup save for this GBA game.
void gba_write_main_save ( uint8_t *  dst,
const gba_save_t save 
)

Writes the save to the main slot of the given dst file.

Parameters
dstThe pointer to the destination data block. Which should be at least GBA_SAVE_SIZE bytes long.
saveThe save to write to the main save area.
void gba_write_backup_save ( uint8_t *  dst,
const gba_save_t save 
)

Writes the save to the backup slot of the given dst file.

Parameters
dstThe pointer to the destination data block. Which should be at least GBA_SAVE_SIZE bytes long.
saveThe save to write to the backup save area.
void gba_save_game ( uint8_t *  dst,
gba_save_t save 
)

Writes the save to the dst similar to how the game would do it.

Parameters
dstThe pointer to the destination data block. Which should be at least GBA_SAVE_SIZE bytes long.
savesave to save to data
void gba_free_save ( gba_save_t save)

Frees the gba save made for the user.

Parameters
saveThe pointer to the save to free.
uint8_t* gba_create_data ( )

Creates a data block of exactly GBA_SAVE_SIZE bytes in size, for loading save data into. You should free this data with free().

Returns
The pointer to the created data block.
void pk3_decrypt ( pk3_box_t pk3)

Decrypts the given PK3 structure.

Parameters
pkmThe PK3 to be decrypted.
void pk3_encrypt ( pk3_box_t pk3)

Encrypts the given PK3 structure.

Parameters
pk3The PK3 to be encrypted.
gba_trainer_t* gba_get_trainer ( gba_save_t save)

Calculates the pointer to the saves trainer data.

Parameters
saveThe save to get the trainer data of.
Returns
Pointer to the saves trainer data.
gba_party_t* gba_get_party ( gba_save_t save)

Calculates the pointer to the saves party data.

Parameters
saveThe save to get the party data of.
Returns
Pointer to the saves party data.
gba_pc_t* gba_get_pc ( gba_save_t save)

Calculates the pointer to the saves pc data.

Parameters
saveThe save to get the pc data of.
Returns
Pointer to the saves pc data.
bool gba_pokedex_get_national ( gba_save_t save)

Determines the national pokedex is owned.

Parameters
saveThe save to check.
Returns
true if national pokedex is owned, false otherwise.
void gba_pokedex_set_national ( gba_save_t save,
bool  has 
)

Sets if the national pokedex is owned.

Parameters
saveThe save to set.
hastrue to set it, false to remove it.
bool gba_pokedex_get_owned ( gba_save_t save,
size_t  index 
)

Determines if the given pokemon is owned.

Parameters
saveThe save to check.
indexThe pokemons national index number (starting from 0)
Returns
true if owned, false if not owned.
void gba_pokedex_set_owned ( gba_save_t save,
size_t  index,
bool  owned 
)

Sets if the given pokemon is owned.

Parameters
saveThe save to set.
indexThe pokemons national index number (starting from 0)
ownedtrue to set it, false to remove it.
bool gba_pokedex_get_seen ( gba_save_t save,
size_t  index 
)

Determines if the given pokemon has been seen.

Parameters
saveThe save to check.
indexThe pokemons national index number (starting from 0)
Returns
true if seen, false if not seen.
void gba_pokedex_set_seen ( gba_save_t save,
size_t  index,
bool  seen 
)

Sets if the given pokemon is seen.

Parameters
saveThe save to set.
indexThe pokemons national index number (starting from 0)
ownedtrue to set it, false to remove it.