fix: invert load_wav return values to match original (1=success, 0=fail)
Browse filesWA's load_wav returns 1 on success and 0 on failure. Our Rust version
had them inverted, causing DSSound_LoadSpeechWAV to think every load
failed. This triggered fallback paths that assigned voice lines to
wrong slots β "ohdear" played on worm hurt instead of "oof/ow".
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crates/openwa-core/src/audio/dssound.rs
CHANGED
|
@@ -169,7 +169,7 @@ pub unsafe extern "thiscall" fn returns_1(_this: *mut DSSound) -> u32 { 1 }
|
|
| 169 |
/// This Rust version uses `hound` for WAV parsing and the `windows` crate
|
| 170 |
/// for DirectSound COM calls.
|
| 171 |
///
|
| 172 |
-
/// Returns
|
| 173 |
#[cfg(target_os = "windows")]
|
| 174 |
pub unsafe extern "thiscall" fn load_wav(
|
| 175 |
this: *mut DSSound,
|
|
@@ -188,23 +188,23 @@ pub unsafe extern "thiscall" fn load_wav(
|
|
| 188 |
// Slot index is used directly as array index (1-based, slot 0 unused).
|
| 189 |
let snd = &mut *this;
|
| 190 |
if snd.direct_sound == 0 {
|
| 191 |
-
return
|
| 192 |
}
|
| 193 |
let slot = slot_idx as usize;
|
| 194 |
if slot == 0 || slot > 499 || snd.channel_slots.get(slot).copied().unwrap_or(1) != 0 {
|
| 195 |
-
return
|
| 196 |
}
|
| 197 |
|
| 198 |
// Read path as C string.
|
| 199 |
let c_path = match core::ffi::CStr::from_ptr(path as *const i8).to_str() {
|
| 200 |
Ok(s) => s,
|
| 201 |
-
Err(_) => return
|
| 202 |
};
|
| 203 |
|
| 204 |
// Parse WAV with hound.
|
| 205 |
let reader = match hound::WavReader::open(c_path) {
|
| 206 |
Ok(r) => r,
|
| 207 |
-
Err(_) => return
|
| 208 |
};
|
| 209 |
let spec = reader.spec();
|
| 210 |
let sample_bytes = (spec.bits_per_sample / 8) as u32;
|
|
@@ -243,11 +243,11 @@ pub unsafe extern "thiscall" fn load_wav(
|
|
| 243 |
let ds: &IDirectSound = &*(&snd.direct_sound as *const Ptr32 as *const IDirectSound);
|
| 244 |
let mut buf: Option<IDirectSoundBuffer> = None;
|
| 245 |
if ds.CreateSoundBuffer(&desc, &mut buf, None).is_err() {
|
| 246 |
-
return
|
| 247 |
}
|
| 248 |
let buf = match buf {
|
| 249 |
Some(b) => b,
|
| 250 |
-
None => return
|
| 251 |
};
|
| 252 |
|
| 253 |
// Lock the buffer and fill with PCM data.
|
|
@@ -259,7 +259,7 @@ pub unsafe extern "thiscall" fn load_wav(
|
|
| 259 |
None, None,
|
| 260 |
DSBLOCK_ENTIREBUFFER,
|
| 261 |
).is_err() {
|
| 262 |
-
return
|
| 263 |
}
|
| 264 |
|
| 265 |
// Read raw PCM bytes from the WAV file (hound gives us the data region).
|
|
@@ -275,7 +275,7 @@ pub unsafe extern "thiscall" fn load_wav(
|
|
| 275 |
16 => {
|
| 276 |
let mut reader = match hound::WavReader::open(c_path) {
|
| 277 |
Ok(r) => r,
|
| 278 |
-
Err(_) => { let _ = buf.Unlock(audio_ptr1, audio_len1, None, 0); return
|
| 279 |
};
|
| 280 |
let mut offset = 0usize;
|
| 281 |
for sample in reader.samples::<i16>() {
|
|
@@ -290,7 +290,7 @@ pub unsafe extern "thiscall" fn load_wav(
|
|
| 290 |
8 => {
|
| 291 |
let mut reader = match hound::WavReader::open(c_path) {
|
| 292 |
Ok(r) => r,
|
| 293 |
-
Err(_) => { let _ = buf.Unlock(audio_ptr1, audio_len1, None, 0); return
|
| 294 |
};
|
| 295 |
let mut offset = 0usize;
|
| 296 |
for sample in reader.samples::<i16>() {
|
|
@@ -317,7 +317,7 @@ pub unsafe extern "thiscall" fn load_wav(
|
|
| 317 |
core::mem::forget(buf); // WA owns the COM reference
|
| 318 |
snd.total_bytes_loaded += data_len;
|
| 319 |
|
| 320 |
-
|
| 321 |
}
|
| 322 |
|
| 323 |
// ββ Construction ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 169 |
/// This Rust version uses `hound` for WAV parsing and the `windows` crate
|
| 170 |
/// for DirectSound COM calls.
|
| 171 |
///
|
| 172 |
+
/// Returns 1 on success, 0 on failure (matching original).
|
| 173 |
#[cfg(target_os = "windows")]
|
| 174 |
pub unsafe extern "thiscall" fn load_wav(
|
| 175 |
this: *mut DSSound,
|
|
|
|
| 188 |
// Slot index is used directly as array index (1-based, slot 0 unused).
|
| 189 |
let snd = &mut *this;
|
| 190 |
if snd.direct_sound == 0 {
|
| 191 |
+
return 0;
|
| 192 |
}
|
| 193 |
let slot = slot_idx as usize;
|
| 194 |
if slot == 0 || slot > 499 || snd.channel_slots.get(slot).copied().unwrap_or(1) != 0 {
|
| 195 |
+
return 0;
|
| 196 |
}
|
| 197 |
|
| 198 |
// Read path as C string.
|
| 199 |
let c_path = match core::ffi::CStr::from_ptr(path as *const i8).to_str() {
|
| 200 |
Ok(s) => s,
|
| 201 |
+
Err(_) => return 0,
|
| 202 |
};
|
| 203 |
|
| 204 |
// Parse WAV with hound.
|
| 205 |
let reader = match hound::WavReader::open(c_path) {
|
| 206 |
Ok(r) => r,
|
| 207 |
+
Err(_) => return 0,
|
| 208 |
};
|
| 209 |
let spec = reader.spec();
|
| 210 |
let sample_bytes = (spec.bits_per_sample / 8) as u32;
|
|
|
|
| 243 |
let ds: &IDirectSound = &*(&snd.direct_sound as *const Ptr32 as *const IDirectSound);
|
| 244 |
let mut buf: Option<IDirectSoundBuffer> = None;
|
| 245 |
if ds.CreateSoundBuffer(&desc, &mut buf, None).is_err() {
|
| 246 |
+
return 0;
|
| 247 |
}
|
| 248 |
let buf = match buf {
|
| 249 |
Some(b) => b,
|
| 250 |
+
None => return 0,
|
| 251 |
};
|
| 252 |
|
| 253 |
// Lock the buffer and fill with PCM data.
|
|
|
|
| 259 |
None, None,
|
| 260 |
DSBLOCK_ENTIREBUFFER,
|
| 261 |
).is_err() {
|
| 262 |
+
return 0;
|
| 263 |
}
|
| 264 |
|
| 265 |
// Read raw PCM bytes from the WAV file (hound gives us the data region).
|
|
|
|
| 275 |
16 => {
|
| 276 |
let mut reader = match hound::WavReader::open(c_path) {
|
| 277 |
Ok(r) => r,
|
| 278 |
+
Err(_) => { let _ = buf.Unlock(audio_ptr1, audio_len1, None, 0); return 0; }
|
| 279 |
};
|
| 280 |
let mut offset = 0usize;
|
| 281 |
for sample in reader.samples::<i16>() {
|
|
|
|
| 290 |
8 => {
|
| 291 |
let mut reader = match hound::WavReader::open(c_path) {
|
| 292 |
Ok(r) => r,
|
| 293 |
+
Err(_) => { let _ = buf.Unlock(audio_ptr1, audio_len1, None, 0); return 0; }
|
| 294 |
};
|
| 295 |
let mut offset = 0usize;
|
| 296 |
for sample in reader.samples::<i16>() {
|
|
|
|
| 317 |
core::mem::forget(buf); // WA owns the COM reference
|
| 318 |
snd.total_bytes_loaded += data_len;
|
| 319 |
|
| 320 |
+
1 // success (original returns 1 on success, 0 on failure)
|
| 321 |
}
|
| 322 |
|
| 323 |
// ββ Construction ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|