Modules (3)

/* one_game.c, in a repository of its own: one game's upscaler replaced by the runtime's */
#include "nx/nn/snx_hook_module.h"

static void upscaler(const SnxHookHost* host, SnxHookCpu* cpu) {
    SnxHookRecordedUpscale u = {0};
    u.size = sizeof u;
    /* the function's arguments: its command buffer, the pass's input and output textures, their sizes */
    uint64_t commands = host->reg(cpu, 0 /* its argument */);
    u.color.texture = host->reg(cpu, 0), u.output.texture = host->reg(cpu, 0);
    u.render[0] = 0, u.render[1] = 0, u.out[0] = 0, u.out[1] = 0;
    u.pre_exposure = 1;
    u.flags = SNX_HOOK_UPSCALE_RANGE_GIVEN | SNX_HOOK_UPSCALE_SPATIAL_OK;
    if (!host->record_upscale(cpu, commands, &u)) host->run_original(cpu);
}
static const SnxHookCpuHook hooks[] = {{0 /* the function's offset in main */, "the game's upscaler", upscaler}};
static const SnxHookModule module = {.abi_major = SNX_HOOK_ABI_MAJOR,
                                     .abi_minor = SNX_HOOK_ABI_MINOR,
                                     .name = "one_game_upscaler",
                                     .what = "the game's upscaler replaced",
                                     .title = 0 /* its title */,
                                     .build_id = "00" /* main's build ID */,
                                     .cpu_hooks = hooks,
                                     .ncpu_hooks = 1};
SNX_HOOK_EXPORT const SnxHookModule* snx_hook_module(const SnxHookHost* host) {
    return host->abi_major == SNX_HOOK_ABI_MAJOR ? &module : NULL;
}

and its build, with CMake, as one_game_upscaler.so:

add_library(one_game_upscaler MODULE one_game.c)
target_include_directories(one_game_upscaler PRIVATE "${SCARLETNX_SOURCE_DIR}/src")
set_target_properties(one_game_upscaler PROPERTIES PREFIX "" SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}"
                      C_VISIBILITY_PRESET hidden)

hook_module_lib (tests/hook_module_lib.c) builds libraries of no game from tests/hook_module_lib_mod.c, one for each case: a folder's library taken, a file that isn't a library passed over, the library hooks_off names never loaded, each refusal above with its reason, the module as the runtime's (title, build ID, code check, CPU hook) applied to its game and not to another build, and the host's log and setting read. snx-test-hook-module-lib --load PATH loads one library and prints what the runtime made of it, to check a module built elsewhere without a game. Only Linux runs it yet: the loads on Windows, macOS and Android are not tested, and Android's shared storage is mounted noexec.


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