Overview
TheSaveFile class is the abstract base class for all Pokémon save file formats in PKHeX. It provides a unified interface for reading, writing, and manipulating save data across all generations of Pokémon games.
Key Concepts
Memory Buffer Architecture
SaveFile uses a memory-based architecture for efficient data manipulation:Core Properties
Every SaveFile implementation must provide:- Version: The game version (see GameVersion enum)
- Generation: The generation number (1-9)
- Context: The entity context for this save file
- PKMType: The type of PKM entities this save uses
- BoxCount: Number of storage boxes
- BoxSlotCount: Slots per box (typically 30)
Working with Save Files
Loading a Save File
Accessing Trainer Information
SaveFile implementsITrainerInfo and provides trainer properties:
Box Data Management
Reading Box Data
Writing Box Data
Party Management
Pokédex Operations
Storage Operations
Sorting Boxes
Clearing Boxes
Modifying Pokémon in Bulk
Flags and Event Data
Saving Changes
Writing Save File
Checksums
SaveFile automatically manages checksums:Game-Specific Implementations
Generation 8 Example (Sword/Shield)
Advanced Topics
Entity Import Settings
Slot Protection
Box Management
Best Practices
Related Resources
- Pokémon Entities - Working with PKM objects
- Legality Analysis - Validating Pokémon legality
- Game Versions - Understanding version handling