paavohtl Claude Opus 4.6 (1M context) commited on
Commit
4d0c588
·
1 Parent(s): d2350ac

docs: add DDGame constructor implementation plan

Browse files

12-task incremental plan: allocation + params, sub-object bridges
(GfxHandler, PCLandscape, SpriteRegion, CoordList, audio init),
arrow sprites, resource loading, integration tests.

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

docs/superpowers/plans/2026-03-16-ddgame-constructor.md ADDED
@@ -0,0 +1,553 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # DDGame Constructor Port — Implementation Plan
2
+
3
+ > **For agentic workers:** REQUIRED: Use superpowers:subagent-driven-development (if subagents available) or superpowers:executing-plans to implement this plan. Steps use checkbox (`- [ ]`) syntax for tracking.
4
+
5
+ **Goal:** Replace DDGame__Constructor (0x56E220) with a Rust `DDGame::new()` function that creates the 0x98B8-byte game state object field by field, bridging WA sub-calls initially.
6
+
7
+ **Architecture:** The constructor allocates DDGame via `wa_malloc(0x98B8)`, zero-fills it, then runs ~35 initialization steps covering param storage, sub-object creation (GfxHandler, PCLandscape, SpriteRegions, CoordList, DisplayGfx objects), resource loading (sprites, gradients, WAVs), and configuration. We'll implement `DDGame::new()` in openwa-core, call it from `construct_ddgame_wrapper` in game_session.rs, and bridge complex sub-calls via typed function pointers.
8
+
9
+ **Tech Stack:** Rust (i686-pc-windows-msvc), `wa_alloc` for WA heap, `core::ptr` for field writes, Ghidra MCP for decompilation reference.
10
+
11
+ ---
12
+
13
+ ## Chunk 1: Foundation — DDGame::new() with Parameter Storage
14
+
15
+ ### Task 1: Add Missing Sub-Function Addresses
16
+
17
+ **Files:**
18
+ - Modify: `crates/openwa-core/src/address.rs`
19
+
20
+ - [ ] **Step 1: Add addresses for all sub-functions called by the constructor**
21
+
22
+ Add to `address.rs` in the appropriate section:
23
+
24
+ ```rust
25
+ // --- DDGame Constructor sub-calls ---
26
+
27
+ /// DDGame__InitFields (0x526120): usercall(EDI=ddgame), plain RET.
28
+ /// Zeroes stride-0x194 table, coordinate entries, calls FUN_00526080.
29
+ pub const DDGAME_INIT_FIELDS: u32 = 0x0052_6120; // already exists
30
+
31
+ /// FUN_00526080: usercall(ESI=ddgame), plain RET.
32
+ /// Initializes RenderQueue index arrays at +0xC4..+0x4A2.
33
+ pub const DDGAME_INIT_RENDER_INDICES: u32 = 0x0052_6080;
34
+
35
+ /// FUN_00525BE0: stdcall(ddgame_wrapper), plain RET.
36
+ /// Sets DDGame+0x7E2E/0x7E2F/0x7E3F flags based on game version/mode.
37
+ pub const DDGAME_INIT_VERSION_FLAGS: u32 = 0x0052_5BE0;
38
+
39
+ /// FUN_005411A0: unknown convention, called at start.
40
+ /// Initializes some CRT / MFC state.
41
+ pub const FUN_5411A0: u32 = 0x0054_11A0;
42
+
43
+ /// GfxHandler constructor pattern: alloc 0x19C, memset 0, set vtable.
44
+ /// vtable at GfxHandler__vtable global.
45
+ pub const GFX_HANDLER_VTABLE: u32 = 0x0066_4308; // verify in Ghidra
46
+
47
+ /// GfxHandler__LoadDir (called after fopen).
48
+ pub const GFX_HANDLER_LOAD_DIR: u32 = 0x0057_0B50; // verify
49
+
50
+ /// FUN_00570A90: called before display palette setup (non-headless).
51
+ pub const FUN_570A90: u32 = 0x0057_0A90;
52
+
53
+ /// FUN_00570E20: called after GfxHandler init.
54
+ pub const FUN_570E20: u32 = 0x0057_0E20;
55
+
56
+ /// FUN_00570F30: called before DSSound_LoadEffectWAVs.
57
+ pub const FUN_570F30: u32 = 0x0057_0F30;
58
+
59
+ /// PCLandscape__Constructor (0xB44 bytes).
60
+ pub const PC_LANDSCAPE_CONSTRUCTOR: u32 = 0x0050_56F0; // verify
61
+
62
+ /// SpriteRegion__Constructor (0x9C bytes).
63
+ pub const SPRITE_REGION_CONSTRUCTOR: u32 = 0x0057_DB20;
64
+
65
+ /// FUN_005717A0: weapon sprite loading.
66
+ pub const LOAD_WEAPON_SPRITES: u32 = 0x0057_17A0;
67
+
68
+ /// HUD_LoadWeaponSprites_Maybe.
69
+ pub const HUD_LOAD_WEAPON_SPRITES: u32 = 0x0052_4070; // verify address
70
+
71
+ /// FUN_004F6300: creates some graphics object, returns ptr or null.
72
+ pub const FUN_4F6300: u32 = 0x004F_6300;
73
+
74
+ /// FUN_004F6370: initializes TaskStateMachine-like object.
75
+ pub const FUN_4F6370: u32 = 0x004F_6370;
76
+
77
+ /// FUN_0056A830: called for non-headless display finalization.
78
+ pub const FUN_56A830: u32 = 0x0056_A830;
79
+
80
+ /// DSSound_LoadEffectWAVs (loads all sound effect WAV files).
81
+ pub const DSSOUND_LOAD_EFFECT_WAVS: u32 = 0x0057_1530; // verify
82
+
83
+ /// DSSound_LoadAllSpeechBanks.
84
+ pub const DSSOUND_LOAD_ALL_SPEECH_BANKS: u32 = 0x0057_1A70;
85
+
86
+ /// g_GameInfo global (0x7749A0).
87
+ pub const G_GAME_INFO: u32 = 0x0077_49A0;
88
+ ```
89
+
90
+ - [ ] **Step 2: Verify addresses in Ghidra and label unnamed functions**
91
+
92
+ Use Ghidra MCP `batch_create_labels` / `batch_rename_function_components` for all newly identified sub-functions. Cross-reference with the decompile to confirm each address.
93
+
94
+ - [ ] **Step 3: Commit**
95
+
96
+ ```bash
97
+ git add crates/openwa-core/src/address.rs
98
+ git commit -m "feat: add DDGame constructor sub-function addresses"
99
+ ```
100
+
101
+ ### Task 2: Add DDGameWrapper Fields Used by Constructor
102
+
103
+ **Files:**
104
+ - Modify: `crates/openwa-core/src/engine/ddgame_wrapper.rs`
105
+
106
+ The constructor accesses DDGameWrapper at offsets +0x488 (ddgame ptr), +0x48C, +0x490, +0x4C0, +0x4C4, +0x4C8, +0x4CC, +0x4D0, +0x4D8, +0x4DC, +0x4E0. Many of these are sub-object pointers set during the DDGame construction.
107
+
108
+ - [ ] **Step 1: Read current DDGameWrapper struct**
109
+
110
+ Read `crates/openwa-core/src/engine/ddgame_wrapper.rs` and identify which offsets are already mapped.
111
+
112
+ - [ ] **Step 2: Add missing DDGameWrapper fields**
113
+
114
+ Add fields for offsets used by the constructor that aren't yet mapped:
115
+ - +0x48C: Network-related object pointer (0x2C bytes, conditional)
116
+ - +0x490: Network flag byte
117
+ - +0x4C0: Primary GfxHandler pointer (0x19C bytes)
118
+ - +0x4C4: Secondary GfxHandler pointer (0x19C bytes, conditional)
119
+ - +0x4C8: GfxHandler index/flag (uint)
120
+ - +0x4CC: PCLandscape pointer (0xB44 bytes)
121
+ - +0x4D0: Display pointer (copied from DDGame display)
122
+ - +0x4D8: Unknown (set to 0)
123
+ - +0x4DC: Calculated height value
124
+ - +0x4E0: Set to -100 (0xFFFFFF9C)
125
+
126
+ - [ ] **Step 3: Verify with runtime dump**
127
+
128
+ Use the F7/validator debug tools to confirm field values at these offsets match expectations.
129
+
130
+ - [ ] **Step 4: Commit**
131
+
132
+ ```bash
133
+ git add crates/openwa-core/src/engine/ddgame_wrapper.rs
134
+ git commit -m "feat: add DDGameWrapper fields used by DDGame constructor"
135
+ ```
136
+
137
+ ### Task 3: Implement DDGame::new() — Phase 1 (Trivial Inits + Param Storage)
138
+
139
+ **Files:**
140
+ - Modify: `crates/openwa-core/src/engine/ddgame.rs`
141
+
142
+ This is the core of the port. Phase 1 covers: allocation, zero-fill, parameter storage, and simple field writes. Complex sub-calls are bridged.
143
+
144
+ - [ ] **Step 1: Create DDGame::new() skeleton**
145
+
146
+ ```rust
147
+ /// Construct a new DDGame, matching DDGame__Constructor (0x56E220).
148
+ ///
149
+ /// # Safety
150
+ /// All pointer params must be valid WA objects. `wrapper` must be
151
+ /// a valid DDGameWrapper with fields initialized up to this point.
152
+ pub unsafe fn new(
153
+ wrapper: *mut DDGameWrapper,
154
+ keyboard: *mut DDKeyboard,
155
+ display: *mut DDDisplay,
156
+ sound: *mut DSSound,
157
+ palette: *mut Palette,
158
+ music: *mut Music,
159
+ param7: *mut u8, // timer? 0x1F4 observed
160
+ net_game: *mut u8, // from GameSession
161
+ game_info: *mut GameInfo,
162
+ network_ecx: u32, // implicit ECX from caller
163
+ ) -> *mut DDGame {
164
+ // 1. Allocate and zero-fill
165
+ let ddgame = wa_malloc(0x98B8) as *mut DDGame;
166
+ if ddgame.is_null() {
167
+ return core::ptr::null_mut();
168
+ }
169
+ core::ptr::write_bytes(ddgame as *mut u8, 0, 0x98B8);
170
+
171
+ // 2. Call InitFields (usercall EDI=ddgame)
172
+ call_init_fields(ddgame);
173
+
174
+ // 3. Store at DDGameWrapper+0x488
175
+ (*wrapper).ddgame = ddgame;
176
+
177
+ // 4. Store constructor parameters
178
+ (*ddgame).display = display;
179
+ (*ddgame).sound = sound;
180
+ (*ddgame).keyboard = keyboard;
181
+ (*ddgame).palette = palette;
182
+ (*ddgame).music = music;
183
+ (*ddgame)._param_018 = param7;
184
+ (*ddgame)._caller = network_ecx as *mut u8;
185
+ (*ddgame).game_info = game_info;
186
+ (*ddgame)._param_028 = net_game;
187
+
188
+ // 5. Set global
189
+ *(rb(va::G_GAME_INFO) as *mut *mut GameInfo) = game_info;
190
+
191
+ // 6. Sound available + always-1 flags
192
+ (*ddgame).sound_available =
193
+ if (*(game_info as *const u8).add(0xF914) as *const i32).read() == 0 { 1 } else { 0 };
194
+ (*ddgame)._field_7efc = 1;
195
+
196
+ // ... (Phase 2 sub-calls added incrementally)
197
+
198
+ ddgame
199
+ }
200
+ ```
201
+
202
+ - [ ] **Step 2: Implement bridge for DDGame__InitFields**
203
+
204
+ InitFields is `usercall(EDI=ddgame)`, plain RET. Create a naked bridge:
205
+
206
+ ```rust
207
+ /// Bridge to DDGame__InitFields (0x526120).
208
+ /// Convention: usercall(EDI=ddgame), plain RET.
209
+ #[unsafe(naked)]
210
+ unsafe extern "C" fn call_init_fields(_ddgame: *mut DDGame) {
211
+ core::arch::naked_asm!(
212
+ "pushl %edi",
213
+ "movl 8(%esp), %edi", // EDI = ddgame
214
+ "calll *({addr})",
215
+ "popl %edi",
216
+ "retl",
217
+ addr = sym INIT_FIELDS_ADDR,
218
+ options(att_syntax),
219
+ );
220
+ }
221
+ static mut INIT_FIELDS_ADDR: u32 = 0;
222
+ ```
223
+
224
+ - [ ] **Step 3: Implement bridge for FUN_00525BE0 (version flags)**
225
+
226
+ This is `stdcall(ddgame_wrapper)` — simple transmute call:
227
+
228
+ ```rust
229
+ /// Bridge to FUN_00525BE0 — sets DDGame+0x7E2E/0x7E2F/0x7E3F flags.
230
+ unsafe fn call_init_version_flags(wrapper: *mut DDGameWrapper) {
231
+ let f: unsafe extern "stdcall" fn(*mut DDGameWrapper) =
232
+ core::mem::transmute(rb(va::DDGAME_INIT_VERSION_FLAGS) as usize);
233
+ f(wrapper);
234
+ }
235
+ ```
236
+
237
+ - [ ] **Step 4: Commit**
238
+
239
+ ```bash
240
+ git add crates/openwa-core/src/engine/ddgame.rs
241
+ git commit -m "feat: DDGame::new() phase 1 — allocation, params, trivial inits"
242
+ ```
243
+
244
+ ### Task 4: Wire DDGame::new() into game_session.rs
245
+
246
+ **Files:**
247
+ - Modify: `crates/openwa-wormkit/src/replacements/game_session.rs`
248
+
249
+ - [ ] **Step 1: Replace ddgame_constructor_call with DDGame::new()**
250
+
251
+ In `construct_ddgame_wrapper`, replace:
252
+ ```rust
253
+ DDGAME_CTOR_ECX = input_ctrl as u32;
254
+ ddgame_constructor_call(
255
+ this, display, sound, keyboard, palette, streaming_audio,
256
+ timer_obj, net_game, game_info,
257
+ );
258
+ ```
259
+
260
+ With:
261
+ ```rust
262
+ DDGame::new(
263
+ this, keyboard, display, sound, palette, streaming_audio as *mut Music,
264
+ timer_obj, net_game, game_info,
265
+ input_ctrl as u32,
266
+ );
267
+ ```
268
+
269
+ - [ ] **Step 2: Remove the naked ddgame_constructor_call bridge and DDGAME_CTOR_ECX/DDGAME_CTOR_ADDR statics**
270
+
271
+ These are no longer needed. Clean up dead code.
272
+
273
+ - [ ] **Step 3: Trap DDGame__Constructor**
274
+
275
+ Add to `game_session::install()`:
276
+ ```rust
277
+ hook::install_trap!("DDGame__Constructor", va::CONSTRUCT_DD_GAME);
278
+ ```
279
+
280
+ - [ ] **Step 4: Build and test**
281
+
282
+ Run: `cargo build --target i686-pc-windows-msvc -p openwa-wormkit --release`
283
+
284
+ This will fail at runtime because DDGame::new() doesn't yet call all the sub-constructors. That's expected — the next tasks add them incrementally.
285
+
286
+ - [ ] **Step 5: Commit**
287
+
288
+ ```bash
289
+ git add crates/openwa-wormkit/src/replacements/game_session.rs
290
+ git commit -m "refactor: wire DDGame::new() into game_session, trap original"
291
+ ```
292
+
293
+ ---
294
+
295
+ ## Chunk 2: Sub-Object Creation Bridges
296
+
297
+ ### Task 5: Network Object Init (DDGameWrapper+0x48C)
298
+
299
+ **Files:**
300
+ - Modify: `crates/openwa-core/src/engine/ddgame.rs`
301
+
302
+ - [ ] **Step 1: Add conditional network object creation**
303
+
304
+ Condition: `game_info+0xD778 == -2`. Alloc 0x2C bytes, zero-fill, store DDGame ptr at [0], copy 2 config bytes from game_info. If `network_ecx != 0`, store at `network_ecx+0x18`.
305
+
306
+ ```rust
307
+ // Conditional network object (game_info+0xD778 == -2)
308
+ let d778 = *((game_info as *const u8).add(0xD778) as *const i32);
309
+ if d778 == -2 {
310
+ let net_obj = wa_malloc(0x2C) as *mut u8;
311
+ core::ptr::write_bytes(net_obj, 0, 0x2C);
312
+ *(net_obj as *mut *mut DDGame) = ddgame;
313
+ // piVar3[1..3] = 0, piVar3[6] = 0 (already zero from memset)
314
+ *net_obj.add(0x28) = *((*(ddgame as *const u8).add(0x24) as *const *const u8)
315
+ .read().add(0xD944));
316
+ *net_obj.add(0x29) = *((*(ddgame as *const u8).add(0x24) as *const *const u8)
317
+ .read().add(0xD946));
318
+ // Store at DDGameWrapper+0x48C
319
+ *(wrapper as *mut u8).add(0x48C).cast::<*mut u8>().write(net_obj);
320
+ if network_ecx != 0 {
321
+ *((network_ecx as *mut u8).add(0x18) as *mut *mut u8) = net_obj;
322
+ }
323
+ }
324
+ ```
325
+
326
+ - [ ] **Step 2: Test with replay test**
327
+
328
+ Run headful replay test — game should not crash during init.
329
+
330
+ - [ ] **Step 3: Commit**
331
+
332
+ ### Task 6: GfxHandler Init + Gfx.dir Loading
333
+
334
+ **Files:**
335
+ - Modify: `crates/openwa-core/src/engine/ddgame.rs`
336
+
337
+ This is a complex section that opens Gfx.dir files, tries multiple paths, and conditionally creates a second GfxHandler. For now, bridge entirely.
338
+
339
+ - [ ] **Step 1: Create bridge for GfxHandler creation and Gfx.dir loading**
340
+
341
+ Extract the entire GfxHandler init section (lines 151-250 of decompile) into a single bridged call. This section operates on DDGameWrapper fields (+0x4C0, +0x4C4, +0x4C8), not DDGame directly, so we can bridge it as one unit.
342
+
343
+ Option A: Call the original constructor section via a calculated offset.
344
+ Option B: Reimplement the file-open logic in Rust (fopen/GfxHandler__LoadDir are simple).
345
+
346
+ Start with Option A (bridge) and convert later.
347
+
348
+ - [ ] **Step 2: Test**
349
+ - [ ] **Step 3: Commit**
350
+
351
+ ### Task 7: Audio Init (Sound Effects + Speech + ActiveSoundTable)
352
+
353
+ **Files:**
354
+ - Modify: `crates/openwa-core/src/engine/ddgame.rs`
355
+
356
+ - [ ] **Step 1: Add audio initialization**
357
+
358
+ Condition: `game_info+0xF914 == 0` (not headless) AND `ddgame.sound != null`.
359
+
360
+ ```rust
361
+ if *((game_info as *const u8).add(0xF914) as *const i32) == 0 {
362
+ call_fun_570f30(); // bridge
363
+ if !(*ddgame).sound.is_null() {
364
+ call_dssound_load_effect_wavs(); // bridge
365
+ call_dssound_load_all_speech_banks(); // bridge
366
+ // Allocate ActiveSoundTable (0x608 bytes)
367
+ let ast = wa_malloc(0x608) as *mut ActiveSoundTable;
368
+ (*ast).ddgame = ddgame;
369
+ (*ast).counter = 0;
370
+ core::ptr::write_bytes(ast as *mut u8, 0, 0x600); // zero entries only
371
+ (*ddgame).active_sounds = ast;
372
+ }
373
+ }
374
+ ```
375
+
376
+ Note: DSSound_LoadEffectWAVs and DSSound_LoadAllSpeechBanks are already known addresses. The ActiveSoundTable allocation can be done in pure Rust since we have the struct.
377
+
378
+ - [ ] **Step 2: Test with headful replay**
379
+ - [ ] **Step 3: Commit**
380
+
381
+ ### Task 8: PCLandscape + TaskStateMachine + SpriteRegions
382
+
383
+ **Files:**
384
+ - Modify: `crates/openwa-core/src/engine/ddgame.rs`
385
+
386
+ - [ ] **Step 1: Bridge PCLandscape__Constructor**
387
+
388
+ Alloc 0xB44, zero-fill, call PCLandscape constructor (complex, many params). Store at DDGameWrapper+0x4CC and DDGame+0x020.
389
+
390
+ - [ ] **Step 2: Bridge TaskStateMachine creation**
391
+
392
+ Alloc 0x2C, zero-fill, call FUN_004F6370 for init, set vtable. Store at DDGame+0x380.
393
+
394
+ - [ ] **Step 3: Bridge 8× SpriteRegion creation**
395
+
396
+ Each: alloc 0x9C, zero-fill, call SpriteRegion__Constructor with (param1, param2). Store at DDGame+0x46C..0x488 (note: these are offsets 0x46C, 0x470, 0x474, 0x478, 0x47C, 0x480, 0x484, 0x488 — the 8 sprite_regions).
397
+
398
+ SpriteRegion params (from decompile):
399
+ | DDGame offset | param1 | param2 |
400
+ |---------------|--------|--------|
401
+ | +0x474 | 0x24 | 0x2E |
402
+ | +0x46C | 0x07 | 0x2D |
403
+ | +0x470 | 0x0A | 0x0D |
404
+ | +0x478 | 0x20 | 0x00 |
405
+ | +0x47C | 0x00 | 0x00 |
406
+ | +0x484 | 0x09 | 0x173 |
407
+ | +0x488 | 0x07 | 0x1E5 |
408
+ | +0x480 | 0x07 | 0x2D |
409
+
410
+ - [ ] **Step 4: Set landscape-derived value at +0x468**
411
+
412
+ ```rust
413
+ // (*ddgame).landscape_val = landscape.vtable[0xB].call()
414
+ let landscape = (*ddgame).landscape;
415
+ let vtable = *(landscape as *const *const u32);
416
+ let get_val: unsafe extern "thiscall" fn(*mut u8) -> u32 =
417
+ core::mem::transmute(*vtable.add(0xB));
418
+ (*ddgame)._landscape_val = get_val(landscape as *mut u8) as *mut u8;
419
+ ```
420
+
421
+ - [ ] **Step 5: Test**
422
+ - [ ] **Step 6: Commit**
423
+
424
+ ### Task 9: Arrow Sprites + Collision Regions (32 iterations)
425
+
426
+ **Files:**
427
+ - Modify: `crates/openwa-core/src/engine/ddgame.rs`
428
+
429
+ - [ ] **Step 1: Bridge arrow sprite loading loop**
430
+
431
+ The loop loads 32 `arrow##.img` files, creates DisplayGfx objects, and creates SpriteRegion collision regions. This is complex graphics code — bridge the entire loop initially.
432
+
433
+ Create a helper that encapsulates the loop body using GfxHandler vtable calls.
434
+
435
+ - [ ] **Step 2: Test**
436
+ - [ ] **Step 3: Commit**
437
+
438
+ ### Task 10: CoordList, DisplayGfx, Resource Loading
439
+
440
+ **Files:**
441
+ - Modify: `crates/openwa-core/src/engine/ddgame.rs`
442
+
443
+ - [ ] **Step 1: Create CoordList in Rust**
444
+
445
+ Pure Rust — this is simple allocation:
446
+ ```rust
447
+ // CoordList: 3 u32s (count, capacity, data_ptr) + 0x12C0 buffer
448
+ let coord_list = wa_malloc(12) as *mut u32;
449
+ *coord_list = 0; // count
450
+ *coord_list.add(1) = 600; // capacity
451
+ let coord_data = wa_malloc(0x12C0) as *mut u8;
452
+ core::ptr::write_bytes(coord_data, 0, 0x12C0);
453
+ *coord_list.add(2) = coord_data as u32;
454
+ (*ddgame).coord_list = coord_list as *mut u8;
455
+ ```
456
+
457
+ - [ ] **Step 2: Bridge coordinate list population from landscape**
458
+
459
+ The loop reads from landscape data and inserts unique entries.
460
+
461
+ - [ ] **Step 3: Bridge DisplayGfx at +0x138**
462
+
463
+ Alloc 0x2C, init via FUN_004F6370, set vtable to DisplayGfx__vtable.
464
+
465
+ - [ ] **Step 4: Bridge weapon sprite loading (FUN_005717A0 ×2)**
466
+ - [ ] **Step 5: Bridge gradient/layer/fill image loading**
467
+ - [ ] **Step 6: Bridge HUD weapon sprite loading**
468
+ - [ ] **Step 7: Set fill pixel at +0x7338**
469
+ - [ ] **Step 8: Bridge display finalization calls**
470
+ - [ ] **Step 9: Test with full headful replay**
471
+ - [ ] **Step 10: Commit**
472
+
473
+ ---
474
+
475
+ ## Chunk 3: Integration and Verification
476
+
477
+ ### Task 11: DDGameWrapper Field Updates
478
+
479
+ **Files:**
480
+ - Modify: `crates/openwa-core/src/engine/ddgame.rs`
481
+
482
+ - [ ] **Step 1: Add DDGameWrapper field writes that happen during the constructor**
483
+
484
+ The original constructor writes to many DDGameWrapper fields:
485
+ - +0x4D8 = 0
486
+ - +0x4DC = calculated from param8+0x44C: `byte_val * 0x38 + 0x7E + 0x2AD`
487
+ - +0x4E0 = -100 (0xFFFFFF9C)
488
+ - +0x6EE8 = 0 (speech name count)
489
+
490
+ - [ ] **Step 2: Commit**
491
+
492
+ ### Task 12: Full Integration Test
493
+
494
+ - [ ] **Step 1: Run headful replay test**
495
+
496
+ ```bash
497
+ powershell -ExecutionPolicy Bypass -File replay-test.ps1
498
+ ```
499
+
500
+ Expected: Game plays through replay without crashes. Verify audio, visuals, and turn transitions.
501
+
502
+ - [ ] **Step 2: Run headless replay test**
503
+
504
+ ```bash
505
+ powershell -ExecutionPolicy Bypass -File replay-test.ps1 -Headless
506
+ ```
507
+
508
+ Expected: Byte-identical log output compared to baseline.
509
+
510
+ - [ ] **Step 3: Manual gameplay test**
511
+
512
+ Start a local match, play 2-3 turns. Verify:
513
+ - Worm sprites render correctly
514
+ - Weapons fire and explode
515
+ - Sound effects play
516
+ - Turn order widget shows
517
+ - Camera follows active worm
518
+
519
+ - [ ] **Step 4: Update Ghidra labels for all newly identified functions**
520
+
521
+ Use `batch_create_labels` for any remaining unnamed functions.
522
+
523
+ - [ ] **Step 5: Final commit**
524
+
525
+ ```bash
526
+ git add -A
527
+ git commit -m "feat: replace DDGame__Constructor with Rust DDGame::new()"
528
+ ```
529
+
530
+ ---
531
+
532
+ ## Notes
533
+
534
+ ### Bridging Strategy
535
+
536
+ For sub-calls that use unusual calling conventions (usercall with EDI/ESI), use `#[unsafe(naked)]` bridge functions matching the pattern in `game_session.rs`. For plain stdcall/thiscall sub-calls, use `core::mem::transmute` to typed function pointers.
537
+
538
+ ### Order Matters
539
+
540
+ The init steps MUST execute in the exact order from the decompile. Some sub-calls depend on fields set by earlier steps (e.g., PCLandscape reads game_info from DDGame+0x24, GfxHandler is used by arrow sprite loading).
541
+
542
+ ### Testing Cadence
543
+
544
+ After each Task, run a headful replay test. If anything crashes, check ERRORLOG.TXT and compare against the decompile to find which field or sub-call was missed.
545
+
546
+ ### Future: Bridge Elimination (Phase 3)
547
+
548
+ Once all bridges are working, each can be independently converted to pure Rust:
549
+ 1. InitFields → direct field writes (already have the offset list)
550
+ 2. FUN_00526080 → Rust loop for render index arrays
551
+ 3. ActiveSoundTable → already done in Task 7
552
+ 4. CoordList → already done in Task 10
553
+ 5. SpriteRegion / PCLandscape / GfxHandler → larger projects, future plans