Skip to content

Commit

Permalink
Updated to dynamic hook registration and fix sfx spam.
Browse files Browse the repository at this point in the history
  • Loading branch information
Caladius committed May 30, 2024
1 parent c0f11fd commit 4a8ed39
Showing 1 changed file with 52 additions and 29 deletions.
81 changes: 52 additions & 29 deletions mm/2s2h/Enhancements/Actor/BankerDialogue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,59 @@
#include "overlays/actors/ovl_En_Ginko_Man/z_en_ginko_man.h"

void RegisterBankerDialogue() {
GameInteractor::Instance->RegisterGameHookForID<GameInteractor::OnActorInit>(
ACTOR_EN_GINKO_MAN, [](Actor* outerActor) {
static uint32_t enGinkoUpdateHook = 0;
static uint32_t enGinkoKillHook = 0;
GameInteractor::Instance->UnregisterGameHookForPtr<GameInteractor::OnActorUpdate>(enGinkoUpdateHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnSceneInit>(enGinkoKillHook);
enGinkoUpdateHook = 0;
enGinkoKillHook = 0;

GameInteractor::Instance->RegisterGameHook<GameInteractor::OnActorUpdate>([](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<GameInteractor::OnActorUpdate>(
(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<GameInteractor::OnSceneInit>([](s8 sceneId, s8 spawnNum) {
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnActorUpdate>(enGinkoUpdateHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnSceneInit>(enGinkoKillHook);
enGinkoUpdateHook = 0;
enGinkoKillHook = 0;
});
});
}

0 comments on commit 4a8ed39

Please sign in to comment.