From 09e4c8e217129b9231807c63fca3d5fd79ebd5a6 Mon Sep 17 00:00:00 2001 From: LT-Schmiddy Date: Sun, 24 Nov 2024 16:37:23 -0500 Subject: [PATCH] Relocated reset code to allow reset any time, not just in-game. --- patches/game_patches.c | 43 ++++++++++++++++++++++++++++++++++++++++++ patches/game_patches.h | 10 ++++++++++ patches/play_patches.c | 13 ------------- patches/play_patches.h | 4 ---- 4 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 patches/game_patches.c create mode 100644 patches/game_patches.h diff --git a/patches/game_patches.c b/patches/game_patches.c new file mode 100644 index 0000000..76a8b34 --- /dev/null +++ b/patches/game_patches.c @@ -0,0 +1,43 @@ +#include "game_patches.h" +#include "global.h" +#include "audiomgr.h" +#include "idle.h" +#include "sys_cfb.h" +#include "libc64/malloc.h" +#include "z64debug_text.h" +#include "z64rumble.h" +#include "z64speed_meter.h" +#include "z64vimode.h" +#include "z64viscvg.h" +#include "z64vismono.h" +#include "z64viszbuf.h" +#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) { + GameState_Draw(gameState, gfxCtx); + GameState_DrawEnd(gfxCtx); + } +} + \ No newline at end of file diff --git a/patches/game_patches.h b/patches/game_patches.h new file mode 100644 index 0000000..c4c9d7d --- /dev/null +++ b/patches/game_patches.h @@ -0,0 +1,10 @@ +#ifndef __PLAY_PATCHES_H__ +#define __PLAY_PATCHES_H__ + +#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 4827e21..d706f86 100644 --- a/patches/play_patches.c +++ b/patches/play_patches.c @@ -40,24 +40,11 @@ void controls_play_update(PlayState* play) { gSaveContext.options.zTargetSetting = recomp_get_targeting_mode(); } -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; -} - // @recomp Patched to add hooks for various added functionality. 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); diff --git a/patches/play_patches.h b/patches/play_patches.h index cce59fb..7c88727 100644 --- a/patches/play_patches.h +++ b/patches/play_patches.h @@ -4,8 +4,6 @@ #include "patches.h" #include "patch_helpers.h" -DECLARE_FUNC(bool, recomp_should_reset_game); - void debug_play_update(PlayState* play); void camera_pre_play_update(PlayState* play); void camera_post_play_update(PlayState* play); @@ -14,6 +12,4 @@ void analog_cam_post_play_update(PlayState* play); void matrix_play_update(PlayState* play); void autosave_post_play_update(PlayState* play); - - #endif