refactor: replace ~50 magic addresses in replay.rs with named constants
Browse filesAdd 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>
crates/openwa-core/src/address.rs
CHANGED
|
@@ -820,6 +820,18 @@ pub mod va {
|
|
| 820 |
pub const WA_FREE: u32 = 0x005D_0D2B;
|
| 821 |
/// WA's CRT _fopen — cdecl(path, mode) → FILE*.
|
| 822 |
pub const WA_FOPEN: u32 = 0x005D_3271;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 823 |
|
| 824 |
// === Bitmap font system ===
|
| 825 |
|
|
@@ -905,6 +917,107 @@ pub mod va {
|
|
| 905 |
pub const G_SAVED_RANDOM_SEED: u32 = 0x0088_ABAC;
|
| 906 |
/// Replay filename buffer.
|
| 907 |
pub const G_REPLAY_FILENAME: u32 = 0x0088_AF58;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 908 |
|
| 909 |
// === Configuration globals (for GameInfo__LoadOptions) ===
|
| 910 |
|
|
|
|
| 820 |
pub const WA_FREE: u32 = 0x005D_0D2B;
|
| 821 |
/// WA's CRT _fopen — cdecl(path, mode) → FILE*.
|
| 822 |
pub const WA_FOPEN: u32 = 0x005D_3271;
|
| 823 |
+
/// WA's CRT _fileno — cdecl(FILE*) → fd.
|
| 824 |
+
pub const WA_FILENO: u32 = 0x005D_5155;
|
| 825 |
+
/// WA's CRT _get_osfhandle — cdecl(fd) → HANDLE.
|
| 826 |
+
pub const WA_GET_OSFHANDLE: u32 = 0x005D_7273;
|
| 827 |
+
/// WA's CRT srand — cdecl(seed).
|
| 828 |
+
pub const WA_SRAND: u32 = 0x005D_293E;
|
| 829 |
+
/// WA's CRT rand — cdecl() → i32.
|
| 830 |
+
pub const WA_RAND: u32 = 0x005D_294B;
|
| 831 |
+
/// WA's CRT _gmtime64 — cdecl(&time_t) → *const tm.
|
| 832 |
+
pub const WA_GMTIME64: u32 = 0x005D_34C0;
|
| 833 |
+
/// WA's CRT malloc (raw, not the wrapper at WA_MALLOC) — cdecl(size) → *mut u8.
|
| 834 |
+
pub const WA_CRT_MALLOC: u32 = 0x005C_0AB8;
|
| 835 |
|
| 836 |
// === Bitmap font system ===
|
| 837 |
|
|
|
|
| 917 |
pub const G_SAVED_RANDOM_SEED: u32 = 0x0088_ABAC;
|
| 918 |
/// Replay filename buffer.
|
| 919 |
pub const G_REPLAY_FILENAME: u32 = 0x0088_AF58;
|
| 920 |
+
/// Game data directory path (null-terminated string).
|
| 921 |
+
pub const G_DATA_DIR: u32 = 0x0088_E078;
|
| 922 |
+
/// WA log file FILE* pointer (for /getlog output).
|
| 923 |
+
pub const G_LOG_FILE_PTR: u32 = 0x0088_C370;
|
| 924 |
+
/// Observer array base (used by RegisterObserver, replay parsing).
|
| 925 |
+
pub const G_OBSERVER_ARRAY: u32 = 0x0088_C35C;
|
| 926 |
+
/// Observer count (number of registered observers).
|
| 927 |
+
pub const G_OBSERVER_COUNT: u32 = 0x0088_AF4C;
|
| 928 |
+
/// Recording timestamp availability flag (nonzero = timestamp present).
|
| 929 |
+
pub const G_RECORDING_TIMESTAMP_FLAG: u32 = 0x0088_C36C;
|
| 930 |
+
/// Replay version flag A (version > 7).
|
| 931 |
+
pub const G_REPLAY_VER_FLAG_A: u32 = 0x0088_AF42;
|
| 932 |
+
/// Replay version flag B (version > 7).
|
| 933 |
+
pub const G_REPLAY_VER_FLAG_B: u32 = 0x0088_AF43;
|
| 934 |
+
/// Game mode flag (from replay version >= 12).
|
| 935 |
+
pub const G_REPLAY_GAME_MODE: u32 = 0x0088_AF44;
|
| 936 |
+
/// Scheme header byte (signed: >= 0 = built-in scheme).
|
| 937 |
+
pub const G_SCHEME_HEADER: u32 = 0x0088_DAD4;
|
| 938 |
+
/// Scheme loading destination (base address for scheme data).
|
| 939 |
+
pub const G_SCHEME_DEST: u32 = 0x0088_DACC;
|
| 940 |
+
/// Scheme data copy destination (raw scheme bytes from stream).
|
| 941 |
+
pub const G_SCHEME_DATA: u32 = 0x0088_DAE0;
|
| 942 |
+
/// Scheme extended options buffer (0x4C bytes, cleared for v1/v2 fallback).
|
| 943 |
+
pub const G_SCHEME_OPTIONS: u32 = 0x0088_DBB8;
|
| 944 |
+
/// Scheme v3 extended data destination (0x6E bytes).
|
| 945 |
+
pub const G_SCHEME_V3_DATA: u32 = 0x0088_DC04;
|
| 946 |
+
/// Host player index (low byte = host, rest masked).
|
| 947 |
+
pub const G_HOST_PLAYER: u32 = 0x0087_79E0;
|
| 948 |
+
/// Player data array base (13 entries, stride 0x78).
|
| 949 |
+
/// Player[0].name = G_PLAYER_ARRAY, Player[0].flag = G_PLAYER_ARRAY + 0x74.
|
| 950 |
+
pub const G_PLAYER_ARRAY: u32 = 0x0087_79E4;
|
| 951 |
+
/// Player count.
|
| 952 |
+
pub const G_PLAYER_COUNT: u32 = 0x0087_D0DE;
|
| 953 |
+
/// Team data array base (6 entries, stride 0xD7B).
|
| 954 |
+
pub const G_TEAM_DATA: u32 = 0x0087_7FFC;
|
| 955 |
+
/// Team count (number of active teams).
|
| 956 |
+
pub const G_TEAM_COUNT: u32 = 0x0087_D0E0;
|
| 957 |
+
/// Replay name buffer (0x29 bytes).
|
| 958 |
+
pub const G_REPLAY_NAME: u32 = 0x0087_D0E1;
|
| 959 |
+
/// Map byte 1 (written during replay parsing).
|
| 960 |
+
pub const G_MAP_BYTE_1: u32 = 0x0087_250C;
|
| 961 |
+
/// Map byte 2 (written during replay parsing).
|
| 962 |
+
pub const G_MAP_BYTE_2: u32 = 0x0087_2508;
|
| 963 |
+
/// Map seed (u16 stored as u32).
|
| 964 |
+
pub const G_MAP_SEED: u32 = 0x0087_D430;
|
| 965 |
+
/// Worm names base (8 worms × teams, stride 0x11 per name).
|
| 966 |
+
pub const G_WORM_NAMES: u32 = 0x0087_8097;
|
| 967 |
+
|
| 968 |
+
// --- Replay team data field offsets from G_TEAM_DATA + team_idx * 0xD7B ---
|
| 969 |
+
/// Team flag (nonzero = team present). Offset 0x124 from per-team base.
|
| 970 |
+
pub const G_TEAM_FLAG_OFF: u32 = 0x0087_8120;
|
| 971 |
+
/// Worm count (unvalidated). Offset 0x96 from per-team base.
|
| 972 |
+
pub const G_TEAM_WORM_COUNT_RAW_OFF: u32 = 0x0087_8092;
|
| 973 |
+
/// Team name (0x41 bytes). Offset 0x14 from per-team base.
|
| 974 |
+
pub const G_TEAM_NAME_OFF: u32 = 0x0087_8010;
|
| 975 |
+
/// Team extra byte (if obs_count > 13). Offset 0x97 from per-team base.
|
| 976 |
+
pub const G_TEAM_EXTRA_OFF: u32 = 0x0087_8093;
|
| 977 |
+
/// Config name (0x41 bytes). Offset 0x55 from per-team base.
|
| 978 |
+
pub const G_TEAM_CONFIG_NAME_OFF: u32 = 0x0087_8051;
|
| 979 |
+
/// Worm count (validated 1-8). Offset 0x98 from per-team base.
|
| 980 |
+
pub const G_TEAM_WORM_COUNT_OFF: u32 = 0x0087_8094;
|
| 981 |
+
/// Team color. Offset 0x99 from per-team base.
|
| 982 |
+
pub const G_TEAM_COLOR_OFF: u32 = 0x0087_8095;
|
| 983 |
+
/// Team flag2. Offset 0x9A from per-team base.
|
| 984 |
+
pub const G_TEAM_FLAG2_OFF: u32 = 0x0087_8096;
|
| 985 |
+
/// Team grave. Offset 0x123 from per-team base.
|
| 986 |
+
pub const G_TEAM_GRAVE_OFF: u32 = 0x0087_811F;
|
| 987 |
+
/// Team soundbank. Offset 0x125 from per-team base.
|
| 988 |
+
pub const G_TEAM_SOUNDBANK_OFF: u32 = 0x0087_8121;
|
| 989 |
+
/// Team soundbank extra. Offset 0x126 from per-team base.
|
| 990 |
+
pub const G_TEAM_SOUNDBANK2_OFF: u32 = 0x0087_8122;
|
| 991 |
+
/// Team weapon data (0xC54 bytes). Offset 0x127 from per-team base.
|
| 992 |
+
pub const G_TEAM_WEAPONS_OFF: u32 = 0x0087_8123;
|
| 993 |
+
|
| 994 |
+
// --- Replay function addresses ---
|
| 995 |
+
/// Load string resource by ID — stdcall(id) → *const u8. RET 0x4.
|
| 996 |
+
pub const WA_LOAD_STRING: u32 = 0x0059_3180;
|
| 997 |
+
/// Load built-in scheme by ID — stdcall(dest, scheme_id). RET 0x8.
|
| 998 |
+
pub const SCHEME_LOAD_BUILTIN: u32 = 0x004D_4840;
|
| 999 |
+
/// Validate extended scheme options — cdecl() → i32.
|
| 1000 |
+
pub const SCHEME_VALIDATE_EXTENDED: u32 = 0x004D_5110;
|
| 1001 |
+
/// Process replay state — stdcall(state). Large function (1032 lines).
|
| 1002 |
+
pub const REPLAY_PROCESS_STATE: u32 = 0x0045_D640;
|
| 1003 |
+
/// Cleanup observer array — usercall(ESI=observer_array). Plain RET.
|
| 1004 |
+
pub const REPLAY_CLEANUP_OBSERVERS: u32 = 0x0053_EE00;
|
| 1005 |
+
/// Map class constructor — stdcall(alloc, flags) → *mut MapClass.
|
| 1006 |
+
pub const MAP_CLASS_CONSTRUCTOR: u32 = 0x0044_7E80;
|
| 1007 |
+
/// Map class load — stdcall(map_obj, path, flags) → i32.
|
| 1008 |
+
pub const MAP_CLASS_LOAD: u32 = 0x0044_A9A0;
|
| 1009 |
+
/// Copy map info to game state — usercall(ESI=map_obj). Plain RET.
|
| 1010 |
+
pub const MAP_COPY_INFO: u32 = 0x0044_9B60;
|
| 1011 |
+
|
| 1012 |
+
// --- String literals ---
|
| 1013 |
+
/// Version string table (array of pointers to version strings).
|
| 1014 |
+
pub const VERSION_STRING_TABLE: u32 = 0x006A_B480;
|
| 1015 |
+
/// Current WA version byte index (indexes into version suffix table).
|
| 1016 |
+
pub const G_VERSION_BYTE: u32 = 0x0069_7702;
|
| 1017 |
+
/// "3.8.1" literal string.
|
| 1018 |
+
pub const STR_VERSION_381: u32 = 0x0064_1C60;
|
| 1019 |
+
/// Version suffix table (array of pointers, indexed by version byte).
|
| 1020 |
+
pub const VERSION_SUFFIX_TABLE: u32 = 0x0069_9814;
|
| 1021 |
|
| 1022 |
// === Configuration globals (for GameInfo__LoadOptions) ===
|
| 1023 |
|
crates/openwa-wormkit/src/replacements/replay.rs
CHANGED
|
@@ -32,9 +32,9 @@ type FILE = c_void;
|
|
| 32 |
/// Convert a WA CRT FILE* to a borrowed Rust File (ManuallyDrop — we don't own it).
|
| 33 |
unsafe fn wa_file_to_rust(file: *mut FILE) -> Option<ManuallyDrop<File>> {
|
| 34 |
let fileno: unsafe extern "cdecl" fn(*mut FILE) -> i32 =
|
| 35 |
-
core::mem::transmute(rb(
|
| 36 |
let get_osfhandle: unsafe extern "cdecl" fn(i32) -> isize =
|
| 37 |
-
core::mem::transmute(rb(
|
| 38 |
|
| 39 |
let fd = fileno(file);
|
| 40 |
if fd < 0 { return None; }
|
|
@@ -46,7 +46,7 @@ unsafe fn wa_file_to_rust(file: *mut FILE) -> Option<ManuallyDrop<File>> {
|
|
| 46 |
/// Load a WA string resource by ID (stdcall). Returns null-terminated C string.
|
| 47 |
unsafe fn wa_load_string(id: u32) -> *const u8 {
|
| 48 |
let f: unsafe extern "stdcall" fn(u32) -> *const u8 =
|
| 49 |
-
core::mem::transmute(rb(
|
| 50 |
f(id)
|
| 51 |
}
|
| 52 |
|
|
@@ -94,7 +94,7 @@ unsafe fn replay_loader_play(state: u32) -> Result<(), ReplayError> {
|
|
| 94 |
// Open replay file using Rust's std::fs::File
|
| 95 |
let replay_path = {
|
| 96 |
// Build path: game data dir + replay filename from state+0xDB60
|
| 97 |
-
let data_dir = CStr::from_ptr(rb(
|
| 98 |
let file_name = CStr::from_ptr(s.add(0xDB60) as *const i8);
|
| 99 |
let dir = data_dir.to_str().unwrap_or(".");
|
| 100 |
let name = file_name.to_str().unwrap_or("");
|
|
@@ -183,7 +183,7 @@ unsafe fn replay_loader_play(state: u32) -> Result<(), ReplayError> {
|
|
| 183 |
match result {
|
| 184 |
Ok(()) => {
|
| 185 |
call_usercall_eax(state, rb(va::REPLAY_PROCESS_FLAGS));
|
| 186 |
-
let wa_log_file = *(rb(
|
| 187 |
if !wa_log_file.is_null() {
|
| 188 |
if let Some(mut log_file) = wa_file_to_rust(wa_log_file) {
|
| 189 |
write_replay_log(state, &mut *log_file)?;
|
|
@@ -225,8 +225,8 @@ unsafe fn parse_and_write_v2plus(
|
|
| 225 |
|
| 226 |
// ── Sub-format flags ─────────────────────────────────────────────────
|
| 227 |
let ver_gt7 = (version > 7) as u8;
|
| 228 |
-
wb(
|
| 229 |
-
wb(
|
| 230 |
wd(va::G_REPLAY_SUB_FORMAT, 0);
|
| 231 |
|
| 232 |
let mut obs_count: u16 = 0;
|
|
@@ -239,25 +239,25 @@ unsafe fn parse_and_write_v2plus(
|
|
| 239 |
if version >= 12 {
|
| 240 |
if version < 18 {
|
| 241 |
let mode = s.read_u8_validated(0, 2)?;
|
| 242 |
-
wb(
|
| 243 |
} else {
|
| 244 |
let raw = s.read_u8_validated(0, 3)?;
|
| 245 |
if raw >= 2 && raw <= 3 {
|
| 246 |
-
wb(
|
| 247 |
-
wb(
|
| 248 |
} else {
|
| 249 |
-
wb(
|
| 250 |
-
wb(
|
| 251 |
-
wb(
|
| 252 |
}
|
| 253 |
}
|
| 254 |
}
|
| 255 |
|
| 256 |
obs_count = s.read_u16_validated(1, version as u16)?;
|
| 257 |
-
wd(
|
| 258 |
|
| 259 |
// FUN_0053ee00: cleanup observer array. usercall(ESI=0x88C35C). Plain RET.
|
| 260 |
-
call_usercall_esi(rb(
|
| 261 |
|
| 262 |
// Observer team loop: register each observer via naked bridge
|
| 263 |
loop {
|
|
@@ -268,7 +268,7 @@ unsafe fn parse_and_write_v2plus(
|
|
| 268 |
let obs_data: [u32; 4] = [team_id, 0, obs_type as u32, 0];
|
| 269 |
// RegisterObserver: usercall(ESI=0x88C35C) + stdcall(1 param = &data). RET 0x4.
|
| 270 |
call_register_observer(
|
| 271 |
-
rb(
|
| 272 |
);
|
| 273 |
if obs_type == 0 {
|
| 274 |
// The terminating entry's team_id is the replay timestamp (time_t)
|
|
@@ -296,13 +296,13 @@ unsafe fn parse_and_write_v2plus(
|
|
| 296 |
// Scheme header byte
|
| 297 |
if obs_count >= 3 {
|
| 298 |
let header_byte = s.read_u8()?;
|
| 299 |
-
wb(
|
| 300 |
// If header >= 0 (signed): load built-in scheme from resources
|
| 301 |
if (header_byte as i8) >= 0 {
|
| 302 |
// FUN_004D4840: stdcall(2 params). RET 0x8.
|
| 303 |
let f: unsafe extern "stdcall" fn(u32, i32) =
|
| 304 |
-
core::mem::transmute(rb(
|
| 305 |
-
f(rb(
|
| 306 |
}
|
| 307 |
}
|
| 308 |
|
|
@@ -327,7 +327,7 @@ unsafe fn parse_and_write_v2plus(
|
|
| 327 |
// Copy defaults first for v3
|
| 328 |
ptr::copy_nonoverlapping(
|
| 329 |
rb(va::SCHEME_V3_DEFAULTS) as *const u8,
|
| 330 |
-
rb(
|
| 331 |
);
|
| 332 |
(scheme_size_indicator as usize) - 5
|
| 333 |
}
|
|
@@ -336,21 +336,21 @@ unsafe fn parse_and_write_v2plus(
|
|
| 336 |
|
| 337 |
// Copy scheme data from stream to global 0x88DAE0
|
| 338 |
let scheme_slice = s.advance_raw(scheme_data_size)?;
|
| 339 |
-
ptr::copy_nonoverlapping(scheme_slice.as_ptr(), rb(
|
| 340 |
|
| 341 |
// If scheme_header < 0 (signed) and v1/v2: clear + defaults
|
| 342 |
-
if scheme_version <= 2 && (*(rb(
|
| 343 |
-
ptr::write_bytes(rb(
|
| 344 |
ptr::copy_nonoverlapping(
|
| 345 |
rb(va::SCHEME_V3_DEFAULTS) as *const u8,
|
| 346 |
-
rb(
|
| 347 |
);
|
| 348 |
}
|
| 349 |
|
| 350 |
// Validate extended options for v3
|
| 351 |
if scheme_version == 3 {
|
| 352 |
let validate: unsafe extern "cdecl" fn() -> i32 =
|
| 353 |
-
core::mem::transmute(rb(
|
| 354 |
let r = validate();
|
| 355 |
if r != 0 { return Err(ReplayError::InvalidFormat); }
|
| 356 |
}
|
|
@@ -370,59 +370,59 @@ unsafe fn parse_and_write_v2plus(
|
|
| 370 |
|
| 371 |
let map_byte1 = s.read_u8()?;
|
| 372 |
let map_byte2 = s.read_u8()?;
|
| 373 |
-
wb(
|
| 374 |
-
wb(
|
| 375 |
|
| 376 |
let mut replay_name = [0u8; 0x29];
|
| 377 |
s.read_prefixed_string(&mut replay_name)?;
|
| 378 |
-
ptr::copy_nonoverlapping(replay_name.as_ptr(), rb(
|
| 379 |
|
| 380 |
if version >= 9 {
|
| 381 |
let host = s.read_u8()?;
|
| 382 |
// Store as low byte of DAT_008779E0 (CONCAT31 pattern)
|
| 383 |
-
let current = *(rb(
|
| 384 |
-
wd(
|
| 385 |
} else {
|
| 386 |
-
wd(
|
| 387 |
}
|
| 388 |
|
| 389 |
let mut player_count: u8 = 0;
|
| 390 |
for i in 0..13u32 {
|
| 391 |
-
let base =
|
| 392 |
let flag = s.read_u8()?;
|
| 393 |
wb(base, flag);
|
| 394 |
if flag == 0 { continue; }
|
| 395 |
|
| 396 |
-
if i as u32 == *(rb(
|
| 397 |
// This is the host player — set local_11 flag
|
| 398 |
}
|
| 399 |
player_count += 1;
|
| 400 |
|
| 401 |
let mut name = [0u8; 0x11];
|
| 402 |
s.read_prefixed_string(&mut name)?;
|
| 403 |
-
ptr::copy_nonoverlapping(name.as_ptr(), rb(
|
| 404 |
|
| 405 |
let mut display = [0u8; 0x31];
|
| 406 |
s.read_prefixed_string(&mut display)?;
|
| 407 |
-
ptr::copy_nonoverlapping(display.as_ptr(), rb(
|
| 408 |
|
| 409 |
let mut config = [0u8; 0x29];
|
| 410 |
s.read_prefixed_string(&mut config)?;
|
| 411 |
-
ptr::copy_nonoverlapping(config.as_ptr(), rb(
|
| 412 |
|
| 413 |
let u16_val = s.read_u16()?;
|
| 414 |
-
*(rb(
|
| 415 |
|
| 416 |
let byte1 = s.read_u8()?;
|
| 417 |
-
wb(
|
| 418 |
|
| 419 |
let u32_val = s.read_u32()?;
|
| 420 |
-
wd(
|
| 421 |
|
| 422 |
let byte2 = s.read_u8()?;
|
| 423 |
-
wb(
|
| 424 |
}
|
| 425 |
-
wb(
|
| 426 |
|
| 427 |
if obs_count >= 16 {
|
| 428 |
let xor_a = s.read_u32()?;
|
|
@@ -432,9 +432,9 @@ unsafe fn parse_and_write_v2plus(
|
|
| 432 |
|
| 433 |
let mut team_count: u8 = 0;
|
| 434 |
for team_idx in 0..6u32 {
|
| 435 |
-
let tb =
|
| 436 |
let team_flag = s.read_u8()?;
|
| 437 |
-
wb(
|
| 438 |
if team_flag == 0 { continue; }
|
| 439 |
team_count += 1;
|
| 440 |
|
|
@@ -459,7 +459,7 @@ unsafe fn parse_and_write_v2plus(
|
|
| 459 |
// 8 worm names
|
| 460 |
for worm_idx in 0..8u32 {
|
| 461 |
let name_off = ((team_idx as usize) * 0xCB + worm_idx as usize) * 0x11;
|
| 462 |
-
let dest = rb(
|
| 463 |
if use_fixed_names {
|
| 464 |
let slice = s.advance_raw(0x11)?;
|
| 465 |
ptr::copy_nonoverlapping(slice.as_ptr(), dest.add(name_off), 0x11);
|
|
@@ -472,38 +472,38 @@ unsafe fn parse_and_write_v2plus(
|
|
| 472 |
|
| 473 |
// Worm count (unvalidated)
|
| 474 |
let worm_count_raw = s.read_u8()?;
|
| 475 |
-
wb(
|
| 476 |
|
| 477 |
// Team name
|
| 478 |
let mut team_name = [0u8; 0x41];
|
| 479 |
s.read_prefixed_string(&mut team_name)?;
|
| 480 |
-
ptr::copy_nonoverlapping(team_name.as_ptr(), rb(
|
| 481 |
|
| 482 |
// Extra byte if obs_count > 13
|
| 483 |
if obs_count > 13 {
|
| 484 |
let extra = s.read_u8()?;
|
| 485 |
-
wb(
|
| 486 |
}
|
| 487 |
|
| 488 |
// Config name
|
| 489 |
let mut config_name = [0u8; 0x41];
|
| 490 |
s.read_prefixed_string(&mut config_name)?;
|
| 491 |
-
ptr::copy_nonoverlapping(config_name.as_ptr(), rb(
|
| 492 |
|
| 493 |
// Worm count (validated 1-8)
|
| 494 |
let worm_count = s.read_u8()?;
|
| 495 |
if worm_count == 0 || worm_count > 8 { return Err(ReplayError::InvalidFormat); }
|
| 496 |
-
wb(
|
| 497 |
|
| 498 |
// Color, flag, grave, soundbank
|
| 499 |
-
wb(
|
| 500 |
-
wb(
|
| 501 |
-
wb(
|
| 502 |
-
wb(
|
| 503 |
-
wb(
|
| 504 |
|
| 505 |
// Weapon data blocks
|
| 506 |
-
let weapons_dest = rb(
|
| 507 |
let w1 = s.advance_raw(0x400)?;
|
| 508 |
ptr::copy_nonoverlapping(w1.as_ptr(), weapons_dest, 0x400);
|
| 509 |
let w2 = s.advance_raw(0x154)?;
|
|
@@ -516,7 +516,7 @@ unsafe fn parse_and_write_v2plus(
|
|
| 516 |
|
| 517 |
if team_count == 0 { return Err(ReplayError::InvalidFormat); }
|
| 518 |
|
| 519 |
-
wb(
|
| 520 |
|
| 521 |
// ProcessTeamColors: stdcall(1 param = state). RET 0x4.
|
| 522 |
let process_colors: unsafe extern "stdcall" fn(u32) =
|
|
@@ -524,11 +524,11 @@ unsafe fn parse_and_write_v2plus(
|
|
| 524 |
process_colors(rb(va::G_REPLAY_STATE));
|
| 525 |
|
| 526 |
let map_seed = s.read_u16()?;
|
| 527 |
-
wd(
|
| 528 |
|
| 529 |
// FUN_0045d640: stdcall(1 param = state). 1032-line function.
|
| 530 |
let fun_45d640: unsafe extern "stdcall" fn(u32) =
|
| 531 |
-
core::mem::transmute(rb(
|
| 532 |
fun_45d640(rb(va::G_REPLAY_STATE));
|
| 533 |
|
| 534 |
if map_seed == 0 || map_seed == 0xFFFF {
|
|
@@ -543,8 +543,8 @@ unsafe fn parse_and_write_v2plus(
|
|
| 543 |
|
| 544 |
// Assembly: MOV ESI,[seed]; PUSH ESI; CALL srand; rand(); SHL<<16; rand(); ADD
|
| 545 |
let current_seed = *(rb(va::G_RANDOM_SEED) as *const u32);
|
| 546 |
-
let srand: unsafe extern "cdecl" fn(u32) = core::mem::transmute(rb(
|
| 547 |
-
let rand_fn: unsafe extern "cdecl" fn() -> i32 = core::mem::transmute(rb(
|
| 548 |
srand(current_seed);
|
| 549 |
let r1 = rand_fn() as u32;
|
| 550 |
let r2 = rand_fn() as u32;
|
|
@@ -554,7 +554,7 @@ unsafe fn parse_and_write_v2plus(
|
|
| 554 |
let ver = *(rb(va::G_REPLAY_VERSION_ID) as *const i32);
|
| 555 |
if ver != 0x22 && !(ver >= 0x29 && ver <= 0x2A) && ver < 0x2D {
|
| 556 |
let check: unsafe extern "cdecl" fn() -> i32 =
|
| 557 |
-
core::mem::transmute(rb(
|
| 558 |
check();
|
| 559 |
}
|
| 560 |
// The map was already written to playback.thm in the header section.
|
|
@@ -564,12 +564,12 @@ unsafe fn parse_and_write_v2plus(
|
|
| 564 |
if *(state as *const i32).byte_add(0xDB1C) >= 1 {
|
| 565 |
// Alloc: PUSH 0x29628; CALL 005C0AB8; ADD ESP,4 — cdecl(size)
|
| 566 |
let alloc: unsafe extern "cdecl" fn(u32) -> u32 =
|
| 567 |
-
core::mem::transmute(rb(
|
| 568 |
let buf = alloc(0x29628);
|
| 569 |
let map_obj = if buf != 0 {
|
| 570 |
// Construct: PUSH 1; PUSH buf; CALL 00447E80 — stdcall(buf, 1)
|
| 571 |
let construct: unsafe extern "stdcall" fn(u32, i32) -> *mut u32 =
|
| 572 |
-
core::mem::transmute(rb(
|
| 573 |
construct(buf, 1)
|
| 574 |
} else {
|
| 575 |
ptr::null_mut()
|
|
@@ -577,7 +577,7 @@ unsafe fn parse_and_write_v2plus(
|
|
| 577 |
|
| 578 |
// Load: PUSH 0; PUSH path; PUSH map_obj; CALL 0044A9A0 — stdcall(3)
|
| 579 |
let load: unsafe extern "stdcall" fn(*mut u32, *const u8, i32) -> i32 =
|
| 580 |
-
core::mem::transmute(rb(
|
| 581 |
let ok = load(map_obj, b"data\\playback.thm\0".as_ptr(), 0);
|
| 582 |
|
| 583 |
if ok == 0 {
|
|
@@ -592,7 +592,7 @@ unsafe fn parse_and_write_v2plus(
|
|
| 592 |
}
|
| 593 |
|
| 594 |
// FUN_00449B60: usercall(ESI=map_obj). Copies map info to game state.
|
| 595 |
-
call_usercall_esi(map_obj as u32, rb(
|
| 596 |
|
| 597 |
// Terrain flag: CMP [ESI+0x29618],0; SETZ
|
| 598 |
*(state as *mut u8).add(0xD98B) =
|
|
@@ -629,11 +629,11 @@ unsafe fn write_replay_log(state: u32, log_file: &mut File) -> Result<(), Replay
|
|
| 629 |
// Date/time line: timestamp from observer array, formatted as GMT.
|
| 630 |
// The observer array at 0x88C35C contains the replay date as a time_t
|
| 631 |
// in its first registered entry. Use WA's gmtime64 for conversion.
|
| 632 |
-
if *(rb(
|
| 633 |
// Format the replay date using the timestamp saved during observer parsing.
|
| 634 |
let ts = REPLAY_TIMESTAMP as i64;
|
| 635 |
let gmtime: unsafe extern "cdecl" fn(*const i64) -> *const [i32; 9] =
|
| 636 |
-
core::mem::transmute(rb(
|
| 637 |
let tm = gmtime(&ts);
|
| 638 |
if !tm.is_null() {
|
| 639 |
let tm = &*tm;
|
|
@@ -660,10 +660,10 @@ unsafe fn write_replay_log(state: u32, log_file: &mut File) -> Result<(), Replay
|
|
| 660 |
-4 => rb(0x650EAC) as *const u8, // "1.0"
|
| 661 |
-2 => rb(0x650EB0) as *const u8, // "3.0"
|
| 662 |
-1 => rb(0x650EB4) as *const u8, // "3.5 Beta 1"
|
| 663 |
-
_ => wa_load_string(0x0F), //
|
| 664 |
}
|
| 665 |
} else {
|
| 666 |
-
let table = rb(
|
| 667 |
let ptr = *table.add(game_ver_id as usize);
|
| 668 |
ptr as *const u8
|
| 669 |
};
|
|
@@ -688,10 +688,10 @@ unsafe fn write_replay_log(state: u32, log_file: &mut File) -> Result<(), Replay
|
|
| 688 |
{
|
| 689 |
let label_exported = wa_load_string(0x6E9); // "Exported with Version"
|
| 690 |
// Current WA version from version table: 0x699814[DAT_00697702]
|
| 691 |
-
let ver_byte = *(rb(
|
| 692 |
// "3.8.1" literal at 0x641C60 + suffix from version table
|
| 693 |
-
let ver_literal = rb(
|
| 694 |
-
let ver_suffix = *(rb(
|
| 695 |
|
| 696 |
let mut s = heapless::String::<256>::new();
|
| 697 |
push_cstr(&mut s, label_exported);
|
|
@@ -718,9 +718,9 @@ unsafe fn write_replay_log(state: u32, log_file: &mut File) -> Result<(), Replay
|
|
| 718 |
// Find max color name length for alignment — only active teams
|
| 719 |
let mut max_color_len = 0usize;
|
| 720 |
for slot in 0..6u32 {
|
| 721 |
-
let flag = *(rb(
|
| 722 |
if flag == 0 { continue; }
|
| 723 |
-
let ci = *(rb(
|
| 724 |
if ci < 6 {
|
| 725 |
let len = c_strlen(color_names[ci]);
|
| 726 |
if len > max_color_len { max_color_len = len; }
|
|
@@ -729,11 +729,11 @@ unsafe fn write_replay_log(state: u32, log_file: &mut File) -> Result<(), Replay
|
|
| 729 |
|
| 730 |
// Team data is in the team header buffer at 0x877FFC + i*0xD7B.
|
| 731 |
// Per-team: +0x00=type, +0x01=alliance(color), +0x14=team_name(prefixed)
|
| 732 |
-
let _team_count = *(rb(
|
| 733 |
|
| 734 |
for slot in 0..6u32 {
|
| 735 |
-
let tb = rb(
|
| 736 |
-
let flag = *(rb(
|
| 737 |
if flag == 0 { continue; }
|
| 738 |
|
| 739 |
let team_type = *tb as i8;
|
|
|
|
| 32 |
/// Convert a WA CRT FILE* to a borrowed Rust File (ManuallyDrop — we don't own it).
|
| 33 |
unsafe fn wa_file_to_rust(file: *mut FILE) -> Option<ManuallyDrop<File>> {
|
| 34 |
let fileno: unsafe extern "cdecl" fn(*mut FILE) -> i32 =
|
| 35 |
+
core::mem::transmute(rb(va::WA_FILENO));
|
| 36 |
let get_osfhandle: unsafe extern "cdecl" fn(i32) -> isize =
|
| 37 |
+
core::mem::transmute(rb(va::WA_GET_OSFHANDLE));
|
| 38 |
|
| 39 |
let fd = fileno(file);
|
| 40 |
if fd < 0 { return None; }
|
|
|
|
| 46 |
/// Load a WA string resource by ID (stdcall). Returns null-terminated C string.
|
| 47 |
unsafe fn wa_load_string(id: u32) -> *const u8 {
|
| 48 |
let f: unsafe extern "stdcall" fn(u32) -> *const u8 =
|
| 49 |
+
core::mem::transmute(rb(va::WA_LOAD_STRING));
|
| 50 |
f(id)
|
| 51 |
}
|
| 52 |
|
|
|
|
| 94 |
// Open replay file using Rust's std::fs::File
|
| 95 |
let replay_path = {
|
| 96 |
// Build path: game data dir + replay filename from state+0xDB60
|
| 97 |
+
let data_dir = CStr::from_ptr(rb(va::G_DATA_DIR) as *const i8);
|
| 98 |
let file_name = CStr::from_ptr(s.add(0xDB60) as *const i8);
|
| 99 |
let dir = data_dir.to_str().unwrap_or(".");
|
| 100 |
let name = file_name.to_str().unwrap_or("");
|
|
|
|
| 183 |
match result {
|
| 184 |
Ok(()) => {
|
| 185 |
call_usercall_eax(state, rb(va::REPLAY_PROCESS_FLAGS));
|
| 186 |
+
let wa_log_file = *(rb(va::G_LOG_FILE_PTR) as *const *mut FILE);
|
| 187 |
if !wa_log_file.is_null() {
|
| 188 |
if let Some(mut log_file) = wa_file_to_rust(wa_log_file) {
|
| 189 |
write_replay_log(state, &mut *log_file)?;
|
|
|
|
| 225 |
|
| 226 |
// ── Sub-format flags ─────────────────────────────────────────────────
|
| 227 |
let ver_gt7 = (version > 7) as u8;
|
| 228 |
+
wb(va::G_REPLAY_VER_FLAG_A, ver_gt7);
|
| 229 |
+
wb(va::G_REPLAY_VER_FLAG_B, ver_gt7);
|
| 230 |
wd(va::G_REPLAY_SUB_FORMAT, 0);
|
| 231 |
|
| 232 |
let mut obs_count: u16 = 0;
|
|
|
|
| 239 |
if version >= 12 {
|
| 240 |
if version < 18 {
|
| 241 |
let mode = s.read_u8_validated(0, 2)?;
|
| 242 |
+
wb(va::G_REPLAY_GAME_MODE, mode);
|
| 243 |
} else {
|
| 244 |
let raw = s.read_u8_validated(0, 3)?;
|
| 245 |
if raw >= 2 && raw <= 3 {
|
| 246 |
+
wb(va::G_REPLAY_GAME_MODE, raw - 1);
|
| 247 |
+
wb(va::G_REPLAY_VER_FLAG_A, 1); wb(va::G_REPLAY_VER_FLAG_B, 1);
|
| 248 |
} else {
|
| 249 |
+
wb(va::G_REPLAY_VER_FLAG_A, (raw != 0) as u8);
|
| 250 |
+
wb(va::G_REPLAY_GAME_MODE, 0);
|
| 251 |
+
wb(va::G_REPLAY_VER_FLAG_B, (raw != 0) as u8);
|
| 252 |
}
|
| 253 |
}
|
| 254 |
}
|
| 255 |
|
| 256 |
obs_count = s.read_u16_validated(1, version as u16)?;
|
| 257 |
+
wd(va::G_OBSERVER_COUNT, obs_count as u32);
|
| 258 |
|
| 259 |
// FUN_0053ee00: cleanup observer array. usercall(ESI=0x88C35C). Plain RET.
|
| 260 |
+
call_usercall_esi(rb(va::G_OBSERVER_ARRAY), rb(va::REPLAY_CLEANUP_OBSERVERS));
|
| 261 |
|
| 262 |
// Observer team loop: register each observer via naked bridge
|
| 263 |
loop {
|
|
|
|
| 268 |
let obs_data: [u32; 4] = [team_id, 0, obs_type as u32, 0];
|
| 269 |
// RegisterObserver: usercall(ESI=0x88C35C) + stdcall(1 param = &data). RET 0x4.
|
| 270 |
call_register_observer(
|
| 271 |
+
rb(va::G_OBSERVER_ARRAY), obs_data.as_ptr() as u32, rb(va::REPLAY_REGISTER_OBSERVER),
|
| 272 |
);
|
| 273 |
if obs_type == 0 {
|
| 274 |
// The terminating entry's team_id is the replay timestamp (time_t)
|
|
|
|
| 296 |
// Scheme header byte
|
| 297 |
if obs_count >= 3 {
|
| 298 |
let header_byte = s.read_u8()?;
|
| 299 |
+
wb(va::G_SCHEME_HEADER, header_byte);
|
| 300 |
// If header >= 0 (signed): load built-in scheme from resources
|
| 301 |
if (header_byte as i8) >= 0 {
|
| 302 |
// FUN_004D4840: stdcall(2 params). RET 0x8.
|
| 303 |
let f: unsafe extern "stdcall" fn(u32, i32) =
|
| 304 |
+
core::mem::transmute(rb(va::SCHEME_LOAD_BUILTIN));
|
| 305 |
+
f(rb(va::G_SCHEME_DEST), header_byte as i32);
|
| 306 |
}
|
| 307 |
}
|
| 308 |
|
|
|
|
| 327 |
// Copy defaults first for v3
|
| 328 |
ptr::copy_nonoverlapping(
|
| 329 |
rb(va::SCHEME_V3_DEFAULTS) as *const u8,
|
| 330 |
+
rb(va::G_SCHEME_V3_DATA) as *mut u8, 0x6E,
|
| 331 |
);
|
| 332 |
(scheme_size_indicator as usize) - 5
|
| 333 |
}
|
|
|
|
| 336 |
|
| 337 |
// Copy scheme data from stream to global 0x88DAE0
|
| 338 |
let scheme_slice = s.advance_raw(scheme_data_size)?;
|
| 339 |
+
ptr::copy_nonoverlapping(scheme_slice.as_ptr(), rb(va::G_SCHEME_DATA) as *mut u8, scheme_data_size);
|
| 340 |
|
| 341 |
// If scheme_header < 0 (signed) and v1/v2: clear + defaults
|
| 342 |
+
if scheme_version <= 2 && (*(rb(va::G_SCHEME_HEADER) as *const i8)) < 0 {
|
| 343 |
+
ptr::write_bytes(rb(va::G_SCHEME_OPTIONS) as *mut u8, 0, 0x4C);
|
| 344 |
ptr::copy_nonoverlapping(
|
| 345 |
rb(va::SCHEME_V3_DEFAULTS) as *const u8,
|
| 346 |
+
rb(va::G_SCHEME_V3_DATA) as *mut u8, 0x6E,
|
| 347 |
);
|
| 348 |
}
|
| 349 |
|
| 350 |
// Validate extended options for v3
|
| 351 |
if scheme_version == 3 {
|
| 352 |
let validate: unsafe extern "cdecl" fn() -> i32 =
|
| 353 |
+
core::mem::transmute(rb(va::SCHEME_VALIDATE_EXTENDED));
|
| 354 |
let r = validate();
|
| 355 |
if r != 0 { return Err(ReplayError::InvalidFormat); }
|
| 356 |
}
|
|
|
|
| 370 |
|
| 371 |
let map_byte1 = s.read_u8()?;
|
| 372 |
let map_byte2 = s.read_u8()?;
|
| 373 |
+
wb(va::G_MAP_BYTE_1, map_byte1);
|
| 374 |
+
wb(va::G_MAP_BYTE_2, map_byte2);
|
| 375 |
|
| 376 |
let mut replay_name = [0u8; 0x29];
|
| 377 |
s.read_prefixed_string(&mut replay_name)?;
|
| 378 |
+
ptr::copy_nonoverlapping(replay_name.as_ptr(), rb(va::G_REPLAY_NAME) as *mut u8, 0x29);
|
| 379 |
|
| 380 |
if version >= 9 {
|
| 381 |
let host = s.read_u8()?;
|
| 382 |
// Store as low byte of DAT_008779E0 (CONCAT31 pattern)
|
| 383 |
+
let current = *(rb(va::G_HOST_PLAYER) as *const u32);
|
| 384 |
+
wd(va::G_HOST_PLAYER, (current & 0xFFFFFF00) | host as u32);
|
| 385 |
} else {
|
| 386 |
+
wd(va::G_HOST_PLAYER, 0xFFFFFFFF);
|
| 387 |
}
|
| 388 |
|
| 389 |
let mut player_count: u8 = 0;
|
| 390 |
for i in 0..13u32 {
|
| 391 |
+
let base = va::G_PLAYER_ARRAY + 0x74 + i * 0x78; // player[i].flag
|
| 392 |
let flag = s.read_u8()?;
|
| 393 |
wb(base, flag);
|
| 394 |
if flag == 0 { continue; }
|
| 395 |
|
| 396 |
+
if i as u32 == *(rb(va::G_HOST_PLAYER) as *const u32) {
|
| 397 |
// This is the host player — set local_11 flag
|
| 398 |
}
|
| 399 |
player_count += 1;
|
| 400 |
|
| 401 |
let mut name = [0u8; 0x11];
|
| 402 |
s.read_prefixed_string(&mut name)?;
|
| 403 |
+
ptr::copy_nonoverlapping(name.as_ptr(), rb(va::G_PLAYER_ARRAY + i * 0x78) as *mut u8, 0x11);
|
| 404 |
|
| 405 |
let mut display = [0u8; 0x31];
|
| 406 |
s.read_prefixed_string(&mut display)?;
|
| 407 |
+
ptr::copy_nonoverlapping(display.as_ptr(), rb(va::G_PLAYER_ARRAY + 0x11 + i * 0x78) as *mut u8, 0x31);
|
| 408 |
|
| 409 |
let mut config = [0u8; 0x29];
|
| 410 |
s.read_prefixed_string(&mut config)?;
|
| 411 |
+
ptr::copy_nonoverlapping(config.as_ptr(), rb(va::G_PLAYER_ARRAY + 0x42 + i * 0x78) as *mut u8, 0x29);
|
| 412 |
|
| 413 |
let u16_val = s.read_u16()?;
|
| 414 |
+
*(rb(va::G_PLAYER_ARRAY + 0x6C + i * 0x3C) as *mut u16) = u16_val;
|
| 415 |
|
| 416 |
let byte1 = s.read_u8()?;
|
| 417 |
+
wb(va::G_PLAYER_ARRAY + 0x6E + i * 0x78, byte1);
|
| 418 |
|
| 419 |
let u32_val = s.read_u32()?;
|
| 420 |
+
wd(va::G_PLAYER_ARRAY + 0x70 + i * 0x1E, u32_val);
|
| 421 |
|
| 422 |
let byte2 = s.read_u8()?;
|
| 423 |
+
wb(va::G_PLAYER_ARRAY + 0x77 + i * 0x78, byte2);
|
| 424 |
}
|
| 425 |
+
wb(va::G_PLAYER_COUNT, player_count);
|
| 426 |
|
| 427 |
if obs_count >= 16 {
|
| 428 |
let xor_a = s.read_u32()?;
|
|
|
|
| 432 |
|
| 433 |
let mut team_count: u8 = 0;
|
| 434 |
for team_idx in 0..6u32 {
|
| 435 |
+
let tb = va::G_TEAM_DATA + team_idx * 0xD7B; // per-team base
|
| 436 |
let team_flag = s.read_u8()?;
|
| 437 |
+
wb(va::G_TEAM_FLAG_OFF + team_idx * 0xD7B, team_flag);
|
| 438 |
if team_flag == 0 { continue; }
|
| 439 |
team_count += 1;
|
| 440 |
|
|
|
|
| 459 |
// 8 worm names
|
| 460 |
for worm_idx in 0..8u32 {
|
| 461 |
let name_off = ((team_idx as usize) * 0xCB + worm_idx as usize) * 0x11;
|
| 462 |
+
let dest = rb(va::G_WORM_NAMES) as *mut u8;
|
| 463 |
if use_fixed_names {
|
| 464 |
let slice = s.advance_raw(0x11)?;
|
| 465 |
ptr::copy_nonoverlapping(slice.as_ptr(), dest.add(name_off), 0x11);
|
|
|
|
| 472 |
|
| 473 |
// Worm count (unvalidated)
|
| 474 |
let worm_count_raw = s.read_u8()?;
|
| 475 |
+
wb(va::G_TEAM_WORM_COUNT_RAW_OFF + team_idx * 0xD7B, worm_count_raw);
|
| 476 |
|
| 477 |
// Team name
|
| 478 |
let mut team_name = [0u8; 0x41];
|
| 479 |
s.read_prefixed_string(&mut team_name)?;
|
| 480 |
+
ptr::copy_nonoverlapping(team_name.as_ptr(), rb(va::G_TEAM_NAME_OFF + team_idx * 0xD7B) as *mut u8, 0x41);
|
| 481 |
|
| 482 |
// Extra byte if obs_count > 13
|
| 483 |
if obs_count > 13 {
|
| 484 |
let extra = s.read_u8()?;
|
| 485 |
+
wb(va::G_TEAM_EXTRA_OFF + team_idx * 0xD7B, extra);
|
| 486 |
}
|
| 487 |
|
| 488 |
// Config name
|
| 489 |
let mut config_name = [0u8; 0x41];
|
| 490 |
s.read_prefixed_string(&mut config_name)?;
|
| 491 |
+
ptr::copy_nonoverlapping(config_name.as_ptr(), rb(va::G_TEAM_CONFIG_NAME_OFF + team_idx * 0xD7B) as *mut u8, 0x41);
|
| 492 |
|
| 493 |
// Worm count (validated 1-8)
|
| 494 |
let worm_count = s.read_u8()?;
|
| 495 |
if worm_count == 0 || worm_count > 8 { return Err(ReplayError::InvalidFormat); }
|
| 496 |
+
wb(va::G_TEAM_WORM_COUNT_OFF + team_idx * 0xD7B, worm_count);
|
| 497 |
|
| 498 |
// Color, flag, grave, soundbank
|
| 499 |
+
wb(va::G_TEAM_COLOR_OFF + team_idx * 0xD7B, s.read_u8()?);
|
| 500 |
+
wb(va::G_TEAM_FLAG2_OFF + team_idx * 0xD7B, s.read_u8()?);
|
| 501 |
+
wb(va::G_TEAM_GRAVE_OFF + team_idx * 0xD7B, s.read_u8()?);
|
| 502 |
+
wb(va::G_TEAM_SOUNDBANK_OFF + team_idx * 0xD7B, s.read_u8()?);
|
| 503 |
+
wb(va::G_TEAM_SOUNDBANK2_OFF + team_idx * 0xD7B, s.read_u8()?);
|
| 504 |
|
| 505 |
// Weapon data blocks
|
| 506 |
+
let weapons_dest = rb(va::G_TEAM_WEAPONS_OFF + team_idx * 0xD7B) as *mut u8;
|
| 507 |
let w1 = s.advance_raw(0x400)?;
|
| 508 |
ptr::copy_nonoverlapping(w1.as_ptr(), weapons_dest, 0x400);
|
| 509 |
let w2 = s.advance_raw(0x154)?;
|
|
|
|
| 516 |
|
| 517 |
if team_count == 0 { return Err(ReplayError::InvalidFormat); }
|
| 518 |
|
| 519 |
+
wb(va::G_TEAM_COUNT, team_count);
|
| 520 |
|
| 521 |
// ProcessTeamColors: stdcall(1 param = state). RET 0x4.
|
| 522 |
let process_colors: unsafe extern "stdcall" fn(u32) =
|
|
|
|
| 524 |
process_colors(rb(va::G_REPLAY_STATE));
|
| 525 |
|
| 526 |
let map_seed = s.read_u16()?;
|
| 527 |
+
wd(va::G_MAP_SEED, map_seed as u32);
|
| 528 |
|
| 529 |
// FUN_0045d640: stdcall(1 param = state). 1032-line function.
|
| 530 |
let fun_45d640: unsafe extern "stdcall" fn(u32) =
|
| 531 |
+
core::mem::transmute(rb(va::REPLAY_PROCESS_STATE));
|
| 532 |
fun_45d640(rb(va::G_REPLAY_STATE));
|
| 533 |
|
| 534 |
if map_seed == 0 || map_seed == 0xFFFF {
|
|
|
|
| 543 |
|
| 544 |
// Assembly: MOV ESI,[seed]; PUSH ESI; CALL srand; rand(); SHL<<16; rand(); ADD
|
| 545 |
let current_seed = *(rb(va::G_RANDOM_SEED) as *const u32);
|
| 546 |
+
let srand: unsafe extern "cdecl" fn(u32) = core::mem::transmute(rb(va::WA_SRAND));
|
| 547 |
+
let rand_fn: unsafe extern "cdecl" fn() -> i32 = core::mem::transmute(rb(va::WA_RAND));
|
| 548 |
srand(current_seed);
|
| 549 |
let r1 = rand_fn() as u32;
|
| 550 |
let r2 = rand_fn() as u32;
|
|
|
|
| 554 |
let ver = *(rb(va::G_REPLAY_VERSION_ID) as *const i32);
|
| 555 |
if ver != 0x22 && !(ver >= 0x29 && ver <= 0x2A) && ver < 0x2D {
|
| 556 |
let check: unsafe extern "cdecl" fn() -> i32 =
|
| 557 |
+
core::mem::transmute(rb(va::SCHEME_CHECK_WEAPON_LIMITS));
|
| 558 |
check();
|
| 559 |
}
|
| 560 |
// The map was already written to playback.thm in the header section.
|
|
|
|
| 564 |
if *(state as *const i32).byte_add(0xDB1C) >= 1 {
|
| 565 |
// Alloc: PUSH 0x29628; CALL 005C0AB8; ADD ESP,4 — cdecl(size)
|
| 566 |
let alloc: unsafe extern "cdecl" fn(u32) -> u32 =
|
| 567 |
+
core::mem::transmute(rb(va::WA_CRT_MALLOC));
|
| 568 |
let buf = alloc(0x29628);
|
| 569 |
let map_obj = if buf != 0 {
|
| 570 |
// Construct: PUSH 1; PUSH buf; CALL 00447E80 — stdcall(buf, 1)
|
| 571 |
let construct: unsafe extern "stdcall" fn(u32, i32) -> *mut u32 =
|
| 572 |
+
core::mem::transmute(rb(va::MAP_CLASS_CONSTRUCTOR));
|
| 573 |
construct(buf, 1)
|
| 574 |
} else {
|
| 575 |
ptr::null_mut()
|
|
|
|
| 577 |
|
| 578 |
// Load: PUSH 0; PUSH path; PUSH map_obj; CALL 0044A9A0 — stdcall(3)
|
| 579 |
let load: unsafe extern "stdcall" fn(*mut u32, *const u8, i32) -> i32 =
|
| 580 |
+
core::mem::transmute(rb(va::MAP_CLASS_LOAD));
|
| 581 |
let ok = load(map_obj, b"data\\playback.thm\0".as_ptr(), 0);
|
| 582 |
|
| 583 |
if ok == 0 {
|
|
|
|
| 592 |
}
|
| 593 |
|
| 594 |
// FUN_00449B60: usercall(ESI=map_obj). Copies map info to game state.
|
| 595 |
+
call_usercall_esi(map_obj as u32, rb(va::MAP_COPY_INFO));
|
| 596 |
|
| 597 |
// Terrain flag: CMP [ESI+0x29618],0; SETZ
|
| 598 |
*(state as *mut u8).add(0xD98B) =
|
|
|
|
| 629 |
// Date/time line: timestamp from observer array, formatted as GMT.
|
| 630 |
// The observer array at 0x88C35C contains the replay date as a time_t
|
| 631 |
// in its first registered entry. Use WA's gmtime64 for conversion.
|
| 632 |
+
if *(rb(va::G_RECORDING_TIMESTAMP_FLAG) as *const u32) != 0 && REPLAY_TIMESTAMP != 0 {
|
| 633 |
// Format the replay date using the timestamp saved during observer parsing.
|
| 634 |
let ts = REPLAY_TIMESTAMP as i64;
|
| 635 |
let gmtime: unsafe extern "cdecl" fn(*const i64) -> *const [i32; 9] =
|
| 636 |
+
core::mem::transmute(rb(va::WA_GMTIME64));
|
| 637 |
let tm = gmtime(&ts);
|
| 638 |
if !tm.is_null() {
|
| 639 |
let tm = &*tm;
|
|
|
|
| 660 |
-4 => rb(0x650EAC) as *const u8, // "1.0"
|
| 661 |
-2 => rb(0x650EB0) as *const u8, // "3.0"
|
| 662 |
-1 => rb(0x650EB4) as *const u8, // "3.5 Beta 1"
|
| 663 |
+
_ => wa_load_string(0x0F), // "Unknown"
|
| 664 |
}
|
| 665 |
} else {
|
| 666 |
+
let table = rb(va::VERSION_STRING_TABLE) as *const u32;
|
| 667 |
let ptr = *table.add(game_ver_id as usize);
|
| 668 |
ptr as *const u8
|
| 669 |
};
|
|
|
|
| 688 |
{
|
| 689 |
let label_exported = wa_load_string(0x6E9); // "Exported with Version"
|
| 690 |
// Current WA version from version table: 0x699814[DAT_00697702]
|
| 691 |
+
let ver_byte = *(rb(va::G_VERSION_BYTE) as *const u8) as u32;
|
| 692 |
// "3.8.1" literal at 0x641C60 + suffix from version table
|
| 693 |
+
let ver_literal = rb(va::STR_VERSION_381) as *const u8; // "3.8.1"
|
| 694 |
+
let ver_suffix = *(rb(va::VERSION_SUFFIX_TABLE + ver_byte * 4) as *const u32) as *const u8; // " (Steam)"
|
| 695 |
|
| 696 |
let mut s = heapless::String::<256>::new();
|
| 697 |
push_cstr(&mut s, label_exported);
|
|
|
|
| 718 |
// Find max color name length for alignment — only active teams
|
| 719 |
let mut max_color_len = 0usize;
|
| 720 |
for slot in 0..6u32 {
|
| 721 |
+
let flag = *(rb(va::G_TEAM_FLAG_OFF + slot * 0xD7B) as *const u8);
|
| 722 |
if flag == 0 { continue; }
|
| 723 |
+
let ci = *(rb(va::G_TEAM_DATA + slot * 0xD7B + 1) as *const u8) as usize;
|
| 724 |
if ci < 6 {
|
| 725 |
let len = c_strlen(color_names[ci]);
|
| 726 |
if len > max_color_len { max_color_len = len; }
|
|
|
|
| 729 |
|
| 730 |
// Team data is in the team header buffer at 0x877FFC + i*0xD7B.
|
| 731 |
// Per-team: +0x00=type, +0x01=alliance(color), +0x14=team_name(prefixed)
|
| 732 |
+
let _team_count = *(rb(va::G_TEAM_COUNT) as *const u8) as u32;
|
| 733 |
|
| 734 |
for slot in 0..6u32 {
|
| 735 |
+
let tb = rb(va::G_TEAM_DATA + slot * 0xD7B) as *const u8;
|
| 736 |
+
let flag = *(rb(va::G_TEAM_FLAG_OFF + slot * 0xD7B) as *const u8);
|
| 737 |
if flag == 0 { continue; }
|
| 738 |
|
| 739 |
let team_type = *tb as i8;
|