Skip to main content

Overview

The PKM 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: ObjectPKM Implements: ISpeciesForm, ITrainerID32, IGeneration, IShiny, ILangNick, IGameValueLimit, INature, IFatefulEncounter, IStringConverter, ITrashIntrospection

Constructors

PKM(Memory<byte> data)
constructor
Creates a new PKM instance from existing byte data.Parameters:
  • data (Memory<byte>): Raw byte data containing the Pokémon’s information
PKM(int size)
constructor
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

Data
Span<byte>
Gets the raw byte data span for the Pokémon.
SIZE_PARTY
int
The size of the Pokémon data structure when stored in party format.
SIZE_STORED
int
The size of the Pokémon data structure when stored in PC box format.
Extension
string
Gets the file extension for this PKM type (e.g., “pk8”, “pk9”).
Context
EntityContext
Gets the entity context (generation/game) this Pokémon belongs to.
Format
byte
Gets the format generation of this Pokémon data structure.

Species and Form

Species
ushort
Gets or sets the species ID of the Pokémon.
Form
byte
Gets or sets the form index of the Pokémon.
PersonalInfo
PersonalInfo
Gets the personal info entry containing base stats and other species-specific data.

Identity

Nickname
string
Gets or sets the nickname of the Pokémon.
IsNicknamed
bool
Gets or sets whether the Pokémon has a custom nickname.
EncryptionConstant
uint
Gets or sets the encryption constant used for data encryption and shiny determination.
PID
uint
Gets or sets the Personality ID of the Pokémon.

Trainer Information

OriginalTrainerName
string
Gets or sets the Original Trainer’s name.
OriginalTrainerGender
byte
Gets or sets the Original Trainer’s gender (0 = Male, 1 = Female).
TID16
ushort
Gets or sets the 16-bit Trainer ID.
SID16
ushort
Gets or sets the 16-bit Secret ID.
ID32
uint
Gets or sets the combined 32-bit Trainer ID.
DisplayTID
uint
Gets or sets the Trainer ID as displayed in-game (format varies by generation).
DisplaySID
uint
Gets or sets the Secret ID as displayed in-game (format varies by generation).

Battle Properties

Nature
Nature
Gets or sets the nature of the Pokémon.
StatNature
Nature
Gets or sets the nature used for stat calculations (can differ from display nature in Gen 8+).
Ability
int
Gets or sets the ability index.
AbilityNumber
int
Gets or sets the ability number (1, 2, or 4 for hidden).
Gender
byte
Gets or sets the gender (0 = Male, 1 = Female, 2 = Genderless).
HeldItem
int
Gets or sets the held item index.

Stats and IVs/EVs

CurrentLevel
byte
Gets or sets the current level of the Pokémon.
EXP
uint
Gets or sets the experience points.
IV_HP
int
Gets or sets the HP Individual Value (0-31).
IV_ATK
int
Gets or sets the Attack Individual Value (0-31).
IV_DEF
int
Gets or sets the Defense Individual Value (0-31).
IV_SPA
int
Gets or sets the Special Attack Individual Value (0-31).
IV_SPD
int
Gets or sets the Special Defense Individual Value (0-31).
IV_SPE
int
Gets or sets the Speed Individual Value (0-31).
EV_HP
int
Gets or sets the HP Effort Value (0-252).
EV_ATK
int
Gets or sets the Attack Effort Value (0-252).
EV_DEF
int
Gets or sets the Defense Effort Value (0-252).
EV_SPA
int
Gets or sets the Special Attack Effort Value (0-252).
EV_SPD
int
Gets or sets the Special Defense Effort Value (0-252).
EV_SPE
int
Gets or sets the Speed Effort Value (0-252).
IVTotal
int
Gets the sum of all Individual Values.
EVTotal
int
Gets the sum of all Effort Values.
FlawlessIVCount
int
Gets the count of IVs that are at maximum value.

Battle Stats

Stat_HPMax
int
Gets or sets the maximum HP stat.
Stat_HPCurrent
int
Gets or sets the current HP stat.
Stat_ATK
int
Gets or sets the Attack stat.
Stat_DEF
int
Gets or sets the Defense stat.
Stat_SPA
int
Gets or sets the Special Attack stat.
Stat_SPD
int
Gets or sets the Special Defense stat.
Stat_SPE
int
Gets or sets the Speed stat.
Stat_Level
byte
Gets or sets the level stored with party stats.

