audio_patches: catch all WinRT exceptions

This commit is contained in:
Hyper 2024-12-08 17:28:56 +00:00
parent ad862adc83
commit 7dfeb8eca9

View file

@ -20,24 +20,62 @@ static GlobalSystemMediaTransportControlsSessionManager GetSessionManager()
if (g_sessionManager) if (g_sessionManager)
return g_sessionManager; return g_sessionManager;
try
{
init_apartment(); init_apartment();
return g_sessionManager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get(); return g_sessionManager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get();
} }
catch (...)
{
printf("[*] Failed to retrieve GSMTC session manager: 0x%08X\n", to_hresult().value);
return nullptr;
}
}
static GlobalSystemMediaTransportControlsSession GetCurrentSession() static GlobalSystemMediaTransportControlsSession GetCurrentSession()
{ {
return GetSessionManager().GetCurrentSession(); auto sessionManager = GetSessionManager();
if (!sessionManager)
return nullptr;
try
{
return sessionManager.GetCurrentSession();
}
catch (...)
{
printf("[*] Failed to retrieve current GSMTC session: 0x%08X\n", to_hresult().value);
return nullptr;
}
} }
static bool IsExternalAudioPlaying() static GlobalSystemMediaTransportControlsSessionPlaybackInfo GetPlaybackInfo()
{ {
auto session = GetCurrentSession(); auto session = GetCurrentSession();
if (!session) if (!session)
return nullptr;
try
{
return session.GetPlaybackInfo();
}
catch (...)
{
printf("[*] Failed to retrieve GSMTC playback info: 0x%08X\n", to_hresult().value);
return nullptr;
}
}
static bool IsExternalAudioPlaying()
{
auto playbackInfo = GetPlaybackInfo();
if (!playbackInfo)
return false; return false;
return session.GetPlaybackInfo().PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing; return playbackInfo.PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing;
} }
int AudioPatches::m_isAttenuationSupported = -1; int AudioPatches::m_isAttenuationSupported = -1;