From e2e0fbe975d041a8ce9ac604901f26581c9cab4e Mon Sep 17 00:00:00 2001 From: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Date: Sun, 28 Jun 2026 13:22:10 +0200 Subject: [PATCH 1/6] reimplement: SHC_3BB0A8C1_0x0047BF20 setup method --- .../playRandomBackgroundMusicUnk.cpp | 308 ++++++++++++++++++ 1 file changed, 308 insertions(+) create mode 100644 src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp diff --git a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp new file mode 100644 index 0000000..42e1572 --- /dev/null +++ b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp @@ -0,0 +1,308 @@ +#include "../SoundSystem.func.hpp" + +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Audio/mss/SoundFlagsAndLoopCountBitwiseFlagEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_SFXDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SoundEffectsHelperData1.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Audio { + namespace MSS { + + // FUNCTION: STRONGHOLDCRUSADER 0x0047BF20 + void SoundSystem::playRandomBackgroundMusicUnk() + { + int iVar1; + int iVar2; + BOOLEnum BVar3; + int iVar4; + int iVar5; + int iVar6; + bool bVar7; + char* pcVar8; + int aiStack_50[20]; + + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 != 5) { + return; + } + BVar3 = MACRO_CALL_MEMBER(Game::GameCore_Func::getAreWeInAInGameMenu, DAT_GameCore::ptr)(); + if ((BVar3 == FALSE) + && ((DAT_GameCore::instance.currentMenuViewType != UI::Enums::MVT_SCENARIO_DESCRIPTION + || (DAT_GameCore::instance.field25_0x64 == 0)))) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 != 5) { + return; + } + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; + return; + } + bVar7 = true; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.troopValueLevel == 0) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel == 1) { + pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[23].musicFile; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { + LAB_0047c00f: + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { + DAT_GameCore::instance.battleLevel2 = DAT_GameCore::instance.battleLevel2 + 2000; + } + goto LAB_0047bfca; + } + /* sfx file: suspense1b */ + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; + } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel == 2) { + pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) + goto LAB_0047c00f; + /* sfx file: suspense2b */ + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; + } else { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel != 5) + goto LAB_0047c386; + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 3) { + pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[27].musicFile; + /* sfx file: drumloop1c */ + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 1) + goto LAB_0047bfc5; + } else { + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; + if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { + DAT_GameCore::instance.battleLevel2 = DAT_GameCore::instance.battleLevel2 + 2000; + } + } + LAB_0047bfbd: + /* sfx file: suspense2b */ + pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile; + } + LAB_0047bfc5: + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + goto LAB_0047bfca; + } + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel == 1) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 == 0) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { + + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[30].musicFile); + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; + } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 1) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; + } else { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); + if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { + DAT_GameCore::instance.battleLevel2 = DAT_GameCore::instance.battleLevel2 + 5000; + } + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; + } + goto LAB_0047bfca; + } + LAB_0047c37e: + bVar7 = false; + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; + } else { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 != 0) + goto LAB_0047c37e; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 2) { + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 2) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[34].musicFile); + } + DAT_SoundEffectsHelperData1::instance.field21_0x70 = 0x22; + } else { + iVar5 = DAT_SoundEffectsHelperData1::instance.field21_0x70 + -0x22; + iVar6 = 0; + if ((iVar5 < 0) || (7 < iVar5)) { + iVar5 = 0; + } + iVar4 = 0; + do { + if ((iVar5 != iVar4) && (DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][iVar4] != 0)) { + if (iVar4 == 4) { + aiStack_50[iVar6] = 4; + aiStack_50[iVar6 + 1] = 4; + aiStack_50[iVar6 + 2] = 4; + aiStack_50[iVar6 + 3] = 4; + aiStack_50[iVar6 + 4] = 4; + iVar6 = iVar6 + 5; + aiStack_50[iVar6] = 4; + LAB_0047c1b8: + iVar6 = iVar6 + 1; + } else { + iVar1 = DAT_SFXDefinedData::instance.field3_0x4a4[iVar4]; + if (((iVar1 != 1) && (iVar1 != 2)) + || (DAT_SoundEffectsHelperData1::instance.field6_0x34 != iVar1)) { + aiStack_50[iVar6] = iVar4; + iVar6 = iVar6 + 1; + if (DAT_SoundEffectsHelperData1::instance.field6_0x34 == 1) { + bVar7 = iVar1 == 2; + } else { + if (DAT_SoundEffectsHelperData1::instance.field6_0x34 != 2) + goto LAB_0047c1bb; + bVar7 = iVar1 == 1; + } + if (bVar7) { + aiStack_50[iVar6] = iVar4; + goto LAB_0047c1b8; + } + } + } + } + LAB_0047c1bb: + iVar1 = iVar4 + 1; + if ((iVar5 != iVar1) + && (DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][iVar4 + 1] != 0)) { + if (iVar1 == 4) { + aiStack_50[iVar6] = 4; + aiStack_50[iVar6 + 1] = 4; + aiStack_50[iVar6 + 2] = 4; + aiStack_50[iVar6 + 3] = 4; + aiStack_50[iVar6 + 4] = 4; + iVar6 = iVar6 + 5; + aiStack_50[iVar6] = 4; + LAB_0047c234: + iVar6 = iVar6 + 1; + } else { + iVar2 = DAT_SFXDefinedData::instance.field3_0x4a4[iVar4 + 1]; + if (((iVar2 != 1) && (iVar2 != 2)) + || (DAT_SoundEffectsHelperData1::instance.field6_0x34 != iVar2)) { + aiStack_50[iVar6] = iVar1; + iVar6 = iVar6 + 1; + if (DAT_SoundEffectsHelperData1::instance.field6_0x34 == 1) { + bVar7 = iVar2 == 2; + } else { + if (DAT_SoundEffectsHelperData1::instance.field6_0x34 != 2) + goto LAB_0047c237; + bVar7 = iVar2 == 1; + } + if (bVar7) { + aiStack_50[iVar6] = iVar1; + goto LAB_0047c234; + } + } + } + } + LAB_0047c237: + iVar1 = iVar4 + 2; + if ((iVar5 != iVar1) + && (DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][iVar4 + 2] != 0)) { + if (iVar1 == 4) { + aiStack_50[iVar6] = 4; + aiStack_50[iVar6 + 1] = 4; + aiStack_50[iVar6 + 2] = 4; + aiStack_50[iVar6 + 3] = 4; + aiStack_50[iVar6 + 4] = 4; + iVar6 = iVar6 + 5; + aiStack_50[iVar6] = 4; + LAB_0047c2b0: + iVar6 = iVar6 + 1; + } else { + iVar2 = DAT_SFXDefinedData::instance.field3_0x4a4[iVar4 + 2]; + if (((iVar2 != 1) && (iVar2 != 2)) + || (DAT_SoundEffectsHelperData1::instance.field6_0x34 != iVar2)) { + aiStack_50[iVar6] = iVar1; + iVar6 = iVar6 + 1; + if (DAT_SoundEffectsHelperData1::instance.field6_0x34 == 1) { + bVar7 = iVar2 == 2; + } else { + if (DAT_SoundEffectsHelperData1::instance.field6_0x34 != 2) + goto LAB_0047c2b3; + bVar7 = iVar2 == 1; + } + if (bVar7) { + aiStack_50[iVar6] = iVar1; + goto LAB_0047c2b0; + } + } + } + } + LAB_0047c2b3: + iVar1 = iVar4 + 3; + if ((iVar5 != iVar1) + && (DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][iVar4 + 3] != 0)) { + if (iVar1 == 4) { + aiStack_50[iVar6] = 4; + aiStack_50[iVar6 + 1] = 4; + aiStack_50[iVar6 + 2] = 4; + aiStack_50[iVar6 + 3] = 4; + aiStack_50[iVar6 + 4] = 4; + iVar6 = iVar6 + 5; + aiStack_50[iVar6] = 4; + LAB_0047c32c: + iVar6 = iVar6 + 1; + } else { + iVar2 = DAT_SFXDefinedData::instance.field3_0x4a4[iVar4 + 3]; + if (((iVar2 != 1) && (iVar2 != 2)) + || (DAT_SoundEffectsHelperData1::instance.field6_0x34 != iVar2)) { + aiStack_50[iVar6] = iVar1; + iVar6 = iVar6 + 1; + if (DAT_SoundEffectsHelperData1::instance.field6_0x34 == 1) { + bVar7 = iVar2 == 2; + } else { + if (DAT_SoundEffectsHelperData1::instance.field6_0x34 != 2) + goto LAB_0047c32f; + bVar7 = iVar2 == 1; + } + if (bVar7) { + aiStack_50[iVar6] = iVar1; + goto LAB_0047c32c; + } + } + } + } + LAB_0047c32f: + iVar4 = iVar4 + 4; + } while (iVar4 < 8); + if (iVar6 != 0) { + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); + iVar5 = aiStack_50[SEC_RNG::instance.currentNumber1 % iVar6]; + } + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[iVar5 + 34].musicFile); + DAT_SoundEffectsHelperData1::instance.field21_0x70 = iVar5 + 34; + } + goto LAB_0047bfca; + } + if (this->sec_Section1055_0x3274 != 0x19) + goto LAB_0047bfbd; + } + LAB_0047c386: + if (this->musicFileHandle_0x178 != -1) { + DAT_SoundEffectsHelperData1::instance.field14_0x54 = TRUE; + MACRO_CALL(OS_Func::_ucrt_close)(this->musicFileHandle_0x178); + this->musicFileHandle_0x178 = -1; + DAT_SoundEffectsHelperData1::instance.field14_0x54 = FALSE; + } + if (bVar7) { + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) != 1) { + return; + } + this->streamFlagsUnkAndLoopCount_0x34[0] + = this->streamFlagsUnkAndLoopCount_0x34[0] & ~FLAG_SOUND_LOOP_COUNT_FIELD; + return; + } + LAB_0047bfca: + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + this->streamFlagsUnkAndLoopCount_0x34[0] = this->streamFlagsUnkAndLoopCount_0x34[0] + 1; + } + return; + } + + } +} +} From 58ac680b5247ef999215965bd39f8cf2ca65f733 Mon Sep 17 00:00:00 2001 From: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Date: Sun, 28 Jun 2026 16:05:00 +0200 Subject: [PATCH 2/6] reimplement: SHC_3BB0A8C1_0x0047BF20 remove gotos --- .../playRandomBackgroundMusicUnk.cpp | 368 +++++++----------- 1 file changed, 149 insertions(+), 219 deletions(-) diff --git a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp index 42e1572..e165a48 100644 --- a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp +++ b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp @@ -18,270 +18,202 @@ namespace Audio { // FUNCTION: STRONGHOLDCRUSADER 0x0047BF20 void SoundSystem::playRandomBackgroundMusicUnk() { - int iVar1; - int iVar2; - BOOLEnum BVar3; - int iVar4; int iVar5; int iVar6; bool bVar7; char* pcVar8; - int aiStack_50[20]; if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 != 5) { return; } - BVar3 = MACRO_CALL_MEMBER(Game::GameCore_Func::getAreWeInAInGameMenu, DAT_GameCore::ptr)(); - if ((BVar3 == FALSE) - && ((DAT_GameCore::instance.currentMenuViewType != UI::Enums::MVT_SCENARIO_DESCRIPTION - || (DAT_GameCore::instance.field25_0x64 == 0)))) { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 != 5) { - return; + if (!MACRO_CALL_MEMBER(Game::GameCore_Func::getAreWeInAInGameMenu, DAT_GameCore::ptr)() + && (DAT_GameCore::instance.currentMenuViewType != UI::Enums::MVT_SCENARIO_DESCRIPTION + || DAT_GameCore::instance.field25_0x64 == 0)) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 == 5) { + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; } - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; return; } bVar7 = true; if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.troopValueLevel == 0) { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel == 1) { + switch (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel) { + case 1: pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[23].musicFile; if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { - LAB_0047c00f: MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { - DAT_GameCore::instance.battleLevel2 = DAT_GameCore::instance.battleLevel2 + 2000; + DAT_GameCore::instance.battleLevel2 += 2000; + } + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; } - goto LAB_0047bfca; + return; } /* sfx file: suspense1b */ DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; - } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel == 2) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; + case 2: pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile; - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) - goto LAB_0047c00f; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { + DAT_GameCore::instance.battleLevel2 += 2000; + } + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; + } /* sfx file: suspense2b */ DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; - } else { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel != 5) - goto LAB_0047c386; - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker - = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 3) { - pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[27].musicFile; - /* sfx file: drumloop1c */ - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 1) - goto LAB_0047bfc5; - } else { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; + case 5: + ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker > 2) { DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { - DAT_GameCore::instance.battleLevel2 = DAT_GameCore::instance.battleLevel2 + 2000; + DAT_GameCore::instance.battleLevel2 += 2000; + } + } else { + pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[27].musicFile; + /* sfx file: drumloop1c */ + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 1) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; } } - LAB_0047bfbd: /* sfx file: suspense2b */ pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile; + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; + default: + if (this->musicFileHandle_0x178 != -1) { + DAT_SoundEffectsHelperData1::instance.field14_0x54 = TRUE; + MACRO_CALL(OS_Func::_ucrt_close)(this->musicFileHandle_0x178); + this->musicFileHandle_0x178 = -1; + DAT_SoundEffectsHelperData1::instance.field14_0x54 = FALSE; + } + if (bVar7) { + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) != 1) { + return; + } + this->streamFlagsUnkAndLoopCount_0x34[0] &= ~FLAG_SOUND_LOOP_COUNT_FIELD; + return; + } + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; } - LAB_0047bfc5: - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); - goto LAB_0047bfca; } - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel == 1) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel != 1) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 != 0) { + bVar7 = false; + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; + } else { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 2) { + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 2) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[34].musicFile); + } + DAT_SoundEffectsHelperData1::instance.field21_0x70 = 0x22; + } else { + iVar5 = DAT_SoundEffectsHelperData1::instance.field21_0x70 + -0x22; + iVar6 = 0; + if ((iVar5 < 0) || (7 < iVar5)) { + iVar5 = 0; + } + + int aiStack_50[20]; + for (int i = 0; i < 8; ++i) { + if (iVar5 == i || DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][i] == 0) { + continue; + } + if (i == 4) { + aiStack_50[iVar6++] = 4; + aiStack_50[iVar6++] = 4; + aiStack_50[iVar6++] = 4; + aiStack_50[iVar6++] = 4; + aiStack_50[iVar6++] = 4; + aiStack_50[iVar6++] = 4; + continue; + } + int iVar1 = DAT_SFXDefinedData::instance.field3_0x4a4[i]; + int field6_0x34 = DAT_SoundEffectsHelperData1::instance.field6_0x34; + if ((iVar1 == 1 && iVar1 == field6_0x34) || (iVar1 == 2 && iVar1 == field6_0x34)) { + continue; + } + aiStack_50[iVar6++] = i; + if ((field6_0x34 == 1 && iVar1 == 2) || (field6_0x34 == 2 && iVar1 == 1)) { + aiStack_50[iVar6++] = i; + } + } + + if (iVar6 != 0) { + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); + iVar5 = aiStack_50[SEC_RNG::instance.currentNumber1 % iVar6]; + } + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[iVar5 + 34].musicFile); + DAT_SoundEffectsHelperData1::instance.field21_0x70 = iVar5 + 34; + } + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + this->streamFlagsUnkAndLoopCount_0x34[0] = this->streamFlagsUnkAndLoopCount_0x34[0] + 1; + } + return; + } + if (this->sec_Section1055_0x3274 != 0x19) { + pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile; + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; + } + } + } else { if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 == 0) { if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( DAT_SFXDefinedData::instance.DAT_SFX_Pointers[30].musicFile); - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker - = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; + ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 1) { MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker - = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; + ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; } else { MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { - DAT_GameCore::instance.battleLevel2 = DAT_GameCore::instance.battleLevel2 + 5000; + DAT_GameCore::instance.battleLevel2 += 5000; } - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker - = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; + ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; } - goto LAB_0047bfca; + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + this->streamFlagsUnkAndLoopCount_0x34[0] = this->streamFlagsUnkAndLoopCount_0x34[0] + 1; + } + return; } - LAB_0047c37e: bVar7 = false; DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; - } else { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 != 0) - goto LAB_0047c37e; - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 2) { - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker - = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 2) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[34].musicFile); - } - DAT_SoundEffectsHelperData1::instance.field21_0x70 = 0x22; - } else { - iVar5 = DAT_SoundEffectsHelperData1::instance.field21_0x70 + -0x22; - iVar6 = 0; - if ((iVar5 < 0) || (7 < iVar5)) { - iVar5 = 0; - } - iVar4 = 0; - do { - if ((iVar5 != iVar4) && (DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][iVar4] != 0)) { - if (iVar4 == 4) { - aiStack_50[iVar6] = 4; - aiStack_50[iVar6 + 1] = 4; - aiStack_50[iVar6 + 2] = 4; - aiStack_50[iVar6 + 3] = 4; - aiStack_50[iVar6 + 4] = 4; - iVar6 = iVar6 + 5; - aiStack_50[iVar6] = 4; - LAB_0047c1b8: - iVar6 = iVar6 + 1; - } else { - iVar1 = DAT_SFXDefinedData::instance.field3_0x4a4[iVar4]; - if (((iVar1 != 1) && (iVar1 != 2)) - || (DAT_SoundEffectsHelperData1::instance.field6_0x34 != iVar1)) { - aiStack_50[iVar6] = iVar4; - iVar6 = iVar6 + 1; - if (DAT_SoundEffectsHelperData1::instance.field6_0x34 == 1) { - bVar7 = iVar1 == 2; - } else { - if (DAT_SoundEffectsHelperData1::instance.field6_0x34 != 2) - goto LAB_0047c1bb; - bVar7 = iVar1 == 1; - } - if (bVar7) { - aiStack_50[iVar6] = iVar4; - goto LAB_0047c1b8; - } - } - } - } - LAB_0047c1bb: - iVar1 = iVar4 + 1; - if ((iVar5 != iVar1) - && (DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][iVar4 + 1] != 0)) { - if (iVar1 == 4) { - aiStack_50[iVar6] = 4; - aiStack_50[iVar6 + 1] = 4; - aiStack_50[iVar6 + 2] = 4; - aiStack_50[iVar6 + 3] = 4; - aiStack_50[iVar6 + 4] = 4; - iVar6 = iVar6 + 5; - aiStack_50[iVar6] = 4; - LAB_0047c234: - iVar6 = iVar6 + 1; - } else { - iVar2 = DAT_SFXDefinedData::instance.field3_0x4a4[iVar4 + 1]; - if (((iVar2 != 1) && (iVar2 != 2)) - || (DAT_SoundEffectsHelperData1::instance.field6_0x34 != iVar2)) { - aiStack_50[iVar6] = iVar1; - iVar6 = iVar6 + 1; - if (DAT_SoundEffectsHelperData1::instance.field6_0x34 == 1) { - bVar7 = iVar2 == 2; - } else { - if (DAT_SoundEffectsHelperData1::instance.field6_0x34 != 2) - goto LAB_0047c237; - bVar7 = iVar2 == 1; - } - if (bVar7) { - aiStack_50[iVar6] = iVar1; - goto LAB_0047c234; - } - } - } - } - LAB_0047c237: - iVar1 = iVar4 + 2; - if ((iVar5 != iVar1) - && (DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][iVar4 + 2] != 0)) { - if (iVar1 == 4) { - aiStack_50[iVar6] = 4; - aiStack_50[iVar6 + 1] = 4; - aiStack_50[iVar6 + 2] = 4; - aiStack_50[iVar6 + 3] = 4; - aiStack_50[iVar6 + 4] = 4; - iVar6 = iVar6 + 5; - aiStack_50[iVar6] = 4; - LAB_0047c2b0: - iVar6 = iVar6 + 1; - } else { - iVar2 = DAT_SFXDefinedData::instance.field3_0x4a4[iVar4 + 2]; - if (((iVar2 != 1) && (iVar2 != 2)) - || (DAT_SoundEffectsHelperData1::instance.field6_0x34 != iVar2)) { - aiStack_50[iVar6] = iVar1; - iVar6 = iVar6 + 1; - if (DAT_SoundEffectsHelperData1::instance.field6_0x34 == 1) { - bVar7 = iVar2 == 2; - } else { - if (DAT_SoundEffectsHelperData1::instance.field6_0x34 != 2) - goto LAB_0047c2b3; - bVar7 = iVar2 == 1; - } - if (bVar7) { - aiStack_50[iVar6] = iVar1; - goto LAB_0047c2b0; - } - } - } - } - LAB_0047c2b3: - iVar1 = iVar4 + 3; - if ((iVar5 != iVar1) - && (DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][iVar4 + 3] != 0)) { - if (iVar1 == 4) { - aiStack_50[iVar6] = 4; - aiStack_50[iVar6 + 1] = 4; - aiStack_50[iVar6 + 2] = 4; - aiStack_50[iVar6 + 3] = 4; - aiStack_50[iVar6 + 4] = 4; - iVar6 = iVar6 + 5; - aiStack_50[iVar6] = 4; - LAB_0047c32c: - iVar6 = iVar6 + 1; - } else { - iVar2 = DAT_SFXDefinedData::instance.field3_0x4a4[iVar4 + 3]; - if (((iVar2 != 1) && (iVar2 != 2)) - || (DAT_SoundEffectsHelperData1::instance.field6_0x34 != iVar2)) { - aiStack_50[iVar6] = iVar1; - iVar6 = iVar6 + 1; - if (DAT_SoundEffectsHelperData1::instance.field6_0x34 == 1) { - bVar7 = iVar2 == 2; - } else { - if (DAT_SoundEffectsHelperData1::instance.field6_0x34 != 2) - goto LAB_0047c32f; - bVar7 = iVar2 == 1; - } - if (bVar7) { - aiStack_50[iVar6] = iVar1; - goto LAB_0047c32c; - } - } - } - } - LAB_0047c32f: - iVar4 = iVar4 + 4; - } while (iVar4 < 8); - if (iVar6 != 0) { - MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); - iVar5 = aiStack_50[SEC_RNG::instance.currentNumber1 % iVar6]; - } - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[iVar5 + 34].musicFile); - DAT_SoundEffectsHelperData1::instance.field21_0x70 = iVar5 + 34; - } - goto LAB_0047bfca; - } - if (this->sec_Section1055_0x3274 != 0x19) - goto LAB_0047bfbd; } - LAB_0047c386: if (this->musicFileHandle_0x178 != -1) { DAT_SoundEffectsHelperData1::instance.field14_0x54 = TRUE; MACRO_CALL(OS_Func::_ucrt_close)(this->musicFileHandle_0x178); @@ -292,13 +224,11 @@ namespace Audio { if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) != 1) { return; } - this->streamFlagsUnkAndLoopCount_0x34[0] - = this->streamFlagsUnkAndLoopCount_0x34[0] & ~FLAG_SOUND_LOOP_COUNT_FIELD; + this->streamFlagsUnkAndLoopCount_0x34[0] &= ~FLAG_SOUND_LOOP_COUNT_FIELD; return; } - LAB_0047bfca: if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - this->streamFlagsUnkAndLoopCount_0x34[0] = this->streamFlagsUnkAndLoopCount_0x34[0] + 1; + ++this->streamFlagsUnkAndLoopCount_0x34[0] = this->streamFlagsUnkAndLoopCount_0x34[0]; } return; } From 7cd4fc73e0a4f08fa5481991c80de4ac1c33ec06 Mon Sep 17 00:00:00 2001 From: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Date: Sun, 28 Jun 2026 23:19:17 +0200 Subject: [PATCH 3/6] reimplement: SHC_3BB0A8C1_0x0047BF20 register and structure issues --- .../Audio/mss/SoundFlagsAndLoopCount.hpp | 2 +- .../playRandomBackgroundMusicUnk.cpp | 254 ++++++++---------- 2 files changed, 114 insertions(+), 142 deletions(-) diff --git a/src/OpenSHC/Audio/mss/SoundFlagsAndLoopCount.hpp b/src/OpenSHC/Audio/mss/SoundFlagsAndLoopCount.hpp index ddbb458..ab26cb2 100644 --- a/src/OpenSHC/Audio/mss/SoundFlagsAndLoopCount.hpp +++ b/src/OpenSHC/Audio/mss/SoundFlagsAndLoopCount.hpp @@ -12,7 +12,7 @@ namespace OpenSHC { namespace Audio { namespace MSS { - typedef uint SoundFlagsAndLoopCount; + typedef int SoundFlagsAndLoopCount; } // namespace MSS } // namespace Audio } // namespace OpenSHC diff --git a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp index e165a48..922c65b 100644 --- a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp +++ b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp @@ -18,11 +18,6 @@ namespace Audio { // FUNCTION: STRONGHOLDCRUSADER 0x0047BF20 void SoundSystem::playRandomBackgroundMusicUnk() { - int iVar5; - int iVar6; - bool bVar7; - char* pcVar8; - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 != 5) { return; } @@ -34,185 +29,163 @@ namespace Audio { } return; } - bVar7 = true; + int bVar7 = true; if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.troopValueLevel == 0) { switch (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel) { - case 1: - pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[23].musicFile; - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + case 1: { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[23].musicFile); + } else { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[23].musicFile); if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { DAT_GameCore::instance.battleLevel2 += 2000; } - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; - } - return; } - /* sfx file: suspense1b */ - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { ++this->streamFlagsUnkAndLoopCount_0x34[0]; } return; - case 2: - pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile; - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + } + case 2: { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); + } else { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { DAT_GameCore::instance.battleLevel2 += 2000; } - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; - } - return; } - /* sfx file: suspense2b */ - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { ++this->streamFlagsUnkAndLoopCount_0x34[0]; } return; - case 5: + } + case 5: { ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker > 2) { DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { DAT_GameCore::instance.battleLevel2 += 2000; } - } else { - pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[27].musicFile; - /* sfx file: drumloop1c */ - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 1) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; - } - return; + + } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 1) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[27].musicFile); + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; } + return; } - /* sfx file: suspense2b */ - pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile; - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { ++this->streamFlagsUnkAndLoopCount_0x34[0]; } return; - default: - if (this->musicFileHandle_0x178 != -1) { - DAT_SoundEffectsHelperData1::instance.field14_0x54 = TRUE; - MACRO_CALL(OS_Func::_ucrt_close)(this->musicFileHandle_0x178); - this->musicFileHandle_0x178 = -1; - DAT_SoundEffectsHelperData1::instance.field14_0x54 = FALSE; - } - if (bVar7) { - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) != 1) { - return; + } + } + } else { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel == 1) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 == 0) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[30].musicFile); + } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 1) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); + } else { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); + if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { + DAT_GameCore::instance.battleLevel2 += 5000; + } + } + ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; } - this->streamFlagsUnkAndLoopCount_0x34[0] &= ~FLAG_SOUND_LOOP_COUNT_FIELD; return; + } else { + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; + bVar7 = false; } - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; - } - return; - } - } - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel != 1) { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 != 0) { - bVar7 = false; - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; } else { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 2) { - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker - = DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker + 1; - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 2) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 == 0) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { + if (this->sec_Section1055_0x3274 != 0x19) { MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[34].musicFile); + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; } - DAT_SoundEffectsHelperData1::instance.field21_0x70 = 0x22; } else { - iVar5 = DAT_SoundEffectsHelperData1::instance.field21_0x70 + -0x22; - iVar6 = 0; - if ((iVar5 < 0) || (7 < iVar5)) { - iVar5 = 0; - } - - int aiStack_50[20]; - for (int i = 0; i < 8; ++i) { - if (iVar5 == i || DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][i] == 0) { - continue; - } - if (i == 4) { - aiStack_50[iVar6++] = 4; - aiStack_50[iVar6++] = 4; - aiStack_50[iVar6++] = 4; - aiStack_50[iVar6++] = 4; - aiStack_50[iVar6++] = 4; - aiStack_50[iVar6++] = 4; - continue; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 2) { + ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 2) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[34].musicFile); } - int iVar1 = DAT_SFXDefinedData::instance.field3_0x4a4[i]; - int field6_0x34 = DAT_SoundEffectsHelperData1::instance.field6_0x34; - if ((iVar1 == 1 && iVar1 == field6_0x34) || (iVar1 == 2 && iVar1 == field6_0x34)) { - continue; + DAT_SoundEffectsHelperData1::instance.field21_0x70 = 34; + } else { + int iVar5 = DAT_SoundEffectsHelperData1::instance.field21_0x70 + -34; + int iVar6 = 0; + if (iVar5 < 0 || 7 < iVar5) { + iVar5 = 0; } - aiStack_50[iVar6++] = i; - if ((field6_0x34 == 1 && iVar1 == 2) || (field6_0x34 == 2 && iVar1 == 1)) { + + int aiStack_50[20]; + for (int i = 0; i < 8; ++i) { + if (iVar5 == i || DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][i] == 0) { + continue; + } + if (i == 4) { + aiStack_50[iVar6++] = 4; + aiStack_50[iVar6++] = 4; + aiStack_50[iVar6++] = 4; + aiStack_50[iVar6++] = 4; + aiStack_50[iVar6++] = 4; + aiStack_50[iVar6++] = 4; + continue; + } + int iVar1 = DAT_SFXDefinedData::instance.field3_0x4a4[i]; + int field6_0x34 = DAT_SoundEffectsHelperData1::instance.field6_0x34; + if ((iVar1 == 1 && iVar1 == field6_0x34) || (iVar1 == 2 && iVar1 == field6_0x34)) { + continue; + } aiStack_50[iVar6++] = i; + if (field6_0x34 == 1 && iVar1 == 2) { + aiStack_50[iVar6++] = i; + } else if (field6_0x34 == 2 && iVar1 == 1) { + aiStack_50[iVar6++] = i; + } } - } - if (iVar6 != 0) { - MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); - iVar5 = aiStack_50[SEC_RNG::instance.currentNumber1 % iVar6]; + if (iVar6 != 0) { + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); + iVar5 = aiStack_50[SEC_RNG::instance.currentNumber1 % iVar6]; + } + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[iVar5 + 34].musicFile); + DAT_SoundEffectsHelperData1::instance.field21_0x70 = iVar5 + 34; } - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[iVar5 + 34].musicFile); - DAT_SoundEffectsHelperData1::instance.field21_0x70 = iVar5 + 34; - } - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - this->streamFlagsUnkAndLoopCount_0x34[0] = this->streamFlagsUnkAndLoopCount_0x34[0] + 1; - } - return; - } - if (this->sec_Section1055_0x3274 != 0x19) { - pcVar8 = DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile; - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)(pcVar8); - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; } - return; - } - } - } else { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 == 0) { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[30].musicFile); - ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; - } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 1) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); - ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; } else { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); - if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { - DAT_GameCore::instance.battleLevel2 += 5000; - } - ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; - } - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - this->streamFlagsUnkAndLoopCount_0x34[0] = this->streamFlagsUnkAndLoopCount_0x34[0] + 1; + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; + bVar7 = false; } - return; } - bVar7 = false; - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; } if (this->musicFileHandle_0x178 != -1) { DAT_SoundEffectsHelperData1::instance.field14_0x54 = TRUE; @@ -221,14 +194,13 @@ namespace Audio { DAT_SoundEffectsHelperData1::instance.field14_0x54 = FALSE; } if (bVar7) { - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) != 1) { - return; + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 1) { + this->streamFlagsUnkAndLoopCount_0x34[0] &= ~FLAG_SOUND_LOOP_COUNT_FIELD; } - this->streamFlagsUnkAndLoopCount_0x34[0] &= ~FLAG_SOUND_LOOP_COUNT_FIELD; return; } if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0] = this->streamFlagsUnkAndLoopCount_0x34[0]; + ++this->streamFlagsUnkAndLoopCount_0x34[0]; } return; } From c56ba6c20ab52fbb5d896bbc83d30e3d8aeec5d4 Mon Sep 17 00:00:00 2001 From: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Date: Fri, 3 Jul 2026 22:20:14 +0200 Subject: [PATCH 4/6] reimplement: SHC_3BB0A8C1_0x0047BF20 improved structure, still issues --- .../playRandomBackgroundMusicUnk.cpp | 191 +++++++++--------- 1 file changed, 90 insertions(+), 101 deletions(-) diff --git a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp index 922c65b..15f5d16 100644 --- a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp +++ b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp @@ -32,7 +32,7 @@ namespace Audio { int bVar7 = true; if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.troopValueLevel == 0) { switch (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel) { - case 1: { + case 1: if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( @@ -48,8 +48,8 @@ namespace Audio { ++this->streamFlagsUnkAndLoopCount_0x34[0]; } return; - } - case 2: { + + case 2: if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( @@ -65,127 +65,117 @@ namespace Audio { ++this->streamFlagsUnkAndLoopCount_0x34[0]; } return; - } - case 5: { + + case 5: ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker > 2) { DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker = 1; if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { DAT_GameCore::instance.battleLevel2 += 2000; } - - } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 1) { + } + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 1) { MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( DAT_SFXDefinedData::instance.DAT_SFX_Pointers[27].musicFile); - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; - } - return; + } else { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); } - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { ++this->streamFlagsUnkAndLoopCount_0x34[0]; } return; } - } - } else { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel == 1) { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 == 0) { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[30].musicFile); - } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 1) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); - } else { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); - if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { - DAT_GameCore::instance.battleLevel2 += 5000; - } - } - ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; - } - return; + } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel == 1) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 == 0) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[30].musicFile); + } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 1) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); } else { - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; - bVar7 = false; + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[31].musicFile); + if (DAT_GameSynchronyState::instance.DAT_CurrentGameMode != Game::GM_SOLITARY) { + DAT_GameCore::instance.battleLevel2 += 5000; + } } - } else { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 == 0) { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { - if (this->sec_Section1055_0x3274 != 0x19) { + ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; + } + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; + bVar7 = false; + } else { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 == 0) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0 + && this->sec_Section1055_0x3274 != 25) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); + } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 2) { + ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 2) { MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; - } - return; + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[34].musicFile); } + DAT_SoundEffectsHelperData1::instance.field21_0x70 = 34; } else { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 2) { - ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 2) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[34].musicFile); - } - DAT_SoundEffectsHelperData1::instance.field21_0x70 = 34; - } else { - int iVar5 = DAT_SoundEffectsHelperData1::instance.field21_0x70 + -34; - int iVar6 = 0; - if (iVar5 < 0 || 7 < iVar5) { - iVar5 = 0; - } + int iVar5 = DAT_SoundEffectsHelperData1::instance.field21_0x70 + -34; + int iVar6 = 0; + if (iVar5 < 0 || 7 < iVar5) { + iVar5 = 0; + } - int aiStack_50[20]; - for (int i = 0; i < 8; ++i) { - if (iVar5 == i || DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][i] == 0) { - continue; - } - if (i == 4) { - aiStack_50[iVar6++] = 4; - aiStack_50[iVar6++] = 4; - aiStack_50[iVar6++] = 4; - aiStack_50[iVar6++] = 4; - aiStack_50[iVar6++] = 4; - aiStack_50[iVar6++] = 4; - continue; - } - int iVar1 = DAT_SFXDefinedData::instance.field3_0x4a4[i]; - int field6_0x34 = DAT_SoundEffectsHelperData1::instance.field6_0x34; - if ((iVar1 == 1 && iVar1 == field6_0x34) || (iVar1 == 2 && iVar1 == field6_0x34)) { - continue; - } + int aiStack_50[20]; + for (int i = 0; i < 8; ++i) { + if (iVar5 == i || DAT_SFXDefinedData::instance.field2_0x3a4[iVar5][i] == 0) { + continue; + } + if (i == 4) { + aiStack_50[iVar6++] = i; + aiStack_50[iVar6++] = i; + aiStack_50[iVar6++] = i; aiStack_50[iVar6++] = i; - if (field6_0x34 == 1 && iVar1 == 2) { - aiStack_50[iVar6++] = i; - } else if (field6_0x34 == 2 && iVar1 == 1) { - aiStack_50[iVar6++] = i; - } + aiStack_50[iVar6++] = i; + aiStack_50[iVar6++] = i; + continue; } - - if (iVar6 != 0) { - MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); - iVar5 = aiStack_50[SEC_RNG::instance.currentNumber1 % iVar6]; + int iVar1 = DAT_SFXDefinedData::instance.field3_0x4a4[i]; + int field6_0x34 = DAT_SoundEffectsHelperData1::instance.field6_0x34; + if ((iVar1 == 1 && iVar1 == field6_0x34) || (iVar1 == 2 && iVar1 == field6_0x34)) { + continue; + } + aiStack_50[iVar6++] = i; + if (field6_0x34 == 1 && iVar1 == 2) { + aiStack_50[iVar6++] = i; + } else if (field6_0x34 == 2 && iVar1 == 1) { + aiStack_50[iVar6++] = i; } - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[iVar5 + 34].musicFile); - DAT_SoundEffectsHelperData1::instance.field21_0x70 = iVar5 + 34; } - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; + + int sfxIndex; + if (iVar6 == 0) { + sfxIndex = iVar5 + 34; + } else { + MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); + sfxIndex = aiStack_50[SEC_RNG::instance.currentNumber1 % iVar6] + 34; } - return; + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[sfxIndex].musicFile); + DAT_SoundEffectsHelperData1::instance.field21_0x70 = sfxIndex; } - } else { - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; - bVar7 = false; } + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; } + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; + bVar7 = false; } if (this->musicFileHandle_0x178 != -1) { DAT_SoundEffectsHelperData1::instance.field14_0x54 = TRUE; @@ -197,12 +187,11 @@ namespace Audio { if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 1) { this->streamFlagsUnkAndLoopCount_0x34[0] &= ~FLAG_SOUND_LOOP_COUNT_FIELD; } - return; - } - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } else { + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } } - return; } } From 0e8b2486a362f983356c2b5c018de2dcb7607149 Mon Sep 17 00:00:00 2001 From: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Date: Fri, 3 Jul 2026 23:50:42 +0200 Subject: [PATCH 5/6] reimplement: SHC_3BB0A8C1_0x0047BF20 still one mismatch --- .../playRandomBackgroundMusicUnk.cpp | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp index 15f5d16..6d6715a 100644 --- a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp +++ b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp @@ -23,12 +23,13 @@ namespace Audio { } if (!MACRO_CALL_MEMBER(Game::GameCore_Func::getAreWeInAInGameMenu, DAT_GameCore::ptr)() && (DAT_GameCore::instance.currentMenuViewType != UI::Enums::MVT_SCENARIO_DESCRIPTION - || DAT_GameCore::instance.field25_0x64 == 0)) { + || !DAT_GameCore::instance.field25_0x64)) { if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 == 5) { DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; } return; } + int bVar7 = true; if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.troopValueLevel == 0) { switch (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.volumeLevel) { @@ -74,15 +75,18 @@ namespace Audio { DAT_GameCore::instance.battleLevel2 += 2000; } } - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 1) { + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 1) { MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[27].musicFile); + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } } else { MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); - } - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[27].musicFile); + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } } return; } @@ -111,10 +115,15 @@ namespace Audio { bVar7 = false; } else { if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field6_0x18 == 0) { - if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0 - && this->sec_Section1055_0x3274 != 25) { - MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( - DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); + if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 0) { + if (this->sec_Section1055_0x3274 != 25) { + MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( + DAT_SFXDefinedData::instance.DAT_SFX_Pointers[25].musicFile); + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; + } } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 2) { ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; @@ -168,14 +177,15 @@ namespace Audio { DAT_SFXDefinedData::instance.DAT_SFX_Pointers[sfxIndex].musicFile); DAT_SoundEffectsHelperData1::instance.field21_0x70 = sfxIndex; } + if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { + ++this->streamFlagsUnkAndLoopCount_0x34[0]; + } + return; } - if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { - ++this->streamFlagsUnkAndLoopCount_0x34[0]; - } - return; + } else { + DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; + bVar7 = false; } - DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; - bVar7 = false; } if (this->musicFileHandle_0x178 != -1) { DAT_SoundEffectsHelperData1::instance.field14_0x54 = TRUE; From 51d5bdb2578c4ab6f1db7f357faab94cb0af840b Mon Sep 17 00:00:00 2001 From: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Date: Sun, 5 Jul 2026 23:30:57 +0200 Subject: [PATCH 6/6] reimplement: SHC_3BB0A8C1_0x0047BF20 97.5% | SHC_3BB0A8C1_0x0046BB60 100% --- .../SoundSystem/playRandomBackgroundMusicUnk.cpp | 8 +++++++- .../Game/GameCore/getAreWeInAInGameMenu.cpp | 15 +++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/OpenSHC/Game/GameCore/getAreWeInAInGameMenu.cpp diff --git a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp index 6d6715a..ee3320e 100644 --- a/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp +++ b/src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp @@ -21,6 +21,12 @@ namespace Audio { if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 != 5) { return; } + + // NOTE: Current state has a mismatch with the bytes of this condition: The following early return is + // directly placed under it. So resolve this, one can move the first early return inside this if as or, + // which will produce the proper code for this position, but messes with the rest of the function in such + // a way that is produces a lower match. Due to the amount of time already spend, the function is kept in + // this state and maybe one day tackled again when the last once are cleaned up. if (!MACRO_CALL_MEMBER(Game::GameCore_Func::getAreWeInAInGameMenu, DAT_GameCore::ptr)() && (DAT_GameCore::instance.currentMenuViewType != UI::Enums::MVT_SCENARIO_DESCRIPTION || !DAT_GameCore::instance.field25_0x64)) { @@ -124,7 +130,7 @@ namespace Audio { } return; } - } else if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker != 0) { + } else { if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker < 2) { ++DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker; if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 2) { diff --git a/src/OpenSHC/Game/GameCore/getAreWeInAInGameMenu.cpp b/src/OpenSHC/Game/GameCore/getAreWeInAInGameMenu.cpp new file mode 100644 index 0000000..53bd2e2 --- /dev/null +++ b/src/OpenSHC/Game/GameCore/getAreWeInAInGameMenu.cpp @@ -0,0 +1,15 @@ +#include "..\GameCore.func.hpp" + +namespace OpenSHC { +namespace Game { + + // FUNCTION: STRONGHOLDCRUSADER 0x0046BB60 + BOOLEnum GameCore::getAreWeInAInGameMenu() + { + return this->currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING + || this->currentMenuViewType == UI::Enums::MVT_BUILD_MENU + || this->currentMenuViewType == UI::Enums::MVT_BUILDING_AND_STATUS_MENU; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index fcb9be8..f4a5f3a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -10261,7 +10261,7 @@ SHC_3BB0A8C1_0x0046B975 | 0.0% | Pending SHC_3BB0A8C1_0x0046B976 | 0.0% | Pending SHC_3BB0A8C1_0x0046B980 | 0.0% | Pending SHC_3BB0A8C1_0x0046BB20 | 0.0% | Pending -SHC_3BB0A8C1_0x0046BB60 | 0.0% | Pending +SHC_3BB0A8C1_0x0046BB60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0046BB80 | 0.0% | Pending SHC_3BB0A8C1_0x0046BBD0 | 0.0% | Pending SHC_3BB0A8C1_0x0046BC90 | 0.0% | Pending @@ -10938,7 +10938,7 @@ SHC_3BB0A8C1_0x0047B800 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0047B830 | 0.0% | Pending SHC_3BB0A8C1_0x0047B870 | 0.0% | Pending SHC_3BB0A8C1_0x0047B890 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0047BF20 | 0.0% | Pending +SHC_3BB0A8C1_0x0047BF20 | 97.5% | Reimplemented, but structural issue due to wrong hot path selection, which causes an early return body to not be placed at the end SHC_3BB0A8C1_0x0047C400 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0047C5D0 | 0.0% | Pending SHC_3BB0A8C1_0x0047C670 | 0.0% | Pending