From e76b990c8a37d4877ebd4aef9ab8093450e9a0c1 Mon Sep 17 00:00:00 2001 From: Malkierian Date: Wed, 22 Mar 2023 17:59:08 -0700 Subject: Randomzier: Fix starting rupee item collection (#2645) * When rupees are given as starting items, they still modify `gSaveContext.rupeeAccumulator`, which means that if you make a new file, start it, and reload without saving, or exit SoH before starting the new file, those rupees were lost. This adds a check for `gPlayState` being NULL, and if it is, adds those initial rupees to the rupee count directly. * Update soh/src/code/z_parameter.c Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com> --------- Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com> --- soh/src/code/z_parameter.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'soh/src/code') diff --git a/soh/src/code/z_parameter.c b/soh/src/code/z_parameter.c index c5bbb38ca..1b44f67d5 100644 --- a/soh/src/code/z_parameter.c +++ b/soh/src/code/z_parameter.c @@ -3084,7 +3084,11 @@ s32 Health_ChangeBy(PlayState* play, s16 healthChange) { } void Rupees_ChangeBy(s16 rupeeChange) { - gSaveContext.rupeeAccumulator += rupeeChange; + if (gPlayState == NULL) { + gSaveContext.rupees += rupeeChange; + } else { + gSaveContext.rupeeAccumulator += rupeeChange; + } if (rupeeChange > 0) { gSaveContext.sohStats.count[COUNT_RUPEES_COLLECTED] += rupeeChange; -- cgit v1.2.3 From f7703e14e85d7646248320168dc0f4aa3c6c43de Mon Sep 17 00:00:00 2001 From: Malkierian Date: Fri, 31 Mar 2023 20:35:29 -0700 Subject: Fix Missing Custom Sequences (#2649) * Modifies custom sequence loading to bypass other sounds being loaded in AudioCollection to fix missing custom sequences on load. * Modified `audio_load`'s sequenceMap allocation to utilize `AudioCollection`'s sequenceMap size to account for all audio assets already loaded into that sequenceMap. This gives a non-arbitrary number in addition to the vanilla sequence count to allocate with for `audio_load`'s sequenceMap. Added `HasSequenceNum` to `AudioCollection` as well to streamline the check against `AudioCollection`'s sequenceMap to skip the non-sequence assets in there. Added clarification comment for seqNum and MAX_AUTHENTIC_SEQID section. * Clarified comment about AudioCollection seqNum and MAX_AUTHENTIC_SEQID. * A bit more on comment from the last commit. --- soh/src/code/audio_load.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'soh/src/code') diff --git a/soh/src/code/audio_load.c b/soh/src/code/audio_load.c index eb788fd0c..583ce84fe 100644 --- a/soh/src/code/audio_load.c +++ b/soh/src/code/audio_load.c @@ -1346,7 +1346,7 @@ void AudioLoad_Init(void* heap, size_t heapSize) { int customSeqListSize = 0; char** seqList = ResourceMgr_ListFiles("audio/sequences*", &seqListSize); char** customSeqList = ResourceMgr_ListFiles("custom/music/*", &customSeqListSize); - sequenceMapSize = (size_t)(seqListSize + customSeqListSize); + sequenceMapSize = (size_t)(AudioCollection_SequenceMapSize() + customSeqListSize); sequenceMap = malloc(sequenceMapSize * sizeof(char*)); gAudioContext.seqLoadStatus = malloc(sequenceMapSize * sizeof(char*)); @@ -1366,16 +1366,27 @@ void AudioLoad_Init(void* heap, size_t heapSize) { int startingSeqNum = MAX_AUTHENTIC_SEQID; // 109 is the highest vanilla sequence qsort(customSeqList, customSeqListSize, sizeof(char*), strcmp_sort); + // Because AudioCollection's sequenceMap actually has more than sequences (including instruments from 130-135 and sfx in the 2000s, 6000s, 10000s, 14000s, 18000s, and 26000s), + // it's better here to keep track of the next empty seqNum in AudioCollection instead of just skipping past the instruments at 130 with a higher MAX_AUTHENTIC_SEQID, + // especially if those others could be added to in the future. However, this really needs to be streamlined with specific ranges in AudioCollection for types, or unifying + // AudioCollection and the various maps in here + int seqNum = startingSeqNum; + for (size_t i = startingSeqNum; i < startingSeqNum + customSeqListSize; i++) { + // ensure that what would be the next sequence number is actually unassigned in AudioCollection + while (AudioCollection_HasSequenceNum(seqNum)) { + seqNum++; + } int j = i - startingSeqNum; - AudioCollection_AddToCollection(customSeqList[j], i); + AudioCollection_AddToCollection(customSeqList[j], seqNum); SequenceData sDat = ResourceMgr_LoadSeqByName(customSeqList[j]); - sDat.seqNumber = i; + sDat.seqNumber = seqNum; char* str = malloc(strlen(customSeqList[j]) + 1); strcpy(str, customSeqList[j]); sequenceMap[sDat.seqNumber] = str; + seqNum++; } free(customSeqList); -- cgit v1.2.3