Added FadeBackgroundMusic option

This commit is contained in:
NovaRain
2021-08-13 20:10:08 +08:00
parent 638499b106
commit 3a0e64e3ce
2 changed files with 15 additions and 1 deletions
+3
View File
@@ -131,6 +131,9 @@ WorldMapTerrainInfo=0
;Set to 0 to leave the default unchanged (i.e. 4). The maximum is 32
NumSoundBuffers=0
;Set to 1 to enable fade effects for background music when stopping and starting the playback
FadeBackgroundMusic=1
;Set to 1 to allow attaching sound files to combat float messages
AllowSoundForFloats=0
+12 -1
View File
@@ -950,7 +950,9 @@ constexpr int SampleRate = 44100; // 44.1kHz
void Sound::init() {
// Set the 44.1kHz sample rate for the primary sound buffer
SafeWrite32(0x44FDBC, SampleRate);
LoadGameHook::OnAfterGameInit() += []() { fo::var::sampleRate = SampleRate / 2; }; // Revert to 22kHz for secondary sound buffers
LoadGameHook::OnAfterGameInit() += []() {
fo::var::sampleRate = SampleRate / 2; // Revert to 22kHz for secondary sound buffers
};
LoadGameHook::OnGameReset() += WipeSounds;
LoadGameHook::OnBeforeGameClose() += WipeSounds;
@@ -1024,6 +1026,15 @@ void Sound::init() {
if (IniReader::GetConfigInt("Sound", "AutoSearchSFX", 1)) {
HookCalls(sfxl_init_hook, {0x4A9999, 0x4A9B34});
}
if (IniReader::GetConfigInt("Sound", "FadeBackgroundMusic", 1)) {
SafeMemSet(0x45020C, CodeType::Nop, 6); // gsound_reset_
SafeWrite32(0x45212C, 250); // delay start
SafeWrite32(0x450ADE, 500); // delay stop
LoadGameHook::OnAfterGameInit() += []() {
*(DWORD*)FO_VAR_gsound_background_fade = 1;
};
}
}
void Sound::exit() {