From 8d22509f18d8ca783c0d1d4d5a2bd4a83abf1ad6 Mon Sep 17 00:00:00 2001 From: Phlex Date: Mon, 19 Feb 2024 19:54:32 -0600 Subject: [PATCH] Fix chest content matching issues. --- code/include/rnd/chest.h | 2 +- code/mm.ld | 4 ++-- code/source/asm/hooks.s | 9 +++---- code/source/asm/patches.s | 1 - code/source/rnd/chest.cpp | 39 +++++++++++++++++++++++-------- code/source/rnd/item_override.cpp | 6 ++--- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/code/include/rnd/chest.h b/code/include/rnd/chest.h index da86bea6..ce37e01d 100644 --- a/code/include/rnd/chest.h +++ b/code/include/rnd/chest.h @@ -30,7 +30,7 @@ namespace rnd { DECORATED_SMALL, }; - extern "C" game::actors::EnBoxType Chest_OverrideSize(game::actors::En_Box*, game::GlobalContext*, s16); + extern "C" game::actors::EnBoxType Chest_OverrideSize(game::actors::En_Box*, game::GlobalContext*); // void EnBox_rInit(game::act::Actor* thisx, game::GlobalContext* globalCtx); // void EnBox_rUpdate(game::act::Actor* thisx, game::GlobalContext* globalCtx); // u8 Chest_OverrideAnimation(); diff --git a/code/mm.ld b/code/mm.ld index 7d6eabdd..f8a6c4e0 100644 --- a/code/mm.ld +++ b/code/mm.ld @@ -355,9 +355,9 @@ SECTIONS{ *(.patch_IceArrowsAnywhere) } - /* .patch_changeChestTypeToMatchContents 0x31cad4 : { + .patch_changeChestTypeToMatchContents 0x31cad4 : { *(.patch_changeChestTypeToMatchContents) - } */ + } .patch_RemoveZoraMaskCheckMikau 0x32BBB8 : { *(.patch_RemoveZoraMaskCheckMikau) diff --git a/code/source/asm/hooks.s b/code/source/asm/hooks.s index 8e030624..73e8129c 100644 --- a/code/source/asm/hooks.s +++ b/code/source/asm/hooks.s @@ -349,20 +349,17 @@ hook_OwlExtDataSave: .global hook_changeChestTypeToMatchContents hook_changeChestTypeToMatchContents: - push {r0-r2, lr} + push {r0-r3, lr} cpy r0, r4 cpy r1, r5 - ldrh r2,[r4,#0x1C] - lsl r2, r2, #0x14 - lsr r2,r2, #0x19 bl Chest_OverrideSize cmp r0,#0xFF beq doNotOverrideChestType strb r0,[r4,#0x3e9] - pop {r0-r2, lr} + pop {r0-r3, lr} bx lr doNotOverrideChestType: - pop {r0-r2, lr} + pop {r0-r3, lr} strb r2,[r4,#0x3e9] bx lr diff --git a/code/source/asm/patches.s b/code/source/asm/patches.s index bb1ca6cf..b6a12f9e 100644 --- a/code/source/asm/patches.s +++ b/code/source/asm/patches.s @@ -384,7 +384,6 @@ patch_IceArrowsAnywhere: .global patch_changeChestTypeToMatchContents patch_changeChestTypeToMatchContents: bl hook_changeChestTypeToMatchContents - @mov r2, #0x02 .section .patch_RemoveZoraMaskCheckMikau .global patch_RemoveZoraMaskCheckMikau diff --git a/code/source/rnd/chest.cpp b/code/source/rnd/chest.cpp index 8b8e7dae..3daa5fe5 100644 --- a/code/source/rnd/chest.cpp +++ b/code/source/rnd/chest.cpp @@ -3,29 +3,48 @@ namespace rnd { extern "C" { - game::actors::EnBoxType Chest_OverrideSize(game::actors::En_Box* actor, game::GlobalContext* gctx, s16 gid) { + game::actors::EnBoxType Chest_OverrideSize(game::actors::En_Box* actor, game::GlobalContext* gctx) { // First check to see if setting is enabled. // TODO: Create setting if (gSettingsContext.chestSize == 0) { return (game::actors::EnBoxType)0xFF; } + s16 gid = (actor->dyna.params << 0x14) >> 0x19; game::SceneId scene = gctx->scene; ItemOverride override = ItemOverride_Lookup((game::act::Actor*)&actor->dyna, (u16)scene, gid); + game::actors::EnBoxType boxType = (game::actors::EnBoxType)(actor->dyna.params >> 0xC); if (override.key.all != 0) { ItemRow* itemToBeGiven = ItemTable_GetItemRow(override.value.getItemId); - if (actor->chest_type == game::actors::EnBoxType::ENBOX_TYPE_SMALL || - actor->chest_type == game::actors::EnBoxType::ENBOX_TYPE_BIG || - actor->chest_type == game::actors::EnBoxType::ENBOX_TYPE_BIG_ORNATE) { - if (itemToBeGiven->baseItemId == 0x02) + if (boxType == game::actors::EnBoxType::ENBOX_TYPE_SMALL || boxType == game::actors::EnBoxType::ENBOX_TYPE_BIG || + boxType == game::actors::EnBoxType::ENBOX_TYPE_BIG_ORNATE) { + if (itemToBeGiven->baseItemId == 0x02) { return game::actors::EnBoxType::ENBOX_TYPE_SMALL; - else if (itemToBeGiven->baseItemId == 0x2B || itemToBeGiven->baseItemId == 0x78) + } else if (itemToBeGiven->baseItemId == 0x2B || itemToBeGiven->baseItemId == 0x78) { return game::actors::EnBoxType::ENBOX_TYPE_BIG; - } else if (actor->chest_type == game::actors::EnBoxType::ENBOX_TYPE_BIG_INVISIBLE || - actor->chest_type == game::actors::EnBoxType::ENBOX_TYPE_SMALL_INVISIBLE) { - if (itemToBeGiven->baseItemId == 0x02) + } + } else if (boxType == game::actors::EnBoxType::ENBOX_TYPE_BIG_INVISIBLE || + boxType == game::actors::EnBoxType::ENBOX_TYPE_SMALL_INVISIBLE) { + if (itemToBeGiven->baseItemId == 0x02) { + boxType = game::actors::EnBoxType::ENBOX_TYPE_SMALL_INVISIBLE; return game::actors::EnBoxType::ENBOX_TYPE_SMALL_INVISIBLE; - else if (itemToBeGiven->baseItemId == 0x2B || itemToBeGiven->baseItemId == 0x78) + } else if (itemToBeGiven->baseItemId == 0x2B || itemToBeGiven->baseItemId == 0x78) { + boxType = game::actors::EnBoxType::ENBOX_TYPE_BIG_INVISIBLE; return game::actors::EnBoxType::ENBOX_TYPE_BIG_INVISIBLE; + } + } else if (boxType == game::actors::EnBoxType::ENBOX_TYPE_BIG_ROOM_CLEAR || + boxType == game::actors::EnBoxType::ENBOX_TYPE_SMALL_ROOM_CLEAR) { + if (itemToBeGiven->baseItemId == 0x02) { + return game::actors::EnBoxType::ENBOX_TYPE_SMALL_ROOM_CLEAR; + } else if (itemToBeGiven->baseItemId == 0x2B || itemToBeGiven->baseItemId == 0x78) { + return game::actors::EnBoxType::ENBOX_TYPE_BIG_ROOM_CLEAR; + } + } else if (boxType == game::actors::EnBoxType::ENBOX_TYPE_SMALL_SWITCH_FLAG || + boxType == game::actors::EnBoxType::ENBOX_TYPE_BIG_SWITCH_FLAG) { + if (itemToBeGiven->baseItemId == 0x02) { + return game::actors::EnBoxType::ENBOX_TYPE_SMALL_SWITCH_FLAG; + } else if (itemToBeGiven->baseItemId == 0x2B || itemToBeGiven->baseItemId == 0x78) { + return game::actors::EnBoxType::ENBOX_TYPE_BIG_SWITCH_FLAG; + } } } else { return (game::actors::EnBoxType)0xFF; diff --git a/code/source/rnd/item_override.cpp b/code/source/rnd/item_override.cpp index 11bdcf09..fd9965a8 100644 --- a/code/source/rnd/item_override.cpp +++ b/code/source/rnd/item_override.cpp @@ -44,9 +44,9 @@ namespace rnd { rItemOverrides[0].value.getItemId = 0x26; rItemOverrides[0].value.looksLikeItemId = 0x26; rItemOverrides[1].key.scene = 0x6F; - rItemOverrides[1].key.type = ItemOverride_Type::OVR_COLLECTABLE; - rItemOverrides[1].value.getItemId = 0x0C; - rItemOverrides[1].value.looksLikeItemId = 0x0C; + rItemOverrides[1].key.type = ItemOverride_Type::OVR_CHEST; + rItemOverrides[1].value.getItemId = 0x02; + rItemOverrides[1].value.looksLikeItemId = 0x02; rItemOverrides[2].key.scene = 0x12; rItemOverrides[2].key.type = ItemOverride_Type::OVR_COLLECTABLE; rItemOverrides[2].value.getItemId = 0x37;