Don't use hardcoded dsp bus/volmod indices

This commit is contained in:
fed 2023-08-23 02:22:49 +02:00
parent 5aa10848ff
commit 0f0caf4553
2 changed files with 35 additions and 3 deletions

View File

@ -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<bool>(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<int*>(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);
}
};
}

View File

@ -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;