Skip to content

Commit

Permalink
Fix regression for state version <4, reorder commands, simplify condi…
Browse files Browse the repository at this point in the history
…tions, formatting
  • Loading branch information
glankk committed Jan 12, 2023
1 parent 4e73cfc commit 8298604
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 72 deletions.
12 changes: 6 additions & 6 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/gz/gz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
105 changes: 54 additions & 51 deletions src/gz/gz_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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()
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions src/gz/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/gz/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -88,9 +91,6 @@ enum commands
COMMAND_STARTTIMER,
COMMAND_STOPTIMER,
COMMAND_RESET,
COMMAND_EQUIP_IRONS,
COMMAND_EQUIP_HOVERS,
COMMAND_USE_OCARINA,
COMMAND_MAX,
};

Expand Down
2 changes: 1 addition & 1 deletion src/gz/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions src/gz/z64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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

0 comments on commit 8298604

Please sign in to comment.