mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-21 00:59:59 -04:00
Faster frames (the replay's memory work, held submits, helper threads, collection and capture cuts), the game letting old areas go (QueryMemoryInfo), the 0.5.2 stutter fixed, AMD RX 5000/6000 and integrated-GPU fixes, the GPU device chosen by name, the in-game menus and launcher reworked, controller, Linux and benchmark fixes.
665 lines
34 KiB
Python
665 lines
34 KiB
Python
"""The mouse in the game's own menus (host/oot_menu.c): where it points, what it asks of the game.
|
|
|
|
The file is compiled on its own against a fake guest memory holding menu screens as the game lays them out: a screen's
|
|
list of entries (+136 the head, +144 the first node, +156 the entry's offset from its node; entry+24 the button), a
|
|
button's focus at +56 and its hit box at *(button+0x58) (its matrix at +0x28: the scale at +0x28 and +0x38, the
|
|
translation at +0x4c and +0x50; its rectangle at +0x84, about the origin; a second box's scale at +0xd8 and centre at
|
|
+0xfc). hos_oot_menu_tick is what a menu screen's update calls each frame (f_802f1380), hos_oot_menu_focus what the pause
|
|
menu's focus handler calls (f_802ed660; nx2/oot_patches.py). The game's focus setter (f_8088ffc0) is a fake that records
|
|
its button; the pad's presses (hos_hid_tap) are recorded as their script.
|
|
|
|
In the pause menu the mouse moved onto a button gives it the focus through the setter, a click on the focused button is
|
|
A and the right button B, a click on the "Back" prompt is B even with a button's box under it, the L and R signs are L
|
|
and R and the wheel turns the pages. A slot whose hit box covers a side of its picture is hit on the other side too. A
|
|
focus change the game reports from another thread while the setter runs (the mouse's lock held) does not wait for the
|
|
lock, and is the mouse's at its next tick. On a
|
|
list of the title's 60 x 60 marks a row is hit across the line and in the gaps between rows, and the wheel moves the
|
|
focus down a row with the setter, without the pad. On the R button's item choice (a carousel) the wheel presses the
|
|
D-pad's right (down) and left (up), a notch each, one after another, and the mouse is not freed (it stays the
|
|
camera's). With the cursor hidden (R held counts as the pad in use) the wheel still moves a list, and moving the mouse
|
|
points at nothing. Once frames go on with no menu holding the mouse, the window is told at once.
|
|
(Triforce) The game's Options screen has the mouse with no focused button found, and as the screen that came last when its
|
|
address held another screen before (another vtable). Its rows' kinds are read from the screen's three lists of widgets (the
|
|
button from a widget through the game's look-up f_80df5410, a fake here): a click on a plate is A, on a toggle's value Left
|
|
for its left half (On, up to where the halves meet, past the value's middle) and Right for its right half (Off), on a
|
|
choice's value Left or Right of its middle, on a name or a row of no kind A. A row scrolled away past the list is not
|
|
pointed at, the header (our tabs', the renderer's) is neither pointed at nor clicked, the right button is B, and the wheel
|
|
gives the focus to the row past the list's foot (the list's view, not the screen's).
|
|
(Triforce, 11-19) The Mods entry under the title's list is told to the renderer a pitch under the last row, and the mouse
|
|
takes it across the line as the game's own rows: moved onto its word it takes the cursor (as the pad's Down), a click there
|
|
opens it. On the pause menu's System page the mouse moved onto Mods or Quit under its buttons takes the cursor as well,
|
|
as the game's own buttons do on hover.
|
|
python -I -B tests/test_oot_menu_mouse.py (Windows: the feature's; elsewhere it is skipped)
|
|
"""
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
HOS_H = r"""
|
|
#pragma once
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
typedef struct Ctx { uint64_t x[32]; uint64_t vreg[32][2]; } Ctx;
|
|
typedef void (*A64Fn)(Ctx *);
|
|
A64Fn a64_lookup(uint64_t addr);
|
|
extern uint8_t *fake_heap;
|
|
#define FAKE_BASE 0x100000ULL
|
|
#define HOS_GUEST_SPACE (FAKE_BASE + (4ULL << 20))
|
|
#define GP(a) ((void *)(fake_heap + ((uint64_t)(a) - FAKE_BASE)))
|
|
void hos_log(const char *fmt, ...);
|
|
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 };
|
|
enum { HOS_OPT_MODS_LIST = 150, HOS_OPT_MODS_X0, HOS_OPT_MODS_X1, HOS_OPT_MODS_Y0, HOS_OPT_MODS_Y1, HOS_OPT_MODS_PITCH, HOS_OPT_MODS_ENTER,
|
|
HOS_OPT_MODS_SELECTED, HOS_OPT_MODS_PRESS };
|
|
enum { HOS_MODS_LIST_SHOWN = 1, HOS_MODS_LIST_LAST_FOCUSED = 2, HOS_MODS_LIST_TITLE = 4 };
|
|
"""
|
|
|
|
FIXTURE = r"""
|
|
#include "hos.h"
|
|
#include "../gpu/vk/vk_api.h"
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <windows.h>
|
|
uint8_t *fake_heap;
|
|
static uint64_t heap_top = FAKE_BASE + 0x1000;
|
|
static int64_t clock_ns = 1000000000LL;
|
|
void hos_log(const char *fmt, ...) { va_list a; va_start(a, fmt); vfprintf(stderr, fmt, a); va_end(a); fputc(10, stderr); }
|
|
int64_t hos_now_ns(void) { return clock_ns; }
|
|
volatile LONG64 hos_present_count; /* (display.c's: the game's presents, which hos_oot_mods_down counts) */
|
|
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);
|
|
|
|
/* the window: 3840 x 2160, so a pixel is a unit of the layout's (x right of the centre, y up) */
|
|
static int ptr_x = 1920, ptr_y = 1080, wheel_next;
|
|
static uint32_t pressed_next;
|
|
static int pointer_hidden; /* (the cursor hidden while the pad is in use: the wheel only) */
|
|
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++; }
|
|
/* (the renderer's options: the Options screen named; (Triforce) the Mods entry's list told, and the host's words on it) */
|
|
static int mods_box_said[5], mods_enter_said, mods_selected, game_options_said;
|
|
void rx_option_set(int id, int value) {
|
|
if (id >= HOS_OPT_MODS_X0 && id <= HOS_OPT_MODS_PITCH) mods_box_said[id - HOS_OPT_MODS_X0] = value;
|
|
if (id == HOS_OPT_MODS_ENTER) mods_enter_said = value;
|
|
if (id == HOS_OPT_GAME_OPTIONS) game_options_said = value;
|
|
}
|
|
int rx_option(int id, int otherwise) { return id == HOS_OPT_MODS_SELECTED ? mods_selected : otherwise; }
|
|
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;
|
|
pressed_next = 0, wheel_next = 0;
|
|
return pointer_hidden ? 2 : 1;
|
|
}
|
|
static char taps[1024];
|
|
void hos_hid_tap(const char *press) { strncat(taps, press, sizeof taps - strlen(taps) - 2), strcat(taps, ";"); }
|
|
void hos_hid_stick(int lx, int ly, int rx, int ry, int hold_ms) { (void)lx, (void)ly, (void)rx, (void)ry, (void)hold_ms; }
|
|
void hos_hid_drag(int dx, int dy, int right) { (void)dx, (void)dy, (void)right; }
|
|
static uint64_t focus_asked, focus_screen;
|
|
static int focus_calls;
|
|
/* (a focus change reported from another of the game's threads while the setter runs: the hook there must not wait for
|
|
the mouse's lock, held around this call) */
|
|
static uint64_t other_screen, other_pane;
|
|
static DWORD other_wait = WAIT_TIMEOUT + 1;
|
|
static DWORD WINAPI other_thread(LPVOID arg) {
|
|
Ctx other = {0};
|
|
(void)arg;
|
|
hos_oot_menu_focus(&other, other_screen, other_pane, 0);
|
|
return 0;
|
|
}
|
|
static void focus_setter(Ctx *c) {
|
|
focus_screen = c->x[0], focus_asked = c->x[1], focus_calls++, c->x[0] = 1;
|
|
if (other_pane) {
|
|
HANDLE t = CreateThread(NULL, 0, other_thread, NULL, 0, NULL);
|
|
other_wait = t ? WaitForSingleObject(t, 5000) : WAIT_FAILED;
|
|
if (t) CloseHandle(t);
|
|
other_pane = 0;
|
|
}
|
|
}
|
|
static uint64_t get64(uint64_t a);
|
|
/* (Triforce) the game's look-up of an Options row's button from its widget's pane (f_80df5410): here the pane's first word */
|
|
static void find_button(Ctx *c) { c->x[0] = get64(c->x[0]); }
|
|
A64Fn a64_lookup(uint64_t addr) { return addr == 0x8088ffc0ULL ? focus_setter : addr == 0x80df5410ULL ? find_button : NULL; }
|
|
|
|
static uint64_t alloc(size_t n) { const uint64_t a = heap_top; heap_top += (n + 15) & ~(size_t)15; return a; }
|
|
static void put64(uint64_t a, uint64_t v) { memcpy(GP(a), &v, 8); }
|
|
static void putf(uint64_t a, float f) { memcpy(GP(a), &f, 4); }
|
|
static uint64_t get64(uint64_t a) { uint64_t v; memcpy(&v, GP(a), 8); return v; }
|
|
/* (Triforce) an Options row's widget, in the screen's list of its kind (+at the count, +at+8 the widgets): *(widget+24) its
|
|
layout's holder, *(holder+56) the pane the look-up is handed */
|
|
static void options_widget(uint64_t s, int at, uint64_t button) {
|
|
int32_t n;
|
|
memcpy(&n, GP(s + at), 4);
|
|
if (!get64(s + at + 8)) put64(s + at + 8, alloc(8 * 16));
|
|
const uint64_t w = alloc(64), holder = alloc(64), pane = alloc(16);
|
|
put64(w + 24, holder), put64(w + 32, 0x5a), put64(holder + 56, pane), put64(pane, button);
|
|
put64(get64(s + at + 8) + 8ull * (unsigned)n, w), n++;
|
|
memcpy(GP(s + at), &n, 4);
|
|
}
|
|
|
|
/* a screen: its vtable, its focus manager (*(screen+32)+96), an empty list */
|
|
static uint64_t screen_new(uint64_t vtable) {
|
|
const uint64_t s = alloc(1024), mgr = alloc(128);
|
|
put64(s, vtable), put64(s + 32, mgr), put64(mgr + 96, alloc(16));
|
|
put64(s + 144, s + 136); /* (no entries: the first node is the head) */
|
|
return s;
|
|
}
|
|
/* a button with a hit box w x h centred at (x, y), last in the screen's list */
|
|
static uint64_t button_new(uint64_t s, float x, float y, float w, float h) {
|
|
const uint64_t entry = alloc(64), button = alloc(128), box = alloc(0x200);
|
|
put64(entry + 24, button), put64(entry + 8, s + 136), put64(button + 0x58, box);
|
|
putf(box + 0x28, 1), putf(box + 0x38, 1), putf(box + 0x4c, x), putf(box + 0x50, y);
|
|
putf(box + 0x84, -w / 2), putf(box + 0x88, -h / 2), putf(box + 0x8c, w), putf(box + 0x90, h);
|
|
uint64_t node = s + 144; /* (the link to the head: the last node's +8, or the first's at +144) */
|
|
while (get64(node) != s + 136) node = get64(node) + 8;
|
|
put64(node, entry);
|
|
return button;
|
|
}
|
|
static void focused(uint64_t button, int on) { *(uint8_t *)GP(button + 56) = (uint8_t)on; }
|
|
|
|
static Ctx ctx;
|
|
static int fails;
|
|
#define CHECK(c) do { if (!(c)) { printf("FAIL line %d: %s (taps \"%s\", focus %#llx)\n", __LINE__, #c, taps, \
|
|
(unsigned long long)focus_asked); fails++; } } while (0)
|
|
/* a frame of the screen's with the mouse at (x, y) in the layout's units */
|
|
static void frame(uint64_t s, float x, float y) {
|
|
ptr_x = (int)(x + 1920), ptr_y = (int)(1080 - y);
|
|
clock_ns += 16666667;
|
|
hos_oot_menu_tick(&ctx, s);
|
|
}
|
|
/* a frame of two screens running (one opened over the other, both updated) */
|
|
static void frame2(uint64_t under, uint64_t over, float x, float y) {
|
|
ptr_x = (int)(x + 1920), ptr_y = (int)(1080 - y);
|
|
clock_ns += 16666667;
|
|
hos_oot_menu_tick(&ctx, under);
|
|
hos_oot_menu_tick(&ctx, over);
|
|
}
|
|
static void reset(void) { taps[0] = 0, focus_asked = 0, focus_calls = 0; }
|
|
/* a click at (x, y) on the Options screen over the list, the row there given the focus first */
|
|
static void options_click_at(uint64_t under, uint64_t over, uint64_t row, float x, float y) {
|
|
frame2(under, over, x, y);
|
|
focused(row, 1);
|
|
reset();
|
|
pressed_next = HOS_MOUSE_LEFT;
|
|
frame2(under, over, x, y);
|
|
focused(row, 0);
|
|
}
|
|
/* the game takes the focus the setter asked for: its handler runs (the pause menu's), the button shows it */
|
|
static void take_focus(uint64_t s, uint64_t from, uint64_t to, int pause) {
|
|
focused(from, 0), focused(to, 1);
|
|
if (pause) hos_oot_menu_focus(&ctx, s, to, 0);
|
|
}
|
|
|
|
int main(void) {
|
|
fake_heap = (uint8_t *)calloc(1, 4u << 20);
|
|
ctx.x[31] = FAKE_BASE + (3u << 20);
|
|
|
|
/* The pause menu: two slots, a box over the "Back" prompt's corner, a slot whose hit box is its picture's right side */
|
|
const uint64_t pause = screen_new(0x84c0baa8ULL);
|
|
const uint64_t a = button_new(pause, -500, 200, 200, 200), b = button_new(pause, 0, 200, 200, 200);
|
|
const uint64_t corner = button_new(pause, 1750, -1020, 400, 200);
|
|
const uint64_t side = button_new(pause, -1120, -400, 100, 260);
|
|
{ /* (its picture's box, centred 80 to the left of the hit box's) */
|
|
const uint64_t box = get64(side + 0x58);
|
|
putf(box + 0xd8, 1), putf(box + 0xfc, -1200), putf(box + 0x100, -400);
|
|
}
|
|
focused(b, 1);
|
|
hos_oot_menu_focus(&ctx, pause, b, 0);
|
|
frame(pause, 0, 200); /* (the screen seen, its focus found: the mouse is for it) */
|
|
reset();
|
|
frame(pause, -500, 210);
|
|
CHECK(focus_calls == 1 && focus_asked == a && focus_screen == pause); /* hover: the setter, on that button */
|
|
CHECK(taps[0] == 0); /* silently: no pad */
|
|
take_focus(pause, b, a, 1);
|
|
reset();
|
|
frame(pause, -505, 210);
|
|
CHECK(focus_calls == 0); /* already focused: nothing asked */
|
|
pressed_next = HOS_MOUSE_LEFT;
|
|
frame(pause, -505, 210);
|
|
CHECK(strstr(taps, "A/80") != NULL); /* a click on it: A */
|
|
reset();
|
|
pressed_next = HOS_MOUSE_RIGHT;
|
|
frame(pause, -505, 210);
|
|
CHECK(!strcmp(taps, "0:B/80;")); /* the right button: B */
|
|
reset();
|
|
frame(pause, 1700, -1020);
|
|
pressed_next = HOS_MOUSE_LEFT;
|
|
frame(pause, 1700, -1020);
|
|
CHECK(focus_asked != corner && !strcmp(taps, "0:B/80;")); /* the Back prompt: B, the box under it not focused */
|
|
reset();
|
|
pressed_next = HOS_MOUSE_LEFT;
|
|
frame(pause, 1000, 1000);
|
|
CHECK(!strcmp(taps, "0:R/120;")); /* the R sign */
|
|
reset();
|
|
pressed_next = HOS_MOUSE_LEFT;
|
|
frame(pause, -1000, 1000);
|
|
CHECK(!strcmp(taps, "0:L/120;")); /* the L sign */
|
|
reset();
|
|
wheel_next = -1;
|
|
frame(pause, -1000, 1000);
|
|
CHECK(!strcmp(taps, "0.00:R/60;")); /* the wheel down: the next page */
|
|
reset();
|
|
frame(pause, -1260, -400);
|
|
CHECK(focus_asked == side); /* the slot's picture's other side: hit */
|
|
take_focus(pause, a, side, 1);
|
|
reset();
|
|
frame(pause, -1400, -400);
|
|
CHECK(focus_calls == 0); /* past it: nothing */
|
|
/* the game reports the focus from another thread while the setter runs: the hook returns at once, and the change
|
|
is the mouse's at its next tick (a click then is A at once: the focus it asked for has come) */
|
|
reset();
|
|
other_screen = pause, other_pane = b;
|
|
frame(pause, 0, 210);
|
|
CHECK(focus_asked == b && other_wait == WAIT_OBJECT_0);
|
|
focused(side, 0), focused(b, 1);
|
|
reset();
|
|
pressed_next = HOS_MOUSE_LEFT;
|
|
frame(pause, 0, 210);
|
|
CHECK(focus_calls == 0 && !strcmp(taps, "0:A/80;"));
|
|
|
|
/* A list of the title's marks (60 x 60, a line's middle), opened over it; the pause menu stopped */
|
|
clock_ns += 300000000LL;
|
|
const uint64_t title = screen_new(0x84c106e8ULL);
|
|
const uint64_t r0 = button_new(title, -600, 200, 60, 60), r1 = button_new(title, -600, 0, 60, 60),
|
|
r2 = button_new(title, -600, -200, 60, 60);
|
|
focused(r0, 1);
|
|
frame(title, -600, 200);
|
|
reset();
|
|
frame(title, -200, 0);
|
|
CHECK(focus_asked == r1); /* across the line, 400 from its mark */
|
|
take_focus(title, r0, r1, 0);
|
|
reset();
|
|
frame(title, -600, 110);
|
|
CHECK(focus_asked == r0); /* in the gap between rows: the nearer */
|
|
take_focus(title, r1, r0, 0);
|
|
reset();
|
|
frame(title, -600, -290);
|
|
CHECK(focus_asked == r2); /* below the last row by as much as the gap's half */
|
|
take_focus(title, r0, r2, 0);
|
|
reset();
|
|
frame(title, -600, -400);
|
|
CHECK(focus_calls == 0); /* further: nothing */
|
|
take_focus(title, r2, r0, 0);
|
|
reset();
|
|
wheel_next = -1;
|
|
frame(title, -600, -400);
|
|
CHECK(focus_asked == r1 && taps[0] == 0); /* the wheel down: the focus a row down, by the setter, no pad */
|
|
|
|
/* R held (the pad in use) over the list: the cursor hidden; the mouse moved over another row takes no focus, the
|
|
wheel still moves it */
|
|
take_focus(title, r0, r1, 0);
|
|
pointer_hidden = 1;
|
|
reset();
|
|
frame(title, -600, -200);
|
|
CHECK(focus_calls == 0);
|
|
wheel_next = -1;
|
|
frame(title, -600, -200);
|
|
CHECK(focus_asked == r2);
|
|
pointer_hidden = 0;
|
|
|
|
/* The R button's item choice (a carousel in a row, in play), opened next: the mouse is not freed (the camera's), the
|
|
wheel is the D-pad's right and left */
|
|
clock_ns += 300000000LL;
|
|
const uint64_t choice = screen_new(0x84c0d430ULL);
|
|
const uint64_t c0 = button_new(choice, -300, 0, 200, 200);
|
|
const uint64_t c1 = button_new(choice, 300, 0, 200, 200);
|
|
focused(c0, 1);
|
|
frame(choice, -300, 0);
|
|
reset();
|
|
menu_frees = 0;
|
|
frame(choice, 300, 0);
|
|
CHECK(menu_frees == 0 && focus_calls == 0 && focus_asked != c1); /* no freed mouse, no pointing */
|
|
wheel_next = -1;
|
|
frame(choice, -300, 0);
|
|
CHECK(!strcmp(taps, "0.000:RIGHT/60;") && focus_calls == 0); /* down: right, a press */
|
|
reset();
|
|
wheel_next = 2;
|
|
frame(choice, -300, 0); /* (the next frame: each press after the last has been let go, 120 ms on) */
|
|
CHECK(!strcmp(taps, "0.103:LEFT/60,0.223:LEFT/60;") && focus_calls == 0); /* up two notches: left twice */
|
|
reset();
|
|
wheel_next = -20;
|
|
frame(choice, -300, 0); /* (a long spin: no more than 0.72 s of presses queued) */
|
|
CHECK(!strcmp(taps, "0.327:RIGHT/60,0.447:RIGHT/60,0.567:RIGHT/60,0.687:RIGHT/60;"));
|
|
clock_ns += 2000000000LL; /* (2 s on, all let go: the next press at once) */
|
|
reset();
|
|
wheel_next = -1;
|
|
frame(choice, -300, 0);
|
|
CHECK(!strcmp(taps, "0.000:RIGHT/60;"));
|
|
|
|
/* (Triforce) The game's Options screen, at the address another screen ran at before (another vtable), opened over a list
|
|
that still runs with its focus (first seen after that other screen): the Options came last, and the mouse is its own
|
|
with no focused button found. Its rows as it lays them out (1824 x 124 about x -730, 170 apart from y 674), their
|
|
widgets in the screen's lists by kind: a plate (amiibo), a toggle (On | Off), a choice, a row in no list, and one
|
|
scrolled away above the list, under the header */
|
|
clock_ns += 300000000LL;
|
|
const uint64_t opt = screen_new(0x84c10a00ULL);
|
|
frame(opt, 0, 0);
|
|
clock_ns += 300000000LL;
|
|
const uint64_t under = screen_new(0x84c106e8ULL);
|
|
const uint64_t u0 = button_new(under, 1300, -600, 60, 60);
|
|
focused(u0, 1);
|
|
frame(under, 1300, -600);
|
|
put64(opt, 0x84c0f108ULL);
|
|
const uint64_t o_plate = button_new(opt, -730, 674, 1824, 124), o_toggle = button_new(opt, -730, 504, 1824, 124),
|
|
o_choice = button_new(opt, -730, 334, 1824, 124), o_none = button_new(opt, -730, 164, 1824, 124),
|
|
o_away = button_new(opt, -730, 844, 1824, 124);
|
|
const uint64_t o_tall = button_new(opt, 1500, 700, 300, 600); /* (a box of the screen's up into the header: 400 to 1000) */
|
|
options_widget(opt, 696, o_plate), options_widget(opt, 712, o_toggle), options_widget(opt, 728, o_choice);
|
|
menu_frees = 0;
|
|
frame2(under, opt, -400, 504);
|
|
frame2(under, opt, -400, 504);
|
|
CHECK(menu_frees > 0); /* the mouse freed for it, no focused button found */
|
|
reset();
|
|
frame2(under, opt, -1200, 674);
|
|
CHECK(focus_asked == o_plate && focus_screen == opt); /* hover: the row's focus, the Options', not the list's under it */
|
|
reset();
|
|
frame2(under, opt, -730, 800);
|
|
CHECK(focus_calls == 0); /* a row scrolled away: not pointed at */
|
|
options_click_at(under, opt, o_plate, 0, 674);
|
|
CHECK(strstr(taps, ":A/80;") && !strstr(taps, "LEFT") && !strstr(taps, "RIGHT")); /* a plate: A, on its right too */
|
|
options_click_at(under, opt, o_toggle, -500, 504);
|
|
CHECK(strstr(taps, ":LEFT/80;") != NULL); /* a toggle's left half (On): Left */
|
|
options_click_at(under, opt, o_toggle, -180, 504);
|
|
CHECK(strstr(taps, ":LEFT/80;") != NULL); /* past the value's middle, short of where the halves meet: still On */
|
|
options_click_at(under, opt, o_toggle, 0, 504);
|
|
CHECK(strstr(taps, ":RIGHT/80;") != NULL); /* its right half (Off): Right */
|
|
options_click_at(under, opt, o_toggle, -1300, 504);
|
|
CHECK(strstr(taps, ":A/80;") != NULL); /* its name: A, as before */
|
|
options_click_at(under, opt, o_choice, -300, 334);
|
|
CHECK(strstr(taps, ":LEFT/80;") != NULL); /* a choice's left of its middle: Left (down) */
|
|
options_click_at(under, opt, o_choice, -180, 334);
|
|
CHECK(strstr(taps, ":RIGHT/80;") != NULL); /* right of it: Right (up) */
|
|
options_click_at(under, opt, o_none, 0, 164);
|
|
CHECK(strstr(taps, ":A/80;") != NULL); /* a row of no kind found: A */
|
|
reset();
|
|
pressed_next = HOS_MOUSE_LEFT;
|
|
frame2(under, opt, 1500, 960);
|
|
CHECK(taps[0] == 0 && focus_calls == 0); /* the header: our tabs' (the renderer's), nothing here, a box under it or not */
|
|
options_click_at(under, opt, o_tall, 1500, 600);
|
|
CHECK(strstr(taps, ":A/80;") != NULL); /* (the same box below the header: the game's) */
|
|
reset();
|
|
pressed_next = HOS_MOUSE_RIGHT;
|
|
frame2(under, opt, 0, 960);
|
|
CHECK(!strcmp(taps, "0:B/80;")); /* the right button: B, anywhere */
|
|
/* the wheel down: the row laid out past the list's foot (y -960: scrolled away below it, on the screen still) is given
|
|
the focus, the list scrolls to it; the rows' view is the list's, not the screen's */
|
|
const uint64_t o_below = button_new(opt, -730, -1000, 1824, 124);
|
|
focused(o_toggle, 1);
|
|
reset();
|
|
wheel_next = -1;
|
|
frame2(under, opt, -1300, 504);
|
|
CHECK(focus_asked == o_below && taps[0] == 0);
|
|
focused(o_toggle, 0);
|
|
(void)o_away;
|
|
|
|
/* ((Triforce, 11-19) The title's list with the Mods entry under it (mods_list_tick; the renderer draws it): four marks
|
|
110 apart, the game's cursor on the last (its focus controller's entry). The entry is told a pitch under the last mark,
|
|
and taken across the line as the game's own rows are (1100 wide, a pitch high): the mouse moved onto its word, well
|
|
off the 60 x 60 mark's square, takes the cursor as the pad's Down does (the renderer's word 1); a click there opens it
|
|
(2). With Mods chosen the mouse moving over it says nothing again */
|
|
clock_ns += 300000000LL;
|
|
const uint64_t tl = screen_new(0x84c106e8ULL);
|
|
button_new(tl, 0, -500, 60, 60), button_new(tl, 0, -610, 60, 60), button_new(tl, 0, -720, 60, 60);
|
|
const uint64_t t3 = button_new(tl, 0, -830, 60, 60);
|
|
{
|
|
const uint64_t mgr = alloc(128), ctrl = alloc(256), e = alloc(64);
|
|
put64(get64(tl + 32) + 96, mgr), put64(mgr + 40, ctrl), put64(ctrl + 120, e), put64(e + 24, t3), put64(e + 32, tl);
|
|
}
|
|
focused(t3, 3);
|
|
frame(tl, 0, -830);
|
|
frame(tl, 0, -830);
|
|
CHECK(mods_box_said[4] == 110 && mods_box_said[2] == -860 && mods_box_said[3] == -800); /* (the last mark's box, the pitch) */
|
|
mods_enter_said = 0;
|
|
reset();
|
|
frame(tl, 230, -950); /* (the word, 230 right of the entry's middle: under no game row) */
|
|
CHECK(mods_enter_said == 1 && focus_calls == 0);
|
|
mods_enter_said = 0;
|
|
pressed_next = HOS_MOUSE_LEFT;
|
|
frame(tl, 230, -950);
|
|
CHECK(mods_enter_said == 2 && taps[0] == 0); /* a click on it: open, not the game's A */
|
|
mods_enter_said = 0;
|
|
frame(tl, -400, -980);
|
|
CHECK(mods_enter_said == 1); /* (the entry's lower half, left of its middle) */
|
|
mods_enter_said = 0;
|
|
frame(tl, 0, -1010);
|
|
CHECK(mods_enter_said == 0); /* below it: nothing */
|
|
mods_selected = 1;
|
|
frame(tl, 230, -950);
|
|
CHECK(mods_enter_said == 0); /* chosen already */
|
|
mods_selected = 0;
|
|
|
|
/* ((Triforce, 11-19) The pause menu's System page: its buttons (Pa_Button_*) in the left column, 200 apart, the game's
|
|
cursor on the last; Mods a pitch under it and Quit under Mods. The mouse moved onto Mods takes the cursor (1), onto
|
|
Quit too (4), as the game's buttons above take it on hover; a click on Quit opens its dialog (3) */
|
|
clock_ns += 300000000LL;
|
|
const uint64_t ps = screen_new(0x84c0baa8ULL);
|
|
uint64_t sys[4];
|
|
for (int i = 0; i < 4; i++) {
|
|
sys[i] = button_new(ps, -1000, 300 - 200.0f * i, 672, 144);
|
|
const uint64_t name = alloc(32);
|
|
memcpy(GP(name), "Pa_Button_00", 13);
|
|
put64(sys[i] + 0x18, name);
|
|
}
|
|
{ /* (the System page's name, as the pause menu's focus handler reads it: pane+32 -> +128 -> +248 -> +24) */
|
|
const uint64_t obj = alloc(256), p1 = alloc(512), p2 = alloc(64), page = alloc(32);
|
|
memcpy(GP(page), "PaSystemMenu_00", 16);
|
|
put64(p2 + 24, page), put64(p1 + 248, p2), put64(obj + 128, p1), put64(sys[3] + 32, obj);
|
|
const uint64_t mgr = alloc(128), ctrl = alloc(256), e = alloc(64);
|
|
put64(get64(ps + 32) + 96, mgr), put64(mgr + 40, ctrl), put64(ctrl + 120, e), put64(e + 24, sys[3]), put64(e + 32, ps);
|
|
}
|
|
focused(sys[3], 3);
|
|
hos_oot_menu_focus(&ctx, ps, sys[3], 0);
|
|
frame(ps, -1000, 0);
|
|
frame(ps, -1000, 0);
|
|
CHECK(mods_box_said[4] == 200 && mods_box_said[2] == -372 && mods_box_said[3] == -228); /* (the last button's box, the pitch) */
|
|
mods_enter_said = 0;
|
|
reset();
|
|
frame(ps, -1100, -500); /* (Mods: under no game button) */
|
|
CHECK(mods_enter_said == 1 && focus_calls == 0);
|
|
mods_enter_said = 0;
|
|
frame(ps, -1100, -700); /* (Quit) */
|
|
CHECK(mods_enter_said == 4 && focus_calls == 0);
|
|
mods_enter_said = 0;
|
|
pressed_next = HOS_MOUSE_LEFT;
|
|
frame(ps, -1100, -700);
|
|
CHECK(mods_enter_said == 3 && taps[0] == 0); /* a click on Quit: its dialog, not the game's A */
|
|
mods_enter_said = 0;
|
|
frame(ps, -1100, -900);
|
|
CHECK(mods_enter_said == 0); /* below Quit: nothing */
|
|
mods_selected = 1;
|
|
frame(ps, -1100, -500);
|
|
frame(ps, -1100, -700);
|
|
CHECK(mods_enter_said == 0); /* chosen already */
|
|
mods_selected = 0;
|
|
|
|
/* Back in play (R let go): only the HUD's screen runs, no menu's. The window is told the menus have closed once
|
|
50 ms of frames have had none: the camera gets its mouse back then, not 300 ms on */
|
|
clock_ns += 300000000LL;
|
|
const uint64_t hud = screen_new(0x84c08300ULL);
|
|
menu_gone = 0;
|
|
frame(hud, 0, 0);
|
|
frame(hud, 0, 0);
|
|
CHECK(menu_gone == 0); /* (the first frames: not yet 50 ms) */
|
|
for (int i = 0; i < 4; i++) frame(hud, 0, 0);
|
|
CHECK(menu_gone > 0);
|
|
|
|
/* ((Triforce, 11-20, a review of 1104352) The Options screen told as 1 from the title (no pause menu ran before it), as 2
|
|
chosen from the pause menu (its screen ran just before), for the whole of that run even with the pause menu's updates
|
|
stopped under it; a new run later with no pause menu before it: 1 again */
|
|
clock_ns += 2000000000LL;
|
|
const uint64_t opts = screen_new(0x84c0f108ULL);
|
|
game_options_said = 0;
|
|
frame(opts, 0, 0);
|
|
CHECK(game_options_said == 1); /* (the title's Options) */
|
|
clock_ns += 300000000LL;
|
|
frame(hud, 0, 0);
|
|
frame(ps, -1000, 0); /* (the pause menu, Options chosen on it) */
|
|
frame(opts, 0, 0);
|
|
CHECK(game_options_said == 2);
|
|
for (int i = 0; i < 60; i++) frame(opts, 0, 0); /* (a second of it alone) */
|
|
CHECK(game_options_said == 2);
|
|
clock_ns += 300000000LL; /* (closed; the pause menu back, then play, then the title's Options) */
|
|
frame(ps, -1000, 0);
|
|
clock_ns += 1000000000LL;
|
|
frame(hud, 0, 0);
|
|
clock_ns += 300000000LL;
|
|
frame(opts, 0, 0);
|
|
CHECK(game_options_said == 1);
|
|
if (!fails) printf("PASS\n");
|
|
return fails != 0;
|
|
}
|
|
"""
|
|
|
|
|
|
# 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 <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
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());
|
|
/* ((Triforce, 11-20, a review of 1104352) chosen from the pause menu (its screen, 0x84c0baa8, ran just before): told as
|
|
2 for that run, the pause menu's updates stopped under it or not; a later run with none before it: 1 */
|
|
memcpy(GP(options), &options_vt, 8);
|
|
const uint64_t pause = FAKE_BASE + 0x3000, pause_vt = 0x84c0baa8ULL;
|
|
memcpy(GP(pause), &pause_vt, 8);
|
|
now_ns += 300000000;
|
|
hos_oot_menu_tick(&ctx, pause);
|
|
CHECK(told == 2); /* (the pause menu is not the Options screen) */
|
|
now_ns += 16000000;
|
|
hos_oot_menu_tick(&ctx, options);
|
|
CHECK(told == 3 && told_value == 2);
|
|
for (int i = 0; i < 60; i++) now_ns += 16000000, hos_oot_menu_tick(&ctx, options);
|
|
CHECK(told == 63 && told_value == 2);
|
|
now_ns += 1000000000; /* (closed, back in play, then the title's Options) */
|
|
hos_oot_menu_tick(&ctx, options);
|
|
CHECK(told == 64 && told_value == 1);
|
|
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")
|
|
shutil.copy(ROOT / "host" / "guest_bounds.h", tmp / "host" / "guest_bounds.h") # (set_item_key's buffer check)
|
|
(tmp / "host" / "hos_bench.h").write_text(HOS_BENCH_H, encoding="utf-8") # ((Triforce, 11-19) benchmark mode: off here)
|
|
(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)
|
|
|
|
|
|
# ((Triforce, 11-19) host/hos_bench.h's two calls oot_menu.c makes, benchmark mode off: the menus as a player has them)
|
|
HOS_BENCH_H = """#pragma once
|
|
#include <stdint.h>
|
|
enum { HOS_BENCH_MENU_NONE, HOS_BENCH_MENU_PRESS_A };
|
|
static inline int hos_bench_on(void) { return 0; }
|
|
static inline int hos_bench_menu(uint64_t screen, uint64_t vt, int focus, int focused_entry, int entries, int *entry) {
|
|
(void)screen, (void)vt, (void)focus, (void)focused_entry, (void)entries, (void)entry;
|
|
return HOS_BENCH_MENU_NONE;
|
|
}
|
|
"""
|
|
|
|
|
|
class OotMenuMouseTests(unittest.TestCase):
|
|
def test_points_and_clicks_the_menus(self):
|
|
if sys.platform != "win32":
|
|
self.skipTest("the game's menus' mouse is Windows' (host/oot_menu.c: _WIN32)")
|
|
compiler = shutil.which("gcc") or shutil.which("clang")
|
|
if not compiler:
|
|
self.skipTest("no C compiler")
|
|
with tempfile.TemporaryDirectory(prefix="hookshot-oot-menu-") as tmp:
|
|
tmp = Path(tmp)
|
|
(tmp / "host").mkdir()
|
|
(tmp / "gpu" / "vk").mkdir(parents=True)
|
|
# (beside the stand-in hos.h, and its "../gpu/vk/vk_api.h" the stand-in's)
|
|
(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")
|
|
shutil.copy(ROOT / "host" / "guest_bounds.h", tmp / "host" / "guest_bounds.h") # (set_item_key's buffer check)
|
|
(tmp / "host" / "hos_bench.h").write_text(HOS_BENCH_H, encoding="utf-8") # ((Triforce, 11-19) benchmark mode: off here)
|
|
(tmp / "host" / "t.c").write_text(FIXTURE, encoding="utf-8")
|
|
binary = tmp / "t.exe"
|
|
build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-O1", "-g", "-D_WIN32_WINNT=0x0601",
|
|
str(tmp / "host" / "t.c"), str(tmp / "host" / "oot_menu.c"), "-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)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(unittest.main(verbosity=1))
|