chore: run cargo fmt
Browse files- crates/openwa-core/src/game/weapon_fire.rs +5 -23
- crates/openwa-debugui/src/app.rs +5 -1
- crates/openwa-test-runner/src/main.rs +4 -14
- crates/openwa-wormkit/src/replacements/headless.rs +2 -3
- crates/openwa-wormkit/src/replacements/mod.rs +1 -1
- crates/openwa-wormkit/src/replacements/replay_test.rs +2 -4
- crates/openwa-wormkit/src/replacements/trace_desync.rs +2 -2
- crates/openwa-wormkit/src/replacements/weapon_release.rs +1 -10
crates/openwa-core/src/game/weapon_fire.rs
CHANGED
|
@@ -48,12 +48,7 @@ const _: () = assert!(core::mem::size_of::<WeaponReleaseContext>() == 0x2C);
|
|
| 48 |
// __usercall: EAX = team_index, EDX = amount, [ESP+4] = team_info_base, [ESP+8] = weapon_id
|
| 49 |
// RET 0x8
|
| 50 |
|
| 51 |
-
pub unsafe fn add_ammo(
|
| 52 |
-
team_index: u32,
|
| 53 |
-
amount: i32,
|
| 54 |
-
arena: TeamArenaRef,
|
| 55 |
-
weapon_id: u32,
|
| 56 |
-
) {
|
| 57 |
let (alliance, wid) = arena.weapon_slot_key(team_index as usize, weapon_id);
|
| 58 |
let state = arena.state_mut();
|
| 59 |
let ammo = state.get_ammo(alliance, wid);
|
|
@@ -87,11 +82,7 @@ pub unsafe fn subtract_ammo(team_index: u32, arena: TeamArenaRef, weapon_id: u32
|
|
| 87 |
// __usercall: EAX = team_index, ESI = team_info_base, EDX = weapon_id
|
| 88 |
// plain RET, returns EAX = ammo count
|
| 89 |
|
| 90 |
-
pub unsafe fn get_ammo(
|
| 91 |
-
team_index: u32,
|
| 92 |
-
arena: TeamArenaRef,
|
| 93 |
-
weapon_id: u32,
|
| 94 |
-
) -> u32 {
|
| 95 |
let (alliance, wid) = arena.weapon_slot_key(team_index as usize, weapon_id);
|
| 96 |
let state = arena.state();
|
| 97 |
|
|
@@ -393,9 +384,7 @@ pub fn can_fire_subtype16(state: u32) -> bool {
|
|
| 393 |
///
|
| 394 |
/// The entity at key (0, 0x14) is a CTaskTurnGame (inherits CTaskTeam).
|
| 395 |
/// Returns null if not found.
|
| 396 |
-
pub unsafe fn lookup_turn_game(
|
| 397 |
-
worm: *const CTaskWorm,
|
| 398 |
-
) -> *mut crate::task::CTaskTurnGame {
|
| 399 |
use crate::task::SharedDataTable;
|
| 400 |
|
| 401 |
let table = SharedDataTable::from_task(worm as *const CTask);
|
|
@@ -419,13 +408,7 @@ unsafe fn fire_surrender(worm: *mut CTaskWorm) {
|
|
| 419 |
|
| 420 |
// Dispatch through vtable — hits CTaskTurnGame::HandleMessage (0x55DC00)
|
| 421 |
// which delegates to CTaskTeam (0x557310) and handles end-turn/sound.
|
| 422 |
-
CTaskTurnGame::handle_message_raw(
|
| 423 |
-
team,
|
| 424 |
-
worm as *mut crate::task::CTask,
|
| 425 |
-
0x2B,
|
| 426 |
-
4,
|
| 427 |
-
buf.as_ptr(),
|
| 428 |
-
);
|
| 429 |
}
|
| 430 |
|
| 431 |
/// Send a message to CTaskTurnGame via SharedData lookup + vtable dispatch.
|
|
@@ -1008,8 +991,7 @@ unsafe fn fire_girder(worm: *mut CTaskWorm) {
|
|
| 1008 |
girder_visual(landscape, girder_x >> 16, girder_y >> 16, sprite1, sprite2);
|
| 1009 |
|
| 1010 |
// Increment WormEntry counters
|
| 1011 |
-
let arena =
|
| 1012 |
-
crate::engine::ddgame::TeamArenaRef::from_ptr(&raw mut (*ddgame).team_arena);
|
| 1013 |
let team_index = (*worm).team_index as usize;
|
| 1014 |
let worm_index = (*worm).worm_index as usize;
|
| 1015 |
let entry = arena.team_worm_mut(team_index, worm_index);
|
|
|
|
| 48 |
// __usercall: EAX = team_index, EDX = amount, [ESP+4] = team_info_base, [ESP+8] = weapon_id
|
| 49 |
// RET 0x8
|
| 50 |
|
| 51 |
+
pub unsafe fn add_ammo(team_index: u32, amount: i32, arena: TeamArenaRef, weapon_id: u32) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
let (alliance, wid) = arena.weapon_slot_key(team_index as usize, weapon_id);
|
| 53 |
let state = arena.state_mut();
|
| 54 |
let ammo = state.get_ammo(alliance, wid);
|
|
|
|
| 82 |
// __usercall: EAX = team_index, ESI = team_info_base, EDX = weapon_id
|
| 83 |
// plain RET, returns EAX = ammo count
|
| 84 |
|
| 85 |
+
pub unsafe fn get_ammo(team_index: u32, arena: TeamArenaRef, weapon_id: u32) -> u32 {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
let (alliance, wid) = arena.weapon_slot_key(team_index as usize, weapon_id);
|
| 87 |
let state = arena.state();
|
| 88 |
|
|
|
|
| 384 |
///
|
| 385 |
/// The entity at key (0, 0x14) is a CTaskTurnGame (inherits CTaskTeam).
|
| 386 |
/// Returns null if not found.
|
| 387 |
+
pub unsafe fn lookup_turn_game(worm: *const CTaskWorm) -> *mut crate::task::CTaskTurnGame {
|
|
|
|
|
|
|
| 388 |
use crate::task::SharedDataTable;
|
| 389 |
|
| 390 |
let table = SharedDataTable::from_task(worm as *const CTask);
|
|
|
|
| 408 |
|
| 409 |
// Dispatch through vtable — hits CTaskTurnGame::HandleMessage (0x55DC00)
|
| 410 |
// which delegates to CTaskTeam (0x557310) and handles end-turn/sound.
|
| 411 |
+
CTaskTurnGame::handle_message_raw(team, worm as *mut crate::task::CTask, 0x2B, 4, buf.as_ptr());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
}
|
| 413 |
|
| 414 |
/// Send a message to CTaskTurnGame via SharedData lookup + vtable dispatch.
|
|
|
|
| 991 |
girder_visual(landscape, girder_x >> 16, girder_y >> 16, sprite1, sprite2);
|
| 992 |
|
| 993 |
// Increment WormEntry counters
|
| 994 |
+
let arena = crate::engine::ddgame::TeamArenaRef::from_ptr(&raw mut (*ddgame).team_arena);
|
|
|
|
| 995 |
let team_index = (*worm).team_index as usize;
|
| 996 |
let worm_index = (*worm).worm_index as usize;
|
| 997 |
let entry = arena.team_worm_mut(team_index, worm_index);
|
crates/openwa-debugui/src/app.rs
CHANGED
|
@@ -52,7 +52,11 @@ unsafe fn entity_label(addr: u32) -> String {
|
|
| 52 |
/// Returns a pointer to DDGame, or None if not in-game.
|
| 53 |
unsafe fn get_ddgame() -> Option<*const DDGame> {
|
| 54 |
let ptr = game_session::get_ddgame();
|
| 55 |
-
if ptr.is_null() {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
/// Unlock all weapons: set ammo to unlimited (-1) and delays to 0 for all teams.
|
|
|
|
| 52 |
/// Returns a pointer to DDGame, or None if not in-game.
|
| 53 |
unsafe fn get_ddgame() -> Option<*const DDGame> {
|
| 54 |
let ptr = game_session::get_ddgame();
|
| 55 |
+
if ptr.is_null() {
|
| 56 |
+
None
|
| 57 |
+
} else {
|
| 58 |
+
Some(ptr)
|
| 59 |
+
}
|
| 60 |
}
|
| 61 |
|
| 62 |
/// Unlock all weapons: set ammo to unlimited (-1) and delays to 0 for all teams.
|
crates/openwa-test-runner/src/main.rs
CHANGED
|
@@ -316,9 +316,7 @@ fn run_test(test: &TestCase, launcher: &Path, wa_exe: &Path, run_dir: &Path) ->
|
|
| 316 |
passed: false,
|
| 317 |
duration,
|
| 318 |
diff_lines: Vec::new(),
|
| 319 |
-
error: Some(format!(
|
| 320 |
-
"No output log generated (exit code: {exit_code})"
|
| 321 |
-
)),
|
| 322 |
crashed: None,
|
| 323 |
};
|
| 324 |
}
|
|
@@ -723,9 +721,7 @@ fn parse_trace_desync_args(argv: &[String]) -> TraceDesyncArgs {
|
|
| 723 |
i += 1;
|
| 724 |
}
|
| 725 |
let replay = replay.unwrap_or_else(|| {
|
| 726 |
-
eprintln!(
|
| 727 |
-
"Usage: openwa-test trace-desync <replay.WAgame> [--no-build] [--wa-path PATH]"
|
| 728 |
-
);
|
| 729 |
std::process::exit(1);
|
| 730 |
});
|
| 731 |
if replay.extension().and_then(|e| e.to_str()) != Some("WAgame") {
|
|
@@ -868,14 +864,8 @@ fn compare_hashes(baseline: &[FrameHash], hooks: &[FrameHash]) {
|
|
| 868 |
let b = &baseline[idx];
|
| 869 |
let h = &hooks[idx];
|
| 870 |
println!("{}", red(&format!("DESYNC at frame {}!", b.frame)));
|
| 871 |
-
println!(
|
| 872 |
-
|
| 873 |
-
b.checksum_a, b.checksum_b
|
| 874 |
-
);
|
| 875 |
-
println!(
|
| 876 |
-
" hooks: A={:08X} B={:08X}",
|
| 877 |
-
h.checksum_a, h.checksum_b
|
| 878 |
-
);
|
| 879 |
if idx > 0 {
|
| 880 |
let prev = &baseline[idx - 1];
|
| 881 |
println!(
|
|
|
|
| 316 |
passed: false,
|
| 317 |
duration,
|
| 318 |
diff_lines: Vec::new(),
|
| 319 |
+
error: Some(format!("No output log generated (exit code: {exit_code})")),
|
|
|
|
|
|
|
| 320 |
crashed: None,
|
| 321 |
};
|
| 322 |
}
|
|
|
|
| 721 |
i += 1;
|
| 722 |
}
|
| 723 |
let replay = replay.unwrap_or_else(|| {
|
| 724 |
+
eprintln!("Usage: openwa-test trace-desync <replay.WAgame> [--no-build] [--wa-path PATH]");
|
|
|
|
|
|
|
| 725 |
std::process::exit(1);
|
| 726 |
});
|
| 727 |
if replay.extension().and_then(|e| e.to_str()) != Some("WAgame") {
|
|
|
|
| 864 |
let b = &baseline[idx];
|
| 865 |
let h = &hooks[idx];
|
| 866 |
println!("{}", red(&format!("DESYNC at frame {}!", b.frame)));
|
| 867 |
+
println!(" baseline: A={:08X} B={:08X}", b.checksum_a, b.checksum_b);
|
| 868 |
+
println!(" hooks: A={:08X} B={:08X}", h.checksum_a, h.checksum_b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 869 |
if idx > 0 {
|
| 870 |
let prev = &baseline[idx - 1];
|
| 871 |
println!(
|
crates/openwa-wormkit/src/replacements/headless.rs
CHANGED
|
@@ -116,9 +116,8 @@ pub fn install() -> Result<(), String> {
|
|
| 116 |
// semaphore per-PID. Without this, concurrent WA.exe instances detect
|
| 117 |
// each other and skip initialization or show warnings.
|
| 118 |
unsafe {
|
| 119 |
-
let k32 =
|
| 120 |
-
b"kernel32.dll\0".as_ptr()
|
| 121 |
-
);
|
| 122 |
if !k32.is_null() {
|
| 123 |
let proc = windows_sys::Win32::System::LibraryLoader::GetProcAddress(
|
| 124 |
k32,
|
|
|
|
| 116 |
// semaphore per-PID. Without this, concurrent WA.exe instances detect
|
| 117 |
// each other and skip initialization or show warnings.
|
| 118 |
unsafe {
|
| 119 |
+
let k32 =
|
| 120 |
+
windows_sys::Win32::System::LibraryLoader::GetModuleHandleA(b"kernel32.dll\0".as_ptr());
|
|
|
|
| 121 |
if !k32.is_null() {
|
| 122 |
let proc = windows_sys::Win32::System::LibraryLoader::GetProcAddress(
|
| 123 |
k32,
|
crates/openwa-wormkit/src/replacements/mod.rs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
mod config;
|
| 2 |
-
pub(crate) mod debug_utils;
|
| 3 |
mod ddgame_init;
|
|
|
|
| 4 |
mod display;
|
| 5 |
pub(crate) mod file_isolation;
|
| 6 |
mod frame_hook;
|
|
|
|
| 1 |
mod config;
|
|
|
|
| 2 |
mod ddgame_init;
|
| 3 |
+
pub(crate) mod debug_utils;
|
| 4 |
mod display;
|
| 5 |
pub(crate) mod file_isolation;
|
| 6 |
mod frame_hook;
|
crates/openwa-wormkit/src/replacements/replay_test.rs
CHANGED
|
@@ -142,8 +142,7 @@ pub fn write_gameplay_report() {
|
|
| 142 |
teams
|
| 143 |
));
|
| 144 |
} else if frames > 0 {
|
| 145 |
-
let _ =
|
| 146 |
-
log_line("[GAMEPLAY FAIL] Match started - never detected multiple alive teams");
|
| 147 |
} else {
|
| 148 |
let _ = log_line("[GAMEPLAY FAIL] Match started - game never initialized");
|
| 149 |
}
|
|
@@ -161,8 +160,7 @@ pub fn write_gameplay_report() {
|
|
| 161 |
outcome, end_frame
|
| 162 |
));
|
| 163 |
} else if started {
|
| 164 |
-
let _ =
|
| 165 |
-
log_line("[GAMEPLAY FAIL] Match completed - match started but never finished");
|
| 166 |
} else {
|
| 167 |
let _ = log_line("[GAMEPLAY FAIL] Match completed - match never started");
|
| 168 |
}
|
|
|
|
| 142 |
teams
|
| 143 |
));
|
| 144 |
} else if frames > 0 {
|
| 145 |
+
let _ = log_line("[GAMEPLAY FAIL] Match started - never detected multiple alive teams");
|
|
|
|
| 146 |
} else {
|
| 147 |
let _ = log_line("[GAMEPLAY FAIL] Match started - game never initialized");
|
| 148 |
}
|
|
|
|
| 160 |
outcome, end_frame
|
| 161 |
));
|
| 162 |
} else if started {
|
| 163 |
+
let _ = log_line("[GAMEPLAY FAIL] Match completed - match started but never finished");
|
|
|
|
| 164 |
} else {
|
| 165 |
let _ = log_line("[GAMEPLAY FAIL] Match completed - match never started");
|
| 166 |
}
|
crates/openwa-wormkit/src/replacements/trace_desync.rs
CHANGED
|
@@ -62,8 +62,8 @@ pub fn install() -> Result<(), String> {
|
|
| 62 |
}
|
| 63 |
|
| 64 |
// Determine log file path
|
| 65 |
-
let path =
|
| 66 |
-
.unwrap_or_else(|_| "frame_hashes.log".to_string());
|
| 67 |
|
| 68 |
let file = std::fs::File::create(&path)
|
| 69 |
.map_err(|e| format!("Failed to create hash log {path}: {e}"))?;
|
|
|
|
| 62 |
}
|
| 63 |
|
| 64 |
// Determine log file path
|
| 65 |
+
let path =
|
| 66 |
+
std::env::var("OPENWA_TRACE_HASH_PATH").unwrap_or_else(|_| "frame_hashes.log".to_string());
|
| 67 |
|
| 68 |
let file = std::fs::File::create(&path)
|
| 69 |
.map_err(|e| format!("Failed to create hash log {path}: {e}"))?;
|
crates/openwa-wormkit/src/replacements/weapon_release.rs
CHANGED
|
@@ -68,16 +68,7 @@ unsafe extern "cdecl" fn spawn_effect_cdecl(
|
|
| 68 |
scale: Fixed,
|
| 69 |
) {
|
| 70 |
wr::spawn_effect(
|
| 71 |
-
worm,
|
| 72 |
-
constant,
|
| 73 |
-
speed_x,
|
| 74 |
-
speed_y,
|
| 75 |
-
rng_scaled,
|
| 76 |
-
rng_offset,
|
| 77 |
-
palette,
|
| 78 |
-
state_flag,
|
| 79 |
-
size,
|
| 80 |
-
scale,
|
| 81 |
);
|
| 82 |
}
|
| 83 |
|
|
|
|
| 68 |
scale: Fixed,
|
| 69 |
) {
|
| 70 |
wr::spawn_effect(
|
| 71 |
+
worm, constant, speed_x, speed_y, rng_scaled, rng_offset, palette, state_flag, size, scale,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
);
|
| 73 |
}
|
| 74 |
|