diff --git a/include/Config/SettingsManager.hpp b/include/Config/SettingsManager.hpp index 98770b6..7253d02 100644 --- a/include/Config/SettingsManager.hpp +++ b/include/Config/SettingsManager.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "Enums/XFiWorkaround.hpp" #include "Enums/OccluderType.hpp" @@ -26,6 +28,7 @@ namespace MetaAudio float Volume(); OccluderType Occluder(); + void RegisterOccluderCallback(std::function f); XFiWorkaround XfiWorkaround(); }; diff --git a/src/AudioEngine.cpp b/src/AudioEngine.cpp index 598883f..affafe1 100644 --- a/src/AudioEngine.cpp +++ b/src/AudioEngine.cpp @@ -773,6 +773,9 @@ namespace MetaAudio SteamAudio_Init(); settings.Init(gEngfuncs); + settings.RegisterOccluderCallback([&](auto cvar) { + AL_ResetEFX(); + }); AL_ResetEFX(); channel_manager = alure::MakeUnique(); diff --git a/src/Config/SettingsManager.cpp b/src/Config/SettingsManager.cpp index 2714fe2..d56ecb5 100644 --- a/src/Config/SettingsManager.cpp +++ b/src/Config/SettingsManager.cpp @@ -24,12 +24,20 @@ namespace MetaAudio static constexpr char* DEFAULT_OCCLUSION = "1"; static constexpr char* DEFAULT_OCCLUSION_FADE = "1"; static constexpr char* DEFAULT_DOPPLER_FACTOR = "0.3"; + static std::vector> occluderChangeCallbacks; + + static void alOccluderCallback(cvar_t* pcvar) + { + for (const auto& func : occluderChangeCallbacks) + { + func(pcvar); + } + } void SettingsManager::Init(const cl_enginefunc_t& engFuncs) { if (al_xfi_workaround == nullptr) al_xfi_workaround = engFuncs.pfnRegisterVariable("al_xfi_workaround", DEFAULT_XFI_WORKAROUND, FCVAR_EXTDLL); if (al_doppler == nullptr) al_doppler = engFuncs.pfnRegisterVariable("al_doppler", DEFAULT_DOPPLER_FACTOR, FCVAR_EXTDLL); - if (gSteamAudio.IsValid() && al_occluder == nullptr) al_occluder = engFuncs.pfnRegisterVariable("al_occluder", DEFAULT_OCCLUDER, FCVAR_EXTDLL); if (al_occlusion == nullptr) al_occlusion = engFuncs.pfnRegisterVariable("al_occlusion", DEFAULT_OCCLUSION, FCVAR_EXTDLL); if (al_occlusion_fade == nullptr) al_occlusion_fade = engFuncs.pfnRegisterVariable("al_occlusion_fade", DEFAULT_OCCLUSION_FADE, FCVAR_EXTDLL); @@ -42,6 +50,12 @@ namespace MetaAudio if (sxroom_off == nullptr) sxroom_off = engFuncs.pfnGetCvarPointer("room_off"); if (snd_show == nullptr) snd_show = engFuncs.pfnGetCvarPointer("snd_show"); } + + if (gSteamAudio.IsValid() && al_occluder == nullptr) + { + al_occluder = engFuncs.pfnRegisterVariable("al_occluder", DEFAULT_OCCLUDER, FCVAR_EXTDLL); + g_pMetaHookAPI->RegisterCvarCallback("al_occluder", alOccluderCallback, nullptr); + } } bool SettingsManager::NoSound() @@ -89,6 +103,11 @@ namespace MetaAudio return al_occluder == nullptr ? OccluderType::GoldSrc : static_cast(al_occluder->value); } + void SettingsManager::RegisterOccluderCallback(std::function f) + { + occluderChangeCallbacks.push_back(f); + } + bool SettingsManager::OcclusionEnabled() { return static_cast(al_occlusion->value);