summaryrefslogtreecommitdiff
path: root/soh/src/code
diff options
context:
space:
mode:
authorAdam Bird <Archez@users.noreply.github.com>2023-08-30 13:07:21 -0400
committerGitHub <noreply@github.com>2023-08-30 17:07:21 +0000
commitbea24fcde71c551f9954aa785dbefd7724e3b69e (patch)
treebfa64ebad5b094baaa7fee9b3a951cb2c077c665 /soh/src/code
parent7c31eafc1e9c355c3cc46f47af7e1d3c6a46ceea (diff)
fix audio crash when trying to detect BGM_DISABLED (#3150)
Diffstat (limited to 'soh/src/code')
-rw-r--r--soh/src/code/audio_load.c6
-rw-r--r--soh/src/code/code_800EC960.c26
2 files changed, 20 insertions, 12 deletions
diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c
index 7c02b7b9c..4a8a94eed 100644
--- a/soh/src/code/audio_load.c
+++ b/soh/src/code/audio_load.c
@@ -486,8 +486,10 @@ void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* ret
u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
s32 index;
- if (seqId == NA_BGM_DISABLED)
- return NULL;
+ // Check for NA_BGM_DISABLED and account for seqId that are stripped with `& 0xFF` by the caller
+ if (seqId == NA_BGM_DISABLED || seqId == 0xFF) {
+ return NULL;
+ }
u16 newSeqId = AudioEditor_GetReplacementSeq(seqId);
if (newSeqId > sequenceMapSize || !sequenceMap[newSeqId]) {
diff --git a/soh/src/code/code_800EC960.c b/soh/src/code/code_800EC960.c
index 3f0c91001..f2f72885d 100644
--- a/soh/src/code/code_800EC960.c
+++ b/soh/src/code/code_800EC960.c
@@ -4659,19 +4659,25 @@ void func_800F5C2C(void) {
void Audio_PlayFanfare(u16 seqId)
{
- u16 sp26;
- u32 sp20;
- u8* sp1C;
- u8* sp18;
-
- sp26 = func_800FA0B4(SEQ_PLAYER_FANFARE);
- sp1C = func_800E5E84(sp26 & 0xFF, &sp20);
- sp18 = func_800E5E84(seqId, &sp20);
- if (!sp1C || !sp18) {
+ u16 curSeqId;
+ u32 outNumFonts;
+ u8* curFontId;
+ u8* requestedFontId;
+
+ curSeqId = func_800FA0B4(SEQ_PLAYER_FANFARE);
+
+ // Although seqIds are u16, there is no fanfare that is above 0xFF
+ // Sometimes the game will add 0x900 to a requested fanfare ID
+ // The `& 0xFF` here is to strip off this 0x900 and get the original fanfare ID
+ // when getting the sound font data for the sequence
+ curFontId = func_800E5E84(curSeqId & 0xFF, &outNumFonts);
+ requestedFontId = func_800E5E84(seqId & 0xFF, &outNumFonts);
+
+ if (!curFontId || !requestedFontId) {
// disable BGM, we're about to null deref!
D_8016B9F4 = 1;
} else {
- if ((sp26 == NA_BGM_DISABLED) || (*sp1C == *sp18)) {
+ if ((curSeqId == NA_BGM_DISABLED) || (*curFontId == *requestedFontId)) {
D_8016B9F4 = 1;
} else {
D_8016B9F4 = 5;