Sly 1:Codes

From SlyMods
Revision as of 02:40, 9 August 2022 by TheOnlyZac (talk | contribs) (Added infobox image)
Jump to navigation Jump to search
Codes
Subsystem
GameSly Cooper and the Thievius Raccoonus
Startup Function0x16f588

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.

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

The main game loop calls UpdateCodes every frame to check if a cheat code has been entered. It keeps track of how many consecutive button presses you have entered without pausing.

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 it checks your input against a particular cheat code sequence and finds an incorrect input, it resets that CHEAT counter to 0.

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 it plays the click sound effect you hear when a cheat code is entered.

Notes

  • It should be possible to add custom cheat codes by injecting them into memory, and hooking StartupCodes to insert more AddCode calls to initialize them.