From 6f7449b9da1a3d0eea355d80e5fb897fbc0a8601 Mon Sep 17 00:00:00 2001 From: Phlex Date: Thu, 21 Dec 2023 09:55:38 -0600 Subject: [PATCH] Update dungeon item keys to show properly in spoiler menu. Update override for dungeon keys to not always give woodfall. Update some override conditions to use actual values. --- code/mm.ld | 4 ++ code/source/asm/hooks.s | 11 ++++++ code/source/asm/patches.s | 5 +++ code/source/rnd/gfx.cpp | 61 ++++++++++++++++--------------- code/source/rnd/item_override.cpp | 1 + code/source/rnd/item_upgrade.cpp | 8 ++-- 6 files changed, 56 insertions(+), 34 deletions(-) diff --git a/code/mm.ld b/code/mm.ld index f7dea7ab..d8c3a58e 100644 --- a/code/mm.ld +++ b/code/mm.ld @@ -167,6 +167,10 @@ SECTIONS{ *(.patch_CheckDungeonItems) } + .patch_CheckDungeonSmallKeys 0x233F4C : { + *(.patch_CheckDungeonSmallKeys) + } + .patch_DisableMilkTimer 0x234BFC : { *(.patch_DisableMilkTimer) } diff --git a/code/source/asm/hooks.s b/code/source/asm/hooks.s index 99099135..01df6b07 100644 --- a/code/source/asm/hooks.s +++ b/code/source/asm/hooks.s @@ -121,6 +121,17 @@ hook_CheckDungeonItems: ldrh r2, [r2, #82] bx lr +.global hook_CheckDungeonSmallKeys +hook_CheckDungeonSmallKeys: + push {r0-r12, lr} + ldr r1,.rCustomDungeonItemRetrieved_addr + ldr r1,[r1] + cmp r1,#0x1 + pop {r0-r12, lr} + beq 0x233F60 + ldrh r0, [r2, #0x52] + bx lr + .global hook_SaveFile_Load hook_SaveFile_Load: push {r0-r12, lr} diff --git a/code/source/asm/patches.s b/code/source/asm/patches.s index d5d4c804..dca4969d 100644 --- a/code/source/asm/patches.s +++ b/code/source/asm/patches.s @@ -150,6 +150,11 @@ patch_CheckCurrentInventoryOverrideItem: patch_CheckDungeonItems: bl hook_CheckDungeonItems +.section .patch_CheckDungeonSmallKeys +.global patch_CheckDungeonSmallKeys +patch_CheckDungeonSmallKeys: + bl hook_CheckDungeonSmallKeys + .section .patch_DisableMilkTimer .global patch_DisableMilkTimer patch_DisableMilkTimer: diff --git a/code/source/rnd/gfx.cpp b/code/source/rnd/gfx.cpp index 4e4841c0..e307d431 100644 --- a/code/source/rnd/gfx.cpp +++ b/code/source/rnd/gfx.cpp @@ -257,43 +257,43 @@ namespace rnd { u8 yPos = 30; for (u32 dungeonId = 0; dungeonId <= DUNGEON_STONE_TOWER; ++dungeonId) { bool hasBossKey = 0; - if ((dungeonId = DUNGEON_WOODFALL)) { + if ((dungeonId == DUNGEON_WOODFALL)) { hasBossKey = saveData.inventory.woodfall_dungeon_items.boss_key.Value(); } - if ((dungeonId = DUNGEON_SNOWHEAD)) { + if ((dungeonId == DUNGEON_SNOWHEAD)) { hasBossKey = saveData.inventory.snowhead_dungeon_items.boss_key.Value(); } - if ((dungeonId = DUNGEON_GREAT_BAY)) { + if ((dungeonId == DUNGEON_GREAT_BAY)) { hasBossKey = saveData.inventory.great_bay_dungeon_items.boss_key.Value(); } - if ((dungeonId = DUNGEON_STONE_TOWER)) { + if ((dungeonId == DUNGEON_STONE_TOWER)) { hasBossKey = saveData.inventory.stone_tower_dungeon_items.boss_key.Value(); } bool hasCompass = 0; - if ((dungeonId = DUNGEON_WOODFALL)) { - hasBossKey = saveData.inventory.woodfall_dungeon_items.compass.Value(); + if ((dungeonId == DUNGEON_WOODFALL)) { + hasCompass = saveData.inventory.woodfall_dungeon_items.compass.Value(); } - if ((dungeonId = DUNGEON_SNOWHEAD)) { - hasBossKey = saveData.inventory.snowhead_dungeon_items.compass.Value(); + if ((dungeonId == DUNGEON_SNOWHEAD)) { + hasCompass = saveData.inventory.snowhead_dungeon_items.compass.Value(); } - if ((dungeonId = DUNGEON_GREAT_BAY)) { - hasBossKey = saveData.inventory.great_bay_dungeon_items.compass.Value(); + if ((dungeonId == DUNGEON_GREAT_BAY)) { + hasCompass = saveData.inventory.great_bay_dungeon_items.compass.Value(); } - if ((dungeonId = DUNGEON_STONE_TOWER)) { - hasBossKey = saveData.inventory.stone_tower_dungeon_items.compass.Value(); + if ((dungeonId == DUNGEON_STONE_TOWER)) { + hasCompass = saveData.inventory.stone_tower_dungeon_items.compass.Value(); } bool hasMap = 0; - if ((dungeonId = DUNGEON_WOODFALL)) { - hasBossKey = saveData.inventory.woodfall_dungeon_items.map.Value(); + if ((dungeonId == DUNGEON_WOODFALL)) { + hasMap = saveData.inventory.woodfall_dungeon_items.map.Value(); } - if ((dungeonId = DUNGEON_SNOWHEAD)) { - hasBossKey = saveData.inventory.snowhead_dungeon_items.map.Value(); + if ((dungeonId == DUNGEON_SNOWHEAD)) { + hasMap = saveData.inventory.snowhead_dungeon_items.map.Value(); } - if ((dungeonId = DUNGEON_GREAT_BAY)) { - hasBossKey = saveData.inventory.great_bay_dungeon_items.map.Value(); + if ((dungeonId == DUNGEON_GREAT_BAY)) { + hasMap = saveData.inventory.great_bay_dungeon_items.map.Value(); } - if ((dungeonId = DUNGEON_STONE_TOWER)) { - hasBossKey = saveData.inventory.stone_tower_dungeon_items.map.Value(); + if ((dungeonId == DUNGEON_STONE_TOWER)) { + hasMap = saveData.inventory.stone_tower_dungeon_items.map.Value(); } Draw_DrawString(24, yPos, COLOR_WHITE, DungeonNames[dungeonId]); @@ -301,17 +301,17 @@ namespace rnd { // Small Keys if (dungeonId <= DUNGEON_STONE_TOWER) { u8 keysHave = 0; - if ((dungeonId = DUNGEON_WOODFALL)) { - keysHave = saveData.inventory.woodfall_temple_keys; + if ((dungeonId == DUNGEON_WOODFALL)) { + keysHave = saveData.inventory.woodfall_temple_keys == 255 ? 0 : saveData.inventory.woodfall_temple_keys; } - if ((dungeonId = DUNGEON_SNOWHEAD)) { - keysHave = saveData.inventory.snowhead_temple_keys; + if ((dungeonId == DUNGEON_SNOWHEAD)) { + keysHave = saveData.inventory.snowhead_temple_keys == 255 ? 0 : saveData.inventory.snowhead_temple_keys; } - if ((dungeonId = DUNGEON_GREAT_BAY)) { - keysHave = saveData.inventory.great_bay_temple_keys; + if ((dungeonId == DUNGEON_GREAT_BAY)) { + keysHave = saveData.inventory.great_bay_temple_keys == 255 ? 0 : saveData.inventory.great_bay_temple_keys; } - if ((dungeonId = DUNGEON_STONE_TOWER)) { - keysHave = saveData.inventory.stone_tower_temple_keys; + if ((dungeonId == DUNGEON_STONE_TOWER)) { + keysHave = saveData.inventory.stone_tower_temple_keys == 255 ? 0 : saveData.inventory.stone_tower_temple_keys; } Draw_DrawFormattedString(208, yPos, keysHave > 0 ? COLOR_WHITE : COLOR_DARK_GRAY, "%d", keysHave); Draw_DrawString(214, yPos, COLOR_WHITE, "/"); @@ -335,8 +335,9 @@ namespace rnd { Draw_DrawIcon(240, yPos, hasBossKey ? COLOR_ICON_BOSS_KEY : COLOR_DARK_GRAY, ICON_BOSS_KEY); } - if (dungeonId >= DUNGEON_PIRATE_FORTRESS) { - // Map and Compassz + // Map and Compasses + if (dungeonId <= DUNGEON_STONE_TOWER) { + Draw_DrawIcon(260, yPos, hasMap ? COLOR_ICON_MAP : COLOR_DARK_GRAY, ICON_MAP); Draw_DrawIcon(280, yPos, hasCompass ? COLOR_ICON_COMPASS : COLOR_DARK_GRAY, ICON_COMPASS); diff --git a/code/source/rnd/item_override.cpp b/code/source/rnd/item_override.cpp index 56d8e96c..864812a3 100644 --- a/code/source/rnd/item_override.cpp +++ b/code/source/rnd/item_override.cpp @@ -140,6 +140,7 @@ namespace rnd { u16 resolvedGetItemId = ItemTable_ResolveUpgrades(override.value.getItemId); ItemRow* itemRow = ItemTable_GetItemRow(resolvedGetItemId); + // XXX: Maybe create function for progressive items so that the item drawn is correct? u8 looksLikeItemId = override.value.looksLikeItemId; if (override.value.getItemId == 0x12) { // Ice trap diff --git a/code/source/rnd/item_upgrade.cpp b/code/source/rnd/item_upgrade.cpp index 2a0c9645..af0a7d77 100644 --- a/code/source/rnd/item_upgrade.cpp +++ b/code/source/rnd/item_upgrade.cpp @@ -10,7 +10,7 @@ namespace rnd { } GetItemID ItemUpgrade_BombBag(game::SaveData* saveCtx, GetItemID GetItemId) { - switch (saveCtx->inventory.inventory_count_register.bomb_bag_upgrade) { + switch (saveCtx->inventory.inventory_count_register.bomb_bag_upgrade.Value()) { case game::BombBag::NoBag: return GetItemID::GI_BOMB_BAG_20; // Bomb Bag case game::BombBag::BombBag20: @@ -21,7 +21,7 @@ namespace rnd { } GetItemID ItemUpgrade_Quiver(game::SaveData* saveCtx, GetItemID GetItemId) { - switch (saveCtx->inventory.inventory_count_register.quiver_upgrade) { + switch (saveCtx->inventory.inventory_count_register.quiver_upgrade.Value()) { case game::Quiver::NoQuiver: return GetItemID::GI_HEROS_BOW; // Bow case game::Quiver::Quiver30: @@ -32,7 +32,7 @@ namespace rnd { } GetItemID ItemUpgrade_Wallet(game::SaveData* saveCtx, GetItemID GetItemId) { - switch (saveCtx->inventory.inventory_count_register.wallet_upgrade) { + switch (saveCtx->inventory.inventory_count_register.wallet_upgrade.Value()) { case 0: return GetItemID::GI_ADULT_WALLET; // Adult's Wallet case 1: @@ -79,7 +79,7 @@ namespace rnd { } GetItemID ItemUpgrade_BombsToRupee(game::SaveData* saveCtx, GetItemID getItemId) { - return (saveCtx->inventory.inventory_count_register.bomb_bag_upgrade == game::BombBag::NoBag) ? + return (saveCtx->inventory.inventory_count_register.bomb_bag_upgrade.Value() == game::BombBag::NoBag) ? GetItemID::GI_RUPEE_BLUE : // Blue Rupee getItemId; }