Clean up mystery gift headers

This commit is contained in:
GriffinR 2021-10-17 02:18:24 -04:00
parent 3cd27acbea
commit d0455485c3
7 changed files with 48 additions and 48 deletions

View File

@ -36,17 +36,17 @@ bool32 SaveWonderNews(const struct WonderNews *news);
bool32 SaveWonderCard(const struct WonderCard *card); bool32 SaveWonderCard(const struct WonderCard *card);
bool32 ValidateSavedWonderNews(void); bool32 ValidateSavedWonderNews(void);
bool32 ValidateSavedWonderCard(void); bool32 ValidateSavedWonderCard(void);
bool32 IsWonderNewsSameAsSaved(const u8 *src); bool32 IsWonderNewsSameAsSaved(const u8 *news);
bool32 IsSendingSavedWonderNewsAllowed(void); bool32 IsSendingSavedWonderNewsAllowed(void);
bool32 IsSendingSavedWonderCardAllowed(void); bool32 IsSendingSavedWonderCardAllowed(void);
u16 GetWonderCardFlagID(void); u16 GetWonderCardFlagID(void);
void DisableWonderCardSending(struct WonderCard *card); void DisableWonderCardSending(struct WonderCard *card);
bool32 IsSavedWonderCardGiftNotReceived(void); bool32 IsSavedWonderCardGiftNotReceived(void);
bool32 MysteryGift_TrySaveStamp(const u16 *stamp); bool32 MysteryGift_TrySaveStamp(const u16 *stamp);
void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 a1); void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 isWonderNews);
bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *data, bool32 a1); bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *data, bool32 isWonderNews);
u32 MysteryGift_CompareCardFlags(const u16 *a0, const struct MysteryGiftLinkGameData *data, const void *unused); u32 MysteryGift_CompareCardFlags(const u16 *flagId, const struct MysteryGiftLinkGameData *data, const void *unused);
u32 MysteryGift_CheckStamps(const u16 *a0, const struct MysteryGiftLinkGameData *data, const void *unused); u32 MysteryGift_CheckStamps(const u16 *stamp, const struct MysteryGiftLinkGameData *data, const void *unused);
bool32 MysteryGift_DoesQuestionnaireMatch(const struct MysteryGiftLinkGameData *data, const u16 *words); bool32 MysteryGift_DoesQuestionnaireMatch(const struct MysteryGiftLinkGameData *data, const u16 *words);
u16 MysteryGift_GetCardStatFromLinkData(const struct MysteryGiftLinkGameData *data, u32 stat); u16 MysteryGift_GetCardStatFromLinkData(const struct MysteryGiftLinkGameData *data, u32 stat);
u16 MysteryGift_GetCardStat(u32 stat); u16 MysteryGift_GetCardStat(u32 stat);

View File

@ -34,16 +34,16 @@ struct MysteryGiftLink
u16 sendCounter; u16 sendCounter;
u16 sendCRC; u16 sendCRC;
u16 sendSize; u16 sendSize;
void * recvBfr; void * recvBuffer;
const void * sendBfr; const void * sendBuffer;
u32 (*recvFunc)(struct MysteryGiftLink *); u32 (*recvFunc)(struct MysteryGiftLink *);
u32 (*sendFunc)(struct MysteryGiftLink *); u32 (*sendFunc)(struct MysteryGiftLink *);
}; };
void MysteryGiftLink_Init(struct MysteryGiftLink *, u32, u32); void MysteryGiftLink_Init(struct MysteryGiftLink * link, u32 sendPlayerId, u32 recvPlayerId);
void MysteryGiftLink_InitSend(struct MysteryGiftLink * manager, u32 ident, const void * src, u32 size); void MysteryGiftLink_InitSend(struct MysteryGiftLink * link, u32 ident, const void * src, u32 size);
bool32 MysteryGiftLink_Recv(struct MysteryGiftLink * manager); bool32 MysteryGiftLink_Recv(struct MysteryGiftLink * link);
bool32 MysteryGiftLink_Send(struct MysteryGiftLink * manager); bool32 MysteryGiftLink_Send(struct MysteryGiftLink * link);
void MysteryGiftLink_InitRecv(struct MysteryGiftLink *, u32, void *); void MysteryGiftLink_InitRecv(struct MysteryGiftLink * link, u32 ident, void * dest);
#endif //GUARD_MEVENT_SERVER_HELPERS_H #endif //GUARD_MEVENT_SERVER_HELPERS_H

