mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-21 21:05:56 +00:00
Give the mouse the same degrees per count in every player camera, and fix the soothe button and the mouse shake
Only the free camera took the mouse as degrees. The other camera modes took it as stick input, which their own speeds, frame time, slow motion and curves reshaped, with the on-foot camera's square-root pitch shaping on top: bow aiming was far too sensitive vertically on slow movements, abilities and the Purah Pad camera eased their pitch, lock-on turned 27% slower, and climbing, shield surfing and the rest each turned at their own rate. Each camera mode's update now loads the gamepad's part of the stick where it computes its turn and adds the mouse's degrees where it adds that turn to its angle (runtime/mouse_direct.c camera_load, the load sites of recomp/patches-v143.txt): aiming, scope, abilities (and Recall's cursor), horse, Purah Pad camera, lock-on, bow lock-on, wall and object climbing, the waterfall's turn, shield surfing, wakeboard and the dialogue cameras. Recall's cursor moves so that its aim turns as many degrees a count. The waterfall's height and the horse's empty lock-on are not angles and stay stick input, now linear. A step whose mouse motion no hook took is logged with the camera's name. Holding L to soothe the horse gave the mouse to the ability wheel's virtual cursor, a held stick for the camera: the mouse goes to the wheel and the D-pad strips only while their screen has the focus (menu_cursor.c menu_cursor_shortcut). A mouse shake no longer plays a 0.8 s swing after it: the right stick follows the mouse's own swings and lets go when it rests, and the camera does not turn by that swing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
27f64d6a29
commit
a1cd122625
8 files changed
+778
-73
No files matched your search
+7
-1
@@ -619,10 +619,16 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
|
||||
pick(&sr[0], &sr[1], k[0], k[1]);
|
||||
int selector = b & (1ull << B_L) ? 1 : b & (1ull << B_UP) ? 2 :
|
||||
b & (1ull << B_LEFT) ? 3 : b & (1ull << B_RIGHT) ? 4 : 0;
|
||||
// Only while the wheel or a strip is on screen (menu_cursor.c reads the focused screen): L also soothes the
|
||||
// horse and turns menu tabs, the D-pad does other things too, and then the mouse stays on the camera.
|
||||
// Before the screens were read (the menu cursor off) the buttons alone decide, as before.
|
||||
if (selector && menu_cursor_shortcut() == 0) selector = 0;
|
||||
mouse_camera(k, selector);
|
||||
pick(&sr[0], &sr[1], k[0], k[1]);
|
||||
int32_t shake = shake_stick(input_map_held(down, B_SHAKE) || input_direct_mouse_shake());
|
||||
int32_t shake = shake_stick(input_map_held(down, B_SHAKE));
|
||||
if (shake) sr[0] = shake, sr[1] = 0;
|
||||
// A mouse shake (mouse_direct.c) moves the stick with the mouse, side by side, and lets go when it rests
|
||||
else if (input_direct_mouse_shake()) sr[0] = input_direct_mouse_shake() * STICK_MAX, sr[1] = 0;
|
||||
static uint32_t travel_seen;
|
||||
uint32_t travel = ikb_mouse_travel();
|
||||
if (travel - travel_seen >= MOUSE_USED) kbm_used = 1;
|
||||
|
||||
+4
-1
@@ -25,8 +25,11 @@ int input_direct_mouse_selector_active(void);
|
||||
void input_direct_mouse_sample(int enabled, int32_t *dx, int32_t *dy);
|
||||
// The buttons (B_* bits) of the last poll, keys and gamepad merged; any thread (mouse_direct.c: ZR for the bow's scale)
|
||||
uint64_t input_buttons_last(void);
|
||||
// mouse_direct.c: the mouse was shaken while Ultrahand holds an object; input.c plays the stick shake as for the key
|
||||
// mouse_direct.c: the right stick's side a mouse shake gives while Ultrahand holds an object (-1 / +1), 0 while the
|
||||
// mouse does not shake; input.c puts it on the stick
|
||||
int input_direct_mouse_shake(void);
|
||||
// menu_cursor.c: the L ability wheel or a D-pad strip has the focus: 1 / 0, -1 with the menu cursor off (not read)
|
||||
int menu_cursor_shortcut(void);
|
||||
// menu_cursor.c: the pointer in the game's menus (1.4.3). poll: once per pad read, adds a click's A or B; pointer: a
|
||||
// menu has the pointer, so the mouse camera's capture is released
|
||||
void menu_cursor_poll(uint64_t *buttons);
|
||||
|
||||
@@ -338,3 +338,14 @@ void menu_cursor_poll(uint64_t *buttons) {
|
||||
else pending_a = 1, pending_node = at, pending_until = now + 300;
|
||||
}
|
||||
}
|
||||
|
||||
// The L ability wheel or a D-pad strip (materials, weapons, shields, bows) has the focus: 1 / 0, -1 with the menu
|
||||
// cursor off (the screens are not read). input.c asks while L or the D-pad is held, before it gives the mouse to their
|
||||
// selectors: L also soothes the horse and turns menu tabs, the D-pad does other things too.
|
||||
int menu_cursor_shortcut(void) {
|
||||
if (!enabled()) return -1;
|
||||
Focus f = focus_now();
|
||||
char nm[48] = "";
|
||||
if (f.screen) layout_name(f.screen, nm, sizeof nm);
|
||||
return f.screen && (!strcmp(nm, "ShortCutMainItem_00") || !strcmp(nm, "ShortCut_00"));
|
||||
}
|
||||
+444
-37
@@ -2,11 +2,13 @@
|
||||
// into a radial dead zone, clamps the radius to one and applies StickExponent. The mouse enters after all three,
|
||||
// at main+0x874cb4, before the game's X/Y inversion and input-activity flags. It never becomes a HID stick value.
|
||||
// Free orbit removes that sample again before the camera's additional vertical square/velocity filters and adds
|
||||
// raw-count angular deltas at its spherical-angle output instead. Ultrahand has a separate post-curve hook.
|
||||
// raw-count angular deltas at its spherical-angle output instead. The aiming, scope, ability, horse and Purah Pad
|
||||
// cameras do the same at the angle each integrates from (camera_load). Ultrahand has a separate post-curve hook.
|
||||
// The other camera modes still take the mouse as stick, linear on both axes (mouse_stick_add).
|
||||
// The ordinary stick's result stays, so a controller still uses the game's own response.
|
||||
//
|
||||
// This is deliberately not a render-camera override: the game remains responsible for aiming, camera collision,
|
||||
// lock-on and scripted cameras. Which of its other modes consume this camera input needs in-game verification.
|
||||
// lock-on and scripted cameras.
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@@ -28,10 +30,11 @@
|
||||
// 70 degrees a second at a full stick, so this is a full stick's turn for 1500 counts a second. The stick rates and the
|
||||
// ability camera's scales below are those Weeping of the Empire's engine/runtime/pc_mouse.cpp works with.
|
||||
#define DEG_PER_COUNT (70.0f / 1500.0f)
|
||||
// The stick turns yaw 70 x / 30 degrees per step at the 30 Hz frame ratio, and pitch 51 y |y| / 30 (a signed square):
|
||||
// a processed stick value of STICK_PER_COUNT a count turns yaw DEG_PER_COUNT, and the mouse's part of y is the square
|
||||
// root of PITCH_GAIN |v| so pitch turns as many degrees a count as yaw, at any speed.
|
||||
// The stick turns yaw 70 x / 30 degrees per step at the 30 Hz frame ratio: a processed stick value of STICK_PER_COUNT a
|
||||
// count turns yaw DEG_PER_COUNT in the cameras that still take the mouse as stick (mouse_stick_add).
|
||||
#define STICK_PER_COUNT (DEG_PER_COUNT * 30.0f / 70.0f)
|
||||
// Pitch turns 51 degrees a second a unit of y against yaw's 70 a unit of x (linearly in every camera but the free
|
||||
// orbit, which squares y and takes degrees instead): the mouse's y is PITCH_GAIN times its x a count.
|
||||
#define PITCH_GAIN (70.0f / 51.0f)
|
||||
// The ability camera (ExecutePlayerCameraSpecialPower) turns the stored stick its own way: yaw x * 0.8 of on foot's
|
||||
// rate and pitch y * 1.5 * 51, linear (no signed square). The mouse's part is scaled back to on foot's degrees a count:
|
||||
@@ -66,10 +69,10 @@ int input_direct_mouse_active(void) {
|
||||
|
||||
int input_direct_mouse_enabled(void) { return direct_mode(); }
|
||||
|
||||
// A shake of the mouse while Ultrahand holds an object (camera_input, mouse_shake_step): input.c's shake_stick plays the
|
||||
// right-stick swing that detaches a fused part, as the shake key does, for a press until this time
|
||||
static volatile uint64_t shake_until;
|
||||
int input_direct_mouse_shake(void) { return plat_now_ns() < __atomic_load_n(&shake_until, __ATOMIC_RELAXED); }
|
||||
// A shake of the mouse while Ultrahand holds an object (camera_input, mouse_shake_step): the right stick's side that
|
||||
// follows it, -1 / +1, 0 while the mouse does not shake (input.c puts it on the right stick's x)
|
||||
static volatile int32_t shake_side;
|
||||
int input_direct_mouse_shake(void) { return __atomic_load_n(&shake_side, __ATOMIC_RELAXED); }
|
||||
|
||||
void input_direct_mouse_radial(int32_t dx, int32_t dy, float sensitivity, float cursor[2], int32_t out[2]) {
|
||||
if (!(sensitivity > 0)) { cursor[0] = cursor[1] = 0; out[0] = out[1] = 0; return; }
|
||||
@@ -119,9 +122,22 @@ typedef struct {
|
||||
uint64_t object, generation, when;
|
||||
float pad[2], motion[2], angle[2]; // post-inversion controller input, mouse input, mouse yaw/pitch in degrees
|
||||
int camera_enabled;
|
||||
uint32_t player; // player_state_logged's flags for this step (0 without mouse motion)
|
||||
} MouseSample;
|
||||
static MouseSample sample;
|
||||
static PlatMutex sample_lock = PLAT_MUTEX_INIT;
|
||||
// The generation of the last sample a direct hook turned a camera by (orbit_angles, load_stick); sample_lock. A sample
|
||||
// with mouse motion that none took went to its camera as stick input only (mouse_stick_add): camera_input logs that.
|
||||
static uint64_t sample_taken;
|
||||
// The last sample with mouse motion a watched camera mode loaded as stick (ROLE_WATCH): its generation and mode
|
||||
static uint64_t sample_watched;
|
||||
static int sample_watched_mode = -1;
|
||||
static const char *mode_name(int mode); // load_sites' camera modes, below
|
||||
static void sample_mark_taken(uint64_t generation) {
|
||||
plat_mutex_lock(&sample_lock);
|
||||
sample_taken = generation;
|
||||
plat_mutex_unlock(&sample_lock);
|
||||
}
|
||||
static _Thread_local struct { uint64_t object; MouseSample mouse; } orbit;
|
||||
typedef struct {
|
||||
uint64_t object, generation, input, seen;
|
||||
@@ -257,9 +273,12 @@ static void orbit_pitch_settle(OrbitTrack *track) {
|
||||
track->hold_pitch = 1, track->resume = 0;
|
||||
}
|
||||
|
||||
// The mouse's part of the processed stick for dx / dy counts at k stick units a count. On foot x is linear and y the
|
||||
// signed square root that makes the camera's signed-square pitch linear again; the ability camera's linear scales are
|
||||
// undone instead.
|
||||
// The mouse's part of the processed stick for dx / dy counts at k stick units a count. Only the free orbit turns its
|
||||
// pitch by the signed square of y, and it never takes this value (orbit_begin removes it, orbit_angles adds degrees).
|
||||
// The other cameras that read the stick turn both axes linearly, yaw at the orbit's rate and pitch at 51 / 70 of it
|
||||
// (Horse, ClimbObj, WaterfallClimb: PlayerCamera +0xc9c for pitch against +0xc9c times the yaw factor for yaw), so y
|
||||
// is linear with PITCH_GAIN. The cameras with load sites below take degrees instead; this is the fallback for the
|
||||
// rest. The ability camera's linear scales are undone in its offset mode, which the load sites leave to the stick.
|
||||
static void mouse_stick_add(int32_t dx, int32_t dy, float k, int ability, float *x, float *y) {
|
||||
float v = -dy * k;
|
||||
if (ability) {
|
||||
@@ -267,34 +286,52 @@ static void mouse_stick_add(int32_t dx, int32_t dy, float k, int ability, float
|
||||
*y += v * ABILITY_GAIN_Y;
|
||||
} else {
|
||||
*x += dx * k;
|
||||
*y += copysignf(sqrtf(PITCH_GAIN * fabsf(v)), v);
|
||||
*y += v * PITCH_GAIN;
|
||||
}
|
||||
}
|
||||
|
||||
// The game detaches a fused part when the right stick swings left and right a few times; in direct mode the mouse
|
||||
// never reaches that stick. A shake: horizontal swings of at least SHAKE_SWING_DEG of camera turn each, changing
|
||||
// direction SHAKE_TURNS times within SHAKE_WINDOW_NS of the first change. Turning a held object back and forth at an
|
||||
// ordinary pace takes longer than that, and a reversal after a shorter swing starts the count again.
|
||||
// never reaches that stick. Once the mouse shakes (horizontal swings of at least SHAKE_SWING_DEG of camera turn each,
|
||||
// changing direction SHAKE_FOLLOW_TURNS times within SHAKE_WINDOW_NS of the first change), the right stick follows
|
||||
// it: full tilt the way the mouse moves, each side held at least SHAKE_SIDE_NS (two frames at the game's 30 fps) so
|
||||
// every side is read, neutral as soon as the mouse rests. Only the player's own swings reach the stick, nothing plays
|
||||
// on after them; SHAKE_IDLE_NS without motion ends the shake. Turning a held object back and forth at an ordinary pace
|
||||
// takes longer than the window, and a reversal after a shorter swing starts the count again.
|
||||
#define SHAKE_SWING_DEG 10.0f
|
||||
#define SHAKE_TURNS 3
|
||||
#define SHAKE_WINDOW_NS 600000000ull
|
||||
typedef struct { int dir, turns; float swing; uint64_t first; } MouseShake;
|
||||
// deg: this step's horizontal motion in degrees of camera turn. 1 when it completes a shake (the state starts over).
|
||||
#define SHAKE_FOLLOW_TURNS 2
|
||||
#define SHAKE_WINDOW_NS 350000000ull
|
||||
#define SHAKE_SIDE_NS 66666667ull
|
||||
#define SHAKE_IDLE_NS 150000000ull
|
||||
typedef struct { int dir, turns, side; float swing; uint64_t first, side_from, moved; } MouseShake;
|
||||
// deg: this step's horizontal motion in degrees of camera turn. Returns the right stick's side for this step: -1 / +1
|
||||
// while it follows the mouse's shake, 0 otherwise.
|
||||
static int mouse_shake_step(MouseShake *s, float deg, uint64_t now) {
|
||||
if (s->turns && now - s->first > SHAKE_WINDOW_NS) s->turns = 0;
|
||||
if (deg == 0) return 0;
|
||||
int d = deg > 0 ? 1 : -1;
|
||||
if (d == s->dir) { s->swing += fabsf(deg); return 0; }
|
||||
if (s->dir && s->swing >= SHAKE_SWING_DEG) {
|
||||
if (!s->turns) s->first = now;
|
||||
s->turns++;
|
||||
} else {
|
||||
s->turns = 0;
|
||||
int following = s->turns >= SHAKE_FOLLOW_TURNS;
|
||||
if (!following && s->turns && now - s->first > SHAKE_WINDOW_NS) s->turns = 0;
|
||||
if (deg != 0) {
|
||||
int d = deg > 0 ? 1 : -1;
|
||||
s->moved = now;
|
||||
if (d == s->dir) {
|
||||
s->swing += fabsf(deg);
|
||||
} else {
|
||||
if (following || (s->dir && s->swing >= SHAKE_SWING_DEG)) {
|
||||
if (!s->turns) s->first = now;
|
||||
s->turns++;
|
||||
} else {
|
||||
s->turns = 0;
|
||||
}
|
||||
s->dir = d, s->swing = fabsf(deg);
|
||||
}
|
||||
following = s->turns >= SHAKE_FOLLOW_TURNS;
|
||||
} else if (following && now - s->moved >= SHAKE_IDLE_NS) { // the shake is over
|
||||
*s = (MouseShake){0};
|
||||
return 0;
|
||||
}
|
||||
s->dir = d, s->swing = fabsf(deg);
|
||||
if (s->turns < SHAKE_TURNS) return 0;
|
||||
*s = (MouseShake){0};
|
||||
return 1;
|
||||
if (!following) return 0;
|
||||
if (s->side && now - s->side_from < SHAKE_SIDE_NS) return s->side; // a side is read before the next
|
||||
int want = deg != 0 ? s->dir : 0; // neutral while the mouse rests
|
||||
if (want != s->side) s->side = want, s->side_from = now;
|
||||
return s->side;
|
||||
}
|
||||
|
||||
// A host call at an instruction site, not an AAPCS64 function replacement. Preserve every guest register except
|
||||
@@ -316,18 +353,27 @@ static void camera_input(Cpu *c) {
|
||||
float sensitivity = (float)cfg_double("TOTK_MOUSE_SENS");
|
||||
sensitivity = fminf(10, fmaxf(0, sensitivity));
|
||||
uint32_t player = (dx || dy) ? player_state_logged() : 0;
|
||||
next.player = player;
|
||||
int ability = (player & PLAYER_ABILITY) != 0;
|
||||
// The bow drawn (in hand with ZR held): mouse_aim_scale times the mouse's motion on every path
|
||||
if ((player & PLAYER_BOW) && (input_buttons_last() & (1ull << B_ZR)))
|
||||
sensitivity *= (float)fminf(3, fmaxf(0.1, cfg_double("TOTK_MOUSE_AIM_SCALE")));
|
||||
// Ultrahand holding an object: a shake of the mouse is the stick shake (a press held 100 ms for shake_stick)
|
||||
// Ultrahand holding an object: a shake of the mouse swings the right stick with it (mouse_shake_step)
|
||||
static MouseShake shake;
|
||||
static int last_side;
|
||||
uint64_t step_now = plat_now_ns();
|
||||
if (hand_active(step_now) && mouse_shake_step(&shake, dx * DEG_PER_COUNT * sensitivity, step_now)) {
|
||||
__atomic_store_n(&shake_until, step_now + 100000000ull, __ATOMIC_RELAXED);
|
||||
int side = 0;
|
||||
if (hand_active(step_now)) side = mouse_shake_step(&shake, dx * DEG_PER_COUNT * sensitivity, step_now);
|
||||
else shake = (MouseShake){0};
|
||||
__atomic_store_n(&shake_side, side, __ATOMIC_RELAXED);
|
||||
if (side) {
|
||||
static int logged;
|
||||
if (!logged) logged = 1, rt_log("mouse: a shake while Ultrahand holds an object shakes the right stick");
|
||||
if (!logged) logged = 1, rt_log("mouse: a shake while Ultrahand holds an object swings the right stick with it");
|
||||
}
|
||||
// That swing is the mouse's own motion, which turns the camera in degrees already: the camera hooks take the
|
||||
// right stick's x as 0 while it swings (the stick read of this step may still carry the last step's side)
|
||||
if (side || last_side) next.pad[0] = 0;
|
||||
last_side = side;
|
||||
// The game multiplies camera input by its 30 Hz frame ratio later. Divide by that exact ratio, rather
|
||||
// than wall-clock time: an equal distance of mouse motion then gives equal input at every frame rate.
|
||||
float ratio = 1;
|
||||
@@ -362,9 +408,22 @@ static void camera_input(Cpu *c) {
|
||||
}
|
||||
}
|
||||
plat_mutex_lock(&sample_lock);
|
||||
MouseSample last = sample;
|
||||
int untaken = last.camera_enabled && (last.angle[0] || last.angle[1]) && sample_taken != last.generation;
|
||||
int watched = sample_watched == last.generation ? sample_watched_mode : -1;
|
||||
next.generation = sample.generation + 1;
|
||||
sample = next;
|
||||
plat_mutex_unlock(&sample_lock);
|
||||
// The camera modes still on stick input, as play reaches them: the first 30 steps, then one in 600
|
||||
static unsigned untaken_count;
|
||||
if (untaken && (++untaken_count <= 30 || untaken_count % 600 == 0)) {
|
||||
uint32_t state = 0;
|
||||
if (readable(last.object, 0x160)) memcpy(&state, (void *)(uintptr_t)(last.object + 0x15c), sizeof state);
|
||||
rt_log("mouse: step %u with mouse motion took the stick path (no direct camera hook): camera %s, player "
|
||||
"%s%s%s, input +0x15c %#x", untaken_count, watched >= 0 ? mode_name(watched) : "not a watched one",
|
||||
last.player & PLAYER_FOUND ? "found" : "not found", last.player & PLAYER_ABILITY ? ", using an ability" : "",
|
||||
last.player & PLAYER_BOW ? ", bow in hand" : "", state);
|
||||
}
|
||||
uint32_t original = (uint32_t)c->v[9];
|
||||
memcpy((void *)(uintptr_t)(c->x[20] + 0x420), &original, sizeof original);
|
||||
}
|
||||
@@ -424,6 +483,7 @@ static void orbit_angles(Cpu *c) {
|
||||
int fresh = plat_now_ns() - orbit.mouse.when < 150000000ull &&
|
||||
orbit_sample_once(object, orbit.mouse.generation);
|
||||
if (!fresh) yaw_delta = pitch_delta = 0;
|
||||
if (yaw_delta || pitch_delta) sample_mark_taken(orbit.mouse.generation);
|
||||
plat_mutex_lock(&sample_lock);
|
||||
OrbitTrack *track = orbit_track(object);
|
||||
if (track->hold_pitch || yaw_delta || pitch_delta) {
|
||||
@@ -485,6 +545,352 @@ static void hand_input(Cpu *c) {
|
||||
memcpy((void *)(uintptr_t)(c->sp + 0x48), &original, sizeof original);
|
||||
}
|
||||
|
||||
// ---- The other player cameras that turn by the stick: degrees at the angle they integrate from.
|
||||
// Each of these camera modes (vtable slot 36 of its ExecutePlayerCamera* class, the per-step update) turns by the
|
||||
// processed stick at input +0x420 (x) / +0x424 (y) times its own speeds and the frame time, and adds that to a base
|
||||
// angle in degrees. Two loads per axis are replaced by a host call (the `mouse_direct` load sites of
|
||||
// recomp/patches-v143.txt, all at page +0xf80; the return address tells them apart):
|
||||
// stick: the load the turn is computed from gets the gamepad's part only (the sample's pad, post-inversion as the
|
||||
// game stored it), so the mode's speeds, time step and slow motion never touch the mouse;
|
||||
// base: the load of the angle the turn is added to gets the mouse's degrees added, DEG_PER_COUNT a count as the
|
||||
// free orbit, once per sample. The game's clamps, collision and blends run on the result as usual.
|
||||
// The stick loads that only test whether there is input (before the gyro branch) keep the mouse, so a mouse move
|
||||
// still counts as stick input there. The stick load always runs before its base load; it leaves the degrees for that
|
||||
// base (pending), so the two never disagree about a step.
|
||||
// Aiming (bow, throwing; main+0x23be978): yaw = input +0x414 + turn ([x29-0x48]), pitch target = +0x15c + turn, the
|
||||
// pitch follows its target at once (main+0x191970 with rate 1).
|
||||
// AimingTelescope (the scope; main+0x23c08ac) and SpecialPower (abilities; main+0x23d2d40): yaw as
|
||||
// Aiming ([sp+0x58], [x29-0x50]); pitch is +0x160 in degrees, taken to a position along an eased curve
|
||||
// (main+0x23c11d8 / 0x23d38e0), moved by the stick and taken back (main+0x23c14dc / 0x23d3be4). Degrees added to
|
||||
// +0x160 before that come back unchanged, so the curve no longer shapes the mouse. Beyond the pitch limits
|
||||
// (+0x1ac / +0x1b0) the stick moves a second camera parameter instead; the mouse's part past the limit stays in
|
||||
// the stick for that (LIMIT_160). That parameter is the camera's distance (the first of the (distance, pitch, yaw)
|
||||
// main+0x2e2468 takes from the camera's look vector), not a turn.
|
||||
// SpecialPower's offset mode (input +0x15c bit 8; SKIP_OFFSET on the sites above, ONLY_OFFSET below) is Recall's
|
||||
// cursor: the camera keeps a direction (+0x54 yaw) and the stick moves the cursor, +0x1d8 += x *
|
||||
// ReverseRecorderCursorSpeed * frame ratio and +0x1dc likewise, clamped to ReverseRecorderCursorRange; the camera
|
||||
// follows it, yaw = +0x54 - +0x1d8 * P.x and pitch = ... - +0x1dc * P.y with P = ReverseRecorderCameraRange (the
|
||||
// getters main+0x18a82a0, 0x18a824c, 0x18a8348; the step publishes the cursor at input +0x6c0). The cursor's base
|
||||
// loads get the change that moves the aim, the camera's turn plus the cursor's angle from the screen's centre
|
||||
// (o * P + atan(o * tan(half view angle)), the offset taken as the screen's half width / height), by the mouse's
|
||||
// degrees: the world under the cursor moves DEG_PER_COUNT a count, as the camera turns elsewhere (recall_offset).
|
||||
// P is read where the step loads P.y (ROLE_SCALE, both floats); until it was read once the mouse stays in the stick.
|
||||
// CameraFinder (the Purah Pad camera; main+0x23c26c8): pitch = +0x50 - PlayerCamera +0xc9c * y * frame ratio,
|
||||
// clamped; yaw = input +0x414 ([sp+0x48]) - the same with x.
|
||||
// LockOn / Target (lock-on; main+0x23d7140): the game points the camera at the target and the stick adds an offset,
|
||||
// yaw +0xbc and pitch +0xa4 += the step's turn ([sp+0x20], -PlayerCamera +0xc9c * stick * frame time), which the
|
||||
// update then limits and lets return; the step's turn is read twice (ROLE_BASE_KEEP, then ROLE_BASE) and also
|
||||
// decides that return, so it is the turn that gets the mouse's degrees. Where the camera points stays the game's.
|
||||
// LockOnAimingAt (the bow drawn while locked on, BowLockOn / BowLockOn_Horse; its stick step main+0x23cec74):
|
||||
// pitch offset +0x198 and yaw offset +0x19c += -PlayerCamera +0xc9c * stick * frame time, then clamped. The
|
||||
// other bow cameras (Bow, Bow_Crouch, Bow_Zoom, Bow_Horse, Bow_Zoom_Horse) are Aiming.
|
||||
// Tail (wall climbing, parameter set Climb; main+0x23d4950): the stick as angle and length; in its manual state
|
||||
// (+0x16c == 4) yaw +0xc0 and pitch +0xb4 -= x / y * speed * frame ratio. ClimbObj (main+0x23c3a98): pitch +0x88
|
||||
// (a pre-indexed load) and yaw +0x90 likewise. WaterfallClimb (main+0x23dce00): yaw = the camera's yaw - x * speed
|
||||
// * frame ratio, kept at [x29-0x34] and loaded into w8 (the base); its vertical axis moves the camera's height
|
||||
// (ManualHeightMin..Max), not an angle, and stays stick input (watched).
|
||||
// EventMultiTalk (main+0x23c531c) and EventTalkManual (main+0x23c8ffc): pitch / yaw fields -= stick * speed *
|
||||
// frame ratio; MultiTalk's x load is also its input test (EPSILON).
|
||||
// ShieldSurfing (main+0x23d0088) and Wakeboard (main+0x23da61c), one template: the stick as angle and length; yaw
|
||||
// in the steering state = the camera's yaw ([sp+0x3c]) - x * speed * frame time; pitch = +0xdc / +0xd8 taken to an
|
||||
// eased curve's position, moved by K * -y|y| ([sp+0x10] / [sp+0x14]) and taken back, and the same turn moves a
|
||||
// second parameter. Stick y keeps the mouse (KEEP_STICK), the pitch base gets the degrees, the pitch's turn is cut
|
||||
// to the pad's share (ROLE_SHARE); stick x is EPSILON, its length also choosing the steering state.
|
||||
// HorseLockOnEmpty (ZL on a horse with no target) maps the stick's position to an offset that returns with it: no
|
||||
// degrees a count to give, so it stays stick input (watched).
|
||||
// Horse (main+0x23ca518, its helpers main+0x23cb1d4 and 0x23cb398): yaw = input +0x414 + turn (+0x68), pitch =
|
||||
// input +0x410 + turn (+0x64), clamped to +0x5c..+0x60.
|
||||
// Every one of them turns by -K x and -K y for a stick (x, y) and a positive K, as the free orbit does: the sample's
|
||||
// angle[] (-x and -y in counts, times DEG_PER_COUNT) is added as it is.
|
||||
#define HOST_MOUSE_LOAD (RT_PATCH_PAGE + 0xf80)
|
||||
// ROLE_BASE_KEEP: a base load another base load follows. ROLE_SHARE: a turn the game computed from a stick load with
|
||||
// KEEP_STICK, cut to the gamepad's share of it.
|
||||
enum { ROLE_STICK, ROLE_BASE, ROLE_SCALE, ROLE_WATCH, ROLE_BASE_KEEP, ROLE_SHARE };
|
||||
// Stick flags. EPSILON: the load is also the game's test for input, so with the gamepad's axis at rest and the mouse
|
||||
// moving it gives +-1e-12 in the mouse's direction (input, no turn) instead of 0. KEEP_STICK: the value stays the
|
||||
// game's, mouse and all (other parameters follow it); the turn it makes is cut to the pad's share at ROLE_SHARE.
|
||||
enum { LIMIT_160 = 1, SKIP_OFFSET = 2, ONLY_OFFSET = 4, EPSILON = 8, KEEP_STICK = 16 };
|
||||
enum {
|
||||
MODE_AIM, MODE_SCOPE, MODE_ABILITY, MODE_HORSE, MODE_ABILITY_OFFSET, MODE_FINDER,
|
||||
MODE_CLIMB, MODE_WAKEBOARD, MODE_WATERFALL, MODE_TAIL, MODE_LOCKON, MODE_LOCKON_AIM, MODE_HORSE_LOCKON, MODE_TALK,
|
||||
MODE_TALK_MANUAL, MODE_SHIELD,
|
||||
MODE_COUNT
|
||||
};
|
||||
static const char *const mode_names[MODE_COUNT] = {
|
||||
"aiming (bow, throw)", "scope", "ability", "horse", "Recall cursor (ability offset mode)", "Purah Pad camera",
|
||||
"climbing an object (ClimbObj)", "Wakeboard", "waterfall climbing (WaterfallClimb)", "climbing (Tail)",
|
||||
"LockOn / Target", "bow lock-on (LockOnAimingAt)", "HorseLockOnEmpty", "dialogue (EventMultiTalk)",
|
||||
"dialogue (EventTalkManual)", "shield surfing"};
|
||||
static const char *mode_name(int mode) { return mode >= 0 && mode < MODE_COUNT ? mode_names[mode] : "?"; }
|
||||
typedef struct {
|
||||
uint32_t offset, insn; // main offset, the original load (ldr / ldur s<t>, [x<n>, #imm])
|
||||
uint8_t mode, axis, role, input_reg, flags;
|
||||
} LoadSite;
|
||||
#define PAIR(m, a) ((m) * 2 + (a))
|
||||
static const LoadSite load_sites[] = {
|
||||
{0x23beb94, 0xbd4426c1, MODE_AIM, 1, ROLE_STICK, 22, 0}, // ldr s1, [x22, #0x424]
|
||||
{0x23bebc8, 0xbd415e61, MODE_AIM, 1, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x15c]
|
||||
{0x23bee2c, 0xbd4422c1, MODE_AIM, 0, ROLE_STICK, 22, 0}, // ldr s1, [x22, #0x420]
|
||||
{0x23beeec, 0xbc5b83a1, MODE_AIM, 0, ROLE_BASE, 0, 0}, // ldur s1, [x29, #-0x48]
|
||||
{0x23c0a10, 0xbd4422e0, MODE_SCOPE, 0, ROLE_STICK, 23, 0}, // ldr s0, [x23, #0x420]
|
||||
{0x23c0a1c, 0xbd4426eb, MODE_SCOPE, 1, ROLE_STICK, 23, LIMIT_160}, // ldr s11, [x23, #0x424]
|
||||
{0x23c0b00, 0xbd416260, MODE_SCOPE, 1, ROLE_BASE, 0, 0}, // ldr s0, [x19, #0x160]
|
||||
{0x23c0e80, 0xbd405be1, MODE_SCOPE, 0, ROLE_BASE, 0, 0}, // ldr s1, [sp, #0x58]
|
||||
{0x23d2eec, 0xbd4422e8, MODE_ABILITY, 0, ROLE_STICK, 23, SKIP_OFFSET}, // ldr s8, [x23, #0x420]
|
||||
{0x23d2ef4, 0xbd4426ee, MODE_ABILITY, 1, ROLE_STICK, 23, SKIP_OFFSET | LIMIT_160}, // ldr s14, [x23, #0x424]
|
||||
{0x23d3158, 0xbd416260, MODE_ABILITY, 1, ROLE_BASE, 0, 0}, // ldr s0, [x19, #0x160]
|
||||
{0x23d34cc, 0xbc5b03a1, MODE_ABILITY, 0, ROLE_BASE, 0, 0}, // ldur s1, [x29, #-0x50]
|
||||
{0x23cb274, 0xbd442288, MODE_HORSE, 0, ROLE_STICK, 20, 0}, // ldr s8, [x20, #0x420]
|
||||
{0x23cb2a0, 0xbd406a61, MODE_HORSE, 0, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x68]
|
||||
{0x23cb3f8, 0xbd4426a8, MODE_HORSE, 1, ROLE_STICK, 21, 0}, // ldr s8, [x21, #0x424]
|
||||
{0x23cb424, 0xbd406661, MODE_HORSE, 1, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x64]
|
||||
{0x23d2f30, 0xbd4422e8, MODE_ABILITY_OFFSET, 0, ROLE_STICK, 23, ONLY_OFFSET}, // ldr s8, [x23, #0x420]
|
||||
{0x23d2f5c, 0xbd41da62, MODE_ABILITY_OFFSET, 0, ROLE_BASE, 0, 0}, // ldr s2, [x19, #0x1d8]
|
||||
{0x23d2f6c, 0xbd4426e8, MODE_ABILITY_OFFSET, 1, ROLE_STICK, 23, ONLY_OFFSET}, // ldr s8, [x23, #0x424]
|
||||
{0x23d2f98, 0xbd41de62, MODE_ABILITY_OFFSET, 1, ROLE_BASE, 0, 0}, // ldr s2, [x19, #0x1dc]
|
||||
{0x23d3210, 0xbd400400, MODE_ABILITY_OFFSET, 1, ROLE_SCALE, 0, 0}, // ldr s0, [x0, #0x4] (P.y)
|
||||
{0x23c2890, 0xbd4426ad, MODE_FINDER, 1, ROLE_STICK, 21, 0}, // ldr s13, [x21, #0x424]
|
||||
{0x23c28b4, 0xbd405261, MODE_FINDER, 1, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x50]
|
||||
{0x23c2934, 0xbd4422ad, MODE_FINDER, 0, ROLE_STICK, 21, 0}, // ldr s13, [x21, #0x420]
|
||||
{0x23c2964, 0xbd404be1, MODE_FINDER, 0, ROLE_BASE, 0, 0}, // ldr s1, [sp, #0x48]
|
||||
{0x23c3dd0, 0xbd442301, MODE_CLIMB, 0, ROLE_STICK, 24, 0}, // ldr s1, [x24, #0x420]
|
||||
{0x23c3dd8, 0xbd409261, MODE_CLIMB, 0, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x90] (yaw)
|
||||
{0x23c3d64, 0xbd442701, MODE_CLIMB, 1, ROLE_STICK, 24, 0}, // ldr s1, [x24, #0x424]
|
||||
{0x23c3d70, 0xbc488ec1, MODE_CLIMB, 1, ROLE_BASE, 0, 0}, // ldr s1, [x22, #0x88]! (pitch; x22 = x19)
|
||||
{0x23da694, 0xbd4422c1, MODE_WAKEBOARD, 0, ROLE_STICK, 22, EPSILON}, // ldr s1, [x22, #0x420]
|
||||
{0x23da698, 0xbd4426c0, MODE_WAKEBOARD, 1, ROLE_STICK, 22, KEEP_STICK}, // ldr s0, [x22, #0x424]
|
||||
{0x23da840, 0xbd40da60, MODE_WAKEBOARD, 1, ROLE_BASE, 0, 0}, // ldr s0, [x19, #0xd8] (pitch)
|
||||
{0x23da894, 0xbd4017e0, MODE_WAKEBOARD, 1, ROLE_SHARE, 0, 0}, // ldr s0, [sp, #0x14] (pitch turn)
|
||||
{0x23daed8, 0xbd403fe9, MODE_WAKEBOARD, 0, ROLE_BASE, 0, 0}, // ldr s9, [sp, #0x3c] (yaw)
|
||||
{0x23d0100, 0xbd4422c1, MODE_SHIELD, 0, ROLE_STICK, 22, EPSILON}, // ldr s1, [x22, #0x420]
|
||||
{0x23d0104, 0xbd4426c0, MODE_SHIELD, 1, ROLE_STICK, 22, KEEP_STICK}, // ldr s0, [x22, #0x424]
|
||||
{0x23d02ac, 0xbd40de60, MODE_SHIELD, 1, ROLE_BASE, 0, 0}, // ldr s0, [x19, #0xdc] (pitch)
|
||||
{0x23d0a34, 0xbd4013e0, MODE_SHIELD, 1, ROLE_SHARE, 0, 0}, // ldr s0, [sp, #0x10] (pitch turn)
|
||||
{0x23d087c, 0xbd403fe9, MODE_SHIELD, 0, ROLE_BASE, 0, 0}, // ldr s9, [sp, #0x3c] (yaw)
|
||||
{0x23dced8, 0xbd4422cd, MODE_WATERFALL, 0, ROLE_STICK, 22, 0}, // ldr s13, [x22, #0x420]
|
||||
{0x23dd070, 0xb85cc3a8, MODE_WATERFALL, 0, ROLE_BASE, 0, 0}, // ldur w8, [x29, #-0x34] (yaw, as bits)
|
||||
{0x23dd008, 0xbd4426c9, MODE_WATERFALL, 1, ROLE_WATCH, 22, 0}, // ldr s9, [x22, #0x424] (height, stick)
|
||||
{0x23d4b14, 0xbd44228c, MODE_TAIL, 0, ROLE_STICK, 20, 0}, // ldr s12, [x20, #0x420]
|
||||
{0x23d4b1c, 0xbd44268d, MODE_TAIL, 1, ROLE_STICK, 20, 0}, // ldr s13, [x20, #0x424]
|
||||
{0x23d4f34, 0xbd40c260, MODE_TAIL, 0, ROLE_BASE, 0, 0}, // ldr s0, [x19, #0xc0] (yaw)
|
||||
{0x23d5028, 0xbd40b661, MODE_TAIL, 1, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0xb4] (pitch)
|
||||
{0x23d756c, 0xbd442300, MODE_LOCKON, 0, ROLE_WATCH, 24, 0}, // ldr s0, [x24, #0x420] (the input test)
|
||||
{0x23d7594, 0xbd442301, MODE_LOCKON, 0, ROLE_STICK, 24, 0}, // ldr s1, [x24, #0x420]
|
||||
{0x23d75b4, 0xbd4023e0, MODE_LOCKON, 0, ROLE_BASE_KEEP, 0, 0}, // ldr s0, [sp, #0x20] (the yaw turn)
|
||||
{0x23d75c4, 0xbd4023e9, MODE_LOCKON, 0, ROLE_BASE, 0, 0}, // ldr s9, [sp, #0x20]
|
||||
{0x23d7998, 0xbd442701, MODE_LOCKON, 1, ROLE_STICK, 24, 0}, // ldr s1, [x24, #0x424]
|
||||
{0x23d79b8, 0xbd4023e0, MODE_LOCKON, 1, ROLE_BASE_KEEP, 0, 0}, // ldr s0, [sp, #0x20] (the pitch turn)
|
||||
{0x23d79c8, 0xbd4023ea, MODE_LOCKON, 1, ROLE_BASE, 0, 0}, // ldr s10, [sp, #0x20]
|
||||
{0x23cecb4, 0xbd4426a9, MODE_LOCKON_AIM, 1, ROLE_STICK, 21, 0}, // ldr s9, [x21, #0x424]
|
||||
{0x23cecf8, 0xbd419a61, MODE_LOCKON_AIM, 1, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x198] (pitch offset)
|
||||
{0x23ced0c, 0xbd4422a9, MODE_LOCKON_AIM, 0, ROLE_STICK, 21, 0}, // ldr s9, [x21, #0x420]
|
||||
{0x23ced4c, 0xbd419e61, MODE_LOCKON_AIM, 0, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x19c] (yaw offset)
|
||||
{0x23cc4b4, 0xbd44232b, MODE_HORSE_LOCKON, 0, ROLE_WATCH, 25, 0}, // ldr s11, [x25, #0x420]
|
||||
{0x23c542c, 0xbd4426eb, MODE_TALK, 1, ROLE_STICK, 23, 0}, // ldr s11, [x23, #0x424]
|
||||
{0x23c546c, 0xbd405e61, MODE_TALK, 1, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x5c] (pitch)
|
||||
{0x23c54d4, 0xbd4422eb, MODE_TALK, 0, ROLE_STICK, 23, EPSILON}, // ldr s11, [x23, #0x420] (also the test)
|
||||
{0x23c5554, 0xbd406661, MODE_TALK, 0, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x64] (yaw)
|
||||
{0x23c90ac, 0xbd442709, MODE_TALK_MANUAL, 1, ROLE_STICK, 24, 0}, // ldr s9, [x24, #0x424]
|
||||
{0x23c90d8, 0xbd407661, MODE_TALK_MANUAL, 1, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x74] (pitch)
|
||||
{0x23c9140, 0xbd442309, MODE_TALK_MANUAL, 0, ROLE_STICK, 24, 0}, // ldr s9, [x24, #0x420]
|
||||
{0x23c9170, 0xbd407e61, MODE_TALK_MANUAL, 0, ROLE_BASE, 0, 0}, // ldr s1, [x19, #0x7c] (yaw)
|
||||
};
|
||||
#define LOAD_SITES (sizeof load_sites / sizeof load_sites[0])
|
||||
|
||||
// The original single-register 32-bit loads: LDR S (unsigned offset), LDUR S, LDR S pre-indexed (the base register
|
||||
// becomes the address) and LDUR W (a float's bits in a general register). Their address:
|
||||
static uint64_t load_address(const Cpu *c, uint32_t insn) {
|
||||
unsigned n = (insn >> 5) & 31;
|
||||
uint64_t base = n == 31 ? c->sp : c->x[n];
|
||||
if ((insn & 0xffc00000u) == 0xbd400000u) return base + (((insn >> 10) & 0xfff) << 2);
|
||||
int32_t imm9 = (int32_t)((insn >> 12) & 0x1ff);
|
||||
if (imm9 & 0x100) imm9 -= 0x200;
|
||||
return base + (int64_t)imm9;
|
||||
}
|
||||
static int load_pre_index(uint32_t insn) { return (insn & 0xffe00c00u) == 0xbc400c00u; }
|
||||
static int load_to_general(uint32_t insn) { return (insn & 0xffe00c00u) == 0xb8400000u; }
|
||||
|
||||
// Degrees a stick load left for its base load, on this thread: per mode and axis, for one camera object
|
||||
static _Thread_local struct { uint64_t object, generation; float degrees; } load_pending[MODE_COUNT * 2];
|
||||
// A KEEP_STICK load's gamepad part and total, for its ROLE_SHARE load
|
||||
static _Thread_local struct { uint64_t object; float pad, total; } load_share[MODE_COUNT * 2];
|
||||
// The sample each camera object and axis took its degrees from: a sample turns a camera once
|
||||
static struct { uint64_t object, generation[2]; } load_taken[16];
|
||||
static int load_take_once(uint64_t object, int axis, uint64_t generation) {
|
||||
plat_mutex_lock(&sample_lock);
|
||||
int slot = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (load_taken[i].object == object) { slot = i; goto found; }
|
||||
if (load_taken[i].generation[0] + load_taken[i].generation[1] <
|
||||
load_taken[slot].generation[0] + load_taken[slot].generation[1]) slot = i;
|
||||
}
|
||||
load_taken[slot].object = object;
|
||||
load_taken[slot].generation[0] = load_taken[slot].generation[1] = 0;
|
||||
found:;
|
||||
int fresh = load_taken[slot].generation[axis] != generation;
|
||||
load_taken[slot].generation[axis] = generation;
|
||||
plat_mutex_unlock(&sample_lock);
|
||||
return fresh;
|
||||
}
|
||||
|
||||
// The ability camera's offset scale P (degrees of turn per unit of offset, x and y), as its last step read it
|
||||
static struct { uint64_t object; float scale[2]; } offset_scale;
|
||||
|
||||
// Recall's view: SpecialPower's Fovy (50 degrees, vertical; PlayerCameraAIParam SpecialPower) times the field-of-view
|
||||
// factor and the camera's aspect ratio when those patch sets are on (resolution.c: page +60, +56), else 16:9. The tangent
|
||||
// of the half view angle along an axis (0 across, 1 up).
|
||||
#define RECALL_FOVY 50.0f
|
||||
#define RECALL_PI 3.14159265f
|
||||
static float recall_tan_half(int axis) {
|
||||
static int fov_set = -2, aspect_set = -2;
|
||||
if (fov_set == -2) fov_set = rt_patch_set("fov"), aspect_set = rt_patch_set("aspect");
|
||||
float fovy = RECALL_FOVY, aspect = 16.0f / 9.0f, v;
|
||||
const uint8_t *page = rt_patch_page();
|
||||
if (page && fov_set >= 0 && rt_patch_enabled(fov_set)) {
|
||||
memcpy(&v, page + 60, sizeof v);
|
||||
if (v > 0.5f && v < 2) fovy *= v;
|
||||
}
|
||||
if (page && aspect_set >= 0 && rt_patch_enabled(aspect_set)) {
|
||||
memcpy(&v, page + 56, sizeof v);
|
||||
if (v > 0.5f && v < 5) aspect = v;
|
||||
}
|
||||
float t = tanf(fovy * 0.5f * RECALL_PI / 180);
|
||||
return axis ? t : t * aspect;
|
||||
}
|
||||
|
||||
// The change of Recall's cursor offset o that moves its aim by `degrees`. The aim is the camera's follow, o * range
|
||||
// degrees, plus the cursor's angle from the centre, atan(o * t); it grows with o, so Newton's method converges from o.
|
||||
static float recall_offset(float o, float range, float t, float degrees) {
|
||||
const float k = 180 / RECALL_PI;
|
||||
float target = o * range + atanf(o * t) * k + degrees, n = o;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
float d = range + k * t / (1 + n * n * t * t);
|
||||
n -= (n * range + atanf(n * t) * k - target) / d;
|
||||
}
|
||||
return isfinite(n) ? n - o : 0;
|
||||
}
|
||||
|
||||
// The stick load: the gamepad's part of the axis, and the degrees for the base load. f is what the game stored.
|
||||
static float load_stick(const LoadSite *s, Cpu *c, float f) {
|
||||
uint64_t object = c->x[19], input = c->x[s->input_reg];
|
||||
int pair = PAIR(s->mode, s->axis);
|
||||
load_pending[pair].object = 0;
|
||||
MouseSample m = sample_read();
|
||||
if (m.object != input || !m.camera_enabled || plat_now_ns() - m.when >= 150000000ull) return f;
|
||||
float scale = 1;
|
||||
if (s->flags & (SKIP_OFFSET | ONLY_OFFSET)) {
|
||||
uint32_t state;
|
||||
memcpy(&state, (void *)(uintptr_t)(input + 0x15c), sizeof state);
|
||||
int offset = (state & 0x100) != 0;
|
||||
if ((s->flags & SKIP_OFFSET) && offset) return f;
|
||||
if (s->flags & ONLY_OFFSET) {
|
||||
if (!offset) return f;
|
||||
plat_mutex_lock(&sample_lock);
|
||||
scale = offset_scale.object == object ? offset_scale.scale[s->axis] : 0;
|
||||
plat_mutex_unlock(&sample_lock);
|
||||
if (!isfinite(scale) || fabsf(scale) < 1e-4f) { // not read yet: the stick, as the game turns it
|
||||
static int logged;
|
||||
if (!logged) logged = 1, rt_log("mouse: ability offset mode before its scale was read, stick input");
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
float mouse = f - m.pad[s->axis], degrees = m.angle[s->axis];
|
||||
float out = m.pad[s->axis];
|
||||
if (s->flags & KEEP_STICK) {
|
||||
out = f;
|
||||
load_share[pair].object = object, load_share[pair].pad = m.pad[s->axis], load_share[pair].total = f;
|
||||
} else if ((s->flags & EPSILON) && out == 0 && mouse != 0) {
|
||||
out = copysignf(1e-12f, mouse);
|
||||
}
|
||||
if (!degrees || !load_take_once(object, s->axis, m.generation)) degrees = 0;
|
||||
// The offset turns the camera by -offset * P: an aim that turns as the sample's angle is -degrees of o's growth
|
||||
if (s->flags & ONLY_OFFSET && degrees)
|
||||
degrees = recall_offset(guest_float(object + (s->axis ? 0x1dc : 0x1d8)), scale, recall_tan_half(s->axis),
|
||||
-degrees);
|
||||
if ((s->flags & LIMIT_160) && degrees) {
|
||||
float pitch = guest_float(object + 0x160), lo = guest_float(object + 0x1ac), hi = guest_float(object + 0x1b0);
|
||||
if (isfinite(pitch) && isfinite(lo) && isfinite(hi)) {
|
||||
if (lo > hi) { float t = lo; lo = hi; hi = t; }
|
||||
float want = pitch + degrees, kept = fminf(hi, fmaxf(lo, want));
|
||||
if (kept != want) { // past the limit: that share of the mouse's stick moves the camera's other parameter
|
||||
out += mouse * ((want - kept) / degrees);
|
||||
degrees = kept - pitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
load_pending[pair].object = object;
|
||||
load_pending[pair].generation = m.generation;
|
||||
load_pending[pair].degrees = degrees;
|
||||
return out;
|
||||
}
|
||||
|
||||
// The base load: the angle plus the degrees its stick load left (ROLE_BASE_KEEP leaves them for the next base load)
|
||||
static float load_base(const LoadSite *s, Cpu *c, float f) {
|
||||
uint64_t object = c->x[19];
|
||||
int pair = PAIR(s->mode, s->axis);
|
||||
if (load_pending[pair].object != object) return f;
|
||||
if (s->role != ROLE_BASE_KEEP) load_pending[pair].object = 0;
|
||||
float degrees = load_pending[pair].degrees;
|
||||
if (degrees) {
|
||||
sample_mark_taken(load_pending[pair].generation);
|
||||
static int logged[MODE_COUNT];
|
||||
if (!logged[s->mode]) {
|
||||
logged[s->mode] = 1;
|
||||
rt_log("mouse: %s camera angles directly, %.4f degrees per count at sensitivity 1",
|
||||
mode_names[s->mode], DEG_PER_COUNT);
|
||||
}
|
||||
}
|
||||
return f + degrees;
|
||||
}
|
||||
|
||||
// A turn the game made from a KEEP_STICK load's total t, as K * -t|t| (shield surfing, wakeboard: their pitch squares
|
||||
// the stick), cut to the gamepad's p: K * -p|p|, the mouse's part being degrees at the base load
|
||||
static float load_share_cut(const LoadSite *s, Cpu *c, float f) {
|
||||
int pair = PAIR(s->mode, s->axis);
|
||||
if (load_share[pair].object != c->x[19]) return f;
|
||||
load_share[pair].object = 0;
|
||||
float p = load_share[pair].pad, t = load_share[pair].total;
|
||||
return t != 0 && isfinite(f) ? f * (p * fabsf(p)) / (t * fabsf(t)) : f;
|
||||
}
|
||||
|
||||
// A host call in place of one float load (load_sites): performs the load, then gives the register the value above
|
||||
static void camera_load(Cpu *c) {
|
||||
uint64_t offset = c->x[30] - 4 - MOD_MAIN_BASE;
|
||||
const LoadSite *s = NULL;
|
||||
for (size_t i = 0; i < LOAD_SITES; i++)
|
||||
if (load_sites[i].offset == offset) { s = &load_sites[i]; break; }
|
||||
if (!s) {
|
||||
rt_log("mouse: load hook called from main+%#llx, no such site", (unsigned long long)offset);
|
||||
abort();
|
||||
}
|
||||
uint64_t at = load_address(c, s->insn);
|
||||
float f = guest_float(at);
|
||||
if (load_pre_index(s->insn)) c->x[(s->insn >> 5) & 31] = at; // the pre-indexed load's write-back
|
||||
if (s->role == ROLE_SCALE) { // the ability camera's offset scale: P.y is this load, P.x the float before it
|
||||
plat_mutex_lock(&sample_lock);
|
||||
offset_scale.object = c->x[19];
|
||||
offset_scale.scale[0] = guest_float(at - 4);
|
||||
offset_scale.scale[1] = f;
|
||||
plat_mutex_unlock(&sample_lock);
|
||||
} else if (s->role == ROLE_WATCH) { // the value stays the game's; a load with the mouse in it names its mode
|
||||
if (direct_mode()) {
|
||||
plat_mutex_lock(&sample_lock);
|
||||
if (sample.object == c->x[(s->insn >> 5) & 31] && sample.camera_enabled &&
|
||||
(sample.angle[0] || sample.angle[1]))
|
||||
sample_watched = sample.generation, sample_watched_mode = s->mode;
|
||||
plat_mutex_unlock(&sample_lock);
|
||||
}
|
||||
} else if (direct_mode()) {
|
||||
f = s->role == ROLE_STICK ? load_stick(s, c, f) : s->role == ROLE_SHARE ? load_share_cut(s, c, f)
|
||||
: load_base(s, c, f);
|
||||
}
|
||||
uint32_t bits;
|
||||
memcpy(&bits, &f, sizeof bits);
|
||||
if (load_to_general(s->insn)) c->x[s->insn & 31] = bits; // a W load clears the upper half
|
||||
else c->v[s->insn & 31] = bits; // a 32-bit load clears the rest of the vector register
|
||||
}
|
||||
|
||||
// The game also uses a 10% activity threshold after processing the stick. A one-count mouse movement must count
|
||||
// as active, even when its displacement is smaller than that threshold. The site is the displaced ldp d9, d8, [sp, #8]
|
||||
// just before the update's last `str w8, [x20, #0x418]`: w8 holds the flags then (bit 0 raw input, bit 4 any input,
|
||||
@@ -509,5 +915,6 @@ __attribute__((constructor)) static void mouse_direct_register(void) {
|
||||
rt_register_host(HOST_MOUSE_ORBIT_BEGIN, orbit_begin);
|
||||
rt_register_host(HOST_MOUSE_ORBIT_ANGLES, orbit_angles);
|
||||
rt_register_host(HOST_MOUSE_HAND, hand_input);
|
||||
rt_register_host(HOST_MOUSE_LOAD, camera_load);
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user