Skip to content

Commit

Permalink
Merge pull request #35 from JCog/warp-fixes
Browse files Browse the repository at this point in the history
Prevent pause/battle menu warp crashes
  • Loading branch information
JCog committed May 29, 2022
2 parents d1ada6a + 5022774 commit 744b29b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
4 changes: 4 additions & 0 deletions lib/libpm-jp.a
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pm_SetCurtainScaleGoal = 0x8002BE9C;
pm_SetCurtainDrawCallback = 0x8002BEC4;
pm_SetCurtainFadeGoal = 0x8002BED4;
pm_SetGameMode = 0x80033180;
pm_state_step_end_battle = 0x80033850;
pm_RemoveEffect = 0x8005A100;
__osPiGetAccess = 0x80061474;
__osPiRelAccess = 0x800614E0;
Expand Down Expand Up @@ -38,13 +39,16 @@ pm_GameState = 0x8009A5E0;
nuGfxCfb_ptr = 0x8009A62C;
pm_MasterGfxPos = 0x8009A64C;
pm_save_info = 0x8009BA10;
pm_GameMode = 0x8009E700;
D_800A0900 = 0x8009E710;
pm_MapChangeState = 0x8009E754;
pm_encounter_status = 0x800B0EF0;
pm_enemy_defeat_flags = 0x800B0FA0;
pm_gCameras = 0x800B1D60;
pm_effects = 0x800B4378;
__osEventStateTab = 0x800D9F60;
pm_save_data = 0x800DACA0;
pm_battle_state = 0x800DC048;
pm_battle_status = 0x800DC050;
pm_battle_state_2 = 0x800DC4BC;
pm_disable_player_input = 0x800E0158;
Expand Down
4 changes: 4 additions & 0 deletions lib/libpm-us.a
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pm_SetCurtainScaleGoal = 0x8002BEDC;
pm_SetCurtainDrawCallback = 0x8002BF04;
pm_SetCurtainFadeGoal = 0x8002BF14;
pm_SetGameMode = 0x800334F0;
pm_state_step_end_battle = 0x80033BC0;
pm_RemoveEffect = 0x8005A450;
__osPiGetAccess = 0x800614A4;
__osPiRelAccess = 0x80061510;
Expand Down Expand Up @@ -38,13 +39,16 @@ pm_GameState = 0x8009A600;
nuGfxCfb_ptr = 0x8009A64C;
pm_MasterGfxPos = 0x8009A66C;
pm_save_info = 0x8009BA30;
pm_GameMode = 0x800A08F0;
D_800A0900 = 0x800A0900;
pm_MapChangeState = 0x800A0944;
pm_encounter_status = 0x800B0F10;
pm_enemy_defeat_flags = 0x800B0FC0;
pm_gCameras = 0x800B1D80;
pm_effects = 0x800B4398;
__osEventStateTab = 0x800D9F80;
pm_save_data = 0x800DACC0;
pm_battle_state = 0x800DC068;
pm_battle_status = 0x800DC070;
pm_battle_state_2 = 0x800DC4DC;
pm_disable_player_input = 0x800E0178;
Expand Down
37 changes: 23 additions & 14 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ void fp_set_input_mask(u16 pad, u8 x, u8 y) {
}

_Bool fp_warp(u16 area, u16 map, u16 entrance) {
if (pm_GameMode == 0xA || pm_GameMode == 0xB) { // paused/unpausing
fp_log("can't warp while paused");
return 0;
} else if ((pm_battle_state == 0xD &&
(pm_battle_state_2 == 0xC9 || pm_battle_state_2 == 0x1F || pm_battle_state_2 == 0x29 ||
pm_battle_state_2 == 0x2 || pm_battle_state_2 == 0x3D)) ||
(pm_battle_state == 0xE &&
(pm_battle_state_2 == 0xB || pm_battle_state_2 == 0xC9 || pm_battle_state_2 == 0x1F)) ||
pm_battle_state == 0x11) {
// these are all the states I can find that crash when you try to warp from battle. 0x11 is slight overkill,
// but the rest aren't. at some point we should figure out how to back out of these states automatically.
fp_log("can't warp in battle menu");
return 0;
} else if (pm_status.is_battle) {
D_800A0900 = 1;
pm_state_step_end_battle();
}

pm_PlayAmbientSounds(-1, 0); // clear ambient sounds
pm_BgmSetSong(1, -1, 0, 0, 8); // clear secondary songs
pm_SfxStopSound(0x19C); // clear upward vine sound
Expand All @@ -83,21 +101,12 @@ _Bool fp_warp(u16 area, u16 map, u16 entrance) {
pm_MapChangeState = 1;

PRINTF("***** WARP TRIGGERED *****\n");

if (pm_status.is_battle) {
if (pm_battle_state_2 == 0xC9) {
PRINTF("battle popup is open, destroying menu\n");
pm_func_802A472C();
}
fp.warp_delay = 0;
if (pm_popup_menu_var == 1) {
PRINTF("overworld popup is open, setting delay and hiding menu\n");
fp.warp_delay = 15;
pm_HidePopupMenu();
} else {
if (pm_popup_menu_var == 1) {
PRINTF("overworld popup is open, setting delay and hiding menu\n");
fp.warp_delay = 15;
pm_HidePopupMenu();
} else {
fp.warp_delay = 0;
}
fp.warp_delay = 0;
}

// set the global curtain to default+off state
Expand Down
4 changes: 4 additions & 0 deletions src/pm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ extern_data u32 *pm_IconScripts[337][2];
extern_data s32 pm_RandSeed;
extern_data EffectInstance *pm_effects[96];
extern_data save_data_ctxt_t pm_save_data;
extern_data s32 pm_battle_state;
extern_data s32 pm_battle_state_2;
extern_data battle_status_ctxt_t pm_battle_status;
extern_data s32 pm_popup_menu_var;
Expand All @@ -1023,6 +1024,8 @@ extern_data script_list_ctxt_t pm_curr_script_lst;
extern_data encounter_status_ctxt_t pm_encounter_status;
extern_data Camera pm_gCameras[4];
extern_data s32 pm_gCurrentCameraID;
extern_data s16 pm_GameMode;
extern_data s8 D_800A0900;

extern_data u16 *nuGfxCfb_ptr;
extern_data u32 osMemSize;
Expand Down Expand Up @@ -1074,6 +1077,7 @@ void update_camera_mode_6(Camera *camera);
void update_player_input(void);
s32 pm_is_ability_active(s32 arg0);
void set_screen_overlay_alpha(s32, f32);
void pm_state_step_end_battle(void);

/* Convenience Values */
#define STORY_PROGRESS pm_save_data.global_bytes[0]
Expand Down

0 comments on commit 744b29b

Please sign in to comment.