Overview
ThePKM class is the abstract base class for all Pokémon entity data structures in PKHeX. It provides a unified interface for accessing and manipulating Pokémon data across all generations.
Namespace: PKHeX.Core
Inheritance: Object → PKM
Implements: ISpeciesForm, ITrainerID32, IGeneration, IShiny, ILangNick, IGameValueLimit, INature, IFatefulEncounter, IStringConverter, ITrashIntrospection
Constructors
Creates a new PKM instance from existing byte data.Parameters:
data(Memory<byte>): Raw byte data containing the Pokémon’s information
Creates a new PKM instance with a new byte array of the specified size.Parameters:
size(int): Size of the byte array to allocate
Core Properties
Data Storage
Gets the raw byte data span for the Pokémon.
The size of the Pokémon data structure when stored in party format.
The size of the Pokémon data structure when stored in PC box format.
Gets the file extension for this PKM type (e.g., “pk8”, “pk9”).
Gets the entity context (generation/game) this Pokémon belongs to.
Gets the format generation of this Pokémon data structure.
Species and Form
Gets or sets the species ID of the Pokémon.
Gets or sets the form index of the Pokémon.
Gets the personal info entry containing base stats and other species-specific data.
Identity
Gets or sets the nickname of the Pokémon.
Gets or sets whether the Pokémon has a custom nickname.
Gets or sets the encryption constant used for data encryption and shiny determination.
Gets or sets the Personality ID of the Pokémon.
Trainer Information
Gets or sets the Original Trainer’s name.
Gets or sets the Original Trainer’s gender (0 = Male, 1 = Female).
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 (format varies by generation).
Gets or sets the Secret ID as displayed in-game (format varies by generation).
Battle Properties
Gets or sets the nature of the Pokémon.
Gets or sets the nature used for stat calculations (can differ from display nature in Gen 8+).
Gets or sets the ability index.
Gets or sets the ability number (1, 2, or 4 for hidden).
Gets or sets the gender (0 = Male, 1 = Female, 2 = Genderless).
Gets or sets the held item index.
Stats and IVs/EVs
Gets or sets the current level of the Pokémon.
Gets or sets the experience points.
Gets or sets the HP Individual Value (0-31).
Gets or sets the Attack Individual Value (0-31).
Gets or sets the Defense Individual Value (0-31).
Gets or sets the Special Attack Individual Value (0-31).
Gets or sets the Special Defense Individual Value (0-31).
Gets or sets the Speed Individual Value (0-31).
Gets or sets the HP Effort Value (0-252).
Gets or sets the Attack Effort Value (0-252).
Gets or sets the Defense Effort Value (0-252).
Gets or sets the Special Attack Effort Value (0-252).
Gets or sets the Special Defense Effort Value (0-252).
Gets or sets the Speed Effort Value (0-252).
Gets the sum of all Individual Values.
Gets the sum of all Effort Values.
Gets the count of IVs that are at maximum value.
Battle Stats
Gets or sets the maximum HP stat.
Gets or sets the current HP stat.
Gets or sets the Attack stat.
Gets or sets the Defense stat.
Gets or sets the Special Attack stat.
Gets or sets the Special Defense stat.
Gets or sets the Speed stat.
Gets or sets the level stored with party stats.
Moves
Gets or sets the first move ID.
Gets or sets the second move ID.
Gets or sets the third move ID.
Gets or sets the fourth move ID.
Gets or sets the PP for the first move.
Gets or sets the PP for the second move.
Gets or sets the PP for the third move.
Gets or sets the PP for the fourth move.
Gets or sets the PP Ups for the first move.
Gets or sets the PP Ups for the second move.
Gets or sets the PP Ups for the third move.
Gets or sets the PP Ups for the fourth move.
Gets or sets all moves as an array.
Gets the count of non-zero moves.
Relearn Moves
Gets or sets the first relearn move ID.
Gets or sets the second relearn move ID.
Gets or sets the third relearn move ID.
Gets or sets the fourth relearn move ID.
Gets or sets all relearn moves as an array.
Location and Date
Gets or sets the location where the Pokémon was met.
Gets or sets the location where the Pokémon egg was received.
Gets or sets the level at which the Pokémon was met.
Gets or sets the date the Pokémon was met. Returns null if date is invalid or not supported.
Gets or sets the date the Pokémon was received as an egg. Returns null if date is invalid or not supported.
Gets or sets the Poké Ball the Pokémon was caught in.
Special Properties
Gets or sets whether the Pokémon is an egg.
Gets whether the Pokémon is shiny based on TSV/PSV comparison.
Gets the XOR value used for shiny determination (0 = square shiny, 1-15 = star shiny, 16+ = not shiny).
Gets the Trainer Shiny Value.
Gets the Pokémon Shiny Value.
Gets or sets the fateful encounter flag.
Gets or sets the language ID.
Gets or sets the game version the Pokémon originated from.
Pokerus
Gets or sets the Pokérus strain value.
Gets or sets the remaining days of Pokérus infection.
Gets or sets whether the Pokémon is infected with Pokérus.
Gets or sets whether the Pokémon has been cured of Pokérus.
Friendship and Contest
Gets or sets the current friendship value.
Gets or sets the Original Trainer’s friendship value.
Gets the characteristic value based on IVs.
Methods
IV/EV Manipulation
Retrieves all IVs in the order: HP, ATK, DEF, SPE, SPA, SPD.Parameters:
value(Span<int>): Span of length 6 to write IVs to
Sets all IVs in the order: HP, ATK, DEF, SPE, SPA, SPD.Parameters:
value(ReadOnlySpan<int>): Span of length 6 containing IV values
Sets IVs from a 32-bit combined value.Parameters:
iv32(uint): Combined IV value
Gets the combined 30-bit IV representation (IV32).Returns: uint - Combined IV value
Retrieves all EVs in the order: HP, ATK, DEF, SPE, SPA, SPD.Parameters:
value(Span<int>): Span of length 6 to write EVs to
Sets all EVs in the order: HP, ATK, DEF, SPE, SPA, SPD.Parameters:
value(ReadOnlySpan<int>): Span of length 6 containing EV values
Randomizes IVs with optional guaranteed perfect IVs.Parameters:
minFlawless(int): Number of IVs to set to maximum (default: 0)
Move Manipulation
Retrieves all move IDs.Parameters:
value(Span<ushort>): Span to write move IDs to
Sets all move IDs and refreshes PP values.Parameters:
value(ReadOnlySpan<ushort>): Span containing move IDs
Checks if the Pokémon has a specific move.Parameters:
move(ushort): Move ID to check
Attempts to add a move to the moveset.Parameters:
move(ushort): Move ID to addpushOut(bool): Whether to push out the first move if moveset is full
Gets the move at the specified index (0-3).Parameters:
index(int): Move slot index
Sets the move at the specified index (0-3).Parameters:
index(int): Move slot indexvalue(ushort): Move ID to set
Reorders moves to put empty entries last and fixes PP values.
Clears moves that are invalid for the current format.
Relearn Move Manipulation
Retrieves all relearn move IDs.Parameters:
value(Span<ushort>): Span to write relearn move IDs to
Sets all relearn move IDs.Parameters:
value(ReadOnlySpan<ushort>): Span containing relearn move IDs
Checks if the Pokémon has a specific relearn move.Parameters:
move(ushort): Move ID to check
Stats and HP
Calculates battle stats based on base stats, IVs, EVs, and level.Parameters:
p(IBaseStat): Base stat information
Calculates and loads battle stats into the provided span.Parameters:
p(IBaseStat): Base stat informationstats(Span<ushort>): Span to write stats to
Applies calculated stats to the Pokémon.Parameters:
stats(ReadOnlySpan<ushort>): Stats to apply
Recalculates and resets all party stats to their proper values.
Fully heals the Pokémon by resetting HP and PP.
Restores all PP to maximum based on current PP Ups.
PP Management
Calculates the maximum PP for a move considering PP Ups.Parameters:
move(ushort): Move IDppUpCount(int): Number of PP Ups applied
Gets the base PP of a move (without PP Ups).Parameters:
move(ushort): Move ID
Shiny and PID Manipulation
Makes the Pokémon shiny by modifying its PID.
Makes the Pokémon shiny by modifying its SID16.Parameters:
shiny(Shiny): Type of shiny (Square, Star, or Random)
Sets a valid PID for the specified gender.Parameters:
gender(byte): Target gender
Sets a valid PID for the specified nature.Parameters:
nature(Nature): Target nature
Sets a valid PID for Unown form (Generation 3).Parameters:
form(byte): Target Unown form
Ability
Applies the specified ability slot.Parameters:
n(int): Ability slot (0 = ability 1, 1 = ability 2, 2 = hidden ability)
Validation
Checks if the current gender is valid for the species.Returns: bool - True if gender is valid
Checks if the Pokémon can hold its current item.Parameters:
valid(ReadOnlySpan<ushort>): List of valid item IDs
Data Export
Creates a deep clone of the Pokémon.Returns: PKM - Cloned Pokémon object
Updates the data checksum.
Gets the encrypted party data as a byte array.Returns: byte[] - Encrypted party data
Gets the encrypted box storage data as a byte array.Returns: byte[] - Encrypted box data
Gets the decrypted party data as a byte array.Returns: byte[] - Decrypted party data
Gets the decrypted box storage data as a byte array.Returns: byte[] - Decrypted box data
Usage Examples
Creating and Modifying a Pokémon
Reading Pokémon Data
Cloning and Data Export
Validating Pokémon Data
Working with Stats
See Also
- SaveFile Class - For working with save files
- LegalityAnalysis Class - For validating Pokémon legality
- ShowdownSet Class - For importing/exporting Showdown format