This had another unintended consequence. If the game hacks itself, then we need some low-level control over the game — and for that, we need a low-level language. C# and Unity were no longer an option, so we had to start looking at some C++ options. We eventually settled on Cocos2d-x for our engine due to its popularity for 2D games.
To emulate real hacking tools, there are only two things that we needed. First, a disassembler for converting the raw machine code into human-readable x86 assembly (or at least nerd-readable). The second thing we need is an assembler to do the opposite.
With these two tools, we effectively have a game that can read and write its own code. We just have to tell the game exactly where to look, which we will explore later.
Of course this means you can totally crash this game, but as any hacker knows, crashing things is just part of the job.
However, there are some cool ways to mitigate this. One option is to save the state of the program (registers/stack) before the hackable region of code, and restore it after it executes to prevent silly mistakes.
For those who like to live a bit more dangerously, there are libraries for ignoring segfaults and other errors, which is pretty frightening. This is no match for a simple
jmp 0x00000000 , but it’s a good start for easing some of the inevitable frustration of an aspiring assembly programmer.