diff --git a/README.md b/README.md index 2fe02b7..e60fb02 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,7 @@ The on/off switches below (`...=1`) are off when unset or set to `0`. | `VICTORY_LOG==debug,...` | debug and trace output | | `VICTORY_STACKS=20,60` | every thread's stack at those seconds | | `VICTORY_WATCH=,...` | logs a title u32 when it changes | +| `VICTORY_POKE=:,...` | writes a title byte twice a second (a hang watchdog's tick, say) | | `VICTORY_KEYS=30:Enter,35:X` | presses keys at those seconds, focus or not | | `VICTORY_CRASH_SAVE=:,...` | saves title memory to the cache folder on a crash | | `VICTORY_CAPTURE=` | saves presented frames (powers of two, or `VICTORY_CAPTURE_FRAMES=`) | diff --git a/apps/victory/src/run.rs b/apps/victory/src/run.rs index 454bdab..3cc3b12 100644 --- a/apps/victory/src/run.rs +++ b/apps/victory/src/run.rs @@ -198,6 +198,7 @@ fn diagnostics(image: &victory_loader::LoadedImage, cfg: &victory_core::Config) victory_loader::dump_stacks_on_schedule(); victory_hle::modules::audio::capture::start(); watch(image.base(), image.info().size_of_image as usize); + poke(image.base(), image.info().size_of_image as usize); // Debugging aid: `VICTORY_CRASH_SAVE=:,...` (hex) writes those // title ranges to `crash-.bin` in the cache dir on a crash. let size = image.info().size_of_image as usize; @@ -245,6 +246,34 @@ fn watch(base: usize, size: usize) { }); } +/// Debugging aid: `VICTORY_POKE=:,...` (hex) writes the byte at +/// each title+rva twice a second. A title that ends itself when its main +/// loop has not ticked for a while (Grand Theft Auto VI: 30 s) runs on +/// through slower frames with its tick flag poked. The address must be +/// writable title data. +#[cfg(all(windows, feature = "diagnostics"))] +fn poke(base: usize, size: usize) { + let Ok(list) = std::env::var("VICTORY_POKE") else { + return; + }; + let hex = |s: &str| usize::from_str_radix(s.trim().trim_start_matches("0x"), 16).ok(); + let pokes: Vec<(usize, u8)> = list + .split(',') + .filter_map(|p| p.split_once(':')) + .filter_map(|(rva, byte)| Some((hex(rva)?, u8::try_from(hex(byte)?).ok()?))) + .filter(|&(rva, _)| rva < size) + .collect(); + std::thread::spawn(move || { + loop { + for &(rva, byte) in &pokes { + // SAFETY: a byte inside the mapped image, checked above. + unsafe { ((base + rva) as *mut u8).write_volatile(byte) }; + } + std::thread::sleep(std::time::Duration::from_millis(500)); + } + }); +} + /// DLLs the host or our runtime provide are never taken from the title. #[cfg(windows)] fn title_dll(host: &victory_hle::HostPolicy, dll: &str) -> bool {