GameShark

Technical overview. A GameShark code encodes a memory write as a type, value, and address in an eight-digit hexadecimal string. Applying a code changes the emulated memory at the point where the cheat is processed, which allows game state such as scores or inventory values to be altered.

Using the API. The GameShark object is available from PyBoy and accepts codes through add. It reapplies active codes while emulation runs, and remove or clear_all can restore the values that were present before the cheats were added.

class pyboy.api.gameshark.GameShark(memory)[source]

Bases: object

__init__(memory)[source]
add(code)[source]

Add a GameShark cheat to the emulator.

Codes use the eight-hex-digit format ttvvaaaa: tt is the code type, vv the byte to write, and aaaa the address in low-byte-first order. Currently, only type 01 (write one byte) is supported.

Example:

>>> pyboy.gameshark.add("01FF16D0")
Parameters:

code (str) – GameShark code to add

Raises:
remove(code, restore_value=True)[source]

Remove a GameShark cheat from the emulator.

Example:

>>> pyboy.gameshark.add("01FF16D0")
>>> pyboy.gameshark.remove("01FF16D0")
Parameters:
  • code (str) – GameShark code to remove

  • restore_value (bool) – Restore the original byte at the code’s address. Defaults to True.

Raises:

ValueError – If the code is not active.

clear_all(restore_value=True)[source]

Remove all GameShark cheats from the emulator.

Example:

>>> pyboy.gameshark.clear_all()
Parameters:

restore_value (bool) – Restore original bytes at modified addresses. Defaults to True.