Skip to content

Commit

Permalink
Merge 'Add setting to require Lens of Truth for Treasure Chest Miniga…
Browse files Browse the repository at this point in the history
…me' (#2307)
  • Loading branch information
fenhl committed Oct 2, 2024
1 parent 8b0c6e2 commit eb52eba
Show file tree
Hide file tree
Showing 16 changed files with 34,456 additions and 34,185 deletions.
1,430 changes: 720 additions & 710 deletions ASM/build/asm_symbols.txt

Large diffs are not rendered by default.

Binary file modified ASM/build/bundle.o
Binary file not shown.
853 changes: 428 additions & 425 deletions ASM/build/c_symbols.txt

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion ASM/c/item_upgrades.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include "z64.h"

extern uint32_t FREE_BOMBCHU_DROPS;

extern uint8_t SHUFFLE_CHEST_GAME;
extern uint8_t TCG_REQUIRES_LENS;

// The layout of this struct is part of the definition of the co-op context.
// If you change it, bump the co-op context version in coop_state.asm and update Notes/coop-ctx.md
Expand Down Expand Up @@ -181,6 +182,15 @@ uint16_t bombchus_to_bag(z64_file_t* save, override_t override) {

uint16_t upgrade_key_model(z64_file_t* save, override_t override) {
uint16_t item_id = override.value.base.item_id;
// Force treasure chest game loss if the setting to require Lens of Truth
// is enabled. Room index is checked to avoid overriding the salesman's item.
if (item_id == GI_DOOR_KEY && !SHUFFLE_CHEST_GAME && TCG_REQUIRES_LENS
&& override.value.base.player == PLAYER_ID
&& save->items[Z64_SLOT_LENS] != Z64_ITEM_LENS
&& z64_game.room_index != 0
) {
return GI_RUPEE_GREEN_LOSE; // Green Rupee (Chest Game)
}
if (CUSTOM_KEY_MODELS) {
if (item_id == GI_DOOR_KEY) {
// Treasure Chest Game Key
Expand Down
26 changes: 21 additions & 5 deletions ASM/c/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,28 @@ void shooting_gallery_message() {
shooting_gallery_show_message = 1;
}

uint8_t treasure_chest_game_show_message = 0;
// Displays a warning message if the player attempted the Treasure Chest Game without
// Lens of Truth when settings require it.
void treasure_chest_game_message() {
if (z64_file.items[Z64_SLOT_LENS] != Z64_ITEM_LENS) {
treasure_chest_game_show_message = 1;
}
}

// Function to display custom textboxes ingame.
void display_misc_messages() {
if (shooting_gallery_show_message == 1 &&
z64_MessageGetState(((uint8_t *)(&z64_game)) + 0x20D8) == 0) {
z64_DisplayTextbox(&z64_game, 0x045C, 0);
// To avoid displaying the message several times if the player just wants to farm the 50 rupees.
shooting_gallery_show_message = -1;
if (z64_MessageGetState(((uint8_t *)(&z64_game)) + 0x20D8) == 0) {
// Each minigame warning message can only be triggered in their respective
// scenes. Order doesn't matter.
if (shooting_gallery_show_message == 1) {
z64_DisplayTextbox(&z64_game, 0x045C, 0);
// To avoid displaying the message several times if the player just wants to farm the 50 rupees.
shooting_gallery_show_message = -1;
} else if (treasure_chest_game_show_message) {
z64_DisplayTextbox(&z64_game, 0x045D, 0);
// No reason not to repeat the message on a reattempt in case the player forgot.
treasure_chest_game_show_message = 0;
}
}
}
76 changes: 76 additions & 0 deletions ASM/src/chest_game.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
SHUFFLE_CHEST_GAME:
.byte 0x00
TCG_REQUIRES_LENS:
.byte 0x00
.align 4

chestgame_buy_item_hook:
Expand Down Expand Up @@ -88,3 +90,77 @@ chestgame_delayed_chest_open:
@@return:
jr ra
lw a0, 0x004C($sp) ; displaced code

; Show a key in the unopened chest regardless of chest
; contents if the tcg_requires_lens setting is enabled
chestgame_force_game_loss_left:
; displaced code
lwc1 $f0, 0x0024($v1)
lwc1 $f2, 0x0028($v1)
; check setting
lb $t7, TCG_REQUIRES_LENS
beqz $t7, @@return
nop
; safety check to prevent simulated loss if keys are shuffled
lb $t7, SHUFFLE_CHEST_GAME
bnez $t7, @@return
nop
; check if player has lens of truth
lui $t1, hi(SAVE_CONTEXT + 0x81)
lb $t2, lo(SAVE_CONTEXT + 0x81)($t1) ; lens item slot
li $t3, 15 ; lens item ID
beq $t2, $t3, @@return
nop
; simulate lost game
addiu $t0, $zero, 0x0071
j chestgame_warn_player_of_rigged_game
nop

@@return:
jr $ra
nop

chestgame_force_game_loss_right:
; displaced code
lwc1 $f0, 0x0024($v0)
lwc1 $f2, 0x0028($v0)
; check setting
lb $t7, TCG_REQUIRES_LENS
beqz $t7, @@return
nop
; safety check to prevent simulated loss if keys are shuffled
lb $t7, SHUFFLE_CHEST_GAME
bnez $t7, @@return
nop
; check if player has lens of truth
lui $t1, hi(SAVE_CONTEXT + 0x81)
lb $t2, lo(SAVE_CONTEXT + 0x81)($t1) ; lens item slot
li $t3, 15 ; lens item ID
beq $t2, $t3, @@return
nop
; simulate lost game
addiu $v1, $zero, 0x0071
j chestgame_warn_player_of_rigged_game
nop

@@return:
jr $ra
nop

; Add a helper message if the tcg_requires_lens
; setting is enabled and the player still attempts
; the game.
chestgame_warn_player_of_rigged_game:
addiu $sp, $sp, -0x20
sw $ra, 0x14($sp)
sw $v0, 0x18($sp)
sw $v1, 0x1C($sp)

jal treasure_chest_game_message
nop

lw $ra, 0x14($sp)
lw $v0, 0x18($sp)
lw $v1, 0x1C($sp)
jr $ra
addiu $sp, $sp, 0x20
18 changes: 18 additions & 0 deletions ASM/src/hacks.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3653,6 +3653,24 @@ DemoEffect_DrawJewel_AfterHook:
jal chestgame_delayed_chest_open
nop

; Show a key in the unopened chest regardless of chest
; contents if the tcg_requires_lens setting is enabled.
; Left/right do the same check for the get item ID,
; but use different registers for the actor spawn branch
; and chest actor references for coordinates.
; Replaces:
; lwc1 $f0, 0x0024(v1)
; lwc1 $f2, 0x0028(v1)
.orga 0xE43964
jal chestgame_force_game_loss_left
nop
; Replaces:
; lwc1 $f0, 0x0024(v0)
; lwc1 $f2, 0x0028(v0)
.orga 0xE43A0C
jal chestgame_force_game_loss_right
nop

;==================================================================================================
; Bombchu Ticking Color
;==================================================================================================
Expand Down
1 change: 1 addition & 0 deletions Messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@
(0x045A, ("\x12\x68\x7AMweep\x07\x04\x5B", 0x23)),
(0x045B, ("\x12\x68\x7AMweep", 0x23)),
(0x045C, ("Come back when you have\x01your own bow and you'll get the\x01\x05\x41real prize\x05\x40!\x0E\x78", 0x00)),
(0x045D, ("\x12\x68\x5F\x05\x44This game seems shady. Maybe\x01the \x05\x41eye of truth\x05\x44 will show the\x01way forward?\x0E\x78", 0x00)),
(0x6013, ("Hey, newcomer!\x04Want me to throw you in jail?\x01\x01\x1B\x05\x42No\x01Yes\x05\x40", 0x00)),
]

Expand Down
3 changes: 3 additions & 0 deletions Patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,9 @@ def update_scrub_text(message: bytearray, text_replacement: list[str], default_p
update_message_by_id(messages, 0x6E, "Wait, that room was off limits!\x02")
update_message_by_id(messages, 0x704C, "I hope you like it!\x02")

if world.settings.tcg_requires_lens:
rom.write_byte(rom.sym('TCG_REQUIRES_LENS'), 0x01)

if world.settings.shuffle_pots != 'off': # Update the first BK door in ganon's castle to use a separate flag so it can be unlocked to get to the pots
patch_ganons_tower_bk_door(rom, 0x15) # Using flag 0x15 for the door. GBK doors normally use 0x14.
locked_doors = get_doors_to_unlock(rom, world)
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,16 @@ issue. You should always Hard Reset to avoid this issue entirely.

### Dev

#### New Settings and Options
* New options `Custom (count)` and `Custom (%)` for the `Ice Traps` setting.
* New hidden `plandomized_locations` setting to allow presets to place specific items at specific locations.
* New setting to speed up the boat ride in the Shadow Temple.
* New `Require Lens of Truth for Treasure Chest Game` setting.

#### Other Changes
* Now supports custom music written for the Majora's Mask Randomizer.
* New Magic Meter item model to allow magic drops to be shuffled in the future.
* New hidden `plandomized_locations` setting to allow presets to place specific items at specific locations.
* The first text box from each carpenter in the Thieves' Hideout is skipped.
* New setting to speed up the boat ride in the Shadow Temple.
* Seeds rolled on ootrandomizer.com display their ID in the top left corner of the file select screen.
* The `Other` tab of the generator has been rearranged for better grouping of settings, and the `One Major Item per Dungeon` setting has been moved there since it was causing frequent failures with `Randomize Main Rule Settings`.

Expand Down
15 changes: 15 additions & 0 deletions SettingsList.py
Original file line number Diff line number Diff line change
Expand Up @@ -2714,6 +2714,9 @@ class SettingInfos:
'Anywhere': Treasure Chest Game keys can appear anywhere
in the world.
''',
disable = {
'!vanilla': {'settings': ['tcg_requires_lens']}
},
shared = True,
gui_params = {
'randomize_key': 'randomize_settings',
Expand Down Expand Up @@ -3842,6 +3845,18 @@ class SettingInfos:
shared = True,
)

tcg_requires_lens = Checkbutton(
gui_text = 'Require Lens of Truth for Treasure Chest Game',
gui_tooltip = '''\
Force the player to always lose the
treasure chest game in the first room
unless they have the Lens of Truth.
Does not function if Treasure Chest Game
small keys are shuffled.
''',
shared = True,
)

no_collectible_hearts = Checkbutton(
gui_text = 'Hero Mode',
gui_tooltip = '''\
Expand Down
Loading

0 comments on commit eb52eba

Please sign in to comment.