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- add(code)[source]¶
Add a GameShark cheat to the emulator.
Codes use the eight-hex-digit format
ttvvaaaa:ttis the code type,vvthe byte to write, andaaaathe address in low-byte-first order. Currently, only type01(write one byte) is supported.Example:
>>> pyboy.gameshark.add("01FF16D0")
- Parameters:
code (str) – GameShark code to add
- Raises:
ValueError – If the code is malformed, has an unsupported type, or targets an invalid address.
PyBoyInvalidInputException – If this code is already active.
- remove(code, restore_value=True)[source]¶
Remove a GameShark cheat from the emulator.
Example:
>>> pyboy.gameshark.add("01FF16D0") >>> pyboy.gameshark.remove("01FF16D0")
- Parameters:
- Raises:
ValueError – If the code is not active.