Initial
This commit is contained in:
1 parent
2cff35f215
commit
c8e6239d45
357 files changed
+253936
-74
No files matched your search
@@ -0,0 +1,42 @@
|
||||
|
||||
|
||||
use windows::Win32::Media::Audio::{IMMDeviceEnumerator, MMDeviceEnumerator, eConsole, eRender};
|
||||
use windows::Win32::System::Com::{
|
||||
CLSCTX_ALL, COINIT_MULTITHREADED, CoCreateInstance, CoInitializeEx, CoUninitialize,
|
||||
};
|
||||
use windows::core::HRESULT;
|
||||
|
||||
const E_NOTFOUND: HRESULT = HRESULT(0x8007_0490_u32 as i32);
|
||||
|
||||
pub const NO_OUTPUT_NOTICE: [&str; 3] = [
|
||||
"NO AUDIO OUTPUT: THE GAME FREEZES WHEN LOADING",
|
||||
"TURN ON A PLAYBACK DEVICE (EVEN A VIRTUAL ONE)",
|
||||
"IN WINDOWS SOUND SETTINGS, THEN START AGAIN",
|
||||
];
|
||||
|
||||
pub fn has_playback_device() -> Option<bool> {
|
||||
std::thread::Builder::new()
|
||||
.name("eonacat-xsbox audio output check".into())
|
||||
.spawn(ask)
|
||||
.ok()?
|
||||
.join()
|
||||
.ok()
|
||||
.flatten()
|
||||
}
|
||||
|
||||
fn ask() -> Option<bool> {
|
||||
|
||||
unsafe {
|
||||
CoInitializeEx(None, COINIT_MULTITHREADED).ok().ok()?;
|
||||
let answer = CoCreateInstance::<_, IMMDeviceEnumerator>(&MMDeviceEnumerator, None, CLSCTX_ALL)
|
||||
.ok()
|
||||
.and_then(|devices| match devices.GetDefaultAudioEndpoint(eRender, eConsole) {
|
||||
Ok(_) => Some(true),
|
||||
Err(e) if e.code() == E_NOTFOUND => Some(false),
|
||||
Err(_) => None,
|
||||
});
|
||||
CoUninitialize();
|
||||
answer
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user