Guide:Finding pointers and offsets

This tutorial will teach you how to find pointers to structs and use offsets to access values stored within those structs. Basically every value the game uses is stored in a struct somewhere in memory, so if you can find a global pointer to a struct, and then figure out the offset to access a value in that struct, you can access that value in any map without having to scan for it. The steps below should work for all three games, but Sly 1 structs are organized slightly differently than Sly 2 and 3 structs.

How to find the pointer/offset to a value stored in any struct

 * 1) Find the address of the value within the struct you want to find the pointer for.
 * 2) *In this tutorial we will use Sly's X position while in the Paris map in Sly 2. By doing changed value scans in Cheat Engine, we know the address of Sly's X position is is 0xFB3710.
 * 3) *We don't need to the 0x20 at the front of the address because the 0x20000000 is the emulator base address, and pointers are automatically read relative to the base address.
 * 4) Set a read breakpoint on that address in the PCSX2 debugger.
 * 5) *In PCSX2, click Debug > Open Debug Window.
 * 6) *Once it opens, click Set Breakpoint.
 * 7) *In the Address box, enter 0xFB3710,
 * 8) *Check the box for "Read", but not "Write" or "Execute".
 * 9) *Click OK.
 * 10) Do something to make the game read the value.
 * 11) *In our case, all you have to do is play as Sly, since the game constantly reads Sly's position while he's active.
 * 12) *When your breakpoint hits, the game will freeze and the debugger will show you which instruction it broke on.
 * 13) In the Debugger, look at the assembly code instruction that reads the value, and see what address is in the register it used.
 * 14) *For example, the instruction will probably be something like . The register in parenthesis (in this case, s1) will contain the base address of the struct, and the number before the parenthesis is the offset (in this case, 0x30).
 * So, if the s0 register contains the value FB36E0, then the base address of the struct is 0xFB36E0, and Sly's X Position is at offset 0x30 from that address.
 * 1) Do a 4-byte scan in Cheat Engine to find an address which stores a pointer to that base address.
 * 2) *Take the value from the register in Step 4, and do a 4-byte / Exact Value scan in Cheat Engine for that value (remember to check the box that says Hex).
 * 3) *All the resulting addresses are pointers to that struct
 * 4) *If you have too many results, load another map, and repeat the process until you narrow it down (however, this will only work if one of the pointers you found is a global value).
 * 1) *All the resulting addresses are pointers to that struct
 * 2) *If you have too many results, load another map, and repeat the process until you narrow it down (however, this will only work if one of the pointers you found is a global value).
 * 1) *If you have too many results, load another map, and repeat the process until you narrow it down (however, this will only work if one of the pointers you found is a global value).

A struct can store pointers to other structs
If you followed the above steps to find the struct that stores Sly's X position, you might think you've found the pointer to the Sly Entity struct. However, what you have actually found is the pointer to Sly's Transform Component struct.

Each entity in the game has a Transform Component, which is referenced by a pointer inside it's Entity struct. This means the pointer you found will not work to find Sly's X position on every map. But, if you find the global pointer to the Sly Entity struct that works on every map, you can always find the Transform Component by using its offset from that pointer, then offset 0x30 from that pointer to find the X position.

Option A
Repeat steps 2-5, but in Step 2, use the address of one of the pointers you got in Step 5. You should probably use the address that is closest to the base address of the Transform Component. That way, you will find the base address of the Sly Entity, and the offset of the pointer Transform struct inside the Sly Entity struct.

Option B
Use the tutorial below to find the base address of the Sly entity struct using the FK$x string. Then use Cheat Engine's memory viewer to find the pointer to the Transform Component in memory nearby. Now use a calculator to subtract the address of the Transform Component pointer from the Sly Entity base address, and that will be the offset of the Transform Component for every entity in the game.

Once you know the offset of the Transform Component from the entity struct, and the offset of the X coordinate from the transform component, you can find the coordinates for every entity in the game without having to repeat the steps above every single time.

How to find the struct base address for a specific entity
This will work for entities like Sly, Bentley, Neyla, guards, antennas, cars, trees, bombs, bullets, music box, etc.


 * 1) Find the FK$X struct for the entity you want
 * 2) *In CE, do a String Search for FK$Xentity_name</tt>, where entity_name is the name of the entity. In this case we will do FK$Xz_antenna</tt> in Sly 2 Ep 1, Paris.
 * 3) *If you do not know the entity name, you can guess, try to search for just part of it (eg. just antenna</tt>), or search for just FK$X</tt> and look through all of them until you find it.
 * 4) Once you found the FK$X string, open that in the Memory Viewer, and scroll up to see the entire FK$X struct.
 * 5) *Right click in the memory viewer, and change the display mode to 4-byte Hex.
 * 6) *It should look like this:
 * 7) Use the entity list pointer to find the array of pointers to each instance of that entity in the world
 * 8) *Ignoring the zeroes at the start of the line, the second value in the FK$X struct is a pointer to the entity pool for that entity
 * 9) *The third value value in the FK$X struct is how many of that entity the game instantiated when the level was loaded
 * 10) *Copy the value of the pool pointer, press Ctrl+G, paste it, and press OK to go to that address in the memory viewer.
 * 11) **I am using the emuprm script so these screenshots do not include the 0x20000000</tt> base address. If you don't have the script, you will have to add 0x20000000</tt>.
 * 12) You are now looking at the proxy pool for that entity, which is an array of pointers to instances of that entity in the current map.
 * 13) *These are pointers to Entity structs. Each 4-byte value is a pointer to an instance of that entity.
 * 14) *There will be a number of pointers equal to the pool size you saw in the FK$X struct. For the antennas, there are 4.
 * 15) *You can use the Dissect Data Structures tool to easily view/edit the data, or manually add the offsets yourself if you know what you're looking for.
 * 1) *These are pointers to Entity structs. Each 4-byte value is a pointer to an instance of that entity.
 * 2) *There will be a number of pointers equal to the pool size you saw in the FK$X struct. For the antennas, there are 4.
 * 3) *You can use the Dissect Data Structures tool to easily view/edit the data, or manually add the offsets yourself if you know what you're looking for.
 * 1) *You can use the Dissect Data Structures tool to easily view/edit the data, or manually add the offsets yourself if you know what you're looking for.

Once you know the base address for an entity, you can add the offset for a known element to get that element for that entity. For example, if you followed the steps in the first tutorial to find the offset for the Transform Component for an entity, you can add that offset to the base address for any entity to get the pointer to its Transform Component. Then you can add the offsets 0x30, 0x34, and 0x38 to that pointer to get the entity's X, Y, and Z coordinates.