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
+2 -2
View File
@@ -810,7 +810,7 @@ bool32 MysteryGift_ValidateLinkGameData(const struct MysteryGiftLinkGameData * d
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?
if (data->flagId == 0)
@@ -824,7 +824,7 @@ u32 MysteryGift_CompareCardFlags(const u16 * flagId, const struct MysteryGiftLin
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);
+185 -174
View File
@@ -6,285 +6,296 @@
#include "battle_tower.h"
#include "mystery_event_script.h"
#include "mystery_gift.h"
#include "mystery_gift_client.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 u32 mevent_client_exec(struct mevent_client *);
static void mevent_client_free_resources(struct mevent_client *);
static EWRAM_DATA struct MysteryGiftClient * sClient = NULL;
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));
mevent_client_init(s_mevent_client_ptr, 1, 0);
sClient = AllocZeroed(sizeof(*sClient));
MysteryGiftClient_Init(sClient, 1, 0);
}
u32 mevent_client_do_exec(u16 * a0)
u32 MysteryGiftClient_Run(u16 * endVal)
{
u32 result;
if (s_mevent_client_ptr == NULL)
return 6;
result = mevent_client_exec(s_mevent_client_ptr);
if (result == 6)
if (sClient == NULL)
return CLI_RET_END;
result = MysteryGiftClient_CallFunc(sClient);
if (result == CLI_RET_END)
{
*a0 = s_mevent_client_ptr->param;
mevent_client_free_resources(s_mevent_client_ptr);
Free(s_mevent_client_ptr);
s_mevent_client_ptr = NULL;
*endVal = sClient->param;
MysteryGiftClient_Free(sClient);
FREE_AND_SET_NULL(sClient);
}
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;
svr->mainseqno = 0;
svr->flag = 0;
svr->sendBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->recvBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->cmdBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->buffer = AllocZeroed(0x40);
MysteryGiftLink_Init(&svr->manager, sendPlayerNo, recvPlayerNo);
client->unused = 0;
client->funcId = FUNC_INIT;
client->funcState = 0;
client->sendBuffer = AllocZeroed(MG_LINK_BUFFER_SIZE);
client->recvBuffer = AllocZeroed(MG_LINK_BUFFER_SIZE);
client->script = AllocZeroed(MG_LINK_BUFFER_SIZE);
client->msg = AllocZeroed(CLIENT_MAX_MSG_SIZE);
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(svr->recvBuffer);
Free(svr->cmdBuffer);
Free(svr->buffer);
Free(client->sendBuffer);
Free(client->recvBuffer);
Free(client->script);
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);
svr->cmdidx = 0;
memcpy(client->script, client->recvBuffer, MG_LINK_BUFFER_SIZE);
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);
*(u32 *)svr->sendBuffer = word;
MysteryGiftLink_InitSend(&svr->manager, ident, svr->sendBuffer, sizeof(u32));
CpuFill32(0, client->sendBuffer, MG_LINK_BUFFER_SIZE);
*(u32 *)client->sendBuffer = word;
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
memcpy(svr->cmdBuffer, gMEventClientScript_InitialListen, ME_SEND_BUF_SIZE);
svr->cmdidx = 0;
svr->mainseqno = 4;
svr->flag = 0;
return 0;
memcpy(client->script, gMysteryGiftClientScript_Init, MG_LINK_BUFFER_SIZE);
client->cmdidx = 0;
client->funcId = FUNC_RUN;
client->funcState = 0;
return CLI_RET_INIT;
}
static u32 client_mainseq_1(struct mevent_client * svr)
static u32 Client_Done(struct MysteryGiftClient * client)
{
// done
return 6;
return CLI_RET_END;
}
static u32 client_mainseq_2(struct mevent_client * svr)
static u32 Client_Recv(struct MysteryGiftClient * client)
{
// do recv
if (MysteryGiftLink_Recv(&svr->manager))
if (MysteryGiftLink_Recv(&client->link))
{
svr->mainseqno = 4;
svr->flag = 0;
client->funcId = FUNC_RUN;
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(&svr->manager))
if (MysteryGiftLink_Send(&client->link))
{
svr->mainseqno = 4;
svr->flag = 0;
client->funcId = FUNC_RUN;
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
struct mevent_client_cmd * cmd = &svr->cmdBuffer[svr->cmdidx];
++svr->cmdidx;
struct MysteryGiftClientCmd * cmd = &client->script[client->cmdidx];
client->cmdidx++;
switch (cmd->instr)
{
case 0:
case CLI_NONE:
break;
case 1:
svr->param = cmd->parameter;
svr->mainseqno = 1;
svr->flag = 0;
case CLI_RETURN:
client->param = cmd->parameter; // Set for endVal in MysteryGiftClient_Run
client->funcId = FUNC_DONE;
client->funcState = 0;
break;
case 2:
MysteryGiftLink_InitRecv(&svr->manager, cmd->parameter, svr->recvBuffer);
svr->mainseqno = 2;
svr->flag = 0;
case CLI_RECV:
MysteryGiftLink_InitRecv(&client->link, cmd->parameter, client->recvBuffer);
client->funcId = FUNC_RECV;
client->funcState = 0;
break;
case 3:
svr->mainseqno = 3;
svr->flag = 0;
case CLI_SEND_LOADED:
// Send without a MysteryGiftLink_InitSend
// Sends whatever has been loaded already
client->funcId = FUNC_SEND;
client->funcState = 0;
break;
case 20:
MysteryGiftLink_InitSend(&svr->manager, 0x14, svr->sendBuffer, 0);
svr->mainseqno = 3;
svr->flag = 0;
case CLI_SEND_READY_END:
MysteryGiftLink_InitSend(&client->link, MG_LINKID_READY_END, client->sendBuffer, 0);
client->funcId = FUNC_SEND;
client->funcState = 0;
break;
case 19:
mevent_client_send_word(svr, 0x12, GetGameStat(cmd->parameter));
svr->mainseqno = 3;
svr->flag = 0;
case CLI_SEND_STAT:
MysteryGiftClient_InitSendWord(client, MG_LINKID_GAME_STAT, GetGameStat(cmd->parameter));
client->funcId = FUNC_SEND;
client->funcState = 0;
break;
case 6:
if (svr->param == 0)
mevent_client_jmp_buffer(svr);
case CLI_COPY_RECV_IF_N:
if (client->param == FALSE)
MysteryGiftClient_CopyRecvScript(client);
break;
case 7:
if (svr->param == 1)
mevent_client_jmp_buffer(svr);
case CLI_COPY_RECV_IF:
if (client->param == TRUE)
MysteryGiftClient_CopyRecvScript(client);
break;
case 4:
mevent_client_jmp_buffer(svr);
case CLI_COPY_RECV:
MysteryGiftClient_CopyRecvScript(client);
break;
case 5:
memcpy(svr->buffer, svr->recvBuffer, 0x40);
svr->mainseqno = 5;
svr->flag = 0;
return 2;
case 11:
memcpy(svr->buffer, svr->recvBuffer, 0x40);
svr->mainseqno = 5;
svr->flag = 0;
return 3;
case 12:
memcpy(svr->buffer, svr->recvBuffer, 0x40);
svr->mainseqno = 5;
svr->flag = 0;
return 5;
case 13:
svr->mainseqno = 5;
svr->flag = 0;
return 4;
case 8:
MysteryGift_LoadLinkGameData(svr->sendBuffer);
MysteryGiftLink_InitSend(&svr->manager, 0x11, svr->sendBuffer, sizeof(struct MysteryGiftLinkGameData));
case CLI_YES_NO:
memcpy(client->msg, client->recvBuffer, CLIENT_MAX_MSG_SIZE);
client->funcId = FUNC_WAIT;
client->funcState = 0;
return CLI_RET_YES_NO;
case CLI_PRINT_MSG:
memcpy(client->msg, client->recvBuffer, CLIENT_MAX_MSG_SIZE);
client->funcId = FUNC_WAIT;
client->funcState = 0;
return CLI_RET_PRINT_MSG;
case CLI_COPY_MSG:
memcpy(client->msg, client->recvBuffer, CLIENT_MAX_MSG_SIZE);
client->funcId = FUNC_WAIT;
client->funcState = 0;
return CLI_RET_COPY_MSG;
case CLI_ASK_TOSS:
client->funcId = FUNC_WAIT;
client->funcState = 0;
return CLI_RET_ASK_TOSS;
case CLI_LOAD_GAME_DATA:
MysteryGift_LoadLinkGameData(client->sendBuffer);
MysteryGiftLink_InitSend(&client->link, MG_LINKID_GAME_DATA, client->sendBuffer, sizeof(struct MysteryGiftLinkGameData));
break;
case 14:
mevent_client_send_word(svr, 0x13, svr->param);
case CLI_LOAD_TOSS_RESPONSE:
// 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;
case 10:
SaveWonderCard(svr->recvBuffer);
case CLI_SAVE_CARD:
SaveWonderCard(client->recvBuffer);
break;
case 9:
if (!IsWonderNewsSameAsSaved(svr->recvBuffer))
case CLI_SAVE_NEWS:
if (!IsWonderNewsSameAsSaved(client->recvBuffer))
{
SaveWonderNews(svr->recvBuffer);
mevent_client_send_word(svr, 0x13, 0);
SaveWonderNews(client->recvBuffer);
MysteryGiftClient_InitSendWord(client, MG_LINKID_RESPONSE, FALSE);
}
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;
case 15:
svr->mainseqno = 6;
svr->flag = 0;
case CLI_RUN_MEVENT_SCRIPT:
client->funcId = FUNC_RUN_MEVENT;
client->funcState = 0;
break;
case 16:
MysteryGift_TrySaveStamp(svr->recvBuffer);
case CLI_SAVE_STAMP:
MysteryGift_TrySaveStamp(client->recvBuffer);
break;
case 17:
InitRamScript_NoObjectEvent(svr->recvBuffer, 1000);
case CLI_SAVE_RAM_SCRIPT:
InitRamScript_NoObjectEvent(client->recvBuffer, sizeof(struct RamScriptData));
break;
case 18:
memcpy(&gSaveBlock2Ptr->battleTower.ereaderTrainer, svr->recvBuffer, sizeof(struct BattleTowerEReaderTrainer));
case CLI_RECV_EREADER_TRAINER:
memcpy(&gSaveBlock2Ptr->battleTower.ereaderTrainer, client->recvBuffer, sizeof(gSaveBlock2Ptr->battleTower.ereaderTrainer));
ValidateEReaderTrainer();
break;
case 21:
memcpy(gDecompressionBuffer, svr->recvBuffer, ME_SEND_BUF_SIZE);
svr->mainseqno = 7;
svr->flag = 0;
case CLI_RUN_BUFFER_SCRIPT:
memcpy(gDecompressionBuffer, client->recvBuffer, MG_LINK_BUFFER_SIZE);
client->funcId = FUNC_RUN_BUFFER;
client->funcState = 0;
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 (svr->flag)
if (client->funcState)
{
svr->mainseqno = 4;
svr->flag = 0;
client->funcId = FUNC_RUN;
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 (svr->flag)
switch (client->funcState)
{
case 0:
MEventScript_InitContext(svr->recvBuffer);
++svr->flag;
MEventScript_InitContext(client->recvBuffer);
client->funcState++;
break;
case 1:
if (!MEventScript_Run(&svr->param))
if (!MEventScript_Run(&client->param))
{
svr->mainseqno = 4;
svr->flag = 0;
client->funcId = FUNC_RUN;
client->funcState = 0;
}
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;
if (func(&svr->param, gSaveBlock2Ptr, gSaveBlock1Ptr) == 1)
if (func(&client->param, gSaveBlock2Ptr, gSaveBlock1Ptr) == 1)
{
svr->mainseqno = 4;
svr->flag = 0;
client->funcId = FUNC_RUN;
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 *) = {
client_mainseq_0,
client_mainseq_1,
client_mainseq_2,
client_mainseq_3,
client_mainseq_4,
client_mainseq_5,
client_mainseq_6,
client_mainseq_7
u32 (*funcs[])(struct MysteryGiftClient *) = {
[FUNC_INIT] = Client_Init,
[FUNC_DONE] = Client_Done,
[FUNC_RECV] = Client_Recv,
[FUNC_SEND] = Client_Send,
[FUNC_RUN] = Client_Run,
[FUNC_WAIT] = Client_Wait,
[FUNC_RUN_MEVENT] = Client_RunMysteryEventScript,
[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 "event_data.h"
#include "mystery_gift_server.h"
#include "mystery_gift_client.h"
#include "wonder_news.h"
#include "help_system.h"
#include "strings.h"
@@ -1222,7 +1223,7 @@ void task00_mystery_gift(u8 taskId)
{
ClearScreenInBg0(TRUE);
data->state = 7;
mevent_client_do_init();
MysteryGiftClient_Create();
}
else if (gSpecialVar_Result == 5)
{
@@ -1235,7 +1236,7 @@ void task00_mystery_gift(u8 taskId)
data->state = 8;
break;
case 8:
switch (mevent_client_do_exec(&data->curPromptWindowId))
switch (MysteryGiftClient_Run(&data->curPromptWindowId))
{
case 6: // done
Rfu_SetCloseLinkCallback();
@@ -1243,8 +1244,8 @@ void task00_mystery_gift(u8 taskId)
data->state = 13;
break;
case 5:
memcpy(data->buffer, mevent_client_get_buffer(), 0x40);
mevent_client_inc_flag();
memcpy(data->buffer, MysteryGiftClient_GetMsg(), 0x40);
MysteryGiftClient_AdvanceState();
break;
case 3:
data->state = 10;
@@ -1259,30 +1260,30 @@ void task00_mystery_gift(u8 taskId)
}
break;
case 9:
flag = DoMysteryGiftYesNo(&data->textState, &data->curPromptWindowId, FALSE, mevent_client_get_buffer());
flag = DoMysteryGiftYesNo(&data->textState, &data->curPromptWindowId, FALSE, MysteryGiftClient_GetMsg());
switch (flag)
{
case 0:
mevent_client_set_param(0);
mevent_client_inc_flag();
MysteryGiftClient_SetParam(0);
MysteryGiftClient_AdvanceState();
data->state = 7;
break;
case 1:
mevent_client_set_param(1);
mevent_client_inc_flag();
MysteryGiftClient_SetParam(1);
MysteryGiftClient_AdvanceState();
data->state = 7;
break;
case -1u:
mevent_client_set_param(1);
mevent_client_inc_flag();
MysteryGiftClient_SetParam(1);
MysteryGiftClient_AdvanceState();
data->state = 7;
break;
}
break;
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;
}
break;
@@ -1297,19 +1298,19 @@ void task00_mystery_gift(u8 taskId)
}
else
{
mevent_client_set_param(0);
mevent_client_inc_flag();
MysteryGiftClient_SetParam(0);
MysteryGiftClient_AdvanceState();
data->state = 7;
}
break;
case 1:
mevent_client_set_param(1);
mevent_client_inc_flag();
MysteryGiftClient_SetParam(1);
MysteryGiftClient_AdvanceState();
data->state = 7;
break;
case -1u:
mevent_client_set_param(1);
mevent_client_inc_flag();
MysteryGiftClient_SetParam(1);
MysteryGiftClient_AdvanceState();
data->state = 7;
break;
}
@@ -1319,18 +1320,18 @@ void task00_mystery_gift(u8 taskId)
switch (flag)
{
case 0:
mevent_client_set_param(0);
mevent_client_inc_flag();
MysteryGiftClient_SetParam(0);
MysteryGiftClient_AdvanceState();
data->state = 7;
break;
case 1:
mevent_client_set_param(1);
mevent_client_inc_flag();
MysteryGiftClient_SetParam(1);
MysteryGiftClient_AdvanceState();
data->state = 7;
break;
case -1u:
mevent_client_set_param(1);
mevent_client_inc_flag();
MysteryGiftClient_SetParam(1);
MysteryGiftClient_AdvanceState();
data->state = 7;
break;
}
@@ -1567,17 +1568,17 @@ void task00_mystery_gift(u8 taskId)
if (data->IsCardOrNews == 0)
{
AddTextPrinterToWindow1(gText_SendingWonderCard);
mevent_srv_new_wcard();
MysterGiftServer_CreateForCard();
}
else
{
AddTextPrinterToWindow1(gText_SendingWonderNews);
mevent_srv_init_wnews();
MysterGiftServer_CreateForNews();
}
data->state = 32;
break;
case 32:
if (mevent_srv_common_do_exec(&data->curPromptWindowId) == 3)
if (MysterGiftServer_Run(&data->curPromptWindowId) == 3)
{
data->prevPromptWindowId = data->curPromptWindowId;
data->state = 33;
+143 -137
View File
@@ -1,192 +1,198 @@
#include "global.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
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
CLI_RECEIVE(0x10),
CLI_JUMPBUF
const struct MysteryGiftClientCmd gMysteryGiftClientScript_Init[] = {
{CLI_RECV, MG_LINKID_CLIENT_SCRIPT},
{CLI_COPY_RECV}
};
const struct mevent_client_cmd gMEventClientScript_Send1442CC[] = {
CLI_SNDHEAD,
CLI_WAITSND,
CLI_RECEIVE(0x10),
CLI_JUMPBUF
static const struct MysteryGiftClientCmd sClientScript_SendGameData[] = {
{CLI_LOAD_GAME_DATA},
{CLI_SEND_LOADED},
{CLI_RECV, MG_LINKID_CLIENT_SCRIPT},
{CLI_COPY_RECV}
};
const struct mevent_client_cmd gMEventClientScript_UnableToRecv[] = { // can't accept card or news
CLI_SENDALL,
CLI_RETURN(0x0a)
static const struct MysteryGiftClientCmd sClientScript_CantAccept[] = {
{CLI_SEND_READY_END},
{CLI_RETURN, CLI_MSG_CANT_ACCEPT}
};
const struct mevent_client_cmd gMEventClientScript_CommError[] = { // comm error
CLI_SENDALL,
CLI_RETURN(0x0b)
static const struct MysteryGiftClientCmd sClientScript_CommError[] = {
{CLI_SEND_READY_END},
{CLI_RETURN, CLI_MSG_COMM_ERROR}
};
const struct mevent_client_cmd gMEventClientScript_NothingSentOver[] = { // nothing sent
CLI_SENDALL,
CLI_RETURN(0x00)
static const struct MysteryGiftClientCmd sClientScript_NothingSent[] = {
{CLI_SEND_READY_END},
{CLI_RETURN, CLI_MSG_NOTHING_SENT}
};
const struct mevent_client_cmd gMEventClientScript_ReceiveCardAndReturnSuccess[] = { // card success
CLI_RECEIVE(0x16),
CLI_RECVSAV,
CLI_RECEIVE(0x19),
CLI_RECVRAM,
CLI_SENDALL,
CLI_RETURN(0x02)
static const struct MysteryGiftClientCmd sClientScript_SaveCard[] = {
{CLI_RECV, MG_LINKID_CARD},
{CLI_SAVE_CARD},
{CLI_RECV, MG_LINKID_RAM_SCRIPT},
{CLI_SAVE_RAM_SCRIPT},
{CLI_SEND_READY_END},
{CLI_RETURN, CLI_MSG_CARD_RECEIVED}
};
const struct mevent_client_cmd gMEventClientScript_ReceiveNewsAndValidate[] = {
CLI_RECEIVE(0x17),
CLI_VLDNEWS,
CLI_WAITSND,
CLI_RECEIVE(0x10),
CLI_JUMPBUF
static const struct MysteryGiftClientCmd sClientScript_SaveNews[] = {
{CLI_RECV, MG_LINKID_NEWS},
{CLI_SAVE_NEWS},
{CLI_SEND_LOADED}, // Send whether or not the News was saved (read by sServerScript_SendNews)
{CLI_RECV, MG_LINKID_CLIENT_SCRIPT},
{CLI_COPY_RECV}
};
const struct mevent_client_cmd gMEventClientScript_AlreadyHadNews[] = { // already had news
CLI_SENDALL,
CLI_RETURN(0x07)
static const struct MysteryGiftClientCmd sClientScript_HadNews[] = {
{CLI_SEND_READY_END},
{CLI_RETURN, CLI_MSG_HAD_NEWS}
};
const struct mevent_client_cmd gMEventClientScript_RecvNewsSuccess[] = { // news success
CLI_SENDALL,
CLI_RETURN(0x03)
static const struct MysteryGiftClientCmd sClientScript_NewsReceived[] = {
{CLI_SEND_READY_END},
{CLI_RETURN, CLI_MSG_NEWS_RECEIVED}
};
const struct mevent_client_cmd gMEventClientScript_AskWouldLikeToTossCard[] = {
CLI_REQWORD,
CLI_SNDWORD,
CLI_WAITSND,
CLI_RECEIVE(0x10),
CLI_JUMPBUF
static const struct MysteryGiftClientCmd sClientScript_AskToss[] = {
{CLI_ASK_TOSS},
{CLI_LOAD_TOSS_RESPONSE},
{CLI_SEND_LOADED},
{CLI_RECV, MG_LINKID_CLIENT_SCRIPT},
{CLI_COPY_RECV}
};
const struct mevent_client_cmd gMEventClientScript_OtherTrainerCanceled[] = { // comm canceled
CLI_SENDALL,
CLI_RETURN(0x09)
static const struct MysteryGiftClientCmd sClientScript_Canceled[] = {
{CLI_SEND_READY_END},
{CLI_RETURN, CLI_MSG_COMM_CANCELED}
};
const struct mevent_client_cmd gMEventClientScript_AlreadyHadCard[] = { // already had card
CLI_SENDALL,
CLI_RETURN(0x05)
static const struct MysteryGiftClientCmd sClientScript_HadCard[] = {
{CLI_SEND_READY_END},
{CLI_RETURN, CLI_MSG_HAD_CARD}
};
const struct mevent_client_cmd gMEventClientScript_SuccessFromBuffer[] = { // success from buffer
CLI_RECEIVE(0x15),
CLI_RECVBUF,
CLI_SENDALL,
CLI_RETURN(0x0d)
static const struct MysteryGiftClientCmd sClientScript_DynamicSuccess[] = {
{CLI_RECV, MG_LINKID_DYNAMIC_MSG},
{CLI_COPY_MSG},
{CLI_SEND_READY_END},
{CLI_RETURN, CLI_MSG_BUFFER_SUCCESS}
};
/* SERVER SCRIPTS */
//==================
// Server scripts
//==================
const struct mevent_server_cmd gMEventSrvScript_UnableToSend[] = {
SRV_SEND(0x10, gMEventClientScript_UnableToRecv),
SRV_WAITSND,
SRV_RECV(0x14),
SRV_RETURN(0x0a)
static const struct MysteryGiftServerCmd sServerScript_CantSend[] = {
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_CantAccept)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_READY_END},
{SVR_RETURN, SVR_MSG_CANT_SEND_GIFT_1}
};
const struct mevent_server_cmd gUnknown_8468950[] = {
SRV_SEND(0x10, gMEventClientScript_CommError),
SRV_WAITSND,
SRV_RECV(0x14),
SRV_RETURN(0x0b)
static const struct MysteryGiftServerCmd sServerScript_CommError[] = {
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_CommError)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_READY_END},
{SVR_RETURN, SVR_MSG_COMM_ERROR}
};
const struct mevent_server_cmd gUnknown_8468980[] = {
SRV_SEND(0x10, gMEventClientScript_OtherTrainerCanceled),
SRV_WAITSND,
SRV_RECV(0x14),
SRV_RETURN(0x09)
static const struct MysteryGiftServerCmd sServerScript_ClientCanceledNews[] = {
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_Canceled)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_READY_END},
{SVR_RETURN, SVR_MSG_CLIENT_CANCELED}
};
const struct mevent_server_cmd gMEventSrvScript_OtherTrnHasNews[] = {
SRV_SEND(0x10, gMEventClientScript_AlreadyHadNews),
SRV_WAITSND,
SRV_RECV(0x14),
SRV_RETURN(0x07)
static const struct MysteryGiftServerCmd sServerScript_HasNews[] = {
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_HadNews)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_READY_END},
{SVR_RETURN, SVR_MSG_HAS_NEWS}
};
const struct mevent_server_cmd gMEventSrvScript_SentNewsSuccess[] = {
SRV_SEND(0x28, gMEventClientScript_ReceiveNewsAndValidate),
SRV_WAITSND,
SRV_SEND_NEWS,
SRV_WAITSND,
SRV_RECV(0x13),
SRV_READWORD,
SRV_BRANCHIF(0x01, gMEventSrvScript_OtherTrnHasNews),
SRV_SEND(0x10, gMEventClientScript_RecvNewsSuccess),
SRV_WAITSND,
SRV_RECV(0x14),
SRV_RETURN(0x03)
static const struct MysteryGiftServerCmd sServerScript_SendNews[] = {
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_SaveNews)},
{SVR_SEND},
{SVR_LOAD_NEWS},
{SVR_SEND},
{SVR_RECV, MG_LINKID_RESPONSE},
{SVR_READ_RESPONSE},
{SVR_GOTO_IF_EQ, TRUE, sServerScript_HasNews}, // Wonder News was not saved
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_NewsReceived)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_READY_END},
{SVR_RETURN, SVR_MSG_NEWS_SENT}
};
const struct mevent_server_cmd gMEventSrvScript_SendCardSuccess[] = {
SRV_SEND(0x30, gMEventClientScript_ReceiveCardAndReturnSuccess),
SRV_WAITSND,
SRV_SEND_CARD,
SRV_WAITSND,
SRV_BUFFER_SEND,
SRV_WAITSND,
SRV_RECV(0x14),
SRV_RETURN(0x02)
static const struct MysteryGiftServerCmd sServerScript_SendCard[] = {
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_SaveCard)},
{SVR_SEND},
{SVR_LOAD_CARD},
{SVR_SEND},
{SVR_LOAD_RAM_SCRIPT},
{SVR_SEND},
{SVR_RECV, MG_LINKID_READY_END},
{SVR_RETURN, SVR_MSG_CARD_SENT}
};
const struct mevent_server_cmd gMEventSrvScript_AskClientToOverwriteCard[] = {
SRV_SEND(0x28, gMEventClientScript_AskWouldLikeToTossCard),
SRV_WAITSND,
SRV_RECV(0x13),
SRV_READWORD,
SRV_BRANCHIF(0x00, gMEventSrvScript_SendCardSuccess),
SRV_BRANCH(gServerScript_ClientCanceledCard)
static const struct MysteryGiftServerCmd sServerScript_TossPrompt[] = {
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_AskToss)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_RESPONSE},
{SVR_READ_RESPONSE},
{SVR_GOTO_IF_EQ, FALSE, sServerScript_SendCard}, // Tossed old card, send new one
{SVR_GOTO, .parameter = gServerScript_ClientCanceledCard} // Kept old card, cancel new one
};
const struct mevent_server_cmd gMEventSrvScript_OtherTrnHasCard[] = {
SRV_SEND(0x10, gMEventClientScript_AlreadyHadCard),
SRV_WAITSND,
SRV_RECV(0x14),
SRV_RETURN(0x05)
static const struct MysteryGiftServerCmd sServerScript_HasCard[] = {
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_HadCard)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_READY_END},
{SVR_RETURN, SVR_MSG_HAS_CARD}
};
const struct mevent_server_cmd gUnknown_8468B3C[] = {
SRV_SEND(0x10, gMEventClientScript_NothingSentOver),
SRV_WAITSND,
SRV_RECV(0x14),
SRV_RETURN(0x00)
static const struct MysteryGiftServerCmd sServerScript_NothingSent[] = {
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_NothingSent)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_READY_END},
{SVR_RETURN, SVR_MSG_NOTHING_SENT}
};
const struct mevent_server_cmd gMEventSrvScript_SendNews[] = {
SRV_BUFFER_NEWS,
SRV_SEND(0x20, gMEventClientScript_Send1442CC),
SRV_WAITSND,
SRV_RECV(0x11),
SRV_READ_1442CC,
SRV_VALID_1442CC,
SRV_BRANCHIF(0x00, gMEventSrvScript_UnableToSend),
SRV_BRANCH(gMEventSrvScript_SentNewsSuccess)
const struct MysteryGiftServerCmd gMysteryGiftServerScript_SendWonderNews[] = {
{SVR_COPY_SAVED_NEWS},
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_SendGameData)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_GAME_DATA},
{SVR_COPY_GAME_DATA},
{SVR_CHECK_GAME_DATA},
{SVR_GOTO_IF_EQ, FALSE, sServerScript_CantSend},
{SVR_GOTO, .parameter = sServerScript_SendNews},
};
const struct mevent_server_cmd gMEventSrvScript_SendCard[] = {
SRV_BUFFER_CARD,
SRV_RAM_SCRIPT_IF_VALID,
SRV_SEND(0x20, gMEventClientScript_Send1442CC),
SRV_WAITSND,
SRV_RECV(0x11),
SRV_READ_1442CC,
SRV_VALID_1442CC,
SRV_BRANCHIF(0x00, gMEventSrvScript_UnableToSend),
SRV_CHECK_1442CC_14,
SRV_BRANCHIF(0x02, gMEventSrvScript_AskClientToOverwriteCard),
SRV_BRANCHIF(0x00, gMEventSrvScript_SendCardSuccess),
SRV_BRANCH(gMEventSrvScript_OtherTrnHasCard)
const struct MysteryGiftServerCmd gMysteryGiftServerScript_SendWonderCard[] = {
{SVR_COPY_SAVED_CARD},
{SVR_COPY_SAVED_RAM_SCRIPT},
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_SendGameData)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_GAME_DATA},
{SVR_COPY_GAME_DATA},
{SVR_CHECK_GAME_DATA},
{SVR_GOTO_IF_EQ, FALSE, sServerScript_CantSend},
{SVR_CHECK_EXISTING_CARD},
{SVR_GOTO_IF_EQ, HAS_DIFF_CARD, sServerScript_TossPrompt},
{SVR_GOTO_IF_EQ, HAS_NO_CARD, sServerScript_SendCard},
{SVR_GOTO, .parameter = sServerScript_HasCard} // HAS_SAME_CARD
};
+208 -198
View File
@@ -4,276 +4,286 @@
#include "mystery_gift.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 void mevent_srv_free_resources(struct mevent_srv_common *);
static u32 mevent_srv_exec_common(struct mevent_srv_common *);
static EWRAM_DATA struct MysteryGiftServer * sServer = NULL;
extern const struct mevent_server_cmd gMEventSrvScript_SendNews[];
extern const struct mevent_server_cmd gMEventSrvScript_SendCard[];
static void MysteryGiftServer_Init(struct MysteryGiftServer *, const void *, u32, u32);
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));
mevent_srv_init_common(s_mevent_srv_common_ptr, gMEventSrvScript_SendNews, 0, 1);
sServer = AllocZeroed(sizeof(*sServer));
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));
mevent_srv_init_common(s_mevent_srv_common_ptr, gMEventSrvScript_SendCard, 0, 1);
sServer = AllocZeroed(sizeof(*sServer));
MysteryGiftServer_Init(sServer, gMysteryGiftServerScript_SendWonderCard, 0, 1);
}
u32 mevent_srv_common_do_exec(u16 * a0)
u32 MysterGiftServer_Run(u16 * endVal)
{
u32 result;
if (s_mevent_srv_common_ptr == NULL)
return 3;
result = mevent_srv_exec_common(s_mevent_srv_common_ptr);
if (result == 3)
if (sServer == NULL)
return SVR_RET_END;
result = MysteryGiftServer_CallFunc(sServer);
if (result == SVR_RET_END)
{
*a0 = s_mevent_srv_common_ptr->param;
mevent_srv_free_resources(s_mevent_srv_common_ptr);
Free(s_mevent_srv_common_ptr);
s_mevent_srv_common_ptr = NULL;
*endVal = sServer->param;
MysteryGiftServer_Free(sServer);
FREE_AND_SET_NULL(sServer);
}
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->mainseqno = 0;
svr->card = AllocZeroed(sizeof(struct WonderCard));
svr->news = AllocZeroed(sizeof(struct WonderNews));
svr->unused = 0;
svr->funcId = FUNC_INIT;
svr->card = AllocZeroed(sizeof(*svr->card));
svr->news = AllocZeroed(sizeof(*svr->news));
svr->recvBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->mevent_unk1442cc = AllocZeroed(sizeof(struct MysteryGiftLinkGameData));
svr->cmdBuffer = cmdBuffer;
svr->linkGameData = AllocZeroed(sizeof(*svr->linkGameData));
svr->script = script;
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->news);
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);
}
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)
return a0;
if (dynamicData != NULL)
return dynamicData;
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;
else if (a1 == a0)
else if (b == a)
return 1;
else
return 2;
}
static u32 common_mainseq_0(struct mevent_srv_common * svr)
static u32 Server_Init(struct MysteryGiftServer * svr)
{
// start
svr->mainseqno = 4;
return 0;
svr->funcId = FUNC_RUN;
return SVR_RET_INIT;
}
static u32 common_mainseq_1(struct mevent_srv_common * svr)
static u32 Server_Done(struct MysteryGiftServer * svr)
{
// done
return 3;
return SVR_RET_END;
}
static u32 common_mainseq_2(struct mevent_srv_common * svr)
static u32 Server_Recv(struct MysteryGiftServer * svr)
{
// do recv
if (MysteryGiftLink_Recv(&svr->manager))
svr->mainseqno = 4;
return 1;
svr->funcId = FUNC_RUN;
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))
svr->mainseqno = 4;
return 1;
svr->funcId = FUNC_RUN;
return SVR_RET_ACTIVE;
}
static u32 common_mainseq_4(struct mevent_srv_common * svr)
static u32 Server_Run(struct MysteryGiftServer * svr)
{
// process command
const struct mevent_server_cmd * cmd = &svr->cmdBuffer[svr->cmdidx];
void *ptr;
const struct MysteryGiftServerCmd * cmd = &svr->script[svr->cmdidx];
const void *ptr;
svr->cmdidx++;
switch (cmd->instr)
{
case 0:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 354);
svr->mainseqno = 1;
svr->param = cmd->flag;
break;
case 1:
svr->mainseqno = 3;
break;
case 2:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 364);
MysteryGiftLink_InitRecv(&svr->manager, cmd->flag, svr->recvBuffer);
svr->mainseqno = 2;
break;
case 3:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 370);
case SVR_RETURN:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 354);
svr->funcId = FUNC_DONE;
svr->param = cmd->flag; // Set for endVal in MysteryGiftServer_Run
break;
case SVR_SEND:
svr->funcId = FUNC_SEND;
break;
case SVR_RECV:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 364);
MysteryGiftLink_InitRecv(&svr->manager, cmd->flag, svr->recvBuffer);
svr->funcId = FUNC_RECV;
break;
case SVR_GOTO:
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->cmdBuffer = cmd->parameter;
break;
case 5:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 376);
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 377);
memcpy(svr->mevent_unk1442cc, svr->recvBuffer, sizeof(struct MysteryGiftLinkGameData));
break;
case 6:
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->mevent_unk1442cc);
break;
case 4:
if (svr->param == cmd->flag)
{
svr->cmdidx = 0;
svr->cmdBuffer = cmd->parameter;
}
break;
case 7:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 396);
ptr = mevent_first_if_not_null_else_second(cmd->parameter, svr->card);
svr->param = MysteryGift_CompareCardFlags(ptr, svr->mevent_unk1442cc, ptr);
break;
case 8:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 402);
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 403);
svr->param = *(u32 *)svr->recvBuffer;
break;
case 9:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 408);
ptr = mevent_first_if_not_null_else_second(cmd->parameter, &svr->sendWord);
svr->param = MysteryGift_CheckStamps(ptr, svr->mevent_unk1442cc, ptr);
break;
case 10:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 415);
svr->param = MysteryGift_GetCardStatFromLinkData(svr->mevent_unk1442cc, cmd->flag);
break;
case 11:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 420);
svr->param = MysteryGift_DoesQuestionnaireMatch(svr->mevent_unk1442cc, cmd->parameter);
break;
case 12:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 426);
svr->param = mevent_compare_pointers(cmd->parameter, *(void **)svr->recvBuffer);
break;
case 14:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 432);
mevent_srv_common_init_send(svr, 0x17, mevent_first_if_not_null_else_second(cmd->parameter, svr->news), sizeof(struct WonderNews));
break;
case 13:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 438);
mevent_srv_common_init_send(svr, 0x16, mevent_first_if_not_null_else_second(cmd->parameter, svr->card), sizeof(struct WonderCard));
break;
case 16:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 444);
mevent_srv_common_init_send(svr, 0x18, mevent_first_if_not_null_else_second(cmd->parameter, &svr->sendWord), 4);
break;
case 15:
if (cmd->parameter == NULL)
mevent_srv_common_init_send(svr, 0x19, svr->sendBuffer1, svr->sendBuffer1Size);
else
mevent_srv_common_init_send(svr, 0x19, cmd->parameter, cmd->flag);
break;
case 18:
if (cmd->parameter == NULL)
mevent_srv_common_init_send(svr, 0x10, svr->sendBuffer2, svr->sendBuffer2Size);
else
mevent_srv_common_init_send(svr, 0x10, cmd->parameter, cmd->flag);
break;
case 19:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 466);
mevent_srv_common_init_send(svr, 0x1a, cmd->parameter, 188);
break;
case 20:
mevent_srv_common_init_send(svr, 0x15, cmd->parameter, cmd->flag);
break;
case 17:
mevent_srv_common_init_send(svr, 0x1c, cmd->parameter, cmd->flag);
break;
case 22:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 481);
memcpy(svr->card, cmd->parameter, 332);
break;
case 23:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 486);
memcpy(svr->news, cmd->parameter, 444);
break;
case 21:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 491);
svr->sendWord = *(u32 *)cmd->parameter;
break;
case 24:
svr->sendBuffer1 = cmd->parameter;
svr->sendBuffer1Size = cmd->flag;
break;
case 25:
svr->sendBuffer2 = cmd->parameter;
svr->sendBuffer2Size = cmd->flag;
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;
svr->script = cmd->parameter;
}
break;
case SVR_CHECK_EXISTING_CARD:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 396);
ptr = MysteryGiftServer_GetSendData(cmd->parameter, svr->card);
svr->param = MysteryGift_CompareCardFlags(ptr, svr->linkGameData, ptr);
break;
case SVR_READ_RESPONSE:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 402);
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 403);
svr->param = *(u32 *)svr->recvBuffer;
break;
case SVR_CHECK_EXISTING_STAMPS:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 408);
ptr = MysteryGiftServer_GetSendData(cmd->parameter, &svr->stamp);
svr->param = MysteryGift_CheckStamps(ptr, svr->linkGameData, ptr);
break;
case SVR_GET_CARD_STAT:
AGB_ASSERT_EX(cmd->parameter == NULL, ABSPATH("mevent_server.c"), 415);
svr->param = MysteryGift_GetCardStatFromLinkData(svr->linkGameData, cmd->flag);
break;
case SVR_CHECK_QUESTIONNAIRE:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 420);
svr->param = MysteryGift_DoesQuestionnaireMatch(svr->linkGameData, cmd->parameter);
break;
case SVR_COMPARE:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 426);
svr->param = MysteryGiftServer_Compare(cmd->parameter, *(void **)svr->recvBuffer);
break;
case SVR_LOAD_NEWS:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 432);
MysteryGiftServer_InitSend(svr, MG_LINKID_NEWS, MysteryGiftServer_GetSendData(cmd->parameter, svr->news), sizeof(struct WonderNews));
break;
case SVR_LOAD_CARD:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 438);
MysteryGiftServer_InitSend(svr, MG_LINKID_CARD, MysteryGiftServer_GetSendData(cmd->parameter, svr->card), sizeof(struct WonderCard));
break;
case SVR_LOAD_STAMP:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 444);
MysteryGiftServer_InitSend(svr, MG_LINKID_STAMP, MysteryGiftServer_GetSendData(cmd->parameter, &svr->stamp), sizeof(svr->stamp));
break;
case SVR_LOAD_RAM_SCRIPT:
if (cmd->parameter == NULL)
MysteryGiftServer_InitSend(svr, MG_LINKID_RAM_SCRIPT, svr->ramScript, svr->ramScriptSize);
else
MysteryGiftServer_InitSend(svr, MG_LINKID_RAM_SCRIPT, cmd->parameter, cmd->flag);
break;
case SVR_LOAD_CLIENT_SCRIPT:
if (cmd->parameter == NULL)
MysteryGiftServer_InitSend(svr, MG_LINKID_CLIENT_SCRIPT, svr->clientScript, svr->clientScriptSize);
else
MysteryGiftServer_InitSend(svr, MG_LINKID_CLIENT_SCRIPT, cmd->parameter, cmd->flag);
break;
case SVR_LOAD_EREADER_TRAINER:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 466);
MysteryGiftServer_InitSend(svr, MG_LINKID_EREADER_TRAINER, cmd->parameter, 188);
break;
case SVR_LOAD_MSG:
MysteryGiftServer_InitSend(svr, MG_LINKID_DYNAMIC_MSG, cmd->parameter, cmd->flag);
break;
case SVR_LOAD_UNK_2:
MysteryGiftServer_InitSend(svr, MG_LINKID_UNK_2, cmd->parameter, cmd->flag);
break;
case SVR_COPY_CARD:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 481);
memcpy(svr->card, cmd->parameter, sizeof(*svr->card));
break;
case SVR_COPY_NEWS:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 486);
memcpy(svr->news, cmd->parameter, sizeof(*svr->news));
break;
case SVR_COPY_STAMP:
AGB_ASSERT_EX(cmd->flag == FALSE, ABSPATH("mevent_server.c"), 491);
svr->stamp = *(u32 *)cmd->parameter;
break;
case SVR_SET_RAM_SCRIPT:
svr->ramScript = cmd->parameter;
svr->ramScriptSize = cmd->flag;
break;
case SVR_SET_CLIENT_SCRIPT:
svr->clientScript = cmd->parameter;
svr->clientScriptSize = cmd->flag;
break;
case SVR_COPY_SAVED_CARD:
AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, ABSPATH("mevent_server.c"), 506);
memcpy(svr->card, GetSavedWonderCard(), sizeof(*svr->card));
DisableWonderCardSending(svr->card);
break;
case SVR_COPY_SAVED_NEWS:
AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, ABSPATH("mevent_server.c"), 512);
memcpy(svr->news, GetSavedWonderNews(), sizeof(*svr->news));
break;
case SVR_COPY_SAVED_RAM_SCRIPT:
AGB_ASSERT_EX(cmd->flag == FALSE && cmd->parameter == NULL, ABSPATH("mevent_server.c"), 517);
svr->ramScript = GetSavedRamScriptIfValid();
break;
case SVR_LOAD_UNK_1:
MysteryGiftServer_InitSend(svr, MG_LINKID_UNK_1, cmd->parameter, cmd->flag);
break;
}
return 1;
return SVR_RET_ACTIVE;
}
static u32 (*const func_tbl[])(struct mevent_srv_common *) = {
common_mainseq_0,
common_mainseq_1,
common_mainseq_2,
common_mainseq_3,
common_mainseq_4
static u32 (*const sFuncTable[])(struct MysteryGiftServer *) = {
[FUNC_INIT] = Server_Init,
[FUNC_DONE] = Server_Done,
[FUNC_RECV] = Server_Recv,
[FUNC_SEND] = Server_Send,
[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;
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);
return response;
#undef mainseqno
#undef func_tbl
}
+13 -12
View File
@@ -1,6 +1,7 @@
#include "global.h"
#include "link_rfu.h"
#include "mystery_gift_server.h"
#include "mystery_gift_client.h"
#include "constants/union_room.h"
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) static const u8 sText_CanceledReadingCard[] = _("Canceled reading the Card.");
static const struct mevent_client_cmd sClientScript_DynamicError[] = {
CLI_RECEIVE(0x15),
CLI_RECVBUF,
CLI_SENDALL,
CLI_RETURN(0x0e)
static const struct MysteryGiftClientCmd sClientScript_DynamicError[] = {
{CLI_RECV, MG_LINKID_DYNAMIC_MSG},
{CLI_COPY_MSG},
{CLI_SEND_READY_END},
{CLI_RETURN, CLI_MSG_BUFFER_FAILURE}
};
const struct mevent_server_cmd gServerScript_ClientCanceledCard[] = {
SRV_SEND(0x20, sClientScript_DynamicError),
SRV_WAITSND,
SRV_SENDSTR(0x1b, sText_CanceledReadingCard),
SRV_WAITSND,
SRV_RECV(0x14),
SRV_RETURN(0x09)
const struct MysteryGiftServerCmd gServerScript_ClientCanceledCard[] = {
{SVR_LOAD_CLIENT_SCRIPT, PTR_ARG(sClientScript_DynamicError)},
{SVR_SEND},
{SVR_LOAD_MSG, PTR_ARG(sText_CanceledReadingCard)},
{SVR_SEND},
{SVR_RECV, MG_LINKID_READY_END},
{SVR_RETURN, SVR_MSG_CLIENT_CANCELED}
};