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)
@nsobid- gives it: the hex of its
first 8 to 32 bytes, the rest of the ID zeros. The offset is the function's entry from the module's base, as a
symbol's value would be. A hook of an offset that isn't 4-aligned is refused.hook is the handler's, as the function has no other, so = HANDLER is refused.@version. A game's other version has another ID: its
functions move, and it gets no hook until a line of its own names it.BUILDID:OFFSET in lower case without the ID's ending zero bytes, 0x or leading zeros
(0123456789abcdef0123456789abcdef01234567:1a2b40), stands for its symbol: in the table, in the log
(hook: 0123...:1a2b40 at 81a7b40 (main+1a2b40) runs game_mode_set), in hooks_off by its family, and in the
route list. The loader makes each key of a module's own build a function seed and a routed function
(route_addresses, loader.c), so the recompiler compiles the function at that entry and calls it through its slot
from every direct call. Under NCE the slot's stub at the function's first word takes the calls from native code, as
it does for any hook (nce_slot_taken).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.