diff --git a/patches/gamestate_patches.c b/patches/gamestate_patches.c index 93058ba..c24c2a1 100644 --- a/patches/gamestate_patches.c +++ b/patches/gamestate_patches.c @@ -14,25 +14,12 @@ #include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h" #include "debug.h" -void do_reset_game(GameState* this) { - PlayState* play = (PlayState*)this; - gSaveContext.gameMode = GAMEMODE_OWL_SAVE; - play->transitionTrigger = TRANS_TRIGGER_START; - play->transitionType = TRANS_TYPE_FADE_BLACK; - play->nextEntrance = ENTRANCE(CUTSCENE, 0); - gSaveContext.save.cutsceneIndex = 0; - gSaveContext.sceneLayer = 0; -} RECOMP_PATCH void GameState_Update(GameState* gameState) { GraphicsContext* gfxCtx = gameState->gfxCtx; GameState_SetFrameBuffer(gameState->gfxCtx); - if (recomp_should_reset_game()) { - do_reset_game(gameState); - } - gameState->main(gameState); if (R_PAUSE_BG_PRERENDER_STATE != PAUSE_BG_PRERENDER_PROCESS) { diff --git a/patches/gamestate_patches.h b/patches/gamestate_patches.h index c4c9d7d..23bcef1 100644 --- a/patches/gamestate_patches.h +++ b/patches/gamestate_patches.h @@ -4,7 +4,5 @@ #include "patches.h" #include "patch_helpers.h" -DECLARE_FUNC(bool, recomp_should_reset_game); - #endif diff --git a/patches/play_patches.c b/patches/play_patches.c index f061160..27cbfee 100644 --- a/patches/play_patches.c +++ b/patches/play_patches.c @@ -33,6 +33,15 @@ RECOMP_DECLARE_EVENT(recomp_on_play_main(PlayState* play)); RECOMP_DECLARE_EVENT(recomp_on_play_update(PlayState* play)); RECOMP_DECLARE_EVENT(recomp_after_play_update(PlayState* play)); +void do_reset_game(PlayState* play) { + gSaveContext.gameMode = GAMEMODE_OWL_SAVE; + play->transitionTrigger = TRANS_TRIGGER_START; + play->transitionType = TRANS_TYPE_FADE_BLACK; + play->nextEntrance = ENTRANCE(CUTSCENE, 0); + gSaveContext.save.cutsceneIndex = 0; + gSaveContext.sceneLayer = 0; +} + void controls_play_update(PlayState* play) { gSaveContext.options.zTargetSetting = recomp_get_targeting_mode(); } @@ -41,6 +50,11 @@ void controls_play_update(PlayState* play) { RECOMP_PATCH void Play_Main(GameState* thisx) { static Input* prevInput = NULL; PlayState* this = (PlayState*)thisx; + + if (recomp_should_reset_game()) { + do_reset_game(this); + } + // @recomp_event recomp_on_play_main(PlayState* play): Allow mods to execute code every frame. recomp_on_play_main(this); @@ -177,6 +191,7 @@ RECOMP_PATCH void Play_Init(GameState* thisx) { recomp_on_play_init(this); recomp_set_reset_button_visibility(1); + if ((gSaveContext.respawnFlag == -4) || (gSaveContext.respawnFlag == -0x63)) { if (CHECK_EVENTINF(EVENTINF_TRIGGER_DAYTELOP)) { CLEAR_EVENTINF(EVENTINF_TRIGGER_DAYTELOP); @@ -444,9 +459,11 @@ RECOMP_PATCH void Play_Init(GameState* thisx) { recomp_after_play_init(this); } + void Play_ClearTransition(PlayState* this); void Play_DestroyMotionBlur(void); void ZeldaArena_Cleanup(); + RECOMP_PATCH void Play_Destroy(GameState* thisx) { PlayState* this = (PlayState*)thisx; GraphicsContext* gfxCtx = this->state.gfxCtx; diff --git a/patches/play_patches.h b/patches/play_patches.h index cce4a4d..5cd51b9 100644 --- a/patches/play_patches.h +++ b/patches/play_patches.h @@ -13,5 +13,6 @@ void matrix_play_update(PlayState* play); void autosave_post_play_update(PlayState* play); DECLARE_FUNC(void, recomp_set_reset_button_visibility, u8 visibility); +DECLARE_FUNC(bool, recomp_should_reset_game); #endif diff --git a/src/game/recomp_api.cpp b/src/game/recomp_api.cpp index a0c1c6b..c295b02 100644 --- a/src/game/recomp_api.cpp +++ b/src/game/recomp_api.cpp @@ -175,14 +175,12 @@ extern "C" void recomp_set_right_analog_suppressed(uint8_t* rdram, recomp_contex recomp::set_right_analog_suppressed(suppressed); } - extern "C" void recomp_should_reset_game(uint8_t* rdram, recomp_context* ctx) { _return(ctx, should_game_reset.exchange(0x00)); } extern "C" void recomp_set_reset_button_visibility(uint8_t* rdram, recomp_context* ctx) { uint8_t storeVal = _arg<0, uint8_t>(rdram, ctx); - std::cout << "Reset Button Visibility: " << std::to_string(storeVal) << "\n"; zelda64::set_reset_button_visibility((bool)storeVal); } \ No newline at end of file diff --git a/src/ui/ui_config.cpp b/src/ui/ui_config.cpp index 43b777e..5eb6ce9 100644 --- a/src/ui/ui_config.cpp +++ b/src/ui/ui_config.cpp @@ -1,3 +1,4 @@ +#include #include "recomp_ui.h" #include "recomp_input.h" #include "zelda_sound.h" @@ -1049,10 +1050,11 @@ public: throw std::runtime_error("Failed to make RmlUi data model for the game reset button"); } - // Bind the debug mode enabled flag. - + // Bind the reset button visibility flag. reset_game_model_handle = constructor.GetModelHandle(); + // Ensuring the flag is set to false on startup. + reset_game_context.reset_button_visibility.store(false); bind_atomic(constructor, reset_game_model_handle, "reset_button_visibility", &reset_game_context.reset_button_visibility); } diff --git a/src/ui/ui_renderer.cpp b/src/ui/ui_renderer.cpp index 7045e04..14f57ca 100644 --- a/src/ui/ui_renderer.cpp +++ b/src/ui/ui_renderer.cpp @@ -2,7 +2,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include #include #include #ifdef _WIN32 @@ -16,7 +15,6 @@ #include "recomp_input.h" #include "librecomp/game.hpp" #include "zelda_config.h" -#include "zelda_game.h" #include "ui_rml_hacks.hpp" #include "concurrentqueue.h"