Document mystery gift link scripts, general mystery gift

This commit is contained in:
GriffinR 2021-10-14 15:36:51 -04:00
parent 37e52c4f34
commit c02001c46d
22 changed files with 610 additions and 574 deletions

View File

@ -6,7 +6,7 @@ CableClub_EventScript_HideOrShowMysteryGiftMan::
specialvar VAR_RESULT, ShouldDistributeEonTicket specialvar VAR_RESULT, ShouldDistributeEonTicket
compare VAR_RESULT, TRUE compare VAR_RESULT, TRUE
goto_if_eq CableClub_EventScript_ShowMysteryGiftMan goto_if_eq CableClub_EventScript_ShowMysteryGiftMan
specialvar VAR_RESULT, ValidateReceivedWonderCard specialvar VAR_RESULT, ValidateSavedWonderCard
compare VAR_RESULT, FALSE compare VAR_RESULT, FALSE
goto_if_eq CableClub_EventScript_HideMysteryGiftMan goto_if_eq CableClub_EventScript_HideMysteryGiftMan
goto CableClub_EventScript_ShowMysteryGiftMan goto CableClub_EventScript_ShowMysteryGiftMan

View File

@ -434,7 +434,7 @@ gSpecials::
def_special ChooseMonForWirelessMinigame def_special ChooseMonForWirelessMinigame
def_special Script_ResetUnionRoomTrade def_special Script_ResetUnionRoomTrade
def_special IsBadEggInParty def_special IsBadEggInParty
def_special ValidateReceivedWonderCard def_special ValidateSavedWonderCard
def_special HasAtLeastOneBerry def_special HasAtLeastOneBerry
def_special IsPokemonJumpSpeciesInParty def_special IsPokemonJumpSpeciesInParty
def_special ShowPokemonJumpRecords def_special ShowPokemonJumpRecords

View File

@ -338,23 +338,24 @@
#define FLAG_RECEIVED_AURORA_TICKET 0x13A #define FLAG_RECEIVED_AURORA_TICKET 0x13A
#define FLAG_RECEIVED_MYSTIC_TICKET 0x13B #define FLAG_RECEIVED_MYSTIC_TICKET 0x13B
#define FLAG_RECEIVED_OLD_SEA_MAP 0x13C #define FLAG_RECEIVED_OLD_SEA_MAP 0x13C
#define FLAG_UNUSED_MYSTERY_GIFT_0x13D 0x13D #define FLAG_MYSTERY_GIFT_UNUSED_1 0x13D // These mystery gift flags are referenced but never set
#define FLAG_UNUSED_MYSTERY_GIFT_0x13E 0x13E #define FLAG_MYSTERY_GIFT_UNUSED_2 0x13E
#define FLAG_UNUSED_MYSTERY_GIFT_0x13F 0x13F #define FLAG_MYSTERY_GIFT_UNUSED_3 0x13F
#define FLAG_UNUSED_MYSTERY_GIFT_0x140 0x140 #define FLAG_MYSTERY_GIFT_UNUSED_4 0x140
#define FLAG_UNUSED_MYSTERY_GIFT_0x141 0x141 #define FLAG_MYSTERY_GIFT_UNUSED_5 0x141
#define FLAG_UNUSED_MYSTERY_GIFT_0x142 0x142 #define FLAG_MYSTERY_GIFT_UNUSED_6 0x142
#define FLAG_UNUSED_MYSTERY_GIFT_0x143 0x143 #define FLAG_MYSTERY_GIFT_UNUSED_7 0x143
#define FLAG_UNUSED_MYSTERY_GIFT_0x144 0x144 #define FLAG_MYSTERY_GIFT_UNUSED_8 0x144
#define FLAG_UNUSED_MYSTERY_GIFT_0x145 0x145 #define FLAG_MYSTERY_GIFT_UNUSED_9 0x145
#define FLAG_UNUSED_MYSTERY_GIFT_0x146 0x146 #define FLAG_MYSTERY_GIFT_UNUSED_10 0x146
#define FLAG_UNUSED_MYSTERY_GIFT_0x147 0x147 #define FLAG_MYSTERY_GIFT_UNUSED_11 0x147
#define FLAG_UNUSED_MYSTERY_GIFT_0x148 0x148 #define FLAG_MYSTERY_GIFT_UNUSED_12 0x148
#define FLAG_UNUSED_MYSTERY_GIFT_0x149 0x149 #define FLAG_MYSTERY_GIFT_UNUSED_13 0x149
#define FLAG_UNUSED_MYSTERY_GIFT_0x14A 0x14A #define FLAG_MYSTERY_GIFT_UNUSED_14 0x14A
#define FLAG_UNUSED_MYSTERY_GIFT_0x14B 0x14B #define FLAG_MYSTERY_GIFT_UNUSED_15 0x14B
#define FLAG_UNUSED_MYSTERY_GIFT_0x14C 0x14C #define FLAG_MYSTERY_GIFT_UNUSED_16 0x14C
#define FLAG_UNUSED_MYSTERY_GIFT_0x14D 0x14D #define FLAG_MYSTERY_GIFT_UNUSED_17 0x14D
#define NUM_MYSTERY_GIFT_FLAGS (1 + FLAG_MYSTERY_GIFT_UNUSED_17 - FLAG_RECEIVED_AURORA_TICKET)
#define FLAG_MIRAGE_TOWER_VISIBLE 0x14E #define FLAG_MIRAGE_TOWER_VISIBLE 0x14E
#define FLAG_CHOSE_ROOT_FOSSIL 0x14F #define FLAG_CHOSE_ROOT_FOSSIL 0x14F

View File

@ -854,15 +854,9 @@ struct MysteryEventStruct
u8 unk_2C[10][WONDER_NEWS_TEXT_LENGTH]; u8 unk_2C[10][WONDER_NEWS_TEXT_LENGTH];
}; };
struct WonderNewsSaveStruct
{
u32 crc;
struct WonderNews data;
};
struct WonderCard struct WonderCard
{ {
u16 unk_00; u16 flagId;
u16 unk_02; u16 unk_02;
u32 unk_04; u32 unk_04;
u8 unk_08_0:2; u8 unk_08_0:2;
@ -876,13 +870,7 @@ struct MysteryEventStruct
u8 unk_122[WONDER_CARD_TEXT_LENGTH]; u8 unk_122[WONDER_CARD_TEXT_LENGTH];
}; };
struct WonderCardSaveStruct struct MEventBuffer_3430
{
u32 crc;
struct WonderCard data;
};
struct MEventBuffer_3430_Sub
{ {
u16 unk_00; u16 unk_00;
u16 unk_02; u16 unk_02;
@ -891,20 +879,17 @@ struct MysteryEventStruct
u16 unk_08[2][7]; u16 unk_08[2][7];
}; };
struct MEventBuffer_3430 struct MysteryGiftSave
{ {
u32 crc; u32 newsCrc;
struct MEventBuffer_3430_Sub data; struct WonderNews news;
}; u32 cardCrc;
struct WonderCard card;
struct MEventBuffers u32 unkCrc;
{ struct MEventBuffer_3430 unk_3430;
/*0x000 0x322C*/ struct WonderNewsSaveStruct wonderNews; u16 questionnaireWords[NUM_QUESTIONNAIRE_WORDS];
/*0x1c0 0x33EC*/ struct WonderCardSaveStruct wonderCard; struct MysteryEventStruct unk_340;
/*0x310 0x353C*/ struct MEventBuffer_3430 buffer_310; u32 unk_344[2][5];
/*0x338 0x3564*/ u16 questionnaireWords[NUM_QUESTIONNAIRE_WORDS];
/*0x340 0x356C*/ struct MysteryEventStruct unk_340;
/*0x344 0x3570*/ u32 unk_344[2][5];
}; // 0x36C 0x3598 }; // 0x36C 0x3598
// For external event data storage. The majority of these may have never been used. // For external event data storage. The majority of these may have never been used.
@ -1031,7 +1016,7 @@ struct SaveBlock1
/*0x31C7*/ struct ExternalEventFlags externalEventFlags; /*0x31C7*/ struct ExternalEventFlags externalEventFlags;
/*0x31DC*/ struct Roamer roamer; /*0x31DC*/ struct Roamer roamer;
/*0x31F8*/ struct EnigmaBerry enigmaBerry; /*0x31F8*/ struct EnigmaBerry enigmaBerry;
/*0x322C*/ struct MEventBuffers unk_322C; /*0x322C*/ struct MysteryGiftSave mysteryGift;
/*0x3598*/ u8 field_3598[0x180]; /*0x3598*/ u8 field_3598[0x180];
/*0x3718*/ u32 trainerHillTimes[4]; /*0x3718*/ u32 trainerHillTimes[4];
/*0x3728*/ struct RamScript ramScript; /*0x3728*/ struct RamScript ramScript;

View File

@ -21,30 +21,30 @@ struct MEventStruct_Unk1442CC
u16 unk_0C; u16 unk_0C;
u32 unk_10; u32 unk_10;
u16 unk_14; u16 unk_14;
u16 unk_16[NUM_QUESTIONNAIRE_WORDS]; u16 questionnaireWords[NUM_QUESTIONNAIRE_WORDS];
struct MEventBuffer_3430_Sub unk_20; struct MEventBuffer_3430 unk_20;
u8 unk_44; u8 unk_44;
u8 unk_45[7]; u8 playerName[PLAYER_NAME_LENGTH];
u8 unk_4C[4]; u8 playerTrainerId[TRAINER_ID_LENGTH];
u16 unk_50[6]; u16 easyChatProfile[EASY_CHAT_BATTLE_WORDS_COUNT];
u8 unk_5C[4]; u8 romHeaderGameCode[4];
u8 unk_60; u8 romHeaderSoftwareVersion;
}; };
void sub_801AFD8(void); void sub_801AFD8(void);
struct WonderNews *GetSavedWonderNews(void); struct WonderNews *GetSavedWonderNews(void);
struct WonderCard *GetSavedWonderCard(void); struct WonderCard *GetSavedWonderCard(void);
struct MEventBuffer_3430_Sub *sav1_get_mevent_buffer_2(void); struct MEventBuffer_3430 *sav1_get_mevent_buffer_2(void);
struct MysteryEventStruct *sub_801B044(void); struct MysteryEventStruct *sub_801B044(void);
u16 *GetQuestionnaireWordsPtr(void); u16 *GetQuestionnaireWordsPtr(void);
void DestroyWonderNews(void); void ClearSavedWonderNews(void);
bool32 sub_801B078(const struct WonderNews *src); bool32 SaveWonderNews(const struct WonderNews *news);
bool32 ValidateReceivedWonderNews(void); bool32 ValidateSavedWonderNews(void);
bool32 WonderNews_Test_Unk_02(void); bool32 WonderNews_Test_Unk_02(void);
bool32 sub_801B1A4(const u8 *src); bool32 sub_801B1A4(const u8 *src);
void DestroyWonderCard(void); void ClearSavedWonderCard(void);
bool32 sub_801B21C(const struct WonderCard *data); bool32 SaveWonderCard(const struct WonderCard *card);
bool32 ValidateReceivedWonderCard(void); bool32 ValidateSavedWonderCard(void);
bool32 WonderCard_Test_Unk_08_6(void); bool32 WonderCard_Test_Unk_08_6(void);
u16 GetWonderCardFlagID(void); u16 GetWonderCardFlagID(void);
void WonderCard_ResetInternalReceivedFlag(struct WonderCard *buffer); void WonderCard_ResetInternalReceivedFlag(struct WonderCard *buffer);
@ -54,7 +54,7 @@ void sub_801B580(struct MEventStruct_Unk1442CC *data, bool32 a1);
bool32 sub_801B6A0(const struct MEventStruct_Unk1442CC *data, bool32 a1); bool32 sub_801B6A0(const struct MEventStruct_Unk1442CC *data, bool32 a1);
u32 sub_801B6EC(const u16 *a0, const struct MEventStruct_Unk1442CC *a1, const void *unused); u32 sub_801B6EC(const u16 *a0, const struct MEventStruct_Unk1442CC *a1, const void *unused);
u32 sub_801B708(const u16 *a0, const struct MEventStruct_Unk1442CC *a1, const void *unused); u32 sub_801B708(const u16 *a0, const struct MEventStruct_Unk1442CC *a1, const void *unused);
bool32 MEventStruct_Unk1442CC_CompareField_unk_16(const struct MEventStruct_Unk1442CC *a0, const u16 *a1); bool32 MysteryGift_DoesQuestionnaireMatch(const struct MEventStruct_Unk1442CC *data, const u16 *words);
u16 MEventStruct_Unk1442CC_GetValueNFrom_unk_20(const struct MEventStruct_Unk1442CC *a0, u32 command); u16 MEventStruct_Unk1442CC_GetValueNFrom_unk_20(const struct MEventStruct_Unk1442CC *a0, u32 command);
u16 mevent_081445C0(u32 command); u16 mevent_081445C0(u32 command);
void ResetReceivedWonderCardFlag(void); void ResetReceivedWonderCardFlag(void);

