diff --git a/soh/soh/Enhancements/randomizer/grassanity.cpp b/soh/soh/Enhancements/randomizer/grassanity.cpp index cb1fd29cf..09511da61 100644 --- a/soh/soh/Enhancements/randomizer/grassanity.cpp +++ b/soh/soh/Enhancements/randomizer/grassanity.cpp @@ -10,8 +10,9 @@ extern "C" { extern PlayState* gPlayState; } -extern void EnItem00_DrawRandomizedItem(EnItem00* enItem00, PlayState* play); +#define RAND_GET_OPTION(option) Rando::Context::GetInstance()->GetOption(option).Get() +extern void EnItem00_DrawRandomizedItem(EnItem00* enItem00, PlayState* play); extern "C" void EnKusa_RandomizerDraw(Actor* thisx, PlayState* play) { static Gfx* dLists[] = { (Gfx*)gFieldBushDL, (Gfx*)object_kusa_DL_000140, (Gfx*)object_kusa_DL_000140 }; @@ -21,7 +22,8 @@ extern "C" void EnKusa_RandomizerDraw(Actor* thisx, PlayState* play) { Gfx_SetupDL_25Opa(play->state.gfxCtx); gDPSetGrayscaleColor(POLY_OPA_DISP++, 175, 255, 0, 255); - if (grassActor->grassIdentity.randomizerCheck != RC_MAX && Flags_GetRandomizerInf(grassActor->grassIdentity.randomizerInf) == 0) { + if (grassActor->grassIdentity.randomizerCheck != RC_MAX && + Flags_GetRandomizerInf(grassActor->grassIdentity.randomizerInf) == 0) { gSPGrayscale(POLY_OPA_DISP++, true); } @@ -59,7 +61,8 @@ uint8_t EnKusa_RandomizerHoldsItem(EnKusa* grassActor, PlayState* play) { void EnKusa_RandomizerSpawnCollectible(EnKusa* grassActor, PlayState* play) { EnItem00* item00 = (EnItem00*)Item_DropCollectible2(play, &grassActor->actor.world.pos, ITEM00_SOH_DUMMY); item00->randoInf = grassActor->grassIdentity.randomizerInf; - item00->itemEntry = Rando::Context::GetInstance()->GetFinalGIEntry(grassActor->grassIdentity.randomizerCheck, true, GI_NONE); + item00->itemEntry = + Rando::Context::GetInstance()->GetFinalGIEntry(grassActor->grassIdentity.randomizerCheck, true, GI_NONE); item00->actor.draw = (ActorFunc)EnItem00_DrawRandomizedItem; item00->actor.velocity.y = 8.0f; item00->actor.speedXZ = 2.0f; @@ -69,20 +72,22 @@ void EnKusa_RandomizerSpawnCollectible(EnKusa* grassActor, PlayState* play) { void EnKusa_RandomizerInit(void* actorRef) { Actor* actor = static_cast(actorRef); - if (actor->id != ACTOR_EN_KUSA) return; + if (actor->id != ACTOR_EN_KUSA) + return; EnKusa* grassActor = static_cast(actorRef); s16 respawnData = gSaveContext.respawn[RESPAWN_MODE_RETURN].data & ((1 << 8) - 1); - grassActor->grassIdentity = OTRGlobals::Instance->gRandomizer->IdentifyGrass(gPlayState->sceneNum, (s16)actor->world.pos.x, (s16)actor->world.pos.z, respawnData, gPlayState->linkAgeOnLoad); + grassActor->grassIdentity = OTRGlobals::Instance->gRandomizer->IdentifyGrass( + gPlayState->sceneNum, (s16)actor->world.pos.x, (s16)actor->world.pos.z, respawnData, gPlayState->linkAgeOnLoad); } -void ShuffleGrass_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_list originalArgs) { - va_list args; - va_copy(args, originalArgs); +void RegisterGrassanity() { + bool shouldRegister = IS_RANDO && RAND_GET_OPTION(RSK_GRASSANITY); - // Draw custom model for grass to indicate it holding a randomized item. - if (id == VB_GRASS_SETUP_DRAW) { + COND_ID_HOOK(OnActorInit, ACTOR_EN_KUSA, shouldRegister, EnKusa_RandomizerInit); + + COND_VB_SHOULD(VB_GRASS_SETUP_DRAW, shouldRegister, { EnKusa* grassActor = va_arg(args, EnKusa*); if (EnKusa_RandomizerHoldsItem(grassActor, gPlayState)) { grassActor->actor.draw = (ActorFunc)EnKusa_RandomizerDraw; @@ -90,10 +95,9 @@ void ShuffleGrass_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, v } else { *should = true; } - } + }); - // Do not spawn vanilla item from grass, instead spawn the randomized item. - if (id == VB_GRASS_DROP_ITEM) { + COND_VB_SHOULD(VB_GRASS_DROP_ITEM, shouldRegister, { EnKusa* grassActor = va_arg(args, EnKusa*); if (EnKusa_RandomizerHoldsItem(grassActor, gPlayState)) { EnKusa_RandomizerSpawnCollectible(grassActor, gPlayState); @@ -103,7 +107,7 @@ void ShuffleGrass_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, v } else { *should = true; } - } - - va_end(args); + }); } + +static RegisterShipInitFunc initFunc(RegisterGrassanity, { "IS_RANDO" }); \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index 5883f4716..cc9708789 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -16,7 +16,6 @@ #include "soh/Notification/Notification.h" #include "soh/SaveManager.h" #include "soh/Enhancements/randomizer/ShuffleFairies.h" -#include "soh/Enhancements/randomizer/grassanity.h" extern "C" { #include "macros.h" @@ -2372,9 +2371,6 @@ void RandomizerRegisterHooks() { static uint32_t shuffleFreestandingOnVanillaBehaviorHook = 0; - static uint32_t shuffleGrassOnActorInitHook = 0; - static uint32_t shuffleGrassOnVanillaBehaviorHook = 0; - GameInteractor::Instance->RegisterGameHook([](int32_t fileNum) { ShipInit::Init("IS_RANDO"); @@ -2410,9 +2406,6 @@ void RandomizerRegisterHooks() { GameInteractor::Instance->UnregisterGameHook(shuffleFreestandingOnVanillaBehaviorHook); - GameInteractor::Instance->UnregisterGameHook(shuffleGrassOnActorInitHook); - GameInteractor::Instance->UnregisterGameHook(shuffleGrassOnVanillaBehaviorHook); - onFlagSetHook = 0; onSceneFlagSetHook = 0; onPlayerUpdateForRCQueueHook = 0; @@ -2441,9 +2434,6 @@ void RandomizerRegisterHooks() { shuffleFreestandingOnVanillaBehaviorHook = 0; - shuffleGrassOnActorInitHook = 0; - shuffleGrassOnVanillaBehaviorHook = 0; - ShuffleFairies_UnregisterHooks(); if (!IS_RANDO) return; @@ -2496,10 +2486,5 @@ void RandomizerRegisterHooks() { if (RAND_GET_OPTION(RSK_SHUFFLE_FAIRIES)) { ShuffleFairies_RegisterHooks(); } - - if (RAND_GET_OPTION(RSK_GRASSANITY)) { - shuffleGrassOnActorInitHook = GameInteractor::Instance->RegisterGameHook(EnKusa_RandomizerInit); - shuffleGrassOnVanillaBehaviorHook = GameInteractor::Instance->RegisterGameHook(ShuffleGrass_OnVanillaBehaviorHandler); - } }); } diff --git a/soh/src/overlays/actors/ovl_En_Kusa/z_en_kusa.c b/soh/src/overlays/actors/ovl_En_Kusa/z_en_kusa.c index 6b59b421c..4ed8d32e4 100644 --- a/soh/src/overlays/actors/ovl_En_Kusa/z_en_kusa.c +++ b/soh/src/overlays/actors/ovl_En_Kusa/z_en_kusa.c @@ -292,7 +292,7 @@ void EnKusa_WaitObject(EnKusa* this, PlayState* play) { EnKusa_SetupMain(this); } - if (!GameInteractor_Should(VB_GRASS_SETUP_DRAW, false, this)) { + if (!GameInteractor_Should(VB_GRASS_SETUP_DRAW, true, this)) { return; }