1
\$\begingroup\$

Game Genie was a tool for the NES that allowed users to input codes that were able to drastically able to change the mechanics of a game by getting CPU reads and replacing the game's response with its own response. I have made a game in JavaScript using the HTML5 canvas and I want to try and make something like the Game Genie for my game but I have no idea where to start or if it's even possible. Any help?

\$\endgroup\$
7
  • \$\begingroup\$ What's preventing you just writing the new values to memory, same as you do elsewhere? \$\endgroup\$
    – Basic
    Jul 31, 2023 at 22:42
  • \$\begingroup\$ I'm confused on how you would do this in JavaScript? Unless I am not understanding you correctly. \$\endgroup\$
    – Jake Miahn
    Jul 31, 2023 at 23:52
  • 3
    \$\begingroup\$ All the game genie code did was identify areas of memory (variables) and what to do with them (fix the value at x). You can either have your "genie" code include variable names (instead of memory addresses), or -if you really want a hex format- come up with some table mapping variables <-> hex numbers (or any other scheme you like.) You haven't specified what it is about game genie codes you want to replicate, so it's hard to be more specific. \$\endgroup\$
    – Basic
    Aug 1, 2023 at 2:02
  • 3
    \$\begingroup\$ Just to add... You can get all defined variables in javascript: stackoverflow.com/a/2762091/156755 . You could loop through that, hash every name and then use that as your mapping table. \$\endgroup\$
    – Basic
    Aug 1, 2023 at 2:09
  • 1
    \$\begingroup\$ @Basic that looks like the seed of an upvote-worthy answer, if you'd like to flesh it out below. \$\endgroup\$
    – DMGregory
    Aug 1, 2023 at 10:48

1 Answer 1

5
\$\begingroup\$

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 could also use hexadecimal (or any reversible operation) for the value itself, so it's not obviously 100.

It depends entirely on how you want the code to look and function.

So ... How do we get the keys for the variable names?

Same 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.

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).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .