From 8b5d71d81a3bb2b34e3ce12c815949a15f982c29 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Mon, 18 Nov 2024 21:35:20 +0000 Subject: [PATCH] CHudPause: fix crash when opening options menu from village/lab --- .../patches/ui/CHudPause_patches.cpp | 27 ++++++++++++++++--- UnleashedRecompLib/config/SWA.toml | 7 +++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/UnleashedRecomp/patches/ui/CHudPause_patches.cpp b/UnleashedRecomp/patches/ui/CHudPause_patches.cpp index e45fd4f9..0369788e 100644 --- a/UnleashedRecomp/patches/ui/CHudPause_patches.cpp +++ b/UnleashedRecomp/patches/ui/CHudPause_patches.cpp @@ -21,7 +21,7 @@ void CHudPauseAddOptionsItemMidAsmHook(PPCRegister& pThis) __HH_FREE(pStrMemory); } -bool InjectOptionsBehaviour(uint32_t pThis, uint32_t count, uint32_t exitType = 2, uint32_t transitionType = 2) +bool InjectOptionsBehaviour(uint32_t pThis, uint32_t count) { auto status = *(be*)g_memory.Translate(pThis + 0x190); auto pauseType = *(be*)g_memory.Translate(pThis + 0x18C); @@ -34,7 +34,7 @@ bool InjectOptionsBehaviour(uint32_t pThis, uint32_t count, uint32_t exitType = 3 ---- Inventory 4 ---- Skills 5 ---- Go to the Lab - 6 ---- Return to World Map + 6 ---- Wait until Day/Night 7 ---- Undefined 8 ---- Restart Stage 9 ---- Continue Stage @@ -56,6 +56,25 @@ bool InjectOptionsBehaviour(uint32_t pThis, uint32_t count, uint32_t exitType = */ auto pTransitionType = (be*)g_memory.Translate(pThis + 0x194); + auto exitType = 0; + auto transitionType = 0; + + switch (pauseType) + { + case 0: // World Map + case 2: // Stage + case 4: // Misc + exitType = 2; + transitionType = 2; + break; + + case 1: // Village + case 3: // Hub + exitType = 2; + transitionType = 6; + break; + } + if (status == 1) { if (cursorIndex == count - 2) @@ -87,11 +106,11 @@ bool CHudPauseItemCountMidAsmHook(PPCRegister& pThis, PPCRegister& count) return InjectOptionsBehaviour(pThis.u32, count.u32); } -bool CHudPauseHubItemCountMidAsmHook(PPCRegister& pThis, PPCRegister& count) +void CHudPauseVillageItemCountMidAsmHook(PPCRegister& pThis, PPCRegister& count) { count.u32 += 1; - return InjectOptionsBehaviour(pThis.u32, count.u32, 2, 6); + InjectOptionsBehaviour(pThis.u32, count.u32); } bool CHudPauseMiscItemCountMidAsmHook(PPCRegister& count) diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index c419ed55..187729ec 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -432,7 +432,7 @@ registers = ["r31"] # Village Pause Menu [[midasm_hook]] name = "CHudPauseAddOptionsItemMidAsmHook" -address = 0x824AF430 +address = 0x824AF5BC registers = ["r31"] # Stage Pause Menu @@ -462,10 +462,9 @@ return_on_true = true # Village Pause Menu [[midasm_hook]] -name = "CHudPauseItemCountMidAsmHook" +name = "CHudPauseVillageItemCountMidAsmHook" address = 0x824B04AC registers = ["r31", "r10"] -return_on_true = true # Stage Pause Menu [[midasm_hook]] @@ -476,7 +475,7 @@ return_on_true = true # Hub Pause Menu [[midasm_hook]] -name = "CHudPauseHubItemCountMidAsmHook" +name = "CHudPauseItemCountMidAsmHook" address = 0x824B07C4 registers = ["r3", "r10"] return_on_true = true