refactor: replace GetTeamConfigName asm bridge with Rust lookup table
Browse filesPort the 49-entry jump table at 0x4A62A0 as a const array of team config
names (country names used for fanfare WAV paths). Eliminates the inline
asm call to WA.exe from hook_play_fanfare_default.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crates/openwa-wormkit/src/replacements/speech.rs
CHANGED
|
@@ -122,21 +122,63 @@ unsafe extern "cdecl" fn wav_player_play_raw(_player: u32, _volume: u32, _func:
|
|
| 122 |
}
|
| 123 |
|
| 124 |
// ============================================================
|
| 125 |
-
//
|
| 126 |
// ============================================================
|
| 127 |
|
| 128 |
-
///
|
| 129 |
-
///
|
| 130 |
-
///
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
// ============================================================
|
| 142 |
// PlayFeSfx replacement (0x4D7960)
|
|
@@ -174,16 +216,12 @@ unsafe extern "stdcall" fn hook_play_fe_sfx(sfx_name: *const u8) {
|
|
| 174 |
// Builds "<wa_path>\user\Fanfare\<name>.wav", plays on FANFARE_WAV_PLAYER.
|
| 175 |
|
| 176 |
unsafe extern "stdcall" fn hook_play_fanfare_default(team_type: u32) {
|
| 177 |
-
// Get the fanfare name
|
| 178 |
-
let
|
| 179 |
-
|
| 180 |
-
get_team_config_name(team_type - 1, name_buf.as_mut_ptr());
|
| 181 |
} else {
|
| 182 |
-
|
| 183 |
-
}
|
| 184 |
-
let name = CStr::from_ptr(name_buf.as_ptr() as *const i8)
|
| 185 |
-
.to_str()
|
| 186 |
-
.unwrap_or("Simple");
|
| 187 |
|
| 188 |
// Read WA data path
|
| 189 |
let wa_path = CStr::from_ptr(rb(va::WA_DATA_PATH) as *const i8)
|
|
|
|
| 122 |
}
|
| 123 |
|
| 124 |
// ============================================================
|
| 125 |
+
// Team config name lookup (port of GetTeamConfigName 0x4A62A0)
|
| 126 |
// ============================================================
|
| 127 |
|
| 128 |
+
/// Team config names indexed 0-48, matching WA.exe's jump table at 0x4A62A0.
|
| 129 |
+
/// Used for fanfare WAV file paths (e.g. "user\Fanfare\Finland.wav").
|
| 130 |
+
/// Note: "Leichtenstein" is WA's original misspelling — must match for file lookup.
|
| 131 |
+
const TEAM_CONFIG_NAMES: [&str; 49] = [
|
| 132 |
+
"UK", // 0
|
| 133 |
+
"Argentina", // 1
|
| 134 |
+
"Australia", // 2
|
| 135 |
+
"Austria", // 3
|
| 136 |
+
"Belgium", // 4
|
| 137 |
+
"Brazil", // 5
|
| 138 |
+
"Canada", // 6
|
| 139 |
+
"Croatia", // 7
|
| 140 |
+
"Simple", // 8
|
| 141 |
+
"Cyprus", // 9
|
| 142 |
+
"Simple", // 10
|
| 143 |
+
"Denmark", // 11
|
| 144 |
+
"Finland", // 12
|
| 145 |
+
"France", // 13
|
| 146 |
+
"Simple", // 14
|
| 147 |
+
"Germany", // 15
|
| 148 |
+
"Greece", // 16
|
| 149 |
+
"Simple", // 17
|
| 150 |
+
"Hungary", // 18
|
| 151 |
+
"Iceland", // 19
|
| 152 |
+
"India", // 20
|
| 153 |
+
"Simple", // 21
|
| 154 |
+
"Psycho Laugh", // 22
|
| 155 |
+
"Psycho Laugh", // 23
|
| 156 |
+
"Ireland", // 24
|
| 157 |
+
"Israel", // 25
|
| 158 |
+
"Italy", // 26
|
| 159 |
+
"Japan", // 27
|
| 160 |
+
"Leichtenstein", // 28
|
| 161 |
+
"Luxembourg", // 29
|
| 162 |
+
"Simple", // 30
|
| 163 |
+
"Malta", // 31
|
| 164 |
+
"Mexico", // 32
|
| 165 |
+
"Morocco", // 33
|
| 166 |
+
"Netherlands", // 34
|
| 167 |
+
"New Zealand", // 35
|
| 168 |
+
"Norway", // 36
|
| 169 |
+
"Poland", // 37
|
| 170 |
+
"Portugal", // 38
|
| 171 |
+
"Simple", // 39
|
| 172 |
+
"Romania", // 40
|
| 173 |
+
"Russia", // 41
|
| 174 |
+
"Singapore", // 42
|
| 175 |
+
"South Africa", // 43
|
| 176 |
+
"Spain", // 44
|
| 177 |
+
"Sweden", // 45
|
| 178 |
+
"Switzerland", // 46
|
| 179 |
+
"Turkey", // 47
|
| 180 |
+
"USA", // 48
|
| 181 |
+
];
|
| 182 |
|
| 183 |
// ============================================================
|
| 184 |
// PlayFeSfx replacement (0x4D7960)
|
|
|
|
| 216 |
// Builds "<wa_path>\user\Fanfare\<name>.wav", plays on FANFARE_WAV_PLAYER.
|
| 217 |
|
| 218 |
unsafe extern "stdcall" fn hook_play_fanfare_default(team_type: u32) {
|
| 219 |
+
// Get the fanfare name from lookup table (port of GetTeamConfigName 0x4A62A0)
|
| 220 |
+
let name = if (1..=49).contains(&team_type) {
|
| 221 |
+
TEAM_CONFIG_NAMES[(team_type - 1) as usize]
|
|
|
|
| 222 |
} else {
|
| 223 |
+
"Simple"
|
| 224 |
+
};
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
// Read WA data path
|
| 227 |
let wa_path = CStr::from_ptr(rb(va::WA_DATA_PATH) as *const i8)
|