Skip to content

Commit 505c5e0

Browse files
committed
Merge 'Add Invisible Chests option' (#1502)
2 parents 36f011a + c9f3894 commit 505c5e0

13 files changed

Lines changed: 16792 additions & 16567 deletions

File tree

ASM/build/asm_symbols.txt

Lines changed: 528 additions & 521 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ASM/c/chests.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ void get_chest_override(z64_actor_t *actor) {
5555

5656
((uint8_t*)actor)[0x01EC] = size;
5757
((uint8_t*)actor)[0x01ED] = color;
58+
if (CHEST_LENS_ONLY) {
59+
// Actor flag 7 makes actors invisible
60+
// Usually only applies to chest types 4 and 6
61+
actor->flags |= 0x80;
62+
}
5863
}
5964

6065
void draw_chest(z64_game_t* game, int part, void* unk, void* unk2,

ASM/c/chests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
extern uint32_t CHEST_SIZE_MATCH_CONTENTS;
99
extern uint32_t CHEST_TEXTURE_MATCH_CONTENTS;
1010
extern uint32_t CHEST_SIZE_TEXTURE;
11+
extern uint32_t CHEST_LENS_ONLY;
1112

1213
void get_chest_override(z64_actor_t *actor);
1314

ASM/src/chests.asm

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
CHEST_LENS_ONLY:
2+
.word 0x00000000
3+
4+
15
GET_CHEST_OVERRIDE_WRAPPER:
26
sb t9,0x01E9(s0)
37

@@ -20,3 +24,117 @@ GET_CHEST_OVERRIDE_WRAPPER:
2024
lwc1 $f16, 0x18 (sp)
2125
jr ra
2226
addiu sp, sp, 0x20
27+
28+
29+
HIDE_CHEST_WITH_INVERTED_LENS:
30+
; displaced code
31+
sll t9, s2, 2
32+
addu t0, s7, t9
33+
34+
; Do not draw chests if invisible chests setting is on and lens is not active
35+
; If lens is active, bypass default actor lens draw logic for chests in rooms
36+
; with inverted lens behavior (hide vs show actors).
37+
; t5 holds if the room has inverted lens logic, branching at VRAM 0x80024BB4
38+
; If the current actor is a chest with its lens flag active, and the
39+
; invisible chests setting is on, override t5 to always hide the current actor
40+
41+
; Invisible Chests setting enabled
42+
lw t2, CHEST_LENS_ONLY
43+
beqz t2, @@return_draw
44+
nop
45+
46+
; Treasure Chest Minigame uses chests with type ID 4,
47+
; same as normal invisible big chests.
48+
; Lens behavior is inverted in this room for chests
49+
; but regular for the key and rupee rewards.
50+
; To keep the game beatable, always show the chests
51+
; in the minigame if invisible chests are enabled.
52+
; Since chests use the same type ID as elsewhere, hard code
53+
; the scene ID for the minigame (16).
54+
lh t2, 0x00A4(s1)
55+
ori t1, $zero, 0x0010
56+
beq t2, t1, @@return_draw
57+
nop
58+
59+
; actor->id == ACTOR_EN_BOX
60+
lh t2, 0x0000(s0)
61+
ori t1, $zero, 0x000A
62+
bne t2, t1, @@return_draw
63+
nop
64+
65+
; actor->flags & ACTOR_FLAG_7
66+
lw t2, 0x0004(s0)
67+
andi t1, t2, 0x0080
68+
beqz t1, @@return_draw
69+
nop
70+
71+
; globalCtx->roomCtx.curRoom.showInvisActors
72+
addu t1, s1, s4
73+
lbu t2, 0x1CC1(t1)
74+
beqz t2, @@return_draw
75+
nop
76+
77+
; globalCtx->actorCtx.lensActive
78+
lbu t2, 0x1C27(s1)
79+
bnez t2, @@return_draw
80+
nop
81+
82+
@@return_hide:
83+
andi t5, $zero, 0x0000
84+
jr ra ; invisible
85+
nop
86+
87+
@@return_draw:
88+
jr ra ; vanilla behavior
89+
nop
90+
91+
92+
SHOW_CHEST_WITH_INVERTED_LENS:
93+
; displaced code
94+
lw v0, 0x0004(s0)
95+
andi t3, v0, 0x0060
96+
97+
; negate actor lens flag in rooms with inverted lens logic if the
98+
; actor is a chest and lens is active
99+
100+
; Invisible Chests setting enabled
101+
lw t2, CHEST_LENS_ONLY
102+
beqz t2, @@return_draw_show
103+
nop
104+
105+
; actor->id == ACTOR_EN_BOX
106+
lh t2, 0x0000(s0)
107+
ori t1, $zero, 0x000A
108+
bne t2, t1, @@return_draw_show
109+
nop
110+
111+
; actor->flags & ACTOR_FLAG_7
112+
lw t2, 0x0004(s0)
113+
andi t1, t2, 0x0080
114+
beqz t1, @@return_draw_show
115+
nop
116+
117+
; globalCtx->roomCtx.curRoom.showInvisActors
118+
addu t1, s1, s4
119+
lbu t2, 0x1CC1(t1)
120+
beqz t2, @@return_draw_show
121+
nop
122+
123+
; globalCtx->actorCtx.lensActive
124+
lbu t2, 0x1C27(s1)
125+
beqz t2, @@return_draw_show
126+
nop
127+
128+
; current scene ID == 16
129+
lh t2, 0x00A4(s1)
130+
ori t1, $zero, 0x0010
131+
beq t2, t1, @@return_draw_show
132+
nop
133+
134+
andi v0, $zero, 0x0000 ; flags aren't referenced again, safe to delete
135+
jr ra ; visible
136+
nop
137+
138+
@@return_draw_show:
139+
jr ra ; vanilla behavior
140+
nop

ASM/src/hacks.asm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,28 @@ skip_GS_BGS_text:
12511251
.org 0xFEB000 + 0x10C0 - 0x32A090 + 0x32A158
12521252
.word 0xDE000000, 0x09000010
12531253

1254+
;==================================================================================================
1255+
; Invisible Chests
1256+
;==================================================================================================
1257+
1258+
; z_actor, offset 0x5F58
1259+
; Hooks into actor draw logic for invisible actors and lens of truth.
1260+
; If invisible chests is enabled, chests in rooms with inverted lens
1261+
; functionality (hide instead of show) will not be drawn at all unless
1262+
; lens is active.
1263+
; replaces
1264+
; lw v0, 0x0004(s0)
1265+
; andi t3, v0, 0x0060
1266+
.orga 0xA9AAF0
1267+
jal SHOW_CHEST_WITH_INVERTED_LENS
1268+
nop
1269+
; replaces
1270+
; sll t9, s2, 2
1271+
; addu t0, s7, t9
1272+
.orga 0xA9AB0C
1273+
jal HIDE_CHEST_WITH_INVERTED_LENS
1274+
nop
1275+
12541276
;==================================================================================================
12551277
; Cast Fishing Rod without B Item
12561278
;==================================================================================================

ASM/src/macros.asm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222

2323
.macro beq_a, reg1, reg2, addr
2424
beq reg1, reg2, (org() + addr - orga())
25+
.endmacro
26+
27+
.macro bnezl_a, reg1, addr
28+
bnezl reg1, (org() + addr - orga())
2529
.endmacro

Patches.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,11 @@ def update_scrub_text(message, text_replacement, default_price, price, item_name
19261926
rom.write_int16(chest_address_0 + 6, 0x0172) # Z pos
19271927
rom.write_int16(chest_address_2 + 6, 0x0172) # Z pos
19281928

1929+
# Make all chests invisible
1930+
if world.settings.invisible_chests:
1931+
symbol = rom.sym('CHEST_LENS_ONLY')
1932+
rom.write_int32(symbol, 0x00000001)
1933+
19291934
# give dungeon items the correct messages
19301935
add_item_messages(messages, shop_items, world)
19311936
if world.settings.enhance_map_compass:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ do that.
120120
* New settings allow for Rainbow Bridge and Ganon's Boss Key to be obtained upon reaching a certain amount of total heart containers.
121121
* New setting `Easier Fire Arrow Entry` allows you to set the amount of torches that must be lit to open Shadow Temple.
122122
* The pause screen info menu has been split into 3 menus, which show icons on the D-Pad indicating which direction leads to which menu. In addition, the menu now tracks the total keys you've found for a dungeon, not just how many you have remaining.
123+
* New setting `Invisible Chests` makes all chests in the game invisible.
123124

124125
* **Gameplay**
125126
* Shortened the animation for equipping magic arrows.

SettingsList.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4205,6 +4205,16 @@ def __init__(self, name, gui_text, min, max, default, step=1,
42054205
''',
42064206
shared = True,
42074207
),
4208+
Checkbutton(
4209+
name = 'invisible_chests',
4210+
gui_text = 'Invisible Chests',
4211+
gui_tooltip = '''\
4212+
Chests will be only be visible with
4213+
the Lens of Truth. Lens is not logically
4214+
required for normally visible chests.
4215+
''',
4216+
shared = True,
4217+
),
42084218
Checkbutton(
42094219
name = 'clearer_hints',
42104220
gui_text = 'Clearer Hints',

0 commit comments

Comments
 (0)