summaryrefslogtreecommitdiff
path: root/src/reload_save.c
diff options
context:
space:
mode:
authorGriffinR <griffin.g.richards@gmail.com>2021-10-15 22:44:01 -0400
committerGitHub <noreply@github.com>2021-10-15 22:44:01 -0400
commita4a3c1c9e5a0026415330eab9bea2f8f3e83e0a3 (patch)
treea4a2a111096ba65ccd8d855b3af936f680f9634f /src/reload_save.c
parent187f10be9d8a08e348a7cfee1d5b0d8fee861859 (diff)
parent3a7995bc7ce8fda6a763ab14f96a2011f735def6 (diff)
Merge pull request #1511 from GriffinRichards/doc-union
Document link_rfu / Union Room
Diffstat (limited to 'src/reload_save.c')
-rw-r--r--src/reload_save.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/reload_save.c b/src/reload_save.c
new file mode 100644
index 000000000..cdbb2f227
--- /dev/null
+++ b/src/reload_save.c
@@ -0,0 +1,30 @@
+#include "global.h"
+#include "main.h"
+#include "gpu_regs.h"
+#include "m4a.h"
+#include "load_save.h"
+#include "save.h"
+#include "new_game.h"
+#include "overworld.h"
+#include "malloc.h"
+
+// Reloads the game, continuing from the point of the last save
+// Used to gracefully exit after a link connection error
+void ReloadSave(void)
+{
+ u16 imeBackup = REG_IME;
+ REG_IME = 0;
+ RegisterRamReset(RESET_EWRAM);
+ ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_FORCED_BLANK);
+ REG_IME = imeBackup;
+ gMain.inBattle = FALSE;
+ SetSaveBlocksPointers(GetSaveBlocksPointersBaseOffset());
+ ResetMenuAndMonGlobals();
+ Save_ResetSaveCounters();
+ Save_LoadGameData(SAVE_NORMAL);
+ if (gSaveFileStatus == SAVE_STATUS_EMPTY || gSaveFileStatus == SAVE_STATUS_CORRUPT)
+ Sav2_ClearSetDefault();
+ SetPokemonCryStereo(gSaveBlock2Ptr->optionsSound);
+ InitHeap(gHeap, HEAP_SIZE);
+ SetMainCallback2(CB2_ContinueSavedGame);
+}