From 0f0caf4553e739e0a97e248ef06621ee308b4eeb Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Wed, 23 Aug 2023 02:22:49 +0200 Subject: [PATCH] Don't use hardcoded dsp bus/volmod indices --- src/client/component/sound.cpp | 23 ++++++++++++++++++++--- src/client/game/structs.hpp | 15 +++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/client/component/sound.cpp b/src/client/component/sound.cpp index 6eb8e2a7..8ee83e71 100644 --- a/src/client/component/sound.cpp +++ b/src/client/component/sound.cpp @@ -15,6 +15,7 @@ namespace sound { game::dvar_t* snd_music_volume = nullptr; game::dvar_t** snd_music_disabled_for_custom_sndtrack = nullptr; + int music_volmod_index = -1; void com_sprintf_raw_sound_localized_stub(char* buffer, int size, const char* fmt, const char* lang, const char* name, const char* extension) @@ -39,17 +40,22 @@ namespace sound return snd_is_music_playing_hook.invoke(a1); } + bool is_sound_music(game::snd_alias_t* sound) + { + return sound->dspBusIndex == *game::music_dsp_bus_index || + sound->volModIndex == music_volmod_index; + } + float get_snd_volume(game::snd_alias_t* sound, float original_volume) { - // original code - if (sound->dspBusIndex == *reinterpret_cast(0x151B9AA40) && + if (is_sound_music(sound) && snd_music_disabled_for_custom_sndtrack && (*snd_music_disabled_for_custom_sndtrack)->current.enabled) { return 0.f; } - if (sound->dspBusIndex == 11 || sound->volModIndex == 5) + if (is_sound_music(sound)) { return original_volume * snd_music_volume->current.value; } @@ -67,6 +73,16 @@ namespace sound a.jmp(0x1407CD8C7); } + + double atof_stub(const char* str) + { + if (!std::strncmp(game::sound_data->volmods[*game::volmod_index].name, "music", sizeof(game::volmod_t::name))) + { + music_volmod_index = *game::volmod_index; + } + + return std::atof(str); + } } class component final : public component_interface @@ -85,6 +101,7 @@ namespace sound snd_is_music_playing_hook.create(0x1407C58A0, snd_is_music_playing_stub); utils::hook::jump(0x1407CD8A5, utils::hook::assemble(snd_update_channel_stub), true); + utils::hook::call(0x1407C5F2F, atof_stub); } }; } diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index 5ac48b78..cba1144b 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1079,6 +1079,21 @@ namespace game HE_FONT_COUNT, }; + struct volmod_t + { + char name[64]; + float value; + float headroom; + float mixExclusion; + }; + + struct sound_data_t + { + char __pad0[163720]; + volmod_t volmods[180]; + // ... + }; + namespace hks { struct lua_State;