Moves

Move1
ushort
Gets or sets the first move ID.
Move2
ushort
Gets or sets the second move ID.
Move3
ushort
Gets or sets the third move ID.
Move4
ushort
Gets or sets the fourth move ID.
Move1_PP
int
Gets or sets the PP for the first move.
Move2_PP
int
Gets or sets the PP for the second move.
Move3_PP
int
Gets or sets the PP for the third move.
Move4_PP
int
Gets or sets the PP for the fourth move.
Move1_PPUps
int
Gets or sets the PP Ups for the first move.
Move2_PPUps
int
Gets or sets the PP Ups for the second move.
Move3_PPUps
int
Gets or sets the PP Ups for the third move.
Move4_PPUps
int
Gets or sets the PP Ups for the fourth move.
Moves
ushort[]
Gets or sets all moves as an array.
MoveCount
int
Gets the count of non-zero moves.

Relearn Moves

RelearnMove1
ushort
Gets or sets the first relearn move ID.
RelearnMove2
ushort
Gets or sets the second relearn move ID.
RelearnMove3
ushort
Gets or sets the third relearn move ID.
RelearnMove4
ushort
Gets or sets the fourth relearn move ID.
RelearnMoves
ushort[]
Gets or sets all relearn moves as an array.

Location and Date

MetLocation
ushort
Gets or sets the location where the Pokémon was met.
EggLocation
ushort
Gets or sets the location where the Pokémon egg was received.
MetLevel
byte
Gets or sets the level at which the Pokémon was met.
MetDate
DateOnly?
Gets or sets the date the Pokémon was met. Returns null if date is invalid or not supported.
EggMetDate
DateOnly?
Gets or sets the date the Pokémon was received as an egg. Returns null if date is invalid or not supported.
Ball
byte
Gets or sets the Poké Ball the Pokémon was caught in.

Special Properties

IsEgg
bool
Gets or sets whether the Pokémon is an egg.
IsShiny
bool
Gets whether the Pokémon is shiny based on TSV/PSV comparison.
ShinyXor
ushort
Gets the XOR value used for shiny determination (0 = square shiny, 1-15 = star shiny, 16+ = not shiny).
TSV
uint
Gets the Trainer Shiny Value.
PSV
uint
Gets the Pokémon Shiny Value.
FatefulEncounter
bool
Gets or sets the fateful encounter flag.
Language
int
Gets or sets the language ID.
Version
GameVersion
Gets or sets the game version the Pokémon originated from.

Pokerus

PokerusStrain
int
Gets or sets the Pokérus strain value.
PokerusDays
int
Gets or sets the remaining days of Pokérus infection.
IsPokerusInfected
bool
Gets or sets whether the Pokémon is infected with Pokérus.
IsPokerusCured
bool
Gets or sets whether the Pokémon has been cured of Pokérus.

Friendship and Contest

CurrentFriendship
byte
Gets or sets the current friendship value.
OriginalTrainerFriendship
byte
Gets or sets the Original Trainer’s friendship value.
Characteristic
int
Gets the characteristic value based on IVs.

Methods

IV/EV Manipulation

GetIVs(Span<int> value)
method
Retrieves all IVs in the order: HP, ATK, DEF, SPE, SPA, SPD.Parameters:
  • value (Span<int>): Span of length 6 to write IVs to
SetIVs(ReadOnlySpan<int> value)
method
Sets all IVs in the order: HP, ATK, DEF, SPE, SPA, SPD.Parameters:
  • value (ReadOnlySpan<int>): Span of length 6 containing IV values
SetIVs(uint iv32)
method
Sets IVs from a 32-bit combined value.Parameters:
  • iv32 (uint): Combined IV value
GetIVs()
method
Gets the combined 30-bit IV representation (IV32).Returns: uint - Combined IV value
GetEVs(Span<int> value)
method
Retrieves all EVs in the order: HP, ATK, DEF, SPE, SPA, SPD.Parameters:
  • value (Span<int>): Span of length 6 to write EVs to
SetEVs(ReadOnlySpan<int> value)
method
Sets all EVs in the order: HP, ATK, DEF, SPE, SPA, SPD.Parameters:
  • value (ReadOnlySpan<int>): Span of length 6 containing EV values
