fix audio crash when trying to detect BGM_DISABLED (#3150)

This commit is contained in:
Adam Bird 2023-08-30 13:07:21 -04:00 committed by GitHub
parent 7c31eafc1e
commit bea24fcde7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View file

@ -486,8 +486,10 @@ void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* ret
u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) { u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* outNumFonts) {
s32 index; s32 index;
if (seqId == NA_BGM_DISABLED) // 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; return NULL;
}
u16 newSeqId = AudioEditor_GetReplacementSeq(seqId); u16 newSeqId = AudioEditor_GetReplacementSeq(seqId);
if (newSeqId > sequenceMapSize || !sequenceMap[newSeqId]) { if (newSeqId > sequenceMapSize || !sequenceMap[newSeqId]) {

View file

@ -4659,19 +4659,25 @@ void func_800F5C2C(void) {
void Audio_PlayFanfare(u16 seqId) void Audio_PlayFanfare(u16 seqId)
{ {
u16 sp26; u16 curSeqId;
u32 sp20; u32 outNumFonts;
u8* sp1C; u8* curFontId;
u8* sp18; u8* requestedFontId;
sp26 = func_800FA0B4(SEQ_PLAYER_FANFARE); curSeqId = func_800FA0B4(SEQ_PLAYER_FANFARE);
sp1C = func_800E5E84(sp26 & 0xFF, &sp20);
sp18 = func_800E5E84(seqId, &sp20); // Although seqIds are u16, there is no fanfare that is above 0xFF
if (!sp1C || !sp18) { // 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! // disable BGM, we're about to null deref!
D_8016B9F4 = 1; D_8016B9F4 = 1;
} else { } else {
if ((sp26 == NA_BGM_DISABLED) || (*sp1C == *sp18)) { if ((curSeqId == NA_BGM_DISABLED) || (*curFontId == *requestedFontId)) {
D_8016B9F4 = 1; D_8016B9F4 = 1;
} else { } else {
D_8016B9F4 = 5; D_8016B9F4 = 5;