Sly 1:Codes

Codes is the subsystem that handles watching for cheat code inputs and executing cheat callbacks. A nearly identical system is used in and.

Startup
During initialization, the game calls, which calls   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,  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 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.