Game patches: hooks by address

A function that no symbol names, in one build of one game, is hooked by its module's build ID and its offset in that module. Each game's hooks are a spec of their own in src/nx/patches/, <game>.hook, with their handlers beside it in <game>.c. No game has one yet: the folder holds only the list of modules, modules.c. src/nx/CMakeLists.txt collects its .c files, and cmake/hookgen.cmake its .hook files, for the first one:

family game_frame_rate
[0123456789abcdef0123456789abcdef01234567:0x1a2b40] hook game_mode_set(u32 mode)

hookgen reads hooks.hook and then each patch into one table, each spec with its own family lines (cmake/hookgen.cmake's snx_hook_patches), so a patch file is added by creating it. Adding one changes the route list, and only a game whose build a key names compiles anything differently.

A game patch's handler changes what the game does, as an IPS patch would, where hooks.hook's handlers only do what their functions do. It is written from reading the function's code, works on the guest's data through hook_host, and keeps the game's own code doing the rest: hook_run_original(c, addr) runs the function's own code with the CPU as the call left it, through the dispatch loop until the function returns to the call's return address, so a handler can change an argument before it and a result after it. hook_site(key) gives the address the hook went to, from which a handler finds its module's base and data.


Made from docs/platforms/nx/hooks.md at 69237645142c. GPL-3.0-or-later.