paavohtl Claude Opus 4.6 (1M context) commited on
Commit
6cbc730
·
1 Parent(s): 3f54e7c

refactor: call DSSound play functions directly instead of via vtable

Browse files

Since all 24 DSSound vtable slots are Rust, skip the vtable indirection
and transmute dance — call play_sound/play_sound_pooled as regular Rust
function calls from the dispatch hooks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

crates/openwa-wormkit/src/replacements/sound.rs CHANGED
@@ -11,7 +11,7 @@ use std::sync::atomic::Ordering;
11
 
12
  use openwa_core::address::va;
13
  use openwa_core::engine::{DDGame, DDGameWrapper, SoundQueueEntry};
14
- use openwa_core::audio::SoundId;
15
  use openwa_core::task::{CGameTask, CTask};
16
 
17
  use crate::hook;
@@ -172,11 +172,7 @@ unsafe extern "fastcall" fn hook_dispatch_global_sound(
172
  return 0;
173
  }
174
 
175
- // Call DSSound vtable slot 3: play_sound(sound_id, flags, volume, pitch, 0)
176
- let vtable = *(dssound as *const *const u32);
177
- let play_fn: unsafe extern "thiscall" fn(*mut u8, u32, u32, u32, u32, u32) -> u32 =
178
- core::mem::transmute(*vtable.add(3));
179
- play_fn(dssound as *mut u8, sound_id, flags, volume, pitch, 0)
180
  }
181
 
182
  /// PlaySoundPooled_Direct (0x546B50) — fastcall(ECX=unused, EDX=task) + 3 stack, RET 0xC.
@@ -206,11 +202,7 @@ unsafe extern "fastcall" fn hook_play_sound_pooled_direct(
206
  return 0;
207
  }
208
 
209
- // Call DSSound vtable slot 4: play_sound_pooled(param1, param2, 0x10000, param3, 0)
210
- let vtable = *(dssound as *const *const u32);
211
- let play_fn: unsafe extern "thiscall" fn(*mut u8, u32, u32, u32, u32, u32) -> u32 =
212
- core::mem::transmute(*vtable.add(4));
213
- play_fn(dssound as *mut u8, param1, param2, 0x10000, param3, 0)
214
  }
215
 
216
  // ============================================================
 
11
 
12
  use openwa_core::address::va;
13
  use openwa_core::engine::{DDGame, DDGameWrapper, SoundQueueEntry};
14
+ use openwa_core::audio::{SoundId, play_sound, play_sound_pooled};
15
  use openwa_core::task::{CGameTask, CTask};
16
 
17
  use crate::hook;
 
172
  return 0;
173
  }
174
 
175
+ play_sound(dssound, sound_id, flags as i32, volume as i32, pitch as i32, 0) as u32
 
 
 
 
176
  }
177
 
178
  /// PlaySoundPooled_Direct (0x546B50) — fastcall(ECX=unused, EDX=task) + 3 stack, RET 0xC.
 
202
  return 0;
203
  }
204
 
205
+ play_sound_pooled(dssound, param1, param2 as i32, 0x10000, param3 as i32, 0) as u32
 
 
 
 
206
  }
207
 
208
  // ============================================================