mirror of
https://github.com/pret/pokefirered.git
synced 2026-10-01 05:20:00 -05:00
add FREE_MYSTERY_GIFT functionality
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "constants/rgb.h"
|
||||
#include "constants/easy_chat.h"
|
||||
#include "constants/items.h"
|
||||
#include "config/save.h"
|
||||
|
||||
// Prevent cross-jump optimization.
|
||||
#define BLOCK_CROSS_JUMP asm("");
|
||||
@@ -844,7 +845,9 @@ struct SaveBlock1
|
||||
/*0x30BB*/ struct ExternalEventFlags externalEventFlags;
|
||||
/*0x30D0*/ struct Roamer roamer;
|
||||
/*0x30EC*/ struct EnigmaBerry enigmaBerry;
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
/*0x3120*/ struct MysteryGiftSave mysteryGift;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
/*0x????*/ u8 dexSeen[DEX_FLAGS_NO];
|
||||
u8 dexCaught[DEX_FLAGS_NO];
|
||||
/*0x361C*/ struct RamScript ramScript;
|
||||
|
||||
@@ -18,14 +18,18 @@
|
||||
|
||||
#define CALC_CRC(data) CalcCRC16WithTable((void *)&(data), sizeof(data))
|
||||
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
static bool32 ValidateWonderNews(const struct WonderNews * src);
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
static void ClearSavedWonderNews(void);
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
static void ClearSavedWonderNewsMetadata(void);
|
||||
static bool32 ValidateWonderCard(const struct WonderCard * src);
|
||||
static void ClearSavedWonderCard(void);
|
||||
static void ClearSavedWonderCardMetadata(void);
|
||||
static void IncrementCardStatForNewTrainer(u32 eventId, u32 trainerId, u32 *idsList, s32 count);
|
||||
static void ClearSavedTrainerIds(void);
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
static const u16 sReceivedGiftFlags[] = {
|
||||
FLAG_RECEIVED_AURORA_TICKET,
|
||||
@@ -54,34 +58,56 @@ static EWRAM_DATA bool32 sStatsEnabled = FALSE;
|
||||
|
||||
void ClearMysteryGift(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
CpuFill32(0, &gSaveBlock1Ptr->mysteryGift, sizeof(gSaveBlock1Ptr->mysteryGift));
|
||||
ClearSavedWonderNewsMetadata();
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
InitQuestionnaireWords();
|
||||
}
|
||||
|
||||
struct WonderNews * GetSavedWonderNews(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
return &gSaveBlock1Ptr->mysteryGift.news;
|
||||
#else
|
||||
return NULL;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
struct WonderCard * GetSavedWonderCard(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
return &gSaveBlock1Ptr->mysteryGift.card;
|
||||
#else
|
||||
return NULL;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
struct WonderCardMetadata * GetSavedWonderCardMetadata(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
return &gSaveBlock1Ptr->mysteryGift.cardMetadata;
|
||||
#else
|
||||
return NULL;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
struct WonderNewsMetadata * GetSavedWonderNewsMetadata(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
return &gSaveBlock1Ptr->mysteryGift.newsMetadata;
|
||||
#else
|
||||
return NULL;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
u16 * GetQuestionnaireWordsPtr(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
return gSaveBlock1Ptr->mysteryGift.questionnaireWords;
|
||||
#else
|
||||
return NULL;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
// Equivalent to ClearSavedWonderCardAndRelated, but nothing else to clear
|
||||
@@ -92,6 +118,7 @@ void ClearSavedWonderNewsAndRelated(void)
|
||||
|
||||
bool32 SaveWonderNews(const struct WonderNews * news)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
if (!ValidateWonderNews(news))
|
||||
return FALSE;
|
||||
|
||||
@@ -99,46 +126,64 @@ bool32 SaveWonderNews(const struct WonderNews * news)
|
||||
gSaveBlock1Ptr->mysteryGift.news = *news;
|
||||
gSaveBlock1Ptr->mysteryGift.newsCrc = CALC_CRC(gSaveBlock1Ptr->mysteryGift.news);
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
bool32 ValidateSavedWonderNews(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
if (CALC_CRC(gSaveBlock1Ptr->mysteryGift.news) != gSaveBlock1Ptr->mysteryGift.newsCrc)
|
||||
return FALSE;
|
||||
if (!ValidateWonderNews(&gSaveBlock1Ptr->mysteryGift.news))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
static bool32 ValidateWonderNews(const struct WonderNews * news)
|
||||
{
|
||||
if (news->id == 0)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
bool32 IsSendingSavedWonderNewsAllowed(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
const struct WonderNews * news = &gSaveBlock1Ptr->mysteryGift.news;
|
||||
if (news->sendType == SEND_TYPE_DISALLOWED)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
static void ClearSavedWonderNews(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
CpuFill32(0, GetSavedWonderNews(), sizeof(gSaveBlock1Ptr->mysteryGift.news));
|
||||
gSaveBlock1Ptr->mysteryGift.newsCrc = 0;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
static void ClearSavedWonderNewsMetadata(void)
|
||||
{
|
||||
CpuFill32(0, GetSavedWonderNewsMetadata(), sizeof(gSaveBlock1Ptr->mysteryGift.newsMetadata));
|
||||
WonderNews_Reset();
|
||||
}
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
bool32 IsWonderNewsSameAsSaved(const u8 * news)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
const u8 * savedNews = (const u8 *)&gSaveBlock1Ptr->mysteryGift.news;
|
||||
u32 i;
|
||||
if (!ValidateSavedWonderNews())
|
||||
@@ -150,21 +195,27 @@ bool32 IsWonderNewsSameAsSaved(const u8 * news)
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
void ClearSavedWonderCardAndRelated(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
ClearSavedWonderCard();
|
||||
ClearSavedWonderCardMetadata();
|
||||
ClearSavedTrainerIds();
|
||||
ClearRamScript();
|
||||
ClearMysteryGiftFlags();
|
||||
ClearMysteryGiftVars();
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
ClearEReaderTrainer(&gSaveBlock2Ptr->battleTower.ereaderTrainer);
|
||||
}
|
||||
|
||||
bool32 SaveWonderCard(const struct WonderCard * card)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
struct WonderCardMetadata * metadata;
|
||||
if (!ValidateWonderCard(card))
|
||||
return FALSE;
|
||||
@@ -175,10 +226,14 @@ bool32 SaveWonderCard(const struct WonderCard * card)
|
||||
metadata = &gSaveBlock1Ptr->mysteryGift.cardMetadata;
|
||||
metadata->iconSpecies = (&gSaveBlock1Ptr->mysteryGift.card)->iconSpecies;
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
bool32 ValidateSavedWonderCard(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
if (gSaveBlock1Ptr->mysteryGift.cardCrc != CALC_CRC(gSaveBlock1Ptr->mysteryGift.card))
|
||||
return FALSE;
|
||||
if (!ValidateWonderCard(&gSaveBlock1Ptr->mysteryGift.card))
|
||||
@@ -186,8 +241,12 @@ bool32 ValidateSavedWonderCard(void)
|
||||
if (!ValidateRamScript())
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
static bool32 ValidateWonderCard(const struct WonderCard * card)
|
||||
{
|
||||
if (card->flagId == 0)
|
||||
@@ -204,15 +263,21 @@ static bool32 ValidateWonderCard(const struct WonderCard * card)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
bool32 IsSendingSavedWonderCardAllowed(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
const struct WonderCard * card = &gSaveBlock1Ptr->mysteryGift.card;
|
||||
if (card->sendType == SEND_TYPE_DISALLOWED)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
static void ClearSavedWonderCard(void)
|
||||
{
|
||||
CpuFill32(0, &gSaveBlock1Ptr->mysteryGift.card, sizeof(gSaveBlock1Ptr->mysteryGift.card));
|
||||
@@ -224,11 +289,15 @@ static void ClearSavedWonderCardMetadata(void)
|
||||
CpuFill32(0, GetSavedWonderCardMetadata(), sizeof(gSaveBlock1Ptr->mysteryGift.cardMetadata));
|
||||
gSaveBlock1Ptr->mysteryGift.cardMetadataCrc = 0;
|
||||
}
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
u16 GetWonderCardFlagId(void)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
if (ValidateSavedWonderCard())
|
||||
return gSaveBlock1Ptr->mysteryGift.card.flagId;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -282,6 +351,7 @@ static bool32 IsStampInMetadata(const struct WonderCardMetadata * metadata, cons
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
static bool32 ValidateStamp(const u16 * stamp)
|
||||
{
|
||||
if (stamp[STAMP_ID] == 0)
|
||||
@@ -303,9 +373,11 @@ static s32 GetNumStampsInSavedCard(void)
|
||||
return 0;
|
||||
return GetNumStampsInMetadata(&gSaveBlock1Ptr->mysteryGift.cardMetadata, card->maxStamps);
|
||||
}
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
bool32 MysteryGift_TrySaveStamp(const u16 * stamp)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
struct WonderCard * card = &gSaveBlock1Ptr->mysteryGift.card;
|
||||
s32 maxStamps = card->maxStamps;
|
||||
s32 i;
|
||||
@@ -323,6 +395,8 @@ bool32 MysteryGift_TrySaveStamp(const u16 * stamp)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -336,6 +410,7 @@ bool32 MysteryGift_TrySaveStamp(const u16 * stamp)
|
||||
|
||||
void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData * data)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
s32 i;
|
||||
CpuFill32(0, data, sizeof(*data));
|
||||
// Magic
|
||||
@@ -368,6 +443,7 @@ void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData * data)
|
||||
|
||||
memcpy(data->gameCode, RomHeaderGameCode, GAME_CODE_LENGTH);
|
||||
data->version = RomHeaderSoftwareVersion;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData * data)
|
||||
@@ -455,6 +531,7 @@ u16 MysteryGift_GetCardStatFromLinkData(const struct MysteryGiftLinkGameData * d
|
||||
}
|
||||
}
|
||||
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
static void IncrementCardStat(u32 statType)
|
||||
{
|
||||
struct WonderCard * card = &gSaveBlock1Ptr->mysteryGift.card;
|
||||
@@ -486,9 +563,11 @@ static void IncrementCardStat(u32 statType)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
u16 MysteryGift_GetCardStat(u32 stat)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
switch (stat)
|
||||
{
|
||||
case CARD_STAT_BATTLES_WON:
|
||||
@@ -536,6 +615,8 @@ u16 MysteryGift_GetCardStat(u32 stat)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
AGB_ASSERT_EX(0, ABSPATH("mevent.c"), 913);
|
||||
return 0;
|
||||
}
|
||||
@@ -550,16 +631,22 @@ bool32 MysteryGift_TryEnableStatsByFlagId(u16 flagId)
|
||||
sStatsEnabled = FALSE;
|
||||
if (flagId == 0)
|
||||
return FALSE;
|
||||
|
||||
if (!ValidateSavedWonderCard())
|
||||
return FALSE;
|
||||
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
if (gSaveBlock1Ptr->mysteryGift.card.flagId != flagId)
|
||||
return FALSE;
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
sStatsEnabled = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId)
|
||||
{
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
if (sStatsEnabled)
|
||||
{
|
||||
switch (stat)
|
||||
@@ -587,8 +674,10 @@ void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
}
|
||||
|
||||
#if FREE_MYSTERY_GIFT == FALSE
|
||||
static void ClearSavedTrainerIds(void)
|
||||
{
|
||||
CpuFill32(0, gSaveBlock1Ptr->mysteryGift.trainerIds, sizeof(gSaveBlock1Ptr->mysteryGift.trainerIds));
|
||||
@@ -632,3 +721,4 @@ static void IncrementCardStatForNewTrainer(u32 stat, u32 trainerId, u32 * traine
|
||||
if (RecordTrainerId(trainerId, trainerIds, size))
|
||||
IncrementCardStat(stat);
|
||||
}
|
||||
#endif //FREE_MYSTERY_GIFT
|
||||
|
||||
Reference in New Issue
Block a user