CHudPause: fix crash when opening options menu from village/lab

This commit is contained in:
Hyper 2024-11-18 21:35:20 +00:00
parent a768e7b96b
commit 8b5d71d81a
2 changed files with 26 additions and 8 deletions

View file

@ -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<uint32_t>*)g_memory.Translate(pThis + 0x190);
auto pauseType = *(be<uint32_t>*)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<uint32_t>*)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)

View file

@ -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