feat: port InitTeamScoring + InitAllianceData to Rust (Group B)
Browse filesTwo team/alliance initialization sub-functions ported as hooks:
- CGameTask__InitTeamScoring (0x528510): fastcall(ECX=wrapper).
Initializes 7 parallel scoring arrays (13 elements each),
sets starting-team flags, and zeros CTask sub-objects.
65 lines, zero dependencies.
- CGameTask__InitAllianceData (0x5262D0): usercall(EAX=wrapper).
Builds alliance bitmask table from scheme data, sets per-team
scoring flags in DDGame+0x7E70, handles game_version >= 0x83
alliance changes.
80 lines, zero dependencies.
Both named in Ghidra. Headful + headless replay tests PASS.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crates/openwa-core/src/address.rs
CHANGED
|
@@ -354,6 +354,10 @@ pub mod va {
|
|
| 354 |
pub const SPRITE_GFX_TABLE_INIT: u32 = 0x0054_1620;
|
| 355 |
/// RingBuffer__Init (0x541060): usercall(EAX=capacity, ESI=struct), plain RET.
|
| 356 |
pub const RING_BUFFER_INIT: u32 = 0x0054_1060;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
/// DDGame__InitDisplayFinal_Maybe (0x56A830): display finalization for non-headless.
|
| 358 |
pub const DDGAME_INIT_DISPLAY_FINAL: u32 = 0x0056_A830;
|
| 359 |
/// PCLandscape__Constructor (0x57ACB0): constructs 0xB44-byte landscape object.
|
|
|
|
| 354 |
pub const SPRITE_GFX_TABLE_INIT: u32 = 0x0054_1620;
|
| 355 |
/// RingBuffer__Init (0x541060): usercall(EAX=capacity, ESI=struct), plain RET.
|
| 356 |
pub const RING_BUFFER_INIT: u32 = 0x0054_1060;
|
| 357 |
+
/// CGameTask__InitTeamScoring (0x528510): fastcall(ECX=wrapper), plain RET.
|
| 358 |
+
pub const INIT_TEAM_SCORING: u32 = 0x0052_8510;
|
| 359 |
+
/// CGameTask__InitAllianceData (0x5262D0): usercall(EAX=wrapper), plain RET.
|
| 360 |
+
pub const INIT_ALLIANCE_DATA: u32 = 0x0052_62D0;
|
| 361 |
/// DDGame__InitDisplayFinal_Maybe (0x56A830): display finalization for non-headless.
|
| 362 |
pub const DDGAME_INIT_DISPLAY_FINAL: u32 = 0x0056_A830;
|
| 363 |
/// PCLandscape__Constructor (0x57ACB0): constructs 0xB44-byte landscape object.
|
crates/openwa-core/src/engine/game_state_init.rs
CHANGED
|
@@ -50,3 +50,276 @@ pub unsafe fn ring_buffer_init(struct_ptr: *mut u8, capacity: u32) {
|
|
| 50 |
*s.add(5) = 0; // field 5
|
| 51 |
*s.add(6) = 0; // field 6
|
| 52 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
*s.add(5) = 0; // field 5
|
| 51 |
*s.add(6) = 0; // field 6
|
| 52 |
}
|
| 53 |
+
|
| 54 |
+
/// Maximum number of teams (13 slots: 6 real + sentinels/padding).
|
| 55 |
+
const MAX_TEAMS: usize = 13;
|
| 56 |
+
|
| 57 |
+
/// Team entry stride in GameInfo (3000 bytes per team slot).
|
| 58 |
+
const TEAM_ENTRY_STRIDE: usize = 3000;
|
| 59 |
+
|
| 60 |
+
/// Helper: read the GameInfo pointer from a DDGameWrapper pointer.
|
| 61 |
+
///
|
| 62 |
+
/// Chain: wrapper+0x488 β DDGame, DDGame+0x24 β GameInfo.
|
| 63 |
+
#[inline]
|
| 64 |
+
unsafe fn game_info_from_wrapper(wrapper: *mut u8) -> *mut u8 {
|
| 65 |
+
let ddgame = *(wrapper.add(0x488) as *const *mut u8);
|
| 66 |
+
*(ddgame.add(0x24) as *const *mut u8)
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/// Helper: read the DDGame pointer from a DDGameWrapper pointer.
|
| 70 |
+
#[inline]
|
| 71 |
+
unsafe fn ddgame_from_wrapper(wrapper: *mut u8) -> *mut u8 {
|
| 72 |
+
*(wrapper.add(0x488) as *const *mut u8)
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/// Pure Rust implementation of CGameTask_InitTeamScoring_Maybe (0x528510).
|
| 76 |
+
///
|
| 77 |
+
/// Convention: fastcall(ECX=wrapper), plain RET.
|
| 78 |
+
///
|
| 79 |
+
/// Initializes 7 parallel u32 arrays (13 elements each) in CGameTask, then
|
| 80 |
+
/// sets the starting-team flag, initializes team task pointer flags based on
|
| 81 |
+
/// game mode (training vs normal), and zeros CTask sub-object fields.
|
| 82 |
+
///
|
| 83 |
+
/// # CGameTask array layout (all 13 Γ u32):
|
| 84 |
+
/// - +0x0F4..+0x128: array_0 β zeroed
|
| 85 |
+
/// - +0x128..+0x15C: array_1 β zeroed
|
| 86 |
+
/// - +0x15C..+0x190: array_2 β scoring_param_a * 50
|
| 87 |
+
/// - +0x190..+0x1C4: array_3 β zeroed
|
| 88 |
+
/// - +0x1C4..+0x1F8: array_4 β scoring_param_b * 50
|
| 89 |
+
/// - +0x1F8..+0x22C: array_5 β scoring_param_b * 50
|
| 90 |
+
/// - +0x2BC..+0x2F0: array_6 β set to 1
|
| 91 |
+
///
|
| 92 |
+
/// # Other fields:
|
| 93 |
+
/// - +0x128[starting_team]: set to 1 (starting team marker in array_1)
|
| 94 |
+
/// - +0x22C[0..team_count]: team activity flags (-1 normal, -2 training)
|
| 95 |
+
/// - +0x054[0..team_count]: CTask pointers β sub-fields zeroed if non-null
|
| 96 |
+
pub unsafe fn init_team_scoring(wrapper: *mut u8) {
|
| 97 |
+
let game_info = game_info_from_wrapper(wrapper);
|
| 98 |
+
|
| 99 |
+
// GameInfo+0xD788: scoring_param_a (u16)
|
| 100 |
+
// GameInfo+0xD78A: scoring_param_b (u16)
|
| 101 |
+
let scoring_param_a = *(game_info.add(0xD788) as *const u16) as u32;
|
| 102 |
+
let scoring_param_b = *(game_info.add(0xD78A) as *const u16) as u32;
|
| 103 |
+
let value_a = scoring_param_a * 50; // uVar1 * 0x32
|
| 104 |
+
let value_b = scoring_param_b * 50; // iVar4
|
| 105 |
+
|
| 106 |
+
// Initialize 7 parallel arrays (13 elements each).
|
| 107 |
+
// puVar3 starts at wrapper+0x128, indexed relative to that.
|
| 108 |
+
let base = wrapper.add(0x128) as *mut u32;
|
| 109 |
+
for i in 0..MAX_TEAMS {
|
| 110 |
+
let p = base.add(i);
|
| 111 |
+
*p.sub(0xd) = 0; // +0x0F4[i]: array_0 β zeroed
|
| 112 |
+
*p = 0; // +0x128[i]: array_1 β zeroed
|
| 113 |
+
*p.add(0xd) = value_a; // +0x15C[i]: array_2 β scoring_param_a * 50
|
| 114 |
+
*p.add(0x27) = value_b; // +0x1C4[i]: array_4 β scoring_param_b * 50
|
| 115 |
+
*p.add(0x34) = value_b; // +0x1F8[i]: array_5 β scoring_param_b * 50
|
| 116 |
+
*p.add(0x1a) = 0; // +0x190[i]: array_3 β zeroed
|
| 117 |
+
*p.add(99) = 1; // +0x2BC[i]: array_6 β set to 1
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
// Mark the starting team in array_1: wrapper+0x128[starting_team] = 1
|
| 121 |
+
// GameInfo+0xD9DC: starting team index (i8)
|
| 122 |
+
let starting_team = *(game_info.add(0xD9DC) as *const i8) as i32;
|
| 123 |
+
*(base.add(starting_team as usize)) = 1;
|
| 124 |
+
|
| 125 |
+
// GameInfo+0xD9DD: mode flag (i8, negative = training/replay mode)
|
| 126 |
+
let mode_flag = *(game_info.add(0xD9DD) as *const i8);
|
| 127 |
+
|
| 128 |
+
// GameInfo+0x0000: first byte = total team count (num_teams, u8)
|
| 129 |
+
let num_teams = *game_info as u8 as i32;
|
| 130 |
+
|
| 131 |
+
// Team activity flags at wrapper+0x22C (one u32 per team)
|
| 132 |
+
let flags_base = wrapper.add(0x22C) as *mut u32;
|
| 133 |
+
|
| 134 |
+
if mode_flag < 0 {
|
| 135 |
+
// Training/replay mode: set all flags to -2 (0xFFFFFFFE)
|
| 136 |
+
if num_teams > 0 {
|
| 137 |
+
for i in 0..num_teams as usize {
|
| 138 |
+
*flags_base.add(i) = 0xFFFF_FFFE;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
// For each active team slot in GameInfo, clear the flag to 0
|
| 143 |
+
// GameInfo+0x44C: team count for alliance data (u8)
|
| 144 |
+
let game_info2 = game_info_from_wrapper(wrapper);
|
| 145 |
+
let alliance_team_count = *game_info2.add(0x44C) as u8 as i32;
|
| 146 |
+
if alliance_team_count > 0 {
|
| 147 |
+
let mut offset: usize = 0;
|
| 148 |
+
for _ in 0..alliance_team_count {
|
| 149 |
+
// GameInfo+0x450 + team_index*3000: alliance group (i8)
|
| 150 |
+
let alliance_group = *(game_info2.add(0x450 + offset) as *const i8) as i32;
|
| 151 |
+
if alliance_group >= 0 {
|
| 152 |
+
*flags_base.add(alliance_group as usize) = 0;
|
| 153 |
+
}
|
| 154 |
+
// Re-read game_info in case pointer chain changed (matches original)
|
| 155 |
+
let gi = game_info_from_wrapper(wrapper);
|
| 156 |
+
let _ = gi; // original re-reads but we already have the value
|
| 157 |
+
offset += TEAM_ENTRY_STRIDE;
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
} else {
|
| 161 |
+
// Normal mode: set all flags to -1 (0xFFFFFFFF)
|
| 162 |
+
if num_teams > 0 {
|
| 163 |
+
for i in 0..num_teams as usize {
|
| 164 |
+
*flags_base.add(i) = 0xFFFF_FFFF;
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
// Set starting team's flag to 1
|
| 169 |
+
// GameInfo+0xD9DD: starting team index for flags (i8, reuse mode_flag which is the same field)
|
| 170 |
+
let starting_flag_team = *(game_info_from_wrapper(wrapper).add(0xD9DD) as *const i8) as i32;
|
| 171 |
+
*flags_base.add(starting_flag_team as usize) = 1;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
// Zero CTask sub-object fields for each team's task pointer
|
| 175 |
+
// wrapper+0x54[i] = CTask pointer, clear offsets +0x08..+0x18 (5 DWORDs)
|
| 176 |
+
let num_teams2 = *game_info_from_wrapper(wrapper) as u8 as i32;
|
| 177 |
+
if num_teams2 > 0 {
|
| 178 |
+
let task_ptrs = wrapper.add(0x54) as *mut *mut u8;
|
| 179 |
+
for i in 0..num_teams2 as usize {
|
| 180 |
+
let task = *task_ptrs.add(i);
|
| 181 |
+
if !task.is_null() {
|
| 182 |
+
*(task.add(0x18) as *mut u32) = 0;
|
| 183 |
+
*(task.add(0x14) as *mut u32) = 0;
|
| 184 |
+
*(task.add(0x10) as *mut u32) = 0;
|
| 185 |
+
*(task.add(0x0C) as *mut u32) = 0;
|
| 186 |
+
*(task.add(0x08) as *mut u32) = 0;
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/// Pure Rust implementation of CGameTask_InitAllianceData_Maybe (0x5262D0).
|
| 193 |
+
///
|
| 194 |
+
/// Convention: usercall(EAX=wrapper), plain RET.
|
| 195 |
+
///
|
| 196 |
+
/// Initializes alliance bitmask table, per-team scoring flags in DDGame,
|
| 197 |
+
/// and an auxiliary alliance array.
|
| 198 |
+
///
|
| 199 |
+
/// # Layout:
|
| 200 |
+
/// - wrapper+0x350..+0x384: 13 Γ u32 alliance bitmasks (one per alliance group)
|
| 201 |
+
/// - DDGame+0x7E70..+0x7E88: 6 Γ u32 per-team scoring flags
|
| 202 |
+
/// - wrapper+0x3AC..: auxiliary array of non-starting-team alliance IDs (+0x10)
|
| 203 |
+
///
|
| 204 |
+
/// # GameInfo fields used:
|
| 205 |
+
/// - +0x000: num_teams (u8, first byte)
|
| 206 |
+
/// - +0x44C: alliance_team_count (u8)
|
| 207 |
+
/// - +0x450 + i*3000: alliance_group (i8) for team i
|
| 208 |
+
/// - +0x451 + i*3000: alliance_id (u8) for team i
|
| 209 |
+
/// - +0xD778: game_version (i32)
|
| 210 |
+
/// - +0xD9DC: starting_team_index (i8)
|
| 211 |
+
///
|
| 212 |
+
/// - wrapper+0x490: first byte used as scoring override value
|
| 213 |
+
pub unsafe fn init_alliance_data(wrapper: *mut u8) {
|
| 214 |
+
// Zero 13 alliance bitmasks at wrapper+0x350..+0x384
|
| 215 |
+
for i in 0..MAX_TEAMS {
|
| 216 |
+
*(wrapper.add(0x350) as *mut u32).add(i) = 0;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
// Build alliance bitmasks: for each team, set bit (alliance_id & 0x1F)
|
| 220 |
+
// in bitmask[alliance_group]
|
| 221 |
+
let game_info = game_info_from_wrapper(wrapper);
|
| 222 |
+
let num_teams = *game_info as u8 as i32;
|
| 223 |
+
|
| 224 |
+
// Global DAT_007a087c+4 = 0 (static variable, offset 0x7A0880)
|
| 225 |
+
// We skip this β it's a global we don't own. The original sets it but
|
| 226 |
+
// it appears unused in the init path.
|
| 227 |
+
|
| 228 |
+
let alliance_team_count = *game_info.add(0x44C) as u8 as i32;
|
| 229 |
+
if num_teams != 0 && alliance_team_count > 0 {
|
| 230 |
+
let mut offset: usize = 0;
|
| 231 |
+
for _ in 0..alliance_team_count {
|
| 232 |
+
let gi = game_info_from_wrapper(wrapper);
|
| 233 |
+
let alliance_group = *(gi.add(0x450 + offset) as *const i8) as i32;
|
| 234 |
+
let alliance_id = *(gi.add(0x451 + offset) as *const u8);
|
| 235 |
+
|
| 236 |
+
if alliance_group >= 0 {
|
| 237 |
+
let bitmask = (wrapper.add(0x350) as *mut u32).add(alliance_group as usize);
|
| 238 |
+
*bitmask |= 1u32 << (alliance_id & 0x1F);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
offset += TEAM_ENTRY_STRIDE;
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
// Zero 6 per-team scoring flags at DDGame+0x7E70..+0x7E88
|
| 246 |
+
let ddgame = ddgame_from_wrapper(wrapper);
|
| 247 |
+
for i in 0..6u32 {
|
| 248 |
+
*(ddgame.add(0x7E70) as *mut u32).add(i as usize) = 0;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
// Build scoring flags and auxiliary alliance array
|
| 252 |
+
let game_info = game_info_from_wrapper(wrapper);
|
| 253 |
+
let alliance_team_count = *game_info.add(0x44C) as u8 as i32;
|
| 254 |
+
|
| 255 |
+
// Local tracking: which alliance IDs we've already added to auxiliary array
|
| 256 |
+
let mut seen: [u8; 6] = [0; 6]; // local_8[0..6], indexed by alliance_id
|
| 257 |
+
let mut aux_count: usize = 0; // index into wrapper+0x3AC auxiliary array
|
| 258 |
+
|
| 259 |
+
if alliance_team_count > 0 {
|
| 260 |
+
let mut team_offset: usize = 0;
|
| 261 |
+
|
| 262 |
+
for team_idx in 0..alliance_team_count {
|
| 263 |
+
let gi = game_info_from_wrapper(wrapper);
|
| 264 |
+
let alliance_group = *(gi.add(0x450 + team_offset) as *const i8) as i32;
|
| 265 |
+
let alliance_id = *(gi.add(0x451 + team_offset) as *const u8) as u32;
|
| 266 |
+
|
| 267 |
+
let ddgame = ddgame_from_wrapper(wrapper);
|
| 268 |
+
let scoring_flag = (ddgame as *mut u32).add((0x7E70 / 4) + team_idx as usize);
|
| 269 |
+
|
| 270 |
+
if alliance_group < 0 {
|
| 271 |
+
// No alliance: flag = value from wrapper+0x490 (i8 sign-extended)
|
| 272 |
+
let override_val = *(wrapper.add(0x490) as *const i8) as i32;
|
| 273 |
+
*scoring_flag = override_val as u32;
|
| 274 |
+
} else {
|
| 275 |
+
// Check if this team is allied with the starting team
|
| 276 |
+
let gi = game_info_from_wrapper(wrapper);
|
| 277 |
+
let num_teams_byte = *gi as u8;
|
| 278 |
+
let override_byte = *(wrapper.add(0x490) as *const u8);
|
| 279 |
+
|
| 280 |
+
if num_teams_byte == 0 || override_byte != 0 {
|
| 281 |
+
// No teams or override set: flag = 1
|
| 282 |
+
*scoring_flag = 1;
|
| 283 |
+
} else {
|
| 284 |
+
let game_version = *(gi.add(0xD778) as *const i32);
|
| 285 |
+
let starting_team = *(gi.add(0xD9DC) as *const i8) as i32;
|
| 286 |
+
|
| 287 |
+
let team_bitmask: u32 = if game_version < 0x83 {
|
| 288 |
+
// Old version: use full alliance bitmask
|
| 289 |
+
*((wrapper.add(0x350) as *const u32).add(alliance_group as usize))
|
| 290 |
+
} else {
|
| 291 |
+
// New version: just the single team's bit
|
| 292 |
+
1u32 << (alliance_id & 0x1F)
|
| 293 |
+
};
|
| 294 |
+
|
| 295 |
+
let starting_bitmask =
|
| 296 |
+
*((wrapper.add(0x350) as *const u32).add(starting_team as usize));
|
| 297 |
+
|
| 298 |
+
if (starting_bitmask & team_bitmask) != 0 {
|
| 299 |
+
// Same alliance as starting team: flag = 1
|
| 300 |
+
*scoring_flag = 1;
|
| 301 |
+
}
|
| 302 |
+
// else: flag stays 0 (already zeroed above)
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
// Build auxiliary array for non-starting-team alliances
|
| 306 |
+
let gi2 = game_info_from_wrapper(wrapper);
|
| 307 |
+
let starting_team2 = *(gi2.add(0xD9DC) as *const i8) as i32;
|
| 308 |
+
|
| 309 |
+
if alliance_group != starting_team2 && seen[alliance_id as usize] == 0 {
|
| 310 |
+
let starting_bitmask2 =
|
| 311 |
+
*((wrapper.add(0x350) as *const u32).add(starting_team2 as usize));
|
| 312 |
+
if (starting_bitmask2 & (1u32 << (alliance_id & 0x1F))) != 0 {
|
| 313 |
+
// Store alliance_id + 0x10 into auxiliary array
|
| 314 |
+
let aux_ptr = (wrapper.add(0x3AC) as *mut u32).add(aux_count);
|
| 315 |
+
*aux_ptr = alliance_id + 0x10;
|
| 316 |
+
aux_count += 1;
|
| 317 |
+
seen[alliance_id as usize] = 1;
|
| 318 |
+
}
|
| 319 |
+
}
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
team_offset += TEAM_ENTRY_STRIDE;
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
}
|
crates/openwa-wormkit/src/replacements/ddgame_init.rs
CHANGED
|
@@ -18,7 +18,9 @@ use openwa_core::engine::ddgame::{
|
|
| 18 |
bit_grid_init, ddgame_init_fields, ddgame_init_render_indices, display_layer_color_init,
|
| 19 |
gfx_dir_find_entry, gfx_dir_load_dir, gfx_resource_create, DDGame,
|
| 20 |
};
|
| 21 |
-
use openwa_core::engine::game_state_init::{
|
|
|
|
|
|
|
| 22 |
use openwa_core::engine::DDGameWrapper;
|
| 23 |
|
| 24 |
// βββ DDGame__InitFields (0x526120) ββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -213,6 +215,18 @@ pub fn install() -> Result<(), String> {
|
|
| 213 |
va::RING_BUFFER_INIT,
|
| 214 |
ring_buffer_init_trampoline as *const (),
|
| 215 |
)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
}
|
| 217 |
|
| 218 |
Ok(())
|
|
@@ -245,3 +259,30 @@ unsafe extern "C" fn ring_buffer_init_trampoline() {
|
|
| 245 |
impl_fn = sym impl_ring_buffer_init,
|
| 246 |
);
|
| 247 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
bit_grid_init, ddgame_init_fields, ddgame_init_render_indices, display_layer_color_init,
|
| 19 |
gfx_dir_find_entry, gfx_dir_load_dir, gfx_resource_create, DDGame,
|
| 20 |
};
|
| 21 |
+
use openwa_core::engine::game_state_init::{
|
| 22 |
+
init_alliance_data, init_team_scoring, ring_buffer_init, sprite_gfx_table_init,
|
| 23 |
+
};
|
| 24 |
use openwa_core::engine::DDGameWrapper;
|
| 25 |
|
| 26 |
// βββ DDGame__InitFields (0x526120) ββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 215 |
va::RING_BUFFER_INIT,
|
| 216 |
ring_buffer_init_trampoline as *const (),
|
| 217 |
)?;
|
| 218 |
+
|
| 219 |
+
hook::install(
|
| 220 |
+
"CGameTask__InitTeamScoring",
|
| 221 |
+
va::INIT_TEAM_SCORING,
|
| 222 |
+
init_team_scoring_trampoline as *const (),
|
| 223 |
+
)?;
|
| 224 |
+
|
| 225 |
+
hook::install(
|
| 226 |
+
"CGameTask__InitAllianceData",
|
| 227 |
+
va::INIT_ALLIANCE_DATA,
|
| 228 |
+
init_alliance_data_trampoline as *const (),
|
| 229 |
+
)?;
|
| 230 |
}
|
| 231 |
|
| 232 |
Ok(())
|
|
|
|
| 259 |
impl_fn = sym impl_ring_buffer_init,
|
| 260 |
);
|
| 261 |
}
|
| 262 |
+
|
| 263 |
+
// βββ CGameTask__InitTeamScoring (0x528510) ββββββββββββββββββββββββββββββββββ
|
| 264 |
+
// Convention: fastcall(ECX=wrapper), plain RET.
|
| 265 |
+
|
| 266 |
+
unsafe extern "fastcall" fn init_team_scoring_trampoline(wrapper: u32, _edx: u32) {
|
| 267 |
+
init_team_scoring(wrapper as *mut u8);
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
// βββ CGameTask__InitAllianceData (0x5262D0) βββββββββββββββββββββββββββββββββ
|
| 271 |
+
// Convention: usercall(EAX=wrapper), plain RET.
|
| 272 |
+
|
| 273 |
+
extern "cdecl" fn impl_init_alliance_data(wrapper: u32) {
|
| 274 |
+
unsafe { init_alliance_data(wrapper as *mut u8) }
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
#[unsafe(naked)]
|
| 278 |
+
unsafe extern "C" fn init_alliance_data_trampoline() {
|
| 279 |
+
core::arch::naked_asm!(
|
| 280 |
+
"push edx",
|
| 281 |
+
"push eax", // wrapper (EAX)
|
| 282 |
+
"call {impl_fn}",
|
| 283 |
+
"add esp, 4",
|
| 284 |
+
"pop edx",
|
| 285 |
+
"ret",
|
| 286 |
+
impl_fn = sym impl_init_alliance_data,
|
| 287 |
+
);
|
| 288 |
+
}
|