Sly 1:Codes

From SlyMods
Jump to navigation Jump to search
Codes
Subsystem
DescriptionWatches for cheat code inputs and handles cheat callbacks
GameSly Cooper and the Thievius Raccoonus
Startup Function0x16f588
Update Function0x16f2e0

Codes is the subsystem that handles watching for cheat code inputs and executing cheat callbacks. A nearly identical system is used in Sly 2: Band of Thieves and Sly 3: Honor Among Thieves.

Lifecycle

Startup

During initialization, the game calls StartupCodes, which calls AddCode nine times. This function takes a pointer to a cheat code sequence (an array of shorts) and registers the cheat code so it can be triggered later.

Update

Each frame, via the main game loop, UpdateCodes is called to check if any cheat code has been entered. It keeps track of how many consecutive button presses you have entered without pausing and compares the last input against the nth input in each cheat code sequence.

For each input you make that is the correct input on a particular cheat code, it increments the counter on the CHEAT struct related to that code. If you stop pressing buttons or enter a wrong input, the counter will reset back to zero.

Once you've entered an entire code correctly (meaning amount of inputs you entered is the same as the length of the cheat code, and all the inputs were correct), it reads the callback function from the CHEAT struct and schedules it to be called on the current frame. This is when the click sound effect plays,

CHEAT struct

Each cheat code is has an associated global CHEAT[check] struct. This struct stores the code input sequence, a counter, a callback function to execute when the code is entered, and one parameter that is passed to the callback function.

The callback and callback parameter be modified to call to any function in the game, provided it has zero or one parameters. This useful for debugging, reverse-engineering functions, or creating a custom cheat code.

Notes

  • You can change the callback pointer on a cheat code to call any other function you want as long as it requires no more than one parameter.
  • It is theoretically possible to add new cheat codes by injecting them into memory and hooking StartupCodes to insert more AddCode calls.

See also