From 4a8ed398c08de2c645d083646f0abce3a9b852ce Mon Sep 17 00:00:00 2001 From: Caladius Date: Thu, 30 May 2024 10:42:39 -0400 Subject: [PATCH] Updated to dynamic hook registration and fix sfx spam. --- mm/2s2h/Enhancements/Actor/BankerDialogue.cpp | 81 ++++++++++++------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/mm/2s2h/Enhancements/Actor/BankerDialogue.cpp b/mm/2s2h/Enhancements/Actor/BankerDialogue.cpp index 86c7fef2e9..10bb5a54d5 100644 --- a/mm/2s2h/Enhancements/Actor/BankerDialogue.cpp +++ b/mm/2s2h/Enhancements/Actor/BankerDialogue.cpp @@ -6,36 +6,59 @@ #include "overlays/actors/ovl_En_Ginko_Man/z_en_ginko_man.h" void RegisterBankerDialogue() { + GameInteractor::Instance->RegisterGameHookForID( + ACTOR_EN_GINKO_MAN, [](Actor* outerActor) { + static uint32_t enGinkoUpdateHook = 0; + static uint32_t enGinkoKillHook = 0; + GameInteractor::Instance->UnregisterGameHookForPtr(enGinkoUpdateHook); + GameInteractor::Instance->UnregisterGameHook(enGinkoKillHook); + enGinkoUpdateHook = 0; + enGinkoKillHook = 0; - GameInteractor::Instance->RegisterGameHook([](Actor* actor) { - if (!CVarGetInteger("gEnhancements.Actor.BankerDepositRupees", 0)) { - return; - } - if (actor->id == ACTOR_EN_GINKO_MAN) { - if (gPlayState->msgCtx.currentTextId == 1104) { - if (CHECK_BTN_ALL(gPlayState->state.input[0].cur.button, BTN_Z)) { - char firstChar = (gSaveContext.save.saveInfo.playerData.rupees / 100) + '0'; - char secondChar = ((gSaveContext.save.saveInfo.playerData.rupees / 10) % 10) + '0'; - char thirdChar = (gSaveContext.save.saveInfo.playerData.rupees % 10) + '0'; - const char rupeeChar[3] = { firstChar, secondChar, thirdChar }; + enGinkoUpdateHook = GameInteractor::Instance->RegisterGameHookForPtr( + (uintptr_t)outerActor, [](Actor* actor) { + EnGinkoMan* enGinko = (EnGinkoMan*)actor; + if (CVarGetInteger("gEnhancements.Actor.BankerDepositRupees", 0)) { + if (gPlayState->msgCtx.currentTextId == 1104 ) { + if (CHECK_BTN_ALL(gPlayState->state.input[0].cur.button, BTN_Z) && + gPlayState->msgCtx.bankRupeesSelected != gSaveContext.save.saveInfo.playerData.rupees) { + char firstChar = (gSaveContext.save.saveInfo.playerData.rupees / 100) + '0'; + char secondChar = ((gSaveContext.save.saveInfo.playerData.rupees / 10) % 10) + '0'; + char thirdChar = (gSaveContext.save.saveInfo.playerData.rupees % 10) + '0'; + const char rupeeChar[3] = { firstChar, secondChar, thirdChar }; - for (int i = 22; i <= 24; i++) { - gPlayState->msgCtx.bankRupeesSelected = gPlayState->msgCtx.decodedBuffer.schar[i] = - rupeeChar[i - 22]; - Font_LoadCharNES(gPlayState, gPlayState->msgCtx.decodedBuffer.schar[i], - gPlayState->msgCtx.unk120C4 + (0 + (i - 22) << 7)); + for (int i = 0; i <= 2; i++) { + gPlayState->msgCtx.bankRupeesSelected = + gPlayState->msgCtx.decodedBuffer.schar[gPlayState->msgCtx.unk120C0 + i] = + rupeeChar[i]; + Font_LoadCharNES( + gPlayState, + gPlayState->msgCtx.decodedBuffer.schar[gPlayState->msgCtx.unk120C0 + i], + gPlayState->msgCtx.unk120C4 + (i << 7)); + } + Audio_PlaySfx(NA_SE_SY_RUPY_COUNT); + } + if (CHECK_BTN_ALL(gPlayState->state.input[0].cur.button, BTN_R) && + gPlayState->msgCtx.bankRupeesSelected != 0) { + for (int i = 0; i <= 2; i++) { + gPlayState->msgCtx.bankRupeesSelected = + gPlayState->msgCtx.decodedBuffer.schar[gPlayState->msgCtx.unk120C0 + i] = '0'; + Font_LoadCharNES( + gPlayState, + gPlayState->msgCtx.decodedBuffer.schar[gPlayState->msgCtx.unk120C0 + i], + gPlayState->msgCtx.unk120C4 + (i << 7)); + } + Audio_PlaySfx(NA_SE_SY_RUPY_COUNT); + } + } } - Audio_PlaySfx(NA_SE_SY_RUPY_COUNT); - } - if (CHECK_BTN_ALL(gPlayState->state.input[0].cur.button, BTN_R)) { - for (int i = 22; i <= 24; i++) { - gPlayState->msgCtx.bankRupeesSelected = gPlayState->msgCtx.decodedBuffer.schar[i] = '0'; - Font_LoadCharNES(gPlayState, gPlayState->msgCtx.decodedBuffer.schar[i], - gPlayState->msgCtx.unk120C4 + (0 + (i - 22) << 7)); - } - Audio_PlaySfx(NA_SE_SY_RUPY_COUNT); - } - } - } - }); + }); + enGinkoKillHook = + GameInteractor::Instance->RegisterGameHook([](s8 sceneId, s8 spawnNum) { + GameInteractor::Instance->UnregisterGameHook(enGinkoUpdateHook); + GameInteractor::Instance->UnregisterGameHook(enGinkoKillHook); + enGinkoUpdateHook = 0; + enGinkoKillHook = 0; + }); + }); } \ No newline at end of file