From 6f668fb31dc601bc54b64b400da2d441c611e316 Mon Sep 17 00:00:00 2001 From: Bassoonian Date: Fri, 2 Feb 2024 16:31:19 +0100 Subject: [PATCH] Add FREE_MYSTERY_GIFT --- include/config/save.h | 11 ++-- include/global.h | 4 +- src/mystery_gift.c | 120 +++++++++++++++++++++--------------------- 3 files changed, 68 insertions(+), 67 deletions(-) diff --git a/include/config/save.h b/include/config/save.h index cbaf144e8a..ff65abaa88 100644 --- a/include/config/save.h +++ b/include/config/save.h @@ -9,17 +9,18 @@ #define FREE_UNION_ROOM_CHAT FALSE // Frees up union room chat (212 bytes). #define FREE_ENIGMA_BERRY FALSE // Frees up E-Reader Enigma Berry data (52 bytes). #define FREE_LINK_BATTLE_RECORDS FALSE // Frees up link battle record data (88 bytes). +#define FREE_MYSTERY_GIFT FALSE // Frees up Mystery Gift data (876 bytes). WARNING THIS HAS BEEN SHOWN TO BREAK THE POKÉ MARTS' QUESTIONNAIRE // saveblock1 total: 1846 bytes //free saveblock 2 defines -#define FREE_BATTLE_TOWER_E_READER FALSE // Frees up Battle Tower E-Reader data (188 bytes). WARNING THIS HAS BEEN SHOWN TO BREAK THE POKÉ MARTS' QUESTIONNAIRE +#define FREE_BATTLE_TOWER_E_READER FALSE // Frees up Battle Tower E-Reader data (188 bytes). #define FREE_POKEMON_JUMP FALSE // Frees up Pokémon Jump data (16 bytes). #define FREE_RECORD_MIXING_HALL_RECORDS FALSE // Frees up hall records for record mixing (1032 bytes). // saveblock2 total: 1236 bytes //grand total: 3082 -#if (FREE_MYSTERY_EVENT_BUFFERS == TRUE) && (FREE_BATTLE_TOWER_E_READER == FALSE) -#error "FREE_BATTLE_TOWER_E_READER must be enabled for FREE_MYSTERY_EVENT_BUFFERS to work" -#endif +//#if (FREE_MYSTERY_EVENT_BUFFERS == TRUE) && (FREE_BATTLE_TOWER_E_READER == FALSE) +//#error "FREE_BATTLE_TOWER_E_READER must be enabled for FREE_MYSTERY_EVENT_BUFFERS to work" +//#endif -#endif // GUARD_CONFIG_DECAP_H +#endif // GUARD_CONFIG_SAVE_H diff --git a/include/global.h b/include/global.h index e3c89f8eb3..e39b880362 100644 --- a/include/global.h +++ b/include/global.h @@ -1068,9 +1068,9 @@ struct SaveBlock1 #if FREE_ENIGMA_BERRY == FALSE /*0x31F8*/ struct EnigmaBerry enigmaBerry; #endif //FREE_ENIGMA_BERRY -#if FREE_MYSTERY_EVENT_BUFFERS == FALSE +#if FREE_MYSTERY_GIFT == FALSE /*0x322C*/ struct MysteryGiftSave mysteryGift; -#endif //FREE_MYSTERY_EVENT_BUFFERS +#endif //FREE_MYSTERY_GIFT /*0x3???*/ u8 dexSeen[NUM_DEX_FLAG_BYTES]; /*0x3???*/ u8 dexCaught[NUM_DEX_FLAG_BYTES]; #if FREE_TRAINER_HILL == FALSE diff --git a/src/mystery_gift.c b/src/mystery_gift.c index d14d2f8e41..48a6b1545f 100755 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -13,73 +13,73 @@ static EWRAM_DATA bool32 sStatsEnabled = FALSE; -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE static void ClearSavedWonderNewsMetadata(void); -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT static void ClearSavedWonderNews(void); -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE static void ClearSavedWonderCard(void); static bool32 ValidateWonderNews(const struct WonderNews *); static bool32 ValidateWonderCard(const struct WonderCard *); static void ClearSavedWonderCardMetadata(void); static void ClearSavedTrainerIds(void); static void IncrementCardStatForNewTrainer(u32, u32, u32 *, int); -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT #define CALC_CRC(data) CalcCRC16WithTable((void *)&(data), sizeof(data)) void ClearMysteryGift(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE CpuFill32(0, &gSaveBlock1Ptr->mysteryGift, sizeof(gSaveBlock1Ptr->mysteryGift)); ClearSavedWonderNewsMetadata(); // Clear is redundant, WonderNews_Reset would be sufficient -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT InitQuestionnaireWords(); } struct WonderNews *GetSavedWonderNews(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE return &gSaveBlock1Ptr->mysteryGift.news; #else return NULL; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } struct WonderCard *GetSavedWonderCard(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE return &gSaveBlock1Ptr->mysteryGift.card; #else return NULL; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } struct WonderCardMetadata *GetSavedWonderCardMetadata(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE return &gSaveBlock1Ptr->mysteryGift.cardMetadata; #else return NULL; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } struct WonderNewsMetadata *GetSavedWonderNewsMetadata(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE return &gSaveBlock1Ptr->mysteryGift.newsMetadata; #else return NULL; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } u16 *GetQuestionnaireWordsPtr(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE return gSaveBlock1Ptr->mysteryGift.questionnaireWords; #else return NULL; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } // Equivalent to ClearSavedWonderCardAndRelated, but nothing else to clear @@ -90,7 +90,7 @@ void ClearSavedWonderNewsAndRelated(void) bool32 SaveWonderNews(const struct WonderNews *news) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE if (!ValidateWonderNews(news)) return FALSE; @@ -100,12 +100,12 @@ bool32 SaveWonderNews(const struct WonderNews *news) return TRUE; #else return FALSE; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } bool32 ValidateSavedWonderNews(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE if (CALC_CRC(gSaveBlock1Ptr->mysteryGift.news) != gSaveBlock1Ptr->mysteryGift.newsCrc) return FALSE; if (!ValidateWonderNews(&gSaveBlock1Ptr->mysteryGift.news)) @@ -114,10 +114,10 @@ bool32 ValidateSavedWonderNews(void) return TRUE; #else return FALSE; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE static bool32 ValidateWonderNews(const struct WonderNews *news) { if (news->id == 0) @@ -125,11 +125,11 @@ static bool32 ValidateWonderNews(const struct WonderNews *news) return TRUE; } -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT bool32 IsSendingSavedWonderNewsAllowed(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE const struct WonderNews *news = &gSaveBlock1Ptr->mysteryGift.news; if (news->sendType == SEND_TYPE_DISALLOWED) return FALSE; @@ -137,28 +137,28 @@ bool32 IsSendingSavedWonderNewsAllowed(void) return TRUE; #else return FALSE; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } static void ClearSavedWonderNews(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE CpuFill32(0, GetSavedWonderNews(), sizeof(gSaveBlock1Ptr->mysteryGift.news)); gSaveBlock1Ptr->mysteryGift.newsCrc = 0; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE static void ClearSavedWonderNewsMetadata(void) { CpuFill32(0, GetSavedWonderNewsMetadata(), sizeof(gSaveBlock1Ptr->mysteryGift.newsMetadata)); WonderNews_Reset(); } -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT bool32 IsWonderNewsSameAsSaved(const u8 *news) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE const u8 *savedNews = (const u8 *)&gSaveBlock1Ptr->mysteryGift.news; u32 i; if (!ValidateSavedWonderNews()) @@ -173,12 +173,12 @@ bool32 IsWonderNewsSameAsSaved(const u8 *news) return TRUE; #else return FALSE; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } void ClearSavedWonderCardAndRelated(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE ClearSavedWonderCard(); ClearSavedWonderCardMetadata(); ClearSavedTrainerIds(); @@ -186,12 +186,12 @@ void ClearSavedWonderCardAndRelated(void) ClearMysteryGiftFlags(); ClearMysteryGiftVars(); ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer); -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } bool32 SaveWonderCard(const struct WonderCard *card) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE struct WonderCardMetadata *metadata; if (!ValidateWonderCard(card)) return FALSE; @@ -204,12 +204,12 @@ bool32 SaveWonderCard(const struct WonderCard *card) return TRUE; #else return FALSE; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } bool32 ValidateSavedWonderCard(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE if (gSaveBlock1Ptr->mysteryGift.cardCrc != CALC_CRC(gSaveBlock1Ptr->mysteryGift.card)) return FALSE; if (!ValidateWonderCard(&gSaveBlock1Ptr->mysteryGift.card)) @@ -220,10 +220,10 @@ bool32 ValidateSavedWonderCard(void) return TRUE; #else return FALSE; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE static bool32 ValidateWonderCard(const struct WonderCard *card) { if (card->flagId == 0) @@ -241,11 +241,11 @@ static bool32 ValidateWonderCard(const struct WonderCard *card) return TRUE; } -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT bool32 IsSendingSavedWonderCardAllowed(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE const struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card; if (card->sendType == SEND_TYPE_DISALLOWED) return FALSE; @@ -253,10 +253,10 @@ bool32 IsSendingSavedWonderCardAllowed(void) return TRUE; #else return FALSE; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE static void ClearSavedWonderCard(void) { CpuFill32(0, &gSaveBlock1Ptr->mysteryGift.card, sizeof(gSaveBlock1Ptr->mysteryGift.card)); @@ -268,14 +268,14 @@ static void ClearSavedWonderCardMetadata(void) CpuFill32(0, GetSavedWonderCardMetadata(), sizeof(gSaveBlock1Ptr->mysteryGift.cardMetadata)); gSaveBlock1Ptr->mysteryGift.cardMetadataCrc = 0; } -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT u16 GetWonderCardFlagID(void) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE if (ValidateSavedWonderCard()) return gSaveBlock1Ptr->mysteryGift.card.flagId; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT return 0; } @@ -358,7 +358,7 @@ static bool32 IsStampInMetadata(const struct WonderCardMetadata *metadata, const return FALSE; } -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE static bool32 ValidateStamp(const u16 *stamp) { if (stamp[STAMP_ID] == 0) @@ -382,11 +382,11 @@ static int GetNumStampsInSavedCard(void) return GetNumStampsInMetadata(&gSaveBlock1Ptr->mysteryGift.cardMetadata, card->maxStamps); } -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT bool32 MysteryGift_TrySaveStamp(const u16 *stamp) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card; int maxStamps = card->maxStamps; int i; @@ -406,7 +406,7 @@ bool32 MysteryGift_TrySaveStamp(const u16 *stamp) return TRUE; } } -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT return FALSE; } @@ -417,7 +417,7 @@ bool32 MysteryGift_TrySaveStamp(const u16 *stamp) void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 isWonderNews) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE int i; CpuFill32(0, data, sizeof(*data)); data->validationVar = GAME_DATA_VALID_VAR; @@ -458,7 +458,7 @@ void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 i memcpy(data->romHeaderGameCode, RomHeaderGameCode, GAME_CODE_LENGTH); data->romHeaderSoftwareVersion = RomHeaderSoftwareVersion; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *data, bool32 isWonderNews) @@ -557,7 +557,7 @@ u16 MysteryGift_GetCardStatFromLinkData(const struct MysteryGiftLinkGameData *da } } -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE static void IncrementCardStat(u32 statType) { struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card; @@ -590,11 +590,11 @@ static void IncrementCardStat(u32 statType) } } } -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT u16 MysteryGift_GetCardStat(u32 stat) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE switch (stat) { case CARD_STAT_BATTLES_WON: @@ -642,7 +642,7 @@ u16 MysteryGift_GetCardStat(u32 stat) break; } } -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT AGB_ASSERT(0); return 0; @@ -662,10 +662,10 @@ bool32 MysteryGift_TryEnableStatsByFlagId(u16 flagId) if (!ValidateSavedWonderCard()) return FALSE; -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE if (gSaveBlock1Ptr->mysteryGift.card.flagId != flagId) return FALSE; -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT sStatsEnabled = TRUE; return TRUE; @@ -673,7 +673,7 @@ bool32 MysteryGift_TryEnableStatsByFlagId(u16 flagId) void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId) { -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE if (sStatsEnabled) { switch (stat) @@ -701,10 +701,10 @@ void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId) break; } } -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT } -#if FREE_BATTLE_TOWER_E_READER == FALSE +#if FREE_MYSTERY_GIFT == FALSE static void ClearSavedTrainerIds(void) { CpuFill32(0, gSaveBlock1Ptr->mysteryGift.trainerIds, sizeof(gSaveBlock1Ptr->mysteryGift.trainerIds)); @@ -747,4 +747,4 @@ static void IncrementCardStatForNewTrainer(u32 stat, u32 trainerId, u32 *trainer if (RecordTrainerId(trainerId, trainerIds, size)) IncrementCardStat(stat); } -#endif //FREE_BATTLE_TOWER_E_READER +#endif //FREE_MYSTERY_GIFT