What exactly do you want to replicate from a Game Genie code?
The format of the original can be found in the docs here, but fundamentally they identified a part of the memory to change and the type of change to make.
Most commonly, that was "Fix the value in memory to always be X", but other operations were supported (like XOR-ing the value found in memory).
Whilst that doesn't map 1:1 to javascript, the core concepts are still valid.
At its most primitive, your "JSGenie" code could be playerLives:fix:100
Then on every frame, run through all the codes in use, extract the variable names, operations and values, then set the variables as appropriate.
If you want something a bit more game-genie-feeling with letters/numbers that aren't so human-readable, you've got a few different ways you can implement that.
Fundamentally, you'll want some way of mapping from "short alphanumeric code" (let's call it a key) to variable name.
Then your genie code becomes something like a3c1:fix:100
. Of course, we can replace fix
with a value to indicate the operation (let's sat "fix" is 0
)... a3c1:0:100
(or even omit the operation entirely and only support fixing values ... a3c1:100
)
There's really no limit to how you can format/pack the data. If you don't want to use colons, make the fields fixed-width, or bit pack them, or ... (you
You could also use hexadecimal (or any subsititionreversible operation) for the value itself, so it's not obviously 100
).
It depends entirely on how you want the code to look/work and function.
So ... How do we get the keys for the variable names?
Again, itSame again... It depends on how you want it to work.
At its simplest, you could have a hand-curated list of variables and their associated keys.
This is easy to control, but somewhat limited and a bit error-prone. Codes
Genie codes can only modify variables manually added to the list, and any time a variable name changes, this list has to be updated.
At the other end of the spectrum, you can get Javascript to tell you all currently defined variables, then hash their names in some way to get a key.
The benefit of this approach is that it's self-maintaining and the codes can change literally any value in the runtime.
The downside is that they can change literally ANY value in the runtime.
(Much like the original Game Genie).