fix: correct WeaponTable layout — no header, add entry fields
Browse filesInitWeaponTable analysis revealed the weapon table is a flat array of
71 × 0x1D0 = 0x80B0 bytes with NO 16-byte header. The previous struct
had a phantom _header that made address math accidentally correct but
mislabeled the field being checked.
WeaponEntry now has proper fields:
- panel_state (+0x08, init 0xFFFFFFFF)
- defined (+0x10, checked by CheckWeaponAvail)
- availability (+0x24, init 0xFFFFFFFF, then 0/1 per weapon)
- enabled (+0x28, init 1)
check_weapon_avail now reads `entry.defined` instead of misnamed
`entry.name1`. Updated weapon-system.md to match.
Verified: headless PASS (byte-identical), headful 133+3 PASS / 0 FAIL.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crates/openwa-core/src/engine/game_state_init.rs
CHANGED
|
@@ -385,11 +385,11 @@ pub unsafe fn check_weapon_avail(ddgame: *mut DDGame, weapon_index: u32) -> i32
|
|
| 385 |
_ => {}
|
| 386 |
}
|
| 387 |
|
| 388 |
-
// Step 2: Branch on weapon
|
| 389 |
let weapon_table = (*ddgame).weapon_table;
|
| 390 |
-
let
|
| 391 |
|
| 392 |
-
if (*ddgame).level_width_raw == 0 || !
|
| 393 |
// Main path: check super weapon flag
|
| 394 |
let super_result = is_super_weapon(weapon_index, (*ddgame).version_flag_3);
|
| 395 |
if super_result != 0 && (*gi).super_weapon_allowed == 0 {
|
|
|
|
| 385 |
_ => {}
|
| 386 |
}
|
| 387 |
|
| 388 |
+
// Step 2: Branch on weapon defined flag (nonzero = weapon exists in table).
|
| 389 |
let weapon_table = (*ddgame).weapon_table;
|
| 390 |
+
let defined = (*weapon_table).entries[weapon_index as usize].defined;
|
| 391 |
|
| 392 |
+
if (*ddgame).level_width_raw == 0 || defined != 0 {
|
| 393 |
// Main path: check super weapon flag
|
| 394 |
let super_result = is_super_weapon(weapon_index, (*ddgame).version_flag_3);
|
| 395 |
if super_result != 0 && (*gi).super_weapon_allowed == 0 {
|
crates/openwa-core/src/game/weapon.rs
CHANGED
|
@@ -104,35 +104,40 @@ impl TryFrom<u32> for Weapon {
|
|
| 104 |
/// 71 standard entries (indices 0..70), matching the `Weapon` enum.
|
| 105 |
/// Source: wkJellyWorm/src/CustomWeapons.h (WeaponStruct).
|
| 106 |
///
|
| 107 |
-
///
|
| 108 |
-
/// entire entries via memcpy when creating custom weapons.
|
| 109 |
#[repr(C)]
|
| 110 |
pub struct WeaponEntry {
|
| 111 |
/// +0x00: Pointer to primary weapon name string.
|
| 112 |
-
/// Non-null means the weapon is defined/available.
|
| 113 |
pub name1: *const c_char,
|
| 114 |
/// +0x04: Pointer to secondary weapon name string.
|
| 115 |
pub name2: *const c_char,
|
| 116 |
-
/// +0x08:
|
| 117 |
-
pub
|
| 118 |
/// +0x0C: Unknown.
|
| 119 |
pub _unknown_0c: i32,
|
| 120 |
-
/// +0x10
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
}
|
| 123 |
const _: () = assert!(core::mem::size_of::<WeaponEntry>() == 0x1D0);
|
| 124 |
|
| 125 |
-
/// Weapon table
|
| 126 |
///
|
| 127 |
-
///
|
| 128 |
-
///
|
| 129 |
#[repr(C)]
|
| 130 |
pub struct WeaponTable {
|
| 131 |
-
///
|
| 132 |
-
pub _header: [u8; 0x10],
|
| 133 |
-
/// +0x10: Weapon entries array (71 standard weapons).
|
| 134 |
pub entries: [WeaponEntry; 71],
|
| 135 |
}
|
| 136 |
-
const _: () = assert!(
|
| 137 |
-
core::mem::size_of::<WeaponTable>() == 0x10 + 71 * 0x1D0
|
| 138 |
-
);
|
|
|
|
| 104 |
/// 71 standard entries (indices 0..70), matching the `Weapon` enum.
|
| 105 |
/// Source: wkJellyWorm/src/CustomWeapons.h (WeaponStruct).
|
| 106 |
///
|
| 107 |
+
/// Known fields from wkJellyWorm and InitWeaponTable (0x53CAB0) analysis.
|
| 108 |
+
/// wkJellyWorm copies entire entries via memcpy when creating custom weapons.
|
| 109 |
#[repr(C)]
|
| 110 |
pub struct WeaponEntry {
|
| 111 |
/// +0x00: Pointer to primary weapon name string.
|
|
|
|
| 112 |
pub name1: *const c_char,
|
| 113 |
/// +0x04: Pointer to secondary weapon name string.
|
| 114 |
pub name2: *const c_char,
|
| 115 |
+
/// +0x08: Panel state (init: 0xFFFFFFFF). wkJellyWorm calls this `panelRow`.
|
| 116 |
+
pub panel_state: i32,
|
| 117 |
/// +0x0C: Unknown.
|
| 118 |
pub _unknown_0c: i32,
|
| 119 |
+
/// +0x10: Weapon defined flag. Nonzero = weapon exists in table.
|
| 120 |
+
/// Checked by DDGame__CheckWeaponAvail to determine if weapon is valid.
|
| 121 |
+
pub defined: i32,
|
| 122 |
+
/// +0x14-0x23: Unknown.
|
| 123 |
+
pub _unknown_14: [u8; 0x24 - 0x14],
|
| 124 |
+
/// +0x24: Availability flag. Init: 0xFFFFFFFF, then set to 0 (unavailable)
|
| 125 |
+
/// or 1 (available) per weapon. Weapon::None, SkipGo, Surrender default to 0.
|
| 126 |
+
pub availability: i32,
|
| 127 |
+
/// +0x28: Enabled flag (init: 1).
|
| 128 |
+
pub enabled: i32,
|
| 129 |
+
/// +0x2C-0x1CF: Unknown fields.
|
| 130 |
+
pub _unknown_2c: [u8; 0x1D0 - 0x2C],
|
| 131 |
}
|
| 132 |
const _: () = assert!(core::mem::size_of::<WeaponEntry>() == 0x1D0);
|
| 133 |
|
| 134 |
+
/// Weapon table — flat array of 71 entries, no header.
|
| 135 |
///
|
| 136 |
+
/// Allocated by `InitWeaponTable` (0x53CAB0), stored at DDGame+0x510.
|
| 137 |
+
/// Total size: 71 × 0x1D0 = 0x80B0 bytes.
|
| 138 |
#[repr(C)]
|
| 139 |
pub struct WeaponTable {
|
| 140 |
+
/// Weapon entries array (71 standard weapons, indices 0..70).
|
|
|
|
|
|
|
| 141 |
pub entries: [WeaponEntry; 71],
|
| 142 |
}
|
| 143 |
+
const _: () = assert!(core::mem::size_of::<WeaponTable>() == 71 * 0x1D0);
|
|
|
|
|
|
docs/re-notes/weapon-system.md
CHANGED
|
@@ -63,27 +63,31 @@ Allocated by `InitWeaponTable` (0x53CAB0, stdcall(wrapper), RET 0x4). Called onc
|
|
| 63 |
during `CTaskGameState__vmethod_7` at game start.
|
| 64 |
|
| 65 |
```
|
| 66 |
-
+0x00 [
|
| 67 |
-
|
| 68 |
-
Total: 0x10 + 71 × 0x1D0 = 0x133E0 bytes
|
| 69 |
```
|
| 70 |
|
| 71 |
### WeaponEntry (0x1D0 = 464 bytes per entry)
|
| 72 |
|
| 73 |
-
Source: `wkJellyWorm/src/CustomWeapons.h` (WeaponStruct).
|
| 74 |
|
| 75 |
```
|
| 76 |
-
+0x00 *const c_char name1
|
| 77 |
-
+0x04 *const c_char name2
|
| 78 |
-
+0x08 i32
|
| 79 |
-
+0x0C i32 unknown_0c
|
| 80 |
-
+0x10
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
```
|
| 82 |
|
| 83 |
-
**InitWeaponTable
|
| 84 |
-
- +0x08 = 0xFFFFFFFF (
|
| 85 |
-
- +0x24 = 0xFFFFFFFF (availability
|
| 86 |
- +0x28 = 1 (enabled)
|
|
|
|
| 87 |
|
| 88 |
**Rust types:** `WeaponEntry`, `WeaponTable` in `openwa-core/src/game/weapon.rs`.
|
| 89 |
|
|
|
|
| 63 |
during `CTaskGameState__vmethod_7` at game start.
|
| 64 |
|
| 65 |
```
|
| 66 |
+
+0x00 [WeaponEntry; 71] entries Standard weapons (0..70)
|
| 67 |
+
Total: 71 × 0x1D0 = 0x80B0 bytes (no header)
|
|
|
|
| 68 |
```
|
| 69 |
|
| 70 |
### WeaponEntry (0x1D0 = 464 bytes per entry)
|
| 71 |
|
| 72 |
+
Source: `wkJellyWorm/src/CustomWeapons.h` (WeaponStruct) + InitWeaponTable analysis.
|
| 73 |
|
| 74 |
```
|
| 75 |
+
+0x00 *const c_char name1 Primary weapon name string
|
| 76 |
+
+0x04 *const c_char name2 Secondary weapon name string
|
| 77 |
+
+0x08 i32 panel_state Panel state (init: 0xFFFFFFFF). wkJellyWorm: panelRow
|
| 78 |
+
+0x0C i32 unknown_0c Unknown
|
| 79 |
+
+0x10 i32 defined Nonzero = weapon exists. Checked by CheckWeaponAvail.
|
| 80 |
+
+0x14 [u8; 0x10] unknown_14 Unknown
|
| 81 |
+
+0x24 i32 availability Init: 0xFFFFFFFF, then 0 or 1. None/SkipGo/Surrender = 0.
|
| 82 |
+
+0x28 i32 enabled Init: 1
|
| 83 |
+
+0x2C [u8; 0x1A4] unknown_2c Remaining fields (opaque)
|
| 84 |
```
|
| 85 |
|
| 86 |
+
**InitWeaponTable per-entry initialization:**
|
| 87 |
+
- +0x08 = 0xFFFFFFFF (panel_state)
|
| 88 |
+
- +0x24 = 0xFFFFFFFF (availability, then overwritten per-weapon)
|
| 89 |
- +0x28 = 1 (enabled)
|
| 90 |
+
- Weapon 0 (None), 57 (SkipGo), 58 (Surrender): availability forced to 0
|
| 91 |
|
| 92 |
**Rust types:** `WeaponEntry`, `WeaponTable` in `openwa-core/src/game/weapon.rs`.
|
| 93 |
|