Skip to content

Commit

Permalink
Address PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshDuMan committed Sep 15, 2023
1 parent 384e7d1 commit 6eb9cff
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 58 deletions.
53 changes: 31 additions & 22 deletions src/game_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@ s32 D_80077420[] = {
// These GameModeStub are used as the struct GameMode. As GameModeStub is 0x14 long and GameMode is 0x18 long, the last element
// and first element of the next struct are shared in data.

typedef struct GameModeStub {
/* 0x00 */ u16 flags;
/* 0x04 */ void (*init)(void);
/* 0x08 */ void (*step)(void);
/* 0x0C */ UNK_FUN_PTR(unusedFunc);
/* 0x10 */ void (*render)(void);
#ifdef AVOID_UB
/* 0x14 */ void (*renderAux)(void); ///< @see state_render_frontUI
#endif
} GameModeStub; // size = 0x14

GameModeStub GameModeStartup = {
0,
MODE_FLAG_NONE,
state_init_startup,
state_step_startup,
NULL,
Expand All @@ -38,7 +49,7 @@ GameModeStub GameModeStartup = {
};

GameModeStub GameModeLogos = {
0,
MODE_FLAG_NONE,
state_init_logos,
state_step_logos,
NULL,
Expand All @@ -49,7 +60,7 @@ GameModeStub GameModeLogos = {
};

GameModeStub GameModeTitleScreen = {
0,
MODE_FLAG_NONE,
state_init_title_screen,
state_step_title_screen,
NULL,
Expand All @@ -60,7 +71,7 @@ GameModeStub GameModeTitleScreen = {
};

GameModeStub GameModeEnterDemoWorld = {
0,
MODE_FLAG_NONE,
state_init_enter_demo,
state_step_enter_world,
NULL,
Expand All @@ -71,7 +82,7 @@ GameModeStub GameModeEnterDemoWorld = {
};

GameModeStub GameModeChangeMap = {
0,
MODE_FLAG_NONE,
state_init_change_map,
state_step_change_map,
NULL,
Expand All @@ -82,7 +93,7 @@ GameModeStub GameModeChangeMap = {
};

GameModeStub GameModeGameOver = {
0,
MODE_FLAG_NONE,
state_init_game_over,
state_step_game_over,
NULL,
Expand All @@ -93,7 +104,7 @@ GameModeStub GameModeGameOver = {
};

GameModeStub GameModeEnterWorld = {
0,
MODE_FLAG_NONE,
state_init_enter_world,
state_step_enter_world,
NULL,
Expand All @@ -104,7 +115,7 @@ GameModeStub GameModeEnterWorld = {
};

GameModeStub GameModeWorld = {
0,
MODE_FLAG_NONE,
state_init_world,
state_step_world,
NULL,
Expand All @@ -115,7 +126,7 @@ GameModeStub GameModeWorld = {
};

GameModeStub GameModeBattle = {
0,
MODE_FLAG_NONE,
state_init_battle,
state_step_battle,
NULL,
Expand All @@ -126,7 +137,7 @@ GameModeStub GameModeBattle = {
};

GameModeStub GameModeEndBattle = {
0,
MODE_FLAG_NONE,
state_init_end_battle,
state_step_end_battle,
NULL,
Expand All @@ -137,7 +148,7 @@ GameModeStub GameModeEndBattle = {
};

GameModeStub GameModePause = {
0,
MODE_FLAG_NONE,
state_init_pause,
state_step_pause,
NULL,
Expand All @@ -148,7 +159,7 @@ GameModeStub GameModePause = {
};

GameModeStub GameModeUnpause = {
0,
MODE_FLAG_NONE,
state_init_unpause,
state_step_unpause,
NULL,
Expand All @@ -159,7 +170,7 @@ GameModeStub GameModeUnpause = {
};

GameModeStub GameModeLanguageSelect = {
0,
MODE_FLAG_NONE,
state_init_language_select,
state_step_language_select,
NULL,
Expand All @@ -170,7 +181,7 @@ GameModeStub GameModeLanguageSelect = {
};

GameModeStub GameModeEndLanguageSelect = {
0,
MODE_FLAG_NONE,
state_init_exit_language_select,
state_step_exit_language_select,
NULL,
Expand All @@ -181,7 +192,7 @@ GameModeStub GameModeEndLanguageSelect = {
};

GameModeStub GameModeFileSelect = {
0,
MODE_FLAG_NONE,
state_init_file_select,
state_step_file_select,
NULL,
Expand All @@ -203,7 +214,7 @@ GameModeStub GameModeEndFileSelect = {
};

GameModeStub GameModeIntro = {
0,
MODE_FLAG_NONE,
state_init_intro,
state_step_intro,
NULL,
Expand All @@ -214,7 +225,7 @@ GameModeStub GameModeIntro = {
};

GameModeStub GameModeDemo = {
0,
MODE_FLAG_NONE,
state_init_demo,
state_step_demo,
NULL,
Expand Down Expand Up @@ -243,17 +254,15 @@ GameMode* gameModeMap[] = {
(GameMode*) &GameModeEndFileSelect,
(GameMode*) &GameModeIntro,
(GameMode*) &GameModeDemo,
NULL,
NULL,
};

SHIFT_BSS s16 activeGameMode;
SHIFT_BSS s16 CurGameMode;

void set_game_mode(s16 mode) {
activeGameMode = mode;
CurGameMode = mode;
set_game_mode_slot(0, gameModeMap[mode]);
}

s16 get_game_mode(void) {
return activeGameMode;
return CurGameMode;
}
19 changes: 3 additions & 16 deletions src/game_modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ enum GameModeFlags {
MODE_FLAG_NONE = 0,
MODE_FLAG_INITIALIZED = (1 << 0), // Set when the mod is initialized
MODE_FLAG_STEP_NOT_DONE = (1 << 1), // Turned off after the first step is done
MODE_FLAG_3 = (1 << 2),
MODE_FLAG_4 = (1 << 3),
MODE_FLAG_5 = (1 << 4),
MODE_FLAG_4 = (1 << 2),
MODE_FLAG_8 = (1 << 3),
MODE_FLAG_10 = (1 << 4),
MODE_FLAG_RENDER_AUX_SET = (1 << 5), // Set when the renderAux function is set
};

Expand All @@ -35,19 +35,6 @@ enum GameModeIDs {
GAME_MODE_DEMO = 17,
};

// GameModeStub are treated as GameMode structs, which creates UB behavior as
// renderAux accesses are outside the range of the struct.
typedef struct GameModeStub {
/* 0x00 */ u16 flags;
/* 0x04 */ void (*init)(void);
/* 0x08 */ void (*step)(void);
/* 0x0C */ UNK_FUN_PTR(unusedFunc);
/* 0x10 */ void (*render)(void);
#ifdef AVOID_UB
/* 0x14 */ void (*renderAux)(void); ///< @see state_render_frontUI
#endif
} GameModeStub; // size = 0x14

typedef struct GameMode {
/* 0x00 */ u16 flags;
/* 0x04 */ void (*init)(void);
Expand Down
34 changes: 17 additions & 17 deletions src/game_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,24 @@ void game_mode_set_fpDrawAuxUI(s32 i, void (*fn)(void)) {
}

// Unused
void set_game_mode_flag_3(s32 i) {
gMainGameMode[i].flags |= MODE_FLAG_3;
void set_game_mode_flag_4(s32 i) {
gMainGameMode[i].flags |= MODE_FLAG_4;
}

// Unused
void set_game_mode_flag_4(s32 i) {
gMainGameMode[i].flags |= MODE_FLAG_4;
void set_game_mode_flag_8(s32 i) {
gMainGameMode[i].flags |= MODE_FLAG_8;
}

// Unused
void clear_game_mode_unk_flags(s32 i) {
gMainGameMode[i].flags &= ~(MODE_FLAG_3|MODE_FLAG_4|MODE_FLAG_5);
gMainGameMode[i].flags &= ~(MODE_FLAG_4 | MODE_FLAG_8 | MODE_FLAG_10);
}

// Unused
void set_game_mode_flag_5(s32 i) {
gMainGameMode[i].flags &= ~(MODE_FLAG_3|MODE_FLAG_4);
gMainGameMode[i].flags |= MODE_FLAG_5;
void set_game_mode_flag_10(s32 i) {
gMainGameMode[i].flags &= ~(MODE_FLAG_4 | MODE_FLAG_8);
gMainGameMode[i].flags |= MODE_FLAG_10;
}

void step_current_game_mode(void) {
Expand All @@ -115,8 +115,8 @@ void step_current_game_mode(void) {

for (i = 0; i < ARRAY_COUNT(gMainGameMode); i++, gameMode++) {
if (gameMode->flags != MODE_FLAG_NONE) {
if (!(gameMode->flags & MODE_FLAG_3)) {
if (!(gameMode->flags & MODE_FLAG_4)) {
if (!(gameMode->flags & MODE_FLAG_4)) {
if (!(gameMode->flags & MODE_FLAG_8)) {
gameMode->flags &= ~MODE_FLAG_STEP_NOT_DONE;
gameMode->step();
}
Expand All @@ -132,8 +132,8 @@ void state_do_unk(void) {

for (i = 0; i < ARRAY_COUNT(gMainGameMode); i++, gameMode++) {
if (gameMode->flags != MODE_FLAG_NONE) {
if (!(gameMode->flags & MODE_FLAG_3)) {
if (!(gameMode->flags & MODE_FLAG_5)) {
if (!(gameMode->flags & MODE_FLAG_4)) {
if (!(gameMode->flags & MODE_FLAG_10)) {
gameMode->unusedFunc();
}
}
Expand All @@ -147,8 +147,8 @@ void state_render_backUI(void) {

for (i = 0; i < ARRAY_COUNT(gMainGameMode); i++, gameMode++) {
if (gameMode->flags != MODE_FLAG_NONE) {
if (!(gameMode->flags & MODE_FLAG_3)) {
if (!(gameMode->flags & MODE_FLAG_5)) {
if (!(gameMode->flags & MODE_FLAG_4)) {
if (!(gameMode->flags & MODE_FLAG_10)) {
gameMode->render();
}
}
Expand All @@ -162,7 +162,7 @@ void state_render_frontUI(void) {

for (i = 0; i < ARRAY_COUNT(gMainGameMode); i++, gameMode++) {
if (gameMode->flags != MODE_FLAG_NONE) {
if (!(gameMode->flags & MODE_FLAG_3)) {
if (!(gameMode->flags & MODE_FLAG_4)) {
if (!(gameMode->flags & MODE_FLAG_STEP_NOT_DONE)) {
if (gameMode->flags & MODE_FLAG_RENDER_AUX_SET) {
gameMode->renderAux();
Expand All @@ -176,9 +176,9 @@ void state_render_frontUI(void) {
gameMode = &gMainGameMode[0];
for (i = 0; i < ARRAY_COUNT(gMainGameMode); i++, gameMode++) {
if (gameMode->flags != MODE_FLAG_NONE) {
if (!(gameMode->flags & MODE_FLAG_3)) {
if (!(gameMode->flags & MODE_FLAG_4)) {
if (!(gameMode->flags & MODE_FLAG_STEP_NOT_DONE)) {
if (gameMode->flags & MODE_FLAG_5) {
if (gameMode->flags & MODE_FLAG_10) {
gameMode->render();
}
}
Expand Down
2 changes: 1 addition & 1 deletion ver/ique/asm/bss.s
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ dlabel D_800A08E8
dlabel D_800A08EC
.space 4

dlabel activeGameMode
dlabel CurGameMode
.space 4

dlabel D_800A08F4
Expand Down
2 changes: 1 addition & 1 deletion ver/jp/asm/main.bss.s
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ dlabel D_800A08E8
dlabel D_800A08EC
.space 4

dlabel activeGameMode
dlabel CurGameMode
.space 0x00000010

dlabel D_800A0900
Expand Down
2 changes: 1 addition & 1 deletion ver/us/asm/bss.s
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ dlabel D_800A08E8
dlabel D_800A08EC
.space 4

dlabel activeGameMode
dlabel CurGameMode
.space 4

dlabel D_800A08F4
Expand Down

0 comments on commit 6eb9cff

Please sign in to comment.