SetRandomIVs(int minFlawless = 0)
method
Randomizes IVs with optional guaranteed perfect IVs.Parameters:
  • minFlawless (int): Number of IVs to set to maximum (default: 0)

Move Manipulation

GetMoves(Span<ushort> value)
method
Retrieves all move IDs.Parameters:
  • value (Span<ushort>): Span to write move IDs to
SetMoves(ReadOnlySpan<ushort> value)
method
Sets all move IDs and refreshes PP values.Parameters:
  • value (ReadOnlySpan<ushort>): Span containing move IDs
HasMove(ushort move)
method
Checks if the Pokémon has a specific move.Parameters:
  • move (ushort): Move ID to check
Returns: bool - True if the move is present
AddMove(ushort move, bool pushOut = true)
method
Attempts to add a move to the moveset.Parameters:
  • move (ushort): Move ID to add
  • pushOut (bool): Whether to push out the first move if moveset is full
Returns: bool - True if the move was added successfully
GetMove(int index)
method
Gets the move at the specified index (0-3).Parameters:
  • index (int): Move slot index
Returns: ushort - Move ID
SetMove(int index, ushort value)
method
Sets the move at the specified index (0-3).Parameters:
  • index (int): Move slot index
  • value (ushort): Move ID to set
Returns: ushort - The move ID that was set
FixMoves()
method
Reorders moves to put empty entries last and fixes PP values.
ClearInvalidMoves()
method
Clears moves that are invalid for the current format.

Relearn Move Manipulation

GetRelearnMoves(Span<ushort> value)
method
Retrieves all relearn move IDs.Parameters:
  • value (Span<ushort>): Span to write relearn move IDs to
SetRelearnMoves(ReadOnlySpan<ushort> value)
method
Sets all relearn move IDs.Parameters:
  • value (ReadOnlySpan<ushort>): Span containing relearn move IDs
HasRelearnMove(ushort move)
method
Checks if the Pokémon has a specific relearn move.Parameters:
  • move (ushort): Move ID to check
Returns: bool - True if the relearn move is present

Stats and HP

GetStats(IBaseStat p)
method
Calculates battle stats based on base stats, IVs, EVs, and level.Parameters:
  • p (IBaseStat): Base stat information
Returns: ushort[] - Array of stats (HP, ATK, DEF, SPE, SPA, SPD)
LoadStats(IBaseStat p, Span<ushort> stats)
method
Calculates and loads battle stats into the provided span.Parameters:
  • p (IBaseStat): Base stat information
  • stats (Span<ushort>): Span to write stats to
SetStats(ReadOnlySpan<ushort> stats)
method
Applies calculated stats to the Pokémon.Parameters:
  • stats (ReadOnlySpan<ushort>): Stats to apply
ResetPartyStats()
method
Recalculates and resets all party stats to their proper values.
Heal()
method
Fully heals the Pokémon by resetting HP and PP.
HealPP()
method
Restores all PP to maximum based on current PP Ups.

PP Management

GetMovePP(ushort move, int ppUpCount)
method
Calculates the maximum PP for a move considering PP Ups.Parameters:
  • move (ushort): Move ID
  • ppUpCount (int): Number of PP Ups applied
Returns: int - Maximum PP
GetBasePP(ushort move)
method
Gets the base PP of a move (without PP Ups).Parameters:
  • move (ushort): Move ID
Returns: int - Base PP

Shiny and PID Manipulation

SetShiny()
method
Makes the Pokémon shiny by modifying its PID.
SetShinySID(Shiny shiny = Shiny.Random)
method
Makes the Pokémon shiny by modifying its SID16.Parameters:
  • shiny (Shiny): Type of shiny (Square, Star, or Random)
SetPIDGender(byte gender)
method
Sets a valid PID for the specified gender.Parameters:
  • gender (byte): Target gender
SetPIDNature(Nature nature)
method
Sets a valid PID for the specified nature.Parameters:
  • nature (Nature): Target nature
SetPIDUnown3(byte form)
method
Sets a valid PID for Unown form (Generation 3).Parameters:
  • form (byte): Target Unown form

Ability

RefreshAbility(int n)
method
Applies the specified ability slot.Parameters:
  • n (int): Ability slot (0 = ability 1, 1 = ability 2, 2 = hidden ability)

