From 00d3907fbb8ac57b4351044553639b62979a096e Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 18 Nov 2026 21:55:09 -0500 Subject: [PATCH 01/10] fix(gameplay): the gameplay view's hook at lift time, so the free camera takes the view nx2/oot_patches.py's patch_view finds the loop head of f_804e48c0 0 times ("the free camera was found 0 times" in every build log, stock 9f725aa1 included), so hos_oot_free_view never ran and the free camera never moved the view. nx2/oot_view.py puts the same call after the instruction at that loop head instead (main+0x4c5068, its three words checked): the view's matrix at view+8 is complete there and x20 is the view. patch_view counts a function that already has the call as found and adds no second one. Co-Authored-By: Claude Opus 5.5 --- engine/nx2/lift.py | 2 ++ engine/nx2/oot_patches.py | 2 ++ engine/nx2/oot_view.py | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 engine/nx2/oot_view.py diff --git a/engine/nx2/lift.py b/engine/nx2/lift.py index 9cea3597f..32237286a 100644 --- a/engine/nx2/lift.py +++ b/engine/nx2/lift.py @@ -165,6 +165,8 @@ def main(): oot_jitter.install(L, img) import oot_occlusion # (no occlusion queries when HOOKSHOT_OCCLUSION_OFF=1: Fritchii's Occlusion Off) oot_occlusion.install(L, img) + import oot_view # (fork: the gameplay view's hook, which oot_patches.py's patch_view no longer finds; host/hos_main.c) + oot_view.install(L, img) L.discover(max_insns=a.max_func) print("discovered %d functions (%.0fs)" % (len(L.funcs), time.time() - t0)) total = coverage(L, img, img_dir) diff --git a/engine/nx2/oot_patches.py b/engine/nx2/oot_patches.py index d41985b59..bdb9d3f39 100644 --- a/engine/nx2/oot_patches.py +++ b/engine/nx2/oot_patches.py @@ -116,6 +116,8 @@ def patch_view(source): body = source[start:end] if end < 0: return None + if "hos_oot_free_view(c, c->x[20])" in body: # (fork: nx2/oot_view.py put the call in at lift time: found, not twice) + return source for anchor in VIEW_ANCHORS: if body.count(anchor) == 1: break diff --git a/engine/nx2/oot_view.py b/engine/nx2/oot_view.py new file mode 100644 index 000000000..5e88b1f3a --- /dev/null +++ b/engine/nx2/oot_view.py @@ -0,0 +1,26 @@ +"""(fork) The gameplay view's hook for the free camera and first person (host/hos_main.c hos_oot_free_view), at lift time. + +nx2/oot_patches.py's patch_view looks for the loop head of f_804e48c0 (main+0x4c48c0, the view-matrix routine) as a bare +label in the lifted C, and finds it 0 times on this build ("the free camera was found 0 times" in every build log, stock +9f725aa1 included), so the free camera's view was never rebuilt. This puts the same call after the instruction at that +loop head instead (main+0x4c5068, ldr x8, [x19, #0x20]): the view's 3x4 matrix at view+8 is complete there (its last row +stored just before, at main+0x4c5064), and x20 is the view. patch_view counts a function that already has the call as +found and adds no second one. +""" + +MAIN = 0x80020000 +SITE = MAIN + 0x4c5068 +# ldr x8, [x19, #0x20]; cbz x8, ...; ldr x21, [x8, #0x150] +WORDS = (0xf9401268, 0xb4005868, 0xf940a915) +HOOK = ("{ extern void hos_oot_free_view(Ctx *c, uint64_t view); hos_oot_free_view(c, c->x[20]); }" + " /* (nx2/oot_view.py: the free camera and first person) */") + + +def install(lifter, img): + """The site into lifter.after, after what is there; left out when its words differ (another game version)""" + if any(img.word(SITE + 4 * i) != word for i, word in enumerate(WORDS)): + print("gameplay view: unsupported view code, left out") + return 0 + lifter.after[SITE] = (lifter.after[SITE] + "\n" if SITE in lifter.after else "") + HOOK + print("gameplay view: free camera and first person hooked") + return 1 From 47874978052e63e7f080f635e345465b7b08cf66 Mon Sep 17 00:00:00 2001 From: ToxicToucan <75706815+ToxicToucan@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:39:14 -0500 Subject: [PATCH 02/10] feat(gameplay): first person, with Link's head hidden A Gameplay row, First person (off by default; HL_OPT_FIRST_PERSON, 91 in vk_opt_ids.h). While it is on, the free view (hos_oot_free_view, host/hos_main.c) builds the gameplay view from Link's eyes instead of the free camera's eye: 0.35 m out from his head along the look, turned by the right stick from his facing; host/nn_hid.c gives the right stick to the view and not to the game's camera. Link walks as ever, the stick read against this view. The free camera, while on, takes its place. The player's update keeps his place, facing and eye height (1.15 m as a child, 1.55 m as an adult) and hides his head the way the game's own AI node OneshotModelSetMaterialVisible does (its execute at main+0x29637f0): through his models' vtable +208 (a material's index by name) and +456 (show or hide it), called as guest functions. The face, eyes, eyebrows, eyelashes, teeth, front hair and the hair model go; the hat is part of the tunic's material and stays. They are hidden again every half second while it is on (a load or a change of age or tunic makes new models) and shown again when off. Co-Authored-By: Claude Opus 5.5 --- engine/gpu/vk/vk_menu.cpp | 3 + engine/gpu/vk/vk_menu.h | 1 + engine/gpu/vk/vk_opt_ids.h | 3 + engine/gpu/vk/vk_replay.cpp | 1 + engine/host/hos_main.c | 122 ++++++++++++++++++++++++-- engine/host/nn_hid.c | 7 +- engine/tests/test_input_background.py | 3 + 7 files changed, 134 insertions(+), 6 deletions(-) diff --git a/engine/gpu/vk/vk_menu.cpp b/engine/gpu/vk/vk_menu.cpp index 79d2e0e95..43eaf1730 100644 --- a/engine/gpu/vk/vk_menu.cpp +++ b/engine/gpu/vk/vk_menu.cpp @@ -677,6 +677,9 @@ Row rows[] = { {TAB_GAMEPLAY, "Skip title screen", &opts.skip_title, 0, 1, 1, tx_onoff, // (HL_OPT_SKIP_TITLE, vk_opt_ids.h, host/oot_autoload.c) "Starts a launch with the most recent saved game: presses through the title screen and its file list. Does nothing " "until the game has a save. Applies after a restart.", nullptr, true, true}, + {TAB_GAMEPLAY, "First person", &opts.first_person, 0, 1, 1, tx_onoff, // (HL_OPT_FIRST_PERSON, vk_opt_ids.h, host/hos_main.c) + "Plays from Link's eyes: the right stick looks around, Link walks the way you look, and his head is hidden. The free " + "camera, while on, takes its place.", nullptr, false, true}, {TAB_GAMEPLAY, "Send performance statistics", &opts.send_perf, 0, 1, 1, tx_telemetry, "Off by default. On: the game counts how its frames go (frame times, stutters and what they waited on, per map) and sends " "a summary of the counts, without your name or any ID; what is kept of it is totals for all players. Every 5 minutes of play " diff --git a/engine/gpu/vk/vk_menu.h b/engine/gpu/vk/vk_menu.h index 7debd267e..c38fdc330 100644 --- a/engine/gpu/vk/vk_menu.h +++ b/engine/gpu/vk/vk_menu.h @@ -59,6 +59,7 @@ struct Options { int vram_mb = 0; // dynamic texture cache budget limit in MB int mirror_mb = 0; // staging mirror limit in MB int audio_output = 0; // (hookshot) the speakers the game mixes for: 0 Auto (the default output's), 1 Stereo, 2 5.1; read once, at the start (host/nn_audio.c; HOS_AUDIO_CHANNELS) + int first_person = 0; // the view from Link's eyes, his head hidden (host/hos_main.c; HL_OPT_FIRST_PERSON) int skip_title = 0; // (longshot) start with the most recent save, pressing through the title and its file list (host/oot_autoload.c); read at the start int discord = 1; // (hookshot) the Discord status (host/discord_rpc.c): 1 on, shown while a Discord client runs on this PC int update_check = 1; // (heylisten) "Check for updates" (host/hos_update.c): 1 the offer at the start (the default), 0 off; saved as update_check= diff --git a/engine/gpu/vk/vk_opt_ids.h b/engine/gpu/vk/vk_opt_ids.h index bf591b01c..75531ba00 100644 --- a/engine/gpu/vk/vk_opt_ids.h +++ b/engine/gpu/vk/vk_opt_ids.h @@ -10,3 +10,6 @@ /* The Skip title screen row (host/oot_autoload.c asks, gpu/vk/vk_replay.cpp answers 0 or 1). 44 is the id Longshot's change of the same row uses in vk_api.h (free in this tree: the ids there run 32 to 35, 40 to 43), so the two agree. */ #define HL_OPT_SKIP_TITLE 44 + +/* The Gameplay page's First person row (host/hos_main.c and host/nn_hid.c ask, gpu/vk/vk_replay.cpp answers 0 or 1) */ +#define HL_OPT_FIRST_PERSON 91 diff --git a/engine/gpu/vk/vk_replay.cpp b/engine/gpu/vk/vk_replay.cpp index cfea99795..35d5d8e5f 100644 --- a/engine/gpu/vk/vk_replay.cpp +++ b/engine/gpu/vk/vk_replay.cpp @@ -6903,6 +6903,7 @@ void fill_replay_table(MkwVkRenderer& t) { if (id == HOS_OPT_HDR_WHITE) return std::clamp(opts.hdr_white, 80, 500); if (id == HOS_OPT_DISCORD) return opts.discord != 0; if (id == HL_OPT_SKIP_TITLE) return opts.skip_title != 0; + if (id == HL_OPT_FIRST_PERSON) return opts.first_person != 0; // (host/hos_main.c, host/nn_hid.c) return id == 0 ? opts.realtime : id == 1 ? menu_is_open() : id == 2 ? resolution_auto() && !temporal_full_scale() : id == 3 ? (temporal_full_scale() ? 10000 : resolution_scale()) : id == 4 ? opts.pad_background : id == 5 ? opts.text_speed : id == 6 ? opts.mouse_native : id == 7 ? opts.mouse_sens : id == 8 ? opts.mouse_invert : id == 9 ? opts.rumble : id == 16 ? opts.invert_cam_x : id == 17 ? opts.invert_cam_y : id == HOS_OPT_GYRO ? opts.gyro : id == HOS_OPT_GYRO_SENS_X ? opts.gyro_sens_x : id == HOS_OPT_GYRO_SENS_Y ? opts.gyro_sens_y : id == HOS_OPT_GYRO_INV_X ? opts.gyro_inv_x : id == HOS_OPT_GYRO_INV_Y ? opts.gyro_inv_y : id == HOS_OPT_GYRO_DEADZONE ? opts.gyro_deadzone : id == HOS_OPT_DLSS_JITTER_W || id == HOS_OPT_DLSS_JITTER_H || id == HOS_OPT_DLSS_JITTER_PHASES ? jitter_option(id) : diff --git a/engine/host/hos_main.c b/engine/host/hos_main.c index 77fe93318..7bc7f6a19 100644 --- a/engine/host/hos_main.c +++ b/engine/host/hos_main.c @@ -13,6 +13,7 @@ #include "hos_run_logs.h" #include "../gpu/vk/vk_api.h" #include "../gpu/vk/oot_cheat_items.h" +#include "../gpu/vk/vk_opt_ids.h" /* (HL_OPT_FIRST_PERSON) */ #include #include #include @@ -1111,6 +1112,103 @@ static int64_t flight_player_seen; static int64_t play_began; /* (the first time the player ran, hos_now_ns clock; 0 before) */ static int64_t process_start_ns; /* (hos_now_ns when main began) */ +/* First person, the Gameplay page's First person row (HL_OPT_FIRST_PERSON). The player's update keeps Link's place, facing + and eye height for the view (oot_build_free_view, which puts the eye there) and hides his head while it is on. + + The head is hidden the way the game's own AI node OneshotModelSetMaterialVisible does it (its execute at main+0x29637f0): + components (actor+624) +8 is a component whose getter (vtable +248) gives the model holder (the default getter, the GOT slot + 0x84cd9d58, returns component+24); the holder's +40 is an array of model slots, each slot's first word a model. On a model, + vtable +208 (model, &name) is a material's index (negative: none) and vtable +456 (model, index, visible) shows or hides it. + The head is the face, eyes, eyebrows, eyelashes, teeth and front hair of the body model (Player_Child / Player_Adult) and the + hair model (Armor_*_Default_Head, Mt_Hair); the hat is the tunic's material and stays (22 materials on the child, logged + at the first hide). */ +static volatile float fp_link[3], fp_link_yaw, fp_eye_height = 1.15f; +static volatile int fp_link_known; + +static const char *const kHeadMaterials[] = {"Mt_Face", "Mt_Face_Eyelid", "Mt_Face_SoftEdge", "Mt_Eye_Inner", "Mt_Eye_Outer", + "Mt_Eyebrow", "Mt_Eyelashes", "Mt_Eyelashes_01", "Mt_Eyelashes_02", "Mt_Eyelashes_03", "Mt_Eyeshadow", "Mt_EyeShadow_test", + "Mt_Teeth", "Mt_Hairs", "Mt_Hair"}; + +static int fp_in_main(uint64_t a) { return a >= 0x80020000ULL && a < 0x85020000ULL; } + +/* a guest call with the stack at sp and up to three arguments: x0 after it, in *ret; 0 when the function is not known */ +static int fp_guest_call(Ctx *c, uint64_t fn, uint64_t sp, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t *ret) { + if (!fp_in_main(fn)) return 0; + A64Fn f = a64_lookup(fn); + if (!f) return 0; + const Ctx saved = *c; + c->x[31] = sp; + c->x[0] = a0, c->x[1] = a1, c->x[2] = a2; + f(c); + if (ret) *ret = c->x[0]; + *c = saved; + return 1; +} + +/* Shows or hides the head materials on each of the actor's models; how many were set */ +static int fp_set_head_visible(Ctx *c, uint64_t components, int visible, int log) { + const uint64_t comp = recomp_load64(c, components + 8); + if (!comp || !fp_in_main(recomp_load64(c, comp))) return 0; + const uint64_t getter = recomp_load64(c, recomp_load64(c, comp) + 248); + const uint64_t scratch = (c->x[31] - 256) & ~15ULL; /* (below the guest stack: the name's pointer, then the name) */ + uint64_t holder = 0; + if (getter == recomp_load64(c, 0x84cd9d58ULL)) holder = recomp_load64(c, comp + 24); + else if (!fp_guest_call(c, getter, scratch - 16, comp, 0, 0, &holder)) return 0; + const uint64_t slots = holder ? recomp_load64(c, holder + 40) : 0; + if (!slots) return 0; + int set = 0; + for (int i = 0; i < 16; i++) { + const uint64_t slot = recomp_load64(c, slots + i * 8); + const uint64_t model = slot ? recomp_load64(c, slot) : 0; + if (!model) break; + const uint64_t vt = recomp_load64(c, model); + if (!fp_in_main(vt)) break; + int found = 0; + for (unsigned n = 0; n < sizeof kHeadMaterials / sizeof kHeadMaterials[0]; n++) { + const char *name = kHeadMaterials[n]; + const size_t len = strlen(name); + for (size_t k = 0; k <= len; k++) recomp_store8_sp(c, scratch + 16 + k, (uint8_t)name[k]); + recomp_store64_sp(c, scratch, scratch + 16); + uint64_t index = ~0ULL; + if (!fp_guest_call(c, recomp_load64(c, vt + 208), scratch - 16, model, scratch, 0, &index) || (index & 0x80000000u)) + continue; + fp_guest_call(c, recomp_load64(c, vt + 456), scratch - 16, model, (uint32_t)index, visible ? 1 : 0, NULL); + found++; + } + if (log) + hos_log("first person: model %d (vtable %#llx): %d head materials %s", i, (unsigned long long)vt, found, + visible ? "shown" : "hidden"); + set += found; + } + return set; +} + +static void oot_first_person_player(Ctx *c, uint64_t actor, uint64_t components, int64_t now) { + int rx_option(int id, int otherwise); + static int hidden, logs; + static int64_t hidden_at, age_at; + const int want = rx_option(HL_OPT_FIRST_PERSON, 0) && !rx_option(HOS_OPT_CHEAT_CAMERA, 0); + for (unsigned i = 0; i < 3; i++) fp_link[i] = oot_load_float(c, actor + 796 + i * 4); + fp_link_yaw = atan2f(oot_load_float(c, actor + 816), oot_load_float(c, actor + 840)); + fp_link_known = 1; + if (want && now - age_at > 2000000000LL) { /* (his eyes: about 1.15 m as a child, 1.55 m as an adult) */ + int child = 1; + if (oot_gamedata_bool(c, 0xcea220d3u, &child)) fp_eye_height = child ? 1.15f : 1.55f; + age_at = now; + } + /* again every half second while on: a scene load or a change of age or tunic makes new models */ + if (want && (!hidden || now - hidden_at > 500000000LL)) { + const int n = fp_set_head_visible(c, components, 0, logs < 2); + if (logs < 2) logs++, hos_log("first person: %d head materials hidden", n); + hidden = 1; + hidden_at = now; + } else if (!want && hidden) { + hos_log("first person: %d head materials shown again", fp_set_head_visible(c, components, 1, 1)); + hidden = 0; + logs = 0; + } +} + static void oot_update_player_cheats(Ctx *c, uint64_t actor, uint64_t components) { int rx_option(int id, int otherwise); static uint64_t flying_actor, marked_actor, marked_controller; @@ -1126,6 +1224,7 @@ static void oot_update_player_cheats(Ctx *c, uint64_t actor, uint64_t components hos_log("play: began at clock %lld ns, %.2f s after the process started", (long long)now, (double)(now - process_start_ns) / 1e9); } + oot_first_person_player(c, actor, components, now); if (marked_actor != actor || now - last_player_tick > 2000000000LL) marked_controller = 0; last_player_tick = now; int action = rx_option(HOS_OPT_CHEAT_ACTION, 0); @@ -1323,10 +1422,14 @@ void hos_oot_lift_player(Ctx *c, uint64_t actor) { } #if defined(_WIN32) || defined(__linux__) /* (the debug tools: host/posix has what they call) */ -static void oot_build_free_view(Ctx *c, uint64_t view, uint64_t out) { +/* first: the first-person view: the eye at Link's eyes, 0.35 m out along the way you look so his head, hair and hat stay + behind it, turned by the right stick from his facing; the free camera's flying is not used. The view is an eye, a yaw and a + pitch, as the free camera's, so another source of the look (a headset) can take their place. */ +static void oot_build_free_view(Ctx *c, uint64_t view, uint64_t out, int first) { int rx_option(int id, int otherwise); static uint64_t active_view; static int64_t last_tick; + static int was_first; static double eye[3], yaw, pitch; const int64_t now = hos_now_ns(); const int64_t elapsed = now - last_tick; @@ -1335,6 +1438,8 @@ static void oot_build_free_view(Ctx *c, uint64_t view, uint64_t out) { active_view = 0; return; } + if (first != was_first) active_view = 0, was_first = first; /* (switching between the two starts again) */ + if (first && !fp_link_known) return; if (active_view != view || elapsed > 500000000) { double target[3]; memcpy(eye, A64_PTR(view + 96), sizeof eye); @@ -1342,8 +1447,9 @@ static void oot_build_free_view(Ctx *c, uint64_t view, uint64_t out) { const double x = eye[0] - target[0], y = eye[1] - target[1], z = eye[2] - target[2]; yaw = atan2(x, z); pitch = atan2(y, hypot(x, z)); + if (first) yaw = fp_link_yaw + 3.14159265358979, pitch = 0; /* (the way Link faces: the view's z axis points back) */ active_view = view; - hos_log("cheats: free camera at %.2f %.2f %.2f", eye[0], eye[1], eye[2]); + hos_log("%s at %.2f %.2f %.2f", first ? "first person: view" : "cheats: free camera", eye[0], eye[1], eye[2]); } last_tick = now; DWORD foreground = 0; @@ -1356,11 +1462,16 @@ static void oot_build_free_view(Ctx *c, uint64_t view, uint64_t out) { if (control) { yaw -= 1.6 * dt * (int16_t)(input >> 32) / 32767.0; pitch -= 1.2 * dt * (int16_t)(input >> 48) / 32767.0; - pitch = fmax(-1.55, fmin(1.55, pitch)); + pitch = first ? fmax(-1.1, fmin(1.3, pitch)) : fmax(-1.55, fmin(1.55, pitch)); /* (first: not straight down at his feet) */ } const double sy = sin(yaw), cy = cos(yaw), sp = sin(pitch), cp = cos(pitch); const double axes[3][3] = {{cy, 0, -sy}, {-sp * sy, cp, -sp * cy}, {cp * sy, sp, cp * cy}}; - if (control) { + if (first) { + const double out_m = 0.35; + eye[0] = fp_link[0] - out_m * axes[2][0]; + eye[1] = fp_link[1] + fp_eye_height - out_m * axes[2][1]; + eye[2] = fp_link[2] - out_m * axes[2][2]; + } else if (control) { const double step = dt * (GetAsyncKeyState(VK_CONTROL) < 0 ? 30.0 : 8.0); const double right = (int16_t)input / 32767.0; const double forward = (int16_t)(input >> 16) / 32767.0; @@ -1393,7 +1504,8 @@ void hos_oot_free_view(Ctx *c, uint64_t view) { static SRWLOCK lock = SRWLOCK_INIT; AcquireSRWLockExclusive(&lock); const int enabled = rx_option(HOS_OPT_CHEAT_CAMERA, 0); - oot_build_free_view(c, enabled ? view : 0, view + 8); + const int first = !enabled && rx_option(HL_OPT_FIRST_PERSON, 0); /* (first person) */ + oot_build_free_view(c, enabled || first ? view : 0, view + 8, first); ReleaseSRWLockExclusive(&lock); #else (void)c; diff --git a/engine/host/nn_hid.c b/engine/host/nn_hid.c index 019bd1427..498771361 100644 --- a/engine/host/nn_hid.c +++ b/engine/host/nn_hid.c @@ -34,6 +34,7 @@ #include #include #include "../gpu/vk/vk_api.h" /* (the controls' names: HOS_SW_*, HOS_PAD_*) */ +#include "../gpu/vk/vk_opt_ids.h" /* (HL_OPT_FIRST_PERSON) */ #include "hos_motion.h" #include "hos_atomic_file.h" /* (the sensitivity is written whole or not at all) */ @@ -862,8 +863,12 @@ static void npad_states(Ctx *c) { int height = 0; const int menu_open = rx_option(1, 0); const int free_camera = rx_option(HOS_OPT_CHEAT_CAMERA, 0); + const int first_person = !free_camera && rx_option(HL_OPT_FIRST_PERSON, 0); const int flying = flight_jump_shortcut(&buttons, rx_option(HOS_OPT_CHEAT_FLIGHT, -1), menu_open, free_camera); - if (free_camera && !menu_open) { + if (first_person && !menu_open) { /* (first person: the right stick turns the view, host/hos_main.c; Link walks as ever) */ + for (int i = 0; i < 4; i++) axes |= (uint64_t)(uint16_t)stick[i] << (16 * i); + stick[2] = stick[3] = 0; + } else if (free_camera && !menu_open) { for (int i = 0; i < 4; i++) axes |= (uint64_t)(uint16_t)stick[i] << (16 * i); height = (int)(buttons >> B_R & 1) - (int)(buttons >> B_L & 1); memset(stick, 0, sizeof stick); diff --git a/engine/tests/test_input_background.py b/engine/tests/test_input_background.py index 1b0feb01b..4f1d6d2ab 100644 --- a/engine/tests/test_input_background.py +++ b/engine/tests/test_input_background.py @@ -62,6 +62,9 @@ def main(): constants = block(hid, "enum { B_A") + ";\n" + block(api, "enum { HOS_SW_A") + ";\n" constants += block(api, "enum { HOS_KEY_MOVE_UP") + ";\n" # (the keys-only controls) constants += block(api, "enum { HOS_OPT_CHEAT_HEARTS") + ";\n" + # (the option ids of rows that are HeyListen's alone, gpu/vk/vk_opt_ids.h: First person's, which the input reads) + ids = (ROOT / "gpu/vk/vk_opt_ids.h").read_text(encoding="utf-8") + constants += "".join(m + "\n" for m in re.findall(r"^#define HL_OPT_\w+\s+\d+", ids, re.M)) for name in ("STATE_SIZE", "NPAD_NO1", "ATTR_CONNECTED"): matches = re.findall(r"^#define " + name + r"\s+[^\n]+", hid, re.M) assert len(matches) == 1, name From 443e7dd3ae72d251ab416ed38e284219e0ca6629 Mon Sep 17 00:00:00 2001 From: ToxicToucan <75706815+ToxicToucan@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:39:24 -0500 Subject: [PATCH 03/10] feat(gameplay): first person eases the eye out while Link is in the air His jump pose leans the head forward and his hair flies up, past the first-person eye's 0.35 m: while his height changes faster than 2.5 m/s the eye eases out to 0.7 m (80 ms), and back after he lands (400 ms). Read from his height over time, so it needs no game state. Co-Authored-By: Claude Opus 5.5 --- engine/host/hos_main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/engine/host/hos_main.c b/engine/host/hos_main.c index 7bc7f6a19..c245911f4 100644 --- a/engine/host/hos_main.c +++ b/engine/host/hos_main.c @@ -1467,7 +1467,19 @@ static void oot_build_free_view(Ctx *c, uint64_t view, uint64_t out, int first) const double sy = sin(yaw), cy = cos(yaw), sp = sin(pitch), cp = cos(pitch); const double axes[3][3] = {{cy, 0, -sy}, {-sp * sy, cp, -sp * cy}, {cp * sy, sp, cp * cy}}; if (first) { - const double out_m = 0.35; + /* In the air (a leap off a ledge, a fall) his jump pose leans the head forward and his hair flies up past 0.35 m: while his + height changes faster than a walk on a slope does, the eye eases out to 0.7 m (80 ms), and back after he lands (400 ms). + Read from his height over time, so it needs no game state. */ + static double last_y, air; + static int air_told; + if (dt > 0) { + const double vy = (fp_link[1] - last_y) / dt; + const int in_air = fabs(vy) > 2.5; /* (m/s: walking and running on slopes stay well below) */ + air = in_air ? fmin(1.0, air + dt / 0.08) : fmax(0.0, air - dt / 0.4); + if (in_air && !air_told) air_told = 1, hos_log("first person: in the air (%.1f m/s up): the eye eased out", vy); + } + last_y = fp_link[1]; + const double out_m = 0.35 + 0.35 * air; eye[0] = fp_link[0] - out_m * axes[2][0]; eye[1] = fp_link[1] + fp_eye_height - out_m * axes[2][1]; eye[2] = fp_link[2] - out_m * axes[2][2]; From 43ffebbd70095525f585992c8d91b161d80c9c17 Mon Sep 17 00:00:00 2001 From: ToxicToucan <75706815+ToxicToucan@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:39:40 -0500 Subject: [PATCH 04/10] feat(gameplay): first person turns with the native mouse With the Mouse camera on Native, the player camera's hook (host/mouse_native.c) leaves the mouse's motion to the first-person view while it is on, still counting as run so the right stick is not given it too, and the view takes it one to one (hos_mouse_first_person: 0.1 degrees a count at the menu's sensitivity, Invert mouse vertical as ever). With the mouse as the right stick, and with the camera keys, the view already turned: they are the right stick. Co-Authored-By: Claude Opus 5.5 --- engine/host/hos_main.c | 5 +++++ engine/host/mouse_native.c | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/engine/host/hos_main.c b/engine/host/hos_main.c index c245911f4..ae78bfc92 100644 --- a/engine/host/hos_main.c +++ b/engine/host/hos_main.c @@ -1462,6 +1462,11 @@ static void oot_build_free_view(Ctx *c, uint64_t view, uint64_t out, int first) if (control) { yaw -= 1.6 * dt * (int16_t)(input >> 32) / 32767.0; pitch -= 1.2 * dt * (int16_t)(input >> 48) / 32767.0; + if (first) { /* the native mouse, one to one (host/mouse_native.c); as the right stick it came in above */ + int hos_mouse_first_person(double *yaw, double *pitch); + double my, mp; + if (hos_mouse_first_person(&my, &mp)) yaw += my, pitch += mp; + } pitch = first ? fmax(-1.1, fmin(1.3, pitch)) : fmax(-1.55, fmin(1.55, pitch)); /* (first: not straight down at his feet) */ } const double sy = sin(yaw), cy = cos(yaw), sp = sin(pitch), cp = cos(pitch); diff --git a/engine/host/mouse_native.c b/engine/host/mouse_native.c index cb7d1602e..469689f9e 100644 --- a/engine/host/mouse_native.c +++ b/engine/host/mouse_native.c @@ -22,6 +22,8 @@ The sensitivity is the mouse's (the menu's Mouse sensitivity, - and =): 0.1 degrees a count at 1. HOS_MOUSE_INVERT_Y=1 or the menu's Invert mouse vertical flips up and down. */ #include "hos.h" +#include "../gpu/vk/vk_api.h" /* (HOS_OPT_CHEAT_CAMERA) */ +#include "../gpu/vk/vk_opt_ids.h" /* (HL_OPT_FIRST_PERSON) */ #include #include #include @@ -69,6 +71,12 @@ static int looks_like_camera(uint64_t cam) { /* f_80644c80's first line (nx2/oot_patches.py): cam is the player camera, the game's thread */ void hos_mouse_camera(uint64_t cam) { if (!cam || !native_on() || !looks_like_camera(cam)) return; + /* First person: the view is ours (host/hos_main.c oot_build_free_view), so the mouse's motion is left for it to + take; the hook still counts as run, so the right stick is not given the motion either */ + if (rx_option(HL_OPT_FIRST_PERSON, 0) && !rx_option(HOS_OPT_CHEAT_CAMERA, 0)) { + InterlockedExchange64(&last_hook_ns, hos_now_ns()); + return; + } /* Only while it is the view: following Link (3) or turned by the player (4). Aiming the slingshot in first person leaves this camera updating with its state 0 while another one draws (traced at Hyrule Castle); shops are reported the same. In any other state the mouse is the right stick, which those views turn by (the hook counts as not @@ -107,6 +115,21 @@ void hos_mouse_camera(uint64_t cam) { hos_log("mouse native: %lld moves applied; pitch %.2f yaw %.2f", applied, p, y); } +/* First person's share of the native mouse (host/hos_main.c, once a frame of the view): the motion since the last + frame as a turn in radians, yaw falling as the view turns right and pitch rising as it tilts down, at the menu's + sensitivity and Invert mouse vertical. 0 when the native mouse is off or not captured (then the mouse is the right + stick, which turns the view too). */ +int hos_mouse_first_person(double *yaw, double *pitch) { + *yaw = *pitch = 0; + if (!native_on()) return 0; + int32_t dx, dy; + if (!hos_mouse_take(&dx, &dy)) return 0; + const double k = DEG_PER_COUNT * hos_mouse_sens * 3.14159265358979 / 180.0; + *yaw = -dx * k; + *pitch = (invert_y() ? -dy : dy) * k; + return 1; +} + /* With each read of the controller (nn_hid.c, the game's threads): 0 if the mouse is not captured, 1 if the camera takes its motion (hos_mouse_camera), -1 if no player camera runs now (the right stick takes it) */ int hos_mouse_native(void) { From 852d7c5d385ed6e3862d94c03f86f2f7c956fd6b Mon Sep 17 00:00:00 2001 From: ToxicToucan <75706815+ToxicToucan@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:39:48 -0500 Subject: [PATCH 05/10] feat(gameplay): first person always takes the mouse one to one While first person is on, the mouse goes the native way whatever the Mouse camera row says (host/nn_hid.c and host/mouse_native.c native_on), so the view turns by the mouse's counts, not by a stick made of them; the right stick and the camera keys still turn it as before. Co-Authored-By: Claude Opus 5.5 --- engine/host/mouse_native.c | 2 ++ engine/host/nn_hid.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/engine/host/mouse_native.c b/engine/host/mouse_native.c index 469689f9e..338382df5 100644 --- a/engine/host/mouse_native.c +++ b/engine/host/mouse_native.c @@ -52,6 +52,8 @@ static int native_on(void) { static const char *env; static int looked; if (!looked) looked = 1, env = getenv("HOS_MOUSE_NATIVE"); + /* first person always takes the mouse one to one, whatever the Mouse camera row says */ + if (rx_option(HL_OPT_FIRST_PERSON, 0) && !rx_option(HOS_OPT_CHEAT_CAMERA, 0)) return 1; return env ? atoi(env) != 0 : rx_option(6, 0); } diff --git a/engine/host/nn_hid.c b/engine/host/nn_hid.c index 498771361..c9b294a45 100644 --- a/engine/host/nn_hid.c +++ b/engine/host/nn_hid.c @@ -802,7 +802,9 @@ static void read_input(uint64_t *buttons, int32_t stick[4]) { static const char *native_env; static int native_looked; if (!native_looked) native_looked = 1, native_env = getenv("HOS_MOUSE_NATIVE"); - const int native = native_env ? atoi(native_env) != 0 : rx_option(6, 0); + /* first person: always the native path, the view taking the mouse one to one (host/mouse_native.c) */ + const int native = (rx_option(HL_OPT_FIRST_PERSON, 0) && !rx_option(HOS_OPT_CHEAT_CAMERA, 0)) || + (native_env ? atoi(native_env) != 0 : rx_option(6, 0)); int hos_mouse_native(void); int captured = 0, as_stick = !native; if (native) { From b2d855f44b2619955b6e422972c269938e917ac2 Mon Sep 17 00:00:00 2001 From: ToxicToucan <75706815+ToxicToucan@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:40:05 -0500 Subject: [PATCH 06/10] feat(gameplay): first person's near plane at 5 cm nx2/oot_near.py hooks the camera update after it loads its near distance (main+0x4c52d4, ldr s0, [x19, #0x134]; its three words checked), and host/hos_main.c hos_oot_near lowers that load to 5 cm at most (the game's is 10 cm) on the gameplay camera while first person is on and no event plays, so what is just in front of the eye is not cut off. The camera's own field is never written. Co-Authored-By: Claude Opus 5.5 --- engine/host/hos_main.c | 27 +++++++++++++++++++++++++++ engine/nx2/lift.py | 2 ++ engine/nx2/oot_near.py | 23 +++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 engine/nx2/oot_near.py diff --git a/engine/host/hos_main.c b/engine/host/hos_main.c index ae78bfc92..3bdeeb084 100644 --- a/engine/host/hos_main.c +++ b/engine/host/hos_main.c @@ -1530,6 +1530,33 @@ void hos_oot_free_view(Ctx *c, uint64_t view) { #endif } +/* (nx2/oot_near.py) After the camera update loads its near distance (s0): while first person is on, the gameplay + camera's near plane at 5 cm at most, so his hands and what they hold are not cut off in front of the eye. Events keep the + game's; the camera's own field is never written. */ +void hos_oot_near(Ctx *c, uint64_t camera) { +#if defined(_WIN32) || defined(__linux__) + int rx_option(int id, int otherwise); + if (!camera || !rx_option(HL_OPT_FIRST_PERSON, 0) || rx_option(HOS_OPT_CHEAT_CAMERA, 0)) return; + const uint64_t views = recomp_load64(c, camera + 0x18); + const uint64_t view = views ? recomp_load64(c, views + 8) : 0; + if (!view || view != oot_gameplay_view(c)) return; + const uint64_t events = oot_singleton(c, OOT_EVENTMGR_SLOT); + if (events && recomp_load64(c, events + 104)) return; + float near_m; + memcpy(&near_m, c->vreg[0], sizeof near_m); + if (!isfinite(near_m) || near_m <= 0.05f) return; + static int told; + if (!told) told = 1, hos_log("first person: near plane %.3f -> 0.050 m", near_m); + const float want = 0.05f; + uint32_t bits; + memcpy(&bits, &want, sizeof bits); + a64_vset64(c->vreg[0], bits); +#else + (void)c; + (void)camera; +#endif +} + float hos_aspect_ratio = 0; /* (the window's default shape: host/display.c) */ /* (nx2/oot_wide.py) read by the widescreen patches in the game's code; 0: the game's own 16:9 */ volatile uint64_t hos_wide_out, hos_wide_scene; diff --git a/engine/nx2/lift.py b/engine/nx2/lift.py index 32237286a..a64c21581 100644 --- a/engine/nx2/lift.py +++ b/engine/nx2/lift.py @@ -167,6 +167,8 @@ def main(): oot_occlusion.install(L, img) import oot_view # (fork: the gameplay view's hook, which oot_patches.py's patch_view no longer finds; host/hos_main.c) oot_view.install(L, img) + import oot_near # (first person's near plane, host/hos_main.c hos_oot_near) + oot_near.install(L, img) L.discover(max_insns=a.max_func) print("discovered %d functions (%.0fs)" % (len(L.funcs), time.time() - t0)) total = coverage(L, img, img_dir) diff --git a/engine/nx2/oot_near.py b/engine/nx2/oot_near.py new file mode 100644 index 000000000..6f1938803 --- /dev/null +++ b/engine/nx2/oot_near.py @@ -0,0 +1,23 @@ +"""First person's near plane (OoT 1.1.1): the gameplay camera's near distance, lowered while first person is on. + +The camera update (the projection's build) loads the near distance from the camera at +0x134 +into s0 and stores it to sead's perspective projection (+0x98). The hook after that load (host/hos_main.c hos_oot_near) +changes s0 only, never the camera's own field, so the next update starts from the game's value again. +""" + +MAIN = 0x80020000 +SITE = MAIN + 0x4c52d4 +# ldr s0, [x19, #0x134]; mov w21, #1; fmov s1, #0.5 +WORDS = (0xbd413660, 0x52800035, 0x1e2c1001) +HOOK = ("{ extern void hos_oot_near(Ctx *c, uint64_t camera); hos_oot_near(c, c->x[19]); }" + " /* (nx2/oot_near.py: first person's near plane) */") + + +def install(lifter, img): + """The site into lifter.after, after what is there; left out when its words differ (another game version)""" + if any(img.word(SITE + 4 * i) != word for i, word in enumerate(WORDS)): + print("near plane: unsupported camera code, left out") + return 0 + lifter.after[SITE] = (lifter.after[SITE] + "\n" if SITE in lifter.after else "") + HOOK + print("near plane: gameplay camera hooked") + return 1 From 18dd5aaf131c123280d121129cfbdff81a03d48b Mon Sep 17 00:00:00 2001 From: ToxicToucan <75706815+ToxicToucan@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:01:31 -0500 Subject: [PATCH 07/10] fix(gameplay): first person shows the game's view until the head is hidden again Turned on, or back from the free camera, the first-person view took over at once while the head was hidden only at the player's next update: one frame showed the cap from inside (a one-frame flash at the free camera's end, dev-fp2 present 6648). The view now waits for that update (fp_head_ready), showing the game's own view meanwhile. Co-Authored-By: Claude Opus 5.5 --- engine/host/hos_main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/engine/host/hos_main.c b/engine/host/hos_main.c index 3bdeeb084..90c7e1518 100644 --- a/engine/host/hos_main.c +++ b/engine/host/hos_main.c @@ -1124,6 +1124,7 @@ static int64_t process_start_ns; /* (hos_now_ns when main began) */ at the first hide). */ static volatile float fp_link[3], fp_link_yaw, fp_eye_height = 1.15f; static volatile int fp_link_known; +static volatile int fp_head_ready; /* (the head hidden in this stretch of first person: the view waits for it) */ static const char *const kHeadMaterials[] = {"Mt_Face", "Mt_Face_Eyelid", "Mt_Face_SoftEdge", "Mt_Eye_Inner", "Mt_Eye_Outer", "Mt_Eyebrow", "Mt_Eyelashes", "Mt_Eyelashes_01", "Mt_Eyelashes_02", "Mt_Eyelashes_03", "Mt_Eyeshadow", "Mt_EyeShadow_test", @@ -1188,6 +1189,7 @@ static void oot_first_person_player(Ctx *c, uint64_t actor, uint64_t components, static int hidden, logs; static int64_t hidden_at, age_at; const int want = rx_option(HL_OPT_FIRST_PERSON, 0) && !rx_option(HOS_OPT_CHEAT_CAMERA, 0); + if (!want) fp_head_ready = 0; for (unsigned i = 0; i < 3; i++) fp_link[i] = oot_load_float(c, actor + 796 + i * 4); fp_link_yaw = atan2f(oot_load_float(c, actor + 816), oot_load_float(c, actor + 840)); fp_link_known = 1; @@ -1201,6 +1203,7 @@ static void oot_first_person_player(Ctx *c, uint64_t actor, uint64_t components, const int n = fp_set_head_visible(c, components, 0, logs < 2); if (logs < 2) logs++, hos_log("first person: %d head materials hidden", n); hidden = 1; + fp_head_ready = 1; hidden_at = now; } else if (!want && hidden) { hos_log("first person: %d head materials shown again", fp_set_head_visible(c, components, 1, 1)); @@ -1439,7 +1442,9 @@ static void oot_build_free_view(Ctx *c, uint64_t view, uint64_t out, int first) return; } if (first != was_first) active_view = 0, was_first = first; /* (switching between the two starts again) */ - if (first && !fp_link_known) return; + /* (first person turned on, or back from the free camera: the game's own view until the player's update has hidden the head + again, so not one frame shows it from inside) */ + if (first && (!fp_link_known || !fp_head_ready)) return; if (active_view != view || elapsed > 500000000) { double target[3]; memcpy(eye, A64_PTR(view + 96), sizeof eye); From f936d1bcd6cacc378f0c786fa7456d8f146baa5f Mon Sep 17 00:00:00 2001 From: ToxicToucan <75706815+ToxicToucan@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:02:02 -0500 Subject: [PATCH 08/10] feat(gameplay): first person scales Link's head bone to 0, so his body and what he holds come into view While first person is on, every player update sets the Head bone's local scale to 0 on each of his models, through the model's own calls: vtable +0x48 names a bone by index (the skeleton's resource dictionary), +0x60 (model, &scale, index; main+0x3596360) sets its local scale, as the animation does. The hat is part of the tunic's mesh (Head_Band__Mt_Cloth, 90 skin bones) and every shape hangs from bone 0, so only the skinning can take it with the head: the head, hair and hat go together. The eye then sits 0.10 m out instead of 0.35 m (HL_FP_EYE_OUT), so looking down shows his arms, his hands and what they hold. HL_FP_HEAD_BONE=0 leaves the bone alone (the materials are hidden as before). Checked in one run (Market, first person on, with the flash and speed checks): the Head bone found (103 of 309) and scaled every update; looking ahead nothing of the head or hat in view; looking down his arm, hand and Deku Shield in view. Co-Authored-By: Claude Opus 5.5 --- engine/host/hos_main.c | 74 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/engine/host/hos_main.c b/engine/host/hos_main.c index 90c7e1518..1c6ff4f8e 100644 --- a/engine/host/hos_main.c +++ b/engine/host/hos_main.c @@ -1125,6 +1125,7 @@ static int64_t process_start_ns; /* (hos_now_ns when main began) */ static volatile float fp_link[3], fp_link_yaw, fp_eye_height = 1.15f; static volatile int fp_link_known; static volatile int fp_head_ready; /* (the head hidden in this stretch of first person: the view waits for it) */ +static volatile int fp_head_scaled; /* (the head bone is at scale 0 now: the eye can sit at his eyes) */ static const char *const kHeadMaterials[] = {"Mt_Face", "Mt_Face_Eyelid", "Mt_Face_SoftEdge", "Mt_Eye_Inner", "Mt_Eye_Outer", "Mt_Eyebrow", "Mt_Eyelashes", "Mt_Eyelashes_01", "Mt_Eyelashes_02", "Mt_Eyelashes_03", "Mt_Eyeshadow", "Mt_EyeShadow_test", @@ -1184,9 +1185,72 @@ static int fp_set_head_visible(Ctx *c, uint64_t components, int visible, int log return set; } +/* Link's head through its bone: its local scale 0 while first person is on, so the head, hair and hat (the hat is + the tunic's mesh, skinned to the head's bones) go with it, and the eye can sit at his eyes. + The model's skeleton is nn::g3d's (model +0xf8): its local matrices at [skel+0x18], 0x60 bytes a bone (flags, scale at + +0x10, the 3x4 matrix at +0x20), the resource's bone dictionary at [[skel]+8] (a count at +4, a bone's name at + [dict + 0x20 + 16 * index] + 2). The model's vtable +0x48 gives a bone's name by index and +0x60 (model, &scale, + index) sets its local scale (main+0x3596360: it clears the bone's identity flags and marks the skeleton dirty), as the + game's own animation does. The animation writes the bones every frame, so this runs every player update. + HL_FP_HEAD_BONE=0 leaves the bone alone (the materials are hidden as before). */ +static int fp_head_bone(Ctx *c, uint64_t components, int log) { + static int env = -1; + if (env < 0) { + const char *e = getenv("HL_FP_HEAD_BONE"); + env = e ? atoi(e) != 0 : 1; + } + if (!env) return 0; + const uint64_t comp = recomp_load64(c, components + 8); + if (!comp || !fp_in_main(recomp_load64(c, comp))) return 0; + const uint64_t getter = recomp_load64(c, recomp_load64(c, comp) + 248); + const uint64_t scratch = (c->x[31] - 256) & ~15ULL; + uint64_t holder = 0; + if (getter == recomp_load64(c, 0x84cd9d58ULL)) holder = recomp_load64(c, comp + 24); + else if (!fp_guest_call(c, getter, scratch - 16, comp, 0, 0, &holder)) return 0; + const uint64_t slots = holder ? recomp_load64(c, holder + 40) : 0; + if (!slots) return 0; + recomp_store32_sp(c, scratch, 0), recomp_store32_sp(c, scratch + 4, 0), recomp_store32_sp(c, scratch + 8, 0); + int set = 0; + uint64_t done[16]; + int ndone = 0; + for (int i = 0; i < 16; i++) { + const uint64_t slot = recomp_load64(c, slots + i * 8); + const uint64_t model = slot ? recomp_load64(c, slot) : 0; + if (!model) break; + const uint64_t vt = recomp_load64(c, model); + if (!fp_in_main(vt)) break; + int seen = 0; + for (int k = 0; k < ndone; k++) seen |= done[k] == model; + if (seen) continue; + done[ndone++] = model; + const uint64_t skel = recomp_load64(c, model + 0xf8); + const uint64_t res = skel ? recomp_load64(c, skel) : 0; + const uint64_t dict = res ? recomp_load64(c, res + 8) : 0; + if (!dict) continue; + const uint32_t count = recomp_load32(c, dict + 4); + int head = -1; + for (uint32_t b = 0; b < count && b < 1024; b++) { + const uint64_t key = recomp_load64(c, dict + 0x20 + 16 * (uint64_t)b); + if (key && !strcmp((const char *)A64_PTR(key + 2), "Head")) { head = (int)b; break; } + } + if (log) hos_log("first person: model %d: %u bones, Head %d", i, count, head); + if (head < 0) continue; + fp_guest_call(c, recomp_load64(c, vt + 0x60), scratch - 16, model, scratch, (uint64_t)head, NULL); + set++; + } + return set; +} + static void oot_first_person_player(Ctx *c, uint64_t actor, uint64_t components, int64_t now) { int rx_option(int id, int otherwise); - static int hidden, logs; + static int hidden, logs, bone_logs; + if (rx_option(HL_OPT_FIRST_PERSON, 0) && !rx_option(HOS_OPT_CHEAT_CAMERA, 0)) { + const int n = fp_head_bone(c, components, bone_logs < 2); + if (bone_logs < 2) bone_logs++, hos_log("first person: the head bone scaled to 0 on %d models", n); + fp_head_scaled = n > 0; + } else { + fp_head_scaled = 0; + } static int64_t hidden_at, age_at; const int want = rx_option(HL_OPT_FIRST_PERSON, 0) && !rx_option(HOS_OPT_CHEAT_CAMERA, 0); if (!want) fp_head_ready = 0; @@ -1489,7 +1553,13 @@ static void oot_build_free_view(Ctx *c, uint64_t view, uint64_t out, int first) if (in_air && !air_told) air_told = 1, hos_log("first person: in the air (%.1f m/s up): the eye eased out", vy); } last_y = fp_link[1]; - const double out_m = 0.35 + 0.35 * air; + /* (with the head bone at scale 0 nothing of his head is left in front of the eye: HL_FP_EYE_OUT metres, 0.10 if unset) */ + static double head_out = -1; + if (head_out < 0) { + const char *e = getenv("HL_FP_EYE_OUT"); + head_out = e ? atof(e) : 0.10; + } + const double out_m = fp_head_scaled ? head_out : 0.35 + 0.35 * air; eye[0] = fp_link[0] - out_m * axes[2][0]; eye[1] = fp_link[1] + fp_eye_height - out_m * axes[2][1]; eye[2] = fp_link[2] - out_m * axes[2][2]; From 2155880c0450de283c862d0bbfa68901d718f836 Mon Sep 17 00:00:00 2001 From: ToxicToucan <75706815+ToxicToucan@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:47:39 -0500 Subject: [PATCH 09/10] fix(mouse): native mouse look reads the first-person rows by number, without the renderer's headers host/mouse_native.c included gpu/vk/vk_api.h and vk_opt_ids.h for two option ids. The mouse test compiles the file alone in a temp folder, where those headers are not, so it failed on Linux ("../gpu/vk/vk_api.h: No such file or directory"). The file now names the two ids by number, as it already does the Mouse camera (6) and Invert mouse vertical (8), and the test checks them against the renderer's headers. Co-Authored-By: Claude Opus 5.5 --- engine/host/mouse_native.c | 10 ++++++---- engine/tests/test_mouse_native.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/engine/host/mouse_native.c b/engine/host/mouse_native.c index 338382df5..8d7b113bb 100644 --- a/engine/host/mouse_native.c +++ b/engine/host/mouse_native.c @@ -22,8 +22,6 @@ The sensitivity is the mouse's (the menu's Mouse sensitivity, - and =): 0.1 degrees a count at 1. HOS_MOUSE_INVERT_Y=1 or the menu's Invert mouse vertical flips up and down. */ #include "hos.h" -#include "../gpu/vk/vk_api.h" /* (HOS_OPT_CHEAT_CAMERA) */ -#include "../gpu/vk/vk_opt_ids.h" /* (HL_OPT_FIRST_PERSON) */ #include #include #include @@ -36,6 +34,10 @@ void hos_mouse_give_back(int32_t dx, int32_t dy); int rx_option(int id, int otherwise); extern double hos_mouse_sens; +/* The renderer's option ids this file reads, by number as 6 and 8 are (the gpu headers stay out of the host's own files; + tests/test_mouse_native.py checks them against gpu/vk/vk_opt_ids.h and gpu/vk/vk_api.h) */ +enum { OPT_FIRST_PERSON = 91 /* HL_OPT_FIRST_PERSON */, OPT_CHEAT_CAMERA = 35 /* HOS_OPT_CHEAT_CAMERA */ }; + enum { LIMITS_AT = 0x178, PITCH_AT = 0x18c, YAW_AT = 0x1a4, STATE_AT = 0x204 }; #define LIVE_NS 150000000LL /* (the hook ran this recently: the camera takes the mouse) */ #define DEG_PER_COUNT 0.1 @@ -53,7 +55,7 @@ static int native_on(void) { static int looked; if (!looked) looked = 1, env = getenv("HOS_MOUSE_NATIVE"); /* first person always takes the mouse one to one, whatever the Mouse camera row says */ - if (rx_option(HL_OPT_FIRST_PERSON, 0) && !rx_option(HOS_OPT_CHEAT_CAMERA, 0)) return 1; + if (rx_option(OPT_FIRST_PERSON, 0) && !rx_option(OPT_CHEAT_CAMERA, 0)) return 1; return env ? atoi(env) != 0 : rx_option(6, 0); } @@ -75,7 +77,7 @@ void hos_mouse_camera(uint64_t cam) { if (!cam || !native_on() || !looks_like_camera(cam)) return; /* First person: the view is ours (host/hos_main.c oot_build_free_view), so the mouse's motion is left for it to take; the hook still counts as run, so the right stick is not given the motion either */ - if (rx_option(HL_OPT_FIRST_PERSON, 0) && !rx_option(HOS_OPT_CHEAT_CAMERA, 0)) { + if (rx_option(OPT_FIRST_PERSON, 0) && !rx_option(OPT_CHEAT_CAMERA, 0)) { InterlockedExchange64(&last_hook_ns, hos_now_ns()); return; } diff --git a/engine/tests/test_mouse_native.py b/engine/tests/test_mouse_native.py index adfd188d6..107a710da 100644 --- a/engine/tests/test_mouse_native.py +++ b/engine/tests/test_mouse_native.py @@ -11,6 +11,7 @@ camera draws, and the motion is then the stick's. python -I -B tests/test_mouse_native.py (Linux: host/posix's windows.h) """ +import re import shutil import subprocess import sys @@ -125,6 +126,18 @@ class MouseNativeTests(unittest.TestCase): + def test_option_ids_match_the_renderer(self): + """mouse_native.c reads the first-person and free-camera rows by number: the renderer's ids""" + src = (ROOT / "host" / "mouse_native.c").read_text(encoding="utf-8") + ids = (ROOT / "gpu" / "vk" / "vk_opt_ids.h").read_text(encoding="utf-8") + api = (ROOT / "gpu" / "vk" / "vk_api.h").read_text(encoding="utf-8") + first = int(re.search(r"OPT_FIRST_PERSON = (\d+)", src).group(1)) + camera = int(re.search(r"OPT_CHEAT_CAMERA = (\d+)", src).group(1)) + self.assertEqual(first, int(re.search(r"#define HL_OPT_FIRST_PERSON (\d+)", ids).group(1))) + cheats = re.search(r"enum \{ HOS_OPT_CHEAT_HEARTS = (\d+),([^}]*)\}", api) + names = [n.strip() for n in cheats.group(2).split(",")] + self.assertEqual(camera, int(cheats.group(1)) + 1 + names.index("HOS_OPT_CHEAT_CAMERA")) + def test_turns_the_player_camera(self): if sys.platform == "win32": self.skipTest("host/posix's windows.h stands in for Windows here") From 2798374c27a5b6043c70d792f6a06120f9b034c9 Mon Sep 17 00:00:00 2001 From: ToxicToucan <75706815+ToxicToucan@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:44:43 -0500 Subject: [PATCH 10/10] feat(gameplay): first person keeps Navi out of the eye She hovers by Link's head, so in first person her glowing body and wings filled the view. Here she is a second actor of Link's own class beside him, whose models carry Mt_Wings (Link's own models have none). She is found from Link's own pointers (his actor and components, one step further), each candidate checked before anything is called on it: in the heap, a vtable in main, a model component of Link's class, within 5 m of Link, then a look-up-only query for Mt_Wings. While first person is on, her materials (Mt_Body, Mt_Body_AlphaMask, Mt_Wings) are hidden on that actor's winged models only; shown again when it is off. A lost actor (a scene load) is looked for again. Her small light glow stays. The head's material code becomes one function for any list of names (fp_set_materials_on, with an optional "only models with this material" filter). Checked in game (Windows, Market save): with the hide toggled every 5 s in third person, screenshots alternate between Navi drawn and only her glow left; Link is unchanged; no frame-rate change against the same run without it. Co-Authored-By: Claude Opus 5.5 --- engine/host/hos_main.c | 120 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 6 deletions(-) diff --git a/engine/host/hos_main.c b/engine/host/hos_main.c index 34881a7e0..2b8b1379b 100644 --- a/engine/host/hos_main.c +++ b/engine/host/hos_main.c @@ -1165,8 +1165,17 @@ static int fp_guest_call(Ctx *c, uint64_t fn, uint64_t sp, uint64_t a0, uint64_t return 1; } -/* Shows or hides the head materials on each of the actor's models; how many were set */ -static int fp_set_head_visible(Ctx *c, uint64_t components, int visible, int log) { +/* Shows or hides the named materials on each of an actor's models; how many were set (visible < 0: only looked up, how many + are there) */ +static int fp_set_materials_on(Ctx *c, uint64_t components, const char *const *names, unsigned count, int visible, int log, + const char *what, const char *only_with); +static int fp_set_materials(Ctx *c, uint64_t components, const char *const *names, unsigned count, int visible, int log, + const char *what) { + return fp_set_materials_on(c, components, names, count, visible, log, what, NULL); +} +/* (only_with: only the models that have a material of that name; NULL every model) */ +static int fp_set_materials_on(Ctx *c, uint64_t components, const char *const *names, unsigned count, int visible, int log, + const char *what, const char *only_with) { const uint64_t comp = recomp_load64(c, components + 8); if (!comp || !fp_in_main(recomp_load64(c, comp))) return 0; const uint64_t getter = recomp_load64(c, recomp_load64(c, comp) + 248); @@ -1183,25 +1192,123 @@ static int fp_set_head_visible(Ctx *c, uint64_t components, int visible, int log if (!model) break; const uint64_t vt = recomp_load64(c, model); if (!fp_in_main(vt)) break; + if (only_with) { /* (the model counts only if it has that material) */ + const size_t len = strlen(only_with); + for (size_t k = 0; k <= len; k++) recomp_store8_sp(c, scratch + 16 + k, (uint8_t)only_with[k]); + recomp_store64_sp(c, scratch, scratch + 16); + uint64_t index = ~0ULL; + const int has = fp_guest_call(c, recomp_load64(c, vt + 208), scratch - 16, model, scratch, 0, &index) && + !(index & 0x80000000u); + if (log) hos_log("first person: model %d (vtable %#llx): %s %s", i, (unsigned long long)vt, has ? "has" : "has no", only_with); + if (!has) continue; + } int found = 0; - for (unsigned n = 0; n < sizeof kHeadMaterials / sizeof kHeadMaterials[0]; n++) { - const char *name = kHeadMaterials[n]; + for (unsigned n = 0; n < count; n++) { + const char *name = names[n]; const size_t len = strlen(name); for (size_t k = 0; k <= len; k++) recomp_store8_sp(c, scratch + 16 + k, (uint8_t)name[k]); recomp_store64_sp(c, scratch, scratch + 16); uint64_t index = ~0ULL; if (!fp_guest_call(c, recomp_load64(c, vt + 208), scratch - 16, model, scratch, 0, &index) || (index & 0x80000000u)) continue; - fp_guest_call(c, recomp_load64(c, vt + 456), scratch - 16, model, (uint32_t)index, visible ? 1 : 0, NULL); + if (visible >= 0) + fp_guest_call(c, recomp_load64(c, vt + 456), scratch - 16, model, (uint32_t)index, visible ? 1 : 0, NULL); found++; } if (log) - hos_log("first person: model %d (vtable %#llx): %d head materials %s", i, (unsigned long long)vt, found, + hos_log("first person: model %d (vtable %#llx): %d %s materials %s", i, (unsigned long long)vt, found, what, visible ? "shown" : "hidden"); set += found; } return set; } +static int fp_set_head_visible(Ctx *c, uint64_t components, int visible, int log) { + return fp_set_materials(c, components, kHeadMaterials, sizeof kHeadMaterials / sizeof kHeadMaterials[0], visible, log, + "head"); +} + +static const char *const kNaviMaterials[] = {"Mt_Body", "Mt_Body_AlphaMask", "Mt_Wings"}; +/* Navi, kept out of the eye: she hovers by Link's head, so in first person her glowing body and wings filled the view. Here + she is a second actor of Link's own class (the same vtable), beside him, whose models carry her wings (Link's own models + have no Mt_Wings). The movement update runs for Link only, so she is looked for from him (fp_navi_search): the 8-byte + words of his actor (0x2000 bytes) and components (0x400), and one step further from each object found there, are taken + as pointers. An object counts only if it is in the heap, starts with a vtable in main, has components (+624) whose model + component (+8) is of the class Link's is (the same getter at its vtable +248: no other code is called on a guess), and + stands within 5 m of Link (+796); then its models are asked, look-up only, for a material named Mt_Wings. The first + such object is hers. While first person is on, her materials (Mt_Body, Mt_Body_AlphaMask, Mt_Wings) are hidden on that + actor's models that have Mt_Wings, and nowhere else; her place is not known, so she is hidden all the time in first + person, not only near the eye, and shown again when it is off. Her light (a small glow) stays. */ +static const char *const kNaviWings[] = {"Mt_Wings"}; +static volatile uint64_t fp_navi_vt, fp_navi_found; +extern uint64_t hos_heap_size; +static int fp_heap_ptr(uint64_t a) { return !(a & 7) && a >= HOS_HEAP_BASE && a + 0x1000 < HOS_HEAP_BASE + hos_heap_size; } +static int fp_navi_try(Ctx *c, uint64_t obj, uint64_t link, uint64_t getter, int *logged) { + if (obj == link || !fp_heap_ptr(obj) || !fp_in_main(recomp_load64(c, obj))) return 0; /* (Link himself: not her) */ + const uint64_t comps = recomp_load64(c, obj + 624); + if (!fp_heap_ptr(comps)) return 0; + const uint64_t comp = recomp_load64(c, comps + 8); + if (!fp_heap_ptr(comp) || !fp_in_main(recomp_load64(c, comp)) || recomp_load64(c, recomp_load64(c, comp) + 248) != getter) + return 0; + float l2 = 0; + for (unsigned i = 0; i < 3; i++) { + const float d = oot_load_float(c, obj + 796 + i * 4) - fp_link[i]; + l2 += d * d; + } + if (!(l2 < 25.0f)) return 0; + const int wings = fp_set_materials(c, comps, kNaviWings, 1, -1, 0, "Navi"); + if (*logged < 24) + (*logged)++, hos_log("first person: Navi search: object %#llx (vtable %#llx) %.2f m from Link, wings %d", (unsigned long long)obj, + (unsigned long long)recomp_load64(c, obj), sqrtf(l2), wings); + if (wings <= 0) return 0; + fp_navi_vt = recomp_load64(c, obj), fp_navi_found = obj; + hos_log("first person: Navi is %#llx (vtable %#llx)", (unsigned long long)obj, (unsigned long long)fp_navi_vt); + return 1; +} +static void fp_navi_search(Ctx *c, uint64_t link, uint64_t components) { + const uint64_t lcomp = recomp_load64(c, components + 8); + if (!fp_heap_ptr(lcomp)) return; + const uint64_t getter = recomp_load64(c, recomp_load64(c, lcomp) + 248); + static uint64_t first[1280]; + int n = 0, logged = 0, tried = 0; + const uint64_t roots[2][2] = {{link, 0x2000}, {components, 0x400}}; + for (int r = 0; r < 2; r++) + for (uint64_t off = 0; off < roots[r][1]; off += 8) { + const uint64_t p = recomp_load64(c, roots[r][0] + off); + if (!fp_heap_ptr(p)) continue; + tried++; + if (fp_navi_try(c, p, link, getter, &logged)) return; + if (n < 1280) first[n++] = p; + } + for (int i = 0; i < n; i++) /* (one step further: 0x400 bytes of each) */ + for (uint64_t off = 0; off < 0x400; off += 8) { + const uint64_t p = recomp_load64(c, first[i] + off); + if (!fp_heap_ptr(p)) continue; + tried++; + if (fp_navi_try(c, p, link, getter, &logged)) return; + } + hos_log("first person: Navi search: not found (%d pointers, %d objects one step on, %d with a model near Link)", tried, n, logged); +} +static void fp_navi(Ctx *c, uint64_t link, uint64_t components, int want, int64_t now) { + static int hidden, logs, searches; + static int64_t at, searched_at; + if (!want) searches = 0; /* (a new stretch of first person looks again) */ + if (fp_navi_found && (recomp_load64(c, fp_navi_found) != fp_navi_vt || !fp_heap_ptr(recomp_load64(c, fp_navi_found + 624)))) + fp_navi_found = 0, searches = 0, hidden = 0; /* (gone with a scene load: looked for again) */ + if (want && !fp_navi_found && searches < 5 && now - searched_at > 2000000000LL) + searched_at = now, searches++, fp_navi_search(c, link, components); + const uint64_t navi = fp_navi_found; + if (!navi) return; + if (!want && !hidden) return; + if (want && hidden && now - at < 500000000LL) return; /* (again every half second while on: new models after a load) */ + const uint64_t comps = recomp_load64(c, navi + 624); + if (!fp_heap_ptr(comps)) return; + const int n = fp_set_materials_on(c, comps, kNaviMaterials, sizeof kNaviMaterials / sizeof kNaviMaterials[0], !want, + logs < 2, "Navi", "Mt_Wings"); + if (logs < 2 || (!want && hidden)) hos_log("first person: Navi %s (%d materials, on her models with wings)", want ? "hidden" : "shown", n); + if (logs < 2) logs++; + hidden = want, at = now; +} + /* Link's head through its bone: its local scale 0 while first person is on, so the head, hair and hat (the hat is the tunic's mesh, skinned to the head's bones) go with it, and the eye can sit at his eyes. @@ -1280,6 +1387,7 @@ static void oot_first_person_player(Ctx *c, uint64_t actor, uint64_t components, if (oot_gamedata_bool(c, 0xcea220d3u, &child)) fp_eye_height = child ? 1.15f : 1.55f; age_at = now; } + fp_navi(c, actor, components, want, now); /* again every half second while on: a scene load or a change of age or tunic makes new models */ if (want && (!hidden || now - hidden_at > 500000000LL)) { const int n = fp_set_head_visible(c, components, 0, logs < 2);