From 1286ef910ba0c482d3f6f7e71d4cd1a105f584f1 Mon Sep 17 00:00:00 2001 From: 3L1A5-1 <276908492+3L1A5-1@users.noreply.github.com> Date: Fri, 27 Nov 2026 01:13:22 +0100 Subject: [PATCH 1/2] xcl run: scripted XCL_PRESS_* times count from guest entry, not host start The scripted presses (XCL_PRESS_AT / XCL_PRESS_A_AT) compared the schedule with the host's uptime. The startup shader preparation runs before the guest and can take longer than the whole script, so every press was already past when the title first polled its input: a cold preparation consumed the schedule and the title then stayed on its first screen. Record the moment preparation returns (log::mark_guest_entry) and count the schedule from it; before it nothing is pressed. The decision is a pure function (press_held) with a unit test. Co-Authored-By: Claude Sonnet 5.5 --- crates/xcl/src/hle/gameinput.rs | 33 ++++++++++++++++++++++++++++----- crates/xcl/src/host.rs | 1 + crates/xcl/src/log.rs | 12 ++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/crates/xcl/src/hle/gameinput.rs b/crates/xcl/src/hle/gameinput.rs index 58aeb5c106..9fe1ec66f4 100644 --- a/crates/xcl/src/hle/gameinput.rs +++ b/crates/xcl/src/hle/gameinput.rs @@ -12,7 +12,8 @@ //! State changes enter a half-second history and reach the reading callbacks. //! Methods not listed log their slot once and fail. //! -//! `XCL_PRESS_A_AT=s1,s2…`: press A for 200 ms at those seconds after start (tests). +//! `XCL_PRESS_A_AT=s1,s2…`: press A for 200 ms at those seconds after the guest starts, i.e. after +//! the startup shader preparation (tests). #![allow(non_snake_case)] @@ -242,7 +243,8 @@ fn button_named(name: &str) -> Option { /// `XCL_PRESS_AT=s:BUTTON,…` ("14:A,18.5:DOWN,20:A"; buttons A B X Y UP DOWN LEFT RIGHT MENU /// VIEW LB RB) and `XCL_PRESS_A_AT=s,…`: buttons held for 200 ms at those seconds after the -/// host started (the log's times) – a title's menus walked without a person at the controls. +/// guest was entered (the startup shader preparation is not counted; the log's times run from +/// the host's start) – a title's menus walked without a person at the controls. fn parse_presses(script: &str, a_only: &str) -> Vec<(f64, u32)> { let mut v: Vec<(f64, u32)> = a_only.split(',').filter_map(|s| s.trim().parse().ok()).map(|s| (s, A)).collect(); for item in script.split(',').map(str::trim).filter(|s| !s.is_empty()) { @@ -254,15 +256,22 @@ fn parse_presses(script: &str, a_only: &str) -> Vec<(f64, u32)> { v } +/// The scripted buttons held `t` seconds after the guest was entered (`None`: not entered yet, +/// e.g. the startup shader preparation is still running, so nothing is pressed). +fn press_held(at: &[(f64, u32)], t: Option) -> u32 { + let Some(t) = t else { return 0 }; + at.iter().filter(|&&(s, _)| t >= s && t < s + 0.2).fold(0, |b, &(_, g)| b | g) +} + fn scripted() -> u32 { static AT: OnceLock> = OnceLock::new(); let at = AT.get_or_init(|| { let var = |n: &str| std::env::var(n).unwrap_or_default(); parse_presses(&var("XCL_PRESS_AT"), &var("XCL_PRESS_A_AT")) }); - // seconds since the host started, as the log's times (not since the title first polled) - let t = crate::log::uptime(); - at.iter().filter(|&&(s, _)| t >= s && t < s + 0.2).fold(0, |b, &(_, g)| b | g) + // seconds since the guest was entered (not since the host started: shader preparation runs + // before the guest and can take longer than the whole script) + press_held(at, crate::log::guest_uptime()) } #[link(name = "user32")] @@ -1350,6 +1359,20 @@ mod tests { assert!(parse_presses("", "").is_empty()); } + #[test] + fn scripted_presses_count_from_guest_entry() { + let at = parse_presses("", "40,60"); + // preparation (guest not entered): nothing fires, however long it takes + assert_eq!(press_held(&at, None), 0); + // at entry + 40 s the first press is held for 200 ms + assert_eq!(press_held(&at, Some(39.9)), 0); + assert_eq!(press_held(&at, Some(40.0)), A); + assert_eq!(press_held(&at, Some(40.19)), A); + assert_eq!(press_held(&at, Some(40.2)), 0); + assert_eq!(press_held(&at, Some(60.1)), A); + assert_eq!(press_held(&at, Some(61.0)), 0); + } + #[test] fn keyboard_mouse_config_gates_keyboard_and_kbm_but_keeps_scripted() { let mut s = GamepadState { buttons: B, left_x: 0.25, ..Default::default() }; diff --git a/crates/xcl/src/host.rs b/crates/xcl/src/host.rs index a9412c658c..6d3f652f53 100644 --- a/crates/xcl/src/host.rs +++ b/crates/xcl/src/host.rs @@ -41,6 +41,7 @@ pub fn host_main(boot_path: &Path) -> i32 { eprintln!("xcl: {e}"); return 2; } + crate::log::mark_guest_entry(); let _ = std::thread::Builder::new().name("xcl-split-counts".into()).spawn(|| loop { std::thread::sleep(std::time::Duration::from_secs(10)); crate::hle::d3d12x::real::log_dispatch_chain_counts(); diff --git a/crates/xcl/src/log.rs b/crates/xcl/src/log.rs index 7f5d1f180a..0681f16ae1 100644 --- a/crates/xcl/src/log.rs +++ b/crates/xcl/src/log.rs @@ -49,6 +49,18 @@ pub fn uptime() -> f64 { START.get_or_init(Instant::now).elapsed().as_secs_f64() } +static GUEST: OnceLock = OnceLock::new(); + +/// Records the moment the guest is entered (after the startup shader preparation). +pub fn mark_guest_entry() { + GUEST.get_or_init(Instant::now); +} + +/// Seconds since the guest was entered, `None` before that. +pub fn guest_uptime() -> Option { + GUEST.get().map(|t| t.elapsed().as_secs_f64()) +} + pub fn init(path: Option<&Path>, level: Level, echo_stderr: bool) { START.get_or_init(Instant::now); LEVEL.store(level as u8, Ordering::Relaxed); From 2a3182839a42201d9ec4f2229c9f205b696832be Mon Sep 17 00:00:00 2001 From: 3L1A5-1 <276908492+3L1A5-1@users.noreply.github.com> Date: Fri, 27 Nov 2026 02:08:57 +0100 Subject: [PATCH 2/2] xcl run: scripted presses count from the title's entry point The marker moves from host_main (right after shader preparation) to loader::main_thread, immediately before the call to the mapped PE entry point, so runtime init and loading are not counted either (about 0.4 s of the schedule was lost before). Suggested and verified by ettehn in review. Co-Authored-By: Claude Sonnet 5.5 --- crates/xcl/src/hle/gameinput.rs | 17 +++++++++-------- crates/xcl/src/host.rs | 1 - crates/xcl/src/loader.rs | 1 + crates/xcl/src/log.rs | 5 +++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/crates/xcl/src/hle/gameinput.rs b/crates/xcl/src/hle/gameinput.rs index 9fe1ec66f4..5af5bf12d2 100644 --- a/crates/xcl/src/hle/gameinput.rs +++ b/crates/xcl/src/hle/gameinput.rs @@ -12,8 +12,8 @@ //! State changes enter a half-second history and reach the reading callbacks. //! Methods not listed log their slot once and fail. //! -//! `XCL_PRESS_A_AT=s1,s2…`: press A for 200 ms at those seconds after the guest starts, i.e. after -//! the startup shader preparation (tests). +//! `XCL_PRESS_A_AT=s1,s2…`: press A for 200 ms at those seconds after the title's entry point is +//! called (the startup shader preparation and loading are not counted) (tests). #![allow(non_snake_case)] @@ -243,8 +243,9 @@ fn button_named(name: &str) -> Option { /// `XCL_PRESS_AT=s:BUTTON,…` ("14:A,18.5:DOWN,20:A"; buttons A B X Y UP DOWN LEFT RIGHT MENU /// VIEW LB RB) and `XCL_PRESS_A_AT=s,…`: buttons held for 200 ms at those seconds after the -/// guest was entered (the startup shader preparation is not counted; the log's times run from -/// the host's start) – a title's menus walked without a person at the controls. +/// title's entry point was called (the startup shader preparation and loading are not counted; +/// the log's times run from the host's start) – a title's menus walked without a person at the +/// controls. fn parse_presses(script: &str, a_only: &str) -> Vec<(f64, u32)> { let mut v: Vec<(f64, u32)> = a_only.split(',').filter_map(|s| s.trim().parse().ok()).map(|s| (s, A)).collect(); for item in script.split(',').map(str::trim).filter(|s| !s.is_empty()) { @@ -256,8 +257,8 @@ fn parse_presses(script: &str, a_only: &str) -> Vec<(f64, u32)> { v } -/// The scripted buttons held `t` seconds after the guest was entered (`None`: not entered yet, -/// e.g. the startup shader preparation is still running, so nothing is pressed). +/// The scripted buttons held `t` seconds after the title's entry point was called (`None`: not +/// called yet, e.g. the startup shader preparation is still running, so nothing is pressed). fn press_held(at: &[(f64, u32)], t: Option) -> u32 { let Some(t) = t else { return 0 }; at.iter().filter(|&&(s, _)| t >= s && t < s + 0.2).fold(0, |b, &(_, g)| b | g) @@ -269,8 +270,8 @@ fn scripted() -> u32 { let var = |n: &str| std::env::var(n).unwrap_or_default(); parse_presses(&var("XCL_PRESS_AT"), &var("XCL_PRESS_A_AT")) }); - // seconds since the guest was entered (not since the host started: shader preparation runs - // before the guest and can take longer than the whole script) + // seconds since the title's entry point was called (not since the host started: shader + // preparation runs before the guest and can take longer than the whole script) press_held(at, crate::log::guest_uptime()) } diff --git a/crates/xcl/src/host.rs b/crates/xcl/src/host.rs index 6d3f652f53..a9412c658c 100644 --- a/crates/xcl/src/host.rs +++ b/crates/xcl/src/host.rs @@ -41,7 +41,6 @@ pub fn host_main(boot_path: &Path) -> i32 { eprintln!("xcl: {e}"); return 2; } - crate::log::mark_guest_entry(); let _ = std::thread::Builder::new().name("xcl-split-counts".into()).spawn(|| loop { std::thread::sleep(std::time::Duration::from_secs(10)); crate::hle::d3d12x::real::log_dispatch_chain_counts(); diff --git a/crates/xcl/src/loader.rs b/crates/xcl/src/loader.rs index 52c49afe78..4b46859e04 100644 --- a/crates/xcl/src/loader.rs +++ b/crates/xcl/src/loader.rs @@ -328,6 +328,7 @@ struct EntryArgs { unsafe extern "system" fn main_thread(param: *mut c_void) -> u32 { let args = Box::from_raw(param as *mut EntryArgs); let f: ExeEntry = std::mem::transmute(args.entry); + crate::log::mark_guest_entry(); f(peb() as *mut c_void) } diff --git a/crates/xcl/src/log.rs b/crates/xcl/src/log.rs index 0681f16ae1..2aef7afabc 100644 --- a/crates/xcl/src/log.rs +++ b/crates/xcl/src/log.rs @@ -51,12 +51,13 @@ pub fn uptime() -> f64 { static GUEST: OnceLock = OnceLock::new(); -/// Records the moment the guest is entered (after the startup shader preparation). +/// Records the moment the title's entry point is called (after the startup shader preparation +/// and the loading). pub fn mark_guest_entry() { GUEST.get_or_init(Instant::now); } -/// Seconds since the guest was entered, `None` before that. +/// Seconds since the title's entry point was called, `None` before that. pub fn guest_uptime() -> Option { GUEST.get().map(|t| t.elapsed().as_secs_f64()) }