Validation

IsGenderValid()
method
Checks if the current gender is valid for the species.Returns: bool - True if gender is valid
CanHoldItem(ReadOnlySpan<ushort> valid)
method
Checks if the Pokémon can hold its current item.Parameters:
  • valid (ReadOnlySpan<ushort>): List of valid item IDs
Returns: bool - True if item can be held

Data Export

Clone()
method
Creates a deep clone of the Pokémon.Returns: PKM - Cloned Pokémon object
RefreshChecksum()
method
Updates the data checksum.
EncryptedPartyData
property
Gets the encrypted party data as a byte array.Returns: byte[] - Encrypted party data
EncryptedBoxData
property
Gets the encrypted box storage data as a byte array.Returns: byte[] - Encrypted box data
DecryptedPartyData
property
Gets the decrypted party data as a byte array.Returns: byte[] - Decrypted party data
DecryptedBoxData
property
Gets the decrypted box storage data as a byte array.Returns: byte[] - Decrypted box data

Usage Examples

Creating and Modifying a Pokémon

using PKHeX.Core;

// Assuming you have a PK9 instance (Generation 9 Pokémon)
var pk = new PK9();

// Set basic properties
pk.Species = 25; // Pikachu
pk.Form = 0;
pk.Nickname = "Sparky";
pk.CurrentLevel = 50;
pk.Nature = Nature.Jolly;
pk.Ability = 9; // Lightning Rod
pk.Gender = 0; // Male

// Set IVs
Span<int> ivs = stackalloc int[6] { 31, 31, 31, 31, 31, 31 };
pk.SetIVs(ivs);

// Set EVs
Span<int> evs = stackalloc int[6] { 0, 252, 0, 252, 0, 4 };
pk.SetEVs(evs);

// Set moves
Span<ushort> moves = stackalloc ushort[4] { 85, 98, 97, 129 };
pk.SetMoves(moves);

// Make it shiny
pk.SetShiny();

// Recalculate stats
pk.ResetPartyStats();

Console.WriteLine($"Created {pk.Nickname} at level {pk.CurrentLevel}");
Console.WriteLine($"Shiny: {pk.IsShiny}");

Reading Pokémon Data

// Read IV values
Span<int> ivs = stackalloc int[6];
pk.GetIVs(ivs);
Console.WriteLine($"HP IV: {ivs[0]}");
Console.WriteLine($"Attack IV: {ivs[1]}");
Console.WriteLine($"Total IVs: {pk.IVTotal}");

// Check moves
if (pk.HasMove(85)) // Thunderbolt
{
    Console.WriteLine("Pokémon knows Thunderbolt");
}

// Get move at specific index
ushort firstMove = pk.GetMove(0);
Console.WriteLine($"First move ID: {firstMove}");

Cloning and Data Export

// Clone the Pokémon
var clonedPk = pk.Clone();

// Export as encrypted data
byte[] partyData = pk.EncryptedPartyData;
byte[] boxData = pk.EncryptedBoxData;

// Save to file
string fileName = pk.FileName; // e.g., "025 - Sparky - 0123456789AB.pk9"
File.WriteAllBytes(fileName, pk.DecryptedBoxData);

Validating Pokémon Data

// Check if gender is valid
if (!pk.IsGenderValid())
{
    Console.WriteLine("Invalid gender for this species!");
}

// Check shiny value
if (pk.IsShiny)
{
    ushort shinyXor = pk.ShinyXor;
    if (shinyXor == 0)
        Console.WriteLine("Square Shiny!");
    else
        Console.WriteLine("Star Shiny!");
}

// Validate checksum
if (pk.ChecksumValid)
{
    Console.WriteLine("Data integrity verified");
}

Working with Stats

// Calculate stats based on personal info
var stats = pk.GetStats(pk.PersonalInfo);
Console.WriteLine($"HP: {stats[0]}");
Console.WriteLine($"Attack: {stats[1]}");
Console.WriteLine($"Defense: {stats[2]}");

// Heal the Pokémon
pk.Heal(); // Restores HP and PP

// Check if party stats are present
if (!pk.PartyStatsPresent)
{
    pk.ResetPartyStats();
}

See Also

Build docs developers (and LLMs) love