paavohtl Claude Opus 4.6 (1M context) commited on
Commit
289459c
Β·
1 Parent(s): cbe376a

feat: hook ReplayLoader (passthrough) and replace ParseReplayPosition

Browse files

ReplayLoader hooked as passthrough with diagnostic logging.
ParseReplayPosition fully replaced with Rust port.
Headless replay test: PASS (byte-identical output).
Headful: 133 validations pass, 0 fail.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

crates/openwa-wormkit/src/replacements/mod.rs CHANGED
@@ -8,6 +8,7 @@ mod hardware_init;
8
  mod headless;
9
  pub(crate) mod input;
10
  mod render;
 
11
  mod scheme;
12
  mod sound;
13
  mod speech;
@@ -30,5 +31,6 @@ pub fn install_all() -> Result<(), String> {
30
  input::install()?;
31
  ddgame_init::install()?;
32
  game_state_hooks::install()?;
 
33
  Ok(())
34
  }
 
8
  mod headless;
9
  pub(crate) mod input;
10
  mod render;
11
+ mod replay;
12
  mod scheme;
13
  mod sound;
14
  mod speech;
 
31
  input::install()?;
32
  ddgame_init::install()?;
33
  game_state_hooks::install()?;
34
+ replay::install()?;
35
  Ok(())
36
  }
crates/openwa-wormkit/src/replacements/replay.rs ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //! Hooks for ReplayLoader and ParseReplayPosition.
2
+ //!
3
+ //! ReplayLoader (0x462DF0): stdcall(param_1, mode), RET 0x8.
4
+ //! ParseReplayPosition (0x4E3490): stdcall(input), RET 0x4.
5
+
6
+ use crate::hook;
7
+ use crate::log_line;
8
+ use openwa_core::address::va;
9
+ use openwa_core::engine::replay;
10
+
11
+ // ─── Trampoline storage ─────────────────────────────────────────────────────
12
+
13
+ static mut REPLAY_LOADER_ORIG: *const () = core::ptr::null();
14
+ #[allow(dead_code)]
15
+ static mut PARSE_POSITION_ORIG: *const () = core::ptr::null();
16
+
17
+ // ─── ReplayLoader passthrough ────────────────────────────────────────────────
18
+
19
+ /// ReplayLoader: stdcall(param_1: u32, mode: i32) -> u32. RET 0x8.
20
+ unsafe extern "stdcall" fn hook_replay_loader(param_1: u32, mode: i32) -> u32 {
21
+ let _ = log_line(&format!(
22
+ "[Replay] ReplayLoader state=0x{param_1:08X} mode={mode}"
23
+ ));
24
+
25
+ let orig: unsafe extern "stdcall" fn(u32, i32) -> u32 =
26
+ core::mem::transmute(REPLAY_LOADER_ORIG);
27
+ let result = orig(param_1, mode);
28
+
29
+ // Log fields the original populated
30
+ if result == 0 {
31
+ let version = *(param_1 as *const u32).byte_add(0xDB50);
32
+ let replay_active = *(param_1 as *const u8).add(0xDB48);
33
+ let _ = log_line(&format!(
34
+ "[Replay] OK: version={version} active={replay_active}"
35
+ ));
36
+ } else {
37
+ let _ = log_line(&format!(
38
+ "[Replay] ReplayLoader error: {}", result as i32
39
+ ));
40
+ }
41
+
42
+ result
43
+ }
44
+
45
+ // ─── ParseReplayPosition full replacement ────────────────────────────────────
46
+
47
+ /// ParseReplayPosition: stdcall(input: *const u8) -> i32. RET 0x4.
48
+ unsafe extern "stdcall" fn hook_parse_replay_position(input: *const u8) -> i32 {
49
+ // Build a safe slice from the null-terminated C string
50
+ let mut len = 0usize;
51
+ while *input.add(len) != 0 {
52
+ len += 1;
53
+ if len > 256 {
54
+ break;
55
+ }
56
+ }
57
+ let slice = core::slice::from_raw_parts(input, len + 1); // include null
58
+ replay::parse_replay_position(slice)
59
+ }
60
+
61
+ // ─── Hook installation ──────────────────────────────────────────────────────
62
+
63
+ pub fn install() -> Result<(), String> {
64
+ unsafe {
65
+ REPLAY_LOADER_ORIG = hook::install(
66
+ "ReplayLoader",
67
+ va::REPLAY_LOADER,
68
+ hook_replay_loader as *const (),
69
+ )? as *const ();
70
+
71
+ PARSE_POSITION_ORIG = hook::install(
72
+ "ParseReplayPosition",
73
+ va::PARSE_REPLAY_POSITION,
74
+ hook_parse_replay_position as *const (),
75
+ )? as *const ();
76
+ }
77
+ Ok(())
78
+ }