From 3181eb58278094eec4972f03de26962aefec17a6 Mon Sep 17 00:00:00 2001 From: PhlexPlexico Date: Wed, 21 Feb 2024 12:59:28 -0600 Subject: [PATCH] Chest fixes (#38) * Fix most chest spawn issues. Temple chests with compasses and maps still run into issues. * Adjust progressive item chest types. * Fix: Nop Key check to ensure chest and compass chests respect the texture. --- code/mm.ld | 7 +++++- code/source/asm/hooks.s | 10 ++++----- code/source/asm/patches.s | 6 ++++++ code/source/rnd/chest.cpp | 39 ++++++---------------------------- code/source/rnd/item_table.cpp | 14 ++++++------ 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/code/mm.ld b/code/mm.ld index 4ba11108..e52690e7 100644 --- a/code/mm.ld +++ b/code/mm.ld @@ -355,7 +355,12 @@ SECTIONS{ *(.patch_IceArrowsAnywhere) } - .patch_changeChestTypeToMatchContents 0x31cad4 : { + .patch_AdjustMapAndCompassChests 0x31CE9C : { + *(.patch_AdjustMapAndCompassChests) + } + + /*0x31cad4*/ + .patch_changeChestTypeToMatchContents 0x31CE0C : { *(.patch_changeChestTypeToMatchContents) } diff --git a/code/source/asm/hooks.s b/code/source/asm/hooks.s index 73e8129c..f2f72635 100644 --- a/code/source/asm/hooks.s +++ b/code/source/asm/hooks.s @@ -349,21 +349,21 @@ hook_OwlExtDataSave: .global hook_changeChestTypeToMatchContents hook_changeChestTypeToMatchContents: - push {r0-r3, lr} + push {r0-r3, r5-r12, lr} cpy r0, r4 cpy r1, r5 bl Chest_OverrideSize cmp r0,#0xFF beq doNotOverrideChestType strb r0,[r4,#0x3e9] - pop {r0-r3, lr} + pop {r0-r3, r5-r12, lr} + strh r7, [r4,#0x18] bx lr doNotOverrideChestType: - pop {r0-r3, lr} - strb r2,[r4,#0x3e9] + pop {r0-r3, r5-r12, lr} + strh r7, [r4,#0x18] bx lr - .global hook_MikauRewardCheck hook_MikauRewardCheck: push {r0-r12, lr} diff --git a/code/source/asm/patches.s b/code/source/asm/patches.s index b6a12f9e..a740142d 100644 --- a/code/source/asm/patches.s +++ b/code/source/asm/patches.s @@ -380,6 +380,12 @@ patch_SaveExtDataOnOwl: patch_IceArrowsAnywhere: nop +@ Removes a check to see if the GID is a small key. +.section .patch_AdjustMapAndCompassChests +.global patch_AdjustMapAndCompassChests +patch_AdjustMapAndCompassChests: + nop + .section .patch_changeChestTypeToMatchContents .global patch_changeChestTypeToMatchContents patch_changeChestTypeToMatchContents: diff --git a/code/source/rnd/chest.cpp b/code/source/rnd/chest.cpp index 3daa5fe5..20e28bf1 100644 --- a/code/source/rnd/chest.cpp +++ b/code/source/rnd/chest.cpp @@ -6,45 +6,20 @@ namespace rnd { 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) { + if (gSettingsContext.chestSize == 1) { 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 (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) { - return game::actors::EnBoxType::ENBOX_TYPE_BIG; - } - } 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) { - 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; - } + if (itemToBeGiven->chestType == ChestType::WOODEN_SMALL) { + return game::actors::EnBoxType::ENBOX_TYPE_SMALL; + } else if (itemToBeGiven->chestType == ChestType::WOODEN_BIG) { + return game::actors::EnBoxType::ENBOX_TYPE_BIG; + } else if (itemToBeGiven->chestType == ChestType::DECORATED_BIG) { + return game::actors::EnBoxType::ENBOX_TYPE_BIG_ORNATE; } } else { return (game::actors::EnBoxType)0xFF; diff --git a/code/source/rnd/item_table.cpp b/code/source/rnd/item_table.cpp index 0e250915..bf758670 100644 --- a/code/source/rnd/item_table.cpp +++ b/code/source/rnd/item_table.cpp @@ -356,8 +356,8 @@ namespace rnd { (rnd::upgradeFunc)ItemUpgrade_None, ItemEffect_None, (s16)-1, (s16)-1), // Hookshot [0x42] = - ITEM_ROW((u32)GetItemID::GI_RUPEE_BLUE, ChestType::WOODEN_SMALL, (u8)game::ItemId::LensOfTruth, 0x0042, - 0x00C0, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s32)DrawGraphicItemID::DI_LENS_OF_TRUTH, + ITEM_ROW((u32)GetItemID::GI_RUPEE_BLUE, ChestType::WOODEN_BIG, (u8)game::ItemId::LensOfTruth, 0x0042, 0x00C0, + (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s32)DrawGraphicItemID::DI_LENS_OF_TRUTH, (rnd::upgradeFunc)ItemUpgrade_None, ItemEffect_None, (s16)-1, (s16)-1), // Lens of Truth @@ -379,25 +379,25 @@ namespace rnd { (rnd::upgradeFunc)ItemUpgrade_None, ItemEffect_None, (s16)-1, (s16)-1), // Recovery Heart - Broken Text - [0x46] = ITEM_ROW(0xFF, ChestType::WOODEN_SMALL, 0xFF, 0xFF, 0x00098, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, + [0x46] = ITEM_ROW(0xFF, ChestType::WOODEN_BIG, 0xFF, 0xFF, 0x00098, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, 0xFF, (rnd::upgradeFunc)ItemUpgrade_BombBag, ItemEffect_None, (s16)-1, (s16)-1), // Progressive Bomb Bag - [0x47] = ITEM_ROW(0xFF, ChestType::WOODEN_SMALL, 0xFF, 0xFF, 0x00097, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, + [0x47] = ITEM_ROW(0xFF, ChestType::WOODEN_BIG, 0xFF, 0xFF, 0x00097, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, 0xFF, (rnd::upgradeFunc)ItemUpgrade_Quiver, ItemEffect_None, (s16)-1, (s16)-1), // Progressive Quiver - [0x48] = ITEM_ROW(0xFF, ChestType::WOODEN_SMALL, 0xFF, 0xFF, 0x000A8, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, + [0x48] = ITEM_ROW(0xFF, ChestType::WOODEN_BIG, 0xFF, 0xFF, 0x000A8, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, 0xFF, (rnd::upgradeFunc)ItemUpgrade_Wallet, ItemEffect_None, (s16)-1, (s16)-1), // Progressive Wallet [0x49] = - ITEM_ROW(0xFF, ChestType::WOODEN_SMALL, 0xFF, 0xFF, 0x000A4, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, + ITEM_ROW(0xFF, ChestType::WOODEN_BIG, 0xFF, 0xFF, 0x000A4, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, 0x000A4, (rnd::upgradeFunc)ItemUpgrade_Magic, ItemEffect_GiveProgressiveMagic, (s16)-1, (s16)-1), // Progressive Magic [0x4A] = - ITEM_ROW(0xFF, ChestType::WOODEN_SMALL, 0xFF, 0xFF, 0x001FA, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, + ITEM_ROW(0xFF, ChestType::WOODEN_BIG, 0xFF, 0xFF, 0x001FA, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, (s8)0xFF, 0xFF, (rnd::upgradeFunc)ItemUpgrade_Sword, ItemEffect_None, (s16)-1, (s16)-1), // Progressive Sword [0x4B] =