Add a sprint button: a setting that makes Link sprint without rolling first, as a toggle or while held.

This commit is contained in:
kendo
2026-11-12 20:50:16 +00:00
committed by chrg6
parent f3856c8dca
commit 6faf4bd7f5
14 changed files with 477 additions and 5 deletions

View File

@@ -55,7 +55,7 @@ static const char *const known[] = {
"HDR_HIGHLIGHTS", "HDR_HUE", "HDR_HUE_CLIP", "HDR_MATCH_SLOPE", "HDR_MIDGRAY", "HDR_SATURATION", "HDR_SHADOWS",
"HDR_TONEMAP", "HDR_TONE_SLOPE", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "LANG", "LIB_PREBUILD",
"BIG_BUILD_FREE_MB", "BIG_BUILD_MAX_MB", "BUILD_FREE_MB", "BUILD_RESERVE_MB", "LIB_PREBUILD_BIG", "LIB_PREBUILD_BIG_BG", "COMPUTE_WARM_REUSE", "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LIB_WARM", "LINE_WIDTH", "POOL_SHOWN_FIRST", "POOL_DATA_FIRST", "TEX_REUSE_NAMED", "TEX_OVERWRITTEN_USED", "PIPE_LINK_MS", "FRAME_HOLD_MS", "PACE_SMOOTH", "OQ_BATCH", "CLEAR_SMALL_CPU", "GATE_WAIT_MS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MEMORY", "MEM_CENSUS", "MEM_NEED_MB", "MENU_LANG", "MENU_SOUND_VOLUME", "MENU_TEST",
"MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_CLICK", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MICROPHONE", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MONITOR", "MOTION", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOUSE_TRACE", "MOVIE_HOST", "MOVIE_PACE", "MOVIE_CLOCK", "TEST_HITCH",
"MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_CLICK", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MICROPHONE", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MONITOR", "MOTION", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOUSE_TRACE", "MOVIE_HOST", "MOVIE_PACE", "MOVIE_CLOCK", "TEST_HITCH", "SPRINT_BUTTON", "SPRINT_MODE", "SPRINT_PATCH",
"MOTION_GUARD_DEGREES", "MOTION_POLICY_TRACE", "SELECTIVE_MOTION", "SELECTIVE_MOTION_RAW", // motion_owner.c, vk_fg_pose.inc
"SKIN_MOTION", // vk_skin_motion.inc
"MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK",
@@ -125,7 +125,7 @@ static const struct { const char *key, *section; } sections[] = {
{"MENU_LANG", "language"}, {"LANG", "language"}, {"OPERATION_MODE", "language"},
{"VOLUME", "audio"}, {"AUDIO_CHANNELS", "audio"}, {"AUDIO_DEVICE", "audio"}, {"MICROPHONE", "audio"}, {"MENU_SOUND_VOLUME", "audio"},
{"AUDIO_RAMP", "audio"}, {"AUDIO_CATCHUP", "audio"},
{"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"}, {"RUMBLE_HD", "input"}, {"DS3", "input"},
{"MOTION", "input"}, {"SPRINT_BUTTON", "input"}, {"SPRINT_MODE", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"}, {"RUMBLE_HD", "input"}, {"DS3", "input"},
{"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"LSTICK_DEADZONE", "input"}, {"RSTICK_DEADZONE", "input"},
{"STICK_SENS", "input"}, {"DEBUG_MENU", "input"},
{"MENU_CURSOR", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"INPUT_RECORD", "input"},
@@ -243,6 +243,8 @@ static const CfgMeta metas[] = {
{"MICROPHONE", "1", "0|1", RESTART}, // ov_audio_input.c mic_on: 0 refuses the game's input streams
{"AUDIO_RAMP", "1", "0|1", RESTART}, // audio_mixer.c accumulate_ramp: a changed volume is reached across the frame
{"AUDIO_CATCHUP", "1", "0|1", RESTART}, // audren.c render_thread: frames owed after a stall are rendered and dropped
// sprint.c: the sprint button (b the bottom face button) and toggle or hold; the Controls tab's Sprint rows (1.1.1)
{"SPRINT_BUTTON", "off", "off|b|l|r|l3|r3", LIVE}, {"SPRINT_MODE", "toggle", "toggle|hold", LIVE},
{"MOTION", "1", "0|1", LIVE}, {"RUMBLE_STRENGTH", "130", "0..300", LIVE}, {"RUMBLE_CURVE", "0.6", "0.2..1.5", LIVE},
{"RUMBLE_TRIGGERS", "0", "0|1", LIVE}, {"PAD_LAYOUT", "nintendo", "auto|nintendo|xbox|playstation", LIVE},
{"DS3", "0", "0|1", LIVE}, // input_ds3_win.c ds3_read: read a DualShock 3 directly; off: no HID scan

View File

@@ -18,6 +18,7 @@
#include "input.h"
#include "ov.h"
#include "platform/platform.h"
#include "sprint.h"
typedef struct { int64_t sampling; uint64_t buttons; int32_t lx, ly, rx, ry; uint32_t attributes, pad; } NpadState;
typedef struct { int64_t sampling; int32_t x, y, dx, dy, wx, wy; uint32_t buttons, attributes; } MouseState;
@@ -101,6 +102,7 @@ static void npad_states(Cpu *c, uint32_t want) {
}
dbg_tick(c); // the debug menu's changes to the game, between two of its frames (debug_tools.c)
if (live) dbg_pad(&s.buttons, &s.lx, &s.ly, &s.rx, &s.ry); // its free camera takes the sticks while it flies
if (live) sprint_pad(&s.buttons); // the sprint button's presses, kept from the game during gameplay (sprint.c)
*out = s;
ret_x(c, 1);
}

163
runtime/sprint.c Normal file
View File

@@ -0,0 +1,163 @@
// Sprint button for Ocarina of Time 1.1.1 (the patch set sprint, recomp/patches-v111.txt). Link sprints while his
// input flags hold the dash input (bit 4 of the word at *(Link +0x50)). The set's two sites call the host functions
// below right after the game loads those flags, and they OR the bit in while the sprint button's sprint is on, so the
// game's own sprint runs: its speed, animation, camera and every rule that ends it.
//
// Settings (live): sprint_button picks the button (off, b the bottom face button, l, r, l3, r3); sprint_mode is toggle
// (a press starts the sprint, the next press or Link's state ends it) or hold (sprint while the button is held). During
// gameplay the button is kept from the game (sprint_pad, called by ov_input.c npad_states), so it does not also fire
// its own action: L or R its item, R3 the camera reset. The bottom button is kept only while Link moves (Walk, Jump,
// Land, Fall, Clamber), so it attacks as usual otherwise.
//
// Link's state: the id at [[[[Link +0x18] +0x270] +0x188] +0x1c0] +0x28 (+0x4c when that reads 0x11a, a state that
// wraps another), the same field main+0x4aed50 compares with 1 (Walk) before the game starts a sprint.
#include <stdatomic.h>
#include <stdint.h>
#include <string.h>
#include "cfg.h"
#include "host.h"
#include "layout.h"
#include "sprint.h"
#if __has_include("patches.h")
#include "patches.h"
#endif
enum { BTN_OFF, BTN_B, BTN_L, BTN_R, BTN_L3, BTN_R3 };
static const char *const button_names[] = {"off", "b", "l", "r", "l3", "r3"};
static const uint64_t button_bits[] = {0, 1u << 1, 1u << 6, 1u << 7, 1u << 4, 1u << 5}; // HidNpadButton bits
#define BUTTON_ZL (1u << 8)
#define DASH_INPUT 0x10u
#define LINK_VTABLE 0x4b4dfc0ull // main offset: Link's actor class
#define GAMEPLAY_POLLS 8 // the button is kept from the game while Link's update ran within this many polls
#define WAIT_STOP_FRAMES 4 // standing still this many frames ends a toggled sprint that has moved
#define WAIT_START_FRAMES 90 // ... or this many after a press while standing, which has not moved yet
// What Link's state does to a sprint: MOVE keeps it (and is when the bottom button sprints), KEEP keeps it,
// WAIT ends it after a few frames, STOP ends it at once. A state not listed stops it too.
enum { MOVE, KEEP, WAIT, STOP };
static const struct { int32_t id; uint8_t kind; } states[] = {
{1, MOVE}, // Walk (also running)
{13, MOVE}, // Jump
{32, MOVE}, // Land
{33, MOVE}, // Fall
{68, MOVE}, // Clamber
{253, KEEP}, // StepOn
{35, KEEP}, // Slide
{36, KEEP}, // SlideLand
{40, WAIT}, // Wait
};
static _Atomic uint64_t pressed; // the button's presses since Link's last update (sprint_pad -> sprint_link)
static _Atomic int held; // the button held at the last poll
static _Atomic int zl_held; // ZL (targeting) held at the last poll
static _Atomic int polls = GAMEPLAY_POLLS; // polls since Link's last update (none yet: not gameplay)
static _Atomic int moving; // Link's state was a MOVE one at his last update
static _Atomic int active; // the sprint is on: the dash input goes in
static int moved, wait_frames; // sprint_link only: the sprint has moved since it started; frames stood still
static int last_button = -1; // sprint_link only: the button setting at the last update
static int setting_button(void) {
const char *v = cfg_value("NX2NAVI_SPRINT_BUTTON");
for (int i = 0; i < (int)(sizeof button_names / sizeof *button_names); i++)
if (v && !strcmp(v, button_names[i])) return i;
return BTN_OFF;
}
static int setting_hold(void) {
const char *v = cfg_value("NX2NAVI_SPRINT_MODE");
return v && !strcmp(v, "hold");
}
static uint64_t ld64(uint64_t a) { return a ? *(const uint64_t *)(uintptr_t)a : 0; }
// 1 when x19 is the Link the player controls. Link's class has one more instance the player does not control: the
// game's actor manager ([[main+0x4c7e0d0]], class main+0x4bdfe68) names the controlled one at +0x470 (class
// main+0x4b49698), whose +0x18 must be Link's own +0x18.
static int is_link(uint64_t link) {
if (!link || ld64(link) != MOD_MAIN_BASE + LINK_VTABLE) return 0;
uint64_t slot = ld64(MOD_MAIN_BASE + 0x4c7e0d0), mgr = slot ? ld64(slot) : 0;
if (!mgr || ld64(mgr) != MOD_MAIN_BASE + 0x4bdfe68) return 1;
uint64_t ctl = ld64(mgr + 0x470);
if (!ctl || ld64(ctl) != MOD_MAIN_BASE + 0x4b49698) return 1;
return ld64(ctl + 0x18) == ld64(link + 0x18);
}
static int state_kind(uint64_t link) {
uint64_t p = ld64(link + 0x18);
if (p) p = ld64(p + 0x270);
if (p) p = ld64(p + 0x188);
if (p) p = ld64(p + 0x1c0);
if (!p) return STOP;
int32_t id = *(const int32_t *)(uintptr_t)(p + 0x28);
if (id == 0x11a) id = *(const int32_t *)(uintptr_t)(p + 0x4c);
for (size_t i = 0; i < sizeof states / sizeof *states; i++)
if (states[i].id == id) return states[i].kind;
return STOP;
}
int sprint_available(void) { return rt_patch_enabled(rt_patch_set("sprint")); }
void sprint_pad(uint64_t *buttons) {
int b = setting_button();
if (b == BTN_OFF) return;
static uint64_t last;
uint64_t bit = button_bits[b], now = *buttons;
if (now & ~last & bit) atomic_fetch_or(&pressed, bit);
last = now;
atomic_store(&held, (now & bit) != 0);
atomic_store(&zl_held, (now & BUTTON_ZL) != 0);
int n = atomic_load(&polls);
if (n <= GAMEPLAY_POLLS) atomic_store(&polls, n + 1);
if (n >= GAMEPLAY_POLLS) return; // a menu, a cutscene or a load: the button keeps its role
if (b == BTN_B && !atomic_load(&moving)) return;
*buttons &= ~bit;
}
// The sprint for this update of Link, from his state and the button's presses: 1 when it is on.
int sprint_step(int kind, int button, int hold) {
if (button != last_button) last_button = button, atomic_store(&active, 0), atomic_store(&pressed, 0);
int press = (atomic_exchange(&pressed, 0) & button_bits[button]) != 0, on = atomic_load(&active);
if (atomic_load(&zl_held)) kind = STOP;
atomic_store(&moving, kind == MOVE);
if (button == BTN_OFF) on = 0;
else if (hold) on = atomic_load(&held) && (button != BTN_B || kind == MOVE || on);
else {
if (press) {
if (on) on = 0;
else if (kind != STOP && (button != BTN_B || kind == MOVE)) on = 1, moved = kind == MOVE, wait_frames = 0;
} else if (on) {
if (kind == STOP) on = 0;
else if (kind == WAIT) {
if (++wait_frames > (moved ? WAIT_STOP_FRAMES : WAIT_START_FRAMES)) on = 0;
} else {
wait_frames = 0;
moved |= kind == MOVE;
}
}
}
atomic_store(&active, on);
return on;
}
// main+0x4ae798, after ldr x10, [x10]: x10 holds Link's input flags for the sprint's start and keep tests.
static void sprint_link(Cpu *c) {
if (!is_link(c->x[19])) return;
atomic_store(&polls, 0);
if (sprint_step(state_kind(c->x[19]), setting_button(), setting_hold())) c->x[10] |= DASH_INPUT;
}
// main+0xc07f3c, after ldrb w8, [x8]: the same flags' low byte for the stance and camera update.
static void sprint_stance(Cpu *c) {
if (atomic_load(&active) && is_link(c->x[19])) c->x[8] |= DASH_INPUT;
}
#ifdef RT_PATCH_PAGE
__attribute__((constructor)) static void sprint_register(void) {
if (!RT_V111) return; // the set's sites are in 1.1.1's main only
rt_register_host(RT_PATCH_PAGE + 0xf40, sprint_link);
rt_register_host(RT_PATCH_PAGE + 0xf50, sprint_stance);
}
#endif

11
runtime/sprint.h Normal file
View File

@@ -0,0 +1,11 @@
// Sprint button (sprint.c): the patch set sprint's host functions and the button's input.
#pragma once
#include <stdint.h>
// Called with the buttons of every controller poll the game gets (ov_input.c npad_states): notes the sprint button's
// presses and keeps it from the game during gameplay.
void sprint_pad(uint64_t *buttons);
// One update of Link's sprint: kind is how his state treats it (sprint.c), button and hold the settings. 1 while on.
int sprint_step(int kind, int button, int hold);
// 1 when the game version has the patch set sprint and it is on: the Controls tab shows the sprint rows then.
int sprint_available(void);

View File

@@ -54,6 +54,7 @@ extern "C" {
#include "perfmon.h"
#include "platform/platform.h"
#include "save_share.h"
#include "sprint.h"
#include "sysinfo.h"
#include "ui/menu.h"
#include "ui_text.h"
@@ -1631,6 +1632,15 @@ static void tab_controls(float scale) {
bool restart;
opt_choice("NX2NAVI_PROMPTS", UI_MENU_PROMPTS, prompts, 5, UI_MENU_PROMPTS_DESC, prompts_note(&restart));
opt_toggle("NX2NAVI_MOTION", UI_MENU_MOTION, UI_MENU_MOTION_DESC);
// The sprint button (sprint.c), where the game version has the patch set sprint; both rows are live. The names
// follow the values in their cfg.c order.
if (sprint_available()) {
static const UiTextId sprint_button[] = {UI_MENU_SPRINT_OFF, UI_MENU_SPRINT_B, UI_MENU_SPRINT_L,
UI_MENU_SPRINT_R, UI_MENU_SPRINT_L3, UI_MENU_SPRINT_R3};
static const UiTextId sprint_mode[] = {UI_MENU_SPRINT_TOGGLE, UI_MENU_SPRINT_HOLD};
opt_choice("NX2NAVI_SPRINT_BUTTON", UI_MENU_SPRINT_BUTTON, sprint_button, 6, UI_MENU_SPRINT_BUTTON_DESC);
opt_choice("NX2NAVI_SPRINT_MODE", UI_MENU_SPRINT_MODE, sprint_mode, 2, UI_MENU_SPRINT_MODE_DESC);
}
opt_slider("NX2NAVI_RUMBLE_STRENGTH", UI_MENU_RUMBLE_STRENGTH, 0, 300, UI_MENU_RUMBLE_STRENGTH_DESC, 10, "%.0f %%");
opt_slider("NX2NAVI_RUMBLE_CURVE", UI_MENU_RUMBLE_CURVE, 0.2f, 1.5f, UI_MENU_RUMBLE_CURVE_DESC, 0.05f, "%.2f");
opt_toggle("NX2NAVI_RUMBLE_TRIGGERS", UI_MENU_RUMBLE_TRIGGERS, UI_MENU_RUMBLE_TRIGGERS_DESC);

View File

@@ -326,6 +326,17 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_CHANNELS_AUTO] = "Automatic", [UI_MENU_CHANNELS_STEREO] = "Stereo", [UI_MENU_CHANNELS_51] = "5.1 surround",
[UI_MENU_MOTION] = "Motion controls", [UI_MENU_MOTION_DESC] = "Aim with the controller's gyro.",
[UI_MENU_SPRINT_BUTTON] = "Sprint button",
[UI_MENU_SPRINT_BUTTON_DESC] = "A button that makes Link sprint without rolling first. During play it only "
"sprints: L or R no longer uses its item, R3 no longer resets the camera. The "
"bottom button sprints only while Link moves and attacks as usual otherwise.",
[UI_MENU_SPRINT_OFF] = "Off", [UI_MENU_SPRINT_B] = "Bottom button", [UI_MENU_SPRINT_L] = "L",
[UI_MENU_SPRINT_R] = "R", [UI_MENU_SPRINT_L3] = "L3 (left stick)", [UI_MENU_SPRINT_R3] = "R3 (right stick)",
[UI_MENU_SPRINT_MODE] = "Sprint mode",
[UI_MENU_SPRINT_MODE_DESC] = "Toggle: press once to sprint and again to stop. The sprint goes on through jumps "
"and ends when Link stops, attacks, rolls, targets, uses an item, swims or climbs. "
"Hold: Link sprints while the button is held.",
[UI_MENU_SPRINT_TOGGLE] = "Toggle", [UI_MENU_SPRINT_HOLD] = "Hold",
[UI_MENU_RUMBLE_STRENGTH] = "Vibration strength",
[UI_MENU_RUMBLE_STRENGTH_DESC] = "How strong the vibration is.",
[UI_MENU_RUMBLE_CURVE] = "Vibration curve",

View File

@@ -105,6 +105,9 @@ typedef enum {
// Controls
UI_MENU_MOTION, UI_MENU_MOTION_DESC,
UI_MENU_SPRINT_BUTTON, UI_MENU_SPRINT_BUTTON_DESC, UI_MENU_SPRINT_OFF, UI_MENU_SPRINT_B, UI_MENU_SPRINT_L,
UI_MENU_SPRINT_R, UI_MENU_SPRINT_L3, UI_MENU_SPRINT_R3, UI_MENU_SPRINT_MODE, UI_MENU_SPRINT_MODE_DESC,
UI_MENU_SPRINT_TOGGLE, UI_MENU_SPRINT_HOLD,
UI_MENU_RUMBLE_STRENGTH, UI_MENU_RUMBLE_STRENGTH_DESC,
UI_MENU_RUMBLE_CURVE, UI_MENU_RUMBLE_CURVE_DESC,
UI_MENU_RUMBLE_TRIGGERS, UI_MENU_RUMBLE_TRIGGERS_DESC,