summaryrefslogtreecommitdiff
path: root/include/load_save.h
diff options
context:
space:
mode:
authorGriffinR <griffin.g.richards@gmail.com>2021-11-13 23:25:29 -0500
committerGitHub <noreply@github.com>2021-11-13 23:25:29 -0500
commit8d18d03c791c40bad532c62f217b0f82aadec6d2 (patch)
tree44e6d447e57941a77623253884304c3174b72886 /include/load_save.h
parent9a932cd9c3089c03adada30ace4c79a84bf73cf0 (diff)
parent159bb37bbe9d960f0d2a3da9736e1be5eefb8290 (diff)
Merge pull request #1552 from ProjectRevoTPP/fix_saveblock_reorder
Enforce structs to enforce save block order for modern toolchains.
Diffstat (limited to 'include/load_save.h')
-rw-r--r--include/load_save.h30
1 files changed, 27 insertions, 3 deletions
diff --git a/include/load_save.h b/include/load_save.h
index 14a979b45..309e62e2b 100644
--- a/include/load_save.h
+++ b/include/load_save.h
@@ -1,9 +1,33 @@
#ifndef GUARD_LOAD_SAVE_H
#define GUARD_LOAD_SAVE_H
-extern struct SaveBlock1 gSaveblock1;
-extern struct SaveBlock2 gSaveblock2;
-extern struct PokemonStorage gPokemonStorage;
+#include "pokemon_storage_system.h"
+
+#define SAVEBLOCK_MOVE_RANGE 128
+
+/**
+ * These structs are to prevent them from being reordered on newer or modern
+ * toolchains. If this is not done, the ClearSav functions will end up erasing
+ * the wrong memory leading to various glitches.
+ */
+struct SaveBlock2DMA {
+ struct SaveBlock2 block;
+ u8 dma[SAVEBLOCK_MOVE_RANGE];
+};
+
+struct SaveBlock1DMA {
+ struct SaveBlock1 block;
+ u8 dma[SAVEBLOCK_MOVE_RANGE];
+};
+
+struct PokemonStorageDMA {
+ struct PokemonStorage block;
+ u8 dma[SAVEBLOCK_MOVE_RANGE];
+};
+
+extern struct SaveBlock1DMA gSaveblock1;
+extern struct SaveBlock2DMA gSaveblock2;
+extern struct PokemonStorageDMA gPokemonStorage;
extern bool32 gFlashMemoryPresent;
extern struct SaveBlock1 *gSaveBlock1Ptr;