From 073205c862c3aa460300c299efe807bd6584ee2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Thu, 19 Jun 2025 20:40:24 +0000 Subject: [PATCH] ShufflePots: ShipInit (#5584) --- .../Enhancements/randomizer/ShufflePots.cpp | 37 +++++++++---------- soh/soh/Enhancements/randomizer/ShufflePots.h | 17 --------- .../Enhancements/randomizer/hook_handlers.cpp | 19 ---------- 3 files changed, 17 insertions(+), 56 deletions(-) delete mode 100644 soh/soh/Enhancements/randomizer/ShufflePots.h diff --git a/soh/soh/Enhancements/randomizer/ShufflePots.cpp b/soh/soh/Enhancements/randomizer/ShufflePots.cpp index 319237b98..e37b9ee16 100644 --- a/soh/soh/Enhancements/randomizer/ShufflePots.cpp +++ b/soh/soh/Enhancements/randomizer/ShufflePots.cpp @@ -1,4 +1,4 @@ -#include "ShufflePots.h" +#include "soh/OTRGlobals.h" #include "soh_assets.h" #include "static_data.h" @@ -51,48 +51,44 @@ void ObjTsubo_RandomizerSpawnCollectible(ObjTsubo* potActor, PlayState* play) { item00->actor.world.rot.y = static_cast(Rand_CenteredFloat(65536.0f)); } -void ObjTsubo_RandomizerInit(void* actorRef) { - Actor* actor = static_cast(actorRef); +void RegisterShufflePots() { + bool shouldRegister = IS_RANDO && RAND_GET_OPTION(RSK_SHUFFLE_POTS); - ObjTsubo* potActor = static_cast(actorRef); + COND_ID_HOOK(OnActorInit, ACTOR_OBJ_TSUBO, shouldRegister, [](void* actorRef) { + Actor* actor = static_cast(actorRef); + ObjTsubo* potActor = static_cast(actorRef); - potActor->potIdentity = OTRGlobals::Instance->gRandomizer->IdentifyPot( - gPlayState->sceneNum, (s16)actor->world.pos.x, (s16)actor->world.pos.z); -} - -void ShufflePots_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_list originalArgs) { - va_list args; - va_copy(args, originalArgs); + potActor->potIdentity = OTRGlobals::Instance->gRandomizer->IdentifyPot( + gPlayState->sceneNum, (s16)actor->world.pos.x, (s16)actor->world.pos.z); + }); // Draw custom model for pot to indicate it holding a randomized item. - if (id == VB_POT_SETUP_DRAW) { + COND_VB_SHOULD(VB_POT_SETUP_DRAW, shouldRegister, { ObjTsubo* potActor = va_arg(args, ObjTsubo*); if (ObjTsubo_RandomizerHoldsItem(potActor, gPlayState)) { potActor->actor.draw = (ActorFunc)ObjTsubo_RandomizerDraw; *should = false; } - } + }); // Do not spawn vanilla item from pot, instead spawn the ranomized item. - if (id == VB_POT_DROP_ITEM) { + COND_VB_SHOULD(VB_POT_DROP_ITEM, shouldRegister, { ObjTsubo* potActor = va_arg(args, ObjTsubo*); if (ObjTsubo_RandomizerHoldsItem(potActor, gPlayState)) { ObjTsubo_RandomizerSpawnCollectible(potActor, gPlayState); *should = false; } - } + }); // Unlock early Ganon's Boss Key doors to allow access to the pots there when pots are shuffled in dungeon - if (id == VB_LOCK_BOSS_DOOR) { + COND_VB_SHOULD(VB_LOCK_BOSS_DOOR, shouldRegister, { DoorShutter* doorActor = va_arg(args, DoorShutter*); uint8_t shufflePotSetting = RAND_GET_OPTION(RSK_SHUFFLE_POTS); if (gPlayState->sceneNum == SCENE_GANONS_TOWER && doorActor->dyna.actor.world.pos.y == 800 && (shufflePotSetting == RO_SHUFFLE_POTS_DUNGEONS || shufflePotSetting == RO_SHUFFLE_POTS_ALL)) { *should = false; } - } - - va_end(args); + }); } void Rando::StaticData::RegisterPotLocations() { @@ -653,4 +649,5 @@ void Rando::StaticData::RegisterPotLocations() { // clang-format on } -static RegisterShipInitFunc initFunc(Rando::StaticData::RegisterPotLocations); +static RegisterShipInitFunc registerShufflePots(RegisterShufflePots, { "IS_RANDO" }); +static RegisterShipInitFunc registerShufflePotLocations(Rando::StaticData::RegisterPotLocations); diff --git a/soh/soh/Enhancements/randomizer/ShufflePots.h b/soh/soh/Enhancements/randomizer/ShufflePots.h deleted file mode 100644 index cbe6ddaf5..000000000 --- a/soh/soh/Enhancements/randomizer/ShufflePots.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef SHUFFLEPOTS_H -#define SHUFFLEPOTS_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif -void ObjTsubo_RandomizerInit(void* actorRef); -#ifdef __cplusplus -}; -#endif - -void ShufflePots_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_list originalArgs); - -#endif // SHUFFLEPOTS_H diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index 58fc9123b..508979eaf 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/ShufflePots.h" #include "soh/Enhancements/randomizer/ShuffleFreestanding.h" #include "soh/Enhancements/game-interactor/GameInteractor.h" #include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" @@ -2332,9 +2331,6 @@ void RandomizerRegisterHooks() { static uint32_t fishsanityOnVanillaBehaviorHook = 0; static uint32_t fishsanityOnItemReceiveHook = 0; - static uint32_t shufflePotsOnActorInitHook = 0; - static uint32_t shufflePotsOnVanillaBehaviorHook = 0; - static uint32_t shuffleFreestandingOnVanillaBehaviorHook = 0; GameInteractor::Instance->RegisterGameHook([](int32_t fileNum) { @@ -2370,10 +2366,6 @@ void RandomizerRegisterHooks() { fishsanityOnVanillaBehaviorHook); GameInteractor::Instance->UnregisterGameHook(fishsanityOnItemReceiveHook); - GameInteractor::Instance->UnregisterGameHookForID(shufflePotsOnActorInitHook); - GameInteractor::Instance->UnregisterGameHook( - shufflePotsOnVanillaBehaviorHook); - GameInteractor::Instance->UnregisterGameHook( shuffleFreestandingOnVanillaBehaviorHook); @@ -2402,9 +2394,6 @@ void RandomizerRegisterHooks() { fishsanityOnVanillaBehaviorHook = 0; fishsanityOnItemReceiveHook = 0; - shufflePotsOnActorInitHook = 0; - shufflePotsOnVanillaBehaviorHook = 0; - shuffleFreestandingOnVanillaBehaviorHook = 0; ShuffleFairies_UnregisterHooks(); @@ -2474,14 +2463,6 @@ void RandomizerRegisterHooks() { Rando::Fishsanity::OnItemReceiveHandler); } - if (RAND_GET_OPTION(RSK_SHUFFLE_POTS) != RO_SHUFFLE_POTS_OFF) { - shufflePotsOnActorInitHook = GameInteractor::Instance->RegisterGameHookForID( - ACTOR_OBJ_TSUBO, ObjTsubo_RandomizerInit); - shufflePotsOnVanillaBehaviorHook = - GameInteractor::Instance->RegisterGameHook( - ShufflePots_OnVanillaBehaviorHandler); - } - if (RAND_GET_OPTION(RSK_SHUFFLE_FREESTANDING) != RO_SHUFFLE_FREESTANDING_OFF) { shuffleFreestandingOnVanillaBehaviorHook = GameInteractor::Instance->RegisterGameHook(