An implemention of MemoryIO specifically for the PCSX2 emulator. Designed along-side MemoryIO to provide an easy-to-use, cross platform PCSX2 memory manipulation experience.
Pcsx2MemoryIO
automatically attempts to detect and attach to a PCSX2 process.
Because different PS2 games use different string encodings, it is recommended that you provide an Encoding for Pcsx2MemoryIO
to use, otherwise it will default to UTF8.
For example, .hack//Fragment uses "Shift-JIS" encoding.
Pcsx2MemoryIO
exposes two bool
properties to check the state of the process such, IsPcsx2Running
and IsAttached
.
Calling Update()
will attempt to find and attach to a PCSX2 process if not already attached.
Pcsx2MemoryIO
automatically finds the BaseAddress of EEmem based on whether the process is running in 64bit or 32bit mode. This allows users to simply use the address without worrying about where the EEmem was initialized.
If you have used Cheat Engine on PCSX2 1.6.0 you might have found a value at address 0x20C461DA
. With Pcsx2MemoryIO
, you would just ignore the first 2 and use 0x00C461DA
.
IMemoryIO methods are overloaded with methods that take an int
address for convenience as the PS2 architecture is 32bit.
Pcsx2MemoryIO
does expose the BaseAddress
of EEmem as an IntPtr
in case users want to access it.
internal struct PlayerStruct
{
public int NamePointer;
public short Level;
public short EXP;
public int GP;
}
const int playerAddress = 0xC461DA;
const int partyPointersAddress = 0x8B9390;
Pcsx2MemoryIO memoryIO = new(Encoding.GetEncoding("Shift-JIS"));
if (memoryIO.IsAttached)
{
PlayerStruct player = memoryIO.Read<PlayerStruct>(playerAddress);
player.GP = 999999;
player.Level = 99;
memoryIO.Write(playerAddress, player);
int[] partyPointers = memoryIO.ReadArray<int>(partyPointersAddress, 3);
PlayerStruct party3 = memoryIO.Read<PlayerStruct>(partyPointers[2]);
memoryIO.WriteString(party3.NamePointer, "Kite");
}