Skip to content

Commit

Permalink
Chest fixes (#38)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
PhlexPlexico committed Mar 10, 2024
1 parent 3b7d257 commit 14550c5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 45 deletions.
7 changes: 6 additions & 1 deletion code/mm.ld
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,12 @@ SECTIONS{
*(.patch_IceArrowsAnywhere)
}

.patch_changeChestTypeToMatchContents 0x31cad4 : {
.patch_AdjustMapAndCompassChests 0x31CE9C : {
*(.patch_AdjustMapAndCompassChests)
}

/*0x31cad4*/
.patch_changeChestTypeToMatchContents 0x31CE0C : {
*(.patch_changeChestTypeToMatchContents)
}

Expand Down
10 changes: 5 additions & 5 deletions code/source/asm/hooks.s
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 6 additions & 0 deletions code/source/asm/patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
39 changes: 7 additions & 32 deletions code/source/rnd/chest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions code/source/rnd/item_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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] =
Expand Down

0 comments on commit 14550c5

Please sign in to comment.