From 4e73cfc3e65fa138e0e6bfe922fd61bb482f9489 Mon Sep 17 00:00:00 2001 From: Exodus <7614885+exodus122@users.noreply.github.com> Date: Sat, 7 Jan 2023 23:05:23 -0500 Subject: [PATCH 1/3] Added commands for equipping iron boots, equipping hover boots, and using ocarina --- USAGE.md | 6 ++++++ lib/liboot-1.0.a | 5 +++++ lib/liboot-1.1.a | 5 +++++ lib/liboot-1.2.a | 5 +++++ lib/liboot-ce-j.a | 5 +++++ lib/liboot-gc-j.a | 5 +++++ lib/liboot-gc-u.a | 5 +++++ lib/liboot-mq-j.a | 5 +++++ lib/liboot-mq-u.a | 5 +++++ src/gz/gz.h | 3 +++ src/gz/gz_command.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ src/gz/settings.c | 3 +++ src/gz/settings.h | 3 +++ src/gz/state.c | 2 +- src/gz/z64.h | 7 ++++++- 15 files changed, 113 insertions(+), 2 deletions(-) diff --git a/USAGE.md b/USAGE.md index 435ec6ac..23229d06 100644 --- a/USAGE.md +++ b/USAGE.md @@ -562,6 +562,12 @@ The following commands are available: *Default: `unbound`* - **reset:** Reset the game, as if the reset button had been pressed. *Default: `unbound`* + **equip irons:** Equip or unequip iron boots, if you have them. + *Default: `unbound`* + **equip hovers:** Equip or unequip hover boots, if you have them. + *Default: `unbound`* + **use ocarina:** Use ocarina, if you have one. + *Default: `unbound`* **_Warning:_** Unbinding the *show/hide menu* or *return from menu* commands, or binding them to a button combination that will interfere with menu diff --git a/lib/liboot-1.0.a b/lib/liboot-1.0.a index 5ef56e49..a6d250bc 100644 --- a/lib/liboot-1.0.a +++ b/lib/liboot-1.0.a @@ -65,6 +65,7 @@ z64_ocarina_sync_hook = 0x800C2EA0 ; z64_afx_rand_call = 0x800C3A50 ; z64_OcarinaUpdate = 0x800C3DC8 ; z64_ResetAudio = 0x800C7E98 ; +z64_PlaySfx = 0x800C806C ; z64_CheckAfxConfigBusy = 0x800CB798 ; z64_LoadOverlay = 0x800CCBB8 ; z64_SeedRandom = 0x800CDCC0 ; @@ -118,6 +119,9 @@ z64_song_ptr = 0x80102B3C ; z64_ocarina_button_state = 0x80102B7C ; z64_sfx_write_pos = 0x80104360 ; z64_sfx_read_pos = 0x80104364 ; +z64_sfx_unk1 = 0x80104394 ; +z64_sfx_unk2 = 0x801043A0 ; +z64_sfx_unk3 = 0x801043A8 ; z64_audio_cmd_write_pos = 0x801043B0 ; z64_audio_cmd_read_pos = 0x801043B4 ; z64_afx_cfg = 0x801043C0 ; @@ -166,4 +170,5 @@ z64_ctxt = 0x801C84A0 ; z64_game = z64_ctxt ; z64_link = 0x801DAA30 ; z64_cimg = 0x803B5000 ; +z64_UseButton = 0x8038C9A0 ; z64_item_highlight_vram = 0x80829D9C ; diff --git a/lib/liboot-1.1.a b/lib/liboot-1.1.a index 989f1b52..e46bd4d8 100644 --- a/lib/liboot-1.1.a +++ b/lib/liboot-1.1.a @@ -65,6 +65,7 @@ z64_ocarina_sync_hook = 0x800C2EFC ; z64_afx_rand_call = 0x800C3AC0 ; z64_OcarinaUpdate = 0x800C3E38 ; z64_ResetAudio = 0x800C8070 ; +z64_PlaySfx = 0x800C823C ; z64_CheckAfxConfigBusy = 0x800CB958 ; z64_LoadOverlay = 0x800CCD78 ; z64_SeedRandom = 0x800CDE80 ; @@ -118,6 +119,9 @@ z64_song_ptr = 0x80102CFC ; z64_ocarina_button_state = 0x80102D3C ; z64_sfx_write_pos = 0x80104520 ; z64_sfx_read_pos = 0x80104524 ; +z64_sfx_unk1 = 0x80104554 ; +z64_sfx_unk2 = 0x80104560 ; +z64_sfx_unk3 = 0x80104568 ; z64_audio_cmd_write_pos = 0x80104570 ; z64_audio_cmd_read_pos = 0x80104574 ; z64_afx_cfg = 0x80104580 ; @@ -166,4 +170,5 @@ z64_ctxt = 0x801C8660 ; z64_game = z64_ctxt ; z64_link = 0x801DABF0 ; z64_cimg = 0x803B5000 ; +z64_UseButton = 0x8038CB18 ; z64_item_highlight_vram = 0x80829D9C ; diff --git a/lib/liboot-1.2.a b/lib/liboot-1.2.a index 165e14dd..ac1ec52e 100644 --- a/lib/liboot-1.2.a +++ b/lib/liboot-1.2.a @@ -65,6 +65,7 @@ z64_ocarina_sync_hook = 0x800C355C ; z64_afx_rand_call = 0x800C4118 ; z64_OcarinaUpdate = 0x800C4490 ; z64_ResetAudio = 0x800C86E8 ; +z64_PlaySfx = 0x800C88BC ; z64_CheckAfxConfigBusy = 0x800CBFD8 ; z64_LoadOverlay = 0x800CD3F8 ; z64_SeedRandom = 0x800CE500 ; @@ -118,6 +119,9 @@ z64_song_ptr = 0x8010317C ; z64_ocarina_button_state = 0x801031BC ; z64_sfx_write_pos = 0x801049A0 ; z64_sfx_read_pos = 0x801049A4 ; +z64_sfx_unk1 = 0x801049D4 ; +z64_sfx_unk2 = 0x801049E0 ; +z64_sfx_unk3 = 0x801049E8 ; z64_audio_cmd_write_pos = 0x801049F0 ; z64_audio_cmd_read_pos = 0x801049F4 ; z64_afx_cfg = 0x80104A00 ; @@ -166,4 +170,5 @@ z64_ctxt = 0x801C8D60 ; z64_game = z64_ctxt ; z64_link = 0x801DB2F0 ; z64_cimg = 0x803B5000 ; +z64_UseButton = 0x8038D15C ; z64_item_highlight_vram = 0x80829D9C ; diff --git a/lib/liboot-ce-j.a b/lib/liboot-ce-j.a index f7372d9a..8618a24c 100644 --- a/lib/liboot-ce-j.a +++ b/lib/liboot-ce-j.a @@ -65,6 +65,7 @@ z64_ocarina_sync_hook = 0x800C38A8 ; z64_afx_rand_call = 0x800C4458 ; z64_OcarinaUpdate = 0x800C47D0 ; z64_ResetAudio = 0x800C8884 ; +z64_PlaySfx = 0x800C8A5C ; z64_CheckAfxConfigBusy = 0x800CC188 ; z64_LoadOverlay = 0x800CD420 ; z64_SeedRandom = 0x800CE3D0 ; @@ -117,6 +118,9 @@ z64_song_ptr = 0x80101BAC ; z64_ocarina_button_state = 0x80101BEC ; z64_sfx_write_pos = 0x801033D0 ; z64_sfx_read_pos = 0x801033D4 ; +z64_sfx_unk1 = 0x80103404 ; +z64_sfx_unk2 = 0x80103410 ; +z64_sfx_unk3 = 0x80103418 ; z64_audio_cmd_write_pos = 0x80103420 ; z64_audio_cmd_read_pos = 0x80103424 ; z64_afx_cfg = 0x80103430 ; @@ -166,4 +170,5 @@ z64_ctxt = 0x801C9660 ; z64_game = z64_ctxt ; z64_link = 0x801DBBB0 ; z64_cimg = 0x803B5000 ; +z64_UseButton = 0x8038D9A4 ; z64_item_highlight_vram = 0x8082996C ; diff --git a/lib/liboot-gc-j.a b/lib/liboot-gc-j.a index a1654eb7..83582851 100644 --- a/lib/liboot-gc-j.a +++ b/lib/liboot-gc-j.a @@ -65,6 +65,7 @@ z64_ocarina_sync_hook = 0x800C38C8 ; z64_afx_rand_call = 0x800C4478 ; z64_OcarinaUpdate = 0x800C47F0 ; z64_ResetAudio = 0x800C88A4 ; +z64_PlaySfx = 0x800C8A7C ; z64_CheckAfxConfigBusy = 0x800CC1A8 ; z64_LoadOverlay = 0x800CD440 ; z64_SeedRandom = 0x800CE3F0 ; @@ -117,6 +118,9 @@ z64_song_ptr = 0x80101BCC ; z64_ocarina_button_state = 0x80101C0C ; z64_sfx_write_pos = 0x801033F0 ; z64_sfx_read_pos = 0x801033F4 ; +z64_sfx_unk1 = 0x80103424 ; +z64_sfx_unk2 = 0x80103430 ; +z64_sfx_unk3 = 0x80103438 ; z64_audio_cmd_write_pos = 0x80103440 ; z64_audio_cmd_read_pos = 0x80103444 ; z64_afx_cfg = 0x80103450 ; @@ -166,4 +170,5 @@ z64_ctxt = 0x801C9660 ; z64_game = z64_ctxt ; z64_link = 0x801DBBB0 ; z64_cimg = 0x803B5000 ; +z64_UseButton = 0x8038D9A4 ; z64_item_highlight_vram = 0x8082999C ; diff --git a/lib/liboot-gc-u.a b/lib/liboot-gc-u.a index 996884c0..1209f582 100644 --- a/lib/liboot-gc-u.a +++ b/lib/liboot-gc-u.a @@ -65,6 +65,7 @@ z64_ocarina_sync_hook = 0x800C38A8 ; z64_afx_rand_call = 0x800C4458 ; z64_OcarinaUpdate = 0x800C47D0 ; z64_ResetAudio = 0x800C8884 ; +z64_PlaySfx = 0x800C8A5C ; z64_CheckAfxConfigBusy = 0x800CC188 ; z64_LoadOverlay = 0x800CD420 ; z64_SeedRandom = 0x800CE3D0 ; @@ -117,6 +118,9 @@ z64_song_ptr = 0x80101BAC ; z64_ocarina_button_state = 0x80101BEC ; z64_sfx_write_pos = 0x801033D0 ; z64_sfx_read_pos = 0x801033D4 ; +z64_sfx_unk1 = 0x80103404 ; +z64_sfx_unk2 = 0x80103410 ; +z64_sfx_unk3 = 0x80103418 ; z64_audio_cmd_write_pos = 0x80103420 ; z64_audio_cmd_read_pos = 0x80103424 ; z64_afx_cfg = 0x80103430 ; @@ -166,4 +170,5 @@ z64_ctxt = 0x801C9660 ; z64_game = z64_ctxt ; z64_link = 0x801DBBB0 ; z64_cimg = 0x803B5000 ; +z64_UseButton = 0x8038D9A4 ; z64_item_highlight_vram = 0x8082997C ; diff --git a/lib/liboot-mq-j.a b/lib/liboot-mq-j.a index 782d854d..6171eb01 100644 --- a/lib/liboot-mq-j.a +++ b/lib/liboot-mq-j.a @@ -65,6 +65,7 @@ z64_ocarina_sync_hook = 0x800C38A8 ; z64_afx_rand_call = 0x800C4458 ; z64_OcarinaUpdate = 0x800C47D0 ; z64_ResetAudio = 0x800C8884 ; +z64_PlaySfx = 0x800C8A5C ; z64_CheckAfxConfigBusy = 0x800CC188 ; z64_LoadOverlay = 0x800CD420 ; z64_SeedRandom = 0x800CE3D0 ; @@ -117,6 +118,9 @@ z64_song_ptr = 0x80101BAC ; z64_ocarina_button_state = 0x80101BEC ; z64_sfx_write_pos = 0x801033D0 ; z64_sfx_read_pos = 0x801033D4 ; +z64_sfx_unk1 = 0x80103404 ; +z64_sfx_unk2 = 0x80103410 ; +z64_sfx_unk3 = 0x80103418 ; z64_audio_cmd_write_pos = 0x80103420 ; z64_audio_cmd_read_pos = 0x80103424 ; z64_afx_cfg = 0x80103430 ; @@ -166,4 +170,5 @@ z64_ctxt = 0x801C9660 ; z64_game = z64_ctxt ; z64_link = 0x801DBBB0 ; z64_cimg = 0x803B5000 ; +z64_UseButton = 0x8038D9A4 ; z64_item_highlight_vram = 0x8082999C ; diff --git a/lib/liboot-mq-u.a b/lib/liboot-mq-u.a index 81cd7060..e25de91b 100644 --- a/lib/liboot-mq-u.a +++ b/lib/liboot-mq-u.a @@ -65,6 +65,7 @@ z64_ocarina_sync_hook = 0x800C3888 ; z64_afx_rand_call = 0x800C4438 ; z64_OcarinaUpdate = 0x800C47B0 ; z64_ResetAudio = 0x800C8864 ; +z64_PlaySfx = 0x800C8A3C ; z64_CheckAfxConfigBusy = 0x800CC168 ; z64_LoadOverlay = 0x800CD400 ; z64_SeedRandom = 0x800CE3B0 ; @@ -117,6 +118,9 @@ z64_song_ptr = 0x80101B8C ; z64_ocarina_button_state = 0x80101BCC ; z64_sfx_write_pos = 0x801033B0 ; z64_sfx_read_pos = 0x801033B4 ; +z64_sfx_unk1 = 0x801033E4 ; +z64_sfx_unk2 = 0x801033F0 ; +z64_sfx_unk3 = 0x801033F0 ; z64_audio_cmd_write_pos = 0x80103400 ; z64_audio_cmd_read_pos = 0x80103404 ; z64_afx_cfg = 0x80103410 ; @@ -166,4 +170,5 @@ z64_ctxt = 0x801C9620 ; z64_game = z64_ctxt ; z64_link = 0x801DBB70 ; z64_cimg = 0x803B5000 ; +z64_UseButton = 0x8038D964 ; z64_item_highlight_vram = 0x8082997C ; diff --git a/src/gz/gz.h b/src/gz/gz.h index e6f9aa6c..14ec98ea 100644 --- a/src/gz/gz.h +++ b/src/gz/gz.h @@ -271,6 +271,9 @@ void command_resettimer(void); void command_starttimer(void); void command_stoptimer(void); void command_reset(void); +void command_equip_irons(void); +void command_equip_hovers(void); +void command_use_ocarina(void); void z_to_movie(int movie_frame, z64_input_t *zi, _Bool reset); void movie_to_z(int movie_frame, z64_input_t *zi, _Bool *reset); diff --git a/src/gz/gz_command.c b/src/gz/gz_command.c index 6f0b9a95..083af1e1 100644 --- a/src/gz/gz_command.c +++ b/src/gz/gz_command.c @@ -50,6 +50,9 @@ struct command_info command_info[COMMAND_MAX] = {"start timer", command_starttimer, CMDACT_PRESS_ONCE}, {"stop timer", command_stoptimer, CMDACT_PRESS_ONCE}, {"reset", command_reset, CMDACT_PRESS_ONCE}, + {"equip irons", command_equip_irons, CMDACT_PRESS_ONCE}, + {"equip hovers", command_equip_hovers, CMDACT_PRESS_ONCE}, + {"use ocarina", command_use_ocarina, CMDACT_PRESS_ONCE}, }; void gz_apply_settings() @@ -406,3 +409,51 @@ void command_reset(void) { gz.reset_flag = 1; } + +#define BLOCK_DPAD (0x00000001 | \ + 0x00000002 | \ + 0x00000080 | \ + 0x00000400 | \ + 0x10000000 | \ + 0x20000000) + +#define BLOCK_OCARINA (0x00800000 | \ + 0x00000800 | \ + 0x00200000 | \ + 0x08000000) + +#define DISPLAY_DPAD (((z64_file.iron_boots || z64_file.hover_boots) && z64_file.link_age==0) || z64_file.items[0x07] == 0x07 || z64_file.items[0x07] == 0x08) + +#define CAN_USE_DPAD (((z64_link.state_flags_1 & BLOCK_DPAD) == 0) && \ + ((uint32_t)z64_ctxt.state_dtor==z64_state_ovl_tab[3].vram_dtor) && \ + (z64_file.interface_flag!=1) && \ + ((z64_event_state_1 & 0x20)==0)) + +#define CAN_USE_OCARINA (z64_game.pause_ctxt.state==0 && (z64_file.items[0x07] == 0x07 || z64_file.items[0x07] == 0x08) && !z64_game.if_ctxt.restriction_flags.ocarina && ((z64_link.state_flags_1 & BLOCK_OCARINA) == 0)) + +void command_equip_irons(void) +{ + if(z64_file.link_age == 0 && CAN_USE_DPAD && DISPLAY_DPAD && z64_file.iron_boots) { + if (z64_file.equip_boots == 2) z64_file.equip_boots = 1; + else z64_file.equip_boots = 2; + z64_UpdateEquipment(&z64_game, &z64_link); + z64_PlaySfx(0x835, &z64_sfx_unk1, 0x04, &z64_sfx_unk2, &z64_sfx_unk2, &z64_sfx_unk3); + } +} + +void command_equip_hovers(void) +{ + if(z64_file.link_age == 0 && CAN_USE_DPAD && DISPLAY_DPAD && z64_file.hover_boots) { + if (z64_file.equip_boots == 3) z64_file.equip_boots = 1; + else z64_file.equip_boots = 3; + z64_UpdateEquipment(&z64_game, &z64_link); + z64_PlaySfx(0x835, &z64_sfx_unk1, 0x04, &z64_sfx_unk2, &z64_sfx_unk2, &z64_sfx_unk3); + } +} + +void command_use_ocarina(void) +{ + if(CAN_USE_OCARINA) { + z64_UseButton(&z64_game,&z64_link,z64_file.items[0x07], 2); + } +} diff --git a/src/gz/settings.c b/src/gz/settings.c index 9cde88e1..ce016970 100644 --- a/src/gz/settings.c +++ b/src/gz/settings.c @@ -135,6 +135,9 @@ void settings_load_default(void) d->binds[COMMAND_STARTTIMER] = bind_make(0); d->binds[COMMAND_STOPTIMER] = bind_make(0); d->binds[COMMAND_RESET] = bind_make(0); + d->binds[COMMAND_EQUIP_IRONS] = bind_make(0); + d->binds[COMMAND_EQUIP_HOVERS] = bind_make(0); + d->binds[COMMAND_USE_OCARINA] = bind_make(0); } void settings_save(int profile) diff --git a/src/gz/settings.h b/src/gz/settings.h index c235d684..cadf2807 100644 --- a/src/gz/settings.h +++ b/src/gz/settings.h @@ -88,6 +88,9 @@ enum commands COMMAND_STARTTIMER, COMMAND_STOPTIMER, COMMAND_RESET, + COMMAND_EQUIP_IRONS, + COMMAND_EQUIP_HOVERS, + COMMAND_USE_OCARINA, COMMAND_MAX, }; diff --git a/src/gz/state.c b/src/gz/state.c index 4805d6f5..08b8b67a 100644 --- a/src/gz/state.c +++ b/src/gz/state.c @@ -1700,7 +1700,7 @@ void load_state(const struct state_meta *state) } else { /* event state */ - serial_read(&p, z64_event_state_1, 0x0008); + serial_read(&p, &z64_event_state_1, sizeof(z64_event_state_1)); serial_read(&p, z64_event_state_2, 0x0004); /* event camera parameters */ for (int i = 0; i < 24; ++i) diff --git a/src/gz/z64.h b/src/gz/z64.h index 2d6c806f..72c75be9 100644 --- a/src/gz/z64.h +++ b/src/gz/z64.h @@ -2230,7 +2230,7 @@ z64_extern z64_part_ovl_t z64_part_ovl_tab[37]; z64_extern z64_actor_ovl_t z64_actor_ovl_tab[471]; z64_extern char z_camera_c_data[]; z64_extern char z64_hud_state[]; -z64_extern char z64_event_state_1[]; +z64_extern uint32_t z64_event_state_1; z64_extern uint32_t z64_letterbox_time; z64_extern char z64_event_state_2[]; z64_extern char z64_event_camera[]; @@ -2317,6 +2317,9 @@ z64_extern z64_game_t z64_game; z64_extern z64_link_t z64_link; z64_extern char z64_cimg[]; z64_extern char z64_item_highlight_vram[]; +z64_extern z64_xyzf_t z64_sfx_unk1; +z64_extern float z64_sfx_unk2; +z64_extern float z64_sfx_unk3; /* functions */ void z64_DrawActors (z64_game_t *game, void *actor_ctxt); @@ -2370,10 +2373,12 @@ void z64_ConfigureAfx (uint8_t cfg); uint32_t z64_AfxRand (void); void z64_OcarinaUpdate (void); void z64_ResetAudio (uint8_t cfg); +void z64_PlaySfx (uint16_t sfx, z64_xyzf_t *unk_00_, int8_t unk_01_ , float *unk_02_, float *unk_03_, float *unk_04_); int z64_CheckAfxConfigBusy (void); uint32_t z64_LoadOverlay (uint32_t vrom_start, uint32_t vrom_end, uint32_t vram_start, uint32_t vram_end, void *dst); void z64_SeedRandom (uint32_t seed); +void z64_UseButton (z64_game_t *game, z64_link_t *link, uint8_t item, uint8_t button); #endif From 82986043a95c065d91bdd9bd3f874dbf840571c4 Mon Sep 17 00:00:00 2001 From: glank Date: Thu, 12 Jan 2023 11:30:57 +0100 Subject: [PATCH 2/3] Fix regression for state version <4, reorder commands, simplify conditions, formatting --- USAGE.md | 12 ++--- src/gz/gz.h | 6 +-- src/gz/gz_command.c | 105 +++++++++++++++++++++++--------------------- src/gz/settings.c | 6 +-- src/gz/settings.h | 6 +-- src/gz/state.c | 2 +- src/gz/z64.h | 13 +++--- 7 files changed, 78 insertions(+), 72 deletions(-) diff --git a/USAGE.md b/USAGE.md index 23229d06..1033d2eb 100644 --- a/USAGE.md +++ b/USAGE.md @@ -515,6 +515,12 @@ The following commands are available: entrance as if Link voided out. *Default: `A + B + L`* - **toggle age:** Toggles between Adult and Child Link. Takes effect when entering a new area. *Default: `unbound`* + **equip iron boots:** Equip or unequip iron boots, if you have them. + *Default: `unbound`* + **equip hover boots:** Equip or unequip hover boots, if you have them. + *Default: `unbound`* + **use ocarina:** Use ocarina, if you have one. + *Default: `unbound`* - **save state:** Save the state of the game to the currently selected state slot. *Default: `D-Left`* - **load state:** Load the state saved in the currently selected state slot. @@ -562,12 +568,6 @@ The following commands are available: *Default: `unbound`* - **reset:** Reset the game, as if the reset button had been pressed. *Default: `unbound`* - **equip irons:** Equip or unequip iron boots, if you have them. - *Default: `unbound`* - **equip hovers:** Equip or unequip hover boots, if you have them. - *Default: `unbound`* - **use ocarina:** Use ocarina, if you have one. - *Default: `unbound`* **_Warning:_** Unbinding the *show/hide menu* or *return from menu* commands, or binding them to a button combination that will interfere with menu diff --git a/src/gz/gz.h b/src/gz/gz.h index 14ec98ea..25379251 100644 --- a/src/gz/gz.h +++ b/src/gz/gz.h @@ -249,6 +249,9 @@ void command_fileselect(void); void command_reload(void); void command_void(void); void command_age(void); +void command_equip_irons(void); +void command_equip_hovers(void); +void command_use_ocarina(void); void command_savestate(void); void command_loadstate(void); void command_savepos(void); @@ -271,9 +274,6 @@ void command_resettimer(void); void command_starttimer(void); void command_stoptimer(void); void command_reset(void); -void command_equip_irons(void); -void command_equip_hovers(void); -void command_use_ocarina(void); void z_to_movie(int movie_frame, z64_input_t *zi, _Bool reset); void movie_to_z(int movie_frame, z64_input_t *zi, _Bool *reset); diff --git a/src/gz/gz_command.c b/src/gz/gz_command.c index 083af1e1..3ae3ddbc 100644 --- a/src/gz/gz_command.c +++ b/src/gz/gz_command.c @@ -26,6 +26,9 @@ struct command_info command_info[COMMAND_MAX] = {"reload scene", command_reload, CMDACT_PRESS_ONCE}, {"void out", command_void, CMDACT_PRESS_ONCE}, {"toggle age", command_age, CMDACT_PRESS_ONCE}, + {"equip iron boots", command_equip_irons, CMDACT_PRESS_ONCE}, + {"equip hover boots", command_equip_hovers, CMDACT_PRESS_ONCE}, + {"use ocarina", command_use_ocarina, CMDACT_PRESS_ONCE}, {"save state", command_savestate, CMDACT_PRESS_ONCE}, {"load state", command_loadstate, CMDACT_PRESS_ONCE}, {"save position", command_savepos, CMDACT_HOLD}, @@ -50,9 +53,6 @@ struct command_info command_info[COMMAND_MAX] = {"start timer", command_starttimer, CMDACT_PRESS_ONCE}, {"stop timer", command_stoptimer, CMDACT_PRESS_ONCE}, {"reset", command_reset, CMDACT_PRESS_ONCE}, - {"equip irons", command_equip_irons, CMDACT_PRESS_ONCE}, - {"equip hovers", command_equip_hovers, CMDACT_PRESS_ONCE}, - {"use ocarina", command_use_ocarina, CMDACT_PRESS_ONCE}, }; void gz_apply_settings() @@ -212,6 +212,57 @@ void command_age(void) z64_UpdateEquipment(&z64_game, &z64_link); } +void command_equip_irons(void) +{ + if (zu_in_game() + && z64_file.link_age == 0 + && z64_file.iron_boots + && (z64_link.state_flags_1 & 0x30000483) == 0 + && z64_file.interface_flag != 1 + && (z64_event_state_1 & 0x20) == 0) + { + if (z64_file.equip_boots == 2) + z64_file.equip_boots = 1; + else + z64_file.equip_boots = 2; + z64_UpdateEquipment(&z64_game, &z64_link); + z64_PlaySfx(0x0835, &z64_sfx_unk1, 0x04, &z64_sfx_unk2, &z64_sfx_unk2, + &z64_sfx_unk3); + } +} + +void command_equip_hovers(void) +{ + if (zu_in_game() + && z64_file.link_age == 0 + && z64_file.hover_boots + && (z64_link.state_flags_1 & 0x30000483) == 0 + && z64_file.interface_flag != 1 + && (z64_event_state_1 & 0x20) == 0) + { + if (z64_file.equip_boots == 3) + z64_file.equip_boots = 1; + else + z64_file.equip_boots = 3; + z64_UpdateEquipment(&z64_game, &z64_link); + z64_PlaySfx(0x0835, &z64_sfx_unk1, 0x04, &z64_sfx_unk2, &z64_sfx_unk2, + &z64_sfx_unk3); + } +} + +void command_use_ocarina(void) +{ + if (zu_in_game() + && z64_game.pause_ctxt.state == 0 + && !z64_game.if_ctxt.restriction_flags.ocarina + && (z64_file.items[Z64_SLOT_OCARINA] == Z64_ITEM_FAIRY_OCARINA + || z64_file.items[Z64_SLOT_OCARINA] == Z64_ITEM_OCARINA_OF_TIME) + && (z64_link.state_flags_1 & 0x08C00800) == 0) + { + z64_UseButton(&z64_game, &z64_link, z64_file.items[Z64_SLOT_OCARINA], 2); + } +} + void command_savestate(void) { if (!zu_in_game()) @@ -409,51 +460,3 @@ void command_reset(void) { gz.reset_flag = 1; } - -#define BLOCK_DPAD (0x00000001 | \ - 0x00000002 | \ - 0x00000080 | \ - 0x00000400 | \ - 0x10000000 | \ - 0x20000000) - -#define BLOCK_OCARINA (0x00800000 | \ - 0x00000800 | \ - 0x00200000 | \ - 0x08000000) - -#define DISPLAY_DPAD (((z64_file.iron_boots || z64_file.hover_boots) && z64_file.link_age==0) || z64_file.items[0x07] == 0x07 || z64_file.items[0x07] == 0x08) - -#define CAN_USE_DPAD (((z64_link.state_flags_1 & BLOCK_DPAD) == 0) && \ - ((uint32_t)z64_ctxt.state_dtor==z64_state_ovl_tab[3].vram_dtor) && \ - (z64_file.interface_flag!=1) && \ - ((z64_event_state_1 & 0x20)==0)) - -#define CAN_USE_OCARINA (z64_game.pause_ctxt.state==0 && (z64_file.items[0x07] == 0x07 || z64_file.items[0x07] == 0x08) && !z64_game.if_ctxt.restriction_flags.ocarina && ((z64_link.state_flags_1 & BLOCK_OCARINA) == 0)) - -void command_equip_irons(void) -{ - if(z64_file.link_age == 0 && CAN_USE_DPAD && DISPLAY_DPAD && z64_file.iron_boots) { - if (z64_file.equip_boots == 2) z64_file.equip_boots = 1; - else z64_file.equip_boots = 2; - z64_UpdateEquipment(&z64_game, &z64_link); - z64_PlaySfx(0x835, &z64_sfx_unk1, 0x04, &z64_sfx_unk2, &z64_sfx_unk2, &z64_sfx_unk3); - } -} - -void command_equip_hovers(void) -{ - if(z64_file.link_age == 0 && CAN_USE_DPAD && DISPLAY_DPAD && z64_file.hover_boots) { - if (z64_file.equip_boots == 3) z64_file.equip_boots = 1; - else z64_file.equip_boots = 3; - z64_UpdateEquipment(&z64_game, &z64_link); - z64_PlaySfx(0x835, &z64_sfx_unk1, 0x04, &z64_sfx_unk2, &z64_sfx_unk2, &z64_sfx_unk3); - } -} - -void command_use_ocarina(void) -{ - if(CAN_USE_OCARINA) { - z64_UseButton(&z64_game,&z64_link,z64_file.items[0x07], 2); - } -} diff --git a/src/gz/settings.c b/src/gz/settings.c index ce016970..54cf08c9 100644 --- a/src/gz/settings.c +++ b/src/gz/settings.c @@ -110,6 +110,9 @@ void settings_load_default(void) d->binds[COMMAND_RELOAD] = bind_make(2, BUTTON_A, BUTTON_L); d->binds[COMMAND_VOID] = bind_make(3, BUTTON_A, BUTTON_B, BUTTON_L); d->binds[COMMAND_AGE] = bind_make(0); + d->binds[COMMAND_EQUIP_IRONS] = bind_make(0); + d->binds[COMMAND_EQUIP_HOVERS] = bind_make(0); + d->binds[COMMAND_USE_OCARINA] = bind_make(0); d->binds[COMMAND_SAVESTATE] = bind_make(1, BUTTON_D_LEFT); d->binds[COMMAND_LOADSTATE] = bind_make(1, BUTTON_D_RIGHT); d->binds[COMMAND_SAVEPOS] = bind_make(0); @@ -135,9 +138,6 @@ void settings_load_default(void) d->binds[COMMAND_STARTTIMER] = bind_make(0); d->binds[COMMAND_STOPTIMER] = bind_make(0); d->binds[COMMAND_RESET] = bind_make(0); - d->binds[COMMAND_EQUIP_IRONS] = bind_make(0); - d->binds[COMMAND_EQUIP_HOVERS] = bind_make(0); - d->binds[COMMAND_USE_OCARINA] = bind_make(0); } void settings_save(int profile) diff --git a/src/gz/settings.h b/src/gz/settings.h index cadf2807..eb708b6e 100644 --- a/src/gz/settings.h +++ b/src/gz/settings.h @@ -64,6 +64,9 @@ enum commands COMMAND_RELOAD, COMMAND_VOID, COMMAND_AGE, + COMMAND_EQUIP_IRONS, + COMMAND_EQUIP_HOVERS, + COMMAND_USE_OCARINA, COMMAND_SAVESTATE, COMMAND_LOADSTATE, COMMAND_SAVEPOS, @@ -88,9 +91,6 @@ enum commands COMMAND_STARTTIMER, COMMAND_STOPTIMER, COMMAND_RESET, - COMMAND_EQUIP_IRONS, - COMMAND_EQUIP_HOVERS, - COMMAND_USE_OCARINA, COMMAND_MAX, }; diff --git a/src/gz/state.c b/src/gz/state.c index 08b8b67a..c61510ab 100644 --- a/src/gz/state.c +++ b/src/gz/state.c @@ -1700,7 +1700,7 @@ void load_state(const struct state_meta *state) } else { /* event state */ - serial_read(&p, &z64_event_state_1, sizeof(z64_event_state_1)); + serial_read(&p, &z64_event_state_1, 0x0008); serial_read(&p, z64_event_state_2, 0x0004); /* event camera parameters */ for (int i = 0; i < 24; ++i) diff --git a/src/gz/z64.h b/src/gz/z64.h index 72c75be9..d26648aa 100644 --- a/src/gz/z64.h +++ b/src/gz/z64.h @@ -2270,6 +2270,9 @@ z64_extern char z64_song_ptr[]; z64_extern uint8_t z64_ocarina_button_state; z64_extern uint8_t z64_sfx_write_pos; z64_extern uint8_t z64_sfx_read_pos; +z64_extern z64_xyzf_t z64_sfx_unk1; +z64_extern float z64_sfx_unk2; +z64_extern float z64_sfx_unk3; z64_extern uint8_t z64_audio_cmd_write_pos; z64_extern uint8_t z64_audio_cmd_read_pos; z64_extern uint8_t z64_afx_cfg; @@ -2317,9 +2320,6 @@ z64_extern z64_game_t z64_game; z64_extern z64_link_t z64_link; z64_extern char z64_cimg[]; z64_extern char z64_item_highlight_vram[]; -z64_extern z64_xyzf_t z64_sfx_unk1; -z64_extern float z64_sfx_unk2; -z64_extern float z64_sfx_unk3; /* functions */ void z64_DrawActors (z64_game_t *game, void *actor_ctxt); @@ -2373,12 +2373,15 @@ void z64_ConfigureAfx (uint8_t cfg); uint32_t z64_AfxRand (void); void z64_OcarinaUpdate (void); void z64_ResetAudio (uint8_t cfg); -void z64_PlaySfx (uint16_t sfx, z64_xyzf_t *unk_00_, int8_t unk_01_ , float *unk_02_, float *unk_03_, float *unk_04_); +void z64_PlaySfx (uint16_t sfx, z64_xyzf_t *unk_00_, + int8_t unk_01_ , float *unk_02_, + float *unk_03_, float *unk_04_); int z64_CheckAfxConfigBusy (void); uint32_t z64_LoadOverlay (uint32_t vrom_start, uint32_t vrom_end, uint32_t vram_start, uint32_t vram_end, void *dst); void z64_SeedRandom (uint32_t seed); -void z64_UseButton (z64_game_t *game, z64_link_t *link, uint8_t item, uint8_t button); +void z64_UseButton (z64_game_t *game, z64_link_t *link, + uint8_t item, uint8_t button); #endif From fb5e34461c62fd82a4fdf07c85f467d83a2f2ad0 Mon Sep 17 00:00:00 2001 From: glank Date: Thu, 12 Jan 2023 11:57:08 +0100 Subject: [PATCH 3/3] Fix z64_sfx_unk3 address for mq-u, fix function signatures and data types --- lib/liboot-1.0.a | 2 +- lib/liboot-1.1.a | 2 +- lib/liboot-1.2.a | 2 +- lib/liboot-ce-j.a | 2 +- lib/liboot-gc-j.a | 2 +- lib/liboot-gc-u.a | 2 +- lib/liboot-mq-j.a | 2 +- lib/liboot-mq-u.a | 4 ++-- src/gz/z64.h | 8 ++++---- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/liboot-1.0.a b/lib/liboot-1.0.a index a6d250bc..91d8eab8 100644 --- a/lib/liboot-1.0.a +++ b/lib/liboot-1.0.a @@ -169,6 +169,6 @@ z64_disp = 0x8016A640 ; z64_ctxt = 0x801C84A0 ; z64_game = z64_ctxt ; z64_link = 0x801DAA30 ; -z64_cimg = 0x803B5000 ; z64_UseButton = 0x8038C9A0 ; +z64_cimg = 0x803B5000 ; z64_item_highlight_vram = 0x80829D9C ; diff --git a/lib/liboot-1.1.a b/lib/liboot-1.1.a index e46bd4d8..ab265004 100644 --- a/lib/liboot-1.1.a +++ b/lib/liboot-1.1.a @@ -169,6 +169,6 @@ z64_disp = 0x8016A800 ; z64_ctxt = 0x801C8660 ; z64_game = z64_ctxt ; z64_link = 0x801DABF0 ; -z64_cimg = 0x803B5000 ; z64_UseButton = 0x8038CB18 ; +z64_cimg = 0x803B5000 ; z64_item_highlight_vram = 0x80829D9C ; diff --git a/lib/liboot-1.2.a b/lib/liboot-1.2.a index ac1ec52e..cb6307f5 100644 --- a/lib/liboot-1.2.a +++ b/lib/liboot-1.2.a @@ -169,6 +169,6 @@ z64_disp = 0x8016AF00 ; z64_ctxt = 0x801C8D60 ; z64_game = z64_ctxt ; z64_link = 0x801DB2F0 ; -z64_cimg = 0x803B5000 ; z64_UseButton = 0x8038D15C ; +z64_cimg = 0x803B5000 ; z64_item_highlight_vram = 0x80829D9C ; diff --git a/lib/liboot-ce-j.a b/lib/liboot-ce-j.a index 8618a24c..807e71ed 100644 --- a/lib/liboot-ce-j.a +++ b/lib/liboot-ce-j.a @@ -169,6 +169,6 @@ z64_disp = 0x8016B840 ; z64_ctxt = 0x801C9660 ; z64_game = z64_ctxt ; z64_link = 0x801DBBB0 ; -z64_cimg = 0x803B5000 ; z64_UseButton = 0x8038D9A4 ; +z64_cimg = 0x803B5000 ; z64_item_highlight_vram = 0x8082996C ; diff --git a/lib/liboot-gc-j.a b/lib/liboot-gc-j.a index 83582851..5b026854 100644 --- a/lib/liboot-gc-j.a +++ b/lib/liboot-gc-j.a @@ -169,6 +169,6 @@ z64_disp = 0x8016B840 ; z64_ctxt = 0x801C9660 ; z64_game = z64_ctxt ; z64_link = 0x801DBBB0 ; -z64_cimg = 0x803B5000 ; z64_UseButton = 0x8038D9A4 ; +z64_cimg = 0x803B5000 ; z64_item_highlight_vram = 0x8082999C ; diff --git a/lib/liboot-gc-u.a b/lib/liboot-gc-u.a index 1209f582..cdd1030d 100644 --- a/lib/liboot-gc-u.a +++ b/lib/liboot-gc-u.a @@ -169,6 +169,6 @@ z64_disp = 0x8016B840 ; z64_ctxt = 0x801C9660 ; z64_game = z64_ctxt ; z64_link = 0x801DBBB0 ; -z64_cimg = 0x803B5000 ; z64_UseButton = 0x8038D9A4 ; +z64_cimg = 0x803B5000 ; z64_item_highlight_vram = 0x8082997C ; diff --git a/lib/liboot-mq-j.a b/lib/liboot-mq-j.a index 6171eb01..25ed05a4 100644 --- a/lib/liboot-mq-j.a +++ b/lib/liboot-mq-j.a @@ -169,6 +169,6 @@ z64_disp = 0x8016B840 ; z64_ctxt = 0x801C9660 ; z64_game = z64_ctxt ; z64_link = 0x801DBBB0 ; -z64_cimg = 0x803B5000 ; z64_UseButton = 0x8038D9A4 ; +z64_cimg = 0x803B5000 ; z64_item_highlight_vram = 0x8082999C ; diff --git a/lib/liboot-mq-u.a b/lib/liboot-mq-u.a index e25de91b..94a17c40 100644 --- a/lib/liboot-mq-u.a +++ b/lib/liboot-mq-u.a @@ -120,7 +120,7 @@ z64_sfx_write_pos = 0x801033B0 ; z64_sfx_read_pos = 0x801033B4 ; z64_sfx_unk1 = 0x801033E4 ; z64_sfx_unk2 = 0x801033F0 ; -z64_sfx_unk3 = 0x801033F0 ; +z64_sfx_unk3 = 0x801033F8 ; z64_audio_cmd_write_pos = 0x80103400 ; z64_audio_cmd_read_pos = 0x80103404 ; z64_afx_cfg = 0x80103410 ; @@ -169,6 +169,6 @@ z64_disp = 0x8016B800 ; z64_ctxt = 0x801C9620 ; z64_game = z64_ctxt ; z64_link = 0x801DBB70 ; -z64_cimg = 0x803B5000 ; z64_UseButton = 0x8038D964 ; +z64_cimg = 0x803B5000 ; z64_item_highlight_vram = 0x8082997C ; diff --git a/src/gz/z64.h b/src/gz/z64.h index d26648aa..98c3f5f2 100644 --- a/src/gz/z64.h +++ b/src/gz/z64.h @@ -2272,7 +2272,7 @@ z64_extern uint8_t z64_sfx_write_pos; z64_extern uint8_t z64_sfx_read_pos; z64_extern z64_xyzf_t z64_sfx_unk1; z64_extern float z64_sfx_unk2; -z64_extern float z64_sfx_unk3; +z64_extern int8_t z64_sfx_unk3; z64_extern uint8_t z64_audio_cmd_write_pos; z64_extern uint8_t z64_audio_cmd_read_pos; z64_extern uint8_t z64_afx_cfg; @@ -2373,9 +2373,9 @@ void z64_ConfigureAfx (uint8_t cfg); uint32_t z64_AfxRand (void); void z64_OcarinaUpdate (void); void z64_ResetAudio (uint8_t cfg); -void z64_PlaySfx (uint16_t sfx, z64_xyzf_t *unk_00_, - int8_t unk_01_ , float *unk_02_, - float *unk_03_, float *unk_04_); +void z64_PlaySfx (uint16_t sfx, z64_xyzf_t *a1, + uint8_t a2, float *a3, + float *sp10, int8_t *sp14); int z64_CheckAfxConfigBusy (void); uint32_t z64_LoadOverlay (uint32_t vrom_start, uint32_t vrom_end, uint32_t vram_start, uint32_t vram_end,