Sly 1:Codes: Difference between revisions
TheOnlyZac (talk | contribs) (Added about hatnote) |
TheOnlyZac (talk | contribs) (Expanded and restructured article) |
||
Line 1: | Line 1: | ||
{{About| |
{{About|the subsystem that handles code inputs|cheat codes|Sly 1:Cheat codes}} |
||
{{For|vault codes|Sly 1:VAULT}} |
|||
{{Infobox subsystem |
{{Infobox subsystem |
||
| image= File:Sly 1 chetkido.png |
| image= File:Sly 1 chetkido.png |
||
Line 6: | Line 7: | ||
'''Codes''' is the subsystem that handles watching for [[Sly 1:Cheat codes|cheat code]] inputs and executing cheat callbacks. A nearly identical system is used in {{Sly 2}} and {{Sly 3}}. |
'''Codes''' is the subsystem that handles watching for [[Sly 1:Cheat codes|cheat code]] inputs and executing cheat callbacks. A nearly identical system is used in {{Sly 2}} and {{Sly 3}}. |
||
== |
== Lifecycle == |
||
=== Startup === |
|||
During initialization, the game calls <code>StartupCodes</code>, which calls <code>AddCode</code> 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. |
During initialization, the game calls <code>StartupCodes</code>, which calls <code>AddCode</code> 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 == |
=== Update === |
||
Each frame, via the main game loop, <code>UpdateCodes</code> 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 n<sup>th</sup> 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 |
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 |
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 == |
|||
{{To do|Add struct member table}} |
|||
Each [[Sly 1:Cheat codes|cheat code]] is has an associated global <tt>CHEAT</tt>{{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 == |
== 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. |
|||
⚫ | |||
== See also == |
|||
{{Google docs|https://docs.google.com/document/d/1WMueShIbTVWnM86z6IrUR1xCSBIFaUjC__sPz7lNSs0/}} |
{{Google docs|https://docs.google.com/document/d/1WMueShIbTVWnM86z6IrUR1xCSBIFaUjC__sPz7lNSs0/}} |
||
* [[Guide:Custom cheat codes]] |
|||
⚫ | |||
{{Navbox Sly 1}} |
{{Navbox Sly 1}} |
Revision as of 04:22, 19 October 2022
Subsystem | |
---|---|
Game | Sly Cooper and the Thievius Raccoonus |
Startup Function | 0x16f588 |
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
To Do: Add struct member table |
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 moreAddCode
calls.