Skip to content

Commit

Permalink
Add SaveButtonIndex enum, use in z_game_over as an example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragorn421 committed May 16, 2022
1 parent d4b6b31 commit a49bc09
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
17 changes: 14 additions & 3 deletions include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@
#include "ultra64.h"
#include "z64math.h"

/**
* Indices into `ItemEquips.buttonItems` and `SaveContext.buttonStatus`
*/
typedef enum {
/* 0 */ SAVE_BUTTON_INDEX_B,
/* 1 */ SAVE_BUTTON_INDEX_C_LEFT,
/* 2 */ SAVE_BUTTON_INDEX_C_DOWN,
/* 3 */ SAVE_BUTTON_INDEX_C_RIGHT,
/* 4 */ SAVE_BUTTON_INDEX_A // A is only for `SaveContext.buttonStatus`
} SaveButtonIndex;

typedef struct {
/* 0x00 */ u8 buttonItems[4];
/* 0x04 */ u8 cButtonSlots[3];
/* 0x00 */ u8 buttonItems[4]; // B, C-Left, C-Down, C-Right
/* 0x04 */ u8 cButtonSlots[3]; // C-Left, C-Down, C-Right
/* 0x08 */ u16 equipment; // a mask where each nibble corresponds to a type of equipment `EquipmentType`, and each nibble is a piece `EquipValue*`
} ItemEquips; // size = 0x0A

Expand Down Expand Up @@ -137,7 +148,7 @@ typedef struct {
/* 0x13DE */ char unk_13DE[0x0002];
/* 0x13E0 */ u8 seqId;
/* 0x13E1 */ u8 natureAmbienceId;
/* 0x13E2 */ u8 buttonStatus[5];
/* 0x13E2 */ u8 buttonStatus[5]; // B, C-Left, C-Down, C-Right, A
/* 0x13E7 */ u8 unk_13E7; // alpha related
/* 0x13E8 */ u16 unk_13E8; // alpha type?
/* 0x13EA */ u16 unk_13EA; // also alpha type?
Expand Down
25 changes: 14 additions & 11 deletions src/code/z_game_over.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void GameOver_Update(GlobalContext* globalCtx) {
INV_CONTENT(gSpoilingItemReverts[i]) = gSpoilingItemReverts[i];

// search c buttons for the found spoiling item and revert if necessary
for (j = 1; j < ARRAY_COUNT(gSaveContext.equips.buttonItems); j++) {
for (j = SAVE_BUTTON_INDEX_C_LEFT; j <= SAVE_BUTTON_INDEX_C_RIGHT; j++) {
if (gSaveContext.equips.buttonItems[j] == gSpoilingItems[i]) {
gSaveContext.equips.buttonItems[j] = gSpoilingItemReverts[i];
Interface_LoadItemIcon1(globalCtx, j);
Expand All @@ -48,15 +48,16 @@ void GameOver_Update(GlobalContext* globalCtx) {
}

// restore "temporary B" to the B Button if not a sword item
if (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KOKIRI &&
gSaveContext.equips.buttonItems[0] != ITEM_SWORD_MASTER &&
gSaveContext.equips.buttonItems[0] != ITEM_SWORD_BGS &&
gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KNIFE) {

if (gSaveContext.buttonStatus[0] != BTN_ENABLED) {
gSaveContext.equips.buttonItems[0] = gSaveContext.buttonStatus[0];
if (gSaveContext.equips.buttonItems[SAVE_BUTTON_INDEX_B] != ITEM_SWORD_KOKIRI &&
gSaveContext.equips.buttonItems[SAVE_BUTTON_INDEX_B] != ITEM_SWORD_MASTER &&
gSaveContext.equips.buttonItems[SAVE_BUTTON_INDEX_B] != ITEM_SWORD_BGS &&
gSaveContext.equips.buttonItems[SAVE_BUTTON_INDEX_B] != ITEM_SWORD_KNIFE) {

if (gSaveContext.buttonStatus[SAVE_BUTTON_INDEX_B] != BTN_ENABLED) {
gSaveContext.equips.buttonItems[SAVE_BUTTON_INDEX_B] =
gSaveContext.buttonStatus[SAVE_BUTTON_INDEX_B];
} else {
gSaveContext.equips.buttonItems[0] = ITEM_NONE;
gSaveContext.equips.buttonItems[SAVE_BUTTON_INDEX_B] = ITEM_NONE;
}
}

Expand All @@ -68,8 +69,10 @@ void GameOver_Update(GlobalContext* globalCtx) {
gSaveContext.eventInf[1] = 0;
gSaveContext.eventInf[2] = 0;
gSaveContext.eventInf[3] = 0;
gSaveContext.buttonStatus[0] = gSaveContext.buttonStatus[1] = gSaveContext.buttonStatus[2] =
gSaveContext.buttonStatus[3] = gSaveContext.buttonStatus[4] = BTN_ENABLED;
gSaveContext.buttonStatus[SAVE_BUTTON_INDEX_B] = gSaveContext.buttonStatus[SAVE_BUTTON_INDEX_C_LEFT] =
gSaveContext.buttonStatus[SAVE_BUTTON_INDEX_C_DOWN] =
gSaveContext.buttonStatus[SAVE_BUTTON_INDEX_C_RIGHT] =
gSaveContext.buttonStatus[SAVE_BUTTON_INDEX_A] = BTN_ENABLED;
gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = 0;

Environment_InitGameOverLights(globalCtx);
Expand Down

0 comments on commit a49bc09

Please sign in to comment.