/******************************************************************************\ ** ** This file is part of the Hades GBA Emulator, and is made available under ** the terms of the GNU General Public License version 2. ** ** Copyright (C) 2021-2026 - The Hades Authors ** \******************************************************************************/ #pragma once #include "hades.h" #include "debugger.h" struct gba; struct cheat_token { enum { CHEAT_TOKEN_KIND_U32, CHEAT_TOKEN_KIND_U16, CHEAT_TOKEN_KIND_U8, } kind; union { uint32_t u32; uint16_t u16; uint8_t u8; } value; struct cheat_token *next; }; struct cheat_compiler { struct cheat_token *tokens; struct cheat_token *last; char *error; }; struct cheat_bin { struct { struct cheat_rom_patch *list; size_t len; size_t capacity; } rom_patches; struct { struct cheat_insn *list; size_t len; size_t capacity; } insns; struct { bool active; struct sw_breakpoint bp; } hook; }; struct cheat_insn { enum cheat_insn_kind { CHEAT_INSN_ASSIGN, CHEAT_INSN_INDIRECT_ASSIGN, CHEAT_INSN_ADD_ASSIGN, CHEAT_INSN_AND_ASSIGN, CHEAT_INSN_OR_ASSIGN, CHEAT_INSN_IF_BUTTON, CHEAT_INSN_IF_KEYPAD, CHEAT_INSN_IF_EQ, CHEAT_INSN_IF_NEQ, CHEAT_INSN_IF_GT_UNSIGNED, CHEAT_INSN_IF_GT_SIGNED, CHEAT_INSN_IF_LT_UNSIGNED, CHEAT_INSN_IF_LT_SIGNED, CHEAT_INSN_IF_AND, } kind; union { struct { uint32_t addr; uint32_t value; uint32_t width; uint32_t addr_offset; uint32_t value_offset; uint32_t repeat; } assign; struct { uint32_t addr; uint32_t offset; uint32_t value; uint32_t width; } ind_assign; struct { uint32_t addr; uint32_t value; uint32_t width; } add_assign; struct { uint32_t addr; uint32_t value; uint32_t width; } and_assign; struct { uint32_t addr; uint32_t value; uint32_t width; } or_assign; struct { uint32_t addr; uint32_t value; uint32_t width; uint32_t skip; } cond; struct { uint16_t mask; } keypad; }; }; struct cheat_rom_patch { uint32_t addr; uint32_t value; uint32_t width; }; struct cheats { struct cheat_bin *list; size_t len; bool button; // GameShark/Action Replay special button. }; void cheat_delete(struct cheat_bin *bin); void cheat_dump(struct cheat_bin const *bin); void cheat_process_hooks_at_addr(struct gba *gba, uint32_t addr); void cheat_hook_impl(struct gba *gba, struct cheat_bin const *bin); struct cheat_insn *cheat_create_insn(struct cheat_bin *bin); bool cheat_parv3_compile(struct cheat_bin *bin, struct cheat_compiler *compiler); bool cheat_gameshark_compile(struct cheat_bin *bin, struct cheat_compiler *compiler); bool cheat_codebreaker_compile(struct cheat_bin *bin, struct cheat_compiler *compiler); void cheat_create_rom_patch(struct cheat_bin *bin, uint32_t addr, uint32_t val, uint32_t width);