mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 12:25:56 +00:00
Keep the gamepad unchanged under the direct mouse and the menu pointer, and fix the mouse activity flags
The camera input's activity hook wrote the flags to +0x418, but the game's next instruction stores w8 over them (1.4.3 main+0x874d80), so a mouse-only turn still read as idle. The hook now changes w8. The free-orbit hooks rewrote the camera stick input from the last sample even in steps without mouse motion; they now take a step only when the mouse moved in it or holds the pitch, so a gamepad-only step reaches the camera as the game made it. The mouse shake gesture for detaching parts is gone: three 24-count reversals fire while a held object is turned back and forth. Arrow keys or the pad's right stick shake as before. The menu pointer comes only while the keyboard and mouse are the device used last (input_kbm_last): a gamepad player sees the menus as on the console. Raw mouse travel is counted while the cursor is released too, so moving the mouse brings the pointer back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8ff29be86f
commit
ff49f6b62f
9 files changed
+77
-95
No files matched your search
+5
-3
@@ -108,8 +108,10 @@ with at least 32 ms of neutral between them. At sensitivity 1, 32 horizontal cou
|
||||
cannot queue continued scrolling after the mouse stops. Vertical movement is ignored in these lists. Switching or
|
||||
releasing a selector resets its cursor/step state without sending the last movement to the camera. Selector input is
|
||||
not consumed by the direct camera or Ultrahand hooks.
|
||||
With a held object, three substantial reversals on one mouse axis, with at most 400 ms between strokes, begin a
|
||||
short stick-shake gesture for the game's own detach detector. Those gesture pulses are excluded from camera and object movement input.
|
||||
The mouse never stands in for a stick shake: to detach a fused part, shake the arrow keys (the keyboard's right stick)
|
||||
or the gamepad's right stick. A mouse gesture for it would also fire while a held object is turned back and forth.
|
||||
A step of the gamepad alone, with no mouse motion and no pitch the mouse holds, reaches the camera exactly as without
|
||||
the hooks.
|
||||
The mapping below is still used when the camera-input hook is unavailable or the game disables camera input.
|
||||
This hook needs in-game checks of aiming, Ultrahand and menu transitions before it can be considered complete mouse
|
||||
support. Games 1.1.0 and 1.2.1 have no hook and keep stick emulation.
|
||||
@@ -124,7 +126,7 @@ The stick direction bits (`StickLLeft` to `StickRDown`) are derived from the sti
|
||||
|
||||
## Mouse in the game's menus
|
||||
|
||||
On game 1.4.3, while one of the game's menus has its focus box (the frame the d-pad moves: the title, the save list, the inventory and its System tab, Options, shops, dialogue choices), the cursor is released from the mouse camera and shown in the middle of the window. The item under the pointer takes the focus as if the d-pad had moved there, with the game's highlight, sound and description; a left click is A on it, a right click is B. The keys and the pad keep working, and the focus moves only when the pointer moves. The ability wheel, the d-pad strips, Autobuild, the Purah Pad's camera and the map stay gameplay: the mouse keeps the camera there. When the menu closes the cursor is captured again.
|
||||
On game 1.4.3, while one of the game's menus has its focus box (the frame the d-pad moves: the title, the save list, the inventory and its System tab, Options, shops, dialogue choices), the cursor is released from the mouse camera and shown in the middle of the window. The item under the pointer takes the focus as if the d-pad had moved there, with the game's highlight, sound and description; a left click is A on it, a right click is B. The keys and the pad keep working, and the focus moves only when the pointer moves. This happens only while the keyboard and mouse are the device used last: after a gamepad button press or a stick pushed past half way the menus are as on the console, with no pointer, until the mouse moves or a key is pressed (`input_kbm_last` in `runtime/input.c`). The ability wheel, the d-pad strips, Autobuild, the Purah Pad's camera and the map stay gameplay: the mouse keeps the camera there. When the menu closes the cursor is captured again.
|
||||
|
||||
`runtime/menu_cursor.c` reads eui's screens at each pad read and moves the focus with the writes `eui::BoxCursorMgr::moveBoxCursor` makes, so no game code is called. `menu_cursor = 0` (`TOTK_MENU_CURSOR=0`, live) turns it off; `TOTK_MENU_CURSOR_LOG=1` logs every screen it reads (by default the first six), with the layout size, the node count and the hit panes it uses.
|
||||
|
||||
|
||||
+16
-5
@@ -27,6 +27,12 @@ enum { STICK_MAX = 32767, STICK_DIR = 16384, TRIGGER_ON = 16384, RESCAN_MS = 100
|
||||
static PlatMutex lock = PLAT_MUTEX_INIT;
|
||||
static int state; // 0 not started, 1 running, -1 disabled or SDL failed
|
||||
static volatile int32_t g_block, g_menu; // text entry / host menu: 0 off, 1 open, 2 waiting for release
|
||||
// The device the player used last (input_kbm_last): 1 keyboard and mouse, 0 the gamepad. A pad counts once a button is
|
||||
// down or a stick is past half way (a drifting stick never switches), the mouse once it moved MOUSE_USED raw counts
|
||||
// within one poll (a slow deliberate move does; a desk bump does not), the keyboard with any key or mouse button.
|
||||
enum { PAD_USED = 16384, MOUSE_USED = 6 };
|
||||
static volatile int32_t g_kbm_last = 1;
|
||||
int input_kbm_last(void) { return __atomic_load_n(&g_kbm_last, __ATOMIC_RELAXED); }
|
||||
static SDL_Gamepad *pad;
|
||||
static uint64_t next_scan;
|
||||
static int pad_rumble; // the open gamepad has rumble motors
|
||||
@@ -563,6 +569,8 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
|
||||
if (state > 0) {
|
||||
binds_refresh();
|
||||
if (state == 1) pad_read(&b, sl, sr);
|
||||
int pad_used = b || abs(sl[0]) > PAD_USED || abs(sl[1]) > PAD_USED || abs(sr[0]) > PAD_USED ||
|
||||
abs(sr[1]) > PAD_USED, kbm_used = 0;
|
||||
if (ikb_foreground()) {
|
||||
uint8_t down[KEY_COUNT] = {0};
|
||||
// Mouse buttons count only while the cursor is captured, and a button already held when the capture began
|
||||
@@ -572,6 +580,7 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
|
||||
int cap = ikb_captured();
|
||||
for (int k = 1; k < KEY_COUNT; k++) {
|
||||
down[k] = ikb_down(k);
|
||||
kbm_used |= down[k];
|
||||
if (k < KEY_MOUSE_L || k > KEY_MOUSE_X2) continue;
|
||||
if (cap && !was_captured) mouse_ignore[k] = down[k];
|
||||
if (!down[k]) mouse_ignore[k] = 0;
|
||||
@@ -592,14 +601,16 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
|
||||
b & (1ull << B_LEFT) ? 3 : b & (1ull << B_RIGHT) ? 4 : 0;
|
||||
mouse_camera(k, selector);
|
||||
pick(&sr[0], &sr[1], k[0], k[1]);
|
||||
static uint32_t travel_seen;
|
||||
uint32_t travel = ikb_mouse_travel();
|
||||
if (travel - travel_seen >= MOUSE_USED) kbm_used = 1;
|
||||
travel_seen = travel;
|
||||
}
|
||||
// A press or a full-way stick on the pad wins over keys held in the same poll: the player picked it up
|
||||
if (pad_used) __atomic_store_n(&g_kbm_last, 0, __ATOMIC_RELAXED);
|
||||
else if (kbm_used) __atomic_store_n(&g_kbm_last, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
script_apply(&b, sl, sr);
|
||||
int32_t shake[2];
|
||||
int wheel = (b & ((1ull << B_L) | (1ull << B_UP) | (1ull << B_LEFT) | (1ull << B_RIGHT))) != 0;
|
||||
if (input_direct_mouse_shake(!wheel && !sr[0] && !sr[1] && !g_menu && !g_block, shake)) {
|
||||
sr[0] = shake[0]; sr[1] = shake[1];
|
||||
}
|
||||
rec_apply(b, sl, sr);
|
||||
// Minus and Plus held together (gamepad or keys) open or close the menu and never reach the game
|
||||
static int combo_held;
|
||||
|
||||
+3
-2
@@ -6,6 +6,9 @@
|
||||
// Down=15) and the stick directions (StickLLeft..Down 16-19, StickRLeft..Down 20-23, derived from the sticks).
|
||||
// Sticks are -32767..32767, up is +y. TOTK_INPUT=none reports no input. Callable from any thread.
|
||||
void input_poll(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx, int32_t *ry);
|
||||
// 1 when keyboard and mouse are the device the player used last, 0 when the gamepad is: what is shown for pointing
|
||||
// (menu_cursor.c shows the pointer in the game's menus only for the keyboard and mouse)
|
||||
int input_kbm_last(void);
|
||||
// Direct mouse input is consumed by the game's camera-input update, after its stick response. While that update
|
||||
// accepts camera input, the HID right stick contains only the controller and keyboard. Selectors route mouse input
|
||||
// separately: a persistent radial cursor for the ability wheel, discrete steps for horizontal quick lists.
|
||||
@@ -17,8 +20,6 @@ void input_direct_mouse_radial(int32_t dx, int32_t dy, float sensitivity, float
|
||||
typedef struct { float distance; uint64_t pulse_until, neutral_until; int direction; } InputMouseRow;
|
||||
void input_direct_mouse_row(int32_t dx, float sensitivity, uint64_t now, InputMouseRow *row, int32_t out[2]);
|
||||
int input_direct_mouse_selector_active(void);
|
||||
// A deliberate mouse shake while manipulating an object feeds a short gesture to the game's native shake detector.
|
||||
int input_direct_mouse_shake(int allow, int32_t out[2]);
|
||||
// Consume direct mouse counts, including one-shot MOUSE events from an input script. enabled=0 discards scripted
|
||||
// counts while leaving the real mouse for menu input. Live counts require cursor capture and foreground focus.
|
||||
void input_direct_mouse_sample(int enabled, int32_t *dx, int32_t *dy);
|
||||
|
||||
@@ -219,6 +219,7 @@ int ikb_escape(void) { return esc_held != 0; }
|
||||
int ikb_captured(void) { return captured != 0; }
|
||||
int ikb_pointer(float *nx, float *ny) { (void)nx, (void)ny; return 0; } // (menu_cursor.c: Windows only for now)
|
||||
void ikb_pointer_set(float nx, float ny) { (void)nx, (void)ny; }
|
||||
uint32_t ikb_mouse_travel(void) { return 0; } // (the last-device switch: keys and buttons only for now)
|
||||
|
||||
void ikb_mouse_take(int32_t *dx, int32_t *dy) {
|
||||
*dx = plat_xchg32(&mouse_dx, 0);
|
||||
|
||||
+10
-3
@@ -83,6 +83,7 @@ uint32_t input_key_char(int key) {
|
||||
|
||||
// ---- mouse camera: raw motion accumulated by the window thread, one stick sample per presented frame
|
||||
static volatile LONG mouse_dx, mouse_dy; // raw counts since the last frame sample
|
||||
static volatile LONG mouse_travel; // raw counts moved in total, captured or not (ikb_mouse_travel)
|
||||
static volatile LONG cur_captured; // cursor hidden and confined to the client area
|
||||
static volatile LONG cur_active; // WM_ACTIVATEAPP: the window's application is active
|
||||
// Bits: CUR_REL, Esc or activation by a click on the title bar or border: until a client click; CUR_ESC, set with CUR_REL
|
||||
@@ -137,10 +138,14 @@ int input_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res) {
|
||||
case WM_INPUT: {
|
||||
RAWINPUT ri;
|
||||
UINT sz = sizeof ri;
|
||||
if (cur_captured && GetRawInputData((HRAWINPUT)l, RID_INPUT, &ri, &sz, sizeof(RAWINPUTHEADER)) != (UINT)-1 &&
|
||||
if (GetRawInputData((HRAWINPUT)l, RID_INPUT, &ri, &sz, sizeof(RAWINPUTHEADER)) != (UINT)-1 &&
|
||||
ri.header.dwType == RIM_TYPEMOUSE && !(ri.data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE)) {
|
||||
InterlockedAdd(&mouse_dx, ri.data.mouse.lLastX);
|
||||
InterlockedAdd(&mouse_dy, ri.data.mouse.lLastY);
|
||||
LONG x = ri.data.mouse.lLastX, y = ri.data.mouse.lLastY;
|
||||
InterlockedAdd(&mouse_travel, (x < 0 ? -x : x) + (y < 0 ? -y : y));
|
||||
if (cur_captured) {
|
||||
InterlockedAdd(&mouse_dx, x);
|
||||
InterlockedAdd(&mouse_dy, y);
|
||||
}
|
||||
}
|
||||
break; // DefWindowProc must see WM_INPUT for cleanup
|
||||
}
|
||||
@@ -222,6 +227,8 @@ void ikb_pointer_set(float nx, float ny) {
|
||||
if (ClientToScreen(h, &p)) SetCursorPos(p.x, p.y);
|
||||
}
|
||||
|
||||
uint32_t ikb_mouse_travel(void) { return (uint32_t)mouse_travel; }
|
||||
|
||||
void ikb_mouse_take(int32_t *dx, int32_t *dy) {
|
||||
*dx = InterlockedExchange(&mouse_dx, 0);
|
||||
*dy = InterlockedExchange(&mouse_dy, 0);
|
||||
|
||||
@@ -12,6 +12,7 @@ int ikb_pointer(float *nx, float *ny);
|
||||
void ikb_pointer_set(float nx, float ny); // moves the pointer there (the window in front only)
|
||||
int ikb_captured(void); // the cursor is captured for the mouse camera
|
||||
void ikb_mouse_take(int32_t *dx, int32_t *dy); // raw mouse motion since the last call, in counts
|
||||
uint32_t ikb_mouse_travel(void); // raw counts the mouse moved in total (|dx| + |dy|), captured or not
|
||||
void ikb_cursor_update(void); // what input_cursor_allowed says may have changed
|
||||
void ikb_menu_closed(void); // the menu closed: a capture that Esc gave up comes back
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
// The other fields are 1.0.0's; menu_cursor logs what it reads the first time a menu opens (TOTK_MENU_CURSOR_LOG=1:
|
||||
// every screen change), so a field that moved shows as a menu with no nodes or boxes off the layout.
|
||||
//
|
||||
// Only while keyboard and mouse are the device used last (input_kbm_last): a gamepad player sees the menus unchanged.
|
||||
// TOTK_MENU_CURSOR (live, default 1): 0 leaves the menus to the keys and the pad.
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
@@ -292,7 +293,9 @@ void menu_cursor_poll(uint64_t *buttons) {
|
||||
Focus f = focus_now();
|
||||
char nm[48] = "";
|
||||
if (f.screen) layout_name(f.screen, nm, sizeof nm);
|
||||
int menu = f.screen && !gameplay_screen(nm) && ikb_foreground();
|
||||
// With the gamepad as the last device the menus stay as they are on the console: no pointer, the capture kept.
|
||||
// Moving the mouse (or a key) makes keyboard and mouse the last device and the pointer comes.
|
||||
int menu = f.screen && !gameplay_screen(nm) && ikb_foreground() && input_kbm_last();
|
||||
set_pointer(menu);
|
||||
int l = ikb_down(KEY_MOUSE_L), r = ikb_down(KEY_MOUSE_R);
|
||||
int click_l = l && !held_l, click_r = r && !held_r;
|
||||
|
||||
+16
-59
@@ -29,8 +29,6 @@ static int direct_mode(void) {
|
||||
|
||||
static uint64_t last_update;
|
||||
static uint64_t hand_update;
|
||||
static uint64_t shake_started, shake_until;
|
||||
static int shake_injected;
|
||||
static int accepts_mouse;
|
||||
|
||||
static int hand_active(uint64_t now) {
|
||||
@@ -82,18 +80,6 @@ void input_direct_mouse_row(int32_t dx, float sensitivity, uint64_t now, InputMo
|
||||
out[0] = row->direction * 32767;
|
||||
}
|
||||
|
||||
int input_direct_mouse_shake(int allow, int32_t out[2]) {
|
||||
uint64_t now = plat_now_ns(), until = __atomic_load_n(&shake_until, __ATOMIC_ACQUIRE);
|
||||
uint64_t start = __atomic_load_n(&shake_started, __ATOMIC_RELAXED);
|
||||
int ready = allow && direct_mode() && hand_active(now) && ikb_captured() && ikb_foreground() && input_cursor_allowed();
|
||||
if (!ready) __atomic_store_n(&shake_until, 0, __ATOMIC_RELEASE);
|
||||
int active = ready && now >= start && now < until;
|
||||
out[0] = active ? ((now - start) / 40000000ull & 1 ? -32767 : 32767) : 0;
|
||||
out[1] = 0;
|
||||
__atomic_store_n(&shake_injected, active, __ATOMIC_RELAXED);
|
||||
return active;
|
||||
}
|
||||
|
||||
#ifdef RT_PATCH_PAGE
|
||||
#define HOST_MOUSE_DIRECT (RT_PATCH_PAGE + 0xfd0)
|
||||
#define HOST_MOUSE_ACTIVITY (RT_PATCH_PAGE + 0xfc0)
|
||||
@@ -163,34 +149,6 @@ static void orbit_pitch_release(OrbitTrack *track) {
|
||||
track->hold_pitch = track->target_saved = 0;
|
||||
}
|
||||
|
||||
static void mouse_shake_feed(int32_t dx, int32_t dy, uint64_t now) {
|
||||
static struct { int sign, confirmed, reversals; double distance; uint64_t last; } stroke[2];
|
||||
static uint64_t cooldown;
|
||||
if (!hand_active(now)) { memset(stroke, 0, sizeof stroke); return; }
|
||||
if (now < cooldown) return;
|
||||
int32_t delta[2] = {dx, dy};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (!delta[i]) continue;
|
||||
if (stroke[i].last && now - stroke[i].last > 400000000ull) memset(&stroke[i], 0, sizeof stroke[i]);
|
||||
int sign = delta[i] > 0 ? 1 : -1;
|
||||
if (sign != stroke[i].sign) stroke[i].sign = sign, stroke[i].distance = 0;
|
||||
stroke[i].distance += fabs((double)delta[i]);
|
||||
if (stroke[i].distance < 24) continue;
|
||||
if (stroke[i].confirmed && sign != stroke[i].confirmed) stroke[i].reversals++;
|
||||
stroke[i].confirmed = sign;
|
||||
stroke[i].last = now;
|
||||
stroke[i].distance = 0;
|
||||
if (stroke[i].reversals >= 3) {
|
||||
__atomic_store_n(&shake_started, now, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&shake_until, now + 320000000ull, __ATOMIC_RELEASE);
|
||||
cooldown = now + 700000000ull;
|
||||
memset(stroke, 0, sizeof stroke);
|
||||
rt_log("mouse: detach shake gesture sent to the game's stick-shake detector");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A host call at an instruction site, not an AAPCS64 function replacement. Preserve every guest register except
|
||||
// s9/s10, which carry the processed camera input, and perform the displaced store of s9 at [x20 + 0x420].
|
||||
static void camera_input(Cpu *c) {
|
||||
@@ -199,9 +157,6 @@ static void camera_input(Cpu *c) {
|
||||
int accept = !(flags & 1) && !input_direct_mouse_selector_active();
|
||||
__atomic_store_n(&accepts_mouse, accept, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&last_update, plat_now_ns(), __ATOMIC_RELEASE);
|
||||
if (direct_mode() && __atomic_load_n(&shake_injected, __ATOMIC_RELAXED)) {
|
||||
c->v[9] = c->v[10] = 0; // discrete shake pulses are for the game's gesture detector, not the camera
|
||||
}
|
||||
MouseSample next = {.object = c->x[20], .when = plat_now_ns(), .camera_enabled = accept};
|
||||
memcpy(&next.pad[0], &c->v[9], sizeof(float));
|
||||
memcpy(&next.pad[1], &c->v[10], sizeof(float));
|
||||
@@ -221,7 +176,6 @@ static void camera_input(Cpu *c) {
|
||||
if (hz > 0) ratio = (float)(30 / hz);
|
||||
}
|
||||
if (isfinite(ratio) && ratio > 0 && sensitivity > 0 && (dx || dy)) {
|
||||
mouse_shake_feed(dx, dy, plat_now_ns());
|
||||
if (accept) mouse_input_object = c->x[20];
|
||||
float x, y;
|
||||
memcpy(&x, &c->v[9], sizeof x);
|
||||
@@ -263,10 +217,9 @@ static void orbit_begin(Cpu *c) {
|
||||
MouseSample m = sample_read();
|
||||
uint64_t input = guest_pointer(object + 0x20);
|
||||
if (m.object == input && m.camera_enabled) {
|
||||
guest_float_store(input + 0x420, m.pad[0]);
|
||||
guest_float_store(input + 0x424, m.pad[1]);
|
||||
orbit.object = object;
|
||||
orbit.mouse = m;
|
||||
// The hooks take a step when the mouse moved in it, or while the mouse holds the pitch. A step of the
|
||||
// gamepad alone (no mouse motion, no hold: a player who never moved the mouse) keeps the game's input.
|
||||
int moved = m.motion[0] != 0 || m.motion[1] != 0, take;
|
||||
uint64_t held = guest_pointer(input + 0x148);
|
||||
uint8_t override;
|
||||
memcpy(&override, (void *)(uintptr_t)(input + 0x15c), 1);
|
||||
@@ -274,9 +227,15 @@ static void orbit_begin(Cpu *c) {
|
||||
OrbitTrack *track = orbit_track(object);
|
||||
if (track->input != input) track->hold_pitch = track->target_saved = 0;
|
||||
if (m.pad[1] != 0 || (held & 0x20) || (override & 0x40)) orbit_pitch_release(track);
|
||||
track->input = input;
|
||||
take = moved || track->hold_pitch;
|
||||
if (take) track->input = input;
|
||||
if (track->hold_pitch) orbit_pitch_target(object, track->pitch);
|
||||
plat_mutex_unlock(&sample_lock);
|
||||
if (moved) { // the mouse's part of this step's stick goes to the final angles instead
|
||||
guest_float_store(input + 0x420, m.pad[0]);
|
||||
guest_float_store(input + 0x424, m.pad[1]);
|
||||
}
|
||||
if (take) orbit.object = object, orbit.mouse = m;
|
||||
}
|
||||
} else {
|
||||
plat_mutex_lock(&sample_lock);
|
||||
@@ -335,7 +294,6 @@ static void hand_input(Cpu *c) {
|
||||
if (m.generation != generation || object != c->x[19]) {
|
||||
float x = guest_float(c->sp + 0x60), y;
|
||||
memcpy(&y, &c->v[15], sizeof y);
|
||||
if (__atomic_load_n(&shake_injected, __ATOMIC_RELAXED)) x = y = 0;
|
||||
x += m.motion[0];
|
||||
y += m.motion[1];
|
||||
guest_float_store(c->sp + 0x60, x);
|
||||
@@ -355,15 +313,14 @@ static void hand_input(Cpu *c) {
|
||||
}
|
||||
|
||||
// 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. Do this after the game computed the bits,
|
||||
// then execute the displaced ldp d9, d8, [sp, #8]. No flag is changed for controller-only input.
|
||||
// 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,
|
||||
// bits 3 and 5 processed input below the threshold), so they are changed in w8; a write to +0x418 would be overwritten
|
||||
// by that store. No flag is changed for controller-only input.
|
||||
static void camera_activity(Cpu *c) {
|
||||
if (mouse_input_object && mouse_input_object == c->x[20]) {
|
||||
uint32_t flags;
|
||||
void *at = (void *)(uintptr_t)(mouse_input_object + 0x418);
|
||||
memcpy(&flags, at, sizeof flags);
|
||||
flags = (flags | 0x11u) & ~0x28u;
|
||||
memcpy(at, &flags, sizeof flags);
|
||||
uint32_t flags = (uint32_t)c->x[8];
|
||||
c->x[8] = (flags | 0x11u) & ~0x28u;
|
||||
mouse_input_object = 0;
|
||||
}
|
||||
uint64_t d9, d8;
|
||||
|
||||
+21
-22
@@ -69,13 +69,14 @@ int main(void) {
|
||||
// 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);
|
||||
uint64_t stack[4]={0,0x123456789abcdef0ull,0x456789abcdef0123ull,0}; c.sp=(uintptr_t)stack;
|
||||
uint32_t inactive=0x28; memcpy(target+0x418,&inactive,4);
|
||||
activity_hook(&c);
|
||||
uint32_t active; memcpy(&active,target+0x418,4); assert(active==0x11);
|
||||
// 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);
|
||||
c.x[8]=inactive; activity_hook(&c);
|
||||
assert((uint32_t)c.x[8]==0x11);
|
||||
uint32_t after; memcpy(&after,target+0x418,4); assert(after==mem);
|
||||
assert(c.v[9]==stack[1] && c.v[8]==stack[2]);
|
||||
// A controller-only update keeps the game's activity bits.
|
||||
memcpy(target+0x418,&inactive,4); activity_hook(&c);
|
||||
memcpy(&active,target+0x418,4); assert(active==inactive);
|
||||
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);
|
||||
assert(takes==before && raw_x==42 && !input_direct_mouse_active()); c.x[21]=0;
|
||||
@@ -140,6 +141,19 @@ int main(void) {
|
||||
memset(target+0x148,0,8);
|
||||
memset(camera+0x88,0,4); memset(camera+0x10c,0,4); memset(camera+0x11c,0,4);
|
||||
}
|
||||
// A gamepad-only step (no mouse motion, no pitch hold) leaves the camera input and the angles as the game made them.
|
||||
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);
|
||||
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);
|
||||
c.x[0]=(uintptr_t)camera; begin_hook(&c);
|
||||
assert(guest_float((uintptr_t)target+0x420)==0.25f && guest_float((uintptr_t)target+0x424)==0.75f);
|
||||
c.x[20]=(uintptr_t)camera; c.sp=(uintptr_t)frame; angles_hook(&c);
|
||||
assert(guest_float((uintptr_t)frame+0x44)==11 && guest_float((uintptr_t)frame+0x48)==22);
|
||||
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);
|
||||
@@ -186,23 +200,9 @@ int main(void) {
|
||||
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);
|
||||
assert(takes==before && raw_x==42); selecting=0; raw_x=0;
|
||||
// Deliberate large reversals with an active held object start a bounded shake; monotonic motion does not.
|
||||
now+=800000000ull;
|
||||
for(int i=0;i<4;i++) {
|
||||
hand_hook(&c); mouse_shake_feed(i&1?-40:40,0,now); now+=50000000ull;
|
||||
}
|
||||
int32_t pulse[2]; assert(input_direct_mouse_shake(1,pulse) && abs(pulse[0])==32767 && pulse[1]==0);
|
||||
int first=pulse[0]; now+=40000000ull; hand_hook(&c);
|
||||
assert(input_direct_mouse_shake(1,pulse) && pulse[0]==-first);
|
||||
captured=0; assert(!input_direct_mouse_shake(1,pulse)); captured=1;
|
||||
now+=800000000ull;
|
||||
for(int i=0;i<4;i++) { hand_hook(&c); mouse_shake_feed(40,0,now); now+=50000000ull; }
|
||||
assert(!input_direct_mouse_shake(1,pulse));
|
||||
for(int i=0;i<10;i++) { hand_hook(&c); mouse_shake_feed(i&1?-5:5,0,now); now+=10000000ull; }
|
||||
assert(!input_direct_mouse_shake(1,pulse));
|
||||
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");
|
||||
puts("direct mouse: persistent pitch target, radial cursor hold, deliberate shake and noise rejection passed");
|
||||
puts("direct mouse: persistent pitch target, radial cursor hold and gamepad-only steps untouched passed");
|
||||
puts("direct mouse: final-pitch recenter rejection, explicit handoff and bounded quick-list steps passed");
|
||||
}
|
||||
'''
|
||||
@@ -223,7 +223,6 @@ void menu_toggle(void) { abort(); }
|
||||
void menu_perf_cycle(void) { abort(); }
|
||||
const char *input_action_name(int action) { (void)action;abort(); }
|
||||
void input_map_configure(void) { abort(); }
|
||||
int input_direct_mouse_shake(int allow,int32_t out[2]) { (void)allow;(void)out;abort(); }
|
||||
int input_direct_mouse_active(void) { return 1; }
|
||||
int input_direct_mouse_enabled(void) { return 1; }
|
||||
static int row_calls, radial_calls, live_mouse;
|
||||
@@ -302,7 +301,7 @@ def main():
|
||||
source.write_text(INPUT_HARNESS)
|
||||
script = folder / 'input.txt'
|
||||
script.write_text('10 MOUSE 123 -45\n20 MOUSE 1000 0\n@100 MOUSE -100 50\n')
|
||||
subprocess.run([args.cc, '-O2', '-flto', '-ffunction-sections', '-fdata-sections', '-Wl,--gc-sections', *(['-Wl,--exclude-all-symbols'] if os.name == 'nt' else []),
|
||||
subprocess.run([args.cc, '-O2', '-flto', '-ffunction-sections', '-fdata-sections', '-Wl,--gc-sections', *(['-fuse-ld=lld', '-Wl,--exclude-all-symbols'] if os.name == 'nt' else []),
|
||||
'-I', str(ROOT/'runtime'), '-I', str(args.deps), '-I', str(args.deps/'vma'),
|
||||
str(source), *link, '-o', str(exe)], check=True)
|
||||
subprocess.run([str(exe), str(script)], check=True)
|
||||
|
||||
Reference in new issue
Block a user