diff --git a/soh/soh/Enhancements/randomizer/ShuffleFreestanding.cpp b/soh/soh/Enhancements/randomizer/ShuffleFreestanding.cpp index fbd459458..7291fdbef 100644 --- a/soh/soh/Enhancements/randomizer/ShuffleFreestanding.cpp +++ b/soh/soh/Enhancements/randomizer/ShuffleFreestanding.cpp @@ -1,17 +1,17 @@ -#include "ShuffleFreestanding.h" +#include extern "C" { +#include "variables.h" #include "functions.h" extern PlayState* gPlayState; } extern void EnItem00_DrawRandomizedItem(EnItem00* enItem00, PlayState* play); -void ShuffleFreestanding_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_list originalArgs) { - va_list args; - va_copy(args, originalArgs); +void RegisterShuffleFreestanding() { + bool shouldRegister = IS_RANDO && RAND_GET_OPTION(RSK_SHUFFLE_FREESTANDING); - if (id == VB_ITEM00_DESPAWN) { + COND_VB_SHOULD(VB_ITEM00_DESPAWN, shouldRegister, { EnItem00* item00 = va_arg(args, EnItem00*); // Heart pieces and small keys are handled by default non-freestanding shuffles. @@ -22,14 +22,16 @@ void ShuffleFreestanding_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* sh uint32_t params = TWO_ACTOR_PARAMS((int32_t)item00->actor.world.pos.x, (int32_t)item00->actor.world.pos.z); Rando::Location* loc = OTRGlobals::Instance->gRandomizer->GetCheckObjectFromActor(item00->actor.id, gPlayState->sceneNum, params); + RandomizerCheck randomizerCheck = loc->GetRandomizerCheck(); + if (Rando::Context::GetInstance()->GetItemLocation(randomizerCheck)->HasObtained()) { + return; + } uint8_t isDungeon = loc->IsDungeon(); uint8_t freestandingSetting = RAND_GET_OPTION(RSK_SHUFFLE_FREESTANDING); - RandomizerCheck randomizerCheck = loc->GetRandomizerCheck(); - bool checkObtained = Rando::Context::GetInstance()->GetItemLocation(randomizerCheck)->HasObtained(); // Don't change to randomized item if current freestanding item isn't shuffled or already obtained. if ((freestandingSetting == RO_SHUFFLE_FREESTANDING_OVERWORLD && isDungeon) || - (freestandingSetting == RO_SHUFFLE_FREESTANDING_DUNGEONS && !isDungeon) || checkObtained || + (freestandingSetting == RO_SHUFFLE_FREESTANDING_DUNGEONS && !isDungeon) || randomizerCheck == RC_UNKNOWN_CHECK) { return; } @@ -41,7 +43,7 @@ void ShuffleFreestanding_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* sh item00->actor.draw = (ActorFunc)EnItem00_DrawRandomizedItem; *should = false; - } + }); } void Rando::StaticData::RegisterFreestandingLocations() { @@ -284,4 +286,5 @@ void Rando::StaticData::RegisterFreestandingLocations() { // clang-format on } -static RegisterShipInitFunc initFunc(Rando::StaticData::RegisterFreestandingLocations); +static RegisterShipInitFunc registerShuffleFreestanding(RegisterShuffleFreestanding, { "IS_RANDO" }); +static RegisterShipInitFunc registerShuffleFreestandingLocations(Rando::StaticData::RegisterFreestandingLocations); diff --git a/soh/soh/Enhancements/randomizer/ShuffleFreestanding.h b/soh/soh/Enhancements/randomizer/ShuffleFreestanding.h deleted file mode 100644 index 9234f76fa..000000000 --- a/soh/soh/Enhancements/randomizer/ShuffleFreestanding.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef SHUFFLE_FREESTANDING_H -#define SHUFFLE_FREESTANDING_H - -#include -#include - -void ShuffleFreestanding_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_list originalArgs); - -#endif diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index 7f23f60cc..a6bbae638 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -8,7 +8,6 @@ #include "soh/Enhancements/randomizer/dungeon.h" #include "soh/Enhancements/randomizer/fishsanity.h" #include "soh/Enhancements/randomizer/static_data.h" -#include "soh/Enhancements/randomizer/ShuffleFreestanding.h" #include "soh/Enhancements/game-interactor/GameInteractor.h" #include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" #include "soh/SohGui/ImGuiUtils.h" @@ -2330,8 +2329,6 @@ void RandomizerRegisterHooks() { static uint32_t fishsanityOnVanillaBehaviorHook = 0; static uint32_t fishsanityOnItemReceiveHook = 0; - static uint32_t shuffleFreestandingOnVanillaBehaviorHook = 0; - GameInteractor::Instance->RegisterGameHook([](int32_t fileNum) { ShipInit::Init("IS_RANDO"); @@ -2365,9 +2362,6 @@ void RandomizerRegisterHooks() { fishsanityOnVanillaBehaviorHook); GameInteractor::Instance->UnregisterGameHook(fishsanityOnItemReceiveHook); - GameInteractor::Instance->UnregisterGameHook( - shuffleFreestandingOnVanillaBehaviorHook); - onFlagSetHook = 0; onSceneFlagSetHook = 0; onPlayerUpdateForRCQueueHook = 0; @@ -2393,8 +2387,6 @@ void RandomizerRegisterHooks() { fishsanityOnVanillaBehaviorHook = 0; fishsanityOnItemReceiveHook = 0; - shuffleFreestandingOnVanillaBehaviorHook = 0; - if (!IS_RANDO) return; @@ -2459,11 +2451,5 @@ void RandomizerRegisterHooks() { fishsanityOnItemReceiveHook = GameInteractor::Instance->RegisterGameHook( Rando::Fishsanity::OnItemReceiveHandler); } - - if (RAND_GET_OPTION(RSK_SHUFFLE_FREESTANDING) != RO_SHUFFLE_FREESTANDING_OFF) { - shuffleFreestandingOnVanillaBehaviorHook = - GameInteractor::Instance->RegisterGameHook( - ShuffleFreestanding_OnVanillaBehaviorHandler); - } }); }