audio_patches: check if Windows version is supported

This commit is contained in:
Hyper 2024-11-21 02:45:03 +00:00
parent a2a086c52c
commit 811156bfae
9 changed files with 78 additions and 4 deletions

View file

@ -38,6 +38,7 @@ set(SWA_KERNEL_CXX_SOURCES
"kernel/xdm.cpp" "kernel/xdm.cpp"
"kernel/heap.cpp" "kernel/heap.cpp"
"kernel/memory.cpp" "kernel/memory.cpp"
"kernel/platform.cpp"
"kernel/xam.cpp" "kernel/xam.cpp"
"kernel/io/file_system.cpp" "kernel/io/file_system.cpp"
) )

View file

@ -14,6 +14,13 @@
#define SWA_API extern "C" SWA_DLLIMPORT #define SWA_API extern "C" SWA_DLLIMPORT
#endif #endif
#define PROC_ADDRESS(libraryName, procName) \
GetProcAddress(LoadLibrary(TEXT(libraryName)), procName)
#define LIB_FUNCTION(returnType, libraryName, procName, ...) \
typedef returnType _##procName(__VA_ARGS__); \
_##procName* procName = (_##procName*)PROC_ADDRESS(libraryName, #procName);
template<typename T> template<typename T>
void ByteSwap(T& value) void ByteSwap(T& value)
{ {
@ -66,4 +73,4 @@ constexpr size_t FirstBitLow(TValue value)
} }
return 0; return 0;
} }

View file

@ -0,0 +1,24 @@
#include <kernel/platform.h>
#if _WIN32
LIB_FUNCTION(LONG, "ntdll.dll", RtlGetVersion, PRTL_OSVERSIONINFOW);
#endif
PlatformVersion GetPlatformVersion()
{
auto result = PlatformVersion{};
#if _WIN32
OSVERSIONINFOEXW osvi = { 0 };
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
if (RtlGetVersion((PRTL_OSVERSIONINFOW)&osvi) != 0)
return result;
result.Major = osvi.dwMajorVersion;
result.Minor = osvi.dwMinorVersion;
result.Build = osvi.dwBuildNumber;
#endif
return result;
}

View file

@ -0,0 +1,11 @@
#pragma once
struct PlatformVersion
{
public:
uint32_t Major{};
uint32_t Minor{};
uint32_t Build{};
};
extern PlatformVersion GetPlatformVersion();

View file

@ -157,7 +157,7 @@ CONFIG_DEFINE_LOCALE(SEVolume)
CONFIG_DEFINE_LOCALE(MusicAttenuation) CONFIG_DEFINE_LOCALE(MusicAttenuation)
{ {
{ ELanguage::English, { "Music Attenuation", "Fade out the game's music when external media is playing.\n\nRequires Windows 10 or later." } } { ELanguage::English, { "Music Attenuation", "Fade out the game's music when external media is playing." } }
}; };
CONFIG_DEFINE_LOCALE(VoiceLanguage) CONFIG_DEFINE_LOCALE(VoiceLanguage)

View file

@ -41,6 +41,12 @@ inline static std::unordered_map<std::string, std::unordered_map<ELanguage, std:
{ {
{ ELanguage::English, "This option is not available at this location." } { ELanguage::English, "This option is not available at this location." }
} }
},
{
"Options_Desc_OSNotSupported",
{
{ ELanguage::English, "This option is not supported by your operating system." }
}
} }
}; };

View file

@ -1,6 +1,7 @@
#include <cpu/guest_code.h> #include <cpu/guest_code.h>
#include <cfg/config.h> #include <cfg/config.h>
#include <kernel/function.h> #include <kernel/function.h>
#include <kernel/platform.h>
#include <patches/audio_patches.h> #include <patches/audio_patches.h>
#if _WIN32 #if _WIN32
@ -37,6 +38,8 @@ bool IsExternalAudioPlaying()
return session.GetPlaybackInfo().PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing; return session.GetPlaybackInfo().PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing;
} }
int AudioPatches::m_isAttenuationSupported = -1;
#endif #endif
be<float>* GetVolume(bool isMusic = true) be<float>* GetVolume(bool isMusic = true)
@ -50,6 +53,22 @@ be<float>* GetVolume(bool isMusic = true)
return (be<float>*)g_memory.Translate(4 * ((int)isMusic + 0x1C) + ((be<uint32_t>*)g_memory.Translate(ppUnkClass->get() + 4))->get()); return (be<float>*)g_memory.Translate(4 * ((int)isMusic + 0x1C) + ((be<uint32_t>*)g_memory.Translate(ppUnkClass->get() + 4))->get());
} }
bool AudioPatches::CanAttenuate()
{
#if _WIN32
if (m_isAttenuationSupported >= 0)
return m_isAttenuationSupported;
auto version = GetPlatformVersion();
m_isAttenuationSupported = version.Major == 10 && version.Build >= 17763;
return m_isAttenuationSupported;
#else
return false;
#endif
}
void AudioPatches::Update(float deltaTime) void AudioPatches::Update(float deltaTime)
{ {
auto pMusicVolume = GetVolume(); auto pMusicVolume = GetVolume();
@ -59,7 +78,7 @@ void AudioPatches::Update(float deltaTime)
return; return;
#if _WIN32 #if _WIN32
if (Config::MusicAttenuation) if (Config::MusicAttenuation && CanAttenuate())
{ {
auto time = 1.0f - expf(2.5f * -deltaTime); auto time = 1.0f - expf(2.5f * -deltaTime);

View file

@ -2,6 +2,10 @@
class AudioPatches class AudioPatches
{ {
protected:
static int m_isAttenuationSupported;
public: public:
static bool CanAttenuate();
static void Update(float deltaTime); static void Update(float deltaTime);
}; };

View file

@ -8,6 +8,8 @@
#include <kernel/memory.h> #include <kernel/memory.h>
#include <locale/locale.h> #include <locale/locale.h>
#include <patches/audio_patches.h>
constexpr float COMMON_PADDING_POS_Y = 118.0f; constexpr float COMMON_PADDING_POS_Y = 118.0f;
constexpr float COMMON_PADDING_POS_X = 30.0f; constexpr float COMMON_PADDING_POS_X = 30.0f;
constexpr float INFO_CONTAINER_POS_X = 870.0f; constexpr float INFO_CONTAINER_POS_X = 870.0f;
@ -859,7 +861,7 @@ static void DrawConfigOptions()
DrawConfigOption(rowCount++, yOffset, &Config::SEVolume, true); DrawConfigOption(rowCount++, yOffset, &Config::SEVolume, true);
DrawConfigOption(rowCount++, yOffset, &Config::VoiceLanguage, true); DrawConfigOption(rowCount++, yOffset, &Config::VoiceLanguage, true);
DrawConfigOption(rowCount++, yOffset, &Config::Subtitles, true); DrawConfigOption(rowCount++, yOffset, &Config::Subtitles, true);
DrawConfigOption(rowCount++, yOffset, &Config::MusicAttenuation, true); // TODO: grey this out for non-Windows platforms. DrawConfigOption(rowCount++, yOffset, &Config::MusicAttenuation, AudioPatches::CanAttenuate(), &Localise("Options_Desc_OSNotSupported"));
DrawConfigOption(rowCount++, yOffset, &Config::WerehogBattleMusic, true); DrawConfigOption(rowCount++, yOffset, &Config::WerehogBattleMusic, true);
break; break;
case 3: // VIDEO case 3: // VIDEO