Skip to content

Commit

Permalink
Merge 'Add Invisible Chests option' (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjohnson57 committed Jun 16, 2022
2 parents 36f011a + c9f3894 commit 505c5e0
Show file tree
Hide file tree
Showing 13 changed files with 16,792 additions and 16,567 deletions.
1,049 changes: 528 additions & 521 deletions ASM/build/asm_symbols.txt

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions ASM/c/chests.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ void get_chest_override(z64_actor_t *actor) {

((uint8_t*)actor)[0x01EC] = size;
((uint8_t*)actor)[0x01ED] = color;
if (CHEST_LENS_ONLY) {
// Actor flag 7 makes actors invisible
// Usually only applies to chest types 4 and 6
actor->flags |= 0x80;
}
}

void draw_chest(z64_game_t* game, int part, void* unk, void* unk2,
Expand Down
1 change: 1 addition & 0 deletions ASM/c/chests.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
extern uint32_t CHEST_SIZE_MATCH_CONTENTS;
extern uint32_t CHEST_TEXTURE_MATCH_CONTENTS;
extern uint32_t CHEST_SIZE_TEXTURE;
extern uint32_t CHEST_LENS_ONLY;

void get_chest_override(z64_actor_t *actor);

Expand Down
118 changes: 118 additions & 0 deletions ASM/src/chests.asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
CHEST_LENS_ONLY:
.word 0x00000000


GET_CHEST_OVERRIDE_WRAPPER:
sb t9,0x01E9(s0)

Expand All @@ -20,3 +24,117 @@ GET_CHEST_OVERRIDE_WRAPPER:
lwc1 $f16, 0x18 (sp)
jr ra
addiu sp, sp, 0x20


HIDE_CHEST_WITH_INVERTED_LENS:
; displaced code
sll t9, s2, 2
addu t0, s7, t9

; Do not draw chests if invisible chests setting is on and lens is not active
; If lens is active, bypass default actor lens draw logic for chests in rooms
; with inverted lens behavior (hide vs show actors).
; t5 holds if the room has inverted lens logic, branching at VRAM 0x80024BB4
; If the current actor is a chest with its lens flag active, and the
; invisible chests setting is on, override t5 to always hide the current actor

; Invisible Chests setting enabled
lw t2, CHEST_LENS_ONLY
beqz t2, @@return_draw
nop

; Treasure Chest Minigame uses chests with type ID 4,
; same as normal invisible big chests.
; Lens behavior is inverted in this room for chests
; but regular for the key and rupee rewards.
; To keep the game beatable, always show the chests
; in the minigame if invisible chests are enabled.
; Since chests use the same type ID as elsewhere, hard code
; the scene ID for the minigame (16).
lh t2, 0x00A4(s1)
ori t1, $zero, 0x0010
beq t2, t1, @@return_draw
nop

; actor->id == ACTOR_EN_BOX
lh t2, 0x0000(s0)
ori t1, $zero, 0x000A
bne t2, t1, @@return_draw
nop

; actor->flags & ACTOR_FLAG_7
lw t2, 0x0004(s0)
andi t1, t2, 0x0080
beqz t1, @@return_draw
nop

; globalCtx->roomCtx.curRoom.showInvisActors
addu t1, s1, s4
lbu t2, 0x1CC1(t1)
beqz t2, @@return_draw
nop

; globalCtx->actorCtx.lensActive
lbu t2, 0x1C27(s1)
bnez t2, @@return_draw
nop

@@return_hide:
andi t5, $zero, 0x0000
jr ra ; invisible
nop

@@return_draw:
jr ra ; vanilla behavior
nop


SHOW_CHEST_WITH_INVERTED_LENS:
; displaced code
lw v0, 0x0004(s0)
andi t3, v0, 0x0060

; negate actor lens flag in rooms with inverted lens logic if the
; actor is a chest and lens is active

; Invisible Chests setting enabled
lw t2, CHEST_LENS_ONLY
beqz t2, @@return_draw_show
nop

; actor->id == ACTOR_EN_BOX
lh t2, 0x0000(s0)
ori t1, $zero, 0x000A
bne t2, t1, @@return_draw_show
nop

; actor->flags & ACTOR_FLAG_7
lw t2, 0x0004(s0)
andi t1, t2, 0x0080
beqz t1, @@return_draw_show
nop

; globalCtx->roomCtx.curRoom.showInvisActors
addu t1, s1, s4
lbu t2, 0x1CC1(t1)
beqz t2, @@return_draw_show
nop

; globalCtx->actorCtx.lensActive
lbu t2, 0x1C27(s1)
beqz t2, @@return_draw_show
nop

; current scene ID == 16
lh t2, 0x00A4(s1)
ori t1, $zero, 0x0010
beq t2, t1, @@return_draw_show
nop

andi v0, $zero, 0x0000 ; flags aren't referenced again, safe to delete
jr ra ; visible
nop

@@return_draw_show:
jr ra ; vanilla behavior
nop
22 changes: 22 additions & 0 deletions ASM/src/hacks.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,28 @@ skip_GS_BGS_text:
.org 0xFEB000 + 0x10C0 - 0x32A090 + 0x32A158
.word 0xDE000000, 0x09000010

;==================================================================================================
; Invisible Chests
;==================================================================================================

; z_actor, offset 0x5F58
; Hooks into actor draw logic for invisible actors and lens of truth.
; If invisible chests is enabled, chests in rooms with inverted lens
; functionality (hide instead of show) will not be drawn at all unless
; lens is active.
; replaces
; lw v0, 0x0004(s0)
; andi t3, v0, 0x0060
.orga 0xA9AAF0
jal SHOW_CHEST_WITH_INVERTED_LENS
nop
; replaces
; sll t9, s2, 2
; addu t0, s7, t9
.orga 0xA9AB0C
jal HIDE_CHEST_WITH_INVERTED_LENS
nop

;==================================================================================================
; Cast Fishing Rod without B Item
;==================================================================================================
Expand Down
4 changes: 4 additions & 0 deletions ASM/src/macros.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@

.macro beq_a, reg1, reg2, addr
beq reg1, reg2, (org() + addr - orga())
.endmacro

.macro bnezl_a, reg1, addr
bnezl reg1, (org() + addr - orga())
.endmacro
5 changes: 5 additions & 0 deletions Patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,11 @@ def update_scrub_text(message, text_replacement, default_price, price, item_name
rom.write_int16(chest_address_0 + 6, 0x0172) # Z pos
rom.write_int16(chest_address_2 + 6, 0x0172) # Z pos

# Make all chests invisible
if world.settings.invisible_chests:
symbol = rom.sym('CHEST_LENS_ONLY')
rom.write_int32(symbol, 0x00000001)

# give dungeon items the correct messages
add_item_messages(messages, shop_items, world)
if world.settings.enhance_map_compass:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ do that.
* New settings allow for Rainbow Bridge and Ganon's Boss Key to be obtained upon reaching a certain amount of total heart containers.
* New setting `Easier Fire Arrow Entry` allows you to set the amount of torches that must be lit to open Shadow Temple.
* 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.
* New setting `Invisible Chests` makes all chests in the game invisible.

* **Gameplay**
* Shortened the animation for equipping magic arrows.
Expand Down
10 changes: 10 additions & 0 deletions SettingsList.py
Original file line number Diff line number Diff line change
Expand Up @@ -4205,6 +4205,16 @@ def __init__(self, name, gui_text, min, max, default, step=1,
''',
shared = True,
),
Checkbutton(
name = 'invisible_chests',
gui_text = 'Invisible Chests',
gui_tooltip = '''\
Chests will be only be visible with
the Lens of Truth. Lens is not logically
required for normally visible chests.
''',
shared = True,
),
Checkbutton(
name = 'clearer_hints',
gui_text = 'Clearer Hints',
Expand Down
Loading

0 comments on commit 505c5e0

Please sign in to comment.