diff --git a/.github/workflows/linux-appimage.yml b/.github/workflows/linux-appimage.yml index 6376895..969d960 100644 --- a/.github/workflows/linux-appimage.yml +++ b/.github/workflows/linux-appimage.yml @@ -9,6 +9,13 @@ on: tags: ['*'] pull_request: workflow_dispatch: + inputs: + # (a build that replaces a release's Linux file names that release: a game built from it compares its version with + # the latest release's tag by name (host/hos_update.c), and git describe's v0.3.6-1-g... would be told of v0.3.6) + version: + description: "The version the AppImage names itself (empty: git describe's)" + required: false + default: '' permissions: contents: read concurrency: @@ -95,6 +102,8 @@ jobs: ls -la work work/image - name: AppImage + env: + HOOKSHOT_VERSION: ${{ inputs.version }} # (empty but for a started run that names one: appimage.sh asks git then) run: scripts/linux/appimage.sh # (AMD FSR 4's Linux side, a build option the AppImage leaves off (gpu/vk/vk_fsr4.cpp: dlopen, the older backend diff --git a/host/oot_menu.c b/host/oot_menu.c index a18363e..d0d1f72 100644 --- a/host/oot_menu.c +++ b/host/oot_menu.c @@ -13,7 +13,15 @@ and hands it to the focus manager (*(screen+32)+96, its vtable +48), when the manager takes the player's input. HOS_MENU_TRACE=1: the focus changes, the screens and what the mouse does logged. */ #include "hos.h" -#if defined(_WIN32) +/* (Triforce) The game's own Options screen (the layout SystemOption_00; the title's Options and the pause menu's are the one + screen), by its vtable (HOS_MENU_TRACE in a headless run, 2026-11-10: the screen of 15 entries that starts to run when + Options is chosen, from the title and from the pause menu alike, and stops with Back; L and R do nothing on it). While + it runs the renderer is told each frame (rx_option_set HOS_OPT_GAME_OPTIONS): the menu draws its tabs over this + screen's header, the game's own list the first of them (gpu/vk/vk_menu.cpp), and nn_hid.c passes Back on when one of + our tabs is left with it. HOS_OPTIONS_TABS=0 keeps the renderer untold */ +#define OPTIONS_SCREEN_VTABLE 0x84c0f108ULL +void rx_option_set(int id, int value); /* rx_backend.c */ +#if defined(_WIN32) && !defined(HOS_OOT_MENU_NO_MOUSE) /* (the macro: tests/test_oot_menu_mouse.py builds the other half on Windows) */ #include #include #include @@ -231,15 +239,7 @@ static int panel_page(uint64_t screen) { return panel_page_vt(peek64(screen)); } search of memory, in Lord Jabu-Jabu's Belly): +0x1368 the floor chosen (2F 1, 1F 0, B1 -1), +0x136c how many floors, +0x1370 the lowest; the top is the lowest + the count - 1. Kept as the screens are seen */ #define HUD_SCREEN_VTABLE 0x84c08300ULL -/* (Triforce) The game's own Options screen (the layout SystemOption_00; the title's Options and the pause menu's are the one - screen), by its vtable (HOS_MENU_TRACE in a headless run, 2026-11-10: the screen of 15 entries that starts to run when - Options is chosen, from the title and from the pause menu alike, and stops with Back; L and R do nothing on it). While - it runs the renderer is told each frame (rx_option_set HOS_OPT_GAME_OPTIONS): the menu draws its tabs over this - screen's header, the game's own list the first of them (gpu/vk/vk_menu.cpp), and nn_hid.c passes Back on when one of - our tabs is left with it. HOS_OPTIONS_TABS=0 keeps the renderer untold */ -#define OPTIONS_SCREEN_VTABLE 0x84c0f108ULL static volatile LONG64 options_seen_ns; -void rx_option_set(int id, int value); /* rx_backend.c */ int hos_oot_options_front(void) { const LONG64 t = InterlockedCompareExchange64(&options_seen_ns, 0, 0); return t && (LONG64)hos_now_ns() - t < 200000000LL; @@ -836,7 +836,32 @@ void hos_oot_menu_tick(Ctx *c, uint64_t screen) { if (screen == pause_screen_now()) InterlockedIncrement(&ticks); } #else +/* Not Windows: the mouse in the game's menus is the Windows window's (display.c), not here. The game's own Options + screen is named all the same, each frame it runs, so the options' tabs sit in it as on Windows: they are the only way + to our options since the keys that opened them over the game went (gpu/vk/vk_menu.cpp overlay_allowed), and with this + left out a Linux build had none at all (2026-11-14). The screen is the one whose update the lifted game is running + (nx2/oot_patches.py patch_menu_tick), so its first word, the vtable, is there to read */ +#include +#include +#include "../gpu/vk/vk_api.h" /* (HOS_OPT_GAME_OPTIONS) */ +static int64_t options_seen_ns; /* (the screens' updates run on several of the game's threads: read and written whole) */ void hos_oot_menu_focus(Ctx *c, uint64_t screen, uint64_t pane, uint64_t lr) { (void)c, (void)screen, (void)pane, (void)lr; } -void hos_oot_menu_tick(Ctx *c, uint64_t screen) { (void)c, (void)screen; } -int hos_oot_options_front(void) { return 0; } +void hos_oot_menu_tick(Ctx *c, uint64_t screen) { + (void)c; + uint64_t vt = 0; + if (screen < 0x100000 || screen >= HOS_GUEST_SPACE - 8) return; + memcpy(&vt, GP(screen), 8); + if (vt != OPTIONS_SCREEN_VTABLE) return; + static int tabs = -1; + if (tabs < 0) { + const char *e = getenv("HOS_OPTIONS_TABS"); + tabs = !(e && *e == '0'); + } + __atomic_store_n(&options_seen_ns, hos_now_ns(), __ATOMIC_RELAXED); + if (tabs) rx_option_set(HOS_OPT_GAME_OPTIONS, 1); +} +int hos_oot_options_front(void) { + const int64_t t = __atomic_load_n(&options_seen_ns, __ATOMIC_RELAXED); + return t && hos_now_ns() - t < 200000000LL; +} #endif diff --git a/tests/test_oot_menu_mouse.py b/tests/test_oot_menu_mouse.py index 8246ba9..dc1e19f 100644 --- a/tests/test_oot_menu_mouse.py +++ b/tests/test_oot_menu_mouse.py @@ -47,6 +47,7 @@ int64_t hos_now_ns(void); VK_API_H = r""" #pragma once enum { HOS_MOUSE_LEFT = 1, HOS_MOUSE_RIGHT = 2, HOS_MOUSE_MIDDLE = 4 }; +enum { HOS_OPT_GAME_OPTIONS = 48 }; """ FIXTURE = r""" @@ -72,6 +73,7 @@ static int pointer_hidden; /* (the cursor hidden while the pad is in use: the static int menu_frees, menu_gone; /* (the game's menus' mouse: freed for a menu's frame; their close told) */ void hos_mouse_game_menu(void) { menu_frees++; } void hos_mouse_game_menu_gone(void) { menu_gone++; } +void rx_option_set(int id, int value) { (void)id, (void)value; } /* (the Options screen named: the renderer's) */ int hos_mouse_wheel_take(void) { const int w = wheel_next; wheel_next = 0; return w; } /* (the wheel only, mouse kept) */ int hos_mouse_game_pointer(int *x, int *y, int *w, int *h, uint32_t *pressed, int *wheel) { *x = ptr_x, *y = ptr_y, *w = 3840, *h = 2160, *pressed = pressed_next, *wheel = wheel_next; @@ -299,6 +301,87 @@ int main(void) { """ +# The game's own Options screen named for the renderer (its tabs sit in it): every system's, the mouse or not. On Windows +# the file's other half is compiled for this (HOS_OOT_MENU_NO_MOUSE), which is the half Linux gets +OPTIONS_FIXTURE = r""" +#include "hos.h" +#include "../gpu/vk/vk_api.h" +#include +#include +#include +uint8_t *fake_heap; +static int64_t now_ns = 1000000000; +int64_t hos_now_ns(void) { return now_ns; } +void hos_log(const char *fmt, ...) { (void)fmt; } +static int told, told_id, told_value; +void rx_option_set(int id, int value) { told++, told_id = id, told_value = value; } +void hos_oot_menu_focus(Ctx *c, uint64_t screen, uint64_t pane, uint64_t lr); +void hos_oot_menu_tick(Ctx *c, uint64_t screen); +int hos_oot_options_front(void); +static int fails; +#define CHECK(x) do { if (!(x)) { printf("FAIL line %d: %s\n", __LINE__, #x); fails++; } } while (0) +int main(void) { + fake_heap = calloc(1, 4 << 20); + Ctx ctx; + memset(&ctx, 0, sizeof ctx); + const uint64_t options = FAKE_BASE + 0x1000, other = FAKE_BASE + 0x2000; + const uint64_t options_vt = 0x84c0f108ULL, other_vt = 0x84c0bc18ULL; + memcpy(GP(options), &options_vt, 8); + memcpy(GP(other), &other_vt, 8); + CHECK(!hos_oot_options_front()); + hos_oot_menu_tick(&ctx, 0); /* (no screen) */ + hos_oot_menu_tick(&ctx, 8); /* (not a guest address) */ + hos_oot_menu_tick(&ctx, HOS_GUEST_SPACE - 4); /* (its vtable would end past the guest's space) */ + hos_oot_menu_tick(&ctx, other); /* (another screen: the pause menu's vtable) */ + hos_oot_menu_focus(&ctx, other, other + 64, 0); + CHECK(told == 0 && !hos_oot_options_front()); + hos_oot_menu_tick(&ctx, options); + CHECK(told == 1 && told_id == HOS_OPT_GAME_OPTIONS && told_value == 1); + CHECK(hos_oot_options_front()); + now_ns += 100000000; /* (0.1 s on, no frame of it between: still in front) */ + CHECK(hos_oot_options_front()); + hos_oot_menu_tick(&ctx, options); + CHECK(told == 2); + now_ns += 300000000; /* (0.3 s with none: closed) */ + hos_oot_menu_tick(&ctx, other); + CHECK(told == 2 && !hos_oot_options_front()); + /* (the screen's memory is another screen's later: its vtable as it is now) */ + memcpy(GP(options), &other_vt, 8); + hos_oot_menu_tick(&ctx, options); + CHECK(told == 2 && !hos_oot_options_front()); + if (!fails) printf("PASS\n"); + return fails != 0; +} +""" + + +class OotOptionsScreenTests(unittest.TestCase): + def test_names_the_options_screen_without_the_mouse(self): + compiler = shutil.which("gcc") or shutil.which("clang") + if not compiler: + self.skipTest("no C compiler") + with tempfile.TemporaryDirectory(prefix="hookshot-oot-options-") as tmp: + tmp = Path(tmp) + (tmp / "host").mkdir() + (tmp / "gpu" / "vk").mkdir(parents=True) + (tmp / "host" / "hos.h").write_text(HOS_H, encoding="utf-8") + (tmp / "gpu" / "vk" / "vk_api.h").write_text(VK_API_H, encoding="utf-8") + shutil.copy(ROOT / "host" / "oot_menu.c", tmp / "host" / "oot_menu.c") + (tmp / "host" / "t.c").write_text(OPTIONS_FIXTURE, encoding="utf-8") + binary = tmp / "t.exe" + other_half = ["-DHOS_OOT_MENU_NO_MOUSE"] if sys.platform == "win32" else [] + build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-O1", "-g", str(tmp / "host" / "t.c")] + + ["-c", "-o", str(tmp / "t.o")], text=True, capture_output=True) + self.assertEqual(build.returncode, 0, build.stderr) + build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-O1", "-g"] + other_half + + ["-c", str(tmp / "host" / "oot_menu.c"), "-o", str(tmp / "m.o")], text=True, capture_output=True) + self.assertEqual(build.returncode, 0, build.stderr) + build = subprocess.run([compiler, str(tmp / "t.o"), str(tmp / "m.o"), "-o", str(binary)], text=True, capture_output=True) + self.assertEqual(build.returncode, 0, build.stderr) + run = subprocess.run([str(binary)], text=True, capture_output=True, timeout=30) + self.assertEqual(run.returncode, 0, run.stdout + run.stderr) + + class OotMenuMouseTests(unittest.TestCase): def test_points_and_clicks_the_menus(self): if sys.platform != "win32":