Saturday, July 8, 2017

The Finer Points of Cheating

I recently obtained about the worst device ever to let me use cheat codes on my SNES: a Super UFO Pro 8.  I bought it for other reasons, and there's a post incoming about the device itself.  This post is about some interesting logic I noticed with the combination of cheat device and Chrono Trigger, while cheating my ass off.  It's applicable to basically any game when using a cheat device, though.

You can follow along in an emulator if you have a ROM of Chrono Trigger.  The cheat codes used in this post are RAM codes (address and value, not encoded in any manner), which also happens to be the format used by emulators, as well as both the X-Terminator and Pro Action Replay cheat devices.  If you have the ability to follow along on console, give it a shot.  That's what this post is written for, anyway.  If all you have is a Game Genie or Goldfinger, you won't be able to use it to follow along.  The Game Genie and Goldfinger use ROM codes.  You could still find codes that would work for these devices, but they would be very different.

First, load up the game with the following cheats, start a new game, get to the world map, enable the codes, and save your game.  If you're doing this on console and your cheat device doesn't let you enter all six at once, you'll have to split them up and do multiple saves.  For best results, enter them in pairs, based on the last digit of the address.

AddressValueEffect
7E2401CDOne Power Tab in inventory slot 2
7E250101
7E2402CEOne Magic Tab in inventory slot 3
7E250201
7E2403CFOne Speed Tab in inventory slot 4
7E250301

Note that inventory slot 1 is left empty, this is because the next code uses that slot.  If you haven't done so already, save your game.  Reset the SNES (power-cycling if necessary to get back to the code entry).  If using an emulator, just remove or disable the previously-entered codes, no need to reset or reload your ROM.  Enter the following cheat, load your save, and enable cheats.

AddressValueEffect
7E250063Inventory slot 1's quantity is always 99

You may not notice this code's effect right away, since the first three codes purposefully didn't put anything into the first inventory slot.  When moving items around your inventory, this code will let you duplicate them.  Go ahead and try it with the Tabs you got from the previous codes.  This is why those codes only give you one of each Tab.

Now, these items are of course meant to be used to increase your stats, so let's do that.  If you just use them, though, the quantity will decrease according to the number of them you use.  To stop that from happening, move the one you're using into the first inventory slot, which has its quantity set to 99 by the cheat we currently have active.  Now, when you use whichever Tabs you moved to this slot, you won't run out of them.

While using the tabs, though, you may notice something interesting: the displayed quantity decreases to 98 and stays there while you use them, as opposed to staying at 99.  Why is this?  Well, that's the subject of this post.

The reason behind this is due to how these cheat devices work: given an address and a value, they detect that the game is reading that specific memory address, and respond with the specified value instead of whatever value is actually at that address.  However, if you think I'd be satisfied leaving you with that explanation, you obviously haven't read very much of this blog.  We gonna get detailed, yo.  Well, not too detailed.  Everything is abstracted away from the fiddly technical specifics, to make it easier to follow.

In this first example, the game is running without a cheat device.

Given the following:
  • We're using Power Tabs on Crono
  • stored_quantity is the number of Power Tabs in our inventory
  • displayed_quantity is the number of Power Tabs that gets shown on screen
  • crono_power is Crono's power stat
This (or something functionally identical) will happen every time we use a Power Tab on Crono:
  1. SET displayed_quantity TO stored_quantity
  2. DECREMENT displayed_quantity BY ONE
  3. SET stored_quantity TO displayed_quantity
  4. INCREMENT crono_power BY ONE
  5. UPDATE DISPLAY
Let's run through that, shall we?  Let's say we have 10 Power Tabs.  When we use one on Crono, stored_quantity is read into displayed_quantitydisplayed_quantity is then decremented by one.  The result, 9, is stored back to stored_quantitycrono_power goes up by one, and the display updates (using displayed_quantity to provide the quantity) to show that we now have 9 Power Tabs.  Using another Power Tab will start this over again and result in that 9 being decremented to 8, as you might expect.

When we're using a cheat device, though, something different happens.

Given the following:
  • We're using Power Tabs on Crono
  • stored_quantity is the number of Power Tabs in our inventory
  • displayed_quantity is the number of Power Tabs that gets shown on screen
  • crono_power is Crono's power stat
  • We have a cheat device that tells the game that stored_quantity is 99 whenever the game asks for its value
The same process as before will happen every time we use a Power Tab on Crono:
  1. SET displayed_quantity TO stored_quantity
  2. DECREMENT displayed_quantity BY ONE
  3. SET stored_quantity TO displayed_quantity
  4. INCREMENT crono_power BY ONE
  5. UPDATE DISPLAY
Let's run through it again.  When the process starts, it reads the number of Power Tabs, just like normal.  The cheat device, being configured to provide the value 99 when stored_quantity is read, does its thing, resulting in displayed_quantity becoming 99.  The game decrements displayed_quantity by one, resulting in displayed_quantity being 98.  It stores displayed_quantity back to stored_quantity and crono_power goes up by one.  Finally, the display is updated (using displayed_quantity to provide the quantity) to say there are 98 Power Tabs.

However, the displayed_quantity doesn't immediately go back up to 99, even though our cheat device will tell the game we have 99 of the item in this slot if it asks.  This is because the game believes it already knows the quantity of this item, and hasn't asked for it again.  This means that game doesn't continually re-read the necessary data to show you what you're currently looking at in the inventory.  You can observe this if you make a change in an emulator, scroll the inventory down far enough that the slot is offscreen, then scroll back up.  The game will then re-read the value, and by doing so, it will show the updated value.

Let's go through the process again, so that what's happening becomes apparent.  The game is currently showing us that there are 98 Power Tabs in our inventory.  However, it reads the value again, which means the cheat device once again provides it with the value 99.  This 99 is decremented to 98 and the display is updated.  As far as the displayed values are concerned, we still have 98 Power Tabs.

"Aha!" you say.  Yeah, you understand now.  It's no longer "for some reason it goes down to 98 and stays there", it's "the cheat device always provides it with a 99 that gets decremented and then displayed".

No comments:

Post a Comment

I moderate comments because when Blogger originally implemented a spam filter it wouldn't work without comment moderation enabled. So if your comment doesn't show up right away, that would be why.