Avoid auto saving in file select (#6298)

This commit is contained in:
Philip Dubé
2026-02-28 00:48:34 +00:00
committed by GitHub
parent 5a7bc9a459
commit d46bfd9716
2 changed files with 5 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ extern PlayState* gPlayState;
#include "variables.h"
}
static uint64_t lastSaveTimestamp = GetUnixTimestamp();
static uint64_t lastSaveTimestamp;
#define CVAR_AUTOSAVE_NAME CVAR_ENHANCEMENT("Autosave")
#define CVAR_AUTOSAVE_DEFAULT AUTOSAVE_OFF
@@ -24,13 +24,12 @@ typedef enum {
} AutosaveOptions;
static bool Autosave_CanSave() {
// Don't save when in title screen or debug file
// Don't save a file that doesn't exist (e.g. it was deleted on death by user option)
// Don't save the first 60 frames to not save the magic meter when it's still in the animation of filling it.
// Don't save in Chamber of Sages and the Cutscene map because of remember save location and cutscene item gives.
// Don't save between obtaining Ocarina of Time and Song of Time because the latter would become unobtainable.
if (!SaveManager::Instance->SaveFile_Exist(gSaveContext.fileNum) || !GameInteractor::IsSaveLoaded(false) ||
if (!GameInteractor::IsSaveLoaded(false) || !SaveManager::Instance->SaveFile_Exist(gSaveContext.fileNum) ||
gPlayState->gameplayFrames < 60 || gPlayState->sceneNum == SCENE_CHAMBER_OF_THE_SAGES ||
gPlayState->sceneNum == SCENE_CUTSCENE_MAP ||
(!CHECK_QUEST_ITEM(QUEST_SONG_TIME) && (INV_CONTENT(ITEM_OCARINA_TIME) == ITEM_OCARINA_TIME))) {
@@ -63,7 +62,6 @@ static void Autosave_IntervalSave() {
// rupees draining after buying an item. Since the interval can just retry until it
// passes, it can use more conditions without hampering the player experience.
if (Autosave_CanSave() && !GameInteractor::IsGameplayPaused()) {
// Reset timestamp, set icon timer to show autosave icon for 5 seconds (100 frames)
lastSaveTimestamp = currentTimestamp;
@@ -78,6 +76,8 @@ static void Autosave_SoftResetSave() {
}
static void RegisterAutosave() {
COND_HOOK(GameInteractor::OnLoadGame, CVAR_AUTOSAVE_VALUE,
[](uint32_t fileNme) { lastSaveTimestamp = GetUnixTimestamp(); });
COND_HOOK(GameInteractor::OnGameFrameUpdate, CVAR_AUTOSAVE_VALUE, Autosave_IntervalSave);
COND_HOOK(GameInteractor::OnExitGame, CVAR_AUTOSAVE_VALUE, [](int32_t fileNum) { Autosave_SoftResetSave(); });
}

View File

@@ -1334,9 +1334,7 @@ void SaveManager::ThreadPoolWait() {
bool SaveManager::SaveFile_Exist(int fileNum) {
try {
bool exists = std::filesystem::exists(GetFileName(fileNum));
SPDLOG_INFO("File[{}] - {}", fileNum, exists ? "exists" : "does not exist");
return exists;
return std::filesystem::exists(GetFileName(fileNum));
} catch (std::filesystem::filesystem_error const& ex) {
SPDLOG_ERROR("Filesystem error");
return false;