Design for launching WA.exe with replay files for automated
validation and RE discovery. Validator DLL detects automated mode
via OPENWA_REPLAY_TEST env var and self-terminates after capture.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add runtime-validated PCLandscape struct, landscape dump via F10 hotkey
Rewrote PCLandscape struct with fields verified against live game memory:
crater sprites, collision bitmap, dirty rect queue, 6 terrain layers,
level/theme paths, visible bounds, GfxHandlers. Added DirtyRect struct
and vtable_slots module. Added 5 new landscape function addresses.
Validator now dumps full PCLandscape state on F10 or after 15s delay.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
refactor: use FullTeamBlock structs in team/weapon hooks, add F9 dump hotkey
Refactor team.rs and weapon.rs replacements to use WormEntry and
FullTeamBlock struct field access instead of raw pointer arithmetic.
Rename HasFullHealthWorm → CheckWormState0x64 (reads state, not health).
Add named worm state constants (IDLE=0x65, ACTIVE=0x67, DEAD=0x87).
Add F9 hotkey to validator for on-demand team block dumps.
Cross-validate struct access against old raw pointer patterns (8/8 pass).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
refactor: extract named constants from magic numbers across all hooks
Add worm layout, game phase, and team data constants to ddgame.rs.
Replace raw hex in all 5 replacement modules with named constants:
weapon IDs use Weapon enum, worm offsets use ddgame::worm::*,
dialog/scheme/config offsets use local named constants.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
refactor: split team/worm accessors from weapon.rs into team.rs
Move CountTeamsByAlliance, GetTeamTotalHealth, IsWormInSpecialState,
GetWormPosition, HasFullHealthWorm to a new team.rs module. weapon.rs
now only contains AddAmmo and GetAmmo.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix: preserve EDX across usercall trampoline cdecl calls
Original __usercall functions often don't touch EDX, but our cdecl impl
functions are free to clobber it. Callers (e.g. FUN_0055fda0) rely on
EDX surviving calls to IsWormInSpecialState — the corrupted EDX caused
an access violation writing to near-null address 0x7EA9.
All 7 trampoline macro arms now push/pop EDX around the cdecl call,
with stack param offsets adjusted by +4.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add 5 DDGame team/worm accessor function replacements
Port CountTeamsByAlliance, GetTeamTotalHealth, IsWormInSpecialState,
GetWormPosition, and HasFullHealthWorm from the 0x5220-0x5260 DDGame
neighborhood. Extends TeamWeaponState with team_count and alliance
tracking fields. Adds 2 new usercall_trampoline! macro arms (2-reg
plain ret, 2-reg+3-stack ret N). Total hooks: 20 → 25.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add GetAmmo and AddAmmo weapon hooks with TeamWeaponState struct
Add Rust replacements for GetAmmo (0x5225E0) and AddAmmo (0x522640),
the first DDGame wrapper functions to be ported. Both use __usercall
conventions with implicit register params, handled by new multi-register
arms in the usercall_trampoline! macro.
- TeamWeaponState/TeamEntry structs in openwa-types with typed accessors
- 3 new usercall_trampoline! arms: 2-reg+1-stack, 2-reg+2-stack, 3-reg
- GetAmmo: alliance-based ammo lookup with delay/phase/SelectWorm checks
- AddAmmo: ammo increment with unlimited (-1) support
- SubtractAmmo (0x522680) address noted but unhooked — only 5 xrefs,
never observed during normal gameplay; likely not the main decrement path
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
docs: add configuration system design and implementation plan
Design doc and implementation plan for porting WA's configuration
subsystem (Theme I/O, Registry, GameInfo, CrashReportURL) to Rust.
These were used to guide the config.rs implementation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chore: sync Ghidra labels and add frame buffer globals
Add G_FRAME_BUFFER_PTR/WIDTH/HEIGHT addresses discovered from
ConstructFrameBuffer (0x5A2430). Gitignore decompiled C dumps
(auto-generated from Ghidra, not version-controlled).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add Debug formatter for GameInfo known fields
Prints all named options fields, data paths as strings, and unknown
config DWORDs in hex. Skips the large unknown padding regions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
refactor: add GameInfo type and use typed field access in LoadOptions
New GameInfo struct in openwa-types with #[repr(C)] layout covering
known fields at offsets 0xDAE8 and 0xF3A0-0xF4C4. Conservative size
0xF500 with _unknown padding for unmapped regions.
Refactors hook_load_options to cast the raw pointer to &mut GameInfo,
replacing all manual pointer arithmetic with named field access.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reads CrashReportURL from HKCU Options registry key into static buffer.
Completes the 7-function configuration system port to Rust.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add GameInfo__LoadOptions hook (registry reads + global copies)
Full Rust replacement for GameInfo__LoadOptions (0x460AC0). Reads 12
registry values from HKCU Options section and copies ~20 global data
blocks into the GameInfo struct. Adds 17 global address constants.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DeleteKeyRecursive delegates to openwa-lib's recursive registry helper.
CleanAll deletes all 4 WA registry subsections and clears NetSettings INI.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
New config.rs replacement module with three theme hooks using std::fs.
Error dialogs use MessageBoxA matching original AfxMessageBox behavior.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
New registry.rs module with read_profile_int, read_profile_string,
and delete_key_recursive. These replace MFC's CWinApp registry helpers
for direct HKCU access to WA's configuration keys.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add windows-sys dep to openwa-lib and configuration address constants
Add windows-sys with Win32_System_Registry + Win32_UI_WindowsAndMessaging
features to openwa-lib. Add 7 address constants for configuration system
functions (Theme I/O, Registry cleanup, GameInfo LoadOptions, CrashReportURL).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add ExtractBuiltins and LoadNumbered scheme hooks
Complete the scheme subsystem: all 10 functions now have Rust hooks.
- ExtractBuiltins (0x4D5720): full Rust replacement that extracts
built-in scheme .wsc files from PE resources to User\Schemes\.
Uses hardcoded scheme names (MFC string resources not accessible
via plain LoadStringA). Skips slot 13 feature check (always
available on Steam).
- LoadNumbered (0x4D4E00): logging sentinel — believed dead code
(zero xrefs), delegates to original with a warning log.
- Add openwa-lib::wa::resource module with Win32 PE resource helpers
(FindResourceA, LoadResource, SizeofResource, LockResource).
- Unify GetModuleHandleA signature across rebase.rs and resource.rs.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
refactor: add CStringRef wrapper, make InitFromData and ScanDirectory fully standalone
Add CStringRef type to openwa-lib::wa::mfc for safe interaction with
MFC ATL::CSimpleStringT<char,0> objects. Includes:
- CStringRef: wraps CString field address, supports assign_from() and
assign_resource() via WA's operator= and string resource lookup
- cstring_release(): standalone refcount release with atomic decrement
and conditional deallocation via pStringMgr vtable
InitFromData and ScanDirectory no longer delegate to their originals.
InitFromData handles CString name assignment directly (operator= for
non-empty, string resource #14 for empty). ScanDirectory releases
the CString parameter refcount after completing the Rust dir scan.
New address constants: CSTRING_OPERATOR_ASSIGN (0x401D20),
CSTRING_ASSIGN_RESOURCE (0x4A39F0), CSTRING_SET_STRING (0x401EA0).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add 5 more Scheme function replacements in Rust
Move rebase + wa_call primitives to shared openwa-lib crate. Add
zero-cost handle types (CWndHandle, CDialogHandle) with methods and
a wa::frontend module that encapsulates inline asm for PaletteAnimation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
refactor: add usercall_trampoline! macro for naked asm generation
Replaces hand-written naked trampolines in frontend.rs and scheme.rs
with a declarative macro that handles register capture + stack forwarding.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Each hook installation was 12-14 lines of repeated MinHook setup.
New hook::install(name, addr, detour) handles create_hook, enable_hook,
and logging, returning the trampoline pointer. Each call site is now
4-5 lines.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: replace Scheme__ReadFile, ValidateExtendedOptions, FileExists with Rust
Three WA.exe scheme functions now fully replaced by Rust implementations:
- Scheme__ReadFile (0x4D3890): Rust file I/O via SchemeFile parser,
writes payload to dest struct matching original memory layout for
V1/V2/V3 schemes. Gameplay modifier globals not yet ported.
- Scheme__ValidateExtendedOptions (0x4D5110): naked asm trampoline
(EAX implicit param) calling ExtendedOptions::validate_bytes()
with 60+ field checks matching Ghidra decompilation.
- Scheme__FileExists (0x4D4CD0): stdcall replacement using
std::path::Path::exists().
Also fixes SchemeVersion enum: replaces Extended(u8) with explicit V3
variant, from_byte() now returns Option for unknown versions, adds
SCHEME_PAYLOAD_V3 constant.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add typed scheme payload structs + field accessors
Add SchemeOptions (36B), WeaponSettings (4B), and ExtendedOptions (110B)
structs with from_bytes/to_bytes for safe typed access to .wsc payload
fields. Include V3 ROM defaults, scheme weapon order table, and 8 new
tests covering typed field access, roundtrips, and version boundaries.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add SchemeFile type to openwa-types with from_bytes/to_bytes for the
SCHM container format (v1: 0xD8 payload, v2: 0x124 payload). Tested
against all 18 bundled scheme files with round-trip verification.
RE discoveries: Scheme__Load (0x4D4CD0) is actually just a file-exists
check, Scheme__ParseFile (0x4D44F0) is a save function. The real reader
is Scheme__ReadFile (0x4D3890), stdcall with 4 params. Hook confirms it
fires when selecting schemes in the multiplayer setup dialog.
8 new Ghidra labels: scheme functions + CFile Read/Write/Open/Close.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
docs: frontend state machine RE + 47 Ghidra labels
Document the complete frontend navigation state machine:
- Main navigation loop at 0x4E6440 (CWinApp::Run, 19KB)
- g_CurrentScreen (0x6B3504) drives screen dispatch
- 20 dialog constructors mapped to screen IDs
- Bitmap font system: 4 font sizes, glyph renderer, textbox API
- Display wrapper at 0x79D6D4 with 6 backend variants
47 new Ghidra labels applied (functions, globals, dialog ctors).
38 new address.rs constants: dialog ctors, font system, display globals.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add openwa-wormkit DLL with FrontendChangeScreen replacement
New crate openwa-wormkit (wkOpenWA.dll) that replaces WA.exe functions
with Rust reimplementations, starting with FrontendChangeScreen (0x447A20).
- Naked ASM trampoline captures ESI (implicit dialog this pointer)
- Full reimplementation of both code paths (init + normal EndDialog)
- ScreenId enum expanded to 35 variants with correct semantics:
screen IDs (main-loop dispatch targets) vs result codes (sub-dialog
exit values like offline/online pairs 35/36 and 37/38)
- New globals: g_CurrentScreen (0x6B3504), g_SkipToMainMenu, etc.
- New addresses: Frontend__MainNavigationLoop, DoModal wrapper, etc.
- Validator: removed FrontendChangeScreen hook (conflicts with wormkit),
silenced constructor hooks to reduce log noise
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix(hooks): correct vtable hook parameter counts from RET analysis
ProcessFrame: RET 0x4 = 1 stack param (flags), was 0 — stack corruption
HandleMessage: RET 0x10 = 4 stack params (sender, msg_type, size, data), was 2
These wrong parameter counts caused stack corruption on every virtual
call, crashing when returning from a match to the main menu.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix(types): correct CTask struct layout from Ghidra decompilation
Expanded opaque padding into named fields based on cross-referencing
Ghidra decompilation of CTask::Constructor (0x5625A0) and its helper
(0x562520) with wkJellyWorm CTask.h. Key findings:
- 3rd constructor param is DDGame pointer (stored at 0x2C), not class_type
- Children list fields (0x08-0x18) now individually named
- shared_data (0x24) and owns_shared_data (0x28) identified
- 82/82 static validation checks pass (up from 78)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat(validator): add function hooking via MinHook and vtable swapping
Two-layer hooking system replaces the failed retour-rs approach:
- VTable hooks: swap function pointers in .rdata for CTask virtual methods
- MinHook inline hooks: FrontendChangeScreen, CTask::Constructor,
CGameTask::Constructor — handles SEH prologues correctly
Also adds .cargo/config.toml to default target to i686-pc-windows-msvc.
Tested in-game: all hooks fire correctly, game runs normally.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: add offline test harness that loads WA.exe and calls its functions
Loads WA.exe into a 32-bit test process via LoadLibraryExA with
DONT_RESOLVE_DLL_REFERENCES, patches the IAT (445 imports), initializes
the statically-linked MSVC CRT heap, and successfully calls WA.exe
functions including malloc and CTask::Constructor.
9 tests: PE loading, vtable validation, prologue checks, IAT patching,
malloc wrapper call, and CTask constructor call with SEH support.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add ASLR rebasing (GetModuleHandleA) — WA.exe loads at 0x90000, not 0x400000
- Replace retour constructor hooks with global pointer polling (10s delay)
Hooks crashed due to retour trampoline splitting SEH prologues
- Fix DDGameWrapper constructor: __stdcall with 7 params, not __thiscall
Confirmed via RET 0x1c and stack parameter access patterns
- Fix CTask constructor: __stdcall with 3 params, not __thiscall
Confirmed via RET 0xc
- Add G_GAME_SESSION (0x7A0884) global for polling DDGameWrapper at runtime
- Fix DDGameWrapper struct: +0x4C0 is not GfxHandler, +0x4D4 is sound ptr
- Remove retour dependency (no longer needed, builds on stable Rust)
- Add missing prologue bytes: 0x64 (FS: SEH), 0x85 (test), 0x8D (lea)
Results: 78/78 static + 6/6 deferred = 84/84 all passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat(validator): add address, struct offset, and constructor hook validation
Map the MFC CDialog-based menu system from 65 decompiled call sites.
Add ScreenId enum with 18 screen IDs (main menu through lobby).
Name 21 frontend/lobby functions and 4 global variables in Ghidra.
Add 25 new addresses to address.rs (14 frontend + 7 lobby + 4 globals).
Document screen transition architecture in frontend-screens.md.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Correct DDGame field offsets from constructor decompilation
Major fixes from analyzing the full 884-line DDGame__Constructor:
- task_ptrs were at wrong offset (0x11B0 vs correct 0x46C-0x488)
- Map 0x000-0x510 range densely: arrows, sprite regions, collision
- DDGameWrapper is ~28KB+ (not 0x500), accesses DWORD 0x1BBA
- Add 5 new function addresses: SpriteRegion ctor, GfxHandler/Dir ops
- Rename 5 functions in Ghidra (SpriteRegion__Constructor, etc.)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add DDGame engine architecture structs and subsystem types
Define DDGame (0x98B8), DDGameWrapper, PCLandscape, DSSound, and
OpenGLState repr(C) structs with compile-time size assertions.
Add 9 subsystem vtable addresses to address.rs. Document the
engine initialization chain and update memory map with DDGame layout.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Initial openwa-types crate: enums, structs, and RE addresses
Bootstrap the Rust type foundation for WA 3.8.1 reverse engineering:
- Cargo workspace with openwa-types crate
- Enums translated from wkJellyWorm: ClassType (34), TaskMessage (83+),
Weapon (71), SoundId (126), SpriteId (696)
- Fixed-point math newtype (16.16 format, 0x10000 = 1.0)
- CTask and CGameTask struct stubs with compile-time size assertions
- 80+ known addresses: vtables, constructors, gameplay, rendering, sound
- RE documentation: task hierarchy, vtable layouts, memory map
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>