Add music volume slider
This commit is contained in:
parent
2768d1360e
commit
861d77ea4b
@ -64,6 +64,9 @@
|
|||||||
"LUA_MENU_INTRO": "Intro movie",
|
"LUA_MENU_INTRO": "Intro movie",
|
||||||
"LUA_MENU_INTRO_DESC": "Show or skip intro movie with companies' logos on startup.",
|
"LUA_MENU_INTRO_DESC": "Show or skip intro movie with companies' logos on startup.",
|
||||||
|
|
||||||
|
"MENU_MUSIC_VOLUME": "Music Volume",
|
||||||
|
"MENU_MUSIC_VOLUME_DESC": "Move the slider to adjust the volume of the music.",
|
||||||
|
|
||||||
"MENU_SYSINFO_CUSTOMER_SUPPORT_LINK": "Github Page:",
|
"MENU_SYSINFO_CUSTOMER_SUPPORT_LINK": "Github Page:",
|
||||||
"MENU_SYSINFO_CUSTOMER_SUPPORT_URL": "https://github.com/fedddddd/h2-mod",
|
"MENU_SYSINFO_CUSTOMER_SUPPORT_URL": "https://github.com/fedddddd/h2-mod",
|
||||||
"MENU_SYSINFO_DONATION_LINK": "Donation link:",
|
"MENU_SYSINFO_DONATION_LINK": "Donation link:",
|
||||||
|
@ -13,6 +13,9 @@ namespace sound
|
|||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
game::dvar_t* snd_music_volume = nullptr;
|
||||||
|
game::dvar_t** snd_music_disabled_for_custom_sndtrack = nullptr;
|
||||||
|
|
||||||
void com_sprintf_raw_sound_localized_stub(char* buffer, int size, const char* fmt,
|
void com_sprintf_raw_sound_localized_stub(char* buffer, int size, const char* fmt,
|
||||||
const char* lang, const char* name, const char* extension)
|
const char* lang, const char* name, const char* extension)
|
||||||
{
|
{
|
||||||
@ -35,6 +38,35 @@ namespace sound
|
|||||||
|
|
||||||
return snd_is_music_playing_hook.invoke<bool>(a1);
|
return snd_is_music_playing_hook.invoke<bool>(a1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float get_snd_volume(game::snd_alias_t* sound, float original_volume)
|
||||||
|
{
|
||||||
|
// original code
|
||||||
|
if (sound->dspBusIndex == *reinterpret_cast<int*>(0x151B9AA40) &&
|
||||||
|
snd_music_disabled_for_custom_sndtrack &&
|
||||||
|
(*snd_music_disabled_for_custom_sndtrack)->current.enabled)
|
||||||
|
{
|
||||||
|
return 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sound->dspBusIndex == 11 || sound->volModIndex == 5)
|
||||||
|
{
|
||||||
|
return original_volume * snd_music_volume->current.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return original_volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void snd_update_channel_stub(utils::hook::assembler& a)
|
||||||
|
{
|
||||||
|
a.pushad64();
|
||||||
|
a.mov(rcx, qword_ptr(rdi, 0xD0));
|
||||||
|
a.call_aligned(get_snd_volume);
|
||||||
|
a.movaps(xmm1, xmm0);
|
||||||
|
a.popad64();
|
||||||
|
|
||||||
|
a.jmp(0x1407CD8C7);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
@ -42,12 +74,17 @@ namespace sound
|
|||||||
public:
|
public:
|
||||||
void post_unpack() override
|
void post_unpack() override
|
||||||
{
|
{
|
||||||
|
snd_music_volume = dvars::register_float("snd_musicVolume", 1.f, 0.0f, 1.f, game::DVAR_FLAG_SAVED, "Music volume scale");
|
||||||
|
snd_music_disabled_for_custom_sndtrack = reinterpret_cast<game::dvar_t**>(0x151B818C8);
|
||||||
|
|
||||||
// remove raw/sound or raw/language/sound prefix when loading raw sounds
|
// remove raw/sound or raw/language/sound prefix when loading raw sounds
|
||||||
utils::hook::call(0x140622FEF, com_sprintf_raw_sound_localized_stub);
|
utils::hook::call(0x140622FEF, com_sprintf_raw_sound_localized_stub);
|
||||||
utils::hook::call(0x14062306C, com_sprintf_raw_sound_stub);
|
utils::hook::call(0x14062306C, com_sprintf_raw_sound_stub);
|
||||||
|
|
||||||
// fix playing non-existing music crashing
|
// fix playing non-existing music crashing
|
||||||
snd_is_music_playing_hook.create(0x1407C58A0, snd_is_music_playing_stub);
|
snd_is_music_playing_hook.create(0x1407C58A0, snd_is_music_playing_stub);
|
||||||
|
|
||||||
|
utils::hook::jump(0x1407CD8A5, utils::hook::assemble(snd_update_channel_stub), true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user