View File

@ -3,31 +3,68 @@
#include "mevent_server_helpers.h" #include "mevent_server_helpers.h"
struct mevent_client_cmd // Return values for client functions called by MysteryGiftClient_Run
enum {
CLI_RET_INIT,
CLI_RET_1,
CLI_RET_2,
CLI_RET_3,
CLI_RET_ASK_TOSS,
CLI_RET_5,
CLI_RET_END,
};
// IDs for client script instructions
enum {
CLI_NONE,
CLI_RETURN,
CLI_RECV,
CLI_SEND_LOADED,
CLI_COPY_RECV,
CLI_5,
CLI_COPY_RECV_IF_N,
CLI_COPY_RECV_IF,
CLI_8,
CLI_9,
CLI_10,
CLI_11,
CLI_12,
CLI_ASK_TOSS,
CLI_LOAD_TOSS_RESPONSE,
CLI_15,
CLI_16,
CLI_17,
CLI_RECV_EREADER_TRAINER,
CLI_SEND_STAT,
CLI_20,
CLI_21,
};
struct MysteryGiftClientCmd
{ {
u32 instr; u32 instr;
u32 parameter; u32 parameter;
}; };
struct mevent_client struct MysteryGiftClient
{ {
u32 unk_00; u32 unk_00;
u32 param; u32 param;
u32 mainseqno; u32 funcId;
u32 flag; u32 funcState;
u32 cmdidx; u32 cmdidx;
void * sendBuffer; void * sendBuffer;
void * recvBuffer; void * recvBuffer;
struct mevent_client_cmd * cmdBuffer; struct MysteryGiftClientCmd * cmdBuffer;
void * buffer; void * buffer;
struct mevent_srv_sub manager; struct MysteryGiftLink link;
u32 unk_4C; bool32 isWonderNews;
}; };
void mevent_client_do_init(u32 arg); void MysteryGiftClient_Create(bool32 isWonderNews);
u32 mevent_client_do_exec(u16 * a0); u32 MysteryGiftClient_Run(u16 * param);
void mevent_client_inc_flag(void); void MysteryGiftClient_AdvanceState(void);
void * mevent_client_get_buffer(void); void * mevent_client_get_buffer(void);
void mevent_client_set_param(u32 a0); void MysteryGiftClient_SetParam(u32 value);
#endif //GUARD_MEVENT_CLIENT_H #endif //GUARD_MEVENT_CLIENT_H

View File

@ -26,7 +26,7 @@ struct mevent_srv_common
const void * sendBuffer2; const void * sendBuffer2;
u32 sendBuffer2Size; u32 sendBuffer2Size;
u32 sendWord; u32 sendWord;
struct mevent_srv_sub manager; struct MysteryGiftLink manager;
}; };
void mevent_srv_new_wcard(); void mevent_srv_new_wcard();

View File

@ -3,7 +3,7 @@
#define ME_SEND_BUF_SIZE 0x400 #define ME_SEND_BUF_SIZE 0x400
struct mevent_srv_sub struct MysteryGiftLink
{ {
s32 seqno; s32 seqno;
u8 sendPlayerNo; u8 sendPlayerNo;
@ -18,8 +18,8 @@ struct mevent_srv_sub
u16 sendSize; u16 sendSize;
void * recvBfr; void * recvBfr;
const void * sendBfr; const void * sendBfr;
u32 (*recvFunc)(struct mevent_srv_sub *); u32 (*recvFunc)(struct MysteryGiftLink *);
u32 (*sendFunc)(struct mevent_srv_sub *); u32 (*sendFunc)(struct MysteryGiftLink *);
}; };
struct send_recv_header struct send_recv_header
@ -29,10 +29,10 @@ struct send_recv_header
u16 size; u16 size;
}; };
void mevent_srv_sub_init(struct mevent_srv_sub *, u32, u32); void MysteryGiftLink_Init(struct MysteryGiftLink *, u32, u32);
void mevent_srv_sub_init_send(struct mevent_srv_sub * manager, u32 ident, const void * src, u32 size); void MysteryGiftLink_InitSend(struct MysteryGiftLink * manager, u32 ident, const void * src, u32 size);
bool32 mevent_srv_sub_recv(struct mevent_srv_sub * manager); bool32 MysteryGiftLink_Recv(struct MysteryGiftLink * manager);
bool32 mevent_srv_sub_send(struct mevent_srv_sub * manager); bool32 MysteryGiftLink_Send(struct MysteryGiftLink * manager);
void mevent_srv_sub_init_recv(struct mevent_srv_sub *, u32, void *); void MysteryGiftLink_InitRecv(struct MysteryGiftLink *, u32, void *);
#endif //GUARD_MEVENT_SERVER_HELPERS_H #endif //GUARD_MEVENT_SERVER_HELPERS_H

View File

@ -1,8 +1,8 @@
#ifndef GUARD_MYSTERY_EVENT_SCRIPT_H #ifndef GUARD_MYSTERY_EVENT_SCRIPT_H
#define GUARD_MYSTERY_EVENT_SCRIPT_H #define GUARD_MYSTERY_EVENT_SCRIPT_H
void sub_8153870(u8 *script); void InitMysteryGiftScriptContext(u8 *script);
bool32 sub_8153884(u32 *a0); bool32 RunMysteryGiftScriptContextCommand(u32 *script);
u32 RunMysteryEventScript(u8 *script); u32 RunMysteryEventScript(u8 *script);
void SetMysteryEventScriptStatus(u32 val); void SetMysteryEventScriptStatus(u32 val);
u16 GetRecordMixingGift(void); u16 GetRecordMixingGift(void);

View File

@ -9,7 +9,7 @@ enum {
NEWS_INPUT_NONE = 0xFF NEWS_INPUT_NONE = 0xFF
}; };
bool32 WonderCard_Init(struct WonderCard * card, struct MEventBuffer_3430_Sub * r6); bool32 WonderCard_Init(struct WonderCard * card, struct MEventBuffer_3430 * r6);
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

@ -94,7 +94,7 @@ GPIOPortReadEnable: @ 80000C8
.byte 0x1e, 0x1e, 0x10, 0x40 .byte 0x1e, 0x1e, 0x10, 0x40
.4byte 0x0000322e @ offsetof(struct SaveBlock1, ? part-way into unk_322C) .4byte 0x0000322e @ offsetof(struct SaveBlock1, ? part-way into mysteryGift)
.4byte 0x00000498 @ offsetof(struct SaveBlock1, pcItems) .4byte 0x00000498 @ offsetof(struct SaveBlock1, pcItems)
.4byte 0x000031a8 @ offsetof(struct SaveBlock1, giftRibbons) .4byte 0x000031a8 @ offsetof(struct SaveBlock1, giftRibbons)
.4byte 0x000031f8 @ offsetof(struct SaveBlock1, enigmaBerry) .4byte 0x000031f8 @ offsetof(struct SaveBlock1, enigmaBerry)

View File

@ -14,73 +14,75 @@
static EWRAM_DATA bool32 gUnknown_02022C70 = FALSE; static EWRAM_DATA bool32 gUnknown_02022C70 = FALSE;
static void sub_801B180(void); static void sub_801B180(void);
static void s_DestroyWonderNews(void); static void ClearSavedWonderNewsInternal(void);
static bool32 sub_801B114(const struct WonderNews *data); static bool32 ValidateWonderNews(const struct WonderNews *news);
static bool32 ValidateWonderCardData(const struct WonderCard *data); static bool32 ValidateWonderCard(const struct WonderCard *card);
static void sub_801B330(void); static void InitSavedWonderCard(void);
static void sub_801B368(void); static void sub_801B368(void);
static void sub_801B9F8(void); static void sub_801B9F8(void);
static void sub_801BA8C(u32 a0, u32 a1, u32 *a2, int a3); static void sub_801BA8C(u32 a0, u32 a1, u32 *a2, int a3);
#define CALC_CRC(data) CalcCRC16WithTable((void *)&(data), sizeof(data))
void sub_801AFD8(void) void sub_801AFD8(void)
{ {
CpuFill32(0, &gSaveBlock1Ptr->unk_322C, sizeof(gSaveBlock1Ptr->unk_322C)); CpuFill32(0, &gSaveBlock1Ptr->mysteryGift, sizeof(gSaveBlock1Ptr->mysteryGift));
sub_801B180(); sub_801B180();
InitQuestionnaireWords(); InitQuestionnaireWords();
} }
struct WonderNews *GetSavedWonderNews(void) struct WonderNews *GetSavedWonderNews(void)
{ {
return &gSaveBlock1Ptr->unk_322C.wonderNews.data; return &gSaveBlock1Ptr->mysteryGift.news;
} }
struct WonderCard *GetSavedWonderCard(void) struct WonderCard *GetSavedWonderCard(void)
{ {
return &gSaveBlock1Ptr->unk_322C.wonderCard.data; return &gSaveBlock1Ptr->mysteryGift.card;
} }
struct MEventBuffer_3430_Sub *sav1_get_mevent_buffer_2(void) struct MEventBuffer_3430 *sav1_get_mevent_buffer_2(void)
{ {
return &gSaveBlock1Ptr->unk_322C.buffer_310.data; return &gSaveBlock1Ptr->mysteryGift.unk_3430;
} }
struct MysteryEventStruct *sub_801B044(void) struct MysteryEventStruct *sub_801B044(void)
{ {
return &gSaveBlock1Ptr->unk_322C.unk_340; return &gSaveBlock1Ptr->mysteryGift.unk_340;
} }
u16 *GetQuestionnaireWordsPtr(void) u16 *GetQuestionnaireWordsPtr(void)
{ {
return gSaveBlock1Ptr->unk_322C.questionnaireWords; return gSaveBlock1Ptr->mysteryGift.questionnaireWords;
} }
void DestroyWonderNews(void) void ClearSavedWonderNews(void)
{ {
s_DestroyWonderNews(); ClearSavedWonderNewsInternal();
} }
bool32 sub_801B078(const struct WonderNews *src) bool32 SaveWonderNews(const struct WonderNews *news)
{ {
if (!sub_801B114(src)) if (!ValidateWonderNews(news))
return FALSE; return FALSE;
s_DestroyWonderNews(); ClearSavedWonderNewsInternal();
gSaveBlock1Ptr->unk_322C.wonderNews.data = *src; gSaveBlock1Ptr->mysteryGift.news = *news;
gSaveBlock1Ptr->unk_322C.wonderNews.crc = CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_322C.wonderNews.data, sizeof(struct WonderNews)); gSaveBlock1Ptr->mysteryGift.newsCrc = CALC_CRC(gSaveBlock1Ptr->mysteryGift.news);
return TRUE; return TRUE;
} }
bool32 ValidateReceivedWonderNews(void) bool32 ValidateSavedWonderNews(void)
{ {
if (CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_322C.wonderNews.data, sizeof(struct WonderNews)) != gSaveBlock1Ptr->unk_322C.wonderNews.crc) if (CALC_CRC(gSaveBlock1Ptr->mysteryGift.news) != gSaveBlock1Ptr->mysteryGift.newsCrc)
return FALSE; return FALSE;
if (!sub_801B114(&gSaveBlock1Ptr->unk_322C.wonderNews.data)) if (!ValidateWonderNews(&gSaveBlock1Ptr->mysteryGift.news))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
static bool32 sub_801B114(const struct WonderNews *data) static bool32 ValidateWonderNews(const struct WonderNews *data)
{ {
if (data->unk_00 == 0) if (data->unk_00 == 0)
return FALSE; return FALSE;
@ -90,17 +92,17 @@ static bool32 sub_801B114(const struct WonderNews *data)
bool32 WonderNews_Test_Unk_02(void) bool32 WonderNews_Test_Unk_02(void)
{ {
const struct WonderNews *data = &gSaveBlock1Ptr->unk_322C.wonderNews.data; const struct WonderNews *data = &gSaveBlock1Ptr->mysteryGift.news;
if (data->unk_02 == 0) if (data->unk_02 == 0)
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
static void s_DestroyWonderNews(void) static void ClearSavedWonderNewsInternal(void)
{ {
CpuFill32(0, GetSavedWonderNews(), sizeof(gSaveBlock1Ptr->unk_322C.wonderNews.data)); CpuFill32(0, GetSavedWonderNews(), sizeof(gSaveBlock1Ptr->mysteryGift.news));
gSaveBlock1Ptr->unk_322C.wonderNews.crc = 0; gSaveBlock1Ptr->mysteryGift.newsCrc = 0;
} }
static void sub_801B180(void) static void sub_801B180(void)
@ -111,9 +113,9 @@ static void sub_801B180(void)
bool32 sub_801B1A4(const u8 *src) bool32 sub_801B1A4(const u8 *src)
{ {
const u8 *r5 = (const u8 *)&gSaveBlock1Ptr->unk_322C.wonderNews.data; const u8 *r5 = (const u8 *)&gSaveBlock1Ptr->mysteryGift.news;
u32 i; u32 i;
if (!ValidateReceivedWonderNews()) if (!ValidateSavedWonderNews())
return FALSE; return FALSE;
for (i = 0; i < sizeof(struct WonderNews); i++) for (i = 0; i < sizeof(struct WonderNews); i++)
@ -125,9 +127,9 @@ bool32 sub_801B1A4(const u8 *src)
return TRUE; return TRUE;
} }
void DestroyWonderCard(void) void ClearSavedWonderCard(void)
{ {
sub_801B330(); InitSavedWonderCard();
sub_801B368(); sub_801B368();
sub_801B9F8(); sub_801B9F8();
ClearRamScript(); ClearRamScript();
@ -136,27 +138,25 @@ void DestroyWonderCard(void)
ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer); ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer);
} }
bool32 sub_801B21C(const struct WonderCard *data) bool32 SaveWonderCard(const struct WonderCard *card)
{ {
struct MEventBuffer_3430_Sub *r2; struct MEventBuffer_3430 *r2;
struct WonderCard *r1; if (!ValidateWonderCard(card))
if (!ValidateWonderCardData(data))
return FALSE; return FALSE;
DestroyWonderCard(); ClearSavedWonderCard();
memcpy(&gSaveBlock1Ptr->unk_322C.wonderCard.data, data, sizeof(struct WonderCard)); memcpy(&gSaveBlock1Ptr->mysteryGift.card, card, sizeof(struct WonderCard));
gSaveBlock1Ptr->unk_322C.wonderCard.crc = CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_322C.wonderCard.data, sizeof(struct WonderCard)); gSaveBlock1Ptr->mysteryGift.cardCrc = CALC_CRC(gSaveBlock1Ptr->mysteryGift.card);
r2 = &gSaveBlock1Ptr->unk_322C.buffer_310.data; r2 = &gSaveBlock1Ptr->mysteryGift.unk_3430;
r1 = &gSaveBlock1Ptr->unk_322C.wonderCard.data; r2->unk_06 = (&gSaveBlock1Ptr->mysteryGift.card)->unk_02;
r2->unk_06 = r1->unk_02;
return TRUE; return TRUE;
} }
bool32 ValidateReceivedWonderCard(void) bool32 ValidateSavedWonderCard(void)
{ {
if (gSaveBlock1Ptr->unk_322C.wonderCard.crc != CalcCRC16WithTable((void *)&gSaveBlock1Ptr->unk_322C.wonderCard.data, sizeof(struct WonderCard))) if (gSaveBlock1Ptr->mysteryGift.cardCrc != CALC_CRC(gSaveBlock1Ptr->mysteryGift.card))
return FALSE; return FALSE;
if (!ValidateWonderCardData(&gSaveBlock1Ptr->unk_322C.wonderCard.data)) if (!ValidateWonderCard(&gSaveBlock1Ptr->mysteryGift.card))
return FALSE; return FALSE;
if (!ValidateSavedRamScript()) if (!ValidateSavedRamScript())
return FALSE; return FALSE;
@ -164,17 +164,17 @@ bool32 ValidateReceivedWonderCard(void)
return TRUE; return TRUE;
} }
static bool32 ValidateWonderCardData(const struct WonderCard *data) static bool32 ValidateWonderCard(const struct WonderCard *card)
{ {
if (data->unk_00 == 0) if (card->flagId == 0)
return FALSE; return FALSE;
if (data->unk_08_0 > 2) if (card->unk_08_0 > 2)
return FALSE; return FALSE;
if (!(data->unk_08_6 == 0 || data->unk_08_6 == 1 || data->unk_08_6 == 2)) if (!(card->unk_08_6 == 0 || card->unk_08_6 == 1 || card->unk_08_6 == 2))
return FALSE; return FALSE;
if (data->bgType >= NUM_WONDER_BGS) if (card->bgType >= NUM_WONDER_BGS)
return FALSE; return FALSE;
if (data->unk_09 > 7) if (card->unk_09 > 7)
return FALSE; return FALSE;
return TRUE; return TRUE;
@ -182,29 +182,29 @@ static bool32 ValidateWonderCardData(const struct WonderCard *data)
bool32 WonderCard_Test_Unk_08_6(void) bool32 WonderCard_Test_Unk_08_6(void)
{ {
const struct WonderCard *data = &gSaveBlock1Ptr->unk_322C.wonderCard.data; const struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (data->unk_08_6 == 0) if (card->unk_08_6 == 0)
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
static void sub_801B330(void) static void InitSavedWonderCard(void)
{ {
CpuFill32(0, &gSaveBlock1Ptr->unk_322C.wonderCard.data, sizeof(struct WonderCard)); CpuFill32(0, &gSaveBlock1Ptr->mysteryGift.card, sizeof(gSaveBlock1Ptr->mysteryGift.card));
gSaveBlock1Ptr->unk_322C.wonderCard.crc = 0; gSaveBlock1Ptr->mysteryGift.cardCrc = 0;
} }
static void sub_801B368(void) static void sub_801B368(void)
{ {
CpuFill32(0, sav1_get_mevent_buffer_2(), 18 *sizeof(u16)); CpuFill32(0, sav1_get_mevent_buffer_2(), 18 *sizeof(u16));
gSaveBlock1Ptr->unk_322C.buffer_310.crc = 0; gSaveBlock1Ptr->mysteryGift.unkCrc = 0;
} }
u16 GetWonderCardFlagID(void) u16 GetWonderCardFlagID(void)
{ {
if (ValidateReceivedWonderCard()) if (ValidateSavedWonderCard())
return gSaveBlock1Ptr->unk_322C.wonderCard.data.unk_00; return gSaveBlock1Ptr->mysteryGift.card.flagId;
return 0; return 0;
} }
@ -215,9 +215,9 @@ void WonderCard_ResetInternalReceivedFlag(struct WonderCard *buffer)
buffer->unk_08_6 = 0; buffer->unk_08_6 = 0;
} }
static bool32 IsWonderCardFlagIDInValidRange(u16 a0) static bool32 IsWonderCardFlagIDInValidRange(u16 flagId)
{ {
if (a0 >= 1000 && a0 < 1020) if (flagId >= 1000 && flagId < 1000 + NUM_MYSTERY_GIFT_FLAGS)
return TRUE; return TRUE;
return FALSE; return FALSE;
@ -228,23 +228,23 @@ static const u16 sMysteryGiftFlags[] =
FLAG_RECEIVED_AURORA_TICKET, FLAG_RECEIVED_AURORA_TICKET,
FLAG_RECEIVED_MYSTIC_TICKET, FLAG_RECEIVED_MYSTIC_TICKET,
FLAG_RECEIVED_OLD_SEA_MAP, FLAG_RECEIVED_OLD_SEA_MAP,
FLAG_UNUSED_MYSTERY_GIFT_0x13D, FLAG_MYSTERY_GIFT_UNUSED_1,
FLAG_UNUSED_MYSTERY_GIFT_0x13E, FLAG_MYSTERY_GIFT_UNUSED_2,
FLAG_UNUSED_MYSTERY_GIFT_0x13F, FLAG_MYSTERY_GIFT_UNUSED_3,
FLAG_UNUSED_MYSTERY_GIFT_0x140, FLAG_MYSTERY_GIFT_UNUSED_4,
FLAG_UNUSED_MYSTERY_GIFT_0x141, FLAG_MYSTERY_GIFT_UNUSED_5,
FLAG_UNUSED_MYSTERY_GIFT_0x142, FLAG_MYSTERY_GIFT_UNUSED_6,
FLAG_UNUSED_MYSTERY_GIFT_0x143, FLAG_MYSTERY_GIFT_UNUSED_7,
FLAG_UNUSED_MYSTERY_GIFT_0x144, FLAG_MYSTERY_GIFT_UNUSED_8,
FLAG_UNUSED_MYSTERY_GIFT_0x145, FLAG_MYSTERY_GIFT_UNUSED_9,
FLAG_UNUSED_MYSTERY_GIFT_0x146, FLAG_MYSTERY_GIFT_UNUSED_10,
FLAG_UNUSED_MYSTERY_GIFT_0x147, FLAG_MYSTERY_GIFT_UNUSED_11,
FLAG_UNUSED_MYSTERY_GIFT_0x148, FLAG_MYSTERY_GIFT_UNUSED_12,
FLAG_UNUSED_MYSTERY_GIFT_0x149, FLAG_MYSTERY_GIFT_UNUSED_13,
FLAG_UNUSED_MYSTERY_GIFT_0x14A, FLAG_MYSTERY_GIFT_UNUSED_14,
FLAG_UNUSED_MYSTERY_GIFT_0x14B, FLAG_MYSTERY_GIFT_UNUSED_15,
FLAG_UNUSED_MYSTERY_GIFT_0x14C, FLAG_MYSTERY_GIFT_UNUSED_16,
FLAG_UNUSED_MYSTERY_GIFT_0x14D, FLAG_MYSTERY_GIFT_UNUSED_17,
}; };
bool32 CheckReceivedGiftFromWonderCard(void) bool32 CheckReceivedGiftFromWonderCard(void)
@ -259,7 +259,7 @@ bool32 CheckReceivedGiftFromWonderCard(void)
return TRUE; return TRUE;
} }
static int sub_801B438(const struct MEventBuffer_3430_Sub *data, int size) static int sub_801B438(const struct MEventBuffer_3430 *data, int size)
{ {
int r3 = 0; int r3 = 0;
int i; int i;
@ -272,7 +272,7 @@ static int sub_801B438(const struct MEventBuffer_3430_Sub *data, int size)
return r3; return r3;
} }
static bool32 sub_801B460(const struct MEventBuffer_3430_Sub *data1, const u16 *data2, int size) static bool32 sub_801B460(const struct MEventBuffer_3430 *data1, const u16 *data2, int size)
{ {
int i; int i;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
@ -300,33 +300,33 @@ static bool32 sub_801B4A4(const u16 *data)
static int sub_801B4CC(void) static int sub_801B4CC(void)
{ {
struct WonderCard *data; struct WonderCard *data;
if (!ValidateReceivedWonderCard()) if (!ValidateSavedWonderCard())
return 0; return 0;
data = &gSaveBlock1Ptr->unk_322C.wonderCard.data; data = &gSaveBlock1Ptr->mysteryGift.card;
if (data->unk_08_0 != 1) if (data->unk_08_0 != 1)
return 0; return 0;
return sub_801B438(&gSaveBlock1Ptr->unk_322C.buffer_310.data, data->unk_09); return sub_801B438(&gSaveBlock1Ptr->mysteryGift.unk_3430, data->unk_09);
} }
bool32 sub_801B508(const u16 *data) bool32 sub_801B508(const u16 *data)
{ {
struct WonderCard *buffer = &gSaveBlock1Ptr->unk_322C.wonderCard.data; struct WonderCard *buffer = &gSaveBlock1Ptr->mysteryGift.card;
int size = buffer->unk_09; int size = buffer->unk_09;
int i; int i;
if (!sub_801B4A4(data)) if (!sub_801B4A4(data))
return FALSE; return FALSE;
if (sub_801B460(&gSaveBlock1Ptr->unk_322C.buffer_310.data, data, size)) if (sub_801B460(&gSaveBlock1Ptr->mysteryGift.unk_3430, data, size))
return FALSE; return FALSE;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
if (gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_08[1][i] == 0 && gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_08[0][i] == 0) if (gSaveBlock1Ptr->mysteryGift.unk_3430.unk_08[1][i] == 0 && gSaveBlock1Ptr->mysteryGift.unk_3430.unk_08[0][i] == 0)
{ {
gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_08[1][i] = data[1]; gSaveBlock1Ptr->mysteryGift.unk_3430.unk_08[1][i] = data[1];
gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_08[0][i] = data[0]; gSaveBlock1Ptr->mysteryGift.unk_3430.unk_08[0][i] = data[0];
return TRUE; return TRUE;
} }
} }
@ -334,7 +334,7 @@ bool32 sub_801B508(const u16 *data)
return FALSE; return FALSE;
} }
void sub_801B580(struct MEventStruct_Unk1442CC *data, bool32 a1) void sub_801B580(struct MEventStruct_Unk1442CC *data, bool32 isWonderNews)
{ {
int i; int i;
CpuFill32(0, data, sizeof(struct MEventStruct_Unk1442CC)); CpuFill32(0, data, sizeof(struct MEventStruct_Unk1442CC));
@ -342,20 +342,20 @@ void sub_801B580(struct MEventStruct_Unk1442CC *data, bool32 a1)
data->unk_04 = 1; data->unk_04 = 1;
data->unk_08 = 1; data->unk_08 = 1;
if (a1) if (isWonderNews)
{ {
data->unk_0C = 5; data->unk_0C = 5;
data->unk_10 = 0x0201; data->unk_10 = 0x0201;
} }
else else // Wonder Card
{ {
data->unk_0C = 4; data->unk_0C = 4;
data->unk_10 = 0x0200; data->unk_10 = 0x0200;
} }
if (ValidateReceivedWonderCard()) if (ValidateSavedWonderCard())
{ {
data->unk_14 = GetSavedWonderCard()->unk_00; data->unk_14 = GetSavedWonderCard()->flagId;
data->unk_20 = *sav1_get_mevent_buffer_2(); data->unk_20 = *sav1_get_mevent_buffer_2();
data->unk_44 = GetSavedWonderCard()->unk_09; data->unk_44 = GetSavedWonderCard()->unk_09;
} }
@ -365,15 +365,15 @@ void sub_801B580(struct MEventStruct_Unk1442CC *data, bool32 a1)
} }
for (i = 0; i < NUM_QUESTIONNAIRE_WORDS; i++) for (i = 0; i < NUM_QUESTIONNAIRE_WORDS; i++)
data->unk_16[i] = gSaveBlock1Ptr->unk_322C.questionnaireWords[i]; data->questionnaireWords[i] = gSaveBlock1Ptr->mysteryGift.questionnaireWords[i];
CopyTrainerId(data->unk_4C, gSaveBlock2Ptr->playerTrainerId); CopyTrainerId(data->playerTrainerId, gSaveBlock2Ptr->playerTrainerId);
StringCopy(data->unk_45, gSaveBlock2Ptr->playerName); StringCopy(data->playerName, gSaveBlock2Ptr->playerName);
for (i = 0; i < 6; i++) for (i = 0; i < EASY_CHAT_BATTLE_WORDS_COUNT; i++)
data->unk_50[i] = gSaveBlock1Ptr->easyChatProfile[i]; data->easyChatProfile[i] = gSaveBlock1Ptr->easyChatProfile[i];
memcpy(data->unk_5C, RomHeaderGameCode, 4); memcpy(data->romHeaderGameCode, RomHeaderGameCode, 4);
data->unk_60 = RomHeaderSoftwareVersion; data->romHeaderSoftwareVersion = RomHeaderSoftwareVersion;
} }
bool32 sub_801B6A0(const struct MEventStruct_Unk1442CC *data, bool32 a1) bool32 sub_801B6A0(const struct MEventStruct_Unk1442CC *data, bool32 a1)
@ -422,12 +422,12 @@ u32 sub_801B708(const u16 *a0, const struct MEventStruct_Unk1442CC *a1, const vo
return 2; return 2;
} }
bool32 MEventStruct_Unk1442CC_CompareField_unk_16(const struct MEventStruct_Unk1442CC *a0, const u16 *a1) bool32 MysteryGift_DoesQuestionnaireMatch(const struct MEventStruct_Unk1442CC *data, const u16 *words)
{ {
int i; int i;
for (i = 0; i < NUM_QUESTIONNAIRE_WORDS; i++) for (i = 0; i < NUM_QUESTIONNAIRE_WORDS; i++)
{ {
if (a0->unk_16[i] != a1[i]) if (data->questionnaireWords[i] != words[i])
return FALSE; return FALSE;
} }
@ -461,20 +461,20 @@ u16 MEventStruct_Unk1442CC_GetValueNFrom_unk_20(const struct MEventStruct_Unk144
static void sub_801B7D8(u32 command) static void sub_801B7D8(u32 command)
{ {
struct WonderCard *data = &gSaveBlock1Ptr->unk_322C.wonderCard.data; struct WonderCard *data = &gSaveBlock1Ptr->mysteryGift.card;
if (data->unk_08_0 == 2) if (data->unk_08_0 == 2)
{ {
u16 *dest = NULL; u16 *dest = NULL;
switch (command) switch (command)
{ {
case 0: case 0:
dest = &gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_00; dest = &gSaveBlock1Ptr->mysteryGift.unk_3430.unk_00;
break; break;
case 1: case 1:
dest = &gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_02; dest = &gSaveBlock1Ptr->mysteryGift.unk_3430.unk_02;
break; break;
case 2: case 2:
dest = &gSaveBlock1Ptr->unk_322C.buffer_310.data.unk_04; dest = &gSaveBlock1Ptr->mysteryGift.unk_3430.unk_04;
break; break;
case 3: case 3:
break; break;
@ -499,46 +499,46 @@ u16 mevent_081445C0(u32 command)
{ {
case GET_CARD_BATTLES_WON_INTERNAL: case GET_CARD_BATTLES_WON_INTERNAL:
{ {
struct WonderCard *data = &gSaveBlock1Ptr->unk_322C.wonderCard.data; struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (data->unk_08_0 == 2) if (card->unk_08_0 == 2)
{ {
struct MEventBuffer_3430_Sub *buffer = &gSaveBlock1Ptr->unk_322C.buffer_310.data; struct MEventBuffer_3430 *buffer = &gSaveBlock1Ptr->mysteryGift.unk_3430;
return buffer->unk_00; return buffer->unk_00;
} }
break; break;
} }
case 1: // Never occurs case 1: // Never occurs
{ {
struct WonderCard *data = &gSaveBlock1Ptr->unk_322C.wonderCard.data; struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (data->unk_08_0 == 2) if (card->unk_08_0 == 2)
{ {
struct MEventBuffer_3430_Sub *buffer = &gSaveBlock1Ptr->unk_322C.buffer_310.data; struct MEventBuffer_3430 *buffer = &gSaveBlock1Ptr->mysteryGift.unk_3430;
return buffer->unk_02; return buffer->unk_02;
} }
break; break;
} }
case 2: // Never occurs case 2: // Never occurs
{ {
struct WonderCard *data = &gSaveBlock1Ptr->unk_322C.wonderCard.data; struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (data->unk_08_0 == 2) if (card->unk_08_0 == 2)
{ {
struct MEventBuffer_3430_Sub *buffer = &gSaveBlock1Ptr->unk_322C.buffer_310.data; struct MEventBuffer_3430 *buffer = &gSaveBlock1Ptr->mysteryGift.unk_3430;
return buffer->unk_04; return buffer->unk_04;
} }
break; break;
} }
case GET_NUM_STAMPS_INTERNAL: case GET_NUM_STAMPS_INTERNAL:
{ {
struct WonderCard *data = &gSaveBlock1Ptr->unk_322C.wonderCard.data; struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (data->unk_08_0 == 1) if (card->unk_08_0 == 1)
return sub_801B4CC(); return sub_801B4CC();
break; break;
} }
case GET_MAX_STAMPS_INTERNAL: case GET_MAX_STAMPS_INTERNAL:
{ {
struct WonderCard *data = &gSaveBlock1Ptr->unk_322C.wonderCard.data; struct WonderCard *card = &gSaveBlock1Ptr->mysteryGift.card;
if (data->unk_08_0 == 1) if (card->unk_08_0 == 1)
return data->unk_09; return card->unk_09;
break; break;
} }
} }
@ -552,16 +552,16 @@ void ResetReceivedWonderCardFlag(void)
gUnknown_02022C70 = FALSE; gUnknown_02022C70 = FALSE;
} }
bool32 MEventHandleReceivedWonderCard(u16 a0) bool32 MEventHandleReceivedWonderCard(u16 flagId)
{ {
gUnknown_02022C70 = FALSE; gUnknown_02022C70 = FALSE;
if (a0 == 0) if (flagId == 0)
return FALSE; return FALSE;
if (!ValidateReceivedWonderCard()) if (!ValidateSavedWonderCard())
return FALSE; return FALSE;
if (gSaveBlock1Ptr->unk_322C.wonderCard.data.unk_00 != a0) if (gSaveBlock1Ptr->mysteryGift.card.flagId != flagId)
return FALSE; return FALSE;
gUnknown_02022C70 = TRUE; gUnknown_02022C70 = TRUE;
@ -575,13 +575,13 @@ void RecordIdOfWonderCardSenderByEventType(u32 a0, u32 a1)
switch (a0) switch (a0)
{ {
case 2: case 2:
sub_801BA8C(2, a1, gSaveBlock1Ptr->unk_322C.unk_344[1], 5); sub_801BA8C(2, a1, gSaveBlock1Ptr->mysteryGift.unk_344[1], 5);
break; break;
case 0: case 0:
sub_801BA8C(0, a1, gSaveBlock1Ptr->unk_322C.unk_344[0], 5); sub_801BA8C(0, a1, gSaveBlock1Ptr->mysteryGift.unk_344[0], 5);
break; break;
case 1: case 1:
sub_801BA8C(1, a1, gSaveBlock1Ptr->unk_322C.unk_344[0], 5); sub_801BA8C(1, a1, gSaveBlock1Ptr->mysteryGift.unk_344[0], 5);
break; break;
default: default:
AGB_ASSERT(0); AGB_ASSERT(0);
@ -591,7 +591,7 @@ void RecordIdOfWonderCardSenderByEventType(u32 a0, u32 a1)
static void sub_801B9F8(void) static void sub_801B9F8(void)
{ {
CpuFill32(0, gSaveBlock1Ptr->unk_322C.unk_344, sizeof(gSaveBlock1Ptr->unk_322C.unk_344)); CpuFill32(0, gSaveBlock1Ptr->mysteryGift.unk_344, sizeof(gSaveBlock1Ptr->mysteryGift.unk_344));
} }
static bool32 sub_801BA24(u32 a0, u32 *a1, int size) static bool32 sub_801BA24(u32 a0, u32 *a1, int size)

View File

@ -8,284 +8,292 @@
#include "mystery_event_script.h" #include "mystery_event_script.h"
#include "mevent_client.h" #include "mevent_client.h"
EWRAM_DATA struct mevent_client * s_mevent_client_ptr = NULL; enum {
FUNC_INIT,
FUNC_DONE,
FUNC_RECV,
FUNC_SEND,
FUNC_RUN,
FUNC_WAIT,
FUNC_6,
FUNC_7,
};
static void mevent_client_init(struct mevent_client *, u32, u32); EWRAM_DATA static struct MysteryGiftClient * sClient = NULL;
static u32 mevent_client_exec(struct mevent_client *);
static void mevent_client_free_resources(struct mevent_client *);
extern const struct mevent_client_cmd gUnknown_082F2598[]; static void MysteryGiftClient_Init(struct MysteryGiftClient *, u32, u32);
static u32 MysteryGiftClient_CallFunc(struct MysteryGiftClient *);
static void MysteryGiftClient_Free(struct MysteryGiftClient *);
void mevent_client_do_init(u32 arg) extern const struct MysteryGiftClientCmd gUnknown_082F2598[];
void MysteryGiftClient_Create(bool32 isWonderNews)
{ {
s_mevent_client_ptr = AllocZeroed(sizeof(struct mevent_client)); sClient = AllocZeroed(sizeof(*sClient));
mevent_client_init(s_mevent_client_ptr, 1, 0); MysteryGiftClient_Init(sClient, 1, 0);
s_mevent_client_ptr->unk_4C = arg; sClient->isWonderNews = isWonderNews;
} }
u32 mevent_client_do_exec(u16 * a0) u32 MysteryGiftClient_Run(u16 * endVal)
{ {
u32 result; u32 result;
if (s_mevent_client_ptr == NULL) if (sClient == NULL)
return 6; return CLI_RET_END;
result = mevent_client_exec(s_mevent_client_ptr); result = MysteryGiftClient_CallFunc(sClient);
if (result == 6) if (result == CLI_RET_END)
{ {
*a0 = s_mevent_client_ptr->param; *endVal = sClient->param;
mevent_client_free_resources(s_mevent_client_ptr); MysteryGiftClient_Free(sClient);
Free(s_mevent_client_ptr); Free(sClient);
s_mevent_client_ptr = NULL; sClient = NULL;
} }
return result; return result;
} }
void mevent_client_inc_flag(void) void MysteryGiftClient_AdvanceState(void)
{ {
s_mevent_client_ptr->flag++; sClient->funcState++;
} }
void * mevent_client_get_buffer(void) void * mevent_client_get_buffer(void)
{ {
return s_mevent_client_ptr->buffer; return sClient->buffer;
} }
void mevent_client_set_param(u32 a0) void MysteryGiftClient_SetParam(u32 val)
{ {
s_mevent_client_ptr->param = a0; sClient->param = val;
} }
static void mevent_client_init(struct mevent_client * svr, u32 sendPlayerNo, u32 recvPlayerNo) static void MysteryGiftClient_Init(struct MysteryGiftClient * client, u32 sendPlayerNo, u32 recvPlayerNo)
{ {
svr->unk_00 = 0; client->unk_00 = 0;
svr->mainseqno = 0; client->funcId = FUNC_INIT;
svr->flag = 0; client->funcState = 0;
svr->sendBuffer = AllocZeroed(ME_SEND_BUF_SIZE); client->sendBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->recvBuffer = AllocZeroed(ME_SEND_BUF_SIZE); client->recvBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->cmdBuffer = AllocZeroed(ME_SEND_BUF_SIZE); client->cmdBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->buffer = AllocZeroed(0x40); client->buffer = AllocZeroed(0x40);
mevent_srv_sub_init(&svr->manager, sendPlayerNo, recvPlayerNo); MysteryGiftLink_Init(&client->link, sendPlayerNo, recvPlayerNo);
} }
static void mevent_client_free_resources(struct mevent_client * svr) static void MysteryGiftClient_Free(struct MysteryGiftClient * client)
{ {
Free(svr->sendBuffer); Free(client->sendBuffer);
Free(svr->recvBuffer); Free(client->recvBuffer);
Free(svr->cmdBuffer); Free(client->cmdBuffer);
Free(svr->buffer); Free(client->buffer);
} }
static void mevent_client_jmp_buffer(struct mevent_client * svr) static void MysteryGiftClient_CopyRecvScript(struct MysteryGiftClient * client)
{ {
memcpy(svr->cmdBuffer, svr->recvBuffer, ME_SEND_BUF_SIZE); memcpy(client->cmdBuffer, client->recvBuffer, ME_SEND_BUF_SIZE);
svr->cmdidx = 0; client->cmdidx = 0;
} }
static void mevent_client_send_word(struct mevent_client * svr, u32 ident, u32 word) static void MysteryGiftClient_InitSend(struct MysteryGiftClient * client, u32 ident, u32 word)
{ {
CpuFill32(0, svr->sendBuffer, ME_SEND_BUF_SIZE); CpuFill32(0, client->sendBuffer, ME_SEND_BUF_SIZE);
*(u32 *)svr->sendBuffer = word; *(u32 *)client->sendBuffer = word;
mevent_srv_sub_init_send(&svr->manager, ident, svr->sendBuffer, sizeof(u32)); MysteryGiftLink_InitSend(&client->link, ident, client->sendBuffer, sizeof(u32));
} }
static u32 mainseq_0(struct mevent_client * svr) static u32 Client_Init(struct MysteryGiftClient * client)
{ {
// init memcpy(client->cmdBuffer, gUnknown_082F2598, ME_SEND_BUF_SIZE);
memcpy(svr->cmdBuffer, gUnknown_082F2598, ME_SEND_BUF_SIZE); client->cmdidx = 0;
svr->cmdidx = 0; client->funcId = FUNC_RUN;
svr->mainseqno = 4; client->funcState = 0;
svr->flag = 0; return CLI_RET_INIT;
return 0;
} }
static u32 mainseq_1(struct mevent_client * svr) static u32 Client_Done(struct MysteryGiftClient * client)
{ {
// done return CLI_RET_END;
return 6;
} }
static u32 mainseq_2(struct mevent_client * svr) static u32 Client_Recv(struct MysteryGiftClient * client)
{ {
// do recv if (MysteryGiftLink_Recv(&client->link))
if (mevent_srv_sub_recv(&svr->manager))
{ {
svr->mainseqno = 4; client->funcId = FUNC_RUN;
svr->flag = 0; client->funcState = 0;
} }
return 1; return CLI_RET_1;
} }
static u32 mainseq_3(struct mevent_client * svr) static u32 Client_Send(struct MysteryGiftClient * client)
{ {
// do send if (MysteryGiftLink_Send(&client->link))
if (mevent_srv_sub_send(&svr->manager))
{ {
svr->mainseqno = 4; client->funcId = FUNC_RUN;
svr->flag = 0; client->funcState = 0;
} }
return 1; return CLI_RET_1;
} }
static u32 mainseq_4(struct mevent_client * svr) static u32 Client_Run(struct MysteryGiftClient * client)
{ {
// process command // process command
struct mevent_client_cmd * cmd = &svr->cmdBuffer[svr->cmdidx]; struct MysteryGiftClientCmd * cmd = &client->cmdBuffer[client->cmdidx];
++svr->cmdidx; client->cmdidx++;
switch (cmd->instr) switch (cmd->instr)
{ {
case 0: case CLI_NONE:
break; break;
case 1: case CLI_RETURN:
svr->param = cmd->parameter; client->param = cmd->parameter; // Set for endVal in MysteryGiftClient_Run
svr->mainseqno = 1; client->funcId = FUNC_DONE;
svr->flag = 0; client->funcState = 0;
break; break;
case 2: case CLI_RECV:
mevent_srv_sub_init_recv(&svr->manager, cmd->parameter, svr->recvBuffer); MysteryGiftLink_InitRecv(&client->link, cmd->parameter, client->recvBuffer);
svr->mainseqno = 2; client->funcId = FUNC_RECV;
svr->flag = 0; client->funcState = 0;
break; break;
case 3: case CLI_SEND_LOADED:
svr->mainseqno = 3; // Send without a MysteryGiftLink_InitSend
svr->flag = 0; // Sends whatever has been loaded already
client->funcId = FUNC_SEND;
client->funcState = 0;
break; break;
case 20: case CLI_20:
mevent_srv_sub_init_send(&svr->manager, 0x14, svr->sendBuffer, 0); MysteryGiftLink_InitSend(&client->link, 0x14, client->sendBuffer, 0);
svr->mainseqno = 3; client->funcId = FUNC_SEND;
svr->flag = 0; client->funcState = 0;
break; break;
case 19: case CLI_SEND_STAT:
mevent_client_send_word(svr, 0x12, GetGameStat(cmd->parameter)); MysteryGiftClient_InitSend(client, 0x12, GetGameStat(cmd->parameter));
svr->mainseqno = 3; client->funcId = FUNC_SEND;
svr->flag = 0; client->funcState = 0;
break; break;
case 6: case CLI_COPY_RECV_IF_N:
if (svr->param == 0) if (client->param == FALSE)
mevent_client_jmp_buffer(svr); MysteryGiftClient_CopyRecvScript(client);
break; break;
case 7: case CLI_COPY_RECV_IF:
if (svr->param == 1) if (client->param == TRUE)
mevent_client_jmp_buffer(svr); MysteryGiftClient_CopyRecvScript(client);
break; break;
case 4: case CLI_COPY_RECV:
mevent_client_jmp_buffer(svr); MysteryGiftClient_CopyRecvScript(client);
break; break;
case 5: case CLI_5:
memcpy(svr->buffer, svr->recvBuffer, 0x40); memcpy(client->buffer, client->recvBuffer, 0x40);
svr->mainseqno = 5; client->funcId = FUNC_WAIT;
svr->flag = 0; client->funcState = 0;
return 2; return CLI_RET_2;
case 11: case CLI_11:
memcpy(svr->buffer, svr->recvBuffer, 0x40); memcpy(client->buffer, client->recvBuffer, 0x40);
svr->mainseqno = 5; client->funcId = FUNC_WAIT;
svr->flag = 0; client->funcState = 0;
return 3; return CLI_RET_3;
case 12: case CLI_12:
memcpy(svr->buffer, svr->recvBuffer, 0x40); memcpy(client->buffer, client->recvBuffer, 0x40);
svr->mainseqno = 5; client->funcId = FUNC_WAIT;
svr->flag = 0; client->funcState = 0;
return 5; return CLI_RET_5;
case 13: case CLI_ASK_TOSS:
svr->mainseqno = 5; client->funcId = FUNC_WAIT;
svr->flag = 0; client->funcState = 0;
return 4; return CLI_RET_ASK_TOSS;
case 8: case CLI_8:
sub_801B580(svr->sendBuffer, svr->unk_4C); sub_801B580(client->sendBuffer, client->isWonderNews);
mevent_srv_sub_init_send(&svr->manager, 0x11, svr->sendBuffer, sizeof(struct MEventStruct_Unk1442CC)); MysteryGiftLink_InitSend(&client->link, 0x11, client->sendBuffer, sizeof(struct MEventStruct_Unk1442CC));
break; break;
case 14: case CLI_LOAD_TOSS_RESPONSE:
mevent_client_send_word(svr, 0x13, svr->param); // param here is set by MG_STATE_LINK_ASK_TOSS or MG_STATE_LINK_ASK_TOSS_UNRECEIVED
MysteryGiftClient_InitSend(client, 0x13, client->param);
break; break;
case 10: case CLI_10:
sub_801B21C(svr->recvBuffer); SaveWonderCard(client->recvBuffer);
break; break;
case 9: case CLI_9:
if (!sub_801B1A4(svr->recvBuffer)) if (!sub_801B1A4(client->recvBuffer))
{ {
sub_801B078(svr->recvBuffer); SaveWonderNews(client->recvBuffer);
mevent_client_send_word(svr, 0x13, 0); MysteryGiftClient_InitSend(client, 0x13, 0);
} }
else else
mevent_client_send_word(svr, 0x13, 1); MysteryGiftClient_InitSend(client, 0x13, 1);
break; break;
case 15: case CLI_15:
svr->mainseqno = 6; client->funcId = FUNC_6;
svr->flag = 0; client->funcState = 0;
break; break;
case 16: case CLI_16:
sub_801B508(svr->recvBuffer); sub_801B508(client->recvBuffer);
break; break;
case 17: case CLI_17:
InitRamScript_NoObjectEvent(svr->recvBuffer, 1000); InitRamScript_NoObjectEvent(client->recvBuffer, 1000);
break; break;
case 18: case CLI_RECV_EREADER_TRAINER:
memcpy(&gSaveBlock2Ptr->frontier.ereaderTrainer, svr->recvBuffer, 0xbc); memcpy(&gSaveBlock2Ptr->frontier.ereaderTrainer, client->recvBuffer, sizeof(gSaveBlock2Ptr->frontier.ereaderTrainer));
ValidateEReaderTrainer(); ValidateEReaderTrainer();
break; break;
case 21: case CLI_21:
memcpy(gDecompressionBuffer, svr->recvBuffer, ME_SEND_BUF_SIZE); memcpy(gDecompressionBuffer, client->recvBuffer, ME_SEND_BUF_SIZE);
svr->mainseqno = 7; client->funcId = FUNC_7;
svr->flag = 0; client->funcState = 0;
break; break;
} }
return 1; return CLI_RET_1;
} }
static u32 mainseq_5(struct mevent_client * svr) static u32 Client_Wait(struct MysteryGiftClient * client)
{ {
// wait flag if (client->funcState)
if (svr->flag)
{ {
svr->mainseqno = 4; client->funcId = FUNC_RUN;
svr->flag = 0; client->funcState = 0;
} }
return 1; return CLI_RET_1;
} }
static u32 mainseq_6(struct mevent_client * svr) static u32 Client_6(struct MysteryGiftClient * client)
{ {
// ??? switch (client->funcState)
switch (svr->flag)
{ {
case 0: case 0:
sub_8153870(svr->recvBuffer); InitMysteryGiftScriptContext(client->recvBuffer);
++svr->flag; client->funcState++;
break; break;
case 1: case 1:
if (!sub_8153884(&svr->param)) if (!RunMysteryGiftScriptContextCommand(&client->param))
{ {
svr->mainseqno = 4; client->funcId = FUNC_RUN;
svr->flag = 0; client->funcState = 0;
} }
break; break;
} }
return 1; return CLI_RET_1;
} }
static u32 mainseq_7(struct mevent_client * svr) static u32 Client_7(struct MysteryGiftClient * client)
{ {
// exec arbitrary code // exec arbitrary code
u32 (*func)(u32 *, struct SaveBlock2 *, struct SaveBlock1 *) = (void *)gDecompressionBuffer; u32 (*func)(u32 *, struct SaveBlock2 *, struct SaveBlock1 *) = (void *)gDecompressionBuffer;
if (func(&svr->param, gSaveBlock2Ptr, gSaveBlock1Ptr) == 1) if (func(&client->param, gSaveBlock2Ptr, gSaveBlock1Ptr) == 1)
{ {
svr->mainseqno = 4; client->funcId = FUNC_RUN;
svr->flag = 0; client->funcState = 0;
} }
return 1; return CLI_RET_1;
} }
static u32 mevent_client_exec(struct mevent_client * svr) static u32 MysteryGiftClient_CallFunc(struct MysteryGiftClient * client)
{ {
u32 (*funcs[])(struct mevent_client *) = { u32 (*funcs[])(struct MysteryGiftClient *) = {
mainseq_0, [FUNC_INIT] = Client_Init,
mainseq_1, [FUNC_DONE] = Client_Done,
mainseq_2, [FUNC_RECV] = Client_Recv,
mainseq_3, [FUNC_SEND] = Client_Send,
mainseq_4, [FUNC_RUN] = Client_Run,
mainseq_5, [FUNC_WAIT] = Client_Wait,
mainseq_6, [FUNC_6] = Client_6,
mainseq_7 [FUNC_7] = Client_7
}; };
return funcs[svr->mainseqno](svr); return funcs[client->funcId](client);
} }

View File

@ -60,7 +60,7 @@ u16 sub_801DC20(void)
struct MysteryEventStruct *r4 = sub_801B044(); struct MysteryEventStruct *r4 = sub_801B044();
u16 r5; u16 r5;
if (!IsMysteryEventEnabled() || !ValidateReceivedWonderNews()) if (!IsMysteryEventEnabled() || !ValidateSavedWonderNews())
return 0; return 0;
r5 = sub_801DD44(r4); r5 = sub_801DD44(r4);

View File

@ -5,187 +5,191 @@
const u8 gText_CanceledReadingCard[] = _("Canceled reading\nthe Card."); const u8 gText_CanceledReadingCard[] = _("Canceled reading\nthe Card.");
const struct mevent_client_cmd gUnknown_082F2598[] = { const struct MysteryGiftClientCmd gUnknown_082F2598[] = {
{.instr = 2, .parameter = 16}, {.instr = CLI_RECV, .parameter = 16},
{.instr = 4, .parameter = 0} {.instr = CLI_COPY_RECV}
}; };
const struct mevent_client_cmd gUnknown_082F25A8[] = { const struct MysteryGiftClientCmd gUnknown_082F25A8[] = {
{.instr = 8, .parameter = 0}, {.instr = CLI_8},
{.instr = 3, .parameter = 0}, {.instr = CLI_SEND_LOADED},
{.instr = 2, .parameter = 16}, {.instr = CLI_RECV, .parameter = 16},
{.instr = 4, .parameter = 0} {.instr = CLI_COPY_RECV}
}; };
const struct mevent_client_cmd gUnknown_082F25C8[] = { const struct MysteryGiftClientCmd gUnknown_082F25C8[] = {
{.instr = 20, .parameter = 0}, {.instr = CLI_20},
{.instr = 1, .parameter = 10} {.instr = CLI_RETURN, .parameter = 10}
}; };
const struct mevent_client_cmd gUnknown_082F25D8[] = { const struct MysteryGiftClientCmd gUnknown_082F25D8[] = {
{.instr = 20, .parameter = 0}, {.instr = CLI_20},
{.instr = 1, .parameter = 11} {.instr = CLI_RETURN, .parameter = 11}
}; };
const struct mevent_client_cmd gUnknown_082F25E8[] = { const struct MysteryGiftClientCmd gUnknown_082F25E8[] = {
{.instr = 20, .parameter = 0}, {.instr = CLI_20},
{.instr = 1, .parameter = 0} {.instr = CLI_RETURN, .parameter = 0}
}; };
const struct mevent_client_cmd gUnknown_082F25F8[] = { const struct MysteryGiftClientCmd gUnknown_082F25F8[] = {
{.instr = 2, .parameter = 22}, {.instr = CLI_RECV, .parameter = 22},
{.instr = 10, .parameter = 0}, {.instr = CLI_10},
{.instr = 2, .parameter = 25}, {.instr = CLI_RECV, .parameter = 25},
{.instr = 17, .parameter = 0}, {.instr = CLI_17},
{.instr = 20, .parameter = 0}, {.instr = CLI_20},
{.instr = 1, .parameter = 2} {.instr = CLI_RETURN, .parameter = 2}
}; };
const struct mevent_client_cmd gUnknown_082F2628[] = { const struct MysteryGiftClientCmd gUnknown_082F2628[] = {
{.instr = 2, .parameter = 23}, {.instr = CLI_RECV, .parameter = 23},
{.instr = 9, .parameter = 0}, {.instr = CLI_9},
{.instr = 3, .parameter = 0}, {.instr = CLI_SEND_LOADED},
{.instr = 2, .parameter = 16}, {.instr = CLI_RECV, .parameter = 16},
{.instr = 4, .parameter = 0} {.instr = CLI_COPY_RECV}
}; };
const struct mevent_client_cmd gUnknown_082F2650[] = { const struct MysteryGiftClientCmd gUnknown_082F2650[] = {
{.instr = 20, .parameter = 0}, {.instr = CLI_20},
{.instr = 1, .parameter = 7} {.instr = CLI_RETURN, .parameter = 7}
}; };
const struct mevent_client_cmd gUnknown_082F2660[] = { const struct MysteryGiftClientCmd gUnknown_082F2660[] = {
{.instr = 20, .parameter = 0}, {.instr = CLI_20},
{.instr = 1, .parameter = 3} {.instr = CLI_RETURN, .parameter = 3}
}; };
const struct mevent_client_cmd gUnknown_082F2670[] = { const struct MysteryGiftClientCmd gUnknown_082F2670[] = {
{.instr = 13, .parameter = 0}, {.instr = CLI_ASK_TOSS},
{.instr = 14, .parameter = 0}, {.instr = CLI_LOAD_TOSS_RESPONSE},
{.instr = 3, .parameter = 0}, {.instr = CLI_SEND_LOADED},
{.instr = 2, .parameter = 16}, {.instr = CLI_RECV, .parameter = 16},
{.instr = 4, .parameter = 0} {.instr = CLI_COPY_RECV}
}; };
const struct mevent_client_cmd gUnknown_082F2698[] = { const struct MysteryGiftClientCmd gUnknown_082F2698[] = {
{.instr = 20, .parameter = 0}, {.instr = CLI_20},
{.instr = 1, .parameter = 9} {.instr = CLI_RETURN, .parameter = 9}
}; };
const struct mevent_client_cmd gUnknown_082F26A8[] = { const struct MysteryGiftClientCmd gUnknown_082F26A8[] = {
{.instr = 20, .parameter = 0}, {.instr = CLI_20},
{.instr = 1, .parameter = 5} {.instr = CLI_RETURN, .parameter = 5}
}; };
const struct mevent_client_cmd gUnknown_082F26B8[] = { const struct MysteryGiftClientCmd gUnknown_082F26B8[] = {
{.instr = 2, .parameter = 21}, {.instr = CLI_RECV, .parameter = 21},
{.instr = 12, .parameter = 0}, {.instr = CLI_12},
{.instr = 20, .parameter = 0}, {.instr = CLI_20},
{.instr = 1, .parameter = 14}, {.instr = CLI_RETURN, .parameter = 14}
{.instr = 2, .parameter = 21}, };
{.instr = 12, .parameter = 0},
{.instr = 20, .parameter = 0}, // Unused
{.instr = 1, .parameter = 13} const struct MysteryGiftClientCmd gUnknown_082F26B8_1[] = {
{.instr = CLI_RECV, .parameter = 21},
{.instr = CLI_12},
{.instr = CLI_20},
{.instr = CLI_RETURN, .parameter = 13}
}; };
const struct mevent_cmd gUnknown_082F26F8[] = { const struct mevent_cmd gUnknown_082F26F8[] = {
{.instr = 18, .flag = 0x10, .parameter = gUnknown_082F25C8}, {.instr = 18, .flag = sizeof(gUnknown_082F25C8), .parameter = gUnknown_082F25C8},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x14, .parameter = NULL}, {.instr = 2, .flag = 0x14},
{.instr = 0, .flag = 0x0a, .parameter = NULL}, {.instr = 0, .flag = 0x0a},
{.instr = 18, .flag = 0x10, .parameter = gUnknown_082F25D8}, {.instr = 18, .flag = sizeof(gUnknown_082F25D8), .parameter = gUnknown_082F25D8},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x14, .parameter = NULL}, {.instr = 2, .flag = 0x14},
{.instr = 0, .flag = 0x0b, .parameter = NULL}, {.instr = 0, .flag = 0x0b},
{.instr = 18, .flag = 0x10, .parameter = gUnknown_082F2698}, {.instr = 18, .flag = sizeof(gUnknown_082F2698), .parameter = gUnknown_082F2698},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x14, .parameter = NULL}, {.instr = 2, .flag = 0x14},
{.instr = 0, .flag = 0x09, .parameter = NULL} {.instr = 0, .flag = 0x09}
}; };
const struct mevent_cmd gUnknown_082F2788[] = { const struct mevent_cmd gUnknown_082F2788[] = {
{.instr = 18, .flag = 0x20, .parameter = gUnknown_082F26B8}, {.instr = 18, .flag = sizeof(gUnknown_082F26B8), .parameter = gUnknown_082F26B8},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 20, .flag = 0x1b, .parameter = gText_CanceledReadingCard}, {.instr = 20, .flag = 0x1b, .parameter = gText_CanceledReadingCard},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x14, .parameter = NULL}, {.instr = 2, .flag = 0x14},
{.instr = 0, .flag = 0x09, .parameter = NULL} {.instr = 0, .flag = 0x09}
}; };
const struct mevent_cmd gUnknown_082F27D0[] = { const struct mevent_cmd gUnknown_082F27D0[] = {
{.instr = 18, .flag = 0x10, .parameter = gUnknown_082F2650}, {.instr = 18, .flag = sizeof(gUnknown_082F2650), .parameter = gUnknown_082F2650},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x14, .parameter = NULL}, {.instr = 2, .flag = 0x14},
{.instr = 0, .flag = 0x07, .parameter = NULL} {.instr = 0, .flag = 0x07}
}; };
const struct mevent_cmd gUnknown_082F2800[] = { const struct mevent_cmd gUnknown_082F2800[] = {
{.instr = 18, .flag = 0x28, .parameter = gUnknown_082F2628}, {.instr = 18, .flag = sizeof(gUnknown_082F2628), .parameter = gUnknown_082F2628},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 14, .flag = 0x00, .parameter = NULL}, {.instr = 14},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x13, .parameter = NULL}, {.instr = 2, .flag = 0x13},
{.instr = 8, .flag = 0x00, .parameter = NULL}, {.instr = 8},
{.instr = 4, .flag = 0x01, .parameter = gUnknown_082F27D0}, {.instr = 4, .flag = 0x01, .parameter = gUnknown_082F27D0},
{.instr = 18, .flag = 0x10, .parameter = gUnknown_082F2660}, {.instr = 18, .flag = sizeof(gUnknown_082F2660), .parameter = gUnknown_082F2660},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x14, .parameter = NULL}, {.instr = 2, .flag = 0x14},
{.instr = 0, .flag = 0x03, .parameter = NULL} {.instr = 0, .flag = 0x03}
}; };
const struct mevent_cmd gUnknown_082F2884[] = { const struct mevent_cmd gUnknown_082F2884[] = {
{.instr = 18, .flag = 0x30, .parameter = gUnknown_082F25F8}, {.instr = 18, .flag = sizeof(gUnknown_082F25F8), .parameter = gUnknown_082F25F8},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 13, .flag = 0x00, .parameter = NULL}, {.instr = 13},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 15, .flag = 0x00, .parameter = NULL}, {.instr = 15},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x14, .parameter = NULL}, {.instr = 2, .flag = 0x14},
{.instr = 0, .flag = 0x02, .parameter = NULL} {.instr = 0, .flag = 0x02}
}; };
const struct mevent_cmd gUnknown_082F28E4[] = { const struct mevent_cmd gUnknown_082F28E4[] = {
{.instr = 18, .flag = 0x28, .parameter = gUnknown_082F2670}, {.instr = 18, .flag = sizeof(gUnknown_082F2670), .parameter = gUnknown_082F2670},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x13, .parameter = NULL}, {.instr = 2, .flag = 0x13},
{.instr = 8, .flag = 0x00, .parameter = NULL}, {.instr = 8},
{.instr = 4, .flag = 0x00, .parameter = gUnknown_082F2884}, {.instr = 4, .parameter = gUnknown_082F2884},
{.instr = 3, .flag = 0x00, .parameter = gUnknown_082F2788} {.instr = 3, .parameter = gUnknown_082F2788}
}; };
const struct mevent_cmd gUnknown_082F292C[] = { const struct mevent_cmd gUnknown_082F292C[] = {
{.instr = 18, .flag = 0x10, .parameter = gUnknown_082F26A8}, {.instr = 18, .flag = sizeof(gUnknown_082F26A8), .parameter = gUnknown_082F26A8},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x14, .parameter = NULL}, {.instr = 2, .flag = 0x14},
{.instr = 0, .flag = 0x05, .parameter = NULL}, {.instr = 0, .flag = 0x05},
{.instr = 18, .flag = 0x10, .parameter = gUnknown_082F25E8}, {.instr = 18, .flag = sizeof(gUnknown_082F25E8), .parameter = gUnknown_082F25E8},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x14, .parameter = NULL}, {.instr = 2, .flag = 0x14},
{.instr = 0, .flag = 0x00, .parameter = NULL} {.instr = 0}
}; };
const struct mevent_cmd s_mevent_wonder_news[] = { const struct mevent_cmd s_mevent_wonder_news[] = {
{.instr = 27, .flag = 0x00, .parameter = NULL}, {.instr = 27},
{.instr = 18, .flag = 0x20, .parameter = gUnknown_082F25A8}, {.instr = 18, .flag = sizeof(gUnknown_082F25A8), .parameter = gUnknown_082F25A8},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x11, .parameter = NULL}, {.instr = 2, .flag = 0x11},
{.instr = 5, .flag = 0x00, .parameter = NULL}, {.instr = 5},
{.instr = 30, .flag = 0x00, .parameter = NULL}, {.instr = 30},
{.instr = 4, .flag = 0x00, .parameter = gUnknown_082F26F8}, {.instr = 4, .parameter = gUnknown_082F26F8},
{.instr = 3, .flag = 0x00, .parameter = gUnknown_082F2800} {.instr = 3, .parameter = gUnknown_082F2800}
}; };
const struct mevent_cmd s_mevent_wonder_card[] = { const struct mevent_cmd s_mevent_wonder_card[] = {
{.instr = 26, .flag = 0x00, .parameter = NULL}, {.instr = 26},
{.instr = 28, .flag = 0x00, .parameter = NULL}, {.instr = 28},
{.instr = 18, .flag = 0x20, .parameter = gUnknown_082F25A8}, {.instr = 18, .flag = sizeof(gUnknown_082F25A8), .parameter = gUnknown_082F25A8},
{.instr = 1, .flag = 0x00, .parameter = NULL}, {.instr = 1},
{.instr = 2, .flag = 0x11, .parameter = NULL}, {.instr = 2, .flag = 0x11},
{.instr = 5, .flag = 0x00, .parameter = NULL}, {.instr = 5},
{.instr = 6, .flag = 0x00, .parameter = NULL}, {.instr = 6},
{.instr = 4, .flag = 0x00, .parameter = gUnknown_082F26F8}, {.instr = 4, .parameter = gUnknown_082F26F8},
{.instr = 7, .flag = 0x00, .parameter = NULL}, {.instr = 7},
{.instr = 4, .flag = 0x02, .parameter = gUnknown_082F28E4}, {.instr = 4, .flag = 0x02, .parameter = gUnknown_082F28E4},
{.instr = 4, .flag = 0x00, .parameter = gUnknown_082F2884}, {.instr = 4, .parameter = gUnknown_082F2884},
{.instr = 3, .flag = 0x00, .parameter = gUnknown_082F292C} {.instr = 3, .parameter = gUnknown_082F292C}
}; };

View File

@ -52,7 +52,7 @@ static void mevent_srv_init_common(struct mevent_srv_common * svr, const void *
svr->mevent_unk1442cc = AllocZeroed(sizeof(struct MEventStruct_Unk1442CC)); svr->mevent_unk1442cc = AllocZeroed(sizeof(struct MEventStruct_Unk1442CC));
svr->cmdBuffer = cmdBuffer; svr->cmdBuffer = cmdBuffer;
svr->cmdidx = 0; svr->cmdidx = 0;
mevent_srv_sub_init(&svr->manager, sendPlayerNo, recvPlayerNo); MysteryGiftLink_Init(&svr->manager, sendPlayerNo, recvPlayerNo);
} }
static void mevent_srv_free_resources(struct mevent_srv_common * svr) static void mevent_srv_free_resources(struct mevent_srv_common * svr)
@ -66,7 +66,7 @@ static void mevent_srv_free_resources(struct mevent_srv_common * svr)
void mevent_srv_common_init_send(struct mevent_srv_common * svr, u32 ident, const void * src, u32 size) void mevent_srv_common_init_send(struct mevent_srv_common * svr, u32 ident, const void * src, u32 size)
{ {
AGB_ASSERT(size <= ME_SEND_BUF_SIZE); AGB_ASSERT(size <= ME_SEND_BUF_SIZE);
mevent_srv_sub_init_send(&svr->manager, ident, src, size); MysteryGiftLink_InitSend(&svr->manager, ident, src, size);
} }
static const void * mevent_first_if_not_null_else_second(const void * a0, const void * a1) static const void * mevent_first_if_not_null_else_second(const void * a0, const void * a1)
@ -103,7 +103,7 @@ static u32 common_mainseq_1(struct mevent_srv_common * svr)
static u32 common_mainseq_2(struct mevent_srv_common * svr) static u32 common_mainseq_2(struct mevent_srv_common * svr)
{ {
// do recv // do recv
if (mevent_srv_sub_recv(&svr->manager)) if (MysteryGiftLink_Recv(&svr->manager))
svr->mainseqno = 4; svr->mainseqno = 4;
return 1; return 1;
} }
@ -111,7 +111,7 @@ static u32 common_mainseq_2(struct mevent_srv_common * svr)
static u32 common_mainseq_3(struct mevent_srv_common * svr) static u32 common_mainseq_3(struct mevent_srv_common * svr)
{ {
// do send // do send
if (mevent_srv_sub_send(&svr->manager)) if (MysteryGiftLink_Send(&svr->manager))
svr->mainseqno = 4; svr->mainseqno = 4;
return 1; return 1;
} }
@ -138,7 +138,7 @@ static u32 common_mainseq_4(struct mevent_srv_common * svr)
case 2: case 2:
// receive // receive
AGB_ASSERT(cmd->parameter == NULL); AGB_ASSERT(cmd->parameter == NULL);
mevent_srv_sub_init_recv(&svr->manager, cmd->flag, svr->recvBuffer); MysteryGiftLink_InitRecv(&svr->manager, cmd->flag, svr->recvBuffer);
svr->mainseqno = 2; svr->mainseqno = 2;
break; break;
case 3: case 3:
@ -196,7 +196,7 @@ static u32 common_mainseq_4(struct mevent_srv_common * svr)
break; break;
case 11: case 11:
AGB_ASSERT(cmd->flag == FALSE); AGB_ASSERT(cmd->flag == FALSE);
svr->param = MEventStruct_Unk1442CC_CompareField_unk_16(svr->mevent_unk1442cc, cmd->parameter); svr->param = MysteryGift_DoesQuestionnaireMatch(svr->mevent_unk1442cc, cmd->parameter);
break; break;
case 12: case 12:
AGB_ASSERT(cmd->flag == FALSE); AGB_ASSERT(cmd->flag == FALSE);

View File

@ -11,20 +11,20 @@
#include "mevent.h" #include "mevent.h"
#include "mevent_server_helpers.h" #include "mevent_server_helpers.h"
static u32 mevent_receive_func(struct mevent_srv_sub *); static u32 mevent_receive_func(struct MysteryGiftLink *);
static u32 mevent_send_func(struct mevent_srv_sub *); static u32 mevent_send_func(struct MysteryGiftLink *);
u32 mevent_srv_sub_recv(struct mevent_srv_sub * svr) u32 MysteryGiftLink_Recv(struct MysteryGiftLink * svr)
{ {
return svr->recvFunc(svr); return svr->recvFunc(svr);
} }
u32 mevent_srv_sub_send(struct mevent_srv_sub * svr) u32 MysteryGiftLink_Send(struct MysteryGiftLink * svr)
{ {
return svr->sendFunc(svr); return svr->sendFunc(svr);
} }
void mevent_srv_sub_init(struct mevent_srv_sub * svr, u32 sendPlayerNo, u32 recvPlayerNo) void MysteryGiftLink_Init(struct MysteryGiftLink * svr, u32 sendPlayerNo, u32 recvPlayerNo)
{ {
svr->sendPlayerNo = sendPlayerNo; svr->sendPlayerNo = sendPlayerNo;
svr->recvPlayerNo = recvPlayerNo; svr->recvPlayerNo = recvPlayerNo;
@ -41,7 +41,7 @@ void mevent_srv_sub_init(struct mevent_srv_sub * svr, u32 sendPlayerNo, u32 recv
svr->recvFunc = mevent_receive_func; svr->recvFunc = mevent_receive_func;
} }
void mevent_srv_sub_init_send(struct mevent_srv_sub * svr, u32 ident, const void * src, u32 size) void MysteryGiftLink_InitSend(struct MysteryGiftLink * svr, u32 ident, const void * src, u32 size)
{ {
svr->seqno = 0; svr->seqno = 0;
svr->sendIdent = ident; svr->sendIdent = ident;
@ -54,7 +54,7 @@ void mevent_srv_sub_init_send(struct mevent_srv_sub * svr, u32 ident, const void
svr->sendBfr = src; svr->sendBfr = src;
} }
void mevent_srv_sub_init_recv(struct mevent_srv_sub * svr, u32 ident, void * dest) void MysteryGiftLink_InitRecv(struct MysteryGiftLink * svr, u32 ident, void * dest)
{ {
svr->seqno = 0; svr->seqno = 0;
svr->recvIdent = ident; svr->recvIdent = ident;
@ -82,7 +82,7 @@ static void mevent_reset_recv(u32 recv_idx)
ResetBlockReceivedFlag(recv_idx); ResetBlockReceivedFlag(recv_idx);
} }
static bool32 mevent_receive_func(struct mevent_srv_sub * svr) static bool32 mevent_receive_func(struct MysteryGiftLink * svr)
{ {
struct send_recv_header header; struct send_recv_header header;
@ -148,7 +148,7 @@ static bool32 mevent_receive_func(struct mevent_srv_sub * svr)
return FALSE; return FALSE;
} }
static bool32 mevent_send_func(struct mevent_srv_sub * svr) static bool32 mevent_send_func(struct MysteryGiftLink * svr)
{ {
struct send_recv_header header; struct send_recv_header header;

View File

@ -65,15 +65,15 @@ static bool32 RunMysteryEventScriptCommand(struct ScriptContext *ctx)
return FALSE; return FALSE;
} }
void sub_8153870(u8 *script) void InitMysteryGiftScriptContext(u8 *script)
{ {
InitMysteryEventScript(&sMysteryEventScriptContext, script); InitMysteryEventScript(&sMysteryEventScriptContext, script);
} }
bool32 sub_8153884(u32 *a0) bool32 RunMysteryGiftScriptContextCommand(u32 *script)
{ {
bool32 ret = RunMysteryEventScriptCommand(&sMysteryEventScriptContext); bool32 ret = RunMysteryEventScriptCommand(&sMysteryEventScriptContext);
*a0 = sMysteryEventScriptContext.data[2]; *script = sMysteryEventScriptContext.data[2];
return ret; return ret;
} }

View File

@ -761,9 +761,9 @@ static s32 HandleMysteryGiftListMenu(u8 * textState, u16 * windowId, bool32 cann
static bool32 ValidateCardOrNews(bool32 isWonderNews) static bool32 ValidateCardOrNews(bool32 isWonderNews)
{ {
if (!isWonderNews) if (!isWonderNews)
return ValidateReceivedWonderCard(); return ValidateSavedWonderCard();
else else
return ValidateReceivedWonderNews(); return ValidateSavedWonderNews();
} }
static bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 isWonderNews) static bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 isWonderNews)
@ -795,12 +795,12 @@ static bool32 HandleLoadWonderCardOrNews(u8 * state, bool32 isWonderNews)
return FALSE; return FALSE;
} }
static bool32 DestroyNewsOrCard(bool32 isWonderNews) static bool32 ClearSavedNewsOrCard(bool32 isWonderNews)
{ {
if (!isWonderNews) if (!isWonderNews)
DestroyWonderCard(); ClearSavedWonderCard();
else else
DestroyWonderNews(); ClearSavedWonderNews();
return TRUE; return TRUE;
} }
@ -1055,8 +1055,8 @@ enum {
MG_STATE_COMMUNICATE, MG_STATE_COMMUNICATE,
MG_STATE_9, MG_STATE_9,
MG_STATE_10, MG_STATE_10,
MG_STATE_11, MG_STATE_LINK_ASK_TOSS,
MG_STATE_12, MG_STATE_LINK_ASK_TOSS_UNRECEIVED,
MG_STATE_LINK_COMPLETE_WAIT, MG_STATE_LINK_COMPLETE_WAIT,
MG_STATE_LINK_COMPLETED, MG_STATE_LINK_COMPLETED,
MG_STATE_LINK_RESULT_MSG, MG_STATE_LINK_RESULT_MSG,
@ -1119,14 +1119,14 @@ static void Task_MysteryGift(u8 taskId)
{ {
case 0: // "Wonder Cards" case 0: // "Wonder Cards"
data->isWonderNews = FALSE; data->isWonderNews = FALSE;
if (ValidateReceivedWonderCard() == TRUE) if (ValidateSavedWonderCard() == TRUE)
data->state = MG_STATE_LOAD_GIFT; data->state = MG_STATE_LOAD_GIFT;
else else
data->state = MG_STATE_DONT_HAVE_ANY; data->state = MG_STATE_DONT_HAVE_ANY;
break; break;
case 1: // "Wonder News" case 1: // "Wonder News"
data->isWonderNews = TRUE; data->isWonderNews = TRUE;
if (ValidateReceivedWonderNews() == TRUE) if (ValidateSavedWonderNews() == TRUE)
data->state = MG_STATE_LOAD_GIFT; data->state = MG_STATE_LOAD_GIFT;
else else
data->state = MG_STATE_DONT_HAVE_ANY; data->state = MG_STATE_DONT_HAVE_ANY;
@ -1220,7 +1220,7 @@ static void Task_MysteryGift(u8 taskId)
{ {
ClearScreenInBg0(TRUE); ClearScreenInBg0(TRUE);
data->state = MG_STATE_COMMUNICATING; data->state = MG_STATE_COMMUNICATING;
mevent_client_do_init(data->isWonderNews); MysteryGiftClient_Create(data->isWonderNews);
} }
else if (gSpecialVar_Result == LINKUP_FAILED) else if (gSpecialVar_Result == LINKUP_FAILED)
{ {
@ -1234,25 +1234,25 @@ static void Task_MysteryGift(u8 taskId)
data->state = MG_STATE_COMMUNICATE; data->state = MG_STATE_COMMUNICATE;
break; break;
case MG_STATE_COMMUNICATE: case MG_STATE_COMMUNICATE:
switch (mevent_client_do_exec(&data->curPromptWindowId)) switch (MysteryGiftClient_Run(&data->curPromptWindowId))
{ {
case 6: case CLI_RET_END:
Rfu_SetCloseLinkCallback(); Rfu_SetCloseLinkCallback();
data->prevPromptWindowId = data->curPromptWindowId; data->prevPromptWindowId = data->curPromptWindowId;
data->state = MG_STATE_LINK_COMPLETE_WAIT; data->state = MG_STATE_LINK_COMPLETE_WAIT;
break; break;
case 5: case CLI_RET_5:
memcpy(data->buffer, mevent_client_get_buffer(), 0x40); memcpy(data->buffer, mevent_client_get_buffer(), 0x40);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
break; break;
case 3: case CLI_RET_3:
data->state = MG_STATE_10; data->state = MG_STATE_10;
break; break;
case 2: case CLI_RET_2:
data->state = MG_STATE_9; data->state = MG_STATE_9;
break; break;
case 4: case CLI_RET_ASK_TOSS:
data->state = MG_STATE_11; data->state = MG_STATE_LINK_ASK_TOSS;
StringCopy(gStringVar1, gLinkPlayers[0].name); StringCopy(gStringVar1, gLinkPlayers[0].name);
break; break;
} }
@ -1262,14 +1262,14 @@ static void Task_MysteryGift(u8 taskId)
switch (input) switch (input)
{ {
case 0: // Yes case 0: // Yes
mevent_client_set_param(0); MysteryGiftClient_SetParam(0);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = MG_STATE_COMMUNICATING; data->state = MG_STATE_COMMUNICATING;
break; break;
case 1: // No case 1: // No
case MENU_B_PRESSED: case MENU_B_PRESSED:
mevent_client_set_param(1); MysteryGiftClient_SetParam(1);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = MG_STATE_COMMUNICATING; data->state = MG_STATE_COMMUNICATING;
break; break;
} }
@ -1277,47 +1277,47 @@ static void Task_MysteryGift(u8 taskId)
case MG_STATE_10: case MG_STATE_10:
if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, mevent_client_get_buffer())) if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, mevent_client_get_buffer()))
{ {
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = MG_STATE_COMMUNICATING; data->state = MG_STATE_COMMUNICATING;
} }
break; break;
case MG_STATE_11: case MG_STATE_LINK_ASK_TOSS:
input = DoMysteryGiftYesNo(&data->textState, &data->curPromptWindowId, FALSE, gText_ThrowAwayWonderCard); input = DoMysteryGiftYesNo(&data->textState, &data->curPromptWindowId, FALSE, gText_ThrowAwayWonderCard);
switch (input) switch (input)
{ {
case 0: // Yes case 0: // Yes
if (CheckReceivedGiftFromWonderCard() == TRUE) if (CheckReceivedGiftFromWonderCard() == TRUE)
{ {
data->state = MG_STATE_12; data->state = MG_STATE_LINK_ASK_TOSS_UNRECEIVED;
} }
else else
{ {
mevent_client_set_param(0); MysteryGiftClient_SetParam(0);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = MG_STATE_COMMUNICATING; data->state = MG_STATE_COMMUNICATING;
} }
break; break;
case 1: // No case 1: // No
case MENU_B_PRESSED: case MENU_B_PRESSED:
mevent_client_set_param(1); MysteryGiftClient_SetParam(1);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = MG_STATE_COMMUNICATING; data->state = MG_STATE_COMMUNICATING;
break; break;
} }
break; break;
case MG_STATE_12: case MG_STATE_LINK_ASK_TOSS_UNRECEIVED:
input = DoMysteryGiftYesNo(&data->textState, &data->curPromptWindowId, FALSE, gText_HaventReceivedCardsGift); input = DoMysteryGiftYesNo(&data->textState, &data->curPromptWindowId, FALSE, gText_HaventReceivedCardsGift);
switch (input) switch (input)
{ {
case 0: // Yes case 0: // Yes
mevent_client_set_param(0); MysteryGiftClient_SetParam(0);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = MG_STATE_COMMUNICATING; data->state = MG_STATE_COMMUNICATING;
break; break;
case 1: // No case 1: // No
case MENU_B_PRESSED: case MENU_B_PRESSED:
mevent_client_set_param(1); MysteryGiftClient_SetParam(1);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = MG_STATE_COMMUNICATING; data->state = MG_STATE_COMMUNICATING;
break; break;
} }
@ -1436,7 +1436,7 @@ static void Task_MysteryGift(u8 taskId)
break; break;
} }
case MG_STATE_ASK_TOSS: case MG_STATE_ASK_TOSS:
// Player is atempting to discard a Wonder Card/News // Player is attempting to discard a Wonder Card/News
switch (AskDiscardGift(&data->textState, &data->curPromptWindowId, data->isWonderNews)) switch (AskDiscardGift(&data->textState, &data->curPromptWindowId, data->isWonderNews))
{ {
case 0: // Yes case 0: // Yes
@ -1452,7 +1452,8 @@ static void Task_MysteryGift(u8 taskId)
} }
break; break;
case MG_STATE_ASK_TOSS_UNRECEIVED: case MG_STATE_ASK_TOSS_UNRECEIVED:
// Player is attempting to discard a Wonder Card that they haven't received the gift for // Player has selected to toss a Wonder Card that they haven't received the gift for.
// Ask for confirmation again.
switch ((u32)DoMysteryGiftYesNo(&data->textState, &data->curPromptWindowId, TRUE, gText_HaventReceivedGiftOkayToDiscard)) switch ((u32)DoMysteryGiftYesNo(&data->textState, &data->curPromptWindowId, TRUE, gText_HaventReceivedGiftOkayToDiscard))
{ {
case 0: // Yes case 0: // Yes
@ -1467,7 +1468,7 @@ static void Task_MysteryGift(u8 taskId)
case MG_STATE_TOSS: case MG_STATE_TOSS:
if (ExitWonderCardOrNews(data->isWonderNews, 1)) if (ExitWonderCardOrNews(data->isWonderNews, 1))
{ {
DestroyNewsOrCard(data->isWonderNews); ClearSavedNewsOrCard(data->isWonderNews);
data->state = MG_STATE_TOSS_SAVE; data->state = MG_STATE_TOSS_SAVE;
} }
break; break;

View File

@ -2230,7 +2230,7 @@ bool8 ScrCmd_checkmoneventlegal(struct ScriptContext *ctx)
} }
// TODO: Should be renamed. Name implies general usage, but its specifically for Wonder Card // TODO: Should be renamed. Name implies general usage, but its specifically for Wonder Card
// See GetSavedRamScriptIfValid, which is NULL if ValidateReceivedWonderCard returns FALSE // See GetSavedRamScriptIfValid, which is NULL if ValidateSavedWonderCard returns FALSE
bool8 ScrCmd_gotoram(struct ScriptContext *ctx) bool8 ScrCmd_gotoram(struct ScriptContext *ctx)
{ {
const u8* script = GetSavedRamScriptIfValid(); const u8* script = GetSavedRamScriptIfValid();

View File

@ -417,7 +417,7 @@ bool32 ValidateSavedRamScript(void)
u8 *GetSavedRamScriptIfValid(void) u8 *GetSavedRamScriptIfValid(void)
{ {
struct RamScriptData *scriptData = &gSaveBlock1Ptr->ramScript.data; struct RamScriptData *scriptData = &gSaveBlock1Ptr->ramScript.data;
if (!ValidateReceivedWonderCard()) if (!ValidateSavedWonderCard())
return NULL; return NULL;
if (scriptData->magic != RAM_SCRIPT_MAGIC) if (scriptData->magic != RAM_SCRIPT_MAGIC)
return NULL; return NULL;

View File

@ -51,7 +51,7 @@ struct UnkStruct_203F3C8_02DC
struct WonderCardData struct WonderCardData
{ {
/*0000*/ struct WonderCard card; /*0000*/ struct WonderCard card;
/*014c*/ struct MEventBuffer_3430_Sub unk_014C; /*014c*/ struct MEventBuffer_3430 unk_014C;
/*0170*/ const struct WonderGraphics * gfx; /*0170*/ const struct WonderGraphics * gfx;
/*0174*/ u8 enterExitState; /*0174*/ u8 enterExitState;
/*0175*/ u8 unk_0175; /*0175*/ u8 unk_0175;
@ -176,7 +176,7 @@ static const struct WonderGraphics sCardGraphics[NUM_WONDER_BGS] = {
{.textPal1 = 1, .textPal2 = 0, .textPal3 = 0, .textPal4 = 7, .tiles = sWonderCardBgGfx8, .map = sWonderCardBgTilemap8, .pal = sWonderCardBgPal8} {.textPal1 = 1, .textPal2 = 0, .textPal3 = 0, .textPal4 = 7, .tiles = sWonderCardBgGfx8, .map = sWonderCardBgTilemap8, .pal = sWonderCardBgPal8}
}; };
bool32 WonderCard_Init(struct WonderCard * card, struct MEventBuffer_3430_Sub * r6) bool32 WonderCard_Init(struct WonderCard * card, struct MEventBuffer_3430 * r6)
{ {
if (card == NULL || r6 == NULL) if (card == NULL || r6 == NULL)
return FALSE; return FALSE;