The mouse turns cameras that run no direct mouse hook, such as Autobuild's placement camera, as the right stick (#1300)

With mouse_mode = direct the mouse reached only the cameras the direct hooks cover. Autobuild's placement camera runs
none of them on games 1.4.3 and 1.2.1 and turns by the right stick, so the mouse moved nothing there. mouse_direct.c
now notes each camera step that runs a hook; after two steps without one the mouse acts as the right stick
(input.c mouse_camera), as with mouse_mode = stick, until a hook runs again. A script's MOUSE lines move that stick
too, also under TOTK_INPUT=none, so the path can be tested with scripted input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
itaskaev2andClaude Opus 5.5 committed 2026-11-19 17:54:58 +01:00
1 parent db7d6603a6
commit 300f88e95f
4 files changed
+101 -36

No files matched your search

+11 -2
View File
@@ -154,6 +154,12 @@ degrees a count as the camera does elsewhere. The follow range is read from the
once, the mouse is stick input there). The stick loads that only test for input keep the mouse in the stick. A step with mouse motion that no
direct hook took is logged (`mouse: step N with mouse motion took the stick path`, the first 30, then one in 600, with
the player's state), so the cameras still on stick input show in `logs/totk.log`.
Some cameras run none of the direct hooks and read their turn from input the hooks never see: Autobuild's placement
camera (games 1.4.3 and 1.2.1) turns by the right stick but, in direct mode, not by the mouse (issue #1300). After two
camera steps in a row that ran no direct hook (none of the free orbit, the load sites above or Ultrahand's held-object
input), the mouse acts as the right stick there, as with `mouse_mode = stick`, until a step runs a direct hook again
(`mouse: the camera runs no direct hook; the mouse acts as the right stick` and `... runs a direct hook again` in the
log, the first 6 changes; `camera_unhooked` in `runtime/mouse_direct.c`).
Lock-on keeps pointing the camera at the target; the stick, and so the mouse, adds an offset around that direction,
which the game limits and lets return: the mouse's degrees are the step's turn the game adds to the offset and judges
the return by.
@@ -291,7 +297,7 @@ own (`gyro_bias_pad` ends in "(under Steam)").
```
<frame> <button> [hold_frames] # A B X Y L R ZL ZR PLUS MINUS LEFT UP RIGHT DOWN LCLICK RCLICK; hold defaults to 4
<frame> LSTICK|RSTICK <x> <y> [hold_frames] # -32767..32767, up is +y
<frame> MOUSE <dx> <dy> # direct-mode raw counts, once; down is +dy
<frame> MOUSE <dx> <dy> # raw mouse counts, once; down is +dy
@<ms> <button> [hold_ms] # timed on the world clock
@<ms> LSTICK|RSTICK <x> <y> [hold_ms]
@<ms> MOUSE <dx> <dy>
@@ -307,7 +313,10 @@ own (`gyro_bias_pad` ends in "(under Steam)").
In direct mouse mode the recording also writes one `MOUSE` event per consumed raw displacement. These are one-shot
displacements rather than held stick segments. They replay without cursor capture, including with `input = none`;
the game must be accepting camera input when the event reaches its camera update.
the game must be accepting camera input when the event reaches its camera update. Where the mouse acts as the right
stick (`mouse_mode = stick`, a camera with no direct hook, the game not accepting camera input), a script's `MOUSE`
lines move the right stick as the mouse would, also without cursor capture or with `input = none`, for 100 ms after
each line (`mouse_camera` in `runtime/input.c`); spread a turn over lines a frame apart, as a real mouse moves.
`TOTK_TEST_PAD=<lx>,<ly>,<rx>,<ry>` attaches an SDL virtual gamepad at start whose sticks rest at these raw SDL axis values (-32768 to 32767, down is +y), so a drifting or held stick can be tested without a controller: the values go through the gamepad mapping and `TOTK_STICK_DEADZONE` like a real pad's, and `TOTK_INPUT_RECORD` shows what reached the game.
+22 -1
View File
@@ -364,6 +364,14 @@ static void walk_get(void) {
static int mouse_selector;
int input_direct_mouse_selector_active(void) { return __atomic_load_n(&mouse_selector, __ATOMIC_RELAXED) != 0; }
// A script's MOUSE line within the last 100 ms (under `lock`): mouse_camera then makes a stick of it
static uint64_t script_mouse_at;
static int input_script_mouse_recent(void) {
uint64_t now = plat_now_ns();
if (script_mouse[0] || script_mouse[1]) script_mouse_at = now;
return script_mouse_at && now - script_mouse_at < 100000000ull;
}
// Selector 1 is a radial wheel, 2..4 are distinct horizontal quick lists; only a wheel retains a virtual cursor.
// Under `lock`.
static void mouse_camera(int32_t out[2], int selector) {
@@ -396,7 +404,10 @@ static void mouse_camera(int32_t out[2], int selector) {
frame = ~0ull;
return; // the camera update takes the raw counts itself, once, outside the HID stick path
}
if (!ikb_captured()) {
// A script's MOUSE lines move the stick as the mouse does, captured or not (in direct mode the camera hook takes
// them, input_direct_mouse_sample): for 100 ms after one the stick is the mouse's, as while captured
int scripted = input_script_mouse_recent();
if (!ikb_captured() && !scripted) {
ikb_mouse_take(&dx, &dy);
held[0] = held[1] = 0;
frame = ~0ull;
@@ -406,6 +417,9 @@ static void mouse_camera(int32_t out[2], int selector) {
if (fr != frame) {
double dt = age < 0.004 ? 0.004 : age > 0.1 ? 0.1 : age;
ikb_mouse_take(&dx, &dy);
if (!ikb_captured()) dx = dy = 0;
dx += script_mouse[0], dy += script_mouse[1];
script_mouse[0] = script_mouse[1] = 0;
input_mouse_stick(dx, dy, dt, mouse_sens_get(), held);
frame = fr;
t0 = now;
@@ -901,6 +915,13 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
if (pad_used) __atomic_store_n(&g_kbm_last, 0, __ATOMIC_RELAXED);
else if (kbm_used) __atomic_store_n(&g_kbm_last, 1, __ATOMIC_RELAXED);
}
// Without the keyboard and mouse poll above (TOTK_INPUT=none in scripted runs, or the window in the background), a
// script's MOUSE lines still move the right stick wherever the mouse would (mouse_camera)
if (!(state > 0 && ikb_foreground()) && input_script_mouse_recent() && !input_direct_mouse_active()) {
int32_t k[2];
mouse_camera(k, 0);
pick(&sr[0], &sr[1], k[0], k[1]);
}
script_apply(&b, sl, sr);
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]);
+28 -2
View File
@@ -7,6 +7,7 @@
// 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).
// A camera that runs none of these hooks gets the mouse as the right stick instead, through input.c (camera_unhooked).
// 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,
@@ -64,10 +65,20 @@ static int hand_active(uint64_t now) {
return last && now - last < 150000000ull;
}
// Cameras no direct hook reaches. The hooks below (the free orbit's orbit_begin, every camera_load site, Ultrahand's
// hand_input) mark each camera step they run in (step_hooked). A camera that runs none of them, such as Autobuild's
// placement camera on games 1.4.3 and 1.2.1, reads its turn from input the hooks never see. After UNHOOKED_STEPS such
// steps in a row the mouse leaves the direct path and acts as the right stick (input.c mouse_camera), as with
// mouse_mode = stick, until a step runs a hook again.
#define UNHOOKED_STEPS 2
static volatile int32_t step_hooked, unhooked_steps;
static void step_mark_hooked(void) { __atomic_store_n(&step_hooked, 1, __ATOMIC_RELAXED); }
static int camera_unhooked(void) { return __atomic_load_n(&unhooked_steps, __ATOMIC_RELAXED) >= UNHOOKED_STEPS; }
int input_direct_mouse_active(void) {
uint64_t last = __atomic_load_n(&last_update, __ATOMIC_ACQUIRE);
return direct_mode() && (__atomic_load_n(&accepts_mouse, __ATOMIC_RELAXED) || hand_active(plat_now_ns())) && last &&
plat_now_ns() - last < 150000000ull;
plat_now_ns() - last < 150000000ull && !camera_unhooked();
}
int input_direct_mouse_enabled(void) { return direct_mode(); }
@@ -373,7 +384,19 @@ static void camera_input(Cpu *c) {
memcpy(&next.pad[1], &c->v[10], sizeof(float));
if (flags & 2) next.pad[0] = -next.pad[0];
if (flags & 4) next.pad[1] = -next.pad[1];
if (direct_mode()) {
// The step before this one ran no direct hook: count it (camera_unhooked)
int hooked = __atomic_exchange_n(&step_hooked, 0, __ATOMIC_RELAXED);
int unhooked = hooked ? 0 : __atomic_load_n(&unhooked_steps, __ATOMIC_RELAXED) + (camera_unhooked() ? 0 : 1);
if (direct_mode() && (unhooked >= UNHOOKED_STEPS) != camera_unhooked()) {
static int lines;
if (lines < 6) {
lines++;
rt_log(unhooked >= UNHOOKED_STEPS ? "mouse: the camera runs no direct hook; the mouse acts as the right stick"
: "mouse: the camera runs a direct hook again; the mouse turns it directly");
}
}
__atomic_store_n(&unhooked_steps, unhooked, __ATOMIC_RELAXED);
if (direct_mode() && !camera_unhooked()) {
int32_t dx, dy;
input_direct_mouse_sample(!input_direct_mouse_selector_active() && (accept || hand_active(plat_now_ns())), &dx, &dy);
float sensitivity = (float)cfg_double("TOTK_MOUSE_SENS");
@@ -463,6 +486,7 @@ static void orbit_begin(Cpu *c) {
__atomic_store_n(&cam_kind_at, plat_now_ns(), __ATOMIC_RELEASE);
orbit.object = 0;
uint64_t object = c->x[0];
step_mark_hooked();
if (direct_mode()) {
MouseSample m = sample_read();
uint64_t input = guest_pointer(object + 0x20);
@@ -587,6 +611,7 @@ static void orbit_angles(Cpu *c) {
static void hand_input(Cpu *c) {
const MouseLayout *ml = mouse_layout();
__atomic_store_n(&hand_update, plat_now_ns(), __ATOMIC_RELEASE);
step_mark_hooked();
static _Thread_local uint64_t object, generation;
if (direct_mode()) {
MouseSample m = sample_read();
@@ -1039,6 +1064,7 @@ static void camera_load(Cpu *c) {
rt_log("mouse: load hook called from main+%#llx, no such site", (unsigned long long)offset);
abort();
}
step_mark_hooked();
int mapped = INPUT_CAM_UNCLASSIFIED;
switch (s->mode) {
case MODE_AIM:
+40 -31
View File
@@ -50,6 +50,8 @@ static uint64_t buttons;
uint64_t input_buttons_last(void) { return buttons; }
int mem_guest_readable(uint64_t a, uint64_t n) { (void)a; (void)n; return 0; } // no player: on-foot gains
static float scalar(__uint128_t v) { float f; memcpy(&f,&v,4); return f; }
// A camera input step of a camera that ran a direct hook in the step before (camera_unhooked)
#define HOOK(c) (step_mark_hooked(), hook(c))
#if TEST_GAME_VERSION == 143
int main(void) {
assert(hook && activity_hook);
@@ -59,7 +61,7 @@ int main(void) {
c.x[20]=(uintptr_t)target; c.x[21]=0; c.v[9]=c.v[10]=0;
expected=c;
raw_x=100; raw_y=-50;
hook(&c);
HOOK(&c);
// x is STICK_PER_COUNT a count over the frame ratio; y PITCH_GAIN times that, for the cameras' linear pitch
assert(fabsf(scalar(c.v[9])-100*STICK_PER_COUNT/ratio)<1e-5f);
assert(fabsf(scalar(c.v[10])-PITCH_GAIN*50*STICK_PER_COUNT/ratio)<1e-5f);
@@ -67,12 +69,12 @@ int main(void) {
expected.v[9]=c.v[9]; expected.v[10]=c.v[10]; assert(!memcmp(&expected,&c,sizeof c));
assert(input_direct_mouse_active());
// The next read sees no repeated movement. Gamepad/keyboard input is preserved.
expected=c; hook(&c); assert(!memcmp(&expected,&c,sizeof c));
expected=c; HOOK(&c); assert(!memcmp(&expected,&c,sizeof c));
// Equal mouse distance turns the camera equally at 30, 60 and 144 Hz, yaw by x and pitch linearly by y, and as
// many degrees a count on both axes; there is no unit-circle clamp.
float rates[]={30,60,144};
for(int i=0;i<3;i++) {
ratio=30/rates[i]; raw_x=10000; raw_y=10000; c.v[9]=c.v[10]=0; hook(&c);
ratio=30/rates[i]; raw_x=10000; raw_y=10000; c.v[9]=c.v[10]=0; HOOK(&c);
float y=scalar(c.v[10]);
assert(fabsf(scalar(c.v[9])*ratio-10000*STICK_PER_COUNT)<0.001f);
assert(fabsf(y*ratio/PITCH_GAIN+10000*STICK_PER_COUNT)<0.001f);
@@ -85,7 +87,7 @@ int main(void) {
assert(fabsf(x-4)<1e-5f && fabsf(y-PITCH_GAIN*2)<1e-5f);
}
// One count is not discarded by a dead zone.
ratio=0.5f; raw_x=1; raw_y=0; c.v[9]=c.v[10]=0; hook(&c); assert(scalar(c.v[9])>0);
ratio=0.5f; raw_x=1; raw_y=0; c.v[9]=c.v[10]=0; HOOK(&c); assert(scalar(c.v[9])>0);
uint64_t stack[4]={0,0x123456789abcdef0ull,0x456789abcdef0123ull,0}; c.sp=(uintptr_t)stack;
// The flags are in w8 at the site: the game's next instruction stores w8 to +0x418, so memory is not touched.
uint32_t inactive=0x28, mem=0x77; memcpy(target+0x418,&mem,4);
@@ -96,14 +98,21 @@ int main(void) {
// A controller-only update keeps the game's activity bits.
c.x[8]=inactive; activity_hook(&c); assert((uint32_t)c.x[8]==inactive);
// Disabled game camera input leaves raw counts for the menu's legacy mouse-to-stick path.
c.x[21]=1; raw_x=42; int before=takes; hook(&c);
c.x[21]=1; raw_x=42; int before=takes; HOOK(&c);
assert(takes==before && raw_x==42 && !input_direct_mouse_active()); c.x[21]=0;
// A camera that runs no direct hook (Autobuild's placement camera): after UNHOOKED_STEPS steps without one the
// camera update leaves the raw counts to the stick path, and the next step after a hook takes them again.
raw_x=0; HOOK(&c);
for(int i=0;i<UNHOOKED_STEPS;i++) hook(&c);
raw_x=42; before=takes; hook(&c);
assert(takes==before && raw_x==42 && !input_direct_mouse_active());
HOOK(&c); assert(takes==before+1 && raw_x==0 && input_direct_mouse_active());
// Focus loss and host menus do not move the camera.
captured=0; before=takes; hook(&c); assert(takes==before); captured=1;
foreground=0; hook(&c); assert(takes==before); foreground=1;
allowed=0; hook(&c); assert(takes==before); allowed=1;
mode=0; hook(&c); assert(takes==before && !input_direct_mouse_active()); mode=1;
patched=0; hook(&c); assert(takes==before && !input_direct_mouse_active()); patched=1;
captured=0; before=takes; HOOK(&c); assert(takes==before); captured=1;
foreground=0; HOOK(&c); assert(takes==before); foreground=1;
allowed=0; HOOK(&c); assert(takes==before); allowed=1;
mode=0; HOOK(&c); assert(takes==before && !input_direct_mouse_active()); mode=1;
patched=0; HOOK(&c); assert(takes==before && !input_direct_mouse_active()); patched=1;
now+=150000001; assert(!input_direct_mouse_active());
// Orbit input removes the mouse from the stick path and writes equal degrees per count at the final angles.
unsigned char camera[0x300]={0}, frame[0x100]={0}, hand[0x300]={0};
@@ -112,7 +121,7 @@ int main(void) {
memset(orbit_seen,0,sizeof orbit_seen);
guest_float_store((uintptr_t)camera+0x15c,0);
ratio=30/rates[rate]; c.x[20]=(uintptr_t)target; c.x[21]=0; c.v[9]=c.v[10]=0;
raw_x=100; raw_y=-50; hook(&c);
raw_x=100; raw_y=-50; HOOK(&c);
guest_float_store((uintptr_t)camera+0x108,30); guest_float_store((uintptr_t)camera+0x120,40);
guest_float_store((uintptr_t)frame+0x44,30); guest_float_store((uintptr_t)frame+0x48,40);
c.x[0]=(uintptr_t)camera; begin_hook(&c);
@@ -125,7 +134,7 @@ int main(void) {
assert(fabsf(guest_float((uintptr_t)frame+0x48)-(40-100*DEG_PER_COUNT))<0.0001f); // one sample cannot repeat next update
// The native target remains available for the distance controller.
// Holding pitch happens at the final output, after the native filter.
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; raw_x=raw_y=0; hook(&c);
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; raw_x=raw_y=0; HOOK(&c);
guest_float_store((uintptr_t)camera+0x15c,0);
c.x[0]=(uintptr_t)camera; begin_hook(&c);
float current=guest_float((uintptr_t)camera+0x108), goal=guest_float((uintptr_t)camera+0x15c);
@@ -145,14 +154,14 @@ int main(void) {
guest_float_store((uintptr_t)frame+0x44,0); angles_hook(&c);
assert(fabsf(guest_float((uintptr_t)camera+0x108)-((30-50*DEG_PER_COUNT)-14))<0.0001f);
}
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; raw_y=1; hook(&c);
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; raw_y=1; HOOK(&c);
c.x[0]=(uintptr_t)camera; begin_hook(&c);
guest_float_store((uintptr_t)frame+0x44,0);
c.x[20]=(uintptr_t)camera; angles_hook(&c);
assert(fabsf(guest_float((uintptr_t)frame+0x44)-((30-50*DEG_PER_COUNT)+DEG_PER_COUNT))<0.0001f);
// An explicit controller recenter still hands pitch back to the game.
uint64_t recenter=0x20; memcpy(target+0x148,&recenter,8);
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; hook(&c);
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; HOOK(&c);
c.x[0]=(uintptr_t)camera; begin_hook(&c);
guest_float_store((uintptr_t)frame+0x44,5);
c.x[20]=(uintptr_t)camera; angles_hook(&c);
@@ -161,14 +170,14 @@ int main(void) {
// When the game lets go (the recenter or an aim ends), the mouse holds the pitch the camera has then: neither its
// target from before nor the game's default target pulls the camera back.
guest_float_store((uintptr_t)camera+0x108,3); // the game left the pitch at 3 + the offset 14
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; hook(&c);
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; HOOK(&c);
c.x[0]=(uintptr_t)camera; begin_hook(&c);
assert(guest_float((uintptr_t)camera+0x15c)==0);
guest_float_store((uintptr_t)frame+0x44,0);
c.x[20]=(uintptr_t)camera; angles_hook(&c);
assert(fabsf(guest_float((uintptr_t)frame+0x44)-17)<0.0001f);
guest_float_store((uintptr_t)camera+0x15c,0); // the game's parameter update writes its default target
c.x[20]=(uintptr_t)target; hook(&c);
c.x[20]=(uintptr_t)target; HOOK(&c);
c.x[0]=(uintptr_t)camera; begin_hook(&c);
assert(guest_float((uintptr_t)camera+0x15c)==0);
// Aim/close-up handoff: the native camera can replace its parameter
@@ -179,7 +188,7 @@ int main(void) {
guest_float_store((uintptr_t)camera+0x15c,native_target);
guest_float_store((uintptr_t)camera+0x164,native_radius);
guest_float_store((uintptr_t)camera+0x130,native_radius-0.5f);
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; hook(&c);
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; HOOK(&c);
c.x[0]=(uintptr_t)camera; begin_hook(&c);
assert(guest_float((uintptr_t)camera+0x15c)==native_target);
guest_float_store((uintptr_t)frame+0x44,0); // native pitch filter
@@ -190,7 +199,7 @@ int main(void) {
assert(guest_float((uintptr_t)camera+0x130)==native_radius-0.5f);
}
float pad_pitch=0.5f; c.x[20]=(uintptr_t)target;
memcpy(&c.v[10],&pad_pitch,4); hook(&c);
memcpy(&c.v[10],&pad_pitch,4); HOOK(&c);
c.x[0]=(uintptr_t)camera; begin_hook(&c);
assert(guest_float((uintptr_t)camera+0x15c)==24);
c.v[10]=0;
@@ -203,7 +212,7 @@ int main(void) {
{
assert(state_hook);
c.x[20]=(uintptr_t)target; c.x[21]=0; c.v[9]=c.v[10]=0;
raw_x=1; raw_y=0; hook(&c);
raw_x=1; raw_y=0; HOOK(&c);
c.x[0]=(uintptr_t)camera; begin_hook(&c);
c.x[20]=(uintptr_t)camera; angles_hook(&c);
uint32_t manual=4, override=0;
@@ -227,9 +236,9 @@ int main(void) {
override=0; memcpy(camera+0x188,&override,4);
// Any real controller input retains the native manual-distance behaviour.
c.x[20]=(uintptr_t)target; float pad=0.25f;
memcpy(&c.v[9],&pad,4); c.v[10]=0; hook(&c);
memcpy(&c.v[9],&pad,4); c.v[10]=0; HOOK(&c);
c.x[20]=(uintptr_t)camera; c.x[10]=4; state_hook(&c); assert(c.x[10]==4);
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; hook(&c);
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; HOOK(&c);
c.x[20]=(uintptr_t)camera; c.x[10]=4; now+=150000000ull;
state_hook(&c); assert(c.x[10]==4); now++;
}
@@ -237,7 +246,7 @@ int main(void) {
memset(orbit_seen,0,sizeof orbit_seen);
c.x[20]=(uintptr_t)target; c.x[21]=0; raw_x=raw_y=0; c.v[9]=c.v[10]=0;
{ float px=0.25f, py=-0.5f; memcpy(&c.v[9],&px,4); memcpy(&c.v[10],&py,4); }
hook(&c);
HOOK(&c);
guest_float_store((uintptr_t)target+0x420,0.25f); guest_float_store((uintptr_t)target+0x424,0.75f);
guest_float_store((uintptr_t)frame+0x44,11); guest_float_store((uintptr_t)frame+0x48,22);
guest_float_store((uintptr_t)camera+0x15c,3);
@@ -248,7 +257,7 @@ int main(void) {
assert(guest_float((uintptr_t)camera+0x15c)==3);
guest_float_store((uintptr_t)camera+0x108,30); guest_float_store((uintptr_t)camera+0x120,40);
for(int count=0;count<100;count++) {
c.x[20]=(uintptr_t)target; c.x[21]=0; c.v[9]=c.v[10]=0; raw_x=1; raw_y=0; hook(&c);
c.x[20]=(uintptr_t)target; c.x[21]=0; c.v[9]=c.v[10]=0; raw_x=1; raw_y=0; HOOK(&c);
c.x[0]=(uintptr_t)camera; begin_hook(&c); c.x[20]=(uintptr_t)camera;
guest_float_store((uintptr_t)frame+0x44,guest_float((uintptr_t)camera+0x108));
guest_float_store((uintptr_t)frame+0x48,guest_float((uintptr_t)camera+0x120));
@@ -257,13 +266,13 @@ int main(void) {
assert(fabsf(guest_float((uintptr_t)camera+0x120)-(40-100*DEG_PER_COUNT))<0.001f);
// A held object receives mouse deltas after its own curves at HAND_PER_COUNT a count, at most HAND_MAX full
// tilts a step, once per sample, including with camera input off.
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; raw_x=200; raw_y=50; ratio=0.5f; hook(&c);
c.x[20]=(uintptr_t)target; c.v[9]=c.v[10]=0; raw_x=200; raw_y=50; ratio=0.5f; HOOK(&c);
c.x[19]=(uintptr_t)hand; c.x[8]=0x12345678; c.v[15]=0;
guest_float_store((uintptr_t)frame+0x60,0); hand_hook(&c);
assert(200*HAND_PER_COUNT/ratio>HAND_MAX && fabsf(guest_float((uintptr_t)frame+0x60)-HAND_MAX)<0.00001f);
assert(fabsf(scalar(c.v[15])+50*HAND_PER_COUNT/ratio)<0.00001f);
hand_hook(&c); assert(fabsf(scalar(c.v[15])+50*HAND_PER_COUNT/ratio)<0.00001f);
c.x[21]=1; raw_x=5; raw_y=6; hook(&c); assert(raw_x==0 && raw_y==0 && input_direct_mouse_active());
c.x[21]=1; raw_x=5; raw_y=6; HOOK(&c); assert(raw_x==0 && raw_y==0 && input_direct_mouse_active());
// A radial selector retains its virtual cursor between mouse packets, including repeated HID polls.
float cursor[2]={0}; int32_t selector[2], held_selector[2];
input_direct_mouse_radial(100,50,1,cursor,selector);
@@ -291,7 +300,7 @@ int main(void) {
input_direct_mouse_row(1000,1,140000000,&row,selector); assert(selector[0]==32767);
input_direct_mouse_row(-1000,1,141000000,&row,selector); assert(!selector[0]);
input_direct_mouse_row(-1,1,180000000,&row,selector); assert(selector[0]==-32767);
selecting=1; c.x[20]=(uintptr_t)target; raw_x=42; raw_y=0; before=takes; hook(&c);
selecting=1; c.x[20]=(uintptr_t)target; raw_x=42; raw_y=0; before=takes; HOOK(&c);
assert(takes==before && raw_x==42); selecting=0; raw_x=0;
puts("direct mouse: register contract, routing, linearity, frame ratio and capture checks passed");
puts("direct mouse: final orbit angles, single-count motion, equal axes and held-object routing passed");
@@ -335,7 +344,7 @@ int main(void) {
float pad_x=0.25f, pad_y=-0.5f;
#define LOAD(site,reg) (c.x[30]=MOD_MAIN_BASE+(site)+4, load_hook(&c), scalar(c.v[reg]))
#define SAMPLE(dx,dy) do { c.x[20]=(uintptr_t)input; c.x[21]=0; c.v[9]=0; c.v[10]=0; \
memcpy(&c.v[9],&pad_x,4); memcpy(&c.v[10],&pad_y,4); raw_x=(dx); raw_y=(dy); hook(&c); \
memcpy(&c.v[9],&pad_x,4); memcpy(&c.v[10],&pad_y,4); raw_x=(dx); raw_y=(dy); HOOK(&c); \
guest_float_store((uintptr_t)input+0x424,scalar(c.v[10])); } while(0)
ratio=0.5f;
SAMPLE(100,-50);
@@ -507,7 +516,7 @@ int main(void) {
memset(&c,0x5a,sizeof c);
// The camera input update keeps x in s11 (y in s10) and stores s11 at +0x420; s9 is not the update's
c.x[20]=(uintptr_t)target; c.x[21]=0; c.v[11]=c.v[10]=0; expected=c;
raw_x=100; raw_y=-50; ratio=0.5f; hook(&c);
raw_x=100; raw_y=-50; ratio=0.5f; HOOK(&c);
assert(fabsf(scalar(c.v[11])-100*STICK_PER_COUNT/ratio)<1e-5f);
assert(fabsf(scalar(c.v[10])-PITCH_GAIN*50*STICK_PER_COUNT/ratio)<1e-5f);
float stored; memcpy(&stored,target+0x420,4); assert(stored==scalar(c.v[11]));
@@ -517,7 +526,7 @@ int main(void) {
c.x[8]=0x28; activity_hook(&c); assert((uint32_t)c.x[8]==0x11 && c.v[9]==stack[2] && c.v[8]==stack[3]);
// The free orbit: the final pitch and yaw at [sp+0x3c] / [sp+0x40], the displaced ldr s13, [sp, #0x3c]
uint64_t input_address=(uintptr_t)target; memcpy(camera+0x20,&input_address,8);
c.x[20]=(uintptr_t)target; c.v[11]=c.v[10]=0; raw_x=100; raw_y=-50; hook(&c);
c.x[20]=(uintptr_t)target; c.v[11]=c.v[10]=0; raw_x=100; raw_y=-50; HOOK(&c);
guest_float_store((uintptr_t)camera+0x108,30); guest_float_store((uintptr_t)camera+0x120,40);
guest_float_store((uintptr_t)frame+0x3c,30); guest_float_store((uintptr_t)frame+0x40,40);
c.x[0]=(uintptr_t)camera; begin_hook(&c);
@@ -527,7 +536,7 @@ int main(void) {
assert(fabsf(guest_float((uintptr_t)frame+0x40)-(40-100*DEG_PER_COUNT))<0.0001f);
assert(scalar(c.v[13])==guest_float((uintptr_t)frame+0x3c));
// Ultrahand: x in s9, y in s15, the displaced str w9, [sp, #0x18]
c.x[20]=(uintptr_t)target; c.v[11]=c.v[10]=0; raw_x=20; raw_y=10; hook(&c);
c.x[20]=(uintptr_t)target; c.v[11]=c.v[10]=0; raw_x=20; raw_y=10; HOOK(&c);
c.x[19]=(uintptr_t)hand; c.x[9]=0x12345678; c.v[9]=0; c.v[15]=0; hand_hook(&c);
assert(fabsf(scalar(c.v[9])-20*HAND_PER_COUNT/ratio)<1e-5f && fabsf(scalar(c.v[15])+10*HAND_PER_COUNT/ratio)<1e-5f);
uint32_t w9; memcpy(&w9,(unsigned char *)frame+0x18,4); assert(w9==0x12345678);
@@ -537,7 +546,7 @@ int main(void) {
float pad_x=0.25f, pad_y=-0.5f;
#define LOAD(site,reg) (c.x[30]=MOD_MAIN_BASE+(site)+4, load_hook(&c), scalar(c.v[reg]))
#define SAMPLE(dx,dy) do { c.x[20]=(uintptr_t)input; c.x[21]=0; c.v[11]=0; c.v[10]=0; \
memcpy(&c.v[11],&pad_x,4); memcpy(&c.v[10],&pad_y,4); raw_x=(dx); raw_y=(dy); hook(&c); \
memcpy(&c.v[11],&pad_x,4); memcpy(&c.v[10],&pad_y,4); raw_x=(dx); raw_y=(dy); HOOK(&c); \
guest_float_store((uintptr_t)input+0x424,scalar(c.v[10])); } while(0)
c.x[19]=(uintptr_t)cam; c.sp=(uintptr_t)lsp; c.x[29]=(uintptr_t)(fp+0x10);
// Aiming: the pitch target the helper computed (+0x15c + turn) is stored with the degrees, and s0 holds it