-
Notifications
You must be signed in to change notification settings - Fork 3
reimplement: SHC_3BB0A8C1_0x0047BF20 97.5% | SHC_3BB0A8C1_0x0046BB60 100% #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
TheRedDaemon
wants to merge
6
commits into
main
Choose a base branch
from
reimpl/SHC_3BB0A8C1_0x0047BF20
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e2e0fbe
reimplement: SHC_3BB0A8C1_0x0047BF20 setup method
TheRedDaemon 58ac680
reimplement: SHC_3BB0A8C1_0x0047BF20 remove gotos
TheRedDaemon 7cd4fc7
reimplement: SHC_3BB0A8C1_0x0047BF20 register and structure issues
TheRedDaemon c56ba6c
reimplement: SHC_3BB0A8C1_0x0047BF20 improved structure, still issues
TheRedDaemon 0e8b248
reimplement: SHC_3BB0A8C1_0x0047BF20 still one mismatch
TheRedDaemon 51d5bdb
reimplement: SHC_3BB0A8C1_0x0047BF20 97.5% | SHC_3BB0A8C1_0x0046BB60 …
TheRedDaemon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
215 changes: 215 additions & 0 deletions
215
src/OpenSHC/Audio/mss/SoundSystem/playRandomBackgroundMusicUnk.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| #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() | ||
| { | ||
| 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)) { | ||
| 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) { | ||
| 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; | ||
|
|
||
| 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; | ||
|
|
||
| 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; | ||
| } | ||
| } | ||
| if (DAT_SoundEffectsHelperData1::instance.SEC_Section1079.musicTracker == 1) { | ||
| 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]; | ||
| } | ||
| } else { | ||
| 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 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; | ||
| } | ||
| 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) { | ||
| 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 < 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 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; | ||
| aiStack_50[iVar6++] = i; | ||
| aiStack_50[iVar6++] = i; | ||
| 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; | ||
| } | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
| MACRO_CALL_MEMBER(SoundSystem_Func::openSound, this)( | ||
| 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; | ||
| } | ||
| } else { | ||
| DAT_SoundEffectsHelperData1::instance.SEC_Section1079.field0_0x0 = 1; | ||
| bVar7 = false; | ||
| } | ||
| } | ||
| 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) { | ||
| this->streamFlagsUnkAndLoopCount_0x34[0] &= ~FLAG_SOUND_LOOP_COUNT_FIELD; | ||
| } | ||
| } else { | ||
| if ((this->streamFlagsUnkAndLoopCount_0x34[0] & FLAG_SOUND_LOOP_COUNT_FIELD) == 0) { | ||
| ++this->streamFlagsUnkAndLoopCount_0x34[0]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure it is int? Some
&operations naturally produce negative right-hand-sides if an int.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It increased the matching and actually started producing the binary mask instead of just using a mov to a 16bit register.
But this function is another one of these annoying ones. A lot of branch optimization, gotos.
Always in the hope that there is a when: When we manage to match the function, I will try reverting this change and test around a bit.
If this goes through, all other methods need to be tested again, of course.