View File

@ -9,7 +9,7 @@ enum {
NEWS_INPUT_NONE = 0xFF NEWS_INPUT_NONE = 0xFF
}; };
bool32 WonderCard_Init(struct WonderCard * card, struct WonderCardMetadata * r6); bool32 WonderCard_Init(struct WonderCard * card, struct WonderCardMetadata * metadata);
bool32 WonderNews_Init(const struct WonderNews * news); bool32 WonderNews_Init(const struct WonderNews * news);
s32 WonderCard_Enter(void); s32 WonderCard_Enter(void);
s32 WonderNews_Enter(void); s32 WonderNews_Enter(void);

View File

@ -387,7 +387,7 @@ void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData *data, bool32 i
data->romHeaderSoftwareVersion = RomHeaderSoftwareVersion; data->romHeaderSoftwareVersion = RomHeaderSoftwareVersion;
} }
bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *data, bool32 forNews) bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *data, bool32 isWonderNews)
{ {
if (data->validationVar != GAME_DATA_VALID_VAR) if (data->validationVar != GAME_DATA_VALID_VAR)
return FALSE; return FALSE;
@ -398,7 +398,7 @@ bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData *da
if (!(data->validationFlag2 & 1)) if (!(data->validationFlag2 & 1))
return FALSE; return FALSE;
if (!forNews) if (!isWonderNews)
{ {
if (!(data->validationGiftType1 & GAME_DATA_VALID_GIFT_TYPE_1)) if (!(data->validationGiftType1 & GAME_DATA_VALID_GIFT_TYPE_1))
return FALSE; return FALSE;

View File

@ -47,8 +47,8 @@ void MysteryGiftLink_Init(struct MysteryGiftLink * link, u32 sendPlayerId, u32 r
link->recvCRC = 0; link->recvCRC = 0;
link->recvSize = 0; link->recvSize = 0;
link->recvCounter = 0; link->recvCounter = 0;
link->sendBfr = NULL; link->sendBuffer = NULL;
link->recvBfr = NULL; link->recvBuffer = NULL;
link->sendFunc = MGL_Send; link->sendFunc = MGL_Send;
link->recvFunc = MGL_Receive; link->recvFunc = MGL_Receive;
} }
@ -63,7 +63,7 @@ void MysteryGiftLink_InitSend(struct MysteryGiftLink * link, u32 ident, const vo
link->sendSize = size; link->sendSize = size;
else else
link->sendSize = MG_LINK_BUFFER_SIZE; link->sendSize = MG_LINK_BUFFER_SIZE;
link->sendBfr = src; link->sendBuffer = src;
} }
void MysteryGiftLink_InitRecv(struct MysteryGiftLink * link, u32 ident, void * dest) void MysteryGiftLink_InitRecv(struct MysteryGiftLink * link, u32 ident, void * dest)
@ -73,7 +73,7 @@ void MysteryGiftLink_InitRecv(struct MysteryGiftLink * link, u32 ident, void * d
link->recvCounter = 0; link->recvCounter = 0;
link->recvCRC = 0; link->recvCRC = 0;
link->recvSize = 0; link->recvSize = 0;
link->recvBfr = dest; link->recvBuffer = dest;
} }
static void MGL_ReceiveBlock(u32 playerId, void * dest, size_t size) static void MGL_ReceiveBlock(u32 playerId, void * dest, size_t size)
@ -130,20 +130,20 @@ static bool32 MGL_Receive(struct MysteryGiftLink * link)
size_t blocksize = link->recvCounter * 252; size_t blocksize = link->recvCounter * 252;
if (link->recvSize - blocksize <= 252) if (link->recvSize - blocksize <= 252)
{ {
MGL_ReceiveBlock(link->recvPlayerId, link->recvBfr + blocksize, link->recvSize - blocksize); MGL_ReceiveBlock(link->recvPlayerId, link->recvBuffer + blocksize, link->recvSize - blocksize);
link->recvCounter++; link->recvCounter++;
link->state++; link->state++;
} }
else else
{ {
MGL_ReceiveBlock(link->recvPlayerId, link->recvBfr + blocksize, 252); MGL_ReceiveBlock(link->recvPlayerId, link->recvBuffer + blocksize, 252);
link->recvCounter++; link->recvCounter++;
} }
MGL_ResetReceived(link->recvPlayerId); MGL_ResetReceived(link->recvPlayerId);
} }
break; break;
case 2: case 2:
if (CalcCRC16WithTable(link->recvBfr, link->recvSize) != link->recvCRC) if (CalcCRC16WithTable(link->recvBuffer, link->recvSize) != link->recvCRC)
{ {
LinkRfu_FatalError(); LinkRfu_FatalError();
return FALSE; return FALSE;
@ -170,7 +170,7 @@ static bool32 MGL_Send(struct MysteryGiftLink * link)
{ {
header.ident = link->sendIdent; header.ident = link->sendIdent;
header.size = link->sendSize; header.size = link->sendSize;
header.crc = CalcCRC16WithTable(link->sendBfr, link->sendSize); header.crc = CalcCRC16WithTable(link->sendBuffer, link->sendSize);
link->sendCRC = header.crc; link->sendCRC = header.crc;
link->sendCounter = 0; link->sendCounter = 0;
SendBlock(0, &header, sizeof(header)); SendBlock(0, &header, sizeof(header));
@ -187,13 +187,13 @@ static bool32 MGL_Send(struct MysteryGiftLink * link)
blocksize = 252 * link->sendCounter; blocksize = 252 * link->sendCounter;
if (link->sendSize - blocksize <= 252) if (link->sendSize - blocksize <= 252)
{ {
SendBlock(0, link->sendBfr + blocksize, link->sendSize - blocksize); SendBlock(0, link->sendBuffer + blocksize, link->sendSize - blocksize);
link->sendCounter++; link->sendCounter++;
link->state++; link->state++;
} }
else else
{ {
SendBlock(0, link->sendBfr + blocksize, 252); SendBlock(0, link->sendBuffer + blocksize, 252);
link->sendCounter++; link->sendCounter++;
} }
} }
@ -202,7 +202,7 @@ static bool32 MGL_Send(struct MysteryGiftLink * link)
case 2: case 2:
if (IsLinkTaskFinished()) if (IsLinkTaskFinished())
{ {
if (CalcCRC16WithTable(link->sendBfr, link->sendSize) != link->sendCRC) if (CalcCRC16WithTable(link->sendBuffer, link->sendSize) != link->sendCRC)
LinkRfu_FatalError(); LinkRfu_FatalError();
else else
link->state++; link->state++;

View File

@ -474,7 +474,7 @@ void MainCB_FreeAllBuffersAndReturnToInitTitleScreen(void)
SetMainCallback2(CB2_InitTitleScreen); SetMainCallback2(CB2_InitTitleScreen);
} }
void PrintMysteryGiftOrEReaderTopMenu(bool8 isEReader, bool32 usePickOkCancel) void PrintMysteryGiftOrEReaderTopMenu(bool8 isEReader, bool32 useCancel)
{ {
const u8 * header; const u8 * header;
const u8 * options; const u8 * options;
@ -482,7 +482,7 @@ void PrintMysteryGiftOrEReaderTopMenu(bool8 isEReader, bool32 usePickOkCancel)
if (!isEReader) if (!isEReader)
{ {
header = gText_MysteryGift; header = gText_MysteryGift;
options = !usePickOkCancel ? gText_PickOKExit : gText_PickOKCancel; options = !useCancel ? gText_PickOKExit : gText_PickOKCancel;
} }
else else
{ {
@ -816,11 +816,11 @@ static bool32 ClearSavedNewsOrCard(bool32 isWonderNews)
return TRUE; return TRUE;
} }
static bool32 ExitWonderCardOrNews(bool32 isWonderNews, bool32 arg1) static bool32 ExitWonderCardOrNews(bool32 isWonderNews, bool32 useCancel)
{ {
if (!isWonderNews) if (!isWonderNews)
{ {
if (WonderCard_Exit(arg1)) if (WonderCard_Exit(useCancel))
{ {
WonderCard_Destroy(); WonderCard_Destroy();
return TRUE; return TRUE;
@ -832,7 +832,7 @@ static bool32 ExitWonderCardOrNews(bool32 isWonderNews, bool32 arg1)
} }
else else
{ {
if (WonderNews_Exit(arg1)) if (WonderNews_Exit(useCancel))
{ {
WonderNews_Destroy(); WonderNews_Destroy();
return TRUE; return TRUE;
@ -1486,7 +1486,7 @@ static void Task_MysteryGift(u8 taskId)
} }
break; break;
case MG_STATE_TOSS: case MG_STATE_TOSS:
if (ExitWonderCardOrNews(data->isWonderNews, 1)) if (ExitWonderCardOrNews(data->isWonderNews, TRUE))
{ {
ClearSavedNewsOrCard(data->isWonderNews); ClearSavedNewsOrCard(data->isWonderNews);
data->state = MG_STATE_TOSS_SAVE; data->state = MG_STATE_TOSS_SAVE;
@ -1504,15 +1504,15 @@ static void Task_MysteryGift(u8 taskId)
} }
break; break;
case MG_STATE_GIFT_INPUT_EXIT: case MG_STATE_GIFT_INPUT_EXIT:
if (ExitWonderCardOrNews(data->isWonderNews, 0)) if (ExitWonderCardOrNews(data->isWonderNews, FALSE))
data->state = MG_STATE_TO_MAIN_MENU; data->state = MG_STATE_TO_MAIN_MENU;
break; break;
case MG_STATE_RECEIVE: case MG_STATE_RECEIVE:
if (ExitWonderCardOrNews(data->isWonderNews, 1)) if (ExitWonderCardOrNews(data->isWonderNews, TRUE))
data->state = MG_STATE_SOURCE_PROMPT; data->state = MG_STATE_SOURCE_PROMPT;
break; break;
case MG_STATE_SEND: case MG_STATE_SEND:
if (ExitWonderCardOrNews(data->isWonderNews, 1)) if (ExitWonderCardOrNews(data->isWonderNews, TRUE))
{ {
switch (data->isWonderNews) switch (data->isWonderNews)
{ {

View File

@ -273,11 +273,11 @@ s32 WonderCard_Enter(void)
sWonderCardData->enterExitState = 0; sWonderCardData->enterExitState = 0;
return 1; return 1;
} }
++sWonderCardData->enterExitState; sWonderCardData->enterExitState++;
return 0; return 0;
} }
s32 WonderCard_Exit(bool32 flag) s32 WonderCard_Exit(bool32 useCancel)
{ {
if (sWonderCardData == NULL) if (sWonderCardData == NULL)
return -1; return -1;
@ -310,7 +310,7 @@ s32 WonderCard_Exit(bool32 flag)
FreeMonIconPalettes(); FreeMonIconPalettes();
break; break;
case 5: case 5:
PrintMysteryGiftOrEReaderTopMenu(gGiftIsFromEReader, flag); PrintMysteryGiftOrEReaderTopMenu(gGiftIsFromEReader, useCancel);
CopyBgTilemapBufferToVram(0); CopyBgTilemapBufferToVram(0);
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK); BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
break; break;
@ -320,7 +320,7 @@ s32 WonderCard_Exit(bool32 flag)
sWonderCardData->enterExitState = 0; sWonderCardData->enterExitState = 0;
return 1; return 1;
} }
++sWonderCardData->enterExitState; sWonderCardData->enterExitState++;
return 0; return 0;
} }
@ -737,11 +737,11 @@ s32 WonderNews_Enter(void)
return 1; return 1;
} }
++sWonderNewsData->enterExitState; sWonderNewsData->enterExitState++;
return 0; return 0;
} }
s32 WonderNews_Exit(bool32 flag) s32 WonderNews_Exit(bool32 useCancel)
{ {
if (sWonderNewsData == NULL) if (sWonderNewsData == NULL)
return -1; return -1;
@ -786,7 +786,7 @@ s32 WonderNews_Exit(bool32 flag)
} }
break; break;
case 5: case 5:
PrintMysteryGiftOrEReaderTopMenu(gGiftIsFromEReader, flag); PrintMysteryGiftOrEReaderTopMenu(gGiftIsFromEReader, useCancel);
MG_DrawCheckerboardPattern(3); MG_DrawCheckerboardPattern(3);
CopyBgTilemapBufferToVram(0); CopyBgTilemapBufferToVram(0);
CopyBgTilemapBufferToVram(3); CopyBgTilemapBufferToVram(3);
@ -798,7 +798,7 @@ s32 WonderNews_Exit(bool32 flag)
sWonderNewsData->enterExitState = 0; sWonderNewsData->enterExitState = 0;
return 1; return 1;
} }
++sWonderNewsData->enterExitState; sWonderNewsData->enterExitState++;
return 0; return 0;
} }
@ -872,12 +872,12 @@ static void BufferNewsText(void)
sWonderNewsData->titleText[WONDER_NEWS_TEXT_LENGTH] = EOS; sWonderNewsData->titleText[WONDER_NEWS_TEXT_LENGTH] = EOS;
// Copy body text // Copy body text
for (; i < WONDER_NEWS_BODY_TEXT_LINES; ++i) for (; i < WONDER_NEWS_BODY_TEXT_LINES; i++)
{ {
memcpy(sWonderNewsData->bodyText[i], sWonderNewsData->news.bodyText[i], WONDER_NEWS_TEXT_LENGTH); memcpy(sWonderNewsData->bodyText[i], sWonderNewsData->news.bodyText[i], WONDER_NEWS_TEXT_LENGTH);
sWonderNewsData->bodyText[i][WONDER_NEWS_TEXT_LENGTH] = EOS; sWonderNewsData->bodyText[i][WONDER_NEWS_TEXT_LENGTH] = EOS;
if (i > 7 && sWonderNewsData->bodyText[i][0] != EOS) if (i > 7 && sWonderNewsData->bodyText[i][0] != EOS)
++sWonderNewsData->scrollEnd; sWonderNewsData->scrollEnd++;
} }
sWonderNewsData->arrowsTemplate = sNews_ArrowsTemplate; sWonderNewsData->arrowsTemplate = sNews_ArrowsTemplate;
sWonderNewsData->arrowsTemplate.fullyDownThreshold = sWonderNewsData->scrollEnd; sWonderNewsData->arrowsTemplate.fullyDownThreshold = sWonderNewsData->scrollEnd;
@ -899,7 +899,7 @@ static void DrawNewsWindows(void)
AddTextPrinterParameterized3(sWonderNewsData->windowIds[NEWS_WIN_TITLE], 3, x, 6, sNews_TextColorTable[sWonderNewsData->gfx->titleTextPal], 0, sWonderNewsData->titleText); AddTextPrinterParameterized3(sWonderNewsData->windowIds[NEWS_WIN_TITLE], 3, x, 6, sNews_TextColorTable[sWonderNewsData->gfx->titleTextPal], 0, sWonderNewsData->titleText);
// Print body text // Print body text
for (; i < WONDER_NEWS_BODY_TEXT_LINES; ++i) for (; i < WONDER_NEWS_BODY_TEXT_LINES; i++)
AddTextPrinterParameterized3(sWonderNewsData->windowIds[NEWS_WIN_BODY], 3, 0, AddTextPrinterParameterized3(sWonderNewsData->windowIds[NEWS_WIN_BODY], 3, 0,
16 * i + 2, 16 * i + 2,
sNews_TextColorTable[sWonderNewsData->gfx->bodyTextPal], sNews_TextColorTable[sWonderNewsData->gfx->bodyTextPal],
@ -927,9 +927,9 @@ static void UpdateNewsScroll(void)
if (sWonderNewsData->scrollTotal > 15) if (sWonderNewsData->scrollTotal > 15)
{ {
if (sWonderNewsData->scrollingDown) if (sWonderNewsData->scrollingDown)
++sWonderNewsData->scrollOffset; sWonderNewsData->scrollOffset++;
else else
--sWonderNewsData->scrollOffset; sWonderNewsData->scrollOffset--;
sWonderNewsData->scrolling = FALSE; sWonderNewsData->scrolling = FALSE;
sWonderNewsData->scrollTotal = 0; sWonderNewsData->scrollTotal = 0;
} }