paavohtl Claude Opus 4.6 (1M context) commited on
Commit
254b6b5
Β·
1 Parent(s): e565bdc

docs: update CLAUDE.md for weapon porting, CTask vtable, baseline rules

Browse files

- Add baseline immutability rule (never delete *_expected.log)
- Fix CTask vtable: 7 slots, ProcessFrame at slot 6
- Add noalias caution for bind_! methods vs raw-pointer alternatives
- Add weapon.rs and worm.rs to key files list

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

Files changed (1) hide show
  1. CLAUDE.md +7 -1
CLAUDE.md CHANGED
@@ -52,6 +52,8 @@ The `openwa-test-runner` crate (`openwa-test` binary) runs all replay tests auto
52
 
53
  Each test runs WA.exe in headless `/getlog` mode (pure CPU simulation, no rendering) and compares the output log byte-for-byte against an expected baseline. Tests are isolated for concurrent execution via per-PID event names, log paths, and landscape temp files (`CreateFileA` hook).
54
 
 
 
55
  Key paths:
56
  - Replay files + expected logs: `testdata/replays/*.WAgame` + `*_expected.log`
57
  - Per-run output: `testdata/runs/<timestamp>/` (gitignored)
@@ -200,9 +202,11 @@ Currently dormant β€” no hooks wired up. Activate by adding calls in `game_sessi
200
  - `crates/openwa-core/src/wa_call.rs` β€” Helpers for calling WA functions (thiscall, stdcall wrappers)
201
  - `crates/openwa-core/src/rebase.rs` β€” ASLR delta computation
202
  - `crates/openwa-core/src/wa/` β€” Typed WA function wrappers (MFC, frontend, registry, DDGame)
203
- - `crates/openwa-core/src/task/base.rs` β€” CTask<V>, CTaskVtable, Task trait, SharedDataTable, broadcast_message
 
204
  - `crates/openwa-core/src/engine/team_arena.rs` β€” TeamArenaState, WormEntry, TeamHeader, TeamArenaRef
205
  - `crates/openwa-core/src/engine/ddgame_constructor.rs` β€” DDGame constructor (create_ddgame, init_graphics_and_resources)
 
206
  - `crates/openwa-wormkit/src/replacements/` β€” Function replacements (one file per subsystem)
207
  - `crates/openwa-wormkit/src/replacements/task/` β€” Vtable method replacements (cloud, filter, ...)
208
  - `docs/re-notes/` β€” Reverse engineering documentation (task hierarchy, memory map, frontend screens)
@@ -324,7 +328,9 @@ vtable_replace!(DSSoundVtable, va::DS_SOUND_VTABLE, {
324
  - **`Task` trait**: Provides `task()`, `ddgame()`, `as_task_ptr()`, `as_task_ptr_mut()`, and `broadcast_message()` on all CTask subclasses. Eliminates `.base.base` chains. Implemented for all task types in `task/mod.rs`.
325
  - **`broadcast_message()`**: Pure Rust port of CTask::HandleMessage (0x562F30). Iterates the sparse children array and calls each child's vtable[2]. Uses `read_volatile` for `children_watermark` and `children_data` β€” **required** because LLVM caches these reads across virtual dispatch calls even through `*mut`.
326
  - **Typed vtable structs via `#[vtable(...)]`**: Use the attribute macro to define vtable structs with `fn(this: *mut T, ...)` shorthand and `#[slot(N)]` for sparse layouts. The macro handles `unsafe extern "thiscall"`, gap-filling, registry metadata, generates `bind_!` calling wrappers, and implements the `Vtable` marker trait. See the `#[vtable(...)]` section above.
 
327
  - **`bind_XxxVtable!`**: Generated by `#[vtable(...)]`, creates `&mut self` method wrappers on the class struct. Supports dotted field paths for inherited vtables: `bind_CTaskTeamVTable!(CTaskTeam, base.vtable)`.
 
328
  - **`vcall!` macro**: Still available for raw-pointer vtable dispatch without bind wrappers. Expands to `((*(*obj).vtable).method)(obj, args...)`.
329
 
330
  ## FFI Style
 
52
 
