Office Mayhem is a goofy and fun party game. On the start screen of the game, the letters of the logo can be picked up, copied, and thrown around, for goodness sake. And we want to embrace that.
Testing has shown that players very much enjoy these letters on the start screen, and attempt to spell words with only the letters in “Office Mayhem.” So we thought, “Wouldn’t it be fun if you could enter the Konami Code or something and get all the letters of the alphabet to spell with?” And then we did.
It fell onto me to create the system to detect the Konami Code. Now, why would I stop at just that? I interpreted this as “Create a system for detecting any arbitrary cheat code input.”
The exact logic of how I implemented this is tricky, but the basic overview of how it works is:
- The codes are defined with a name and an arbitrarily long list of commands.
- The detector looks through the list of codes and creates a buffer as long as the longest code for each controller.
- The last inputs from each controller are stored in these buffers and constantly updated.
- When the last X inputs match the list of inputs for one of the codes (where X is that code’s length), an event is fired with the name of the code that was detected and the player id who entered it.
It’s not perfect, but it works, and between finishing the system and writing this now, it is used for all kinds of dev cheats throughout the game. As the overview states, once the detector system detects a code, it fires an event. This is probably my favorite thing about the system, because the detection system is completely decoupled from anything that might want to use it.
If you want a cheat code to trigger some functionality in the game, you simply have the relevant class implement the
EventListener interface (which many may be doing already), and register it to listen for
CodeDetected events. Then if the code’s name matches the code you want to react to, you’ve got a hit.
I’m reasonably happy with this system, especially because it was created in such a short time for an inconsequential Easter egg. And I’m even more happy that it has come into use for developer cheats to speed up the development process!
I would definitely use this again… albeit with some optimization and convenience improvements.