diff --git a/docs/controls.md b/docs/controls.md index 9fcbe68d..541d2747 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -129,6 +129,39 @@ bind_X = pad:west, key:space bind_Y = pad:north, key:mouse_l ``` +## Free camera + +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 | +|---|---|---| +| 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 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 +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. 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. + ## 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 fe38aea3..1e8fc7d0 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -232,6 +232,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 fills, and the game's guard (1.2.1 main+0x9bcdc4) switches the sound commands off until the game is restarted once 300 updates in a row find it full. The guard starts over whenever two audio frames fall between two updates, so by the code it fires only while the audio frames come evenly, 5 ms apart: with `audio = none`, or while the audio device takes nothing and the mixer keeps time by its own timer. The guard's count and the switch have not been read in a run. With a device playing the game kept its sound in every run on Linux with PipeWire and 1024-frame device periods, where the frames come in bursts after each period; on Windows the bursts are read from the code (`gap_ns = 0` in `runtime/audren.c`), not measured; a device with periods of 240 frames or less was not tried and may pace as evenly as the timer. The set acts only when more than one list is queued, so below that rate it seldom changes anything. Measured at `fps_limit = 240` (Linux, PipeWire), seconds with sound with `0` and with `1`. On 1.2.1: without a device 6 of 119 and 111 of 119; with a device 111 of 119 and 112 of 119; with the game's stream paused for 5 s from outside (`pw-cli`, not a real device stalling) 4 of 120 (silent from the pause on, also after the device resumed) and 113 of 119; a pause of 2 s silenced the game with `0`, a pause of 1 s did not. On 1.4.3: without a device 3 of 119 and 113 of 120; with a device 111 of 119 with `0`; with the stream paused for 5 s, in 60 s runs, 3 of 59 and 51 of 59; a pause of 2 s with `0`, 4 of 59. | 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 3265ff7a..735dbc60 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 1c40f239..6040675f 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_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"}, {"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"}, @@ -190,6 +190,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", "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 new file mode 100644 index 00000000..5034aa75 --- /dev/null +++ b/runtime/freecam.c @@ -0,0 +1,264 @@ +// 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 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 +#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) +static double mouse_deg[2]; // under pad_lock: mouse turn not yet applied, degrees (right +, down +) +// + 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_state(void) { return __atomic_load_n(&generation, __ATOMIC_ACQUIRE) % 3; } + +void freecam_pad(const FreecamPad *p) { + plat_mutex_lock(&pad_lock); + pad_now = *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 +#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_cycle(void) { + unsigned gen = __atomic_add_fetch(&generation, 1, __ATOMIC_ACQ_REL); + 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 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; + 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; + 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) { + 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; + // 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); + // 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 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; + plat_mutex_unlock(&pad_lock); + } + 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; + if (state == FREECAM_MOVE) step(now); // locked, the view holds its pose + 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_cycle(void) {} +#endif diff --git a/runtime/input.c b/runtime/input.c index 4e307899..1891b8cd 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -148,6 +148,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; @@ -269,7 +273,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; + // 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; } @@ -803,15 +808,149 @@ 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; +} + +// 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; + static uint32_t mask; + unsigned v = cfg_version(); + if (read && v == seen) return mask; + read = 1, seen = v; + 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; none, the default (the settings table), 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 (on the gamepad, +// 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(); + uint32_t mask = available ? freecam_pad_mask() : 0, raw = 0; + 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 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 && script_seen & input_map_pad_buttons(one, layout))) raw |= 1u << p; + } + if (!mask) held = 0; + else if (held) held = raw != 0; + else if (raw == mask) { + held = 1; + 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_cycle(); + key_held = key_down; + 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; + FreecamPad fp = {sl[0] / (float)STICK_MAX, sl[1] / (float)STICK_MAX, sr[0] / (float)STICK_MAX, + sr[1] / (float)STICK_MAX, lt, rt}; + freecam_pad(&fp); + for (int k = 0; k < 2; k++) { + 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; + } + 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; @@ -928,7 +1067,9 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx mouse_camera(k, 0); pick(&sr[0], &sr[1], k[0], k[1]); } - 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); @@ -939,6 +1080,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 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 e2b61a6a..6370eca6 100644 --- a/runtime/input.h +++ b/runtime/input.h @@ -91,9 +91,25 @@ 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); + +// 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_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 // 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/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); diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 4bff6396..d70762e9 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -944,6 +944,32 @@ static void row_quicksave_keys(void) { key_taken("TOTK_QUICKLOAD_KEY", note[1], sizeof note[1])); } +// 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. 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}, + {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); + 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 // 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 +1110,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"); + 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 ff43bf01..a2b7dd83 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -358,6 +358,18 @@ 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 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 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.", @@ -969,6 +981,18 @@ 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_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] = "Управление колесом мыши: вращение и дистанция предметов в Ультраруке, выбор оружия и предметов, плавный зум карты.", @@ -1771,6 +1795,18 @@ 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 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 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.", @@ -2520,6 +2556,11 @@ 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_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 51c8c2db..f3d398e3 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -154,6 +154,8 @@ 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, + UI_MENU_FREECAM_KEY, UI_MENU_FREECAM_KEY_DESC, // Controls tab: Gameplay tweaks UI_MENU_GROUP_GAMEPLAY_TWEAKS, 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 78333137..9ae2ad44 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -486,6 +486,16 @@ # reads as a partial tilt only. # walk_key = lshift # walk_scale = 0.51 +# 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 = 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