mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2025-01-27 05:43:51 +01:00
Merge pull request #1668 from mrgriffin/static-assert-save-structs
Static assertion for size of save structs
This commit is contained in:
commit
b59fb7637a
@ -135,6 +135,10 @@
|
|||||||
#define NUM_FLAG_BYTES ROUND_BITS_TO_BYTES(FLAGS_COUNT)
|
#define NUM_FLAG_BYTES ROUND_BITS_TO_BYTES(FLAGS_COUNT)
|
||||||
#define NUM_ADDITIONAL_PHRASE_BYTES ROUND_BITS_TO_BYTES(NUM_ADDITIONAL_PHRASES)
|
#define NUM_ADDITIONAL_PHRASE_BYTES ROUND_BITS_TO_BYTES(NUM_ADDITIONAL_PHRASES)
|
||||||
|
|
||||||
|
// This produces an error at compile-time if expr is zero.
|
||||||
|
// It looks like file.c:line: size of array `id' is negative
|
||||||
|
#define STATIC_ASSERT(expr, id) typedef char id[(expr) ? 1 : -1];
|
||||||
|
|
||||||
struct Coords8
|
struct Coords8
|
||||||
{
|
{
|
||||||
s8 x;
|
s8 x;
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include "constants/items.h"
|
#include "constants/items.h"
|
||||||
#include "constants/trainer_hill.h"
|
#include "constants/trainer_hill.h"
|
||||||
|
|
||||||
|
STATIC_ASSERT(sizeof(struct TrainerHillChallenge) <= SECTOR_DATA_SIZE, TrainerHillChallengeFreeSpace);
|
||||||
|
|
||||||
struct SendRecvMgr
|
struct SendRecvMgr
|
||||||
{
|
{
|
||||||
bool8 isParent;
|
bool8 isParent;
|
||||||
|
@ -52,6 +52,8 @@ struct HallofFameTeam
|
|||||||
struct HallofFameMon mon[PARTY_SIZE];
|
struct HallofFameMon mon[PARTY_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
STATIC_ASSERT(sizeof(struct HallofFameTeam) * HALL_OF_FAME_MAX_TEAMS <= SECTOR_DATA_SIZE * NUM_HOF_SECTORS, HallOfFameFreeSpace);
|
||||||
|
|
||||||
struct HofGfx
|
struct HofGfx
|
||||||
{
|
{
|
||||||
u16 state;
|
u16 state;
|
||||||
|
@ -67,6 +67,8 @@ struct RecordedBattleSave
|
|||||||
u32 checksum;
|
u32 checksum;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
STATIC_ASSERT(sizeof(struct RecordedBattleSave) <= SECTOR_DATA_SIZE, RecordedBattleSaveFreeSpace);
|
||||||
|
|
||||||
EWRAM_DATA u32 gRecordedBattleRngSeed = 0;
|
EWRAM_DATA u32 gRecordedBattleRngSeed = 0;
|
||||||
EWRAM_DATA u32 gBattlePalaceMoveSelectionRngValue = 0;
|
EWRAM_DATA u32 gBattlePalaceMoveSelectionRngValue = 0;
|
||||||
EWRAM_DATA static u8 sBattleRecords[MAX_BATTLERS_COUNT][BATTLER_RECORD_SIZE] = {0};
|
EWRAM_DATA static u8 sBattleRecords[MAX_BATTLERS_COUNT][BATTLER_RECORD_SIZE] = {0};
|
||||||
|
@ -73,6 +73,12 @@ struct
|
|||||||
SAVEBLOCK_CHUNK(struct PokemonStorage, 8), // SECTOR_ID_PKMN_STORAGE_END
|
SAVEBLOCK_CHUNK(struct PokemonStorage, 8), // SECTOR_ID_PKMN_STORAGE_END
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// These will produce an error if a save struct is larger than the space
|
||||||
|
// alloted for it in the flash.
|
||||||
|
STATIC_ASSERT(sizeof(struct SaveBlock2) <= SECTOR_DATA_SIZE, SaveBlock2FreeSpace);
|
||||||
|
STATIC_ASSERT(sizeof(struct SaveBlock1) <= SECTOR_DATA_SIZE * (SECTOR_ID_SAVEBLOCK1_END - SECTOR_ID_SAVEBLOCK1_START + 1), SaveBlock1FreeSpace);
|
||||||
|
STATIC_ASSERT(sizeof(struct PokemonStorage) <= SECTOR_DATA_SIZE * (SECTOR_ID_PKMN_STORAGE_END - SECTOR_ID_PKMN_STORAGE_START + 1), PokemonStorageFreeSpace);
|
||||||
|
|
||||||
u16 gLastWrittenSector;
|
u16 gLastWrittenSector;
|
||||||
u32 gLastSaveCounter;
|
u32 gLastSaveCounter;
|
||||||
u16 gLastKnownGoodSector;
|
u16 gLastKnownGoodSector;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user