Overview
TheSaveFile class is the abstract base class for all Pokémon save file formats. It provides a unified interface for accessing and manipulating save data across all generations.
Namespace: PKHeX.Core
Inheritance: Object → SaveFile
Implements: ITrainerInfo, IGameValueLimit, IStringConverter, ITrainerID32
Constructors
Creates a SaveFile instance from existing byte data.Parameters:
data(Memory<byte>): Raw save file dataexportable(bool): Whether the save can be exported (default: true)
Creates a SaveFile instance with a new byte array.Parameters:
size(int): Size of the byte array (default: 0 for empty array)
Core Properties
Data Storage
The raw save file data buffer.
Gets the raw byte data span for the save file.
Gets the current state of the save file (edited status, exportable status).
Gets the metadata associated with this save file.
File Information
Gets the file extension for this save file format.
Gets the generation this save file belongs to.
Gets the entity context for this save file.
Gets or sets the game version.
Trainer Information
Gets or sets the Original Trainer name.
Gets or sets the trainer’s gender (0 = Male, 1 = Female).
Gets or sets the language ID of the save file.
Gets or sets the 16-bit Trainer ID.
Gets or sets the 16-bit Secret ID.
Gets or sets the combined 32-bit Trainer ID.
Gets or sets the Trainer ID as displayed in-game.
Gets or sets the Secret ID as displayed in-game.
Game Progress
Gets or sets the hours played.
Gets or sets the minutes played.
Gets or sets the seconds played.
Gets the formatted play time string (HH:MM:SS).
Gets or sets the seconds until start time.
Gets or sets the seconds to Hall of Fame entry.
Gets or sets the trainer’s money.
Gets the maximum money value (default: 9,999,999).
Gets the maximum coins value (default: 9,999).
Storage Properties
Gets the total number of boxes in the PC.
Gets the number of slots per box (typically 30).
Gets the total number of storage slots (BoxCount × BoxSlotCount).
Gets or sets the currently selected box.
Gets or sets the number of unlocked boxes.
Gets whether this save file has box storage.
Party Properties
Gets or sets the number of Pokémon in the party.
Gets whether this save file has a party.
Gets or sets the party Pokémon.
Format Limits
Gets the personal data table for this save file.
Gets the maximum trainer name length.
Gets the maximum nickname length.
Gets the maximum move ID.
Gets the maximum species ID.
Gets the maximum ability ID.
Gets the maximum item ID.
Gets the maximum ball ID.
Gets the maximum game version ID.
Gets the maximum EV value per stat.
Gets the maximum IV value per stat (typically 31).
Pokédex
Gets whether this save file has Pokédex data.
Gets the count of Pokémon species seen.
Gets the count of Pokémon species caught.
Gets the percentage of Pokédex completion (seen).
Gets the percentage of Pokédex completion (caught).
Validation
Gets whether all checksums in the save file are valid.
Gets checksum validation information.
Methods
Save File Operations
Writes the save file to a Memory buffer with optional export settings.Parameters:
setting(BinaryExportSetting): Export settings to apply
Creates a deep clone of the save file.Returns: SaveFile - Cloned save file
Updates all checksums in the save file.
Checks if the game version is valid for this save file.Returns: bool - True if version is valid
Data Manipulation
Writes data to the save file at the specified offset.Parameters:
input(ReadOnlySpan<byte>): Data to writeoffset(int): Offset in the save file
Copies input data to the destination span.Parameters:
dest(Span<byte>): Destination spaninput(ReadOnlySpan<byte>): Source data
Copies all changes from another save file.Parameters:
sav(SaveFile): Source save file
Box Operations
Gets or sets all Pokémon in all boxes.Type: IList<PKM>
Gets all Pokémon from a specific box.Parameters:
box(int): Box index
Gets the Pokémon at a specific box and slot.Parameters:
box(int): Box indexslot(int): Slot index within the box
Sets a Pokémon at a specific box and slot.Parameters:
pk(PKM): Pokémon to setbox(int): Box indexslot(int): Slot index within the boxsettings(EntityImportSettings): Import settings
Gets the byte offset for a specific box.Parameters:
box(int): Box index
Gets the byte offset for a specific box slot.Parameters:
box(int): Box indexslot(int): Slot index
Party Operations
Gets the Pokémon at the specified party index.Parameters:
index(int): Party slot (0-5)
Sets a Pokémon at the specified party index.Parameters:
pk(PKM): Pokémon to setindex(int): Party slot (0-5)settings(EntityImportSettings): Import settings
Deletes a party slot and shifts remaining Pokémon down.Parameters:
slot(int): Party slot to delete
Gets the byte offset for a party slot.Parameters:
slot(int): Party slot index
Checks if all party members are eggs (optionally excluding one slot).Parameters:
except(int): Slot to exclude from check (default: -1 for none)
Storage Management
SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>, int, IEnumerable<PKM>>? sortMethod = null, bool reverse = false)
method
Sorts Pokémon in the specified box range.Parameters:
BoxStart(int): Starting box indexBoxEnd(int): Ending box index (-1 for last box)sortMethod(Func): Custom sort methodreverse(bool): Reverse the sort order
Clears Pokémon from boxes.Parameters:
BoxStart(int): Starting box indexBoxEnd(int): Ending box index (-1 for last box)deleteCriteria(Func): Criteria for deletion
Modifies all Pokémon in the specified box range.Parameters:
action(Action<PKM>): Modification actionBoxStart(int): Starting box indexBoxEnd(int): Ending box index (-1 for last box)
Moves a box to a new position.Parameters:
box(int): Box to moveinsertBeforeBox(int): Position to insert before
Swaps two boxes.Parameters:
box1(int): First boxbox2(int): Second box
Compresses storage by moving all Pokémon to the front.Parameters:
storedCount(out int): Number of Pokémon storedslotPointers(Span<int>): Slot pointers to update
Slot Protection
Gets the protection flags for a box slot.Parameters:
box(int): Box indexslot(int): Slot index
Checks if a box slot is locked.Parameters:
box(int): Box indexslot(int): Slot index
Checks if a box slot is protected from overwriting.Parameters:
box(int): Box indexslot(int): Slot index
Finds the next open box slot.Parameters:
lastKnownOccupied(int): Last known occupied slot
Gets whether storage is completely full.Type: bool
Pokédex Operations
Checks if a species has been seen.Parameters:
species(ushort): Species ID
Sets whether a species has been seen.Parameters:
species(ushort): Species IDseen(bool): Seen status
Checks if a species has been caught.Parameters:
species(ushort): Species ID
Sets whether a species has been caught.Parameters:
species(ushort): Species IDcaught(bool): Caught status
Binary Export
Exports all PC box data as a binary array.Returns: byte[] - Binary data
Exports a single box as binary data.Parameters:
box(int): Box index
Imports PC box data from binary.Parameters:
data(ReadOnlySpan<byte>): Binary data to import
Imports a single box from binary data.Parameters:
data(ReadOnlySpan<byte>): Binary databox(int): Box index
Flag Operations
Gets the value of a flag bit.Parameters:
offset(int): Byte offsetbitIndex(int): Bit index within the byte
Sets the value of a flag bit.Parameters:
offset(int): Byte offsetbitIndex(int): Bit index within the bytevalue(bool): Value to set
Usage Examples
Loading and Saving
Working with Party
Box Management
Sorting and Filtering
Pokédex Operations
Binary Import/Export
Slot Protection
See Also
- PKM Class - For working with individual Pokémon
- LegalityAnalysis Class - For validating Pokémon legality
- ShowdownSet Class - For importing/exporting Showdown format