A module is one game's patch as one unit (nn/module.h): what it applies to, what it hooks on the CPU, and its
handlers, in one file of src/nx/patches/. src/nx/patches/modules.c lists every module built into the runtime, and
nothing else names one. A module can also be a library of its own, built outside ScarletNX
(below), which the runtime adds after them. When the game starts, hook_install takes each
module of the list (hook_modules_select) and logs whether it applies, and why not (hooks: module NAME doesn't
apply, and leaves the game as it is: check 0 at main+100 differs at byte 1 (21 there)). A module of another title
isn't logged.
A module that doesn't apply leaves the game as it is: its hooks aren't installed. hooks=0 turns every module off,
and hooks_off names modules as it names families (a module's name is its family's), so the game's .ini turns one
off for that game alone.
typedef struct {
const char* name; /* its word in hooks_off and in the log, the family of its address hooks */
const char* what; /* what it does, for the log */
u64 title; /* the title ID it applies to, 0 any */
const char* module; /* the game's module its build ID and checks name: NULL for main */
const char* build_id; /* that module's build ID, the hex of its first bytes, NULL any */
const HookModuleCode* code;
u32 ncode;
} HookModule;
title isn't 0: the game's title ID (SnxModule.title_id).build_id is given: the hex of the first bytes of its build ID, as
an address hook's key names it. Another version of the game is another build, and gets nothing.HookModuleCode): bytes at an offset of one of the game's modules, a byte as two hex digits or
?? for any ("fd 7b bf a9 ?? ?? 00 94"). Each must lie within that module's code and hold. A check is the gate
for a module that hooks code it read: a build ID can't tell a patched module (a mod's) from the original.All of them must hold. A compiled-in module's CPU hooks are then the address hooks of its family, as
Game patches says: family NAME in src/nx/patches/NAME.hook, the handlers in its
.c file. A library's are its CPU hooks (below). A module never writes the game's code,
so it doesn't meet a mod's detours (below). A 32-bit game gets no module
yet: hook_install chooses them for a 64-bit game alone.
hook_module_applied, hook_module_refused and hook_module_off (tests/hook_install.c with
tests/hook_module_plain.c) check a compiled-in module: one named after a family, its hook installed when its code
check holds, and the function left to its own code when the check fails or hooks_off names the module.
A module that replaces a pass of the game's GPU work (its upscaler, say) hooks the game's function that records that
pass. gpu_hook_trace=N ([Debug], gpu/nvn/nvn_trace.c) finds the pass and that function: it logs the game's first
N draws and dispatches as its queues replay them. Each dispatch's line has its program's hash (FNV-1a 64 of its code),
its code's size and address, its call site in main (the return address of the game's call that recorded it), grid and
block. An Ounce dispatch's line also has its packed c[0]'s buffers (address and size) and each texture and image
handle with the image it names (address, render target format, size). Each draw's line has its fragment program's
hash, targets and viewport. Each line ends with the records since the one before that aren't state binds or barriers
(their op codes), and the log marks each wait, each end of a submission and each present. gpu_hook_trace_from lets
that many presents go by first, to trace a scene the game reaches after its start. gpu_hook_trace_words adds words
of one constant buffer of each draw (a stage, a slot, an offset and a count), as floats, to read a camera's matrices
across frames. The pass is read off a frame of that log, with the game's own pictures of its passes (a RenderDoc
capture) to tell their roles, and its call site leads to the function to hook (tools/disasm.py). The hashes, call
sites and layouts are the game's, so they stay in the module of that game and in no other file. Off, the replay tests
one flag per record and calls nothing of the trace. nvn_trace (tests/nvn_trace.c) checks its lines.
Made from docs/platforms/nx/hooks.md at 69237645142c. GPL-3.0-or-later.