Skip to content

Commit

Permalink
Reset EFX automatically when occluder changes
Browse files Browse the repository at this point in the history
Not working on HL25 yet, needs to update metahook
  • Loading branch information
LAGonauta committed Dec 16, 2023
1 parent eb1bd25 commit 26fb334
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/Config/SettingsManager.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <functional>

#include "Enums/XFiWorkaround.hpp"
#include "Enums/OccluderType.hpp"

Expand All @@ -26,6 +28,7 @@ namespace MetaAudio
float Volume();

OccluderType Occluder();
void RegisterOccluderCallback(std::function<void(cvar_t*)> f);

XFiWorkaround XfiWorkaround();
};
Expand Down
3 changes: 3 additions & 0 deletions src/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@ namespace MetaAudio

SteamAudio_Init();
settings.Init(gEngfuncs);
settings.RegisterOccluderCallback([&](auto cvar) {
AL_ResetEFX();
});
AL_ResetEFX();

channel_manager = alure::MakeUnique<ChannelManager>();
Expand Down
21 changes: 20 additions & 1 deletion src/Config/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::function<void(cvar_t* pcvar)>> 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);

Expand All @@ -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()
Expand Down Expand Up @@ -89,6 +103,11 @@ namespace MetaAudio
return al_occluder == nullptr ? OccluderType::GoldSrc : static_cast<OccluderType>(al_occluder->value);
}

void SettingsManager::RegisterOccluderCallback(std::function<void(cvar_t*)> f)
{
occluderChangeCallbacks.push_back(f);
}

bool SettingsManager::OcclusionEnabled()
{
return static_cast<bool>(al_occlusion->value);
Expand Down

0 comments on commit 26fb334

Please sign in to comment.