From c17b55b465ca122cff68e2c125940f41affa9bde Mon Sep 17 00:00:00 2001 From: Pepper0ni <93387759+Pepper0ni@users.noreply.github.com> Date: Fri, 20 Dec 2024 22:44:35 +0000 Subject: [PATCH] Improve KZ hook (#4732) * improve KZ hook * Adjust KZ hooks to permit early eyeball frog in rando * Update soh/soh/Enhancements/randomizer/hook_handlers.cpp Co-authored-by: Archez * Update soh/soh/Enhancements/game-interactor/GameInteractor.h Co-authored-by: Archez --------- Co-authored-by: Archez --- .../game-interactor/GameInteractor.h | 10 ++-- .../Enhancements/randomizer/hook_handlers.cpp | 46 ++++++++++++------- soh/src/overlays/actors/ovl_En_Kz/z_en_kz.c | 38 ++++++--------- soh/src/overlays/actors/ovl_En_Kz/z_en_kz.h | 1 - 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor.h b/soh/soh/Enhancements/game-interactor/GameInteractor.h index 44d0ef1fc..754b77cc1 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor.h @@ -196,6 +196,9 @@ typedef enum { // Opt: *EnKz // Vanilla condition: Flags_GetEventChkInf(EVENTCHKINF_KING_ZORA_MOVED) VB_KING_ZORA_BE_MOVED, + // Opt: *EnKz, + // Vanilla condition: CHECK_OWNED_EQUIP(EQUIP_TYPE_TUNIC, EQUIP_INV_TUNIC_ZORA) + VB_KING_ZORA_TUNIC_CHECK, // Vanilla condition: gSaveState.bgsFlag VB_BIGGORON_CONSIDER_TRADE_COMPLETE, // Vanilla condition: gSaveState.bgsFlag @@ -395,9 +398,6 @@ typedef enum { VB_GIVE_ITEM_FROM_ANJU_AS_CHILD, // Opt: *EnNiwLady VB_GIVE_ITEM_FROM_ANJU_AS_ADULT, - // Opt: *EnKz - // Vanilla condition: !CHECK_OWNED_EQUIP(EQUIP_TYPE_TUNIC, EQUIP_INV_TUNIC_ZORA) - VB_GIVE_ITEM_FROM_THAWING_KING_ZORA, // Opt: *EnGo2 VB_GIVE_ITEM_FROM_GORON, // Opt: *EnGb @@ -479,13 +479,13 @@ typedef enum { // Opt: *EnToryo VB_TRADE_SAW, // Opt: *EnKz, - VB_TRADE_PRESCRIPTION, + VB_ADULT_KING_ZORA_ITEM_GIVE, // Opt: *EnMk VB_TRADE_FROG, VB_TRADE_TIMER_ODD_MUSHROOM, - VB_TRADE_TIMER_EYEDROPS, VB_TRADE_TIMER_FROG, + VB_TRADE_TIMER_EYEDROPS, // Opt: *EnNiwLady VB_ANJU_SET_OBTAINED_TRADE_ITEM, diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index 0a99dfb86..93213afb8 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -946,6 +946,12 @@ void RandomizerOnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_l } break; } + case VB_KING_ZORA_TUNIC_CHECK: { + if (!Flags_GetRandomizerInf(RAND_INF_KING_ZORA_THAWED)) { + *should = false; + } + break; + } case VB_BIGGORON_CONSIDER_SWORD_COLLECTED: { *should = Flags_GetRandomizerInf(RAND_INF_ADULT_TRADES_DMT_TRADE_CLAIM_CHECK); break; @@ -1054,17 +1060,6 @@ void RandomizerOnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_l *should = false; break; } - case VB_GIVE_ITEM_FROM_THAWING_KING_ZORA: { - EnKz* enKz = va_arg(args, EnKz*); - // If we aren't setting up the item offer, then we're just checking if it should be possible. - if (enKz->actionFunc != (EnKzActionFunc)EnKz_SetupGetItem) { - // Always give the reward in rando - *should = true; - break; - } - *should = false; - break; - } case VB_GIVE_ITEM_FROM_ANJU_AS_CHILD: { Flags_SetItemGetInf(ITEMGETINF_0C); *should = false; @@ -1195,14 +1190,31 @@ void RandomizerOnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_l *should = false; break; } - case VB_TRADE_PRESCRIPTION: { + case VB_ADULT_KING_ZORA_ITEM_GIVE: { EnKz* enKz = va_arg(args, EnKz*); - // If we aren't setting up the item offer, then we're just checking if it should be possible. - if (enKz->actionFunc != (EnKzActionFunc)EnKz_SetupGetItem) { - *should = !Flags_GetRandomizerInf(RAND_INF_ADULT_TRADES_ZD_TRADE_PRESCRIPTION); - break; + Input input = gPlayState->state.input[0]; + + if (CVarGetInteger(CVAR_ENHANCEMENT("EarlyEyeballFrog"), 0)) { + // For early eyeball frog hook override, simulate collection delay behavior by just checking for the R + // button being held while wearing a shield, and a trade item lower than frog in inventory + bool hasShieldHoldingR = (CHECK_BTN_ANY(input.cur.button, BTN_R) && + CUR_EQUIP_VALUE(EQUIP_TYPE_SHIELD) > EQUIP_VALUE_SHIELD_NONE); + + if (func_8002F368(gPlayState) == EXCH_ITEM_PRESCRIPTION || + (hasShieldHoldingR && INV_CONTENT(ITEM_TRADE_ADULT) < ITEM_FROG)) { + Flags_SetRandomizerInf(RAND_INF_ADULT_TRADES_ZD_TRADE_PRESCRIPTION); + Randomizer_ConsumeAdultTradeItem(gPlayState, ITEM_PRESCRIPTION); + } else { + Flags_SetRandomizerInf(RAND_INF_KING_ZORA_THAWED); + } + } else { + if (enKz->isTrading){ + Flags_SetRandomizerInf(RAND_INF_ADULT_TRADES_ZD_TRADE_PRESCRIPTION); + Randomizer_ConsumeAdultTradeItem(gPlayState, ITEM_PRESCRIPTION); + } else { + Flags_SetRandomizerInf(RAND_INF_KING_ZORA_THAWED); + } } - Randomizer_ConsumeAdultTradeItem(gPlayState, ITEM_PRESCRIPTION); *should = false; break; } diff --git a/soh/src/overlays/actors/ovl_En_Kz/z_en_kz.c b/soh/src/overlays/actors/ovl_En_Kz/z_en_kz.c index e6ad9e997..22e0fa413 100644 --- a/soh/src/overlays/actors/ovl_En_Kz/z_en_kz.c +++ b/soh/src/overlays/actors/ovl_En_Kz/z_en_kz.c @@ -94,9 +94,8 @@ u16 EnKz_GetTextNoMaskAdult(PlayState* play, EnKz* this) { // this works because both ITEM_NONE and later trade items are > ITEM_FROG if (INV_CONTENT(ITEM_TRADE_ADULT) >= ITEM_FROG) { if (!Flags_GetInfTable(INFTABLE_139)) { - if (!GameInteractor_Should(VB_GIVE_ITEM_FROM_THAWING_KING_ZORA, ( - !CHECK_OWNED_EQUIP(EQUIP_TYPE_TUNIC, EQUIP_INV_TUNIC_ZORA) - ), this)) { + if (GameInteractor_Should(VB_KING_ZORA_TUNIC_CHECK, + CHECK_OWNED_EQUIP(EQUIP_TYPE_TUNIC, EQUIP_INV_TUNIC_ZORA), this)) { return 0x401F; } else { return 0x4012; @@ -148,7 +147,7 @@ s16 func_80A9C6C0(PlayState* play, Actor* thisx) { case 0x401F: Flags_SetInfTable(INFTABLE_139); break; - } + } } break; case TEXT_STATE_CLOSING: @@ -306,15 +305,13 @@ void func_80A9CB18(EnKz* this, PlayState* play) { if (LINK_IS_ADULT) { if ((INV_CONTENT(ITEM_TRADE_ADULT) == ITEM_PRESCRIPTION) && (func_8002F368(play) == EXCH_ITEM_PRESCRIPTION)) { - if (GameInteractor_Should(VB_TRADE_PRESCRIPTION, true, this)) { - this->actor.textId = 0x4014; - this->sfxPlayed = false; - player->actor.textId = this->actor.textId; - if (!CVarGetInteger(CVAR_ENHANCEMENT("EarlyEyeballFrog"), 0)) { - this->isTrading = true; - } - return; + this->actor.textId = 0x4014; + this->sfxPlayed = false; + player->actor.textId = this->actor.textId; + if (!CVarGetInteger(CVAR_ENHANCEMENT("EarlyEyeballFrog"), 0)) { + this->isTrading = true; } + return; } if (!CVarGetInteger(CVAR_ENHANCEMENT("EarlyEyeballFrog"), 0)) { this->isTrading = false; @@ -324,11 +321,10 @@ void func_80A9CB18(EnKz* this, PlayState* play) { player->actor.textId = this->actor.textId; } else { this->actor.textId = - !GameInteractor_Should(VB_GIVE_ITEM_FROM_THAWING_KING_ZORA, - (!CHECK_OWNED_EQUIP(EQUIP_TYPE_TUNIC, EQUIP_INV_TUNIC_ZORA)), this) + GameInteractor_Should(VB_KING_ZORA_TUNIC_CHECK, + CHECK_OWNED_EQUIP(EQUIP_TYPE_TUNIC, EQUIP_INV_TUNIC_ZORA), this) ? 0x401F : 0x4012; - player->actor.textId = this->actor.textId; } } @@ -511,18 +507,10 @@ void EnKz_SetupGetItem(EnKz* this, PlayState* play) { f32 xzRange; f32 yRange; - if (Actor_HasParent(&this->actor, play) || ( - (this->isTrading && !GameInteractor_Should(VB_TRADE_PRESCRIPTION, true, this)) || - (!this->isTrading && !GameInteractor_Should(VB_GIVE_ITEM_FROM_THAWING_KING_ZORA, true, this)) - )) { + if (Actor_HasParent(&this->actor, play) || !GameInteractor_Should(VB_ADULT_KING_ZORA_ITEM_GIVE, true, this)) { this->actor.parent = NULL; this->interactInfo.talkState = NPC_TALK_STATE_TALKING; this->actionFunc = EnKz_StartTimer; - if (!this->isTrading) { - Flags_SetRandomizerInf(RAND_INF_KING_ZORA_THAWED); - } else { - Flags_SetRandomizerInf(RAND_INF_ADULT_TRADES_ZD_TRADE_PRESCRIPTION); - } } else { if (CVarGetInteger(CVAR_ENHANCEMENT("EarlyEyeballFrog"), 0)) { getItemId = func_8002F368(play) == EXCH_ITEM_PRESCRIPTION ? GI_FROG : GI_TUNIC_ZORA; @@ -537,7 +525,7 @@ void EnKz_SetupGetItem(EnKz* this, PlayState* play) { void EnKz_StartTimer(EnKz* this, PlayState* play) { if ((Message_GetState(&play->msgCtx) == TEXT_STATE_DONE) && Message_ShouldAdvance(play)) { - if (INV_CONTENT(ITEM_TRADE_ADULT) == ITEM_FROG && GameInteractor_Should(VB_TRADE_TIMER_FROG, true)) { + if (GameInteractor_Should(VB_TRADE_TIMER_FROG, INV_CONTENT(ITEM_TRADE_ADULT) == ITEM_FROG)) { func_80088AA0(180); // start timer2 with 3 minutes gSaveContext.eventInf[1] &= ~1; } diff --git a/soh/src/overlays/actors/ovl_En_Kz/z_en_kz.h b/soh/src/overlays/actors/ovl_En_Kz/z_en_kz.h index c97732356..0b48ff202 100644 --- a/soh/src/overlays/actors/ovl_En_Kz/z_en_kz.h +++ b/soh/src/overlays/actors/ovl_En_Kz/z_en_kz.h @@ -28,6 +28,5 @@ typedef struct EnKz { /* 0x02BE */ s16 unk_2BE[12]; } EnKz; // size = 0x02D8 -void EnKz_SetupGetItem(EnKz* enKz, PlayState* play); #endif