53
  Each test runs WA.exe in headless `/getlog` mode (pure CPU simulation, no rendering) and compares the output log byte-for-byte against an expected baseline. Tests are isolated for concurrent execution via per-PID event names, log paths, and landscape temp files (`CreateFileA` hook).
54
 
55
+ **IMPORTANT:** The `*_expected.log` baselines are ground truth generated from unmodified WA.exe. They must NEVER be deleted or regenerated. If a test fails, the Rust code is wrong.
56
+
57
  Key paths:
58
  - Replay files + expected logs: `testdata/replays/*.WAgame` + `*_expected.log`
59
  - Per-run output: `testdata/runs/<timestamp>/` (gitignored)
 
202
  - `crates/openwa-core/src/wa_call.rs` β€” Helpers for calling WA functions (thiscall, stdcall wrappers)
203
  - `crates/openwa-core/src/rebase.rs` β€” ASLR delta computation
204
  - `crates/openwa-core/src/wa/` β€” Typed WA function wrappers (MFC, frontend, registry, DDGame)
205
+ - `crates/openwa-core/src/task/base.rs` β€” CTask<V>, CTaskVtable (7 slots), Task trait, SharedDataTable, broadcast_message
206
+ - `crates/openwa-core/src/task/worm.rs` β€” CTaskWorm, CTaskWormVTable (20 slots), WormState enum
207
  - `crates/openwa-core/src/engine/team_arena.rs` β€” TeamArenaState, WormEntry, TeamHeader, TeamArenaRef
208
  - `crates/openwa-core/src/engine/ddgame_constructor.rs` β€” DDGame constructor (create_ddgame, init_graphics_and_resources)
209
+ - `crates/openwa-wormkit/src/replacements/weapon.rs` β€” Weapon fire dispatch (mostly pure Rust, 20+ subtypes ported)
210
  - `crates/openwa-wormkit/src/replacements/` β€” Function replacements (one file per subsystem)
211
  - `crates/openwa-wormkit/src/replacements/task/` β€” Vtable method replacements (cloud, filter, ...)
212
  - `docs/re-notes/` β€” Reverse engineering documentation (task hierarchy, memory map, frontend screens)
 
328
  - **`Task` trait**: Provides `task()`, `ddgame()`, `as_task_ptr()`, `as_task_ptr_mut()`, and `broadcast_message()` on all CTask subclasses. Eliminates `.base.base` chains. Implemented for all task types in `task/mod.rs`.
329
  - **`broadcast_message()`**: Pure Rust port of CTask::HandleMessage (0x562F30). Iterates the sparse children array and calls each child's vtable[2]. Uses `read_volatile` for `children_watermark` and `children_data` β€” **required** because LLVM caches these reads across virtual dispatch calls even through `*mut`.
330
  - **Typed vtable structs via `#[vtable(...)]`**: Use the attribute macro to define vtable structs with `fn(this: *mut T, ...)` shorthand and `#[slot(N)]` for sparse layouts. The macro handles `unsafe extern "thiscall"`, gap-filling, registry metadata, generates `bind_!` calling wrappers, and implements the `Vtable` marker trait. See the `#[vtable(...)]` section above.
331
+ - **CTask base vtable**: 7 slots (not 8). ProcessFrame is slot 6. Slots 7+ are class-specific extensions. CGameTask adds no virtuals.
332
  - **`bind_XxxVtable!`**: Generated by `#[vtable(...)]`, creates `&mut self` method wrappers on the class struct. Supports dotted field paths for inherited vtables: `bind_CTaskTeamVTable!(CTaskTeam, base.vtable)`.
333
+ - **Noalias caution**: `bind_!` methods use `&mut self`, which gives LLVM noalias guarantees. In weapon dispatch and other code that mixes Rust and WA function calls through bridges, prefer raw-pointer associated functions (e.g., `CTaskWorm::set_state_raw(ptr, state)`) to avoid potential miscompilation from LLVM caching reads across bridge calls.
334
  - **`vcall!` macro**: Still available for raw-pointer vtable dispatch without bind wrappers. Expands to `((*(*obj).vtable).method)(obj, args...)`.
335
 
336
  ## FFI Style