Don't use hardcoded dsp bus/volmod indices
This commit is contained in:
parent
5aa10848ff
commit
0f0caf4553
@ -15,6 +15,7 @@ namespace sound
|
|||||||
{
|
{
|
||||||
game::dvar_t* snd_music_volume = nullptr;
|
game::dvar_t* snd_music_volume = nullptr;
|
||||||
game::dvar_t** snd_music_disabled_for_custom_sndtrack = 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,
|
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)
|
||||||
@ -39,17 +40,22 @@ namespace sound
|
|||||||
return snd_is_music_playing_hook.invoke<bool>(a1);
|
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)
|
float get_snd_volume(game::snd_alias_t* sound, float original_volume)
|
||||||
{
|
{
|
||||||
// original code
|
if (is_sound_music(sound) &&
|
||||||
if (sound->dspBusIndex == *reinterpret_cast<int*>(0x151B9AA40) &&
|
|
||||||
snd_music_disabled_for_custom_sndtrack &&
|
snd_music_disabled_for_custom_sndtrack &&
|
||||||
(*snd_music_disabled_for_custom_sndtrack)->current.enabled)
|
(*snd_music_disabled_for_custom_sndtrack)->current.enabled)
|
||||||
{
|
{
|
||||||
return 0.f;
|
return 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sound->dspBusIndex == 11 || sound->volModIndex == 5)
|
if (is_sound_music(sound))
|
||||||
{
|
{
|
||||||
return original_volume * snd_music_volume->current.value;
|
return original_volume * snd_music_volume->current.value;
|
||||||
}
|
}
|
||||||
@ -67,6 +73,16 @@ namespace sound
|
|||||||
|
|
||||||
a.jmp(0x1407CD8C7);
|
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
|
class component final : public component_interface
|
||||||
@ -85,6 +101,7 @@ namespace sound
|
|||||||
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);
|
utils::hook::jump(0x1407CD8A5, utils::hook::assemble(snd_update_channel_stub), true);
|
||||||
|
utils::hook::call(0x1407C5F2F, atof_stub);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1079,6 +1079,21 @@ namespace game
|
|||||||
HE_FONT_COUNT,
|
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
|
namespace hks
|
||||||
{
|
{
|
||||||
struct lua_State;
|
struct lua_State;
|
||||||
|
Loading…
Reference in New Issue
Block a user