MapView is a CWnd-derived class used across all game modes (local MP,
network, campaign, replay) for terrain/map data β not replay-specific.
Inheritance: CWnd β base (vtable 0x64C348) β MapView (vtable 0x64FC60).
Embedded in frontend dialogs as child windows for map preview/selection.
Loads .thm terrain files (current.thm for live, playback.thm for replay).
Move from engine/map_class.rs to new frontend/ module. Rename constants
(MAP_CLASS_* β MAP_VIEW_*). Update Ghidra labels.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
refactor: add MapClass struct, use typed pointer in replay map loadingβ
Create MapClass (0x29628 bytes) with vtable pointer and terrain_flag
field. Define MapClassVtable with typed destructor slot.
Replace raw u32/pointer arithmetic in replay map loading with typed
MapClass pointers β constructor, load, vtable destructor calls, and
terrain_flag field access all use the correct type. Eliminates manual
vtable offset calculations.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
refactor: use typed GameInfo pointer throughout replay parserβ
Add replay-related fields to GameInfo struct (replay_map_type,
replay_format_version, replay_active, replay_filename, terrain_flag,
etc.) by splitting unknown padding regions.
Replace all `state: u32` parameters with `*mut GameInfo` / `*const
GameInfo` across replay functions and bridge calls. Raw offset
arithmetic (`s.add(0xDB50)`) replaced with named field access
(`gi.replay_format_version`).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cleanup: remove dead host player flag check in replay parserβ
Create ReplayTeamEntry (0xD7B bytes, #[repr(C)]) in openwa-core with
named fields for all team data: team_type, alliance, config_abbrev,
team_name, config_name, worm_count, color, grave, soundbank, weapons.
Replace all `wb(va::G_TEAM_*_OFF + team_idx * 0xD7B, ...)` patterns
with direct struct field writes via `team.field = value`. Remove 13
G_TEAM_*_OFF constants from address.rs that are now expressed as struct
field offsets.
Log writer also updated to read team data via ReplayTeamEntry pointers.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
refactor: replace ~50 magic addresses in replay.rs with named constantsβ
Add 60+ named constants to address.rs for replay globals, CRT functions,
game functions, and string tables. Replace nearly all rb(0x...) calls in
replay.rs with rb(va::CONSTANT) for readability.
Categories added:
- WA CRT: WA_FILENO, WA_GET_OSFHANDLE, WA_SRAND, WA_RAND, WA_GMTIME64
- Replay globals: G_DATA_DIR, G_LOG_FILE_PTR, G_OBSERVER_ARRAY/COUNT,
G_SCHEME_*, G_HOST_PLAYER, G_PLAYER_ARRAY, G_TEAM_DATA/COUNT, etc.
- Functions: SCHEME_LOAD_BUILTIN, SCHEME_VALIDATE_EXTENDED,
REPLAY_PROCESS_STATE, REPLAY_CLEANUP_OBSERVERS, MAP_CLASS_*
- Strings: VERSION_STRING_TABLE, VERSION_SUFFIX_TABLE, STR_VERSION_381
Only 3 minor string literal addresses remain (version strings in match).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
refactor: name DDGame fields, add CoordEntry struct, unify gfx_color_tableβ
Add wa_malloc_zeroed() utility that combines wa_malloc + write_bytes.
Replace 10 malloc+zero pairs in DDGame constructor with single calls.
Type landscape temp buffers as [u32] arrays instead of [u8], enabling
direct indexing for coordinate data. Update wa_pc_landscape_ctor
signature to match (*mut u32 for output params). Use &raw mut for
obtaining raw pointers to DDGame fields.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
refactor: use stack arrays for temporary landscape buffers in DDGame ctorβ
Replace wa_malloc/wa_free with stack arrays for three temporary buffers
(landscape_coords_buf, landscape_byte_buf, landscape_temp) that were
originally stack locals in the C++ code. Rename stack_local_8 to
landscape_temp for clarity.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: add gameplay milestone checks to replay testingβ
Replace misleading "133 PASS" output (all static checks) with two
distinct categories:
- Static checks ([STATIC PASS/FAIL]): vtables, struct offsets, prologues
- Gameplay checks ([GAMEPLAY PASS/FAIL]): game init, match start, match end
Gameplay milestones are detected hook-based via TurnManager_ProcessFrame
(no timers): frame counter for init, health-based alive-team counting
for match start/completion. Report written from DLL_PROCESS_DETACH.
Key finding: team arena indices are 1-based (index 0 is unused preamble),
and sentinel header fields like worm_count are populated lazily β direct
worm health checks are more reliable for early-frame detection.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add debug_watchpoint.rs β a self-contained x86 debug register
instrumentation module that sets DR0βDR3 write watchpoints on DDGame
offsets via an INT3βVEH trick (no external debugger needed). Logs the
exact Ghidra VA of every write to watched offsets.
Used the watchpoint debugger to investigate 5 DDGame constructor field
differences. Found:
- +0x041C/+0x0420: written by DDGame__InitPaletteGradientSprites
(0x5706D0) which our Rust constructor was missing. Fixed by adding
a stdcall bridge call after LoadHudAndWeaponSprites.
- +0x7820/+0x7824/+0x7828: stale observations β both constructors
now produce identical speech slot table values.
Also removes Shadow comparison code and the original DDGame constructor
bridge (ddgame_constructor_call) since the Rust constructor is fully
matched.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cleanup: remove unused DDGame debug param loggers from game_session.rsβ
Removed PCLandscape, HUD_LoadWeaponSprites, and SpriteRegion
constructor passthrough hooks that were used during DDGame constructor
development. These were never installed β just leftover debug tools.
Eliminates all 7 compiler warnings from the wormkit crate.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cleanup: use imported names instead of fully qualified pathsβ
Remove duplicate wa_malloc/wa_free definitions from replay module,
import from openwa_core::wa_alloc instead.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
refactor: use heapless::String for replay log formattingβ
Replace hand-rolled SliceFmtWriter + write_cstr with heapless::String<N>
and push_cstr helper for fixed-capacity string building in the replay
log output. Added heapless dependency to openwa-core.
as_cstr() helper null-terminates the heapless::String buffer for C
interop (heapless::String is NOT null-terminated by default).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: port ReplayLoader and ParseReplayPosition to Rustβ
Ported the replay log header formatting entirely in Rust:
- Date/time line: extracts timestamp from observer array data,
formats via WA's gmtime64 as "Game Started at YYYY-MM-DD HH:MM:SS GMT"
- Game Engine Version + File Format Version: loaded from WA's version
table at 0x6AB480 and string resources (IDs 0x6E7, 0x6E8)
- Exported with Version: literal "3.8.1" at 0x641C60 + suffix from
version table at 0x699814 (e.g., " (Steam)")
- Per-team listing: color names from string resources (IDs 0x20-0x25),
first letter capitalized, CPU difficulty as integer math (no f64)
Key string resource IDs discovered:
0x20-0x25: color names, 0x6E7: "Game Engine Version",
0x6E8: "File Format Version", 0x6E9: "Exported with Version",
0x6ED: "CPU" label
Both headful (133/0) and headless (byte-identical) tests pass.
Zero delegation β ReplayLoader is fully ported to Rust.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Log output now writes to /getlog file without crashing:
- Version labels loaded via WA's string resources (stdcall!)
- Version string lookup from table at 0x6AB480
- Team listing with color names and CPU difficulty
- Date line skipped (needs timestamp extraction)
Known issues to fix:
- Team name: wrong offset (shows "hrombosis1" not "CPU 2")
- Version string missing from "Exported with" line
- Color names lowercase (string resource gives lowercase?)
- "Spectator" instead of "CPU" for team type label
- Padding alignment too wide (uses all 6 colors, not just active)
- Date line missing (timestamp extraction TODO)
Bugs found and fixed:
- wa_load_string: stdcall (RET 0x4), not cdecl
- fflush: wrong address (was 0x5D5068 inside _filelengthi64)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: headless /getlog output via conditional delegationβ
When a log file is open (headless /getlog mode), delegate to the
original ReplayLoader after our Rust path completes. The original
re-parses the replay and writes the log header (date, version strings,
team listing). Globals are overwritten with identical values.
In headful mode (no log file), the Rust path runs standalone.
Both headful (133/0) and headless (byte-identical) tests pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Removed ~120 lines of checkpoint/seed/diff/dump debug code.
Only two log lines remain: header info and completion status.
Headful: PASS 133/0, validation completed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Three critical bugs fixed:
1. Random seed: decompiler showed save/restore but assembly reveals
ReadU32 overwrites the save destination. Seed must be REPLACED
with stream value, not restored to old value.
2. FUN_00449B60 (map info copy): usercall(ESI=map_obj), was called
as cdecl with no ESI β corrupted game state.
3. FUN_004D4840 (scheme loader): stdcall(2 params), was cdecl β
stack corruption causing crash on return.
Also added:
- FUN_0053ee00 cleanup call (usercall ESI bridge)
- RegisterObserver bridge (usercall ESI + stdcall 1 param)
- Naked asm bridges: call_usercall_esi, call_register_observer
- Pre-loop worm name written to correct global offset (+0x03)
- ValidateTeamSetup: stdcall(1 param), not cdecl()
- Map loading: alloc(0x29628), construct, load, copy info, release
Headful: PASS 133/0, validation completed, no timeout.
Headless: FAIL (log output not yet implemented).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: ReplayLoader fully replaced β no delegation for mode 1β
Preparation for replacing delegation with direct global writes.
Added TEAM_DATA_BASE, TEAM_STRIDE, OBSERVER_ENTRY_BASE constants.
Added scheme_present field to ReplayInfo for finalization logic.
Global write attempt revealed RegisterObserver bridge needs more
investigation (crashed with current struct layout). Keeping
delegation until all bridge conventions are verified.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
parse_v2plus_payload validates the second payload structure using
ReplayStream: sub-format flags, observer team loop, game version ID,
SCHM magic + scheme data (v1/v2/v3 with correct sizes from assembly),
random seed, map bytes, replay name, host index, and 13 observer
player entries.
Key findings from assembly analysis:
- Scheme data sizes: v1=216, v2=292, v3=variable (indicator-5)
- Scheme size indicator read when obs_count >= 0x14 (assembly CMP ESI,0x14)
- Scheme header byte read when obs_count >= 3
- Version 7-9 extra field (transitional format, assembly ADD ECX,-7; CMP ECX,2)
Team parsing (XOR game ID + 6Γ0xD7B per-team data) still TODO β needs
more decompilation work for per-team field structure.
Headless PASS, unit tests pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
refactor: split ReplayLoader into parse_version1 and parse_version2plusβ
Restructured replay_loader_play to dispatch to version-specific
functions after header parsing. parse_version1 and parse_version2plus
both delegate to original for now, but parse_version2plus reads the
second payload (6800 bytes for bots.WAgame) before delegating.
Clean separation for incremental replacement of field parsing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: ReplayLoader mode routing + header parsing in Rustβ
- Mode 1 (play): Rust parses header (magic, version, payload)
- Modes 2/3/4: delegate to original trampoline
- Uses WA's own CRT functions (fopen/fread/fclose/malloc/free) via
rebased addresses to avoid CRT instance mismatch
- ReplayGuard RAII struct for file/payload cleanup on all paths
- Artclass counter uses signed comparison (JL) matching original
- Version-specific payload parsing still delegates to original
- Headless PASS, headful 133/0
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: hook ReplayLoader (passthrough) and replace ParseReplayPositionβ
- ReplayStream: cursor over byte buffer with read_u8, read_u16, read_u32,
read_prefixed_string, read_worm_name, skip methods
- parse_replay_position: converts "MM:SS.FF" time strings to frame count
- validate_team_type: validates team type byte range
- 18 unit tests covering all methods and edge cases
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: add replay system addresses for stream helpers and globalsβ
Adds 12 replay helper function addresses and 12 global data addresses.
All helper functions labelled in Ghidra.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
docs: add ReplayLoader port design spec and implementation planβ
Group F (display objects):
- DisplayGfx__ConstructFull (0x563FC0): stdcall(5), RET 0x14
- DDDisplay__ConstructTextbox (0x4FAF00): stdcall(3), RET 0xC
- DDGame__InitWeaponPanel (0x567770): stdcall(1), RET 0x4
Group G (buffer/stream objects):
- BufferObject__Constructor (0x545FD0): stdcall(3), RET 0xC
- GameStateStream__Init (0x4FB490): stdcall(1), RET 0x4
- DisplayObject__Constructor (0x540440): stdcall(2), RET 0x8
All no-log passthroughs (heap allocation in logging clobbers registers).
All 6 named in Ghidra. Total: 12 stdcall + 7 pure Rust = 19 hooks on
InitGameState sub-functions.
Headful + headless replay tests PASS.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: add passthrough hooks for 6 InitGameState constructors (Groups D+E)β
Passthrough hooks that call the original WA function, validating
calling conventions at runtime:
Group D (core game objects):
- HudPanel__Constructor (0x524070): stdcall(1), RET 0x4
- InitWeaponTable (0x53CAB0): stdcall(1), RET 0x4
- DDGame__InitTeamsFromSetup (0x5220B0): stdcall(2), RET 0x8
Group E (task objects):
- TeamManager__Constructor (0x563D40): stdcall(2), RET 0x8
- CTaskTurnGame__Constructor (0x55B280): stdcall(2), RET 0x8
- CTaskGameState__Constructor (0x532330): stdcall(2), RET 0x8
Key finding: TurnGame and GameState hooks cannot use format!/log_line
in the passthrough β the heap allocation clobbers ECX/EDX which the
caller's post-call code depends on. Logging removed from these two.
New file: game_state_hooks.rs for InitGameState passthrough hooks.
All 5 functions named in Ghidra. Headful + headless PASS.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two bugs in the agent-generated port:
1. DDGame+0x510 is a POINTER to the weapon table (needs double deref),
not an inline offset. Was reading from wrong memory.
2. Condition was inverted: (777C==0 || entry!=0) β main path with
super weapon checks. The else branch (777C!=0 && entry==0) returns
-2 or 0. Original code had these swapped.
All 7 usercall InitGameState sub-functions now ported and passing:
- SpriteGfxTable__Init, RingBuffer__Init (Group A)
- InitTeamScoring, InitAllianceData (Group B)
- InitTurnState, IsSuperWeapon, InitLandscapeFlags, CheckWeaponAvail (Group C)
Headful + headless replay tests PASS.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: port 6 of 7 InitGameState usercall functions to Rust (Group C)β
Ported and hooked:
- CGameTask__InitTurnState (0x528690): 96-line field init, camera
center, per-team flags. Bridges to DDGame__InitFeatureFlags (0x524700).
- DDGame__IsSuperWeapon (0x565960): pure switch on weapon index.
ECX preservation fix: callers rely on ECX being preserved.
- CGameTask__InitLandscapeFlags (0x528480): scheme flag + vtable dispatch.
NOT yet hooked (porting bug, disabled):
- DDGame__CheckWeaponAvail (0x53FFC0): weapon availability check.
Implementation has logic errors β needs careful re-port.
Named 5 functions in Ghidra. Headful + headless replay tests PASS
with 3 Group C hooks active (6 of 7 usercalls total ported).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: port InitTeamScoring + InitAllianceData to Rust (Group B)β
Incremental strategy: 7 usercall functions ported to pure Rust (Groups A-C),
10 stdcall constructors hooked individually (Groups D-G), with headful+headless
replay tests after each group.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
refactor: use *const c_char for C string parametersβ
The high-level sprite lookup helper now accepts &CStr directly,
moving the pointer cast inside the function. Callers pass c"name"
without .as_ptr().cast().
Lower-level functions (gfx_dir_find_entry, gfx_resource_create,
DDDisplay vtable methods) keep *const u8 since they're called from
FFI hooks or thin vtable wrappers.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
refactor: use c"..." CStr literals instead of b"...\0" binary stringsβ
Replace manual null-terminated byte strings with Rust's C string
literals for compile-time null termination guarantee:
- b"something\0".as_ptr() β c"something".as_ptr().cast()
- b"something\0" in arrays β c"something".to_bytes_with_nul()
Kept b"..." for two strings mutated at runtime (gfx_c_path, name_buf).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix: palette init used DDDisplay pointer arithmetic (sizeof scaling)β
disp.add(0x3120) with disp: *mut DDDisplay addressed 0x3120 * 4 bytes
(sizeof DDDisplay = 4) instead of 0x3120 bytes. Cast to *mut u8 for
raw byte offsets into the DisplayBase region.
Bug introduced in DDDisplayVtable commit when disp type changed from
*mut u8 to *mut DDDisplay.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>