paavohtl Claude Opus 4.6 (1M context) commited on
Commit
628ffd1
Β·
1 Parent(s): a92dbfc

refactor: type GameInfo pointers, merge ctor_impl, fix warnings

Browse files

- Type GAME_INFO static and construct_ddgame_wrapper param as *mut GameInfo
- Merge ctor_impl into construct_ddgame_wrapper (single function now)
- Fix dangerous_implicit_autorefs in config.rs (use let gi = &mut *)
- Remove unused GameInfo import in config.rs and MissileType in validation

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

crates/openwa-wormkit/src/replacements/config.rs CHANGED
@@ -9,7 +9,7 @@
9
  //! - GameInfo__LoadOptions (0x460AC0): game options from registry
10
  //! - Options__GetCrashReportURL (0x5A63F0): crash report URL from registry
11
 
12
- use openwa_core::address::va;
13
  use crate::log_line;
14
  use openwa_core::rebase::rb;
15
 
@@ -137,13 +137,11 @@ unsafe extern "stdcall" fn hook_registry_clean_all(struct_ptr: u32) {
137
  ///
138
  /// Reads game options from the Windows registry and copies various globals
139
  /// into the GameInfo struct at known offsets.
140
- unsafe extern "stdcall" fn hook_load_options(gi_ptr: u32) {
141
  use openwa_core::wa::registry::read_profile_int;
142
- use openwa_core::game_info::GameInfo;
143
-
144
- let gi = &mut *(gi_ptr as *mut GameInfo);
145
 
146
  let _ = log_line("[Config] LoadOptions: loading game options from registry");
 
147
 
148
  // Format speech path: "%s\\user\\speech"
149
  let base_dir = rb(va::G_BASE_DIR) as *const u8;
 
9
  //! - GameInfo__LoadOptions (0x460AC0): game options from registry
10
  //! - Options__GetCrashReportURL (0x5A63F0): crash report URL from registry
11
 
12
+ use openwa_core::{address::va, game_info::GameInfo};
13
  use crate::log_line;
14
  use openwa_core::rebase::rb;
15
 
 
137
  ///
138
  /// Reads game options from the Windows registry and copies various globals
139
  /// into the GameInfo struct at known offsets.
140
+ unsafe extern "stdcall" fn hook_load_options(game_info: *mut GameInfo) {
141
  use openwa_core::wa::registry::read_profile_int;
 
 
 
142
 
143
  let _ = log_line("[Config] LoadOptions: loading game options from registry");
144
+ let gi = &mut *game_info;
145
 
146
  // Format speech path: "%s\\user\\speech"
147
  let base_dir = rb(va::G_BASE_DIR) as *const u8;
crates/openwa-wormkit/src/replacements/game_session.rs CHANGED
@@ -15,6 +15,7 @@
15
  //! - `DDGame__InitGameState` (0x526500): plain stdcall(this), called via transmute.
16
 
17
  use openwa_core::address::va;
 
18
  use openwa_core::rebase::rb;
19
  use openwa_core::ddgame_wrapper::DDGameWrapper;
20
  use openwa_core::dddisplay::DDDisplay;
@@ -25,7 +26,7 @@ use crate::hook;
25
  use crate::log_line;
26
 
27
  /// Implicit EDI = game_info pointer, captured from EDI on entry.
28
- static mut GAME_INFO: u32 = 0;
29
 
30
  /// Implicit ECX = network pointer for `DDGame__Constructor`. Set in `ctor_impl`
31
  /// just before calling `ddgame_constructor_call`.
@@ -51,7 +52,7 @@ static mut DDGAME_CTOR_ADDR: u32 = 0;
51
  // After `pushl %esi`:
52
  // [esp+0] = old_esi, [esp+4] = ret addr, [esp+8] = game_info, [esp+0xC] = this
53
  #[unsafe(naked)]
54
- unsafe extern "stdcall" fn call_init_replay(_game_info: *mut u8, _this: *mut DDGameWrapper) {
55
  core::arch::naked_asm!(
56
  "pushl %esi",
57
  "movl 8(%esp), %eax", // EAX = game_info
@@ -87,7 +88,7 @@ unsafe extern "stdcall" fn ddgame_constructor_call(
87
  _streaming_audio: *mut u8,
88
  _timer_obj: *mut u8,
89
  _net_game: *mut u8,
90
- _game_info: *mut u8,
91
  ) -> *mut u8 {
92
  core::arch::naked_asm!(
93
  "movl {ecx_val}, %ecx", // ECX = input_ctrl (implicit param for DDGame::ctor)
@@ -98,14 +99,13 @@ unsafe extern "stdcall" fn ddgame_constructor_call(
98
  );
99
  }
100
 
101
- // ─── Implementation ───────────────────────────────────────────────────────────
102
-
103
- /// Core Rust implementation of `DDGameWrapper__Constructor`.
104
  ///
105
- /// Called by the naked trampoline via `calll`. The 7 stdcall args are already
106
- /// on the stack in cdecl position (the trampoline popped the original return
107
- /// address into `SAVED_RET`, leaving [this, display, …, network] at [esp+4..]).
108
- unsafe extern "cdecl" fn ctor_impl(
 
109
  this: *mut DDGameWrapper,
110
  display: *mut DDDisplay,
111
  sound: *mut DSSound,
@@ -114,7 +114,9 @@ unsafe extern "cdecl" fn ctor_impl(
114
  streaming_audio: *mut u8,
115
  input_ctrl: *mut u8,
116
  ) -> *mut DDGameWrapper {
117
- let game_info = GAME_INFO as *mut u8;
 
 
118
 
119
  // Initialize DDGameWrapper fields (order matches original decompile).
120
  (*this).ddgame = core::ptr::null_mut();
@@ -152,25 +154,6 @@ unsafe extern "cdecl" fn ctor_impl(
152
  this
153
  }
154
 
155
- /// Called by `impl_init_hardware` to construct the DDGameWrapper in-place.
156
- ///
157
- /// Sets `GAME_INFO` (read by `ctor_impl`) and delegates directly to `ctor_impl`,
158
- /// bypassing the naked entry trampoline which is designed as a hook target, not a
159
- /// callable subroutine.
160
- pub(crate) unsafe fn construct_ddgame_wrapper(
161
- game_info: *mut u8,
162
- this: *mut DDGameWrapper,
163
- display: *mut DDDisplay,
164
- sound: *mut DSSound,
165
- keyboard: *mut u8,
166
- palette: *mut Palette,
167
- streaming_audio: *mut u8,
168
- input_ctrl: *mut u8,
169
- ) -> *mut DDGameWrapper {
170
- GAME_INFO = game_info as u32;
171
- ctor_impl(this, display, sound, keyboard, palette, streaming_audio, input_ctrl)
172
- }
173
-
174
  pub fn install() -> Result<(), String> {
175
  unsafe {
176
  INIT_REPLAY_ADDR = rb(va::DDGAMEWRAPPER_INIT_REPLAY);
 
15
  //! - `DDGame__InitGameState` (0x526500): plain stdcall(this), called via transmute.
16
 
17
  use openwa_core::address::va;
18
+ use openwa_core::game_info::GameInfo;
19
  use openwa_core::rebase::rb;
20
  use openwa_core::ddgame_wrapper::DDGameWrapper;
21
  use openwa_core::dddisplay::DDDisplay;
 
26
  use crate::log_line;
27
 
28
  /// Implicit EDI = game_info pointer, captured from EDI on entry.
29
+ static mut GAME_INFO: *mut GameInfo = core::ptr::null_mut();
30
 
31
  /// Implicit ECX = network pointer for `DDGame__Constructor`. Set in `ctor_impl`
32
  /// just before calling `ddgame_constructor_call`.
 
52
  // After `pushl %esi`:
53
  // [esp+0] = old_esi, [esp+4] = ret addr, [esp+8] = game_info, [esp+0xC] = this
54
  #[unsafe(naked)]
55
+ unsafe extern "stdcall" fn call_init_replay(_game_info: *mut GameInfo, _this: *mut DDGameWrapper) {
56
  core::arch::naked_asm!(
57
  "pushl %esi",
58
  "movl 8(%esp), %eax", // EAX = game_info
 
88
  _streaming_audio: *mut u8,
89
  _timer_obj: *mut u8,
90
  _net_game: *mut u8,
91
+ _game_info: *mut GameInfo,
92
  ) -> *mut u8 {
93
  core::arch::naked_asm!(
94
  "movl {ecx_val}, %ecx", // ECX = input_ctrl (implicit param for DDGame::ctor)
 
99
  );
100
  }
101
 
102
+ /// Called by `impl_init_hardware` to construct the DDGameWrapper in-place.
 
 
103
  ///
104
+ /// Sets `GAME_INFO` (read by `ctor_impl`) and delegates directly to `ctor_impl`,
105
+ /// bypassing the naked entry trampoline which is designed as a hook target, not a
106
+ /// callable subroutine.
107
+ pub(crate) unsafe fn construct_ddgame_wrapper(
108
+ game_info: *mut GameInfo,
109
  this: *mut DDGameWrapper,
110
  display: *mut DDDisplay,
111
  sound: *mut DSSound,
 
114
  streaming_audio: *mut u8,
115
  input_ctrl: *mut u8,
116
  ) -> *mut DDGameWrapper {
117
+ GAME_INFO = game_info;
118
+
119
+ let this = this;
120
 
121
  // Initialize DDGameWrapper fields (order matches original decompile).
122
  (*this).ddgame = core::ptr::null_mut();
 
154
  this
155
  }
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  pub fn install() -> Result<(), String> {
158
  unsafe {
159
  INIT_REPLAY_ADDR = rb(va::DDGAMEWRAPPER_INIT_REPLAY);
crates/openwa-wormkit/src/replacements/hardware_init.rs CHANGED
@@ -440,7 +440,7 @@ unsafe extern "cdecl" fn impl_init_hardware(
440
 
441
  // ── DDGameWrapper (ALWAYS) ────────────────────────────────────────────────
442
  let wrapper = game_session::construct_ddgame_wrapper(
443
- game_info as *mut u8,
444
  WABox::<DDGameWrapper>::alloc(0x6F10, 0x6EF0).leak(),
445
  (*session).display_gfx as *mut DDDisplay,
446
  (*session).sound,
 
440
 
441
  // ── DDGameWrapper (ALWAYS) ────────────────────────────────────────────────
442
  let wrapper = game_session::construct_ddgame_wrapper(
443
+ game_info,
444
  WABox::<DDGameWrapper>::alloc(0x6F10, 0x6EF0).leak(),
445
  (*session).display_gfx as *mut DDDisplay,
446
  (*session).sound,
crates/openwa-wormkit/src/validation/mod.rs CHANGED
@@ -11,7 +11,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
11
 
12
  use openwa_core::rebase::rb;
13
  use openwa_core::address::va;
14
- use openwa_core::task::{CTask, CTaskBfsIter, CGameTask, CTaskMissile, MissileType, CTaskTeam, CTaskTurnGame, TurnGameCtx, SharedDataTable};
15
  use openwa_core::ddgame::DDGame;
16
  use openwa_core::ddgame_wrapper::DDGameWrapper;
17
 
 
11
 
12
  use openwa_core::rebase::rb;
13
  use openwa_core::address::va;
14
+ use openwa_core::task::{CTask, CTaskBfsIter, CGameTask, CTaskMissile, CTaskTeam, CTaskTurnGame, TurnGameCtx, SharedDataTable};
15
  use openwa_core::ddgame::DDGame;
16
  use openwa_core::ddgame_wrapper::DDGameWrapper;
17