Guide:Finding pointers and offsets: Difference between revisions

Minor text fixes
(Fixed typo, minor tweak)
(Minor text fixes)
Line 1:
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, butthough keep in mind that [[Sly 1]] structs are organized slightly differently than [[Sly 2]] and [[Sly 3]] structs.
 
{{Needs images|Need to transfer the images over from theThe original [https://docs.google.com/document/d/12XPT3YeYfiwtyEcJOJfOAMNKklIuc4MyXkLM6YAUXU0 google doc] has lots of screenshots to copy over.}}
 
==How to find the pointer/offset to a value stored in any struct==
#'''Find the address of the value within the struct you want to find the pointer for.'''
#*In this tutorial we will use [[Sly 2:Jt|Sly]]'s]] X -position while in the [[Sly 2:F nightclub exterior|Paris map]] in [[Sly 2:Overview|Sly 2]]. By doing changed value scans in Cheat Engine, we know the address of Sly's X position is is <tt>0xFB3710</tt>.
#*We don't need to the 0x20 at the front of the address because the <tt>0x20000000</tt> is the emulator base address, and pointers are automatically read relative to the base address.
#'''Set a read breakpoint on that address in the PCSX2 debugger.'''
Line 11:
#*Once it opens, click '''Set Breakpoint'''.
#*In the '''Address''' box, enter 0xFB3710,
#*Check the box for "'''Read'''", but not "Write" or "Execute".
#*Click '''OK'''.
#:{{No image}}
#'''Do something to make the game read the value.'''
#*In ourthis case, all you have to do is play as Sly, since the game constantly reads Sly's position while he's active.
#*When your breakpoint hits, the game will freeze and the debugger will show you which instruction it broke on.
#'''In the Debugger, look at the assembly code instruction that reads the value, and see what address is in the register it used.'''
Line 37:
 
====Option B====
Use the tutorial below to find the base address of the Sly entity struct using the [[Sly 2:FK$x|FK$xX]] 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.