From 94c33b1d857c8338efc152f15cb41d348572280c Mon Sep 17 00:00:00 2001 From: lebomis <26766744+lebomis@users.noreply.github.com> Date: Sun, 15 Nov 2026 17:54:57 +1100 Subject: [PATCH 1/9] The gamepad poll keeps its buttons by position, the Home button and the trigger axes, and input_pad_combo reads a combo setting pad_read stores what pad_physical saw (pad_seen, by PAD_* position, with the Home / Guide button after the Switch buttons as PAD_GUIDE) and the two trigger axes (trigger_seen), under the input lock, for gamepad combos that are no Switch buttons and for analog trigger readers. input_pad_combo parses a setting of button positions joined with + (the bind_ lines' pad: names plus guide or home) into a mask, logging a name that is no button. input_map.c exports input_key_id and input_pad_id, and ui/binds_page.cpp binds_pad_label gives the label the open pad has on a button, so menu rows can name buttons as the Controls tab does. No behaviour changes on its own. Co-Authored-By: Claude Opus 5.5 --- runtime/input.c | 41 ++++++++++++++++++++++++++++++++++++++- runtime/input.h | 4 ++++ runtime/input_map.c | 8 ++++---- runtime/input_map.h | 2 ++ runtime/ui/binds_page.cpp | 2 ++ runtime/ui/binds_page.h | 2 ++ 6 files changed, 54 insertions(+), 5 deletions(-) diff --git a/runtime/input.c b/runtime/input.c index 3f539acf..4e776858 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -767,15 +767,54 @@ static int pad_physical(uint8_t pd[PAD_COUNT]) { // Under lock, state 1: the open gamepad's buttons (Switch bits after TOTK_PAD_LAYOUT and the TOTK_BIND_* lines) and // sticks; 0 without a connected gamepad. +// Under lock: the last pad_read's inputs by position, [PAD_GUIDE] the Home / Guide button (no Switch button), and its +// left and right trigger axes, 0..32767: what the gamepad combos and the free camera read +#define PAD_GUIDE PAD_COUNT +static uint8_t pad_seen[PAD_COUNT + 1]; +static int16_t trigger_seen[2]; + static int pad_read(uint64_t *b, int32_t sl[2], int32_t sr[2]) { uint8_t pd[PAD_COUNT] = {0}; - if (!pad_physical(pd)) return 0; + if (!pad_physical(pd)) { + memset(pad_seen, 0, sizeof pad_seen); + memset(trigger_seen, 0, sizeof trigger_seen); + return 0; + } + memcpy(pad_seen, pd, sizeof pd); + pad_seen[PAD_GUIDE] = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_GUIDE); + trigger_seen[0] = SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_LEFT_TRIGGER); + trigger_seen[1] = SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER); *b |= input_map_pad_buttons(pd, pad_layout_get()); stick(SDL_GAMEPAD_AXIS_LEFTX, SDL_GAMEPAD_AXIS_LEFTY, stick_dead_get(0), sl); stick(SDL_GAMEPAD_AXIS_RIGHTX, SDL_GAMEPAD_AXIS_RIGHTY, stick_dead_get(1), sr); return 1; } +uint32_t input_pad_combo(const char *env, const char *s) { + uint32_t mask = 0; + char name[32]; + size_t n = 0; + for (const char *c = s;; c++) { + if (*c && *c != '+' && *c != ' ') { + if (n < sizeof name - 1) name[n++] = *c; + continue; + } + if (n) { + name[n] = 0; + int p = !strcasecmp(name, "guide") || !strcasecmp(name, "home") ? PAD_GUIDE : input_pad_id(name); + if (p == PAD_NONE) { + rt_log("input: %s=%s: %s is not a gamepad button (south east west north lstick rstick " + "l r zl zr start back guide dpad_*, paddles)", env, s, name); + return 0; + } + mask |= 1u << p; + n = 0; + } + if (!*c) break; + } + return mask; +} + int input_pad_stick_percent(double pct[2]) { int ok = 0; pct[0] = pct[1] = 0; diff --git a/runtime/input.h b/runtime/input.h index e2b61a6a..2316d5df 100644 --- a/runtime/input.h +++ b/runtime/input.h @@ -91,6 +91,10 @@ void input_menu(int open); // of the combo, sticks are lx, ly, rx, ry. Returns 1 in the poll where the combo goes down (toggle the menu once). int input_menu_gate(int *held, int menu_open, uint64_t *buttons, int32_t sticks[4]); int input_overlay_gate(int *held, uint64_t *buttons); // L3+R3: 1 in the poll both go down +// A gamepad combo setting: buttons by position joined with '+' (guide+south: Home and the bottom face button, the +// pad: names of the bind_ lines plus guide or home). Bit p is PAD_* p, bit PAD_COUNT the Home button; 0 for an empty +// value or one with a name that is no button, which logs a line naming env. +uint32_t input_pad_combo(const char *env, const char *s); int input_pad_read(uint64_t *buttons, int32_t *lx, int32_t *ly); // The gamepad layout in effect (PAD_LAYOUT_*, input_map.h; TOTK_PAD_LAYOUT, live); -1 without a gamepad. Any thread. int input_pad_layout(void); diff --git a/runtime/input_map.c b/runtime/input_map.c index 5d5ae885..44009ba7 100644 --- a/runtime/input_map.c +++ b/runtime/input_map.c @@ -66,13 +66,13 @@ const char *input_pad_name(int pad) { return pad > PAD_NONE && pad < PAD_COUNT ? void input_map_reset(void) { input_map = defaults; } -static int key_id(const char *name) { +int input_key_id(const char *name) { for (int k = KEY_A; k < KEY_COUNT; k++) if (key_names[k] && !strcasecmp(key_names[k], name)) return k; return KEY_NONE; } -static int pad_id(const char *name) { +int input_pad_id(const char *name) { for (int p = PAD_SOUTH; p < PAD_COUNT; p++) if (!strcasecmp(pad_names[p], name)) return p; return PAD_NONE; @@ -133,12 +133,12 @@ int input_map_bind(const char *button, const char *list) { int ok = 0; if (!strncasecmp(tok, "pad:", 4) && action < B_SL_LEFT) { const char *name = trim(tok + 4); - int p = pad_id(name); + int p = input_pad_id(name); if (!strcasecmp(name, "default")) pad_def = ok = 1; else if (p && np < INPUT_PAD_BINDING_MAX) pads[np++] = (uint8_t)p, ok = 1; } else if (!strncasecmp(tok, "key:", 4)) { const char *name = trim(tok + 4); - int k = key_id(name); + int k = input_key_id(name); if (!strcasecmp(name, "default")) key_def = ok = 1; else if (k && nk < INPUT_BINDING_MAX) keys[nk++] = (uint8_t)k, ok = 1; } diff --git a/runtime/input_map.h b/runtime/input_map.h index bb660ea6..376be4c9 100644 --- a/runtime/input_map.h +++ b/runtime/input_map.h @@ -73,6 +73,8 @@ void input_map_reset(void); // stick directions the keys drive), then SHAKE. Keys: a-z 0-9 space tab lshift ... (key_names in input_map.c). Pads: south east ... const char *input_action_name(int action); const char *input_key_name(int key); +int input_key_id(const char *name); // KEY_NONE for a name without a key +int input_pad_id(const char *name); // PAD_NONE for a name without a gamepad button const char *input_pad_name(int pad); // Replaces every binding of the action `button` (an action name) with `list`: comma separated "pad:" and // "key:" entries, "key:default" / "pad:default" for that part's defaults, or "none" for no input. A part the list diff --git a/runtime/ui/binds_page.cpp b/runtime/ui/binds_page.cpp index 700b0f2a..0e57a0fc 100644 --- a/runtime/ui/binds_page.cpp +++ b/runtime/ui/binds_page.cpp @@ -122,6 +122,8 @@ static const char *pad_label(int p) { return menu_text((UiTextId)(UI_PAD_SOUTH + (p - PAD_SOUTH))); } +const char *binds_pad_label(int pad) { return pad_label(pad); } + // The layout the gamepad cells show: the one in effect, or without a gamepad the one the setting names (Xbox for auto). static int shown_layout(void) { int l = input_pad_layout(); diff --git a/runtime/ui/binds_page.h b/runtime/ui/binds_page.h index 219cb0f9..5cca0665 100644 --- a/runtime/ui/binds_page.h +++ b/runtime/ui/binds_page.h @@ -15,3 +15,5 @@ bool binds_modal(void); // A key setting (TOTK_ name) as a row of one key cell, set by pressing the key as a binding's cell is; Delete sets it // to none. note (NULL none) follows the description. void binds_key_row(const char *setting, UiTextId label, UiTextId desc, const char *note); +// A gamepad input by position (PAD_*): the label the open pad has on a face button, else its place on the pad. +const char *binds_pad_label(int pad); From 29eec072452f9347a30c5491c1ecff82a0f419a1 Mon Sep 17 00:00:00 2001 From: lebomis <26766744+lebomis@users.noreply.github.com> Date: Sun, 15 Nov 2026 17:39:50 +1100 Subject: [PATCH 2/9] ZL+ZR+L3 detaches the view from Link on 1.4.3 and flies it with the gamepad (freecam_pad) The camera component update (main+0x628460) copies each component's eye, target and up into its sead camera. The site freecam (main+0x6286d4, the load every path to that copy runs first) calls runtime/freecam.c freecam_hook, which writes the component's one-shot eye and target overrides (+0x180, +0x198) while the free camera is on; the update takes them in place of the pose and clears them, so the game camera's own state is never changed and resumes the frame the free camera ends. The up vector is levelled through the component's up offset (+0x200), which is kept and put back. Of the three components a frame updates, the hook drives the two that share the player camera's eye, leaves the one at the default pose and picks again after a load; with the free camera off it does only the displaced load. input.c freecam_gate latches TOTK_FREECAM_PAD (zl+zr+lstick when unset, none for no combo) like Minus+Plus and, while the free camera is on, gives it the sticks, the trigger axes and L and R presses and the game nothing. The left stick flies along the view and sideways, the triggers straight up and down, the right stick turns, each L or R press halves or doubles the speed (0.25 to 512 m/s, 8 at the start); the flight follows the wall clock. TOTK_FREECAM_PATCH=0 removes the hook. Co-Authored-By: Claude Opus 5.5 --- docs/controls.md | 25 ++++ docs/settings.md | 1 + recomp/patches-v143.txt | 8 ++ runtime/cfg.c | 4 +- runtime/freecam.c | 244 ++++++++++++++++++++++++++++++++++++++++ runtime/input.c | 57 ++++++++++ runtime/input.h | 9 ++ tools/build_game.py | 4 +- totk.ini.example | 5 + 9 files changed, 353 insertions(+), 4 deletions(-) create mode 100644 runtime/freecam.c diff --git a/docs/controls.md b/docs/controls.md index e2102f4b..5d498d62 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -129,6 +129,31 @@ bind_X = pad:west, key:space bind_Y = pad:north, key:mouse_l ``` +## Free camera + +On game 1.4.3, ZL+ZR+L3 together (LT+RT+L3 on an Xbox pad; `freecam_pad` in `totk.ini` picks another combo, `none` none) +detach the view from Link; the same combo brings it back. The world goes on, but the game gets no gamepad input while the +free camera is on, so Link stands where he was. + +| Input | Free camera | +|---|---| +| Left stick | forward and back along the view, and sideways | +| ZR / ZL (RT / LT) | straight up / down, by how far the trigger is pressed | +| Right stick | turn (yaw and pitch; pitch stops 5 degrees short of straight up or down) | +| R / L (RB / LB) | each press doubles / halves the speed, 0.25 to 512 m/s | + +The keys that drive the sticks (W A S D and the arrow keys by default) move it too. Each switch starts at the game +camera's position and view at 8 m/s; the speed follows the clock, so it is the same at any frame rate and game speed. +The horizon stays level. + +How it works (`runtime/freecam.c`): the camera component update (main+0x628460) copies each component's eye, target +and up into its sead camera. The site `freecam` (`recomp/patches-v143.txt`, main+0x6286d4) runs before that copy and +writes the component's one-shot eye and target overrides (+0x180, +0x198), which the update takes in place of the pose +and then clears, so the game camera's own state is never changed and resumes the frame the free camera ends. The up +vector is levelled through the component's up offset (+0x200), which is kept and put back. Of the three components a +frame updates, the free camera drives the two that share the player camera's eye and leaves the one at the default pose +(eye 0, 0, 10). After a load replaced the components it picks the new ones and keeps its position. + ## Mouse camera `mouse_mode = direct` (the default) turns the camera by the raw mouse motion on games 1.4.3 and 1.2.1, through hooks in the game's camera code (`runtime/mouse_direct.c`, the `mouse_direct` sites of `recomp/patches-v143.txt` and `recomp/patches-v121.txt`). None of them changes a step of the gamepad alone. The free-orbit camera receives raw-count diff --git a/docs/settings.md b/docs/settings.md index dc35b3ec..35ef506c 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -231,6 +231,7 @@ These names are code patch sets built into the generated game code (`recomp/patc | `aspect_patch` (default `0`) | Patch set that feeds the camera the output's aspect ratio when it is not 16:9. | The resolution code switches this set on or off itself at start, so a value here is replaced; the code does not settle what a manual value does. | Unknown | | `audio_drain_fix` (default `1`) | Patch set that sends the game's audio thread back to its command ring after each list (1.2.1 main+0x883780, 1.4.3 main+0x149244), so it takes every queued list per 5 ms audio frame instead of one (#337). Game 1.1.0 has no site and keeps the game's code. | `0` runs the game's code as shipped: above about 200 game updates a second the ring stays full and the game's guard (1.2.1 main+0x9bcdc4) switches the sound commands off until the game is restarted. The set acts only when more than one list is queued, so below that rate it seldom changes anything. Measured at `fps_limit = 240`, seconds with sound: on 1.2.1 5 of 118 with `0` and 108 of 118 with `1`; on 1.4.3 2 of 118 with `0` and 110 of 119 with `1`. | Safe | | `fixed_res_patch` (default `0`) | Patch set that holds the game's dynamic resolution at 100 percent (the scene tier). | The resolution code switches this set from `dynamic_res` (on at `0`); a manual value is replaced. | Unknown | +| `freecam_patch` (default `1`) | Patch set of the hook in the camera component update behind the free camera (`freecam_pad`) on game 1.4.3. | `0` removes the hook: the free camera combo does nothing and the game gets the combo's buttons. | Safe | | `fov_patch` (default `0`) | Patch set that scales the camera's vertical view angle by the field-of-view setting. | The resolution code switches this set itself whenever the field of view is not 100 percent; a manual value is replaced. | Unknown | | `mouse_direct_patch` (default `1`) | Patch set of the hooks in the game's camera code behind `mouse_mode = direct` on game 1.4.3. | `0` stops `mouse_mode = direct` from taking effect; other mouse modes are unaffected. | Safe | | `optref_guard` (default `1`) | Patch set that treats a negative value in the optional reference at object +0x6b0 (1.4.3 main+0x1bd01c0, 1.2.1 main+0x1622bec) as absent instead of loading through it (#1005). | `0` runs the game's code as shipped: the random crash reading `0xffffffffffffffff` after minutes to hours of play can return. | Risky | diff --git a/recomp/patches-v143.txt b/recomp/patches-v143.txt index 8ecb5d7b..f786befd 100644 --- a/recomp/patches-v143.txt +++ b/recomp/patches-v143.txt @@ -128,6 +128,14 @@ set fov TOTK_FOV_PATCH 0 site fov main 628c3c bd413e60 f81f0fea @page:x10 bd413e60 bd403d48 1e280800 f84107ea # ldr s0, [x19, #0x13c] (camera update) site fov main b4342c bd4066c0 f81f0fea @page:x10 bd4066c0 bd403d48 1e280800 f84107ea # ldr s0, [x22, #0x64] (camera setup) +# Free camera (runtime/freecam.c freecam_hook, page +0xf50). The camera component update (main+0x628460, the routine of +# the first fov and aspect sites) copies the component's eye, target and up into its sead camera; every path to that +# copy runs this load of the component's link first. The hook performs the load and, while the free camera is on, +# writes the component's one-shot eye and target overrides (+0x180, +0x198). The function saves x30 in its prologue, so +# the bl's link write is harmless. +set freecam TOTK_FREECAM_PATCH 1 +site freecam main 6286d4 f9400e68 94d2de1f # ldr x8, [x19, #0x18] + # The camera input update, after its stick dead zone, unit-radius clamp and StickExponent. The host callback # performs the displaced store and adds raw mouse counts to s9/s10 (runtime/mouse_direct.c camera_input). # Its address is page +0xfd0; the page is main+0x3adf000 on this verified build. diff --git a/runtime/cfg.c b/runtime/cfg.c index 9e2f0547..2ee51e2d 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -43,7 +43,7 @@ static const char *const known[] = { "COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT", "DESC_TEMPLATE", "DESWIZZLE", "DEVICE_PROFILE", "DIALOGUE_CLICK", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_CAM_JITTER", "DLAA_EFFECTS_AFTER", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_FIXED_EXPOSURE", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG", "DYNAMIC_RES", "DYN_DELTA", "EXEFS", "FEEDBACK", "FIXED_RES_PATCH", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", - "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_QUEUE", + "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_QUEUE", "FREECAM_PAD", "FREECAM_PATCH", "FREEZE_IDLE", "FREE_CORES", "FULLSCREEN", "FXAA", "GAMEPLAY_DISTANCE_SENSITIVITY", "GAMEPLAY_ITEM_AD", "GAMEPLAY_ITEM_SENSITIVITY", "GAMEPLAY_ITEM_WHEEL", @@ -99,7 +99,7 @@ static const struct { const char *key, *section; } sections[] = { {"GYRO_BIAS_X", "input"}, {"GYRO_BIAS_Y", "input"}, {"GYRO_BIAS_Z", "input"}, {"GYRO_BIAS_PAD", "input"}, {"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"LSTICK_DEADZONE", "input"}, {"RSTICK_DEADZONE", "input"}, {"STICK_SENS", "input"}, - {"MENU_CURSOR", "input"}, {"MAP_CLICK", "input"}, {"DIALOGUE_CLICK", "input"}, {"POINTER_IMAGE", "input"}, {"QUICKSAVE", "input"}, {"QUICKSAVE_KEY", "input"}, {"QUICKLOAD_KEY", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"INPUT_RECORD", "input"}, + {"MENU_CURSOR", "input"}, {"MAP_CLICK", "input"}, {"DIALOGUE_CLICK", "input"}, {"POINTER_IMAGE", "input"}, {"QUICKSAVE", "input"}, {"QUICKSAVE_KEY", "input"}, {"QUICKLOAD_KEY", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"FREECAM_PAD", "input"}, {"INPUT_RECORD", "input"}, {"BIND_A", "input"}, {"BIND_B", "input"}, {"BIND_X", "input"}, {"BIND_Y", "input"}, {"BIND_LCLICK", "input"}, {"BIND_RCLICK", "input"}, {"BIND_L", "input"}, {"BIND_R", "input"}, {"BIND_ZL", "input"}, {"BIND_ZR", "input"}, {"BIND_PLUS", "input"}, {"BIND_MINUS", "input"}, {"BIND_LEFT", "input"}, {"BIND_UP", "input"}, diff --git a/runtime/freecam.c b/runtime/freecam.c new file mode 100644 index 00000000..882cf707 --- /dev/null +++ b/runtime/freecam.c @@ -0,0 +1,244 @@ +// Free camera for TotK 1.4.3: the view leaves Link and flies with the gamepad while the game goes on (docs/controls.md, +// "Free camera"). +// +// The camera component update (main+0x628460, called with the component as x0 = x19 from main+0x627dc8, the camera +// actor's component array +0x228, slot +0x270) copies the component's pose into its sead camera and builds the view +// matrix from it. Component fields (doubles unless noted): eye +0xe8, target +0x110, up +0x128 (floats), then near, +// far, vertical view angle and aspect +0x134..+0x140 (the fov and aspect sets of recomp/patches-v143.txt load the last +// two). Two one-shot overrides come after: a non-zero eye at +0x180 or target at +0x198 replaces the pose for that +// update and is cleared (main+0x628fdc, main+0x629004). Additive offsets follow at +0x1b0 (flag) / +0x1c0 (eye), +// +0x1d8 / +0x1e8 (target) and +0x200 (up, three floats, applied when any is non-zero and never cleared by the game). +// +// The freecam set's one site (main+0x6286d4, `ldr x8, [x19, #0x18]`, the first instruction every path to the pose +// copy runs) calls freecam_hook, which performs that load and, while the free camera is on, writes the overrides. +// The game's own eye and target stay as they were, so the game camera takes over the update after the hook stops. +// The up offset is the game's state: the hook keeps the component's value and puts it back when the free camera ends, +// and makes the up vector the world's +Y meanwhile, so the horizon stays level. +// +// Which components: a 1.4.3 frame updates three. Two share the player camera's pose (both must move, or the scene +// and what follows the second disagree); the third rests at the default pose, eye (0, 0, 10) towards the origin. The +// first component seen away from that default anchors the pick, and every component whose eye is within MATCH_M of +// the anchor is driven. When no driven component has been updated for LOST_NS (a load replaced them) the next one +// away from the default anchors again; the free camera keeps its own position. +// +// Input (runtime/input.c freecam_gate): TOTK_FREECAM_PAD switches it, ZL+ZR+L3 by default. While it is on the game +// gets no gamepad input; the left stick flies along the view and to the side, the triggers straight up and down, the +// right stick turns, and each press of L or R halves or doubles the speed. Every driven component steps the flight by +// the wall-clock time since the last step, so the speed is the same at any frame rate and game speed. +#include +#include +#include +#include + +#include "cfg.h" +#include "host.h" +#include "input.h" +#include "platform/platform.h" + +#if __has_include("patches.h") +#include "patches.h" +#endif + +#define SPEED_START 8.0 // metres a second at full deflection +#define SPEED_MIN 0.25 // 8 m/s halved five times +#define SPEED_MAX 512.0 // 8 m/s doubled six times +#define TURN_DEG_S 110.0 // the right stick's turn rate at full deflection +#define PITCH_MAX_DEG 85.0 // short of straight up or down, where the view's up vector would fail +#define TARGET_M 10.0 // the target's distance in front of the eye +#define MATCH_M 2.0 +#define LOST_NS 500000000ull +#define STEP_MAX_S 0.1 // a longer gap (a load, a hitch) moves the camera no further than this +#define MAX_DRIVEN 8 + +static PlatMutex pad_lock = PLAT_MUTEX_INIT; +static FreecamPad pad_now; // the last poll's input (input thread), under pad_lock +static int speed_clicks; // R presses minus L presses not yet applied (input thread adds, the hook takes) +// + 1 at every switch (input thread); odd while the free camera is on. One value, so the hook never sees a switch +// without the state it switched to. +static unsigned generation; + +int freecam_on(void) { return __atomic_load_n(&generation, __ATOMIC_ACQUIRE) & 1; } + +void freecam_pad(const FreecamPad *p) { + plat_mutex_lock(&pad_lock); + pad_now = *p; + plat_mutex_unlock(&pad_lock); +} + +void freecam_speed_click(int faster) { __atomic_add_fetch(&speed_clicks, faster ? 1 : -1, __ATOMIC_RELAXED); } + +#ifdef RT_PATCH_PAGE +#define HOST_FREECAM (RT_PATCH_PAGE + 0xf50) + +enum { + OFF_LINK = 0x18, OFF_EYE = 0xe8, OFF_TARGET = 0x110, OFF_UP = 0x128, + OFF_EYE_OVERRIDE = 0x180, OFF_TARGET_OVERRIDE = 0x198, OFF_UP_OFFSET = 0x200, + SPAN = OFF_UP_OFFSET + 12 - OFF_EYE, // the fields the hook reads and writes, from OFF_EYE +}; + +int freecam_available(void) { return rt_game_version == 143 && rt_patch_enabled(rt_patch_set("freecam")); } + +void freecam_toggle(void) { + unsigned gen = __atomic_add_fetch(&generation, 1, __ATOMIC_ACQ_REL); + rt_log("freecam: %s", gen & 1 ? "on" : "off"); +} + +// Game thread only (the camera update runs on one thread). A component stays listed from its first drive until its +// up offset is put back (the first update after the switch goes off) or, while off, until it has gone LOST_NS +// without an update (freed by a load). +static struct { + unsigned generation; + int started; // pos, yaw and pitch hold a pose + double pos[3], yaw, pitch, speed; // radians; yaw 0 looks along +Z, pitch > 0 up + uint64_t last_step, anchor_seen; + int anchored; // anchor holds the eye of the components being driven + double anchor[3]; + int n; + struct { uint64_t cam, seen; float up_offset[3]; } driven[MAX_DRIVEN]; +} fc; + +static void read3(uint64_t at, double v[3]) { memcpy(v, (const void *)(uintptr_t)at, 3 * sizeof(double)); } +static void write3(uint64_t at, const double v[3]) { memcpy((void *)(uintptr_t)at, v, 3 * sizeof(double)); } + +static int at_default(const double eye[3], const double target[3]) { + return eye[0] == 0 && eye[1] == 0 && eye[2] == 10 && target[0] == 0 && target[1] == 0 && target[2] == 0; +} + +static void direction(double d[3]) { + d[0] = sin(fc.yaw) * cos(fc.pitch); + d[1] = sin(fc.pitch); + d[2] = cos(fc.yaw) * cos(fc.pitch); +} + +static int driven_index(uint64_t cam) { + for (int i = 0; i < fc.n; i++) + if (fc.driven[i].cam == cam) return i; + return -1; +} + +static void drop(int i) { fc.driven[i] = fc.driven[--fc.n]; } + +// The free camera starts where the game camera is: its eye, looking at its target. +static void start(const double eye[3], const double target[3], uint64_t now) { + double d[3] = {target[0] - eye[0], target[1] - eye[1], target[2] - eye[2]}; + double len = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]); + memcpy(fc.pos, eye, sizeof fc.pos); + fc.yaw = len > 1e-6 ? atan2(d[0], d[2]) : 0; + fc.pitch = len > 1e-6 ? asin(fmax(-1.0, fmin(1.0, d[1] / len))) : 0; + fc.started = 1; + fc.last_step = now; + rt_log("freecam: starting at (%.1f %.1f %.1f)", eye[0], eye[1], eye[2]); +} + +// A new component joins while it shares the anchor's eye; the first one away from the default pose sets the anchor. +static int pick(uint64_t cam, const double eye[3], const double target[3]) { + if (at_default(eye, target)) return -1; + if (fc.anchored) { + double dx = eye[0] - fc.anchor[0], dy = eye[1] - fc.anchor[1], dz = eye[2] - fc.anchor[2]; + if (dx * dx + dy * dy + dz * dz > MATCH_M * MATCH_M) return -1; + } else { + memcpy(fc.anchor, eye, sizeof fc.anchor); + fc.anchored = 1; + } + if (fc.n == MAX_DRIVEN) { // full after several loads: the one unseen longest was freed by a load + int oldest = 0; + for (int k = 1; k < fc.n; k++) + if (fc.driven[k].seen < fc.driven[oldest].seen) oldest = k; + drop(oldest); + } + int i = fc.n++; + fc.driven[i].cam = cam; + memcpy(fc.driven[i].up_offset, (const void *)(uintptr_t)(cam + OFF_UP_OFFSET), sizeof fc.driven[i].up_offset); + rt_log("freecam: driving camera component %#llx", (unsigned long long)cam); + return i; +} + +static double axis(float v) { return v > 1 ? 1 : v < -1 ? -1 : v; } + +// Flight since the last step: L and R presses scale the speed, the right stick turns, the left stick moves along the +// view and to the side, the triggers along the world's up. +// Every driven component steps; the second one of a frame comes microseconds after the first and moves that little. +static void step(uint64_t now) { + double dt = (now - fc.last_step) / 1e9; + fc.last_step = now; + if (dt <= 0) return; + if (dt > STEP_MAX_S) dt = STEP_MAX_S; + FreecamPad p; + plat_mutex_lock(&pad_lock); + p = pad_now; + plat_mutex_unlock(&pad_lock); + int clicks = __atomic_exchange_n(&speed_clicks, 0, __ATOMIC_RELAXED); + if (clicks) { + fc.speed *= exp2(clicks); + fc.speed = fc.speed < SPEED_MIN ? SPEED_MIN : fc.speed > SPEED_MAX ? SPEED_MAX : fc.speed; + } + double turn = TURN_DEG_S * M_PI / 180 * dt, limit = PITCH_MAX_DEG * M_PI / 180; + fc.yaw = remainder(fc.yaw - axis(p.rx) * turn, 2 * M_PI); // right turns towards -yaw (see right[] below) + fc.pitch += axis(p.ry) * turn; + fc.pitch = fc.pitch > limit ? limit : fc.pitch < -limit ? -limit : fc.pitch; + double d[3], right[3]; + direction(d); + // world +Y up, right-handed: right = d x Y, level + double rl = sqrt(d[0] * d[0] + d[2] * d[2]); + right[0] = -d[2] / rl, right[1] = 0, right[2] = d[0] / rl; + double fwd = axis(p.ly), side = axis(p.lx), lift = axis(p.rt) - axis(p.lt), dist = fc.speed * dt; + for (int k = 0; k < 3; k++) fc.pos[k] += (d[k] * fwd + right[k] * side) * dist; + fc.pos[1] += lift * dist; +} + +static void drive(uint64_t cam) { + double d[3], target[3]; + direction(d); + for (int k = 0; k < 3; k++) target[k] = fc.pos[k] + d[k] * TARGET_M; + write3(cam + OFF_EYE_OVERRIDE, fc.pos); + write3(cam + OFF_TARGET_OVERRIDE, target); + // up + offset = +Y: the game adds the offset to its up vector before it builds the view + float up[3], offset[3]; + memcpy(up, (const void *)(uintptr_t)(cam + OFF_UP), sizeof up); + offset[0] = -up[0], offset[1] = 1.0f - up[1], offset[2] = -up[2]; + if (offset[0] == 0 && offset[1] == 0 && offset[2] == 0) offset[1] = 1e-6f; // all zero would skip the offset + memcpy((void *)(uintptr_t)(cam + OFF_UP_OFFSET), offset, sizeof offset); +} + +// The site's own instruction first: x8 = [x19 + 0x18]. x19 is the camera component (read only: the lifter keeps +// X19-X29 in locals across a host call). +static void freecam_hook(Cpu *c) { + uint64_t cam = c->x[19]; + memcpy(&c->x[8], (const void *)(uintptr_t)(cam + OFF_LINK), sizeof c->x[8]); + unsigned gen = __atomic_load_n(&generation, __ATOMIC_ACQUIRE); + int active = gen & 1; + if (!active && !fc.n) return; // the common case: one load and two compares + if (gen != fc.generation) { // a switch: a new flight starts at the game camera, at the start speed + fc.generation = gen; + fc.started = 0, fc.anchored = 0, fc.speed = SPEED_START; + } + uint64_t now = plat_now_ns(); + int i = driven_index(cam); + if (!active) { + if (i >= 0) { + memcpy((void *)(uintptr_t)(cam + OFF_UP_OFFSET), fc.driven[i].up_offset, sizeof fc.driven[i].up_offset); + drop(i); + } + for (int k = fc.n - 1; k >= 0; k--) + if (now - fc.driven[k].seen > LOST_NS) drop(k); // freed by a load while it waited + return; + } + if (!mem_guest_readable(cam + OFF_EYE, SPAN)) return; + if (fc.anchored && now - fc.anchor_seen > LOST_NS) fc.anchored = 0; // a load replaced the components + double eye[3], target[3]; + read3(cam + OFF_EYE, eye); + read3(cam + OFF_TARGET, target); + if (i < 0 && (i = pick(cam, eye, target)) < 0) return; + if (!fc.started) start(eye, target, now); + fc.driven[i].seen = fc.anchor_seen = now; + step(now); + drive(cam); +} + +__attribute__((constructor)) static void freecam_register(void) { + if (rt_game_version == 143) rt_register_host(HOST_FREECAM, freecam_hook); +} +#else +int freecam_available(void) { return 0; } +void freecam_toggle(void) {} +#endif diff --git a/runtime/input.c b/runtime/input.c index 4e776858..c15ac48c 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -815,6 +815,62 @@ uint32_t input_pad_combo(const char *env, const char *s) { return mask; } +// TOTK_FREECAM_PAD (live): the combo that switches the free camera (freecam.c); zl+zr+lstick (LT+RT+L3) when unset, +// none for no combo. Under lock. +static uint32_t freecam_pad_mask(void) { + static unsigned seen; + static int read; + static uint32_t mask; + unsigned v = cfg_version(); + if (read && v == seen) return mask; + read = 1, seen = v; + const char *s = cfg_get("TOTK_FREECAM_PAD"); + if (!s || !*s) s = "zl+zr+lstick"; + mask = strcasecmp(s, "none") ? input_pad_combo("TOTK_FREECAM_PAD", s) : 0; + return mask; +} + +static float trigger_unit(int16_t v) { // 0..1 past a 5 % dead zone + float t = v / 32767.0f; + return t < 0.05f ? 0 : (t - 0.05f) / 0.95f; +} + +// The free camera combo, latched like Minus+Plus (input_map.c, chord): once every button of it is down the free +// camera switches once, and the buttons stay hidden from the game until all are released. While the free camera is on +// it gets the gamepad (and the keys' sticks, merged into sl and sr) and the game gets nothing, so Link stands still; +// each press of L or R is a speed click. Off for other updates and with the freecam patch set off. Under lock. +static void freecam_gate(uint64_t *b, int32_t sl[2], int32_t sr[2]) { + static int held, available = -1, shoulder[2]; + if (available < 0) available = freecam_available(); + uint32_t mask = available ? freecam_pad_mask() : 0, raw = 0; + for (int p = PAD_SOUTH; p <= PAD_GUIDE; p++) + if (mask >> p & 1 && pad_seen[p]) raw |= 1u << p; + if (!mask) held = 0; + else if (held) held = raw != 0; + else if (raw == mask) { + held = 1; + freecam_toggle(); + } + if (available && freecam_on()) { + FreecamPad fp = {sl[0] / (float)STICK_MAX, sl[1] / (float)STICK_MAX, sr[0] / (float)STICK_MAX, + sr[1] / (float)STICK_MAX, trigger_unit(trigger_seen[0]), trigger_unit(trigger_seen[1])}; + freecam_pad(&fp); + for (int k = 0; k < 2; k++) { + int down = pad_seen[k ? PAD_R : PAD_L]; + if (down && !shoulder[k]) freecam_speed_click(k); + shoulder[k] = down; + } + *b = 0; + sl[0] = sl[1] = sr[0] = sr[1] = 0; + return; + } + shoulder[0] = shoulder[1] = 1; // a shoulder held when the free camera starts is no click + if (!held) return; + uint8_t sub[PAD_COUNT] = {0}; + for (int p = PAD_SOUTH; p < PAD_COUNT; p++) sub[p] = mask >> p & 1; + *b &= ~input_map_pad_buttons(sub, pad_layout_get()); +} + int input_pad_stick_percent(double pct[2]) { int ok = 0; pct[0] = pct[1] = 0; @@ -935,6 +991,7 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx static int overlay_held; // L3+R3 step the performance overlay (F10) int overlay = input_overlay_gate(&overlay_held, &b); sl[0] = st[0], sl[1] = st[1], sr[0] = st[2], sr[1] = st[3]; + freecam_gate(&b, sl, sr); // TOTK_FREECAM_PAD switches the free camera, which then takes the pad (freecam.c) plat_mutex_unlock(&lock); if (toggle) menu_toggle(); if (overlay) menu_perf_cycle(); diff --git a/runtime/input.h b/runtime/input.h index 2316d5df..80a218a0 100644 --- a/runtime/input.h +++ b/runtime/input.h @@ -98,6 +98,15 @@ uint32_t input_pad_combo(const char *env, const char *s); int input_pad_read(uint64_t *buttons, int32_t *lx, int32_t *ly); // The gamepad layout in effect (PAD_LAYOUT_*, input_map.h; TOTK_PAD_LAYOUT, live); -1 without a gamepad. Any thread. int input_pad_layout(void); + +// Free camera (freecam.c). input.c switches it with TOTK_FREECAM_PAD and, while it is on, hands it the gamepad and +// gives the game none: sticks -1..1 with up +y after the dead zone, triggers 0..1; each L or R press is one speed click. +typedef struct { float lx, ly, rx, ry, lt, rt; } FreecamPad; +int freecam_available(void); // game 1.4.3 with the freecam patch set on +int freecam_on(void); +void freecam_toggle(void); // logs; input thread +void freecam_pad(const FreecamPad *p); +void freecam_speed_click(int faster); // R (1) doubles the speed, L (0) halves it // How far the open gamepad's left (pct[0]) and right (pct[1]) sticks are from the centre now, in percent of full // deflection, before the dead zone: the menu shows it on the dead zone rows, so a drifting stick's resting value can be // read off. 0 (and both 0) without a connected gamepad. Any thread. diff --git a/tools/build_game.py b/tools/build_game.py index 3de72efd..8537c550 100644 --- a/tools/build_game.py +++ b/tools/build_game.py @@ -201,11 +201,11 @@ LLVM_LINK_LIBS = ['-lpsapi', '-lbcrypt', '-luser32', '-lgdi32', '-ldwmapi', '-li DEFAULT_DEPS = ROOT / 'toolchain' / 'deps-mingw' # Runtime sources compiled per install, not in the library: romfs.c includes romfs_config.h, patches.c and ov_zstd.c # the patches.h of the player's game version (its patch page is the page after that version's main; ov_zstd.c's host -# functions sit on it). mouse_direct.c and ov_ability.c also register host callbacks relative to that version's patch +# functions sit on it). mouse_direct.c, ov_ability.c and freecam.c also register host callbacks relative to that version's patch # page. plugin_init.c reads the install's own plugin records from patches.h (RT_PLUGINS, RT_PLUGIN_WRITES): a mod plugin # the rebuild built in. A library source that includes one of PER_VERSION_HEADERS stops the library build # (library_sources). -INSTALL_SIDE = {'romfs.c', 'patches.c', 'ov_zstd.c', 'mouse_direct.c', 'ov_ability.c', 'plugin_init.c'} +INSTALL_SIDE = {'romfs.c', 'patches.c', 'ov_zstd.c', 'mouse_direct.c', 'ov_ability.c', 'plugin_init.c', 'freecam.c'} PER_VERSION_HEADERS = ('"patches.h"', '"romfs_config.h"') LIB_NAME = 'libtotkrt.a' AR = UCRT / 'llvm-ar.exe' if WIN else on_path('llvm-ar') diff --git a/totk.ini.example b/totk.ini.example index a4b33431..d81f7eea 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -480,6 +480,11 @@ # reads as a partial tilt only. # walk_key = lshift # walk_scale = 0.51 +# Free camera (game 1.4.3): the gamepad combo that switches it, buttons by position joined with +, the pad: names of the +# bind_ lines. While it is on the game gets no input and the view flies: the left stick along the view and sideways, +# the triggers straight up and down, the right stick turns; each press of L halves the speed, of R doubles it +# (docs/controls.md, "Free camera"). none turns the combo off. Default: zl+zr+lstick (LT+RT+L3 on an Xbox pad). +# freecam_pad = zl+zr+lstick # Write the input of this run to a file that replays as a script (docs/controls.md, "Scripted input"). Default: off. # input_record = input.txt # Remap buttons: the Controls tab of the settings menu (F1) writes these lines. One line per Switch button or stick From 34b6b380acf9cdaee205d3f43a53fc993372661e Mon Sep 17 00:00:00 2001 From: lebomis <26766744+lebomis@users.noreply.github.com> Date: Sun, 15 Nov 2026 17:45:00 +1100 Subject: [PATCH 3/9] The Controls tab picks the free camera combo A row under the walk rows offers the trigger pair or the shoulder pair with either stick click, or off, named as the open pad labels its buttons (binds_page.cpp binds_pad_label, the Controls tab's labels). TOTK_FREECAM_PAD gets a live row in the cfg table with its default zl+zr+lstick; totk.ini still takes any combo of button positions, shown as written. On other game versions than 1.4.3 the row is off and says so. Text in all four menu languages. Co-Authored-By: Claude Opus 5.5 --- runtime/cfg.c | 1 + runtime/ui/menu.cpp | 20 ++++++++++++++++++++ runtime/ui_text.c | 19 +++++++++++++++++++ runtime/ui_text.h | 1 + 4 files changed, 41 insertions(+) diff --git a/runtime/cfg.c b/runtime/cfg.c index 2ee51e2d..485eda3e 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -189,6 +189,7 @@ static const CfgMeta metas[] = { {"QUICKSAVE", "0", "0|1", LIVE}, // quicksave.c: one key saves (an autosave), another loads it {"QUICKSAVE_KEY", "f6", NULL, LIVE}, {"QUICKLOAD_KEY", "f7", NULL, LIVE}, // Half-Life's keys; a key name or none {"WALK_KEY", "none", NULL, LIVE}, {"WALK_SCALE", "0.51", "0.2..0.9", LIVE}, + {"FREECAM_PAD", "zl+zr+lstick", NULL, LIVE}, // Gameplay Tweaks {"GAMEPLAY_TWEAKS_ENABLED", "0", "0|1", LIVE}, {"GAMEPLAY_ULTRAHAND_ROTATE", "1", "0|1", LIVE}, {"GAMEPLAY_ULTRAHAND_C_AXIS", "1", "0|1", LIVE}, diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 4bff6396..dcbdca7c 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -944,6 +944,25 @@ static void row_quicksave_keys(void) { key_taken("TOTK_QUICKLOAD_KEY", note[1], sizeof note[1])); } +// The free camera combo (freecam.c): the trigger and shoulder pairs with a stick click, named as the open pad labels +// its buttons, or none. totk.ini takes any combo of button positions, shown as written. Off on other game versions. +static void row_freecam_pad(void) { + static const char *const combos[] = {"zl+zr+lstick", "zl+zr+rstick", "l+r+lstick", "l+r+rstick", "none"}; + static const int pads[][3] = {{PAD_ZL, PAD_ZR, PAD_LSTICK}, {PAD_ZL, PAD_ZR, PAD_RSTICK}, + {PAD_L, PAD_R, PAD_LSTICK}, {PAD_L, PAD_R, PAD_RSTICK}}; + enum { N = sizeof combos / sizeof *combos }; + static char shown[N - 1][128]; + const char *names[N]; + for (int i = 0; i < N - 1; i++) { + snprintf(shown[i], sizeof shown[i], "%s + %s + %s", binds_pad_label(pads[i][0]), binds_pad_label(pads[i][1]), + binds_pad_label(pads[i][2])); + names[i] = shown[i]; + } + names[N - 1] = menu_text(UI_MENU_OFF); + if (!freecam_available()) opt_disable_next(UI_MENU_FREECAM_PAD_V143); + opt_choice_list("TOTK_FREECAM_PAD", UI_MENU_FREECAM_PAD, combos, names, N, UI_MENU_FREECAM_PAD_DESC); +} + // The note under the prompts. The settings name a folder of prompts (input_prompts_folder: the prompts and the pad // layout, as a layout that puts A on the right button needs the face buttons named the other way round), but the game // reads its fonts and UI archive once at start (romfs.c overlay_init). While the folder in use differs: when the @@ -1084,6 +1103,7 @@ static void tab_controls(float scale) { row_quicksave_keys(); row_walk_key(); opt_slider("TOTK_WALK_SCALE", UI_MENU_WALK_SCALE, 0.2f, 0.9f, UI_MENU_WALK_SCALE_DESC, 0.01f, "%.2f"); + row_freecam_pad(); rows_gameplay_tweaks(); // Analog sticks: one dead zone row per stick, falling back to TOTK_STICK_DEADZONE (both sticks) while unset. With // a gamepad connected each row shows its stick's deflection now, before the dead zone: a drifting stick's resting diff --git a/runtime/ui_text.c b/runtime/ui_text.c index ff43bf01..abd56a73 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -358,6 +358,11 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_WALK_SCALE] = "Walk scale", [UI_MENU_WALK_SCALE_DESC] = "The tilt the keyboard's sticks get while the walk key is held. Half is a walk, the " "full tilt a run.", + [UI_MENU_FREECAM_PAD] = "Free camera combo", + [UI_MENU_FREECAM_PAD_DESC] = "Gamepad buttons pressed together that detach the view from Link and bring it back. " + "While it is on the game gets no input: the left stick flies along the view and sideways, the triggers up and " + "down, the right stick turns, and each press of L or R halves or doubles the speed. Game version 1.4.3.", + [UI_MENU_FREECAM_PAD_V143] = "Game version 1.4.3 only", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Gameplay tweaks", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Gameplay tweaks", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Mouse wheel controls for Ultrahand rotation and distance, item and weapon switching, and smooth map zoom.", @@ -969,6 +974,11 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_WALK_SCALE] = "Сила шага", [UI_MENU_WALK_SCALE_DESC] = "Отклонение стиков клавиатуры при удержании клавиши шага. Половина — шаг, полное " "отклонение — бег.", + [UI_MENU_FREECAM_PAD] = "Сочетание свободной камеры", + [UI_MENU_FREECAM_PAD_DESC] = "Кнопки геймпада, нажатые вместе, отделяют камеру от Линка и возвращают её. Пока она " + "включена, игра не получает ввод: левый стик ведёт камеру вдоль взгляда и вбок, курки — вверх и вниз, правый " + "стик поворачивает, а каждое нажатие L или R уменьшает или увеличивает скорость вдвое. Версия игры 1.4.3.", + [UI_MENU_FREECAM_PAD_V143] = "Только для версии игры 1.4.3", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Геймплей", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Настройки геймплея", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Управление колесом мыши: вращение и дистанция предметов в Ультраруке, выбор оружия и предметов, плавный зум карты.", @@ -1771,6 +1781,12 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_WALK_SCALE] = "Intensidade do andar", [UI_MENU_WALK_SCALE_DESC] = "A inclinação dos analógicos do teclado enquanto a tecla de andar está segura. Metade " "é andar, a inclinação total é correr.", + [UI_MENU_FREECAM_PAD] = "Combinação da câmera livre", + [UI_MENU_FREECAM_PAD_DESC] = "Botões do controle pressionados juntos que soltam a câmera do Link e a trazem de " + "volta. Enquanto ela está ligada o jogo não recebe comandos: o analógico esquerdo voa na direção da visão e " + "para os lados, os gatilhos sobem e descem, o analógico direito gira, e cada toque em L ou R reduz a " + "velocidade à metade ou a dobra. Versão do jogo 1.4.3.", + [UI_MENU_FREECAM_PAD_V143] = "Só na versão 1.4.3 do jogo", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Ajustes de jogabilidade", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Ajustes de jogabilidade", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Controles com a roda do mouse para rotação e distância na Ultramão, seleção de armas e itens, e zoom suave no mapa.", @@ -2520,6 +2536,9 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_WALK_KEY_TAKEN] = "同时为 %s", [UI_MENU_WALK_SCALE] = "步行幅度", [UI_MENU_WALK_SCALE_DESC] = "按住步行键时键盘摇杆的推动幅度。一半为走路,推满为奔跑。", + [UI_MENU_FREECAM_PAD] = "自由镜头组合键", + [UI_MENU_FREECAM_PAD_DESC] = "同时按下的手柄按键,让镜头脱离林克,再按一次回到林克。开启期间游戏不接收输入:左摇杆沿视线方向和左右移动,扳机键上升和下降,右摇杆转动视角,每按一次 L 或 R 速度减半或加倍。游戏版本 1.4.3。", + [UI_MENU_FREECAM_PAD_V143] = "仅限游戏版本 1.4.3", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "游戏操作微调", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "启用操作微调", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "使用鼠标滚轮控制究极手物体旋转与距离、武器与道具切换以及地图平滑缩放。", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 51c8c2db..ca75c70e 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -154,6 +154,7 @@ typedef enum { UI_QS_SAVED, UI_QS_LOADING, UI_QS_NOT_NOW, UI_QS_NONE, UI_QS_FAILED, UI_QS_LOAD_FAILED, UI_MENU_MOUSE_SENS, UI_MENU_MOUSE_SENS_DESC, UI_MENU_WALK_KEY, UI_MENU_WALK_KEY_DESC, UI_MENU_WALK_KEY_TAKEN, UI_MENU_WALK_SCALE, UI_MENU_WALK_SCALE_DESC, + UI_MENU_FREECAM_PAD, UI_MENU_FREECAM_PAD_DESC, UI_MENU_FREECAM_PAD_V143, // Controls tab: Gameplay tweaks UI_MENU_GROUP_GAMEPLAY_TWEAKS, From 5fa6db3c7030e7c8731d71058da7aa62abf10cac Mon Sep 17 00:00:00 2001 From: lebomis <26766744+lebomis@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:24:37 +1100 Subject: [PATCH 4/9] The free camera works on the keyboard and mouse: freecam_key switches it, the bound keys fly it and the mouse turns it input.c freecam_gate also switches the free camera on a press of TOTK_FREECAM_KEY (f6 by default, none for no key). While it is on, ZL, ZR, L and R come from the merged Switch buttons, so the keys bound to them (Z, X, Q and R by default) go down, up and change the speed like the gamepad's; the keys' sticks already flew and turned it. The mouse's counts are taken in the poll and turn it at the game camera's rate (0.08 degrees a count times mouse_sens, through freecam_mouse), and input_direct_mouse_sample gives the game's mouse camera none meanwhile; in the stick emulation mode the mouse arrives in the right stick as before. The Controls tab gets a Free camera key row (off, F2 to F7, F9), with text in all four menu languages; docs/controls.md lists the keyboard column. Co-Authored-By: Claude Opus 5.5 --- docs/controls.md | 25 +++++++++++++------------ runtime/cfg.c | 6 +++--- runtime/freecam.c | 28 ++++++++++++++++++++++------ runtime/input.c | 45 ++++++++++++++++++++++++++++++++++++++------- runtime/input.h | 1 + runtime/ui/menu.cpp | 14 ++++++++++---- runtime/ui_text.c | 15 +++++++++++++++ runtime/ui_text.h | 1 + totk.ini.example | 3 +++ 9 files changed, 106 insertions(+), 32 deletions(-) diff --git a/docs/controls.md b/docs/controls.md index 5d498d62..0aa02978 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -131,20 +131,21 @@ bind_Y = pad:north, key:mouse_l ## Free camera -On game 1.4.3, ZL+ZR+L3 together (LT+RT+L3 on an Xbox pad; `freecam_pad` in `totk.ini` picks another combo, `none` none) -detach the view from Link; the same combo brings it back. The world goes on, but the game gets no gamepad input while the -free camera is on, so Link stands where he was. +On game 1.4.3, ZL+ZR+L3 together (LT+RT+L3 on an Xbox pad) or F6 detach the view from Link; the same combo or key brings +it back (`freecam_pad` and `freecam_key` in `totk.ini` and on the Controls tab pick others, `none` none). The world goes +on, but the game gets no input while the free camera is on, so Link stands where he was. -| Input | Free camera | -|---|---| -| Left stick | forward and back along the view, and sideways | -| ZR / ZL (RT / LT) | straight up / down, by how far the trigger is pressed | -| Right stick | turn (yaw and pitch; pitch stops 5 degrees short of straight up or down) | -| R / L (RB / LB) | each press doubles / halves the speed, 0.25 to 512 m/s | +| Gamepad | Keyboard and mouse (default bindings) | Free camera | +|---|---|---| +| Left stick | W A S D | forward and back along the view, and sideways | +| ZR / ZL (RT / LT) | X / Z | straight up / down; a trigger by how far it is pressed | +| Right stick | mouse, arrow keys | turn (yaw and pitch; pitch stops 5 degrees short of straight up or down) | +| R / L (RB / LB) | R / Q | each press doubles / halves the speed, 0.25 to 512 m/s | -The keys that drive the sticks (W A S D and the arrow keys by default) move it too. Each switch starts at the game -camera's position and view at 8 m/s; the speed follows the clock, so it is the same at any frame rate and game speed. -The horizon stays level. +The keys are the ones bound to the left and right stick and to ZR, ZL, R and L (`bind_` lines), so remapped keys follow. +The mouse turns the free camera at the game camera's rate (0.08 degrees a count at `mouse_sens = 1`) and the game's +mouse camera gets none of it meanwhile. Each switch starts at the game camera's position and view at 8 m/s; the speed +follows the clock, so it is the same at any frame rate and game speed. The horizon stays level. How it works (`runtime/freecam.c`): the camera component update (main+0x628460) copies each component's eye, target and up into its sead camera. The site `freecam` (`recomp/patches-v143.txt`, main+0x6286d4) runs before that copy and diff --git a/runtime/cfg.c b/runtime/cfg.c index 485eda3e..f6a3caa5 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -43,7 +43,7 @@ static const char *const known[] = { "COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT", "DESC_TEMPLATE", "DESWIZZLE", "DEVICE_PROFILE", "DIALOGUE_CLICK", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_CAM_JITTER", "DLAA_EFFECTS_AFTER", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_FIXED_EXPOSURE", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG", "DYNAMIC_RES", "DYN_DELTA", "EXEFS", "FEEDBACK", "FIXED_RES_PATCH", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", - "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_QUEUE", "FREECAM_PAD", "FREECAM_PATCH", + "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_QUEUE", "FREECAM_KEY", "FREECAM_PAD", "FREECAM_PATCH", "FREEZE_IDLE", "FREE_CORES", "FULLSCREEN", "FXAA", "GAMEPLAY_DISTANCE_SENSITIVITY", "GAMEPLAY_ITEM_AD", "GAMEPLAY_ITEM_SENSITIVITY", "GAMEPLAY_ITEM_WHEEL", @@ -99,7 +99,7 @@ static const struct { const char *key, *section; } sections[] = { {"GYRO_BIAS_X", "input"}, {"GYRO_BIAS_Y", "input"}, {"GYRO_BIAS_Z", "input"}, {"GYRO_BIAS_PAD", "input"}, {"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"LSTICK_DEADZONE", "input"}, {"RSTICK_DEADZONE", "input"}, {"STICK_SENS", "input"}, - {"MENU_CURSOR", "input"}, {"MAP_CLICK", "input"}, {"DIALOGUE_CLICK", "input"}, {"POINTER_IMAGE", "input"}, {"QUICKSAVE", "input"}, {"QUICKSAVE_KEY", "input"}, {"QUICKLOAD_KEY", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"FREECAM_PAD", "input"}, {"INPUT_RECORD", "input"}, + {"MENU_CURSOR", "input"}, {"MAP_CLICK", "input"}, {"DIALOGUE_CLICK", "input"}, {"POINTER_IMAGE", "input"}, {"QUICKSAVE", "input"}, {"QUICKSAVE_KEY", "input"}, {"QUICKLOAD_KEY", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"FREECAM_PAD", "input"}, {"FREECAM_KEY", "input"}, {"INPUT_RECORD", "input"}, {"BIND_A", "input"}, {"BIND_B", "input"}, {"BIND_X", "input"}, {"BIND_Y", "input"}, {"BIND_LCLICK", "input"}, {"BIND_RCLICK", "input"}, {"BIND_L", "input"}, {"BIND_R", "input"}, {"BIND_ZL", "input"}, {"BIND_ZR", "input"}, {"BIND_PLUS", "input"}, {"BIND_MINUS", "input"}, {"BIND_LEFT", "input"}, {"BIND_UP", "input"}, @@ -189,7 +189,7 @@ static const CfgMeta metas[] = { {"QUICKSAVE", "0", "0|1", LIVE}, // quicksave.c: one key saves (an autosave), another loads it {"QUICKSAVE_KEY", "f6", NULL, LIVE}, {"QUICKLOAD_KEY", "f7", NULL, LIVE}, // Half-Life's keys; a key name or none {"WALK_KEY", "none", NULL, LIVE}, {"WALK_SCALE", "0.51", "0.2..0.9", LIVE}, - {"FREECAM_PAD", "zl+zr+lstick", NULL, LIVE}, + {"FREECAM_PAD", "zl+zr+lstick", NULL, LIVE}, {"FREECAM_KEY", "f6", NULL, LIVE}, // Gameplay Tweaks {"GAMEPLAY_TWEAKS_ENABLED", "0", "0|1", LIVE}, {"GAMEPLAY_ULTRAHAND_ROTATE", "1", "0|1", LIVE}, {"GAMEPLAY_ULTRAHAND_C_AXIS", "1", "0|1", LIVE}, diff --git a/runtime/freecam.c b/runtime/freecam.c index 882cf707..60759e8f 100644 --- a/runtime/freecam.c +++ b/runtime/freecam.c @@ -21,10 +21,11 @@ // the anchor is driven. When no driven component has been updated for LOST_NS (a load replaced them) the next one // away from the default anchors again; the free camera keeps its own position. // -// Input (runtime/input.c freecam_gate): TOTK_FREECAM_PAD switches it, ZL+ZR+L3 by default. While it is on the game -// gets no gamepad input; the left stick flies along the view and to the side, the triggers straight up and down, the -// right stick turns, and each press of L or R halves or doubles the speed. Every driven component steps the flight by -// the wall-clock time since the last step, so the speed is the same at any frame rate and game speed. +// Input (runtime/input.c freecam_gate): TOTK_FREECAM_PAD (ZL+ZR+L3 by default) or TOTK_FREECAM_KEY (F6) switches +// it. While it is on the game gets no input; the left stick flies along the view and to the side, ZR and ZL straight +// up and down, the right stick and the mouse turn, and each press of L or R halves or doubles the speed. Keys work +// through their bindings: the keys' sticks, and the keys bound to ZL, ZR, L and R. Every driven component steps the +// flight by the wall-clock time since the last step, so the speed is the same at any frame rate and game speed. #include #include #include @@ -53,6 +54,7 @@ static PlatMutex pad_lock = PLAT_MUTEX_INIT; static FreecamPad pad_now; // the last poll's input (input thread), under pad_lock static int speed_clicks; // R presses minus L presses not yet applied (input thread adds, the hook takes) +static double mouse_deg[2]; // under pad_lock: mouse turn not yet applied, degrees (right +, down +) // + 1 at every switch (input thread); odd while the free camera is on. One value, so the hook never sees a switch // without the state it switched to. static unsigned generation; @@ -65,6 +67,13 @@ void freecam_pad(const FreecamPad *p) { plat_mutex_unlock(&pad_lock); } +void freecam_mouse(double right_deg, double down_deg) { + plat_mutex_lock(&pad_lock); + mouse_deg[0] += right_deg; + mouse_deg[1] += down_deg; + plat_mutex_unlock(&pad_lock); +} + void freecam_speed_click(int faster) { __atomic_add_fetch(&speed_clicks, faster ? 1 : -1, __ATOMIC_RELAXED); } #ifdef RT_PATCH_PAGE @@ -164,8 +173,11 @@ static void step(uint64_t now) { if (dt <= 0) return; if (dt > STEP_MAX_S) dt = STEP_MAX_S; FreecamPad p; + double mouse[2]; plat_mutex_lock(&pad_lock); p = pad_now; + mouse[0] = mouse_deg[0], mouse[1] = mouse_deg[1]; + mouse_deg[0] = mouse_deg[1] = 0; plat_mutex_unlock(&pad_lock); int clicks = __atomic_exchange_n(&speed_clicks, 0, __ATOMIC_RELAXED); if (clicks) { @@ -173,8 +185,9 @@ static void step(uint64_t now) { fc.speed = fc.speed < SPEED_MIN ? SPEED_MIN : fc.speed > SPEED_MAX ? SPEED_MAX : fc.speed; } double turn = TURN_DEG_S * M_PI / 180 * dt, limit = PITCH_MAX_DEG * M_PI / 180; - fc.yaw = remainder(fc.yaw - axis(p.rx) * turn, 2 * M_PI); // right turns towards -yaw (see right[] below) - fc.pitch += axis(p.ry) * turn; + // right turns towards -yaw (see right[] below); the mouse's degrees come on top of the stick's + fc.yaw = remainder(fc.yaw - axis(p.rx) * turn - mouse[0] * M_PI / 180, 2 * M_PI); + fc.pitch += axis(p.ry) * turn - mouse[1] * M_PI / 180; fc.pitch = fc.pitch > limit ? limit : fc.pitch < -limit ? -limit : fc.pitch; double d[3], right[3]; direction(d); @@ -211,6 +224,9 @@ static void freecam_hook(Cpu *c) { if (gen != fc.generation) { // a switch: a new flight starts at the game camera, at the start speed fc.generation = gen; fc.started = 0, fc.anchored = 0, fc.speed = SPEED_START; + plat_mutex_lock(&pad_lock); // mouse motion from before the switch does not turn the new flight + mouse_deg[0] = mouse_deg[1] = 0; + plat_mutex_unlock(&pad_lock); } uint64_t now = plat_now_ns(); int i = driven_index(cam); diff --git a/runtime/input.c b/runtime/input.c index c15ac48c..e12fce7f 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -267,7 +267,7 @@ static void rec_apply(uint64_t b, const int32_t sl[2], const int32_t sr[2]) { void input_direct_mouse_sample(int enabled, int32_t *dx, int32_t *dy) { plat_mutex_lock(&lock); - enabled = enabled && !g_block && !g_menu; + enabled = enabled && !g_block && !g_menu && !freecam_on(); // the free camera takes the mouse (freecam_gate) *dx = script_mouse[0]; *dy = script_mouse[1]; script_mouse[0] = script_mouse[1] = 0; if (!enabled) { *dx = *dy = 0; } @@ -830,17 +830,35 @@ static uint32_t freecam_pad_mask(void) { return mask; } +// TOTK_FREECAM_KEY (live): the key that switches the free camera, f6 by default (the settings table), none for no key. +// Under lock. +static int freecam_key(void) { + static unsigned seen; + static int read, key; + unsigned v = cfg_version(); + if (read && v == seen) return key; + read = 1, seen = v; + const char *s = cfg_value("TOTK_FREECAM_KEY"); + key = !*s || !strcasecmp(s, "none") ? KEY_NONE : input_key_id(s); + if (key == KEY_NONE && *s && strcasecmp(s, "none")) + rt_log("input: TOTK_FREECAM_KEY=%s is not a key name (docs/controls.md)", s); + return key; +} + static float trigger_unit(int16_t v) { // 0..1 past a 5 % dead zone float t = v / 32767.0f; return t < 0.05f ? 0 : (t - 0.05f) / 0.95f; } // The free camera combo, latched like Minus+Plus (input_map.c, chord): once every button of it is down the free -// camera switches once, and the buttons stay hidden from the game until all are released. While the free camera is on -// it gets the gamepad (and the keys' sticks, merged into sl and sr) and the game gets nothing, so Link stands still; -// each press of L or R is a speed click. Off for other updates and with the freecam patch set off. Under lock. +// camera switches once, and the buttons stay hidden from the game until all are released; the free camera key +// switches it on its press. While the free camera is on it gets the input and the game gets nothing, so Link stands +// still: the sticks (the keys' sticks merged into sl and sr), the trigger axes or else ZL and ZR as buttons, a press of +// L or R as a speed click, and the mouse's motion, which input_direct_mouse_sample then keeps from the game's camera. +// ZL, ZR, L and R are the merged Switch buttons, so the keys bound to them count. Off for other updates and with the +// freecam patch set off. Under lock. static void freecam_gate(uint64_t *b, int32_t sl[2], int32_t sr[2]) { - static int held, available = -1, shoulder[2]; + static int held, key_held, available = -1, shoulder[2]; if (available < 0) available = freecam_available(); uint32_t mask = available ? freecam_pad_mask() : 0, raw = 0; for (int p = PAD_SOUTH; p <= PAD_GUIDE; p++) @@ -851,15 +869,28 @@ static void freecam_gate(uint64_t *b, int32_t sl[2], int32_t sr[2]) { held = 1; freecam_toggle(); } + int key = available ? freecam_key() : KEY_NONE; + int key_down = key != KEY_NONE && ikb_foreground() && ikb_down(key); + if (key_down && !key_held) freecam_toggle(); + key_held = key_down; if (available && freecam_on()) { + float lt = trigger_unit(trigger_seen[0]), rt = trigger_unit(trigger_seen[1]); + if (*b >> B_ZL & 1) lt = 1; + if (*b >> B_ZR & 1) rt = 1; FreecamPad fp = {sl[0] / (float)STICK_MAX, sl[1] / (float)STICK_MAX, sr[0] / (float)STICK_MAX, - sr[1] / (float)STICK_MAX, trigger_unit(trigger_seen[0]), trigger_unit(trigger_seen[1])}; + sr[1] / (float)STICK_MAX, lt, rt}; freecam_pad(&fp); for (int k = 0; k < 2; k++) { - int down = pad_seen[k ? PAD_R : PAD_L]; + int down = (int)(*b >> (k ? B_R : B_L) & 1); if (down && !shoulder[k]) freecam_speed_click(k); shoulder[k] = down; } + if (ikb_captured() && ikb_foreground() && input_cursor_allowed()) { + int32_t x, y; + ikb_mouse_take(&x, &y); // what the stick emulation left (none in that mode: it is in sr already) + float deg = 0.08f * mouse_sens_get(); // the game camera's rate a count (mouse_direct.c DEG_PER_COUNT) + if (x || y) freecam_mouse(x * deg, y * deg); + } *b = 0; sl[0] = sl[1] = sr[0] = sr[1] = 0; return; diff --git a/runtime/input.h b/runtime/input.h index 80a218a0..cad3a1f3 100644 --- a/runtime/input.h +++ b/runtime/input.h @@ -107,6 +107,7 @@ int freecam_on(void); void freecam_toggle(void); // logs; input thread void freecam_pad(const FreecamPad *p); void freecam_speed_click(int faster); // R (1) doubles the speed, L (0) halves it +void freecam_mouse(double right_deg, double down_deg); // a turn from the mouse, added at the next step // How far the open gamepad's left (pct[0]) and right (pct[1]) sticks are from the centre now, in percent of full // deflection, before the dead zone: the menu shows it on the dead zone rows, so a drifting stick's resting value can be // read off. 0 (and both 0) without a connected gamepad. Any thread. diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index dcbdca7c..b8eb708a 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -944,9 +944,10 @@ static void row_quicksave_keys(void) { key_taken("TOTK_QUICKLOAD_KEY", note[1], sizeof note[1])); } -// The free camera combo (freecam.c): the trigger and shoulder pairs with a stick click, named as the open pad labels -// its buttons, or none. totk.ini takes any combo of button positions, shown as written. Off on other game versions. -static void row_freecam_pad(void) { +// The free camera combo and key (freecam.c): the trigger and shoulder pairs with a stick click, named as the open pad +// labels its buttons, or none. totk.ini takes any combo of button positions, shown as written. Off on other game +// versions. +static void rows_freecam(void) { static const char *const combos[] = {"zl+zr+lstick", "zl+zr+rstick", "l+r+lstick", "l+r+rstick", "none"}; static const int pads[][3] = {{PAD_ZL, PAD_ZR, PAD_LSTICK}, {PAD_ZL, PAD_ZR, PAD_RSTICK}, {PAD_L, PAD_R, PAD_LSTICK}, {PAD_L, PAD_R, PAD_RSTICK}}; @@ -961,6 +962,11 @@ static void row_freecam_pad(void) { names[N - 1] = menu_text(UI_MENU_OFF); if (!freecam_available()) opt_disable_next(UI_MENU_FREECAM_PAD_V143); opt_choice_list("TOTK_FREECAM_PAD", UI_MENU_FREECAM_PAD, combos, names, N, UI_MENU_FREECAM_PAD_DESC); + // The free camera key: keys no default binding uses ("none" rather than an empty value turns it off: unset is f6) + static const char *const keys[] = {"none", "f2", "f3", "f4", "f5", "f6", "f7", "f9"}; + const char *key_names[] = {menu_text(UI_MENU_OFF), "F2", "F3", "F4", "F5", "F6", "F7", "F9"}; + if (!freecam_available()) opt_disable_next(UI_MENU_FREECAM_PAD_V143); + opt_choice_list("TOTK_FREECAM_KEY", UI_MENU_FREECAM_KEY, keys, key_names, 8, UI_MENU_FREECAM_KEY_DESC); } // The note under the prompts. The settings name a folder of prompts (input_prompts_folder: the prompts and the pad @@ -1103,7 +1109,7 @@ static void tab_controls(float scale) { row_quicksave_keys(); row_walk_key(); opt_slider("TOTK_WALK_SCALE", UI_MENU_WALK_SCALE, 0.2f, 0.9f, UI_MENU_WALK_SCALE_DESC, 0.01f, "%.2f"); - row_freecam_pad(); + rows_freecam(); rows_gameplay_tweaks(); // Analog sticks: one dead zone row per stick, falling back to TOTK_STICK_DEADZONE (both sticks) while unset. With // a gamepad connected each row shows its stick's deflection now, before the dead zone: a drifting stick's resting diff --git a/runtime/ui_text.c b/runtime/ui_text.c index abd56a73..e4c1b8a5 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -363,6 +363,10 @@ static const char *const text_en[UI_TEXT_COUNT] = { "While it is on the game gets no input: the left stick flies along the view and sideways, the triggers up and " "down, the right stick turns, and each press of L or R halves or doubles the speed. Game version 1.4.3.", [UI_MENU_FREECAM_PAD_V143] = "Game version 1.4.3 only", + [UI_MENU_FREECAM_KEY] = "Free camera key", + [UI_MENU_FREECAM_KEY_DESC] = "A key that detaches the view from Link and brings it back. While it is on: W A S D " + "fly along the view and sideways, the keys bound to ZR and ZL (X and Z by default) up and down, the mouse and " + "the arrow keys turn, and the keys bound to L and R (Q and R) halve or double the speed. Game version 1.4.3.", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Gameplay tweaks", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Gameplay tweaks", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Mouse wheel controls for Ultrahand rotation and distance, item and weapon switching, and smooth map zoom.", @@ -979,6 +983,10 @@ static const char *const text_ru[UI_TEXT_COUNT] = { "включена, игра не получает ввод: левый стик ведёт камеру вдоль взгляда и вбок, курки — вверх и вниз, правый " "стик поворачивает, а каждое нажатие L или R уменьшает или увеличивает скорость вдвое. Версия игры 1.4.3.", [UI_MENU_FREECAM_PAD_V143] = "Только для версии игры 1.4.3", + [UI_MENU_FREECAM_KEY] = "Клавиша свободной камеры", + [UI_MENU_FREECAM_KEY_DESC] = "Клавиша, которая отделяет камеру от Линка и возвращает её. Пока она включена: W A S " + "D ведут камеру вдоль взгляда и вбок, клавиши ZR и ZL (по умолчанию X и Z) — вверх и вниз, мышь и стрелки " + "поворачивают, а клавиши L и R (Q и R) уменьшают или увеличивают скорость вдвое. Версия игры 1.4.3.", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Геймплей", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Настройки геймплея", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Управление колесом мыши: вращение и дистанция предметов в Ультраруке, выбор оружия и предметов, плавный зум карты.", @@ -1787,6 +1795,11 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { "para os lados, os gatilhos sobem e descem, o analógico direito gira, e cada toque em L ou R reduz a " "velocidade à metade ou a dobra. Versão do jogo 1.4.3.", [UI_MENU_FREECAM_PAD_V143] = "Só na versão 1.4.3 do jogo", + [UI_MENU_FREECAM_KEY] = "Tecla da câmera livre", + [UI_MENU_FREECAM_KEY_DESC] = "Uma tecla que solta a câmera do Link e a traz de volta. Enquanto ela está ligada: W " + "A S D voam na direção da visão e para os lados, as teclas de ZR e ZL (X e Z por padrão) sobem e descem, o " + "mouse e as setas giram, e as teclas de L e R (Q e R) reduzem a velocidade à metade ou a dobram. Versão do " + "jogo 1.4.3.", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Ajustes de jogabilidade", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Ajustes de jogabilidade", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Controles com a roda do mouse para rotação e distância na Ultramão, seleção de armas e itens, e zoom suave no mapa.", @@ -2539,6 +2552,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_FREECAM_PAD] = "自由镜头组合键", [UI_MENU_FREECAM_PAD_DESC] = "同时按下的手柄按键,让镜头脱离林克,再按一次回到林克。开启期间游戏不接收输入:左摇杆沿视线方向和左右移动,扳机键上升和下降,右摇杆转动视角,每按一次 L 或 R 速度减半或加倍。游戏版本 1.4.3。", [UI_MENU_FREECAM_PAD_V143] = "仅限游戏版本 1.4.3", + [UI_MENU_FREECAM_KEY] = "自由镜头键", + [UI_MENU_FREECAM_KEY_DESC] = "让镜头脱离林克、再按一次回到林克的按键。开启期间:W A S D 沿视线方向和左右移动,ZR 和 ZL 对应的按键(默认 X 和 Z)上升和下降,鼠标和方向键转动视角,L 和 R 对应的按键(默认 Q 和 R)让速度减半或加倍。游戏版本 1.4.3。", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "游戏操作微调", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "启用操作微调", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "使用鼠标滚轮控制究极手物体旋转与距离、武器与道具切换以及地图平滑缩放。", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index ca75c70e..f3d398e3 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -155,6 +155,7 @@ typedef enum { UI_MENU_MOUSE_SENS, UI_MENU_MOUSE_SENS_DESC, UI_MENU_WALK_KEY, UI_MENU_WALK_KEY_DESC, UI_MENU_WALK_KEY_TAKEN, UI_MENU_WALK_SCALE, UI_MENU_WALK_SCALE_DESC, UI_MENU_FREECAM_PAD, UI_MENU_FREECAM_PAD_DESC, UI_MENU_FREECAM_PAD_V143, + UI_MENU_FREECAM_KEY, UI_MENU_FREECAM_KEY_DESC, // Controls tab: Gameplay tweaks UI_MENU_GROUP_GAMEPLAY_TWEAKS, diff --git a/totk.ini.example b/totk.ini.example index d81f7eea..4302ed6f 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -485,6 +485,9 @@ # the triggers straight up and down, the right stick turns; each press of L halves the speed, of R doubles it # (docs/controls.md, "Free camera"). none turns the combo off. Default: zl+zr+lstick (LT+RT+L3 on an Xbox pad). # freecam_pad = zl+zr+lstick +# A key that does the same, by its name in the bind_ lines; on the keyboard the keys bound to the sticks fly and turn, +# the keys of ZR and ZL go up and down, those of R and L change the speed, and the mouse turns. none turns it off. +# freecam_key = f6 # Write the input of this run to a file that replays as a script (docs/controls.md, "Scripted input"). Default: off. # input_record = input.txt # Remap buttons: the Controls tab of the settings menu (F1) writes these lines. One line per Switch button or stick From 88f9a965aff3f70c32fc1ef4296a61af5c9bc5d8 Mon Sep 17 00:00:00 2001 From: lebomis <26766744+lebomis@users.noreply.github.com> Date: Tue, 17 Nov 2026 00:15:51 +1100 Subject: [PATCH 5/9] Change freecam default binds for keyboard and controller to `none`, configurable through totk.ini or the Controls tab. freecam_key and freecam_pad were F6 and ZL+ZR+L3 for everyone, potentially causing unwanted toggles. F6 is also the quick save key of #1188. Both are none now. runtime/cfg.c: the FREECAM_PAD and FREECAM_KEY rows of the settings table default to none. runtime/input.c freecam_pad_mask reads the combo with cfg_value instead of falling back to its own zl+zr+lstick, so an unset combo is the table's none like the key. The comments in runtime/freecam.c, runtime/input.c and runtime/ui/menu.cpp rows_freecam, docs/controls.md ("Free camera") and totk.ini.example say so and keep F6 and ZL+ZR+L3 as examples. Co-Authored-By: Claude Opus 5.5 --- docs/controls.md | 7 ++++--- runtime/cfg.c | 2 +- runtime/freecam.c | 11 ++++++----- runtime/input.c | 11 +++++------ runtime/ui/menu.cpp | 2 +- totk.ini.example | 3 ++- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/docs/controls.md b/docs/controls.md index 0aa02978..0b628186 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -131,9 +131,10 @@ bind_Y = pad:north, key:mouse_l ## Free camera -On game 1.4.3, ZL+ZR+L3 together (LT+RT+L3 on an Xbox pad) or F6 detach the view from Link; the same combo or key brings -it back (`freecam_pad` and `freecam_key` in `totk.ini` and on the Controls tab pick others, `none` none). The world goes -on, but the game gets no input while the free camera is on, so Link stands where he was. +On game 1.4.3, a chosen gamepad combo or a key activates or deactivates the free camera. Neither is set by default: pick +them with `freecam_pad` and `freecam_key` in `totk.ini` or on the Controls tab (for example ZL+ZR+L3, LT+RT+L3 on an +Xbox pad, and F6; `none` turns one off). The world goes on, but the game gets no input while the free camera is on, so +Link stands where he was. | Gamepad | Keyboard and mouse (default bindings) | Free camera | |---|---|---| diff --git a/runtime/cfg.c b/runtime/cfg.c index f6a3caa5..6a5bcec1 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -189,7 +189,7 @@ static const CfgMeta metas[] = { {"QUICKSAVE", "0", "0|1", LIVE}, // quicksave.c: one key saves (an autosave), another loads it {"QUICKSAVE_KEY", "f6", NULL, LIVE}, {"QUICKLOAD_KEY", "f7", NULL, LIVE}, // Half-Life's keys; a key name or none {"WALK_KEY", "none", NULL, LIVE}, {"WALK_SCALE", "0.51", "0.2..0.9", LIVE}, - {"FREECAM_PAD", "zl+zr+lstick", NULL, LIVE}, {"FREECAM_KEY", "f6", NULL, LIVE}, + {"FREECAM_PAD", "none", NULL, LIVE}, {"FREECAM_KEY", "none", NULL, LIVE}, // Gameplay Tweaks {"GAMEPLAY_TWEAKS_ENABLED", "0", "0|1", LIVE}, {"GAMEPLAY_ULTRAHAND_ROTATE", "1", "0|1", LIVE}, {"GAMEPLAY_ULTRAHAND_C_AXIS", "1", "0|1", LIVE}, diff --git a/runtime/freecam.c b/runtime/freecam.c index 60759e8f..9eb71bd3 100644 --- a/runtime/freecam.c +++ b/runtime/freecam.c @@ -21,11 +21,12 @@ // the anchor is driven. When no driven component has been updated for LOST_NS (a load replaced them) the next one // away from the default anchors again; the free camera keeps its own position. // -// Input (runtime/input.c freecam_gate): TOTK_FREECAM_PAD (ZL+ZR+L3 by default) or TOTK_FREECAM_KEY (F6) switches -// it. While it is on the game gets no input; the left stick flies along the view and to the side, ZR and ZL straight -// up and down, the right stick and the mouse turn, and each press of L or R halves or doubles the speed. Keys work -// through their bindings: the keys' sticks, and the keys bound to ZL, ZR, L and R. Every driven component steps the -// flight by the wall-clock time since the last step, so the speed is the same at any frame rate and game speed. +// Input (runtime/input.c freecam_gate): TOTK_FREECAM_PAD or TOTK_FREECAM_KEY switches it (both none by default, so the +// player opts in). While it is on the game gets no input; the left stick flies along the view and to the side, ZR and +// ZL straight up and down, the right stick and the mouse turn, and each press of L or R halves or doubles the speed. +// Keys work through their bindings: the keys' sticks, and the keys bound to ZL, ZR, L and R. Every driven component +// steps the flight by the wall-clock time since the last step, so the speed is the same at any frame rate and game +// speed. #include #include #include diff --git a/runtime/input.c b/runtime/input.c index e12fce7f..aef76cd6 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -815,8 +815,8 @@ uint32_t input_pad_combo(const char *env, const char *s) { return mask; } -// TOTK_FREECAM_PAD (live): the combo that switches the free camera (freecam.c); zl+zr+lstick (LT+RT+L3) when unset, -// none for no combo. Under lock. +// TOTK_FREECAM_PAD (live): the combo that switches the free camera (freecam.c), for example zl+zr+lstick (LT+RT+L3); +// none, the default (the settings table), for no combo. Under lock. static uint32_t freecam_pad_mask(void) { static unsigned seen; static int read; @@ -824,13 +824,12 @@ static uint32_t freecam_pad_mask(void) { unsigned v = cfg_version(); if (read && v == seen) return mask; read = 1, seen = v; - const char *s = cfg_get("TOTK_FREECAM_PAD"); - if (!s || !*s) s = "zl+zr+lstick"; - mask = strcasecmp(s, "none") ? input_pad_combo("TOTK_FREECAM_PAD", s) : 0; + const char *s = cfg_value("TOTK_FREECAM_PAD"); + mask = *s && strcasecmp(s, "none") ? input_pad_combo("TOTK_FREECAM_PAD", s) : 0; return mask; } -// TOTK_FREECAM_KEY (live): the key that switches the free camera, f6 by default (the settings table), none for no key. +// TOTK_FREECAM_KEY (live): the key that switches the free camera; none, the default (the settings table), for no key. // Under lock. static int freecam_key(void) { static unsigned seen; diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index b8eb708a..5b7a9812 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -962,7 +962,7 @@ static void rows_freecam(void) { names[N - 1] = menu_text(UI_MENU_OFF); if (!freecam_available()) opt_disable_next(UI_MENU_FREECAM_PAD_V143); opt_choice_list("TOTK_FREECAM_PAD", UI_MENU_FREECAM_PAD, combos, names, N, UI_MENU_FREECAM_PAD_DESC); - // The free camera key: keys no default binding uses ("none" rather than an empty value turns it off: unset is f6) + // The free camera key: keys no default binding uses (none, the default, turns it off) static const char *const keys[] = {"none", "f2", "f3", "f4", "f5", "f6", "f7", "f9"}; const char *key_names[] = {menu_text(UI_MENU_OFF), "F2", "F3", "F4", "F5", "F6", "F7", "F9"}; if (!freecam_available()) opt_disable_next(UI_MENU_FREECAM_PAD_V143); diff --git a/totk.ini.example b/totk.ini.example index 4302ed6f..cbba2bea 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -483,10 +483,11 @@ # Free camera (game 1.4.3): the gamepad combo that switches it, buttons by position joined with +, the pad: names of the # bind_ lines. While it is on the game gets no input and the view flies: the left stick along the view and sideways, # the triggers straight up and down, the right stick turns; each press of L halves the speed, of R doubles it -# (docs/controls.md, "Free camera"). none turns the combo off. Default: zl+zr+lstick (LT+RT+L3 on an Xbox pad). +# (docs/controls.md, "Free camera"). none turns the combo off. Default: none; # freecam_pad = zl+zr+lstick # A key that does the same, by its name in the bind_ lines; on the keyboard the keys bound to the sticks fly and turn, # the keys of ZR and ZL go up and down, those of R and L change the speed, and the mouse turns. none turns it off. +# Default: none. # freecam_key = f6 # Write the input of this run to a file that replays as a script (docs/controls.md, "Scripted input"). Default: off. # input_record = input.txt From 8dfc3609c4d55066cb583e69ff182d75025e275f Mon Sep 17 00:00:00 2001 From: lebomis <26766744+lebomis@users.noreply.github.com> Date: Tue, 17 Nov 2026 00:29:36 +1100 Subject: [PATCH 6/9] The free camera combo also switches from the keys bound to its buttons and from an input script. freecam_gate read the combo from the physical gamepad only, so a tester's input script that pressed ZL+ZR+L3 sent it to the game instead (#1213). Each position of the combo now also counts when the Switch buttons it stands for are down in the merged buttons, as the Minus+Plus menu combo already does; Home has no Switch button and stays gamepad only. Co-Authored-By: Claude Opus 5.5 --- docs/controls.md | 5 +++-- runtime/input.c | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/docs/controls.md b/docs/controls.md index 0b628186..c49bd34a 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -133,8 +133,9 @@ bind_Y = pad:north, key:mouse_l On game 1.4.3, a chosen gamepad combo or a key activates or deactivates the free camera. Neither is set by default: pick them with `freecam_pad` and `freecam_key` in `totk.ini` or on the Controls tab (for example ZL+ZR+L3, LT+RT+L3 on an -Xbox pad, and F6; `none` turns one off). The world goes on, but the game gets no input while the free camera is on, so -Link stands where he was. +Xbox pad, and F6; `none` turns one off). The combo's buttons also count when they come from the keys bound to them or +from an input script. The world goes on, but the game gets no input while the free camera is on, so Link stands where he +was. | Gamepad | Keyboard and mouse (default bindings) | Free camera | |---|---|---| diff --git a/runtime/input.c b/runtime/input.c index aef76cd6..0473da17 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -849,19 +849,26 @@ static float trigger_unit(int16_t v) { // 0..1 past a 5 % dead zone return t < 0.05f ? 0 : (t - 0.05f) / 0.95f; } -// The free camera combo, latched like Minus+Plus (input_map.c, chord): once every button of it is down the free -// camera switches once, and the buttons stay hidden from the game until all are released; the free camera key -// switches it on its press. While the free camera is on it gets the input and the game gets nothing, so Link stands -// still: the sticks (the keys' sticks merged into sl and sr), the trigger axes or else ZL and ZR as buttons, a press of -// L or R as a speed click, and the mouse's motion, which input_direct_mouse_sample then keeps from the game's camera. -// ZL, ZR, L and R are the merged Switch buttons, so the keys bound to them count. Off for other updates and with the -// freecam patch set off. Under lock. +// The free camera combo, latched like Minus+Plus (input_map.c, chord): once every button of it is down (on the gamepad, +// or as the merged Switch buttons from bound keys or an input script) the free camera switches once, and the buttons +// stay hidden from the game until all are released; the free camera key switches it on its press. While the free camera +// is on it gets the input and the game gets nothing, so Link stands still: the sticks (the keys' sticks merged into sl +// and sr), the trigger axes or else ZL and ZR as buttons, a press of L or R as a speed click, and the mouse's motion, +// which input_direct_mouse_sample then keeps from the game's camera. ZL, ZR, L and R are the merged Switch buttons, so +// the keys bound to them count. Off for other updates and with the freecam patch set off. Under lock. static void freecam_gate(uint64_t *b, int32_t sl[2], int32_t sr[2]) { static int held, key_held, available = -1, shoulder[2]; if (available < 0) available = freecam_available(); uint32_t mask = available ? freecam_pad_mask() : 0, raw = 0; - for (int p = PAD_SOUTH; p <= PAD_GUIDE; p++) - if (mask >> p & 1 && pad_seen[p]) raw |= 1u << p; + int layout = pad_layout_get(); + for (int p = PAD_SOUTH; p <= PAD_GUIDE; p++) { + if (!(mask >> p & 1)) continue; + // A position counts as down on the gamepad or through the Switch buttons it stands for in the merged buttons, + // so the keys bound to them and an input script press the combo too. Home has no Switch button: gamepad only. + uint8_t one[PAD_COUNT] = {0}; + if (p < PAD_COUNT) one[p] = 1; + if (pad_seen[p] || (p < PAD_COUNT && *b & input_map_pad_buttons(one, layout))) raw |= 1u << p; + } if (!mask) held = 0; else if (held) held = raw != 0; else if (raw == mask) { From 58930c152c3c8a4df9a62a14a9b6533c0d28420a Mon Sep 17 00:00:00 2001 From: lebomis <26766744+lebomis@users.noreply.github.com> Date: Tue, 17 Nov 2026 00:46:57 +1100 Subject: [PATCH 7/9] The free camera combo counts the gamepad and an input script, not the keys bound to its buttons. The previous commit read the combo from the merged buttons, where a key bound to ZL is the same bit as the left trigger: with freecam_pad = zl+zr, the right mouse button and F switched the free camera in play. The keyboard has freecam_key for that, so the gamepad combo now counts the gamepad and the input script, which stands in for one. runtime/input.c poll_merged: script_apply writes its buttons into script_seen, which is then merged into the buttons as before. freecam_gate counts a position of the combo when pad_seen has it or script_seen has the Switch buttons it stands for; Home stays gamepad only. docs/controls.md ("Free camera") says so. Co-Authored-By: Claude Opus 5.5 --- docs/controls.md | 5 ++--- runtime/input.c | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/docs/controls.md b/docs/controls.md index c49bd34a..a5072ee2 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -133,9 +133,8 @@ bind_Y = pad:north, key:mouse_l On game 1.4.3, a chosen gamepad combo or a key activates or deactivates the free camera. Neither is set by default: pick them with `freecam_pad` and `freecam_key` in `totk.ini` or on the Controls tab (for example ZL+ZR+L3, LT+RT+L3 on an -Xbox pad, and F6; `none` turns one off). The combo's buttons also count when they come from the keys bound to them or -from an input script. The world goes on, but the game gets no input while the free camera is on, so Link stands where he -was. +Xbox pad, and F6; `none` turns one off). An input script can press the combo as a gamepad would; the keys bound to its +buttons do not. The world goes on, but the game gets no input while the free camera is on, so Link stands where he was. | Gamepad | Keyboard and mouse (default bindings) | Free camera | |---|---|---| diff --git a/runtime/input.c b/runtime/input.c index 0473da17..95a057f2 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -146,6 +146,10 @@ static void script_load(void) { rt_log("input: script %s, %d events", path, script_n); } +// Under lock: the Switch buttons the input script pressed in the last poll, apart from the keys' and the gamepad's, so +// a gamepad combo can count a scripted press as the gamepad's without counting the keys bound to the same buttons +static uint64_t script_seen; + static void script_apply(uint64_t *b, int32_t sl[2], int32_t sr[2]) { if (!script_state) script_load(); if (!script_n) return; @@ -850,12 +854,12 @@ static float trigger_unit(int16_t v) { // 0..1 past a 5 % dead zone } // The free camera combo, latched like Minus+Plus (input_map.c, chord): once every button of it is down (on the gamepad, -// or as the merged Switch buttons from bound keys or an input script) the free camera switches once, and the buttons -// stay hidden from the game until all are released; the free camera key switches it on its press. While the free camera -// is on it gets the input and the game gets nothing, so Link stands still: the sticks (the keys' sticks merged into sl -// and sr), the trigger axes or else ZL and ZR as buttons, a press of L or R as a speed click, and the mouse's motion, -// which input_direct_mouse_sample then keeps from the game's camera. ZL, ZR, L and R are the merged Switch buttons, so -// the keys bound to them count. Off for other updates and with the freecam patch set off. Under lock. +// or pressed by an input script) the free camera switches once, and the buttons stay hidden from the game until all are +// released; the free camera key switches it on its press. While the free camera is on it gets the input and the game +// gets nothing, so Link stands still: the sticks (the keys' sticks merged into sl and sr), the trigger axes or else ZL +// and ZR as buttons, a press of L or R as a speed click, and the mouse's motion, which input_direct_mouse_sample then +// keeps from the game's camera. ZL, ZR, L and R are the merged Switch buttons, so the keys bound to them count. Off for +// other updates and with the freecam patch set off. Under lock. static void freecam_gate(uint64_t *b, int32_t sl[2], int32_t sr[2]) { static int held, key_held, available = -1, shoulder[2]; if (available < 0) available = freecam_available(); @@ -863,11 +867,12 @@ static void freecam_gate(uint64_t *b, int32_t sl[2], int32_t sr[2]) { int layout = pad_layout_get(); for (int p = PAD_SOUTH; p <= PAD_GUIDE; p++) { if (!(mask >> p & 1)) continue; - // A position counts as down on the gamepad or through the Switch buttons it stands for in the merged buttons, - // so the keys bound to them and an input script press the combo too. Home has no Switch button: gamepad only. + // A position counts as down on the gamepad or when the input script presses the Switch buttons it stands for, + // as a gamepad would; the keys bound to those buttons do not (the free camera key is theirs). Home has no + // Switch button: gamepad only. uint8_t one[PAD_COUNT] = {0}; if (p < PAD_COUNT) one[p] = 1; - if (pad_seen[p] || (p < PAD_COUNT && *b & input_map_pad_buttons(one, layout))) raw |= 1u << p; + if (pad_seen[p] || (p < PAD_COUNT && script_seen & input_map_pad_buttons(one, layout))) raw |= 1u << p; } if (!mask) held = 0; else if (held) held = raw != 0; @@ -1017,7 +1022,9 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx if (pad_used) __atomic_store_n(&g_kbm_last, 0, __ATOMIC_RELAXED); else if (kbm_used) __atomic_store_n(&g_kbm_last, 1, __ATOMIC_RELAXED); } - script_apply(&b, sl, sr); + script_seen = 0; + script_apply(&script_seen, sl, sr); + b |= script_seen; wheel_route(&b, sl, sr); gameplay_tweaks_apply(__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED), input_gameplay_active(), &b, &sl[0], &sl[1], &sr[0], &sr[1]); rec_apply(b, sl, sr); From 5fdacca237b2b29d8b3758f0eda80d40255bcd4a Mon Sep 17 00:00:00 2001 From: lebomis <26766744+lebomis@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:50:44 +1100 Subject: [PATCH 8/9] The free camera steps through move, lock and off: locked, the view stays and Link walks where the left stick points on screen Co-Authored-By: Claude Opus 5.5 --- docs/controls.md | 16 ++++++++++----- runtime/freecam.c | 39 +++++++++++++++++++----------------- runtime/input.c | 24 ++++++++++++---------- runtime/input.h | 10 ++++++---- runtime/ui_text.c | 51 +++++++++++++++++++++++++++-------------------- totk.ini.example | 11 +++++----- 6 files changed, 86 insertions(+), 65 deletions(-) diff --git a/docs/controls.md b/docs/controls.md index a5072ee2..e9e1de90 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -131,10 +131,15 @@ bind_Y = pad:north, key:mouse_l ## Free camera -On game 1.4.3, a chosen gamepad combo or a key activates or deactivates the free camera. Neither is set by default: pick -them with `freecam_pad` and `freecam_key` in `totk.ini` or on the Controls tab (for example ZL+ZR+L3, LT+RT+L3 on an -Xbox pad, and F6; `none` turns one off). An input script can press the combo as a gamepad would; the keys bound to its -buttons do not. The world goes on, but the game gets no input while the free camera is on, so Link stands where he was. +On game 1.4.3, a chosen gamepad combo or a key steps the free camera through three stages: move, lock, and off again. +Neither is set by default: pick them with `freecam_pad` and `freecam_key` in `totk.ini` or on the Controls tab (for +example ZL+ZR+L3, LT+RT+L3 on an Xbox pad, and F2; `none` turns one off). An input script can press the combo as a +gamepad would; the keys bound to its buttons do not. While the free camera moves, the world goes on but the game gets +no input, so Link stands where he was. + +Locked, the view stays where the flight left it and the game gets its input back. Link walks where the left stick +points on screen, as the game steers him by the camera it draws. The right stick and the mouse turn the game camera, +which still follows Link unseen. | Gamepad | Keyboard and mouse (default bindings) | Free camera | |---|---|---| @@ -151,7 +156,8 @@ follows the clock, so it is the same at any frame rate and game speed. The horiz How it works (`runtime/freecam.c`): the camera component update (main+0x628460) copies each component's eye, target and up into its sead camera. The site `freecam` (`recomp/patches-v143.txt`, main+0x6286d4) runs before that copy and writes the component's one-shot eye and target overrides (+0x180, +0x198), which the update takes in place of the pose -and then clears, so the game camera's own state is never changed and resumes the frame the free camera ends. The up +and then clears, so the game camera's own state is never changed and resumes the frame the free camera ends. Locked, +the site keeps writing the overrides without moving them. The up vector is levelled through the component's up offset (+0x200), which is kept and put back. Of the three components a frame updates, the free camera drives the two that share the player camera's eye and leaves the one at the default pose (eye 0, 0, 10). After a load replaced the components it picks the new ones and keeps its position. diff --git a/runtime/freecam.c b/runtime/freecam.c index 9eb71bd3..5034aa75 100644 --- a/runtime/freecam.c +++ b/runtime/freecam.c @@ -21,12 +21,14 @@ // the anchor is driven. When no driven component has been updated for LOST_NS (a load replaced them) the next one // away from the default anchors again; the free camera keeps its own position. // -// Input (runtime/input.c freecam_gate): TOTK_FREECAM_PAD or TOTK_FREECAM_KEY switches it (both none by default, so the -// player opts in). While it is on the game gets no input; the left stick flies along the view and to the side, ZR and -// ZL straight up and down, the right stick and the mouse turn, and each press of L or R halves or doubles the speed. -// Keys work through their bindings: the keys' sticks, and the keys bound to ZL, ZR, L and R. Every driven component -// steps the flight by the wall-clock time since the last step, so the speed is the same at any frame rate and game -// speed. +// Input (runtime/input.c freecam_gate): TOTK_FREECAM_PAD or TOTK_FREECAM_KEY steps it off, move, lock and off again +// (both none by default, so the player opts in). While it moves the game gets no input; the left stick flies along the +// view and to the side, ZR and ZL straight up and down, the right stick and the mouse turn, and each press of L or R +// halves or doubles the speed. Keys work through their bindings: the keys' sticks, and the keys bound to ZL, ZR, L and +// R. Every driven component steps the flight by the wall-clock time since the last step, so the speed is the same at +// any frame rate and game speed. Locked, the view stays where the flight left it and the game gets its input back. +// The game steers Link by the camera it draws, which takes the overrides, so Link walks where the stick points on +// screen with the stick as it is. #include #include #include @@ -56,11 +58,11 @@ static PlatMutex pad_lock = PLAT_MUTEX_INIT; static FreecamPad pad_now; // the last poll's input (input thread), under pad_lock static int speed_clicks; // R presses minus L presses not yet applied (input thread adds, the hook takes) static double mouse_deg[2]; // under pad_lock: mouse turn not yet applied, degrees (right +, down +) -// + 1 at every switch (input thread); odd while the free camera is on. One value, so the hook never sees a switch -// without the state it switched to. +// + 1 at every switch (input thread); modulo 3 the stage (FREECAM_OFF, _MOVE, _LOCK). One value, so the hook never +// sees a switch without the stage it switched to. static unsigned generation; -int freecam_on(void) { return __atomic_load_n(&generation, __ATOMIC_ACQUIRE) & 1; } +int freecam_state(void) { return __atomic_load_n(&generation, __ATOMIC_ACQUIRE) % 3; } void freecam_pad(const FreecamPad *p) { plat_mutex_lock(&pad_lock); @@ -88,16 +90,17 @@ enum { int freecam_available(void) { return rt_game_version == 143 && rt_patch_enabled(rt_patch_set("freecam")); } -void freecam_toggle(void) { +void freecam_cycle(void) { unsigned gen = __atomic_add_fetch(&generation, 1, __ATOMIC_ACQ_REL); - rt_log("freecam: %s", gen & 1 ? "on" : "off"); + static const char *const names[] = {"off", "move", "lock"}; + rt_log("freecam: %s", names[gen % 3]); } // Game thread only (the camera update runs on one thread). A component stays listed from its first drive until its // up offset is put back (the first update after the switch goes off) or, while off, until it has gone LOST_NS // without an update (freed by a load). static struct { - unsigned generation; + unsigned flight; // (generation + 2) / 3: the same from move through lock, new at the next move int started; // pos, yaw and pitch hold a pose double pos[3], yaw, pitch, speed; // radians; yaw 0 looks along +Z, pitch > 0 up uint64_t last_step, anchor_seen; @@ -220,10 +223,10 @@ static void freecam_hook(Cpu *c) { uint64_t cam = c->x[19]; memcpy(&c->x[8], (const void *)(uintptr_t)(cam + OFF_LINK), sizeof c->x[8]); unsigned gen = __atomic_load_n(&generation, __ATOMIC_ACQUIRE); - int active = gen & 1; - if (!active && !fc.n) return; // the common case: one load and two compares - if (gen != fc.generation) { // a switch: a new flight starts at the game camera, at the start speed - fc.generation = gen; + int state = gen % 3, active = state != FREECAM_OFF; + if (!active && !fc.n) return; // the common case: one load, a division and two compares + if ((gen + 2) / 3 != fc.flight) { // a new flight starts at the game camera, at the start speed + fc.flight = (gen + 2) / 3; fc.started = 0, fc.anchored = 0, fc.speed = SPEED_START; plat_mutex_lock(&pad_lock); // mouse motion from before the switch does not turn the new flight mouse_deg[0] = mouse_deg[1] = 0; @@ -248,7 +251,7 @@ static void freecam_hook(Cpu *c) { if (i < 0 && (i = pick(cam, eye, target)) < 0) return; if (!fc.started) start(eye, target, now); fc.driven[i].seen = fc.anchor_seen = now; - step(now); + if (state == FREECAM_MOVE) step(now); // locked, the view holds its pose drive(cam); } @@ -257,5 +260,5 @@ __attribute__((constructor)) static void freecam_register(void) { } #else int freecam_available(void) { return 0; } -void freecam_toggle(void) {} +void freecam_cycle(void) {} #endif diff --git a/runtime/input.c b/runtime/input.c index 95a057f2..113ce597 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -271,7 +271,8 @@ static void rec_apply(uint64_t b, const int32_t sl[2], const int32_t sr[2]) { void input_direct_mouse_sample(int enabled, int32_t *dx, int32_t *dy) { plat_mutex_lock(&lock); - enabled = enabled && !g_block && !g_menu && !freecam_on(); // the free camera takes the mouse (freecam_gate) + // the moving free camera takes the mouse (freecam_gate) + enabled = enabled && !g_block && !g_menu && freecam_state() != FREECAM_MOVE; *dx = script_mouse[0]; *dy = script_mouse[1]; script_mouse[0] = script_mouse[1] = 0; if (!enabled) { *dx = *dy = 0; } @@ -854,12 +855,13 @@ static float trigger_unit(int16_t v) { // 0..1 past a 5 % dead zone } // The free camera combo, latched like Minus+Plus (input_map.c, chord): once every button of it is down (on the gamepad, -// or pressed by an input script) the free camera switches once, and the buttons stay hidden from the game until all are -// released; the free camera key switches it on its press. While the free camera is on it gets the input and the game -// gets nothing, so Link stands still: the sticks (the keys' sticks merged into sl and sr), the trigger axes or else ZL -// and ZR as buttons, a press of L or R as a speed click, and the mouse's motion, which input_direct_mouse_sample then -// keeps from the game's camera. ZL, ZR, L and R are the merged Switch buttons, so the keys bound to them count. Off for -// other updates and with the freecam patch set off. Under lock. +// or pressed by an input script) the free camera steps once (off, move, lock), and the buttons stay hidden from the +// game until all are released; the free camera key steps it on its press. While the free camera moves it gets the +// input and the game gets nothing, so Link stands still: the sticks (the keys' sticks merged into sl and sr), the +// trigger axes or else ZL and ZR as buttons, a press of L or R as a speed click, and the mouse's motion, which +// input_direct_mouse_sample then keeps from the game's camera. ZL, ZR, L and R are the merged Switch buttons, so the +// keys bound to them count. Locked, the game gets the input as it is (freecam.c: the game steers Link by the camera it +// draws). Off for other updates and with the freecam patch set off. Under lock. static void freecam_gate(uint64_t *b, int32_t sl[2], int32_t sr[2]) { static int held, key_held, available = -1, shoulder[2]; if (available < 0) available = freecam_available(); @@ -878,13 +880,13 @@ static void freecam_gate(uint64_t *b, int32_t sl[2], int32_t sr[2]) { else if (held) held = raw != 0; else if (raw == mask) { held = 1; - freecam_toggle(); + freecam_cycle(); } int key = available ? freecam_key() : KEY_NONE; int key_down = key != KEY_NONE && ikb_foreground() && ikb_down(key); - if (key_down && !key_held) freecam_toggle(); + if (key_down && !key_held) freecam_cycle(); key_held = key_down; - if (available && freecam_on()) { + if (available && freecam_state() == FREECAM_MOVE) { float lt = trigger_unit(trigger_seen[0]), rt = trigger_unit(trigger_seen[1]); if (*b >> B_ZL & 1) lt = 1; if (*b >> B_ZR & 1) rt = 1; @@ -1035,7 +1037,7 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx static int overlay_held; // L3+R3 step the performance overlay (F10) int overlay = input_overlay_gate(&overlay_held, &b); sl[0] = st[0], sl[1] = st[1], sr[0] = st[2], sr[1] = st[3]; - freecam_gate(&b, sl, sr); // TOTK_FREECAM_PAD switches the free camera, which then takes the pad (freecam.c) + freecam_gate(&b, sl, sr); // TOTK_FREECAM_PAD steps the free camera, which takes the pad while moving (freecam.c) plat_mutex_unlock(&lock); if (toggle) menu_toggle(); if (overlay) menu_perf_cycle(); diff --git a/runtime/input.h b/runtime/input.h index cad3a1f3..6370eca6 100644 --- a/runtime/input.h +++ b/runtime/input.h @@ -99,12 +99,14 @@ int input_pad_read(uint64_t *buttons, int32_t *lx, int32_t *ly); // The gamepad layout in effect (PAD_LAYOUT_*, input_map.h; TOTK_PAD_LAYOUT, live); -1 without a gamepad. Any thread. int input_pad_layout(void); -// Free camera (freecam.c). input.c switches it with TOTK_FREECAM_PAD and, while it is on, hands it the gamepad and -// gives the game none: sticks -1..1 with up +y after the dead zone, triggers 0..1; each L or R press is one speed click. +// Free camera (freecam.c). input.c steps it with TOTK_FREECAM_PAD and, while it moves, hands it the gamepad and gives +// the game none: sticks -1..1 with up +y after the dead zone, triggers 0..1; each L or R press is one speed click. +// Locked, the view stays and the game gets the input. typedef struct { float lx, ly, rx, ry, lt, rt; } FreecamPad; +enum { FREECAM_OFF, FREECAM_MOVE, FREECAM_LOCK }; int freecam_available(void); // game 1.4.3 with the freecam patch set on -int freecam_on(void); -void freecam_toggle(void); // logs; input thread +int freecam_state(void); // FREECAM_* +void freecam_cycle(void); // off, move, lock, off; logs; input thread void freecam_pad(const FreecamPad *p); void freecam_speed_click(int faster); // R (1) doubles the speed, L (0) halves it void freecam_mouse(double right_deg, double down_deg); // a turn from the mouse, added at the next step diff --git a/runtime/ui_text.c b/runtime/ui_text.c index e4c1b8a5..a2b7dd83 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -359,14 +359,17 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_WALK_SCALE_DESC] = "The tilt the keyboard's sticks get while the walk key is held. Half is a walk, the " "full tilt a run.", [UI_MENU_FREECAM_PAD] = "Free camera combo", - [UI_MENU_FREECAM_PAD_DESC] = "Gamepad buttons pressed together that detach the view from Link and bring it back. " - "While it is on the game gets no input: the left stick flies along the view and sideways, the triggers up and " - "down, the right stick turns, and each press of L or R halves or doubles the speed. Game version 1.4.3.", + [UI_MENU_FREECAM_PAD_DESC] = "Gamepad buttons pressed together that step the view through three stages: it leaves " + "Link and flies, it stays where it was left while Link plays on, and it comes back. While it flies the game " + "gets no input: the left stick flies along the view and sideways, the triggers up and down, the right stick " + "turns, and each press of L or R halves or doubles the speed. Locked, Link walks where the left stick points " + "on screen. Game version 1.4.3.", [UI_MENU_FREECAM_PAD_V143] = "Game version 1.4.3 only", [UI_MENU_FREECAM_KEY] = "Free camera key", - [UI_MENU_FREECAM_KEY_DESC] = "A key that detaches the view from Link and brings it back. While it is on: W A S D " - "fly along the view and sideways, the keys bound to ZR and ZL (X and Z by default) up and down, the mouse and " - "the arrow keys turn, and the keys bound to L and R (Q and R) halve or double the speed. Game version 1.4.3.", + [UI_MENU_FREECAM_KEY_DESC] = "A key that steps the view through the same stages: it leaves Link and flies, it " + "stays while Link plays on, and it comes back. While it flies: W A S D fly along the view and sideways, the " + "keys bound to ZR and ZL (X and Z by default) up and down, the mouse and the arrow keys turn, and the keys " + "bound to L and R (Q and R) halve or double the speed. Game version 1.4.3.", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Gameplay tweaks", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Gameplay tweaks", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Mouse wheel controls for Ultrahand rotation and distance, item and weapon switching, and smooth map zoom.", @@ -979,14 +982,17 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_WALK_SCALE_DESC] = "Отклонение стиков клавиатуры при удержании клавиши шага. Половина — шаг, полное " "отклонение — бег.", [UI_MENU_FREECAM_PAD] = "Сочетание свободной камеры", - [UI_MENU_FREECAM_PAD_DESC] = "Кнопки геймпада, нажатые вместе, отделяют камеру от Линка и возвращают её. Пока она " - "включена, игра не получает ввод: левый стик ведёт камеру вдоль взгляда и вбок, курки — вверх и вниз, правый " - "стик поворачивает, а каждое нажатие L или R уменьшает или увеличивает скорость вдвое. Версия игры 1.4.3.", + [UI_MENU_FREECAM_PAD_DESC] = "Кнопки геймпада, нажатые вместе, переключают камеру по трём режимам: она отделяется " + "от Линка и летает, остаётся на месте, пока Линком снова можно управлять, и возвращается. Пока камера летает, " + "игра не получает ввод: левый стик ведёт камеру вдоль взгляда и вбок, курки — вверх и вниз, правый стик " + "поворачивает, а каждое нажатие L или R уменьшает или увеличивает скорость вдвое. Когда камера закреплена, " + "Линк идёт туда, куда левый стик указывает на экране. Версия игры 1.4.3.", [UI_MENU_FREECAM_PAD_V143] = "Только для версии игры 1.4.3", [UI_MENU_FREECAM_KEY] = "Клавиша свободной камеры", - [UI_MENU_FREECAM_KEY_DESC] = "Клавиша, которая отделяет камеру от Линка и возвращает её. Пока она включена: W A S " - "D ведут камеру вдоль взгляда и вбок, клавиши ZR и ZL (по умолчанию X и Z) — вверх и вниз, мышь и стрелки " - "поворачивают, а клавиши L и R (Q и R) уменьшают или увеличивают скорость вдвое. Версия игры 1.4.3.", + [UI_MENU_FREECAM_KEY_DESC] = "Клавиша, которая переключает те же режимы: камера отделяется от Линка и летает, " + "остаётся на месте, пока Линком снова можно управлять, и возвращается. Пока она летает: W A S D ведут камеру " + "вдоль взгляда и вбок, клавиши ZR и ZL (по умолчанию X и Z) — вверх и вниз, мышь и стрелки поворачивают, а " + "клавиши L и R (Q и R) уменьшают или увеличивают скорость вдвое. Версия игры 1.4.3.", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Геймплей", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Настройки геймплея", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Управление колесом мыши: вращение и дистанция предметов в Ультраруке, выбор оружия и предметов, плавный зум карты.", @@ -1790,16 +1796,17 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_WALK_SCALE_DESC] = "A inclinação dos analógicos do teclado enquanto a tecla de andar está segura. Metade " "é andar, a inclinação total é correr.", [UI_MENU_FREECAM_PAD] = "Combinação da câmera livre", - [UI_MENU_FREECAM_PAD_DESC] = "Botões do controle pressionados juntos que soltam a câmera do Link e a trazem de " - "volta. Enquanto ela está ligada o jogo não recebe comandos: o analógico esquerdo voa na direção da visão e " - "para os lados, os gatilhos sobem e descem, o analógico direito gira, e cada toque em L ou R reduz a " - "velocidade à metade ou a dobra. Versão do jogo 1.4.3.", + [UI_MENU_FREECAM_PAD_DESC] = "Botões do controle pressionados juntos que passam a câmera por três etapas: ela se " + "solta do Link e voa, fica parada onde foi deixada enquanto o Link volta a ser controlado, e volta. Enquanto " + "ela voa o jogo não recebe comandos: o analógico esquerdo voa na direção da visão e para os lados, os gatilhos " + "sobem e descem, o analógico direito gira, e cada toque em L ou R reduz a velocidade à metade ou a dobra. Com " + "a câmera parada, o Link anda para onde o analógico esquerdo aponta na tela. Versão do jogo 1.4.3.", [UI_MENU_FREECAM_PAD_V143] = "Só na versão 1.4.3 do jogo", [UI_MENU_FREECAM_KEY] = "Tecla da câmera livre", - [UI_MENU_FREECAM_KEY_DESC] = "Uma tecla que solta a câmera do Link e a traz de volta. Enquanto ela está ligada: W " - "A S D voam na direção da visão e para os lados, as teclas de ZR e ZL (X e Z por padrão) sobem e descem, o " - "mouse e as setas giram, e as teclas de L e R (Q e R) reduzem a velocidade à metade ou a dobram. Versão do " - "jogo 1.4.3.", + [UI_MENU_FREECAM_KEY_DESC] = "Uma tecla que passa a câmera pelas mesmas etapas: ela se solta do Link e voa, fica " + "parada enquanto o Link volta a ser controlado, e volta. Enquanto ela voa: W A S D voam na direção da visão e " + "para os lados, as teclas de ZR e ZL (X e Z por padrão) sobem e descem, o mouse e as setas giram, e as teclas " + "de L e R (Q e R) reduzem a velocidade à metade ou a dobram. Versão do jogo 1.4.3.", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Ajustes de jogabilidade", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Ajustes de jogabilidade", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Controles com a roda do mouse para rotação e distância na Ultramão, seleção de armas e itens, e zoom suave no mapa.", @@ -2550,10 +2557,10 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_WALK_SCALE] = "步行幅度", [UI_MENU_WALK_SCALE_DESC] = "按住步行键时键盘摇杆的推动幅度。一半为走路,推满为奔跑。", [UI_MENU_FREECAM_PAD] = "自由镜头组合键", - [UI_MENU_FREECAM_PAD_DESC] = "同时按下的手柄按键,让镜头脱离林克,再按一次回到林克。开启期间游戏不接收输入:左摇杆沿视线方向和左右移动,扳机键上升和下降,右摇杆转动视角,每按一次 L 或 R 速度减半或加倍。游戏版本 1.4.3。", + [UI_MENU_FREECAM_PAD_DESC] = "同时按下的手柄按键,让镜头依次切换三个阶段:脱离林克自由飞行、停在原处而林克恢复操作、回到林克。飞行期间游戏不接收输入:左摇杆沿视线方向和左右移动,扳机键上升和下降,右摇杆转动视角,每按一次 L 或 R 速度减半或加倍。镜头固定时,林克朝左摇杆在屏幕上指向的方向移动。游戏版本 1.4.3。", [UI_MENU_FREECAM_PAD_V143] = "仅限游戏版本 1.4.3", [UI_MENU_FREECAM_KEY] = "自由镜头键", - [UI_MENU_FREECAM_KEY_DESC] = "让镜头脱离林克、再按一次回到林克的按键。开启期间:W A S D 沿视线方向和左右移动,ZR 和 ZL 对应的按键(默认 X 和 Z)上升和下降,鼠标和方向键转动视角,L 和 R 对应的按键(默认 Q 和 R)让速度减半或加倍。游戏版本 1.4.3。", + [UI_MENU_FREECAM_KEY_DESC] = "让镜头依次切换相同阶段的按键:脱离林克自由飞行、停在原处而林克恢复操作、回到林克。飞行期间:W A S D 沿视线方向和左右移动,ZR 和 ZL 对应的按键(默认 X 和 Z)上升和下降,鼠标和方向键转动视角,L 和 R 对应的按键(默认 Q 和 R)让速度减半或加倍。游戏版本 1.4.3。", [UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "游戏操作微调", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "启用操作微调", [UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "使用鼠标滚轮控制究极手物体旋转与距离、武器与道具切换以及地图平滑缩放。", diff --git a/totk.ini.example b/totk.ini.example index cbba2bea..b6c085b9 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -480,15 +480,16 @@ # reads as a partial tilt only. # walk_key = lshift # walk_scale = 0.51 -# Free camera (game 1.4.3): the gamepad combo that switches it, buttons by position joined with +, the pad: names of the -# bind_ lines. While it is on the game gets no input and the view flies: the left stick along the view and sideways, -# the triggers straight up and down, the right stick turns; each press of L halves the speed, of R doubles it -# (docs/controls.md, "Free camera"). none turns the combo off. Default: none; +# Free camera (game 1.4.3): the gamepad combo that steps it through move, lock and off, buttons by position joined with +# +, the pad: names of the bind_ lines. While it moves the game gets no input and the view flies: the left stick along +# the view and sideways, the triggers straight up and down, the right stick turns; each press of L halves the speed, of +# R doubles it. Locked, the view stays and Link walks where the left stick points on screen (docs/controls.md, "Free +# camera"). none turns the combo off. Default: none; # freecam_pad = zl+zr+lstick # A key that does the same, by its name in the bind_ lines; on the keyboard the keys bound to the sticks fly and turn, # the keys of ZR and ZL go up and down, those of R and L change the speed, and the mouse turns. none turns it off. # Default: none. -# freecam_key = f6 +# freecam_key = f2 # Write the input of this run to a file that replays as a script (docs/controls.md, "Scripted input"). Default: off. # input_record = input.txt # Remap buttons: the Controls tab of the settings menu (F1) writes these lines. One line per Switch button or stick From 9ab4192bccc9834404dfeb994711c34306641263 Mon Sep 17 00:00:00 2001 From: lebomis <26766744+lebomis@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:50:44 +1100 Subject: [PATCH 9/9] The free camera key is set on the Controls tab by pressing it, as quick save's keys are Co-Authored-By: Claude Opus 5.5 --- runtime/ui/menu.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 5b7a9812..d70762e9 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -945,8 +945,10 @@ static void row_quicksave_keys(void) { } // The free camera combo and key (freecam.c): the trigger and shoulder pairs with a stick click, named as the open pad -// labels its buttons, or none. totk.ini takes any combo of button positions, shown as written. Off on other game -// versions. +// labels its buttons, or none. totk.ini takes any combo of button positions, shown as written. The key is any key or +// mouse button, taken by the bindings' capture window (binds_key_row) as quick save's are; Delete leaves it without +// one. A key the bindings also use says which action it presses. The combo is off on other game versions; the key +// row, which opt_disable_next does not grey, says so in its note. static void rows_freecam(void) { static const char *const combos[] = {"zl+zr+lstick", "zl+zr+rstick", "l+r+lstick", "l+r+rstick", "none"}; static const int pads[][3] = {{PAD_ZL, PAD_ZR, PAD_LSTICK}, {PAD_ZL, PAD_ZR, PAD_RSTICK}, @@ -962,11 +964,10 @@ static void rows_freecam(void) { names[N - 1] = menu_text(UI_MENU_OFF); if (!freecam_available()) opt_disable_next(UI_MENU_FREECAM_PAD_V143); opt_choice_list("TOTK_FREECAM_PAD", UI_MENU_FREECAM_PAD, combos, names, N, UI_MENU_FREECAM_PAD_DESC); - // The free camera key: keys no default binding uses (none, the default, turns it off) - static const char *const keys[] = {"none", "f2", "f3", "f4", "f5", "f6", "f7", "f9"}; - const char *key_names[] = {menu_text(UI_MENU_OFF), "F2", "F3", "F4", "F5", "F6", "F7", "F9"}; - if (!freecam_available()) opt_disable_next(UI_MENU_FREECAM_PAD_V143); - opt_choice_list("TOTK_FREECAM_KEY", UI_MENU_FREECAM_KEY, keys, key_names, 8, UI_MENU_FREECAM_KEY_DESC); + static char note[64]; + binds_key_row("TOTK_FREECAM_KEY", UI_MENU_FREECAM_KEY, UI_MENU_FREECAM_KEY_DESC, + freecam_available() ? key_taken("TOTK_FREECAM_KEY", note, sizeof note) + : menu_text(UI_MENU_FREECAM_PAD_V143)); } // The note under the prompts. The settings name a folder of prompts (input_prompts_folder: the prompts and the pad