From 5f9069628d193b61b7601dc016509b91024ffa1b Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 17 Oct 2021 01:35:26 -0400 Subject: [PATCH] Clean up mevent2 --- include/constants/global.h | 2 ++ include/constants/mevent.h | 5 +++-- include/global.h | 4 ++-- include/mevent.h | 14 +++++++------ src/cable_club.c | 4 ++-- src/mevent2.c | 42 ++++++++++++++++++++++---------------- src/trade.c | 2 +- src/wonder_transfer.c | 4 ++-- 8 files changed, 44 insertions(+), 33 deletions(-) diff --git a/include/constants/global.h b/include/constants/global.h index 7fca5453c..12d6178b2 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -92,6 +92,8 @@ #define WONDER_CARD_BODY_TEXT_LINES 4 #define WONDER_NEWS_BODY_TEXT_LINES 10 +#define MAX_STAMP_CARD_STAMPS 7 + #define MALE 0 #define FEMALE 1 #define GENDER_COUNT 2 diff --git a/include/constants/mevent.h b/include/constants/mevent.h index 91eacd801..636043fdb 100644 --- a/include/constants/mevent.h +++ b/include/constants/mevent.h @@ -13,11 +13,13 @@ #define CARD_STAT_NUM_STAMPS 3 #define CARD_STAT_MAX_STAMPS 4 +// Values for the type field of Wonder Card #define CARD_TYPE_GIFT 0 // Normal "Wonder Card" #define CARD_TYPE_STAMP 1 // "Stamp Card" #define CARD_TYPE_LINK_STAT 2 // Referred to as the "Battle Card", shows battle and trade stats #define CARD_TYPE_COUNT 3 +// Values for the sendType field of Wonder Card/News #define SEND_TYPE_DISALLOWED 0 #define SEND_TYPE_ALLOWED 1 #define SEND_TYPE_ALLOWED_ALWAYS 2 @@ -27,10 +29,9 @@ #define HAS_SAME_CARD 1 #define HAS_DIFF_CARD 2 +// The number of battles needed to be recorded on a Battle Card to win a prize #define REQUIRED_CARD_BATTLES 3 -#define MAX_CARD_STAMPS 7 - // Stamps are 32 bits. The first 16 bits are the species // and the second 16 bits are a number (presumably an ID of some kind) #define STAMP_SPECIES 0 diff --git a/include/global.h b/include/global.h index 36fbfc38d..8681f7289 100644 --- a/include/global.h +++ b/include/global.h @@ -847,7 +847,7 @@ struct WonderNewsMetadata struct WonderNews { - u16 unk_00; + u16 id; u8 sendType; // SEND_TYPE_* u8 bgType; u8 titleText[WONDER_NEWS_TEXT_LENGTH]; @@ -876,7 +876,7 @@ struct WonderCardMetadata u16 battlesLost; u16 numTrades; u16 iconSpecies; - u16 stampData[2][7]; + u16 stampData[2][MAX_STAMP_CARD_STAMPS]; // First element is STAMP_SPECIES, second is STAMP_ID }; struct MysteryGiftSave diff --git a/include/mevent.h b/include/mevent.h index 9b7ef3ab5..c3e14f1f3 100755 --- a/include/mevent.h +++ b/include/mevent.h @@ -6,11 +6,13 @@ struct MysteryGiftLinkGameData { - u32 unk_00; - u16 unk_04; - u32 unk_08; - u16 unk_0C; - u32 unk_10; + // It's possible these first 5 fields had some other meaningful purpose, + // but they are only ever set when creating this data and read to validate it. + u32 validationVar; + u16 validationFlag1; + u32 validationFlag2; + u16 validationGiftType1; + u32 validationGiftType2; u16 flagId; u16 questionnaireWords[NUM_QUESTIONNAIRE_WORDS]; struct WonderCardMetadata cardMetadata; @@ -50,6 +52,6 @@ u16 MysteryGift_GetCardStatFromLinkData(const struct MysteryGiftLinkGameData *da u16 MysteryGift_GetCardStat(u32 stat); void MysteryGift_DisableStats(void); bool32 MysteryGift_TryEnableStatsByFlagId(u16 flagId); -void TryIncrementMysteryGiftStat(u32 stat, u32 trainerId); +void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId); #endif //GUARD_MEVENT_H diff --git a/src/cable_club.c b/src/cable_club.c index e9100b011..69fcb660b 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -1004,10 +1004,10 @@ void CB2_ReturnFromCableClubBattle(void) switch (gBattleOutcome) { case B_OUTCOME_WON: - TryIncrementMysteryGiftStat(CARD_STAT_BATTLES_WON, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId); + MysteryGift_TryIncrementStat(CARD_STAT_BATTLES_WON, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId); break; case B_OUTCOME_LOST: - TryIncrementMysteryGiftStat(CARD_STAT_BATTLES_LOST, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId); + MysteryGift_TryIncrementStat(CARD_STAT_BATTLES_LOST, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId); break; } } diff --git a/src/mevent2.c b/src/mevent2.c index d781e2119..36652f44e 100755 --- a/src/mevent2.c +++ b/src/mevent2.c @@ -83,9 +83,9 @@ bool32 ValidateSavedWonderNews(void) return TRUE; } -static bool32 ValidateWonderNews(const struct WonderNews *data) +static bool32 ValidateWonderNews(const struct WonderNews *news) { - if (data->unk_00 == 0) + if (news->id == 0) return FALSE; return TRUE; @@ -93,8 +93,8 @@ static bool32 ValidateWonderNews(const struct WonderNews *data) bool32 IsSendingSavedWonderNewsAllowed(void) { - const struct WonderNews *data = &gSaveBlock1Ptr->mysteryGift.news; - if (data->sendType == SEND_TYPE_DISALLOWED) + const struct WonderNews *news = &gSaveBlock1Ptr->mysteryGift.news; + if (news->sendType == SEND_TYPE_DISALLOWED) return FALSE; return TRUE; @@ -177,7 +177,7 @@ static bool32 ValidateWonderCard(const struct WonderCard *card) return FALSE; if (card->bgType >= NUM_WONDER_BGS) return FALSE; - if (card->maxStamps > MAX_CARD_STAMPS) + if (card->maxStamps > MAX_STAMP_CARD_STAMPS) return FALSE; return TRUE; @@ -339,23 +339,29 @@ bool32 MysteryGift_TrySaveStamp(const u16 *stamp) return FALSE; } +#define GAME_DATA_VALID_VAR 0x101 +#define GAME_DATA_VALID_GIFT_TYPE_1 (1 << 2) +#define GAME_DATA_VALID_GIFT_TYPE_2 (1 << 9) + void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 isWonderNews) { int i; CpuFill32(0, data, sizeof(*data)); - data->unk_00 = 0x101; - data->unk_04 = 1; - data->unk_08 = 1; + data->validationVar = GAME_DATA_VALID_VAR; + data->validationFlag1 = 1; + data->validationFlag2 = 1; if (isWonderNews) { - data->unk_0C = 5; - data->unk_10 = 0x0201; + // Despite setting these for News, they are + // only ever checked for Cards + data->validationGiftType1 = GAME_DATA_VALID_GIFT_TYPE_1 | 1; + data->validationGiftType2 = GAME_DATA_VALID_GIFT_TYPE_2 | 1; } else // Wonder Card { - data->unk_0C = 4; - data->unk_10 = 0x0200; + data->validationGiftType1 = GAME_DATA_VALID_GIFT_TYPE_1; + data->validationGiftType2 = GAME_DATA_VALID_GIFT_TYPE_2; } if (ValidateSavedWonderCard()) @@ -383,21 +389,21 @@ void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 i bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *data, bool32 forNews) { - if (data->unk_00 != 0x101) + if (data->validationVar != GAME_DATA_VALID_VAR) return FALSE; - if (!(data->unk_04 & 1)) + if (!(data->validationFlag1 & 1)) return FALSE; - if (!(data->unk_08 & 1)) + if (!(data->validationFlag2 & 1)) return FALSE; if (!forNews) { - if (!(data->unk_0C & 4)) + if (!(data->validationGiftType1 & GAME_DATA_VALID_GIFT_TYPE_1)) return FALSE; - if (!(data->unk_10 & 0x380)) + if (!(data->validationGiftType2 & (GAME_DATA_VALID_GIFT_TYPE_2 | 0x180))) return FALSE; } @@ -581,7 +587,7 @@ bool32 MysteryGift_TryEnableStatsByFlagId(u16 flagId) return TRUE; } -void TryIncrementMysteryGiftStat(u32 stat, u32 trainerId) +void MysteryGift_TryIncrementStat(u32 stat, u32 trainerId) { if (sStatsEnabled) { diff --git a/src/trade.c b/src/trade.c index f51a9f6e9..acae292e5 100644 --- a/src/trade.c +++ b/src/trade.c @@ -4655,7 +4655,7 @@ static void CB2_SaveAndEndTrade(void) if (!InUnionRoom()) IncrementGameStat(GAME_STAT_POKEMON_TRADES); if (gWirelessCommType) - TryIncrementMysteryGiftStat(CARD_STAT_NUM_TRADES, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId); + MysteryGift_TryIncrementStat(CARD_STAT_NUM_TRADES, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId); SetContinueGameWarpStatusToDynamicWarp(); sub_8153380(); diff --git a/src/wonder_transfer.c b/src/wonder_transfer.c index efabc460e..d958b8aef 100644 --- a/src/wonder_transfer.c +++ b/src/wonder_transfer.c @@ -57,7 +57,7 @@ struct WonderCardData /*0175*/ u8 statFooterWidth; /*0176*/ u16 windowIds[CARD_WIN_COUNT]; /*017C*/ u8 monIconSpriteId; - /*017D*/ u8 stampSpriteIds[MAX_CARD_STAMPS][2]; // 2 sprites each, 1 for the shadw and 1 for the Pokémon + /*017D*/ u8 stampSpriteIds[MAX_STAMP_CARD_STAMPS][2]; // 2 sprites each, 1 for the shadw and 1 for the Pokémon /*018B*/ u8 titleText[WONDER_CARD_TEXT_LENGTH + 1]; /*01B4*/ u8 subtitleText[WONDER_CARD_TEXT_LENGTH + 1]; /*01DD*/ u8 idNumberText[7]; @@ -196,7 +196,7 @@ bool32 WonderCard_Init(struct WonderCard * card, struct WonderCardMetadata * met sWonderCardData->card.bgType = 0; if (sWonderCardData->card.type >= CARD_TYPE_COUNT) sWonderCardData->card.type = 0; - if (sWonderCardData->card.maxStamps > MAX_CARD_STAMPS) + if (sWonderCardData->card.maxStamps > MAX_STAMP_CARD_STAMPS) sWonderCardData->card.maxStamps = 0; sWonderCardData->gfx = &sCardGraphics[sWonderCardData->card.bgType]; return TRUE;