mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 12:51:42 +00:00
audio_patches: check if Windows version is supported
This commit is contained in:
parent
a2a086c52c
commit
811156bfae
9 changed files with 78 additions and 4 deletions
|
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
24
UnleashedRecomp/kernel/platform.cpp
Normal file
24
UnleashedRecomp/kernel/platform.cpp
Normal 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;
|
||||||
|
}
|
||||||
11
UnleashedRecomp/kernel/platform.h
Normal file
11
UnleashedRecomp/kernel/platform.h
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
struct PlatformVersion
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
uint32_t Major{};
|
||||||
|
uint32_t Minor{};
|
||||||
|
uint32_t Build{};
|
||||||
|
};
|
||||||
|
|
||||||
|
extern PlatformVersion GetPlatformVersion();
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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." }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue