Sync mystery gift server, client, scripts

This commit is contained in:
GriffinR
2022-11-19 21:49:50 -05:00
parent 12b0c70069
commit af6837c093
11 changed files with 800 additions and 648 deletions
+1 -1
View File
@@ -325,6 +325,6 @@ void SetUnionRoomChatPlayerData(u32 numPlayers);
void ClearRecvCommands(void); void ClearRecvCommands(void);
#include "mystery_gift_server.h" #include "mystery_gift_server.h"
extern const struct mevent_server_cmd gServerScript_ClientCanceledCard[]; extern const struct MysteryGiftServerCmd gServerScript_ClientCanceledCard[];
#endif //GUARD_LINK_RFU_H #endif //GUARD_LINK_RFU_H
+2 -2
View File
@@ -79,8 +79,8 @@ void DisableWonderCardSending(struct WonderCard * card);
bool32 MysteryGift_TrySaveStamp(const u16 * stamp); bool32 MysteryGift_TrySaveStamp(const u16 * stamp);
void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData * data); void MysteryGift_LoadLinkGameData(struct MysteryGiftLinkGameData * data);
bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData * data); bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData * data);
u32 MysteryGift_CompareCardFlags(const u16 * flagId, const struct MysteryGiftLinkGameData * data, void *unused); u32 MysteryGift_CompareCardFlags(const u16 * flagId, const struct MysteryGiftLinkGameData * data, const void *unused);
u32 MysteryGift_CheckStamps(const u16 * stamp, const struct MysteryGiftLinkGameData * data, 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);
bool32 WonderCard_Init(struct WonderCard * card, struct WonderCardMetadata * metadata); bool32 WonderCard_Init(struct WonderCard * card, struct WonderCardMetadata * metadata);
+91
View File
@@ -0,0 +1,91 @@
#ifndef GUARD_MYSTERY_GIFT_CLIENT_H
#define GUARD_MYSTERY_GIFT_CLIENT_H
#include "mystery_gift_link.h"
// Return values for client functions called by MysteryGiftClient_Run
enum {
CLI_RET_INIT,
CLI_RET_ACTIVE,
CLI_RET_YES_NO,
CLI_RET_PRINT_MSG,
CLI_RET_ASK_TOSS,
CLI_RET_COPY_MSG,
CLI_RET_END,
};
// IDs for client script instructions
enum {
CLI_NONE,
CLI_RETURN,
CLI_RECV,
CLI_SEND_LOADED,
CLI_COPY_RECV,
CLI_YES_NO,
CLI_COPY_RECV_IF_N,
CLI_COPY_RECV_IF,
CLI_LOAD_GAME_DATA,
CLI_SAVE_NEWS,
CLI_SAVE_CARD,
CLI_PRINT_MSG,
CLI_COPY_MSG,
CLI_ASK_TOSS,
CLI_LOAD_TOSS_RESPONSE,
CLI_RUN_MEVENT_SCRIPT,
CLI_SAVE_STAMP,
CLI_SAVE_RAM_SCRIPT,
CLI_RECV_EREADER_TRAINER,
CLI_SEND_STAT,
CLI_SEND_READY_END,
CLI_RUN_BUFFER_SCRIPT,
};
// IDs for client messages when ending a script.
// Given as the parameter to CLI_RETURN, and resolved to text in GetClientResultMessage
enum {
CLI_MSG_NOTHING_SENT,
CLI_MSG_RECORD_UPLOADED,
CLI_MSG_CARD_RECEIVED,
CLI_MSG_NEWS_RECEIVED,
CLI_MSG_STAMP_RECEIVED,
CLI_MSG_HAD_CARD,
CLI_MSG_HAD_STAMP,
CLI_MSG_HAD_NEWS,
CLI_MSG_NO_ROOM_STAMPS,
CLI_MSG_COMM_CANCELED,
CLI_MSG_CANT_ACCEPT,
CLI_MSG_COMM_ERROR,
CLI_MSG_TRAINER_RECEIVED,
CLI_MSG_BUFFER_SUCCESS,
CLI_MSG_BUFFER_FAILURE,
};
#define CLIENT_MAX_MSG_SIZE 64
struct MysteryGiftClientCmd
{
u32 instr;
u32 parameter;
};
struct MysteryGiftClient
{
u32 unused;
u32 param;
u32 funcId;
u32 funcState;
u32 cmdidx;
void *sendBuffer;
void *recvBuffer;
struct MysteryGiftClientCmd * script;
void *msg;
struct MysteryGiftLink link;
};
void MysteryGiftClient_Create(void);
u32 MysteryGiftClient_Run(u16 * endVal);
void MysteryGiftClient_AdvanceState(void);
void * MysteryGiftClient_GetMsg(void);
void MysteryGiftClient_SetParam(u32 value);
#endif //GUARD_MYSTERY_GIFT_CLIENT_H
+50
View File
@@ -0,0 +1,50 @@
#ifndef GUARD_MYSTERY_GIFT_LINK_H
#define GUARD_MYSTERY_GIFT_LINK_H
#define MG_LINK_BUFFER_SIZE 0x400
#define ME_SEND_BUF_SIZE MG_LINK_BUFFER_SIZE
// Send/receive ids for the Client/Server to make sure
// they're sending/receiving the same thing
enum {
MG_LINKID_CLIENT_SCRIPT = 16,
MG_LINKID_GAME_DATA,
MG_LINKID_GAME_STAT,
MG_LINKID_RESPONSE,
MG_LINKID_READY_END,
MG_LINKID_DYNAMIC_MSG,
MG_LINKID_CARD,
MG_LINKID_NEWS,
MG_LINKID_STAMP,
MG_LINKID_RAM_SCRIPT,
MG_LINKID_EREADER_TRAINER,
MG_LINKID_UNK_1,
MG_LINKID_UNK_2,
};
struct MysteryGiftLink
{
s32 state;
u8 sendPlayerId;
u8 recvPlayerId;
u16 recvIdent;
u16 recvCounter;
u16 recvCRC;
u16 recvSize;
u16 sendIdent;
u16 sendCounter;
u16 sendCRC;
u16 sendSize;
void * recvBuffer;
const void * sendBuffer;
u32 (*recvFunc)(struct MysteryGiftLink *);
u32 (*sendFunc)(struct MysteryGiftLink *);
};
void MysteryGiftLink_Init(struct MysteryGiftLink * link, u32 sendPlayerId, u32 recvPlayerId);
void MysteryGiftLink_InitSend(struct MysteryGiftLink * link, u32 ident, const void * src, u32 size);
bool32 MysteryGiftLink_Recv(struct MysteryGiftLink * link);
bool32 MysteryGiftLink_Send(struct MysteryGiftLink * link);
void MysteryGiftLink_InitRecv(struct MysteryGiftLink * link, u32 ident, void * dest);
#endif //GUARD_MYSTERY_GIFT_LINK_H
+76 -94
View File
@@ -2,121 +2,103 @@
#define GUARD_MYSTERY_GIFT_SERVER_H #define GUARD_MYSTERY_GIFT_SERVER_H
#include "global.h" #include "global.h"
#include "mystery_gift_link.h"
#define ME_SEND_BUF_SIZE 0x400 // Return values for Server_* functions.
// Other than SVR_RET_END, effectively useless (not checked for).
struct MysteryGiftLink enum {
{ SVR_RET_INIT,
s32 state; SVR_RET_ACTIVE,
u8 sendPlayerId; SVR_RET_UNUSED,
u8 recvPlayerId; SVR_RET_END
u16 recvIdent;
u16 recvCounter;
u16 recvCRC;
u16 recvSize;
u16 sendIdent;
u16 sendCounter;
u16 sendCRC;
u16 sendSize;
void *recvBuffer;
const void *sendBuffer;
u32 (*recvFunc)(struct MysteryGiftLink *);
u32 (*sendFunc)(struct MysteryGiftLink *);
}; };
struct mevent_client_cmd // IDs for server script instructions
{ enum {
u32 instr; SVR_RETURN,
u32 parameter; SVR_SEND,
SVR_RECV,
SVR_GOTO,
SVR_GOTO_IF_EQ,
SVR_COPY_GAME_DATA,
SVR_CHECK_GAME_DATA, // In Emerald, this was separated into SVR_CHECK_GAME_DATA_CARD and SVR_CHECK_GAME_DATA_NEWS
SVR_CHECK_EXISTING_CARD,
SVR_READ_RESPONSE,
SVR_CHECK_EXISTING_STAMPS,
SVR_GET_CARD_STAT,
SVR_CHECK_QUESTIONNAIRE,
SVR_COMPARE,
SVR_LOAD_CARD,
SVR_LOAD_NEWS,
SVR_LOAD_RAM_SCRIPT,
SVR_LOAD_STAMP,
SVR_LOAD_UNK_2,
SVR_LOAD_CLIENT_SCRIPT,
SVR_LOAD_EREADER_TRAINER,
SVR_LOAD_MSG,
SVR_COPY_STAMP,
SVR_COPY_CARD,
SVR_COPY_NEWS,
SVR_SET_RAM_SCRIPT,
SVR_SET_CLIENT_SCRIPT,
SVR_COPY_SAVED_CARD,
SVR_COPY_SAVED_NEWS,
SVR_COPY_SAVED_RAM_SCRIPT,
SVR_LOAD_UNK_1,
}; };
// Client commands // Create arguments for SVR_LOAD_CLIENT_SCRIPT or SVR_LOAD_MSG
#define CLI_RETURN(x) {.instr = 1, .parameter = x} // (a script/text size and pointer to send to the client)
#define CLI_RECEIVE(x) {.instr = 2, .parameter = x} #define PTR_ARG(pointer) .flag = sizeof(pointer), .parameter = pointer
#define CLI_WAITSND {.instr = 3, .parameter = 0}
#define CLI_JUMPBUF {.instr = 4, .parameter = 0}
#define CLI_SNDHEAD {.instr = 8, .parameter = 0}
#define CLI_VLDNEWS {.instr = 9, .parameter = 0}
#define CLI_RECVSAV {.instr = 10, .parameter = 0}
#define CLI_RECVBUF {.instr = 12, .parameter = 0}
#define CLI_REQWORD {.instr = 13, .parameter = 0}
#define CLI_SNDWORD {.instr = 14, .parameter = 0}
#define CLI_RECVMON {.instr = 16, .parameter = 0}
#define CLI_RECVRAM {.instr = 17, .parameter = 0}
#define CLI_SENDALL {.instr = 20, .parameter = 0}
struct mevent_client // IDs for server messages when ending a script.
{ // Given as the parameter to SVR_RETURN, and resolved to text in GetServerResultMessage
u32 unk_00; enum {
u32 param; SVR_MSG_NOTHING_SENT,
u32 mainseqno; SVR_MSG_RECORD_UPLOADED,
u32 flag; SVR_MSG_CARD_SENT,
u32 cmdidx; SVR_MSG_NEWS_SENT,
void *sendBuffer; SVR_MSG_STAMP_SENT,
void *recvBuffer; SVR_MSG_HAS_CARD,
struct mevent_client_cmd * cmdBuffer; SVR_MSG_HAS_STAMP,
void *buffer; SVR_MSG_HAS_NEWS,
struct MysteryGiftLink manager; SVR_MSG_NO_ROOM_STAMPS,
SVR_MSG_CLIENT_CANCELED,
SVR_MSG_CANT_SEND_GIFT_1,
SVR_MSG_COMM_ERROR,
SVR_MSG_GIFT_SENT_1,
SVR_MSG_GIFT_SENT_2,
SVR_MSG_CANT_SEND_GIFT_2,
}; };
struct mevent_server_cmd struct MysteryGiftServerCmd
{ {
u32 instr; u32 instr;
bool32 flag; bool32 flag;
void *parameter; const void *parameter;
}; };
// Server commands struct MysteryGiftServer
#define SRV_RETURN(x) {.instr = 0, .flag = x}
#define SRV_WAITSND {.instr = 1}
#define SRV_RECV(x) {.instr = 2, .flag = x}
#define SRV_BRANCH(y) {.instr = 3, .parameter = (void *)y}
#define SRV_BRANCHIF(x, y) {.instr = 4, .flag = x, .parameter = (void *)y}
#define SRV_READ_1442CC {.instr = 5}
#define SRV_VALID_1442CC {.instr = 6}
#define SRV_CHECK_1442CC_14 {.instr = 7}
#define SRV_READWORD {.instr = 8}
#define SRV_SEND_CARD {.instr = 13}
#define SRV_SEND_NEWS {.instr = 14}
#define SRV_BUFFER_SEND {.instr = 15}
#define SRV_SEND(x, y) {.instr = 18, .flag = x, .parameter = (void *)y}
#define SRV_SENDSTR(x, y) {.instr = 20, .flag = x, .parameter = (void *)y}
#define SRV_BUFFER_CARD {.instr = 26}
#define SRV_BUFFER_NEWS {.instr = 27}
#define SRV_RAM_SCRIPT_IF_VALID {.instr = 28}
struct mevent_srv_common
{ {
u32 unk_00; u32 unused;
u32 param; u32 param;
u32 mainseqno; u32 funcId;
u32 cmdidx; u32 cmdidx;
const struct mevent_server_cmd * cmdBuffer; const struct MysteryGiftServerCmd * script;
void *recvBuffer; void *recvBuffer;
struct WonderCard * card; struct WonderCard * card;
struct WonderNews * news; struct WonderNews * news;
struct MysteryGiftLinkGameData * mevent_unk1442cc; struct MysteryGiftLinkGameData * linkGameData;
void *sendBuffer1; const void *ramScript;
u32 sendBuffer1Size; u32 ramScriptSize;
void *sendBuffer2; const void *clientScript;
u32 sendBuffer2Size; u32 clientScriptSize;
u32 sendWord; u32 stamp;
struct MysteryGiftLink manager; struct MysteryGiftLink manager;
}; };
u32 MysteryGiftLink_Recv(struct MysteryGiftLink * link); void MysterGiftServer_CreateForNews(void);
u32 MysteryGiftLink_Send(struct MysteryGiftLink * link); void MysterGiftServer_CreateForCard(void);
void MysteryGiftLink_Init(struct MysteryGiftLink * link, u32 sendPlayerId, u32 recvPlayerId); u32 MysterGiftServer_Run(u16 * endVal);
void MysteryGiftLink_InitSend(struct MysteryGiftLink * link, u32 ident, const void *src, u32 size);
void MysteryGiftLink_InitRecv(struct MysteryGiftLink * link, u32 ident, void *dest);
void mevent_client_do_init(void);
u32 mevent_client_do_exec(u16 * a0);
void mevent_client_inc_flag(void);
void *mevent_client_get_buffer(void);
void mevent_client_set_param(u32 a0);
void mevent_srv_init_wnews(void);
void mevent_srv_new_wcard(void);
u32 mevent_srv_common_do_exec(u16 * a0);
#endif //GUARD_MYSTERY_GIFT_SERVER_H #endif //GUARD_MYSTERY_GIFT_SERVER_H
+2 -2
View File
@@ -810,7 +810,7 @@ bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData * d
return TRUE; return TRUE;
} }
u32 MysteryGift_CompareCardFlags(const u16 * flagId, const struct MysteryGiftLinkGameData * data, void *unused) u32 MysteryGift_CompareCardFlags(const u16 * flagId, const struct MysteryGiftLinkGameData * data, const void *unused)
{ {
// Has a Wonder Card already? // Has a Wonder Card already?
if (data->flagId == 0) if (data->flagId == 0)
@@ -824,7 +824,7 @@ u32 MysteryGift_CompareCardFlags(const u16 * flagId, const struct MysteryGiftLin
return 2; return 2;
} }
u32 MysteryGift_CheckStamps(const u16 * stamp, const struct MysteryGiftLinkGameData * data, void *unused) u32 MysteryGift_CheckStamps(const u16 * stamp, const struct MysteryGiftLinkGameData * data, const void *unused)
{ {
s32 stampsMissing = data->maxStamps - GetNumStampsInMetadata(&data->cardMetadata, data->maxStamps); s32 stampsMissing = data->maxStamps - GetNumStampsInMetadata(&data->cardMetadata, data->maxStamps);
+185 -174
View File
@@ -6,285 +6,296 @@
#include "battle_tower.h" #include "battle_tower.h"
#include "mystery_event_script.h" #include "mystery_event_script.h"
#include "mystery_gift.h" #include "mystery_gift.h"
#include "mystery_gift_client.h"
#include "mystery_gift_server.h" #include "mystery_gift_server.h"
static EWRAM_DATA struct mevent_client * s_mevent_client_ptr = NULL; enum {
FUNC_INIT,
FUNC_DONE,
FUNC_RECV,
FUNC_SEND,
FUNC_RUN,
FUNC_WAIT,
FUNC_RUN_MEVENT,
FUNC_RUN_BUFFER,
};
static void mevent_client_init(struct mevent_client *, u32, u32); static EWRAM_DATA 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 gMEventClientScript_InitialListen[]; 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(void) extern const struct MysteryGiftClientCmd gMysteryGiftClientScript_Init[];
void MysteryGiftClient_Create(void)
{ {
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);
} }
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_AND_SET_NULL(sClient);
s_mevent_client_ptr = 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 *MysteryGiftClient_GetMsg(void)
{ {
return s_mevent_client_ptr->buffer; return sClient->msg;
} }
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 sendPlayerId, u32 recvPlayerId)
{ {
svr->unk_00 = 0; client->unused = 0;
svr->mainseqno = 0; client->funcId = FUNC_INIT;
svr->flag = 0; client->funcState = 0;
svr->sendBuffer = AllocZeroed(ME_SEND_BUF_SIZE); client->sendBuffer = AllocZeroed(MG_LINK_BUFFER_SIZE);
svr->recvBuffer = AllocZeroed(ME_SEND_BUF_SIZE); client->recvBuffer = AllocZeroed(MG_LINK_BUFFER_SIZE);
svr->cmdBuffer = AllocZeroed(ME_SEND_BUF_SIZE); client->script = AllocZeroed(MG_LINK_BUFFER_SIZE);
svr->buffer = AllocZeroed(0x40); client->msg = AllocZeroed(CLIENT_MAX_MSG_SIZE);
MysteryGiftLink_Init(&svr->manager, sendPlayerNo, recvPlayerNo); MysteryGiftLink_Init(&client->link, sendPlayerId, recvPlayerId);
} }
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->script);
Free(svr->buffer); Free(client->msg);
} }
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->script, client->recvBuffer, MG_LINK_BUFFER_SIZE);
svr->cmdidx = 0; client->cmdidx = 0;
} }
static void mevent_client_send_word(struct mevent_client * svr, u32 ident, u32 word) static void MysteryGiftClient_InitSendWord(struct MysteryGiftClient * client, u32 ident, u32 word)
{ {
CpuFill32(0, svr->sendBuffer, ME_SEND_BUF_SIZE); CpuFill32(0, client->sendBuffer, MG_LINK_BUFFER_SIZE);
*(u32 *)svr->sendBuffer = word; *(u32 *)client->sendBuffer = word;
MysteryGiftLink_InitSend(&svr->manager, ident, svr->sendBuffer, sizeof(u32)); MysteryGiftLink_InitSend(&client->link, ident, client->sendBuffer, sizeof(word));
} }
static u32 client_mainseq_0(struct mevent_client * svr) static u32 Client_Init(struct MysteryGiftClient * client)
{ {
// init // init
memcpy(svr->cmdBuffer, gMEventClientScript_InitialListen, ME_SEND_BUF_SIZE); memcpy(client->script, gMysteryGiftClientScript_Init, MG_LINK_BUFFER_SIZE);
svr->cmdidx = 0; client->cmdidx = 0;
svr->mainseqno = 4; client->funcId = FUNC_RUN;
svr->flag = 0; client->funcState = 0;
return 0; return CLI_RET_INIT;
} }
static u32 client_mainseq_1(struct mevent_client * svr) static u32 Client_Done(struct MysteryGiftClient * client)
{ {
// done return CLI_RET_END;
return 6;
} }
static u32 client_mainseq_2(struct mevent_client * svr) static u32 Client_Recv(struct MysteryGiftClient * client)
{ {
// do recv if (MysteryGiftLink_Recv(&client->link))
if (MysteryGiftLink_Recv(&svr->manager))
{ {
svr->mainseqno = 4; client->funcId = FUNC_RUN;
svr->flag = 0; client->funcState = 0;
} }
return 1; return CLI_RET_ACTIVE;
} }
static u32 client_mainseq_3(struct mevent_client * svr) static u32 Client_Send(struct MysteryGiftClient * client)
{ {
// do send if (MysteryGiftLink_Send(&client->link))
if (MysteryGiftLink_Send(&svr->manager))
{ {
svr->mainseqno = 4; client->funcId = FUNC_RUN;
svr->flag = 0; client->funcState = 0;
} }
return 1; return CLI_RET_ACTIVE;
} }
static u32 client_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->script[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:
MysteryGiftLink_InitRecv(&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_SEND_READY_END:
MysteryGiftLink_InitSend(&svr->manager, 0x14, svr->sendBuffer, 0); MysteryGiftLink_InitSend(&client->link, MG_LINKID_READY_END, 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_InitSendWord(client, MG_LINKID_GAME_STAT, 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_YES_NO:
memcpy(svr->buffer, svr->recvBuffer, 0x40); memcpy(client->msg, client->recvBuffer, CLIENT_MAX_MSG_SIZE);
svr->mainseqno = 5; client->funcId = FUNC_WAIT;
svr->flag = 0; client->funcState = 0;
return 2; return CLI_RET_YES_NO;
case 11: case CLI_PRINT_MSG:
memcpy(svr->buffer, svr->recvBuffer, 0x40); memcpy(client->msg, client->recvBuffer, CLIENT_MAX_MSG_SIZE);
svr->mainseqno = 5; client->funcId = FUNC_WAIT;
svr->flag = 0; client->funcState = 0;
return 3; return CLI_RET_PRINT_MSG;
case 12: case CLI_COPY_MSG:
memcpy(svr->buffer, svr->recvBuffer, 0x40); memcpy(client->msg, client->recvBuffer, CLIENT_MAX_MSG_SIZE);
svr->mainseqno = 5; client->funcId = FUNC_WAIT;
svr->flag = 0; client->funcState = 0;
return 5; return CLI_RET_COPY_MSG;
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_LOAD_GAME_DATA:
MysteryGift_LoadLinkGameData(svr->sendBuffer); MysteryGift_LoadLinkGameData(client->sendBuffer);
MysteryGiftLink_InitSend(&svr->manager, 0x11, svr->sendBuffer, sizeof(struct MysteryGiftLinkGameData)); MysteryGiftLink_InitSend(&client->link, MG_LINKID_GAME_DATA, client->sendBuffer, sizeof(struct MysteryGiftLinkGameData));
break; break;
case 14: case CLI_LOAD_TOSS_RESPONSE:
mevent_client_send_word(svr, 0x13, svr->param); // param here is set by MG_STATE_CLIENT_ASK_TOSS or MG_STATE_CLIENT_ASK_TOSS_UNRECEIVED
MysteryGiftClient_InitSendWord(client, MG_LINKID_RESPONSE, client->param);
break; break;
case 10: case CLI_SAVE_CARD:
SaveWonderCard(svr->recvBuffer); SaveWonderCard(client->recvBuffer);
break; break;
case 9: case CLI_SAVE_NEWS:
if (!IsWonderNewsSameAsSaved(svr->recvBuffer)) if (!IsWonderNewsSameAsSaved(client->recvBuffer))
{ {
SaveWonderNews(svr->recvBuffer); SaveWonderNews(client->recvBuffer);
mevent_client_send_word(svr, 0x13, 0); MysteryGiftClient_InitSendWord(client, MG_LINKID_RESPONSE, FALSE);
} }
else else
// Other trainer already has news {
mevent_client_send_word(svr, 0x13, 1); // Wonder News has already been saved (or is invalid).
// Prepare a signal to indicate it was not saved.
MysteryGiftClient_InitSendWord(client, MG_LINKID_RESPONSE, TRUE);
}
break; break;
case 15: case CLI_RUN_MEVENT_SCRIPT:
svr->mainseqno = 6; client->funcId = FUNC_RUN_MEVENT;
svr->flag = 0; client->funcState = 0;
break; break;
case 16: case CLI_SAVE_STAMP:
MysteryGift_TrySaveStamp(svr->recvBuffer); MysteryGift_TrySaveStamp(client->recvBuffer);
break; break;
case 17: case CLI_SAVE_RAM_SCRIPT:
InitRamScript_NoObjectEvent(svr->recvBuffer, 1000); InitRamScript_NoObjectEvent(client->recvBuffer, sizeof(struct RamScriptData));
break; break;
case 18: case CLI_RECV_EREADER_TRAINER:
memcpy(&gSaveBlock2Ptr->battleTower.ereaderTrainer, svr->recvBuffer, sizeof(struct BattleTowerEReaderTrainer)); memcpy(&gSaveBlock2Ptr->battleTower.ereaderTrainer, client->recvBuffer, sizeof(gSaveBlock2Ptr->battleTower.ereaderTrainer));
ValidateEReaderTrainer(); ValidateEReaderTrainer();
break; break;
case 21: case CLI_RUN_BUFFER_SCRIPT:
memcpy(gDecompressionBuffer, svr->recvBuffer, ME_SEND_BUF_SIZE); memcpy(gDecompressionBuffer, client->recvBuffer, MG_LINK_BUFFER_SIZE);
svr->mainseqno = 7; client->funcId = FUNC_RUN_BUFFER;
svr->flag = 0; client->funcState = 0;
break; break;
} }
return 1; return CLI_RET_ACTIVE;
} }
static u32 client_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_ACTIVE;
} }
static u32 client_mainseq_6(struct mevent_client * svr) static u32 Client_RunMysteryEventScript(struct MysteryGiftClient * client)
{ {
// Run mevent buffer script switch (client->funcState)
switch (svr->flag)
{ {
case 0: case 0:
MEventScript_InitContext(svr->recvBuffer); MEventScript_InitContext(client->recvBuffer);
++svr->flag; client->funcState++;
break; break;
case 1: case 1:
if (!MEventScript_Run(&svr->param)) if (!MEventScript_Run(&client->param))
{ {
svr->mainseqno = 4; client->funcId = FUNC_RUN;
svr->flag = 0; client->funcState = 0;
} }
break; break;
} }
return 1; return CLI_RET_ACTIVE;
} }
static u32 client_mainseq_7(struct mevent_client * svr) static u32 Client_RunBufferScript(struct MysteryGiftClient * client)
{ {
// 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_ACTIVE;
} }
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 *) = {
client_mainseq_0, [FUNC_INIT] = Client_Init,
client_mainseq_1, [FUNC_DONE] = Client_Done,
client_mainseq_2, [FUNC_RECV] = Client_Recv,
client_mainseq_3, [FUNC_SEND] = Client_Send,
client_mainseq_4, [FUNC_RUN] = Client_Run,
client_mainseq_5, [FUNC_WAIT] = Client_Wait,
client_mainseq_6, [FUNC_RUN_MEVENT] = Client_RunMysteryEventScript,
client_mainseq_7 [FUNC_RUN_BUFFER] = Client_RunBufferScript
}; };
return funcs[svr->mainseqno](svr); return funcs[client->funcId](client);
} }
+29 -28
View File
@@ -14,6 +14,7 @@
#include "link.h" #include "link.h"
#include "event_data.h" #include "event_data.h"
#include "mystery_gift_server.h" #include "mystery_gift_server.h"
#include "mystery_gift_client.h"
#include "wonder_news.h" #include "wonder_news.h"
#include "help_system.h" #include "help_system.h"
#include "strings.h" #include "strings.h"
@@ -1222,7 +1223,7 @@ void task00_mystery_gift(u8 taskId)
{ {
ClearScreenInBg0(TRUE); ClearScreenInBg0(TRUE);
data->state = 7; data->state = 7;
mevent_client_do_init(); MysteryGiftClient_Create();
} }
else if (gSpecialVar_Result == 5) else if (gSpecialVar_Result == 5)
{ {
@@ -1235,7 +1236,7 @@ void task00_mystery_gift(u8 taskId)
data->state = 8; data->state = 8;
break; break;
case 8: case 8:
switch (mevent_client_do_exec(&data->curPromptWindowId)) switch (MysteryGiftClient_Run(&data->curPromptWindowId))
{ {
case 6: // done case 6: // done
Rfu_SetCloseLinkCallback(); Rfu_SetCloseLinkCallback();
@@ -1243,8 +1244,8 @@ void task00_mystery_gift(u8 taskId)
data->state = 13; data->state = 13;
break; break;
case 5: case 5:
memcpy(data->buffer, mevent_client_get_buffer(), 0x40); memcpy(data->buffer, MysteryGiftClient_GetMsg(), 0x40);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
break; break;
case 3: case 3:
data->state = 10; data->state = 10;
@@ -1259,30 +1260,30 @@ void task00_mystery_gift(u8 taskId)
} }
break; break;
case 9: case 9:
flag = DoMysteryGiftYesNo(&data->textState, &data->curPromptWindowId, FALSE, mevent_client_get_buffer()); flag = DoMysteryGiftYesNo(&data->textState, &data->curPromptWindowId, FALSE, MysteryGiftClient_GetMsg());
switch (flag) switch (flag)
{ {
case 0: case 0:
mevent_client_set_param(0); MysteryGiftClient_SetParam(0);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = 7; data->state = 7;
break; break;
case 1: case 1:
mevent_client_set_param(1); MysteryGiftClient_SetParam(1);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = 7; data->state = 7;
break; break;
case -1u: case -1u:
mevent_client_set_param(1); MysteryGiftClient_SetParam(1);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = 7; data->state = 7;
break; break;
} }
break; break;
case 10: case 10:
if (PrintMysteryGiftMenuMessage(&data->textState, mevent_client_get_buffer())) if (PrintMysteryGiftMenuMessage(&data->textState, MysteryGiftClient_GetMsg()))
{ {
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = 7; data->state = 7;
} }
break; break;
@@ -1297,19 +1298,19 @@ void task00_mystery_gift(u8 taskId)
} }
else else
{ {
mevent_client_set_param(0); MysteryGiftClient_SetParam(0);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = 7; data->state = 7;
} }
break; break;
case 1: case 1:
mevent_client_set_param(1); MysteryGiftClient_SetParam(1);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = 7; data->state = 7;
break; break;
case -1u: case -1u:
mevent_client_set_param(1); MysteryGiftClient_SetParam(1);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = 7; data->state = 7;
break; break;
} }
@@ -1319,18 +1320,18 @@ void task00_mystery_gift(u8 taskId)
switch (flag) switch (flag)
{ {
case 0: case 0:
mevent_client_set_param(0); MysteryGiftClient_SetParam(0);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = 7; data->state = 7;
break; break;
case 1: case 1:
mevent_client_set_param(1); MysteryGiftClient_SetParam(1);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = 7; data->state = 7;
break; break;
case -1u: case -1u:
mevent_client_set_param(1); MysteryGiftClient_SetParam(1);
mevent_client_inc_flag(); MysteryGiftClient_AdvanceState();
data->state = 7; data->state = 7;
break; break;
} }
@@ -1567,17 +1568,17 @@ void task00_mystery_gift(u8 taskId)
if (data->IsCardOrNews == 0) if (data->IsCardOrNews == 0)
{ {
AddTextPrinterToWindow1(gText_SendingWonderCard); AddTextPrinterToWindow1(gText_SendingWonderCard);
mevent_srv_new_wcard(); MysterGiftServer_CreateForCard();
} }
else else
{ {
AddTextPrinterToWindow1(gText_SendingWonderNews); AddTextPrinterToWindow1(gText_SendingWonderNews);
mevent_srv_init_wnews(); MysterGiftServer_CreateForNews();
} }
data->state = 32; data->state = 32;
break; break;
case 32: case 32:
if (mevent_srv_common_do_exec(&data->curPromptWindowId) == 3) if (MysterGiftServer_Run(&data->curPromptWindowId) == 3)
{ {
data->prevPromptWindowId = data->curPromptWindowId; data->prevPromptWindowId = data->curPromptWindowId;
data->state = 33; data->state = 33;
+143 -137
View File
@@ -1,192 +1,198 @@
#include "global.h" #include "global.h"
#include "mystery_gift_server.h" #include "mystery_gift_server.h"
#include "mystery_gift_client.h"
#include "constants/mystery_gift.h"
extern const struct mevent_server_cmd gServerScript_ClientCanceledCard[]; extern const struct MysteryGiftServerCmd gServerScript_ClientCanceledCard[];
// Unreferenced // Unreferenced
const u8 gUnknown_84687A0[] = _("You have collected all STAMPs!\nWant to input a CARD as a prize?"); static const u8 sText_CollectedAllStamps[] = _("You have collected all STAMPs!\nWant to input a CARD as a prize?");
/* CLIENT SCRIPTS */ //==================
// Client scripts
//==================
const struct mevent_client_cmd gMEventClientScript_InitialListen[] = { // 84687E0 const struct MysteryGiftClientCmd gMysteryGiftClientScript_Init[] = {
CLI_RECEIVE(0x10), {CLI_RECV, MG_LINKID_CLIENT_SCRIPT},
CLI_JUMPBUF {CLI_COPY_RECV}
}; };
const struct mevent_client_cmd gMEventClientScript_Send1442CC[] = { static const struct MysteryGiftClientCmd sClientScript_SendGameData[] = {
CLI_SNDHEAD, {CLI_LOAD_GAME_DATA},
CLI_WAITSND, {CLI_SEND_LOADED},
CLI_RECEIVE(0x10), {CLI_RECV, MG_LINKID_CLIENT_SCRIPT},
CLI_JUMPBUF {CLI_COPY_RECV}
}; };
const struct mevent_client_cmd gMEventClientScript_UnableToRecv[] = { // can't accept card or news static const struct MysteryGiftClientCmd sClientScript_CantAccept[] = {
CLI_SENDALL, {CLI_SEND_READY_END},
CLI_RETURN(0x0a) {CLI_RETURN, CLI_MSG_CANT_ACCEPT}
}; };
const struct mevent_client_cmd gMEventClientScript_CommError[] = { // comm error static const struct MysteryGiftClientCmd sClientScript_CommError[] = {
CLI_SENDALL, {CLI_SEND_READY_END},
CLI_RETURN(0x0b) {CLI_RETURN, CLI_MSG_COMM_ERROR}
}; };
const struct mevent_client_cmd gMEventClientScript_NothingSentOver[] = { // nothing sent static const struct MysteryGiftClientCmd sClientScript_NothingSent[] = {
CLI_SENDALL, {CLI_SEND_READY_END},
CLI_RETURN(0x00) {CLI_RETURN, CLI_MSG_NOTHING_SENT}
}; };
const struct mevent_client_cmd gMEventClientScript_ReceiveCardAndReturnSuccess[] = { // card success static const struct MysteryGiftClientCmd sClientScript_SaveCard[] = {
CLI_RECEIVE(0x16), {CLI_RECV, MG_LINKID_CARD},
CLI_RECVSAV, {CLI_SAVE_CARD},
CLI_RECEIVE(0x19), {CLI_RECV, MG_LINKID_RAM_SCRIPT},
CLI_RECVRAM, {CLI_SAVE_RAM_SCRIPT},
CLI_SENDALL, {CLI_SEND_READY_END},
CLI_RETURN(0x02) {CLI_RETURN, CLI_MSG_CARD_RECEIVED}
}; };
const struct mevent_client_cmd gMEventClientScript_ReceiveNewsAndValidate[] = { static const struct MysteryGiftClientCmd sClientScript_SaveNews[] = {
CLI_RECEIVE(0x17), {CLI_RECV, MG_LINKID_NEWS},
CLI_VLDNEWS, {CLI_SAVE_NEWS},
CLI_WAITSND, {CLI_SEND_LOADED}, // Send whether or not the News was saved (read by sServerScript_SendNews)
CLI_RECEIVE(0x10), {CLI_RECV, MG_LINKID_CLIENT_SCRIPT},
CLI_JUMPBUF {CLI_COPY_RECV}
}; };
const struct mevent_client_cmd gMEventClientScript_AlreadyHadNews[] = { // already had news static const struct MysteryGiftClientCmd sClientScript_HadNews[] = {
CLI_SENDALL, {CLI_SEND_READY_END},
CLI_RETURN(0x07) {CLI_RETURN, CLI_MSG_HAD_NEWS}
}; };
const struct mevent_client_cmd gMEventClientScript_RecvNewsSuccess[] = { // news success static const struct MysteryGiftClientCmd sClientScript_NewsReceived[] = {
CLI_SENDALL, {CLI_SEND_READY_END},
CLI_RETURN(0x03) {CLI_RETURN, CLI_MSG_NEWS_RECEIVED}
}; };
const struct mevent_client_cmd gMEventClientScript_AskWouldLikeToTossCard[] = { static const struct MysteryGiftClientCmd sClientScript_AskToss[] = {
CLI_REQWORD, {CLI_ASK_TOSS},
CLI_SNDWORD, {CLI_LOAD_TOSS_RESPONSE},
CLI_WAITSND, {CLI_SEND_LOADED},
CLI_RECEIVE(0x10), {CLI_RECV, MG_LINKID_CLIENT_SCRIPT},
CLI_JUMPBUF {CLI_COPY_RECV}
}; };
const struct mevent_client_cmd gMEventClientScript_OtherTrainerCanceled[] = { // comm canceled static const struct MysteryGiftClientCmd sClientScript_Canceled[] = {
CLI_SENDALL, {CLI_SEND_READY_END},
CLI_RETURN(0x09) {CLI_RETURN, CLI_MSG_COMM_CANCELED}
}; };
const struct mevent_client_cmd gMEventClientScript_AlreadyHadCard[] = { // already had card static const struct MysteryGiftClientCmd sClientScript_HadCard[] = {
CLI_SENDALL, {CLI_SEND_READY_END},
CLI_RETURN(0x05) {CLI_RETURN, CLI_MSG_HAD_CARD}
}; };
const struct mevent_client_cmd gMEventClientScript_SuccessFromBuffer[] = { // success from buffer static const struct MysteryGiftClientCmd sClientScript_DynamicSuccess[] = {
CLI_RECEIVE(0x15), {CLI_RECV, MG_LINKID_DYNAMIC_MSG},
CLI_RECVBUF, {CLI_COPY_MSG},
CLI_SENDALL, {CLI_SEND_READY_END},
CLI_RETURN(0x0d) {CLI_RETURN, CLI_MSG_BUFFER_SUCCESS}
}; };
/* SERVER SCRIPTS */ //==================
// Server scripts
//==================
const struct mevent_server_cmd gMEventSrvScript_UnableToSend[] = { static const struct MysteryGiftServerCmd sServerScript_CantSend[] = {
SRV_SEND(0x10, gMEventClientScript_UnableToRecv), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_CantAccept)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x14), {SVR_RECV, MG_LINKID_READY_END},
SRV_RETURN(0x0a) {SVR_RETURN, SVR_MSG_CANT_SEND_GIFT_1}
}; };
const struct mevent_server_cmd gUnknown_8468950[] = { static const struct MysteryGiftServerCmd sServerScript_CommError[] = {
SRV_SEND(0x10, gMEventClientScript_CommError), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_CommError)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x14), {SVR_RECV, MG_LINKID_READY_END},
SRV_RETURN(0x0b) {SVR_RETURN, SVR_MSG_COMM_ERROR}
}; };
const struct mevent_server_cmd gUnknown_8468980[] = { static const struct MysteryGiftServerCmd sServerScript_ClientCanceledNews[] = {
SRV_SEND(0x10, gMEventClientScript_OtherTrainerCanceled), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_Canceled)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x14), {SVR_RECV, MG_LINKID_READY_END},
SRV_RETURN(0x09) {SVR_RETURN, SVR_MSG_CLIENT_CANCELED}
}; };
const struct mevent_server_cmd gMEventSrvScript_OtherTrnHasNews[] = { static const struct MysteryGiftServerCmd sServerScript_HasNews[] = {
SRV_SEND(0x10, gMEventClientScript_AlreadyHadNews), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_HadNews)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x14), {SVR_RECV, MG_LINKID_READY_END},
SRV_RETURN(0x07) {SVR_RETURN, SVR_MSG_HAS_NEWS}
}; };
const struct mevent_server_cmd gMEventSrvScript_SentNewsSuccess[] = { static const struct MysteryGiftServerCmd sServerScript_SendNews[] = {
SRV_SEND(0x28, gMEventClientScript_ReceiveNewsAndValidate), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_SaveNews)},
SRV_WAITSND, {SVR_SEND},
SRV_SEND_NEWS, {SVR_LOAD_NEWS},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x13), {SVR_RECV, MG_LINKID_RESPONSE},
SRV_READWORD, {SVR_READ_RESPONSE},
SRV_BRANCHIF(0x01, gMEventSrvScript_OtherTrnHasNews), {SVR_GOTO_IF_EQ, TRUE, sServerScript_HasNews}, // Wonder News was not saved
SRV_SEND(0x10, gMEventClientScript_RecvNewsSuccess), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_NewsReceived)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x14), {SVR_RECV, MG_LINKID_READY_END},
SRV_RETURN(0x03) {SVR_RETURN, SVR_MSG_NEWS_SENT}
}; };
const struct mevent_server_cmd gMEventSrvScript_SendCardSuccess[] = { static const struct MysteryGiftServerCmd sServerScript_SendCard[] = {
SRV_SEND(0x30, gMEventClientScript_ReceiveCardAndReturnSuccess), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_SaveCard)},
SRV_WAITSND, {SVR_SEND},
SRV_SEND_CARD, {SVR_LOAD_CARD},
SRV_WAITSND, {SVR_SEND},
SRV_BUFFER_SEND, {SVR_LOAD_RAM_SCRIPT},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x14), {SVR_RECV, MG_LINKID_READY_END},
SRV_RETURN(0x02) {SVR_RETURN, SVR_MSG_CARD_SENT}
}; };
const struct mevent_server_cmd gMEventSrvScript_AskClientToOverwriteCard[] = { static const struct MysteryGiftServerCmd sServerScript_TossPrompt[] = {
SRV_SEND(0x28, gMEventClientScript_AskWouldLikeToTossCard), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_AskToss)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x13), {SVR_RECV, MG_LINKID_RESPONSE},
SRV_READWORD, {SVR_READ_RESPONSE},
SRV_BRANCHIF(0x00, gMEventSrvScript_SendCardSuccess), {SVR_GOTO_IF_EQ, FALSE, sServerScript_SendCard}, // Tossed old card, send new one
SRV_BRANCH(gServerScript_ClientCanceledCard) {SVR_GOTO, .parameter = gServerScript_ClientCanceledCard} // Kept old card, cancel new one
}; };
const struct mevent_server_cmd gMEventSrvScript_OtherTrnHasCard[] = { static const struct MysteryGiftServerCmd sServerScript_HasCard[] = {
SRV_SEND(0x10, gMEventClientScript_AlreadyHadCard), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_HadCard)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x14), {SVR_RECV, MG_LINKID_READY_END},
SRV_RETURN(0x05) {SVR_RETURN, SVR_MSG_HAS_CARD}
}; };
const struct mevent_server_cmd gUnknown_8468B3C[] = { static const struct MysteryGiftServerCmd sServerScript_NothingSent[] = {
SRV_SEND(0x10, gMEventClientScript_NothingSentOver), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_NothingSent)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x14), {SVR_RECV, MG_LINKID_READY_END},
SRV_RETURN(0x00) {SVR_RETURN, SVR_MSG_NOTHING_SENT}
}; };
const struct mevent_server_cmd gMEventSrvScript_SendNews[] = { const struct MysteryGiftServerCmd gMysteryGiftServerScript_SendWonderNews[] = {
SRV_BUFFER_NEWS, {SVR_COPY_SAVED_NEWS},
SRV_SEND(0x20, gMEventClientScript_Send1442CC), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_SendGameData)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x11), {SVR_RECV, MG_LINKID_GAME_DATA},
SRV_READ_1442CC, {SVR_COPY_GAME_DATA},
SRV_VALID_1442CC, {SVR_CHECK_GAME_DATA},
SRV_BRANCHIF(0x00, gMEventSrvScript_UnableToSend), {SVR_GOTO_IF_EQ, FALSE, sServerScript_CantSend},
SRV_BRANCH(gMEventSrvScript_SentNewsSuccess) {SVR_GOTO, .parameter = sServerScript_SendNews},
}; };
const struct mevent_server_cmd gMEventSrvScript_SendCard[] = { const struct MysteryGiftServerCmd gMysteryGiftServerScript_SendWonderCard[] = {
SRV_BUFFER_CARD, {SVR_COPY_SAVED_CARD},
SRV_RAM_SCRIPT_IF_VALID, {SVR_COPY_SAVED_RAM_SCRIPT},
SRV_SEND(0x20, gMEventClientScript_Send1442CC), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_SendGameData)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x11), {SVR_RECV, MG_LINKID_GAME_DATA},
SRV_READ_1442CC, {SVR_COPY_GAME_DATA},
SRV_VALID_1442CC, {SVR_CHECK_GAME_DATA},
SRV_BRANCHIF(0x00, gMEventSrvScript_UnableToSend), {SVR_GOTO_IF_EQ, FALSE, sServerScript_CantSend},
SRV_CHECK_1442CC_14, {SVR_CHECK_EXISTING_CARD},
SRV_BRANCHIF(0x02, gMEventSrvScript_AskClientToOverwriteCard), {SVR_GOTO_IF_EQ, HAS_DIFF_CARD, sServerScript_TossPrompt},
SRV_BRANCHIF(0x00, gMEventSrvScript_SendCardSuccess), {SVR_GOTO_IF_EQ, HAS_NO_CARD, sServerScript_SendCard},
SRV_BRANCH(gMEventSrvScript_OtherTrnHasCard) {SVR_GOTO, .parameter = sServerScript_HasCard} // HAS_SAME_CARD
}; };
+208 -198
View File
@@ -4,276 +4,286 @@
#include "mystery_gift.h" #include "mystery_gift.h"
#include "mystery_gift_server.h" #include "mystery_gift_server.h"
EWRAM_DATA struct mevent_srv_common * s_mevent_srv_common_ptr = NULL; enum {
FUNC_INIT,
FUNC_DONE,
FUNC_RECV,
FUNC_SEND,
FUNC_RUN,
};
static void mevent_srv_init_common(struct mevent_srv_common *, const void *, u32, u32); static EWRAM_DATA struct MysteryGiftServer * sServer = NULL;
static void mevent_srv_free_resources(struct mevent_srv_common *);
static u32 mevent_srv_exec_common(struct mevent_srv_common *);
extern const struct mevent_server_cmd gMEventSrvScript_SendNews[]; static void MysteryGiftServer_Init(struct MysteryGiftServer *, const void *, u32, u32);
extern const struct mevent_server_cmd gMEventSrvScript_SendCard[]; static void MysteryGiftServer_Free(struct MysteryGiftServer *);
static u32 MysteryGiftServer_CallFunc(struct MysteryGiftServer *);
void mevent_srv_init_wnews(void) extern const struct MysteryGiftServerCmd gMysteryGiftServerScript_SendWonderNews[];
extern const struct MysteryGiftServerCmd gMysteryGiftServerScript_SendWonderCard[];
void MysterGiftServer_CreateForNews(void)
{ {
s_mevent_srv_common_ptr = AllocZeroed(sizeof(struct mevent_srv_common)); sServer = AllocZeroed(sizeof(*sServer));
mevent_srv_init_common(s_mevent_srv_common_ptr, gMEventSrvScript_SendNews, 0, 1); MysteryGiftServer_Init(sServer, gMysteryGiftServerScript_SendWonderNews, 0, 1);
} }
void mevent_srv_new_wcard(void) void MysterGiftServer_CreateForCard(void)
{ {
s_mevent_srv_common_ptr = AllocZeroed(sizeof(struct mevent_srv_common)); sServer = AllocZeroed(sizeof(*sServer));
mevent_srv_init_common(s_mevent_srv_common_ptr, gMEventSrvScript_SendCard, 0, 1); MysteryGiftServer_Init(sServer, gMysteryGiftServerScript_SendWonderCard, 0, 1);
} }
u32 mevent_srv_common_do_exec(u16 * a0) u32 MysterGiftServer_Run(u16 * endVal)
{ {
u32 result; u32 result;
if (s_mevent_srv_common_ptr == NULL) if (sServer == NULL)
return 3; return SVR_RET_END;
result = mevent_srv_exec_common(s_mevent_srv_common_ptr); result = MysteryGiftServer_CallFunc(sServer);
if (result == 3) if (result == SVR_RET_END)
{ {
*a0 = s_mevent_srv_common_ptr->param; *endVal = sServer->param;
mevent_srv_free_resources(s_mevent_srv_common_ptr); MysteryGiftServer_Free(sServer);
Free(s_mevent_srv_common_ptr); FREE_AND_SET_NULL(sServer);
s_mevent_srv_common_ptr = NULL;
} }
return result; return result;
} }
static void mevent_srv_init_common(struct mevent_srv_common * svr, const void *cmdBuffer, u32 sendPlayerNo, u32 recvPlayerNo) static void MysteryGiftServer_Init(struct MysteryGiftServer * svr, const void *script, u32 sendPlayerId, u32 recvPlayerId)
{ {
svr->unk_00 = 0; svr->unused = 0;
svr->mainseqno = 0; svr->funcId = FUNC_INIT;
svr->card = AllocZeroed(sizeof(struct WonderCard)); svr->card = AllocZeroed(sizeof(*svr->card));
svr->news = AllocZeroed(sizeof(struct WonderNews)); svr->news = AllocZeroed(sizeof(*svr->news));
svr->recvBuffer = AllocZeroed(ME_SEND_BUF_SIZE); svr->recvBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->mevent_unk1442cc = AllocZeroed(sizeof(struct MysteryGiftLinkGameData)); svr->linkGameData = AllocZeroed(sizeof(*svr->linkGameData));
svr->cmdBuffer = cmdBuffer; svr->script = script;
svr->cmdidx = 0; svr->cmdidx = 0;
MysteryGiftLink_Init(&svr->manager, sendPlayerNo, recvPlayerNo); MysteryGiftLink_Init(&svr->manager, sendPlayerId, recvPlayerId);
} }
static void mevent_srv_free_resources(struct mevent_srv_common * svr) static void MysteryGiftServer_Free(struct MysteryGiftServer * svr)
{ {
Free(svr->card); Free(svr->card);
Free(svr->news); Free(svr->news);
Free(svr->recvBuffer); Free(svr->recvBuffer);
Free(svr->mevent_unk1442cc); Free(svr->linkGameData);
} }
static void mevent_srv_common_init_send(struct mevent_srv_common * svr, u32 ident, const void *src, u32 size) static void MysteryGiftServer_InitSend(struct MysteryGiftServer * svr, u32 ident, const void *src, u32 size)
{ {
AGB_ASSERT_EX(size <= ME_SEND_BUF_SIZE, ABSPATH("mevent_server.c"), 257); AGB_ASSERT_EX(size <= ME_SEND_BUF_SIZE, ABSPATH("mevent_server.c"), 257);
MysteryGiftLink_InitSend(&svr->manager, ident, src, size); MysteryGiftLink_InitSend(&svr->manager, ident, src, size);
} }
static void *mevent_first_if_not_null_else_second(void *a0, void *a1) // Given the command pointer parameter and the 'default' normal data.
// If the command's pointer is not empty use that as the send data, otherwise use the default.
static const void *MysteryGiftServer_GetSendData(const void *dynamicData, const void *defaultData)
{ {
if (a0 != NULL) if (dynamicData != NULL)
return a0; return dynamicData;
else else
return a1; return defaultData;
} }
static u32 mevent_compare_pointers(void *a0, void *a1) static u32 MysteryGiftServer_Compare(const void *a, const void *b)
{ {
if (a1 < a0) if (b < a)
return 0; return 0;
else if (a1 == a0) else if (b == a)
return 1; return 1;
else else
return 2; return 2;
} }
static u32 common_mainseq_0(struct mevent_srv_common * svr) static u32 Server_Init(struct MysteryGiftServer * svr)
{ {
// start svr->funcId = FUNC_RUN;
svr->mainseqno = 4; return SVR_RET_INIT;
return 0;
} }
static u32 common_mainseq_1(struct mevent_srv_common * svr) static u32 Server_Done(struct MysteryGiftServer * svr)
{ {
// done return SVR_RET_END;
return 3;
} }
static u32 common_mainseq_2(struct mevent_srv_common * svr) static u32 Server_Recv(struct MysteryGiftServer * svr)
{ {
// do recv
if (MysteryGiftLink_Recv(&svr->manager)) if (MysteryGiftLink_Recv(&svr->manager))
svr->mainseqno = 4; svr->funcId = FUNC_RUN;
return 1; return SVR_RET_ACTIVE;
} }
static u32 common_mainseq_3(struct mevent_srv_common * svr) static u32 Server_Send(struct MysteryGiftServer * svr)
{ {
// do send
if (MysteryGiftLink_Send(&svr->manager)) if (MysteryGiftLink_Send(&svr->manager))
svr->mainseqno = 4; svr->funcId = FUNC_RUN;
return 1; return SVR_RET_ACTIVE;
} }
static u32 common_mainseq_4(struct mevent_srv_common * svr) static u32 Server_Run(struct MysteryGiftServer * svr)
{ {
// process command // process command
const struct mevent_server_cmd * cmd = &svr->cmdBuffer[svr->cmdidx]; const struct MysteryGiftServerCmd * cmd = &svr->script[svr->cmdidx];
void *ptr; const void *ptr;
svr->cmdidx++; svr->cmdidx++;
switch (cmd->instr) switch (cmd->instr)
{ {
case 0: case SVR_RETURN:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 354); AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 354);
svr->mainseqno = 1; svr->funcId = FUNC_DONE;
svr->param = cmd->flag; svr->param = cmd->flag; // Set for endVal in MysteryGiftServer_Run
break; break;
case 1: case SVR_SEND:
svr->mainseqno = 3; svr->funcId = FUNC_SEND;
break; break;
case 2: case SVR_RECV:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 364); AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 364);
MysteryGiftLink_InitRecv(&svr->manager, cmd->flag, svr->recvBuffer); MysteryGiftLink_InitRecv(&svr->manager, cmd->flag, svr->recvBuffer);
svr->mainseqno = 2; svr->funcId = FUNC_RECV;
break; break;
case 3: case SVR_GOTO:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 370); AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 370);
svr->cmdidx = 0;
svr->script = cmd->parameter;
break;
case SVR_COPY_GAME_DATA:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 376);
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 377);
memcpy(svr->linkGameData, svr->recvBuffer, sizeof(*svr->linkGameData));
break;
case SVR_CHECK_GAME_DATA:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 382);
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 383);
svr->param = MysteryGift_ValidateLinkGameData(svr->linkGameData);
break;
case SVR_GOTO_IF_EQ:
if (svr->param == cmd->flag)
{
svr->cmdidx = 0; svr->cmdidx = 0;
svr->cmdBuffer = cmd->parameter; svr->script = cmd->parameter;
break; }
case 5: break;
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 376); case SVR_CHECK_EXISTING_CARD:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 377); AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 396);
memcpy(svr->mevent_unk1442cc, svr->recvBuffer, sizeof(struct MysteryGiftLinkGameData)); ptr = MysteryGiftServer_GetSendData(cmd->parameter, svr->card);
break; svr->param = MysteryGift_CompareCardFlags(ptr, svr->linkGameData, ptr);
case 6: break;
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 382); case SVR_READ_RESPONSE:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 383); AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 402);
svr->param = MysteryGift_ValidateLinkGameData(svr->mevent_unk1442cc); AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 403);
break; svr->param = *(u32 *)svr->recvBuffer;
case 4: break;
if (svr->param == cmd->flag) case SVR_CHECK_EXISTING_STAMPS:
{ AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 408);
svr->cmdidx = 0; ptr = MysteryGiftServer_GetSendData(cmd->parameter, &svr->stamp);
svr->cmdBuffer = cmd->parameter; svr->param = MysteryGift_CheckStamps(ptr, svr->linkGameData, ptr);
} break;
break; case SVR_GET_CARD_STAT:
case 7: AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 415);
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 396); svr->param = MysteryGift_GetCardStatFromLinkData(svr->linkGameData, cmd->flag);
ptr = mevent_first_if_not_null_else_second(cmd->parameter, svr->card); break;
svr->param = MysteryGift_CompareCardFlags(ptr, svr->mevent_unk1442cc, ptr); case SVR_CHECK_QUESTIONNAIRE:
break; AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 420);
case 8: svr->param = MysteryGift_DoesQuestionnaireMatch(svr->linkGameData, cmd->parameter);
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 402); break;
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 403); case SVR_COMPARE:
svr->param = *(u32 *)svr->recvBuffer; AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 426);
break; svr->param = MysteryGiftServer_Compare(cmd->parameter, *(void **)svr->recvBuffer);
case 9: break;
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 408); case SVR_LOAD_NEWS:
ptr = mevent_first_if_not_null_else_second(cmd->parameter, &svr->sendWord); AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 432);
svr->param = MysteryGift_CheckStamps(ptr, svr->mevent_unk1442cc, ptr); MysteryGiftServer_InitSend(svr, MG_LINKID_NEWS, MysteryGiftServer_GetSendData(cmd->parameter, svr->news), sizeof(struct WonderNews));
break; break;
case 10: case SVR_LOAD_CARD:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 415); AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 438);
svr->param = MysteryGift_GetCardStatFromLinkData(svr->mevent_unk1442cc, cmd->flag); MysteryGiftServer_InitSend(svr, MG_LINKID_CARD, MysteryGiftServer_GetSendData(cmd->parameter, svr->card), sizeof(struct WonderCard));
break; break;
case 11: case SVR_LOAD_STAMP:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 420); AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 444);
svr->param = MysteryGift_DoesQuestionnaireMatch(svr->mevent_unk1442cc, cmd->parameter); MysteryGiftServer_InitSend(svr, MG_LINKID_STAMP, MysteryGiftServer_GetSendData(cmd->parameter, &svr->stamp), sizeof(svr->stamp));
break; break;
case 12: case SVR_LOAD_RAM_SCRIPT:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 426); if (cmd->parameter == NULL)
svr->param = mevent_compare_pointers(cmd->parameter, *(void **)svr->recvBuffer); MysteryGiftServer_InitSend(svr, MG_LINKID_RAM_SCRIPT, svr->ramScript, svr->ramScriptSize);
break; else
case 14: MysteryGiftServer_InitSend(svr, MG_LINKID_RAM_SCRIPT, cmd->parameter, cmd->flag);
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 432); break;
mevent_srv_common_init_send(svr, 0x17, mevent_first_if_not_null_else_second(cmd->parameter, svr->news), sizeof(struct WonderNews)); case SVR_LOAD_CLIENT_SCRIPT:
break; if (cmd->parameter == NULL)
case 13: MysteryGiftServer_InitSend(svr, MG_LINKID_CLIENT_SCRIPT, svr->clientScript, svr->clientScriptSize);
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 438); else
mevent_srv_common_init_send(svr, 0x16, mevent_first_if_not_null_else_second(cmd->parameter, svr->card), sizeof(struct WonderCard)); MysteryGiftServer_InitSend(svr, MG_LINKID_CLIENT_SCRIPT, cmd->parameter, cmd->flag);
break; break;
case 16: case SVR_LOAD_EREADER_TRAINER:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 444); AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 466);
mevent_srv_common_init_send(svr, 0x18, mevent_first_if_not_null_else_second(cmd->parameter, &svr->sendWord), 4); MysteryGiftServer_InitSend(svr, MG_LINKID_EREADER_TRAINER, cmd->parameter, 188);
break; break;
case 15: case SVR_LOAD_MSG:
if (cmd->parameter == NULL) MysteryGiftServer_InitSend(svr, MG_LINKID_DYNAMIC_MSG, cmd->parameter, cmd->flag);
mevent_srv_common_init_send(svr, 0x19, svr->sendBuffer1, svr->sendBuffer1Size); break;
else case SVR_LOAD_UNK_2:
mevent_srv_common_init_send(svr, 0x19, cmd->parameter, cmd->flag); MysteryGiftServer_InitSend(svr, MG_LINKID_UNK_2, cmd->parameter, cmd->flag);
break; break;
case 18: case SVR_COPY_CARD:
if (cmd->parameter == NULL) AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 481);
mevent_srv_common_init_send(svr, 0x10, svr->sendBuffer2, svr->sendBuffer2Size); memcpy(svr->card, cmd->parameter, sizeof(*svr->card));
else break;
mevent_srv_common_init_send(svr, 0x10, cmd->parameter, cmd->flag); case SVR_COPY_NEWS:
break; AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 486);
case 19: memcpy(svr->news, cmd->parameter, sizeof(*svr->news));
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 466); break;
mevent_srv_common_init_send(svr, 0x1a, cmd->parameter, 188); case SVR_COPY_STAMP:
break; AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 491);
case 20: svr->stamp = *(u32 *)cmd->parameter;
mevent_srv_common_init_send(svr, 0x15, cmd->parameter, cmd->flag); break;
break; case SVR_SET_RAM_SCRIPT:
case 17: svr->ramScript = cmd->parameter;
mevent_srv_common_init_send(svr, 0x1c, cmd->parameter, cmd->flag); svr->ramScriptSize = cmd->flag;
break; break;
case 22: case SVR_SET_CLIENT_SCRIPT:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 481); svr->clientScript = cmd->parameter;
memcpy(svr->card, cmd->parameter, 332); svr->clientScriptSize = cmd->flag;
break; break;
case 23: case SVR_COPY_SAVED_CARD:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 486); AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, ABSPATH("mevent_server.c"), 506);
memcpy(svr->news, cmd->parameter, 444); memcpy(svr->card, GetSavedWonderCard(), sizeof(*svr->card));
break; DisableWonderCardSending(svr->card);
case 21: break;
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 491); case SVR_COPY_SAVED_NEWS:
svr->sendWord = *(u32 *)cmd->parameter; AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, ABSPATH("mevent_server.c"), 512);
break; memcpy(svr->news, GetSavedWonderNews(), sizeof(*svr->news));
case 24: break;
svr->sendBuffer1 = cmd->parameter; case SVR_COPY_SAVED_RAM_SCRIPT:
svr->sendBuffer1Size = cmd->flag; AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, ABSPATH("mevent_server.c"), 517);
break; svr->ramScript = GetSavedRamScriptIfValid();
case 25: break;
svr->sendBuffer2 = cmd->parameter; case SVR_LOAD_UNK_1:
svr->sendBuffer2Size = cmd->flag; MysteryGiftServer_InitSend(svr, MG_LINKID_UNK_1, cmd->parameter, cmd->flag);
break; break;
case 26:
AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, ABSPATH("mevent_server.c"), 506);
memcpy(svr->card, GetSavedWonderCard(), 332);
DisableWonderCardSending(svr->card);
break;
case 27:
AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, ABSPATH("mevent_server.c"), 512);
memcpy(svr->news, GetSavedWonderNews(), 444);
break;
case 28:
AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, ABSPATH("mevent_server.c"), 517);
svr->sendBuffer1 = GetSavedRamScriptIfValid();
break;
case 29:
mevent_srv_common_init_send(svr, 0x1b, cmd->parameter, cmd->flag);
break;
} }
return 1; return SVR_RET_ACTIVE;
} }
static u32 (*const func_tbl[])(struct mevent_srv_common *) = { static u32 (*const sFuncTable[])(struct MysteryGiftServer *) = {
common_mainseq_0, [FUNC_INIT] = Server_Init,
common_mainseq_1, [FUNC_DONE] = Server_Done,
common_mainseq_2, [FUNC_RECV] = Server_Recv,
common_mainseq_3, [FUNC_SEND] = Server_Send,
common_mainseq_4 [FUNC_RUN] = Server_Run
}; };
static u32 mevent_srv_exec_common(struct mevent_srv_common * svr) static u32 MysteryGiftServer_CallFunc(struct MysteryGiftServer * svr)
{ {
// Original GF names
#define mainseqno funcId
#define func_tbl sFuncTable
u32 response; u32 response;
AGB_ASSERT_EX(svr->mainseqno < NELEMS(func_tbl), ABSPATH("mevent_server.c"), 546); AGB_ASSERT_EX(svr->mainseqno < NELEMS(func_tbl), ABSPATH("mevent_server.c"), 546);
response = func_tbl[svr->mainseqno](svr); response = sFuncTable[svr->funcId](svr);
AGB_ASSERT_EX(svr->mainseqno < NELEMS(func_tbl), ABSPATH("mevent_server.c"), 548); AGB_ASSERT_EX(svr->mainseqno < NELEMS(func_tbl), ABSPATH("mevent_server.c"), 548);
return response; return response;
#undef mainseqno
#undef func_tbl
} }
+13 -12
View File
@@ -1,6 +1,7 @@
#include "global.h" #include "global.h"
#include "link_rfu.h" #include "link_rfu.h"
#include "mystery_gift_server.h" #include "mystery_gift_server.h"
#include "mystery_gift_client.h"
#include "constants/union_room.h" #include "constants/union_room.h"
ALIGNED(4) const u8 gText_UR_EmptyString[] = _(""); ALIGNED(4) const u8 gText_UR_EmptyString[] = _("");
@@ -558,18 +559,18 @@ const u8 *const gTexts_UR_GladToMeetYou[GENDER_COUNT] = {
ALIGNED(4) const u8 gText_UR_FinishedCheckingPlayersTrainerCard[] = _("Finished checking {SPECIAL_F7 0x01}'s\nTRAINER CARD.{PAUSE 60}"); ALIGNED(4) const u8 gText_UR_FinishedCheckingPlayersTrainerCard[] = _("Finished checking {SPECIAL_F7 0x01}'s\nTRAINER CARD.{PAUSE 60}");
ALIGNED(4) static const u8 sText_CanceledReadingCard[] = _("Canceled reading the Card."); ALIGNED(4) static const u8 sText_CanceledReadingCard[] = _("Canceled reading the Card.");
static const struct mevent_client_cmd sClientScript_DynamicError[] = { static const struct MysteryGiftClientCmd sClientScript_DynamicError[] = {
CLI_RECEIVE(0x15), {CLI_RECV, MG_LINKID_DYNAMIC_MSG},
CLI_RECVBUF, {CLI_COPY_MSG},
CLI_SENDALL, {CLI_SEND_READY_END},
CLI_RETURN(0x0e) {CLI_RETURN, CLI_MSG_BUFFER_FAILURE}
}; };
const struct mevent_server_cmd gServerScript_ClientCanceledCard[] = { const struct MysteryGiftServerCmd gServerScript_ClientCanceledCard[] = {
SRV_SEND(0x20, sClientScript_DynamicError), {SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_DynamicError)},
SRV_WAITSND, {SVR_SEND},
SRV_SENDSTR(0x1b, sText_CanceledReadingCard), {SVR_LOAD_MSG, PTR_ARG(sText_CanceledReadingCard)},
SRV_WAITSND, {SVR_SEND},
SRV_RECV(0x14), {SVR_RECV, MG_LINKID_READY_END},
SRV_RETURN(0x09) {SVR_RETURN, SVR_MSG_CLIENT_CANCELED}
}; };