2020-02-16 19:49:36 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "malloc.h"
|
|
|
|
#include "battle.h"
|
|
|
|
#include "berry_blender.h"
|
|
|
|
#include "decompress.h"
|
|
|
|
#include "event_data.h"
|
|
|
|
#include "gpu_regs.h"
|
|
|
|
#include "librfu.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "link_rfu.h"
|
|
|
|
#include "overworld.h"
|
|
|
|
#include "random.h"
|
|
|
|
#include "palette.h"
|
|
|
|
#include "union_room.h"
|
|
|
|
#include "string_util.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "constants/species.h"
|
|
|
|
#include "save.h"
|
|
|
|
#include "mystery_gift.h"
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
struct SioInfo
|
|
|
|
{
|
|
|
|
char magic[15]; // PokemonSioInfo
|
|
|
|
u8 playerCount;
|
|
|
|
u8 linkPlayerIdx[RFU_CHILD_MAX];
|
|
|
|
struct LinkPlayer linkPlayers[MAX_RFU_PLAYERS];
|
|
|
|
u8 filler[92];
|
|
|
|
};
|
2020-02-16 19:49:36 +01:00
|
|
|
|
2020-06-08 06:45:06 +02:00
|
|
|
struct RfuDebug
|
|
|
|
{
|
|
|
|
u8 filler0[6];
|
|
|
|
u16 unk_06;
|
|
|
|
u8 filler1[6];
|
|
|
|
vu8 unk_0e;
|
|
|
|
u8 unk_0f;
|
|
|
|
u8 filler2[84];
|
|
|
|
u16 unk_64;
|
|
|
|
u8 filler3[29];
|
|
|
|
u8 unk_83;
|
|
|
|
u8 filler4[88];
|
|
|
|
};
|
|
|
|
|
2020-02-16 19:49:36 +01:00
|
|
|
u32 gf_rfu_REQ_api[RFU_API_BUFF_SIZE_RAM / 4];
|
2020-06-06 22:46:19 +02:00
|
|
|
struct GFRfuManager Rfu;
|
2020-02-16 19:49:36 +01:00
|
|
|
|
2020-06-08 06:45:06 +02:00
|
|
|
static u8 sHeldKeyCount;
|
|
|
|
static u8 sResendBlock8[16];
|
|
|
|
static u16 sResendBlock16[8];
|
2020-02-16 19:49:36 +01:00
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
EWRAM_DATA struct GFtgtGname gHostRFUtgtGnameBuffer = {};
|
2020-06-08 06:45:06 +02:00
|
|
|
EWRAM_DATA u8 gHostRFUtgtUnameBuffer[PLAYER_NAME_LENGTH + 1] = {};
|
|
|
|
static EWRAM_DATA INIT_PARAM sRfuReqConfig = {};
|
|
|
|
static EWRAM_DATA struct RfuDebug sRfuDebug = {};
|
2020-02-16 19:49:36 +01:00
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void ResetSendDataManager(struct RfuBlockSend *);
|
|
|
|
static void sub_800EAB4(void);
|
|
|
|
static void sub_800EAFC(void);
|
2020-06-07 23:37:09 +02:00
|
|
|
static void sub_800ED34(u16);
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_800EDBC(u16);
|
2020-06-07 23:37:09 +02:00
|
|
|
static void UpdateBackupQueue(void);
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Task_ExchangeLinkPlayers(u8);
|
|
|
|
static void RfuHandleReceiveCommand(u8);
|
|
|
|
static void CallRfuFunc(void);
|
|
|
|
static void RfuPrepareSendBuffer(u16);
|
|
|
|
static void HandleBlockSend(void);
|
|
|
|
static void SendNextBlock(void);
|
|
|
|
static void SendLastBlock(void);
|
|
|
|
static u8 GetPartnerIndexByNameAndTrainerID(const u8 *, u16);
|
2020-06-09 00:16:57 +02:00
|
|
|
static void UpdateChildStatuses(void);
|
2020-06-06 22:46:19 +02:00
|
|
|
static s32 sub_80107A0(void);
|
|
|
|
static void sub_801084C(u8);
|
2020-06-07 23:37:09 +02:00
|
|
|
static void ClearSelectedLinkPlayerIds(u16);
|
2020-06-06 22:46:19 +02:00
|
|
|
static void ValidateAndReceivePokemonSioInfo(void *);
|
|
|
|
static void sub_8010D0C(u8);
|
|
|
|
static void sub_80115EC(s32);
|
|
|
|
static void sub_8011BF8(void);
|
|
|
|
static void RfuReqDisconnectSlot(u32);
|
|
|
|
static void sub_8011E94(u32, u32);
|
|
|
|
static void sub_801209C(u8);
|
|
|
|
static void Debug_PrintEmpty(void);
|
|
|
|
static void Task_Idle(u8);
|
|
|
|
|
|
|
|
static const INIT_PARAM sRfuReqConfigTemplate = {
|
|
|
|
.maxMFrame = 4,
|
|
|
|
.MC_TimerCount = 32,
|
|
|
|
.availSlot_flag = 0,
|
|
|
|
.mboot_flag = 0,
|
|
|
|
.serialNo = 2,
|
|
|
|
.gameName = (void *)&gHostRFUtgtGnameBuffer,
|
|
|
|
.userName = gHostRFUtgtUnameBuffer,
|
|
|
|
.fastSearchParent_flag = TRUE,
|
|
|
|
.linkRecovery_enable = FALSE,
|
|
|
|
.linkRecovery_period = 600,
|
|
|
|
.NI_failCounter_limit = 0x12c
|
2020-02-16 19:49:36 +01:00
|
|
|
};
|
2020-06-06 22:46:19 +02:00
|
|
|
|
|
|
|
static const u8 sAvailSlots[] = {
|
|
|
|
[1] = AVAIL_SLOT1,
|
|
|
|
[2] = AVAIL_SLOT2,
|
|
|
|
[3] = AVAIL_SLOT3,
|
|
|
|
[4] = AVAIL_SLOT4
|
2020-02-16 19:49:36 +01:00
|
|
|
};
|
2020-06-06 22:46:19 +02:00
|
|
|
|
|
|
|
static const u32 sAllBlocksReceived[] = {
|
2020-02-16 19:49:36 +01:00
|
|
|
0x000000,
|
|
|
|
0x000001,
|
|
|
|
0x000003,
|
|
|
|
0x000007,
|
|
|
|
0x00000f,
|
|
|
|
0x00001f,
|
|
|
|
0x00003f,
|
|
|
|
0x00007f,
|
|
|
|
0x0000ff,
|
|
|
|
0x0001ff,
|
|
|
|
0x0003ff,
|
|
|
|
0x0007ff,
|
|
|
|
0x000fff,
|
|
|
|
0x001fff,
|
|
|
|
0x003fff,
|
|
|
|
0x007fff,
|
|
|
|
0x00ffff,
|
|
|
|
0x01ffff,
|
|
|
|
0x03ffff,
|
|
|
|
0x07ffff,
|
|
|
|
0x0fffff,
|
|
|
|
0x1fffff,
|
|
|
|
0x3fffff,
|
|
|
|
0x7fffff,
|
|
|
|
0xffffff
|
|
|
|
};
|
2020-06-06 22:46:19 +02:00
|
|
|
|
|
|
|
static const u8 sUnknown_082ED68C[] = {
|
2020-02-16 19:49:36 +01:00
|
|
|
0, 0, 1,
|
|
|
|
1, 2, 2,
|
|
|
|
2, 2, 3
|
|
|
|
};
|
2020-06-06 22:46:19 +02:00
|
|
|
|
|
|
|
static const u8 sUnknown_082ED695[] = {
|
2020-02-16 19:49:36 +01:00
|
|
|
0, 1, 1, 2,
|
|
|
|
1, 2, 2, 3,
|
|
|
|
1, 2, 2, 3,
|
|
|
|
2, 3, 3, 4
|
|
|
|
};
|
2020-06-06 22:46:19 +02:00
|
|
|
|
|
|
|
static const u8 sUnknown_082ED6A5[] = {
|
2020-02-16 19:49:36 +01:00
|
|
|
0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
|
|
|
|
};
|
2020-06-06 22:46:19 +02:00
|
|
|
|
|
|
|
static const struct {
|
2020-02-16 19:49:36 +01:00
|
|
|
u8 *buffer;
|
|
|
|
u32 size;
|
2020-06-06 22:46:19 +02:00
|
|
|
} sUnknown_082ED6B8[] = {
|
2020-02-16 19:49:36 +01:00
|
|
|
{ gBlockSendBuffer, 200 },
|
|
|
|
{ gBlockSendBuffer, 200 },
|
|
|
|
{ gBlockSendBuffer, 100 },
|
|
|
|
{ gBlockSendBuffer, 220 },
|
|
|
|
{ gBlockSendBuffer, 40 }
|
|
|
|
};
|
2020-06-06 22:46:19 +02:00
|
|
|
|
|
|
|
static const u16 sAcceptedSerialNos[] = {
|
2020-06-08 06:45:06 +02:00
|
|
|
0x0002,
|
|
|
|
RFU_SERIAL_7F7D,
|
2020-06-06 22:46:19 +02:00
|
|
|
0x0000,
|
|
|
|
0xFFFF
|
2020-02-16 19:49:36 +01:00
|
|
|
};
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static const char sASCII_RfuCmds[][15] = {
|
2020-02-16 19:49:36 +01:00
|
|
|
"RFU WAIT",
|
|
|
|
"RFU BOOT",
|
|
|
|
"RFU ERROR",
|
|
|
|
"RFU RESET",
|
|
|
|
"RFU CONFIG",
|
|
|
|
"RFU START",
|
|
|
|
"RFU SC POLL",
|
|
|
|
"RFU SP POLL",
|
|
|
|
"RFU START",
|
|
|
|
"RFU SEND ERR",
|
|
|
|
"RFU CP POLL"
|
|
|
|
};
|
2020-06-06 22:46:19 +02:00
|
|
|
|
|
|
|
static const char sASCII_RecoverCmds[][16] = {
|
2020-02-16 19:49:36 +01:00
|
|
|
" ",
|
|
|
|
"RECOVER START ",
|
|
|
|
"DISSCONECT ",
|
|
|
|
"RECOVER SUUSES",
|
|
|
|
"RECOVER FAILED"
|
|
|
|
};
|
2020-06-06 22:46:19 +02:00
|
|
|
|
|
|
|
static const TaskFunc sUnknown_082ED7E0[] = {
|
2020-02-16 19:49:36 +01:00
|
|
|
sub_801084C,
|
2020-06-06 22:46:19 +02:00
|
|
|
Task_ExchangeLinkPlayers,
|
2020-02-16 19:49:36 +01:00
|
|
|
sub_8010D0C
|
|
|
|
};
|
2020-06-06 22:46:19 +02:00
|
|
|
|
|
|
|
static const char sASCII_PokemonSioInfo[] = "PokemonSioInfo";
|
|
|
|
static const char sASCII_LinkLossDisconnect[] = "LINK LOSS DISCONNECT!";
|
|
|
|
static const char sASCII_LinkLossRecoveryNow[] = "LINK LOSS RECOVERY NOW";
|
|
|
|
ALIGNED(4) static const char sASCII_30Commas[31] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'};
|
|
|
|
static const char sASCII_15Commas[16] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'};
|
|
|
|
static const char sASCII_8Commas[9] = {' ',' ',' ',' ',' ',' ',' ',' ','\0'};
|
|
|
|
ALIGNED(4) static const char sASCII_Space[2] = {' ','\0'};
|
|
|
|
static const char sASCII_Asterisk[2] = {'*','\0'};
|
|
|
|
static const char sASCII_NowSlot[8] = "NOWSLOT";
|
|
|
|
|
|
|
|
static const char sASCII_ClockCmds[][12] = {
|
|
|
|
" ",
|
|
|
|
"CLOCK DRIFT",
|
|
|
|
"BUSY SEND ",
|
|
|
|
"CMD REJECT ",
|
|
|
|
"CLOCK SLAVE"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char sASCII_ChildParentSearch[3][8] = {
|
2020-02-16 19:49:36 +01:00
|
|
|
"CHILD ",
|
|
|
|
"PARENT",
|
|
|
|
"SEARCH"
|
|
|
|
};
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Debug_PrintString(const void *str, u8 x, u8 y)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Debug_PrintNum(u16 num, u8 x, u8 y, u8 numDigits)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void ResetLinkRfuGFLayer(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 errorState = Rfu.errorState;
|
2020-02-16 19:49:36 +01:00
|
|
|
CpuFill16(0, &Rfu, sizeof Rfu);
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.errorState = errorState;
|
|
|
|
Rfu.parentChild = 0xFF;
|
|
|
|
if (Rfu.errorState != 4)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.errorState = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-08 06:45:06 +02:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
ResetSendDataManager(&Rfu.recvBlock[i]);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-08 06:45:06 +02:00
|
|
|
ResetSendDataManager(&Rfu.sendBlock);
|
2020-06-07 23:37:09 +02:00
|
|
|
RfuRecvQueue_Reset(&Rfu.recvQueue);
|
|
|
|
RfuSendQueue_Reset(&Rfu.sendQueue);
|
2020-02-16 19:49:36 +01:00
|
|
|
CpuFill16(0, gSendCmd, sizeof gSendCmd);
|
|
|
|
CpuFill16(0, gRecvCmds, sizeof gRecvCmds);
|
|
|
|
CpuFill16(0, gLinkPlayers, sizeof gLinkPlayers);
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void InitRFU(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
IntrFunc serialIntr = gIntrTable[1];
|
|
|
|
IntrFunc timerIntr = gIntrTable[2];
|
2020-06-08 06:45:06 +02:00
|
|
|
InitRFUAPI();
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_REQ_stopMode();
|
|
|
|
rfu_waitREQComplete();
|
|
|
|
REG_IME = 0;
|
|
|
|
gIntrTable[1] = serialIntr;
|
|
|
|
gIntrTable[2] = timerIntr;
|
|
|
|
REG_IME = INTR_FLAG_VBLANK;
|
|
|
|
}
|
|
|
|
|
2020-06-08 06:45:06 +02:00
|
|
|
void InitRFUAPI(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (!rfu_initializeAPI((void *)gf_rfu_REQ_api, sizeof gf_rfu_REQ_api, gIntrTable + 1, TRUE))
|
|
|
|
{
|
|
|
|
gLinkType = 0;
|
2020-06-08 06:45:06 +02:00
|
|
|
ClearSavedLinkPlayers();
|
2020-06-06 22:46:19 +02:00
|
|
|
sub_80111B0(FALSE);
|
|
|
|
ResetLinkRfuGFLayer();
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_setTimerInterrupt(3, gIntrTable + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Task_LinkLeaderSearchForChildren(u8 taskId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateChildStatuses();
|
2020-06-06 22:46:19 +02:00
|
|
|
switch (Rfu.state)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case 0:
|
|
|
|
rfu_LMAN_initializeRFU(&sRfuReqConfig);
|
|
|
|
Rfu.state = 1;
|
|
|
|
gTasks[taskId].data[1] = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rfu_LMAN_establishConnection(Rfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos);
|
|
|
|
Rfu.state = 3;
|
|
|
|
gTasks[taskId].data[1] = 6;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
rfu_LMAN_stopManager(FALSE);
|
|
|
|
Rfu.state = 5;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
break;
|
|
|
|
case 18:
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_cdb = FALSE;
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_LMAN_setMSCCallback(sub_800EDBC);
|
|
|
|
sub_800EAB4();
|
|
|
|
sub_800EAFC();
|
|
|
|
Rfu.state = 20;
|
|
|
|
gTasks[taskId].data[1] = 8;
|
|
|
|
CreateTask(sub_801084C, 5);
|
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 sub_800E87C(u8 idx)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
return sUnknown_082ED6A5[idx];
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800E88C(s32 r2, s32 r5)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 r4 = 1;
|
|
|
|
s32 r1 = r2;
|
|
|
|
s32 r6 = 0;
|
|
|
|
if (r5 == -1)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; r2 >>= 1, i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (r2 & 1)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.linkPlayerIdx[i] = r4;
|
2020-02-16 19:49:36 +01:00
|
|
|
r4++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; r1 >>= 1, i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (!(r1 & 1))
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.linkPlayerIdx[i] = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
for (r4 = RFU_CHILD_MAX; r4 != 0; r4--)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX && Rfu.linkPlayerIdx[i] != r4; i++);
|
|
|
|
if (i == RFU_CHILD_MAX)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
r6 = r4;
|
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
for (r5 &= ~r2, i = 0; i < RFU_CHILD_MAX; r5 >>= 1, i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (r5 & 1)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.linkPlayerIdx[i] = r6++;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Task_JoinGroupSearchForParent(u8 taskId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
switch (Rfu.state)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case 0:
|
|
|
|
rfu_LMAN_initializeRFU((INIT_PARAM *)&sRfuReqConfigTemplate);
|
|
|
|
Rfu.state = 1;
|
|
|
|
gTasks[taskId].data[1] = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
rfu_LMAN_establishConnection(Rfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos);
|
|
|
|
Rfu.state = 7;
|
|
|
|
gTasks[taskId].data[1] = 7;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
gTasks[taskId].data[1] = 10;
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
switch (sub_80107A0())
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_JOIN_GROUP_OK:
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.state = 12;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-09 00:16:57 +02:00
|
|
|
case RFU_STATUS_JOIN_GROUP_NO:
|
|
|
|
case RFU_STATUS_LEAVE_GROUP:
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_LMAN_requestChangeAgbClockMaster();
|
|
|
|
Rfu.unk_ce4 = 2;
|
2020-02-16 19:49:36 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
u8 bmChildSlot = 1 << Rfu.childSlot;
|
|
|
|
rfu_clearSlot(TYPE_NI_SEND | TYPE_NI_RECV, Rfu.childSlot);
|
|
|
|
rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, 70);
|
|
|
|
rfu_UNI_setSendData(bmChildSlot, Rfu.unk_4c, sizeof(Rfu.unk_4c));
|
|
|
|
gTasks[taskId].data[1] = 8;
|
|
|
|
DestroyTask(taskId);
|
2020-06-08 06:45:06 +02:00
|
|
|
if (sRfuDebug.unk_0f == 0)
|
2020-06-06 22:46:19 +02:00
|
|
|
{
|
|
|
|
Debug_PrintEmpty();
|
2020-06-08 06:45:06 +02:00
|
|
|
sRfuDebug.unk_0f++;
|
2020-06-06 22:46:19 +02:00
|
|
|
}
|
|
|
|
CreateTask(sub_801084C, 5);
|
|
|
|
break;
|
|
|
|
}
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_800EAB4(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 acceptSlot = lman.acceptSlot_flag;
|
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (acceptSlot & 1)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_setRecvBuffer(TYPE_UNI, i, Rfu.unk_14[i], 14);
|
|
|
|
rfu_clearSlot(TYPE_UNI_SEND | TYPE_UNI_RECV, i);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
acceptSlot >>= 1;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_800EAFC(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 acceptSlot = lman.acceptSlot_flag;
|
|
|
|
rfu_UNI_setSendData(acceptSlot, Rfu.recvCmds, 70);
|
|
|
|
Rfu.unk_cda = sub_800E87C(acceptSlot);
|
|
|
|
Rfu.unk_ce2 = acceptSlot;
|
|
|
|
sub_800E88C(acceptSlot, -1);
|
|
|
|
Rfu.parentChild = MODE_PARENT;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Task_LinkRfu_UnionRoomListen(u8 taskId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (GetHostRFUtgtGname()->activity == (ACTIVITY_PLYRTALK | IN_UNION_ROOM) && RfuGetStatus() == RFU_STATUS_NEW_CHILD_DETECTED)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
rfu_REQ_disconnect(lman.acceptSlot_flag);
|
|
|
|
rfu_waitREQComplete();
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_OK, 0);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
switch (Rfu.state)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case 0:
|
|
|
|
rfu_LMAN_initializeRFU(&sRfuReqConfig);
|
|
|
|
Rfu.state = 1;
|
|
|
|
gTasks[taskId].data[1] = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
case 17:
|
|
|
|
rfu_LMAN_establishConnection(2, 0, 240, (u16 *)sAcceptedSerialNos);
|
|
|
|
rfu_LMAN_setMSCCallback(sub_800ED34);
|
|
|
|
Rfu.state = 18;
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
if (rfu_UNI_setSendData(1 << Rfu.childSlot, Rfu.unk_4c, sizeof(Rfu.unk_4c)) == 0)
|
|
|
|
{
|
|
|
|
Rfu.parentChild = MODE_CHILD;
|
|
|
|
DestroyTask(taskId);
|
|
|
|
if (gTasks[taskId].data[7])
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
CreateTask(sub_8010D0C, 1);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CreateTask(sub_801084C, 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
rfu_LMAN_stopManager(0);
|
|
|
|
Rfu.state = 15;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
break;
|
|
|
|
case 16:
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_cdb = FALSE;
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_LMAN_setMSCCallback(sub_800EDBC);
|
|
|
|
UpdateGameData_GroupLockedIn(TRUE);
|
|
|
|
sub_800EAB4();
|
|
|
|
sub_800EAFC();
|
|
|
|
Rfu.state = 20;
|
|
|
|
gTasks[taskId].data[1] = 8;
|
|
|
|
Rfu.parentChild = MODE_PARENT;
|
|
|
|
CreateTask(sub_801084C, 5);
|
|
|
|
Rfu.unk_ce8 = TRUE;
|
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void LinkRfu_CreateConnectionAsParent(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_LMAN_establishConnection(MODE_PARENT, 0, 240, (u16 *)sAcceptedSerialNos);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void LinkRfu_StopManagerBeforeEnteringChat(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
rfu_LMAN_stopManager(FALSE);
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:37:09 +02:00
|
|
|
static void sub_800ED34(u16 unused)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < (int)ARRAY_COUNT(Rfu.unk_4c); i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
Rfu.unk_4c[i] = 0;
|
|
|
|
}
|
|
|
|
rfu_REQ_recvData();
|
|
|
|
rfu_waitREQComplete();
|
2020-06-06 22:46:19 +02:00
|
|
|
if (gRfuSlotStatusUNI[Rfu.childSlot]->recv.newDataFlag)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
Rfu.unk_cd0++;
|
2020-06-07 23:37:09 +02:00
|
|
|
RfuRecvQueue_Enqueue(&Rfu.recvQueue, Rfu.unk_c3f);
|
2020-06-08 06:45:06 +02:00
|
|
|
sRfuDebug.unk_06++;
|
2020-06-07 23:37:09 +02:00
|
|
|
UpdateBackupQueue();
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_UNI_readySendData(Rfu.childSlot);
|
|
|
|
rfu_UNI_clearRecvNewDataFlag(Rfu.childSlot);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_LMAN_REQ_sendData(TRUE);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_800EDBC(u16 unused)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_cdb = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void LinkRfu_Shutdown(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
rfu_LMAN_powerDownRFU();
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.parentChild == MODE_PARENT)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (FuncIsActiveTask(Task_LinkLeaderSearchForChildren) == TRUE)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
DestroyTask(Rfu.searchTaskId);
|
|
|
|
ResetLinkRfuGFLayer();
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
else if (Rfu.parentChild == MODE_CHILD)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (FuncIsActiveTask(Task_JoinGroupSearchForParent) == TRUE)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
DestroyTask(Rfu.searchTaskId);
|
|
|
|
ResetLinkRfuGFLayer();
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
else if (Rfu.parentChild == 2)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
DestroyTask(Rfu.searchTaskId);
|
|
|
|
ResetLinkRfuGFLayer();
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < ARRAY_COUNT(sUnknown_082ED7E0); i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (FuncIsActiveTask(sUnknown_082ED7E0[i]) == TRUE)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
DestroyTask(FindTaskIdByFunc(sUnknown_082ED7E0[i]));
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void CreateTask_LinkLeaderSearchForChildren(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.searchTaskId = CreateTask(Task_LinkLeaderSearchForChildren, 1);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static bool8 sub_800EE94(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.state == 7 && Rfu.parentId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static bool32 IsParentSuccessfullyReconnected(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.state == 7 && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[Rfu.unk_c3d].id, 240))
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.state = 9;
|
2020-02-16 19:49:36 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void CreateTask_JoinGroupSearchForParent(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.searchTaskId = CreateTask(Task_JoinGroupSearchForParent, 1);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
bool8 LmanAcceptSlotFlagIsNotZero(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (lman.acceptSlot_flag)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void LinkRfu_StopManagerAndFinalizeSlots(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.state = 4;
|
|
|
|
Rfu.acceptSlot_flag = lman.acceptSlot_flag;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
bool32 WaitRfuState(bool32 force)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.state == 17 || force)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.state = 18;
|
2020-02-16 19:49:36 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800EF7C(void)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.state = 14;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_800EF88(u8 a0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (a0 & 1)
|
|
|
|
{
|
|
|
|
rfu_UNI_readySendData(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
a0 >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_800EFB0(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
struct GFRfuManager *ptr = &Rfu;
|
2020-02-16 19:49:36 +01:00
|
|
|
for (j = 0; j < 7; j++)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
ptr->recvCmds[i][j][1] = gRecvCmds[i][j] >> 8;
|
|
|
|
ptr->recvCmds[i][j][0] = gRecvCmds[i][j];
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CpuFill16(0, gRecvCmds, sizeof gRecvCmds);
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_800F014(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
2020-06-08 06:45:06 +02:00
|
|
|
for (i = 0; i < CMD_LENGTH - 1; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
gRecvCmds[0][i] = gSendCmd[i];
|
|
|
|
}
|
2020-06-08 06:45:06 +02:00
|
|
|
for (i = 0; i < CMD_LENGTH - 1; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
gSendCmd[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:37:09 +02:00
|
|
|
static void UpdateBackupQueue(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-07 23:37:09 +02:00
|
|
|
if (Rfu.linkRecovered)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-07 23:37:09 +02:00
|
|
|
bool8 backupEmpty = RfuBackupQueue_Dequeue(&Rfu.backupQueue, Rfu.unk_4c);
|
|
|
|
|
|
|
|
if (Rfu.backupQueue.count == 0)
|
|
|
|
Rfu.linkRecovered = FALSE;
|
|
|
|
|
|
|
|
if (backupEmpty)
|
2020-02-16 19:49:36 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-06-07 23:37:09 +02:00
|
|
|
if (!Rfu.linkRecovered)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-07 23:37:09 +02:00
|
|
|
RfuSendQueue_Dequeue(&Rfu.sendQueue, Rfu.unk_4c);
|
|
|
|
RfuBackupQueue_Enqueue(&Rfu.backupQueue, Rfu.unk_4c);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 IsRfuRecvQueueEmpty(void)
|
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
s32 j;
|
|
|
|
|
|
|
|
if (gRfuLinkStatus->sendSlotUNIFlag == 0)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-06-08 06:45:06 +02:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
for (j = 0; j < CMD_LENGTH - 1; j++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (gRecvCmds[i][j] != 0)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static bool32 sub_800F0F8(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.state < 20)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
rfu_REQ_recvData();
|
|
|
|
rfu_waitREQComplete();
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_LMAN_REQ_sendData(FALSE);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_cdb = FALSE;
|
2020-02-16 19:49:36 +01:00
|
|
|
if ((Rfu.unk_ce2 & gRfuLinkStatus->connSlotFlag) == Rfu.unk_ce2 && (Rfu.unk_ce2 & gRfuLinkStatus->connSlotFlag))
|
|
|
|
{
|
|
|
|
if (!Rfu.unk_cdc)
|
|
|
|
{
|
|
|
|
if (Rfu.unk_ce3)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuReqDisconnectSlot(Rfu.unk_ce3);
|
2020-02-16 19:49:36 +01:00
|
|
|
Rfu.unk_ce3 = 0;
|
|
|
|
if (Rfu.unk_ce4 == 1)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x8000);
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(0x8000);
|
2020-02-16 19:49:36 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!lman.acceptSlot_flag)
|
|
|
|
{
|
2020-05-30 10:09:21 +02:00
|
|
|
LinkRfu_Shutdown();
|
2020-02-16 19:49:36 +01:00
|
|
|
gReceivedRemoteLinkPlayers = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sub_800EFB0();
|
|
|
|
rfu_UNI_readySendData(Rfu.unk_cda);
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_LMAN_REQ_sendData(TRUE);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rfu_REQ_PARENT_resumeRetransmitAndChange();
|
|
|
|
}
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_0e = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static bool32 sub_800F1E0(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
u16 flags;
|
|
|
|
u8 r0;
|
|
|
|
u16 j;
|
|
|
|
u8 retval;
|
|
|
|
|
2020-06-08 06:45:06 +02:00
|
|
|
if (Rfu.state >= 20 && Rfu.unk_0e == TRUE)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
rfu_waitREQComplete();
|
2020-06-08 06:45:06 +02:00
|
|
|
while (Rfu.unk_cdb == FALSE)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.errorState != 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rfu_REQ_recvData();
|
|
|
|
rfu_waitREQComplete();
|
|
|
|
if ((lman.parentAck_flag & Rfu.unk_ce2) == Rfu.unk_ce2)
|
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_cdc = FALSE;
|
|
|
|
sRfuDebug.unk_06++;
|
2020-02-16 19:49:36 +01:00
|
|
|
flags = lman.acceptSlot_flag;
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (flags & 1)
|
|
|
|
{
|
|
|
|
if (Rfu.unk_14[i][1])
|
|
|
|
{
|
|
|
|
if (Rfu.unk_cee[i] != 0xFF && (Rfu.unk_14[i][0] >> 5) != ((Rfu.unk_cee[i] + 1) & 7))
|
|
|
|
{
|
|
|
|
if (++Rfu.unk_cea[i] > 4)
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(0x8100);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Rfu.unk_cee[i] = Rfu.unk_14[i][0] / 32;
|
|
|
|
Rfu.unk_cea[i] = 0;
|
|
|
|
Rfu.unk_14[i][0] &= 0x1f;
|
2020-06-06 22:46:19 +02:00
|
|
|
r0 = Rfu.linkPlayerIdx[i];
|
2020-02-16 19:49:36 +01:00
|
|
|
for (j = 0; j < 7; j++)
|
|
|
|
{
|
|
|
|
gRecvCmds[r0][j] = (Rfu.unk_14[i][(j << 1) + 1] << 8) | Rfu.unk_14[i][(j << 1) + 0];
|
|
|
|
Rfu.unk_14[i][(j << 1) + 1] = 0;
|
|
|
|
Rfu.unk_14[i][(j << 1) + 0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rfu_UNI_clearRecvNewDataFlag(i);
|
|
|
|
}
|
|
|
|
flags >>= 1;
|
|
|
|
}
|
|
|
|
sub_800F014();
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuHandleReceiveCommand(0);
|
|
|
|
CallRfuFunc();
|
2020-02-16 19:49:36 +01:00
|
|
|
if (Rfu.unk_ce5 && !Rfu.unk_cd9)
|
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
sRfuDebug.unk_0e = FALSE;
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_clearSlot(TYPE_UNI_SEND | TYPE_UNI_RECV, Rfu.unk_cda);
|
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if ((Rfu.unk_ce5 >> i) & 1)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_setRecvBuffer(TYPE_UNI, i, Rfu.unk_14[i], 14);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sub_800E88C(Rfu.unk_ce2, Rfu.unk_ce2 | Rfu.unk_ce5);
|
|
|
|
Rfu.unk_ce9 = Rfu.unk_ce5;
|
|
|
|
Rfu.unk_ce2 |= Rfu.unk_ce5;
|
|
|
|
Rfu.unk_ce5 = 0;
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_UNI_setSendData(Rfu.unk_ce2, Rfu.recvCmds, 70);
|
2020-02-16 19:49:36 +01:00
|
|
|
Rfu.unk_cda = sub_800E87C(Rfu.unk_ce2);
|
2020-06-06 22:46:19 +02:00
|
|
|
CreateTask(Task_ExchangeLinkPlayers, 0);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_cdc = TRUE;
|
|
|
|
Rfu.unk_0e = FALSE;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_0e = FALSE;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
retval = Rfu.unk_cdc;
|
|
|
|
return gRfuLinkStatus->sendSlotUNIFlag ? retval & 1 : FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_800F498(u16 *a0, u8 *a1)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
if (a0[0])
|
|
|
|
{
|
|
|
|
a0[0] |= (Rfu.unk_102 << 5);
|
|
|
|
Rfu.unk_102 = (Rfu.unk_102 + 1) & 7;
|
|
|
|
for (i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
a1[2 * i + 1] = a0[i] >> 8;
|
|
|
|
a1[2 * i + 0] = a0[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < 14; i++)
|
|
|
|
a1[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static bool32 RfuProcessEnqueuedRecvBlock(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 j;
|
|
|
|
u8 sp00[MAX_RFU_PLAYERS * (2 * (CMD_LENGTH - 1))];
|
|
|
|
u8 sp48[2 * (CMD_LENGTH - 1)];
|
2020-06-09 00:16:57 +02:00
|
|
|
u8 status;
|
2020-02-16 19:49:36 +01:00
|
|
|
|
2020-06-07 23:37:09 +02:00
|
|
|
RfuRecvQueue_Dequeue(&Rfu.recvQueue, sp00);
|
2020-02-16 19:49:36 +01:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < CMD_LENGTH - 1; j++)
|
|
|
|
{
|
|
|
|
gRecvCmds[i][j] = (sp00[i * 14 + (j << 1) + 1] << 8) | sp00[i * 14 + (j << 1) + 0];
|
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuHandleReceiveCommand(0);
|
2020-02-16 19:49:36 +01:00
|
|
|
if (lman.childClockSlave_flag == 0 && Rfu.unk_ce4)
|
|
|
|
{
|
|
|
|
rfu_REQ_disconnect(gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag);
|
|
|
|
rfu_waitREQComplete();
|
2020-06-09 00:16:57 +02:00
|
|
|
status = RfuGetStatus();
|
|
|
|
if (status != RFU_STATUS_FATAL_ERROR && status != RFU_STATUS_JOIN_GROUP_NO && status != RFU_STATUS_LEAVE_GROUP)
|
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x9000);
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_clearAllSlot();
|
|
|
|
gReceivedRemoteLinkPlayers = FALSE;
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = NULL;
|
2020-02-16 19:49:36 +01:00
|
|
|
if (Rfu.unk_ce4 == 1)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x9000);
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(0x9000);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
lman.state = lman.next_state = 0;
|
|
|
|
Rfu.unk_ce4 = 0;
|
|
|
|
}
|
|
|
|
if (Rfu.unk_cd0)
|
|
|
|
{
|
|
|
|
Rfu.unk_cd0--;
|
2020-06-06 22:46:19 +02:00
|
|
|
CallRfuFunc();
|
2020-02-16 19:49:36 +01:00
|
|
|
sub_800F498(gSendCmd, sp48);
|
2020-06-07 23:37:09 +02:00
|
|
|
RfuSendQueue_Enqueue(&Rfu.sendQueue, sp48);
|
2020-02-16 19:49:36 +01:00
|
|
|
for (i = 0; i < CMD_LENGTH - 1; i++)
|
|
|
|
gSendCmd[i] = 0;
|
|
|
|
}
|
|
|
|
return IsRfuRecvQueueEmpty();
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void HandleSendFailure(u8 unused, u32 flags)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i, j;
|
|
|
|
|
2020-06-08 06:45:06 +02:00
|
|
|
const u8 *r10 = Rfu.sendBlock.payload;
|
|
|
|
for (i = 0; i < Rfu.sendBlock.count; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (!(flags & 1))
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
sResendBlock16[0] = RFU_COMMAND_0x8900 | i;
|
2020-02-16 19:49:36 +01:00
|
|
|
for (j = 0; j < 7; j++)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
sResendBlock16[j + 1] = (r10[12 * i + (j << 1) + 1] << 8) | r10[12 * i + (j << 1) + 0];
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
for (j = 0; j < 7; j++)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
sResendBlock8[2 * j + 1] = sResendBlock16[j] >> 8;
|
|
|
|
sResendBlock8[2 * j + 0] = sResendBlock16[j];
|
2020-02-16 19:49:36 +01:00
|
|
|
|
|
|
|
j++;j--; // Needed to match;
|
|
|
|
}
|
2020-06-07 23:37:09 +02:00
|
|
|
RfuSendQueue_Enqueue(&Rfu.sendQueue, sResendBlock8);
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.sendBlock.failedFlags |= (1 << i);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
flags >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void Rfu_SetBlockReceivedFlag(u8 linkPlayerId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.parentChild == MODE_PARENT && linkPlayerId)
|
2020-06-07 23:37:09 +02:00
|
|
|
Rfu.numBlocksReceived[linkPlayerId] = 1;
|
2020-02-16 19:49:36 +01:00
|
|
|
else
|
2020-06-07 23:37:09 +02:00
|
|
|
Rfu.blockReceived[linkPlayerId] = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void Rfu_ResetBlockReceivedFlag(u8 linkPlayerId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-07 23:37:09 +02:00
|
|
|
Rfu.blockReceived[linkPlayerId] = FALSE;
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.recvBlock[linkPlayerId].receiving = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static u8 sub_800F74C(const u8 *a0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.parentChild == MODE_PARENT)
|
2020-02-16 19:49:36 +01:00
|
|
|
return FALSE;
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.linkPlayerIdx[i] = a0[i];
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
return a0[Rfu.childSlot];
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void RfuFunc_SendKeysToRfu(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (gReceivedRemoteLinkPlayers
|
|
|
|
&& gHeldKeyCodeToSend != LINK_KEY_CODE_NULL
|
|
|
|
&& gLinkTransferringData != TRUE)
|
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
sHeldKeyCount++;
|
|
|
|
gHeldKeyCodeToSend |= (sHeldKeyCount << 8);
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0xBE00);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
struct GFtgtGname *GetHostRFUtgtGname(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
return &gHostRFUtgtGnameBuffer;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool32 IsSendingKeysToRfu(void)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
return Rfu.callback == RfuFunc_SendKeysToRfu;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void StartSendingKeysToRfu(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = RfuFunc_SendKeysToRfu;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearLinkRfuCallback(void)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = NULL;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800F820(void)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x4400);
|
2020-02-16 19:49:36 +01:00
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
gSendCmd[6] = GetBlenderArrowPosition();
|
|
|
|
gUnknown_020223C0++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800F850(void)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.callback == NULL)
|
|
|
|
Rfu.callback = sub_800F820;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void RfuHandleReceiveCommand(u8 unused)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
u16 j;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
|
|
|
{
|
|
|
|
switch (gRecvCmds[i][0] & 0xff00)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x7800:
|
|
|
|
if (Rfu.parentChild == MODE_CHILD && gReceivedRemoteLinkPlayers)
|
2020-02-16 19:49:36 +01:00
|
|
|
return;
|
|
|
|
// fallthrough
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x7700:
|
|
|
|
if (gRfuLinkStatus->parentChild == MODE_CHILD)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
Rfu.playerCount = gRecvCmds[i][1];
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.multiplayerId = sub_800F74C((u8 *)(gRecvCmds[i] + 2));
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x8800:
|
2020-06-08 06:45:06 +02:00
|
|
|
if (Rfu.recvBlock[i].receiving == 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.recvBlock[i].next = 0;
|
|
|
|
Rfu.recvBlock[i].count = gRecvCmds[i][1];
|
|
|
|
Rfu.recvBlock[i].owner = gRecvCmds[i][2];
|
|
|
|
Rfu.recvBlock[i].receivedFlags = 0;
|
|
|
|
Rfu.recvBlock[i].receiving = 1;
|
2020-06-07 23:37:09 +02:00
|
|
|
Rfu.blockReceived[i] = FALSE;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x8900:
|
2020-06-08 06:45:06 +02:00
|
|
|
if (Rfu.recvBlock[i].receiving == 1)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.recvBlock[i].next = gRecvCmds[i][0] & 0xff;
|
|
|
|
Rfu.recvBlock[i].receivedFlags |= (1 << Rfu.recvBlock[i].next);
|
2020-02-16 19:49:36 +01:00
|
|
|
for (j = 0; j < 6; j++)
|
2020-06-08 06:45:06 +02:00
|
|
|
gBlockRecvBuffer[i][Rfu.recvBlock[i].next * 6 + j] = gRecvCmds[i][j + 1];
|
|
|
|
if (Rfu.recvBlock[i].receivedFlags == sAllBlocksReceived[Rfu.recvBlock[i].count])
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.recvBlock[i].receiving = 2;
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu_SetBlockReceivedFlag(i);
|
2020-06-08 06:45:06 +02:00
|
|
|
if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && gReceivedRemoteLinkPlayers != 0 && Rfu.parentChild == MODE_CHILD)
|
2020-06-06 22:46:19 +02:00
|
|
|
ValidateAndReceivePokemonSioInfo(gBlockRecvBuffer);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0xA100:
|
|
|
|
Rfu_InitBlockSend(sUnknown_082ED6B8[gRecvCmds[i][1]].buffer, (u16)sUnknown_082ED6B8[gRecvCmds[i][1]].size);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x5F00:
|
2020-02-16 19:49:36 +01:00
|
|
|
Rfu.unk_e4[i] = 1;
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x6600:
|
2020-02-16 19:49:36 +01:00
|
|
|
if (Rfu.unk_100 == gRecvCmds[i][1])
|
|
|
|
Rfu.unk_e9[i] = 1;
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0xED00:
|
|
|
|
if (Rfu.parentChild == MODE_CHILD)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (gReceivedRemoteLinkPlayers)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (gRecvCmds[i][1] & gRfuLinkStatus->connSlotFlag)
|
|
|
|
{
|
|
|
|
gReceivedRemoteLinkPlayers = 0;
|
|
|
|
rfu_LMAN_requestChangeAgbClockMaster();
|
|
|
|
Rfu.unk_ce4 = gRecvCmds[i][2];
|
|
|
|
}
|
|
|
|
Rfu.playerCount = gRecvCmds[i][3];
|
2020-06-07 23:37:09 +02:00
|
|
|
ClearSelectedLinkPlayerIds(gRecvCmds[i][1]);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0xEE00);
|
2020-02-16 19:49:36 +01:00
|
|
|
gSendCmd[1] = gRecvCmds[i][1];
|
|
|
|
gSendCmd[2] = gRecvCmds[i][2];
|
|
|
|
gSendCmd[3] = gRecvCmds[i][3];
|
|
|
|
}
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0xEE00:
|
|
|
|
if (Rfu.parentChild == MODE_PARENT)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
Rfu.unk_ce3 |= gRecvCmds[i][1];
|
|
|
|
Rfu.unk_ce4 = gRecvCmds[i][2];
|
2020-06-07 23:37:09 +02:00
|
|
|
ClearSelectedLinkPlayerIds(gRecvCmds[i][1]);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x4400:
|
|
|
|
case RFU_COMMAND_0xBE00:
|
2020-02-16 19:49:36 +01:00
|
|
|
gLinkPartnersHeldKeys[i] = gRecvCmds[i][1];
|
|
|
|
break;
|
|
|
|
}
|
2020-06-07 23:37:09 +02:00
|
|
|
if (Rfu.parentChild == MODE_PARENT && Rfu.numBlocksReceived[i])
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-07 23:37:09 +02:00
|
|
|
if (Rfu.numBlocksReceived[i] == 4)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-07 23:37:09 +02:00
|
|
|
Rfu.blockReceived[i] = TRUE;
|
|
|
|
Rfu.numBlocksReceived[i] = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
else
|
2020-06-07 23:37:09 +02:00
|
|
|
Rfu.numBlocksReceived[i]++;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:37:09 +02:00
|
|
|
static bool8 AreNoPlayersReceiving(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
if (Rfu.recvBlock[i].receiving)
|
2020-02-16 19:49:36 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static bool8 sub_800FC88(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < Rfu.playerCount; i++)
|
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
if (Rfu.recvBlock[i].receiving != 2 || Rfu.blockReceived[i] != TRUE)
|
2020-02-16 19:49:36 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void ResetSendDataManager(struct RfuBlockSend *data)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
data->next = 0;
|
|
|
|
data->count = 0;
|
|
|
|
data->payload = NULL;
|
|
|
|
data->receivedFlags = 0;
|
|
|
|
data->sending = FALSE;
|
|
|
|
data->owner = 0;
|
|
|
|
data->receiving = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 Rfu_GetBlockReceivedStatus(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 flags = 0;
|
|
|
|
s32 i;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
if (Rfu.recvBlock[i].receiving == 2 && Rfu.blockReceived[i] == TRUE)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
flags |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void RfuPrepareSendBuffer(u16 command)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 *buff;
|
|
|
|
u8 tmp;
|
|
|
|
|
|
|
|
gSendCmd[0] = command;
|
|
|
|
switch (command)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x8800:
|
2020-06-08 06:45:06 +02:00
|
|
|
gSendCmd[1] = Rfu.sendBlock.count;
|
|
|
|
gSendCmd[2] = Rfu.sendBlock.owner + 0x80;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0xA100:
|
2020-06-07 23:37:09 +02:00
|
|
|
if (AreNoPlayersReceiving())
|
2020-02-16 19:49:36 +01:00
|
|
|
gSendCmd[1] = Rfu.unk_5a;
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x7700:
|
|
|
|
case RFU_COMMAND_0x7800:
|
2020-02-16 19:49:36 +01:00
|
|
|
tmp = Rfu.unk_ce2 ^ Rfu.unk_ce3;
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.playerCount = sUnknown_082ED695[tmp] + 1;
|
2020-02-16 19:49:36 +01:00
|
|
|
gSendCmd[1] = Rfu.playerCount;
|
|
|
|
buff = (u8 *)(gSendCmd + 2);
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
|
|
|
buff[i] = Rfu.linkPlayerIdx[i];
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x6600:
|
|
|
|
case RFU_COMMAND_0x5F00:
|
2020-02-16 19:49:36 +01:00
|
|
|
gSendCmd[1] = Rfu.unk_100;
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x4400:
|
2020-02-16 19:49:36 +01:00
|
|
|
gSendCmd[0] = command;
|
|
|
|
gSendCmd[1] = gMain.heldKeys;
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0x2F00:
|
2020-02-16 19:49:36 +01:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
gSendCmd[1 + i] = Rfu.unk_f2[i];
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0xBE00:
|
2020-02-16 19:49:36 +01:00
|
|
|
gSendCmd[1] = gHeldKeyCodeToSend;
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0xEE00:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case RFU_COMMAND_0xED00:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800FE50(void *a0)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (gSendCmd[0] == 0 && !RfuHasErrored())
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
memcpy(Rfu.unk_f2, a0, sizeof(Rfu.unk_f2));
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x2F00);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
bool32 Rfu_InitBlockSend(const u8 *src, size_t size)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
bool8 r4;
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.callback != NULL)
|
2020-02-16 19:49:36 +01:00
|
|
|
return FALSE;
|
|
|
|
if (gSendCmd[0] != 0)
|
|
|
|
return FALSE;
|
2020-06-08 06:45:06 +02:00
|
|
|
if (Rfu.sendBlock.sending)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
sRfuDebug.unk_83++;
|
2020-02-16 19:49:36 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
r4 = (size % 12) != 0;
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.sendBlock.owner = GetMultiplayerId();
|
|
|
|
Rfu.sendBlock.sending = TRUE;
|
|
|
|
Rfu.sendBlock.count = (size / 12) + r4;
|
|
|
|
Rfu.sendBlock.next = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
if (size > 0x100)
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.sendBlock.payload = src;
|
2020-02-16 19:49:36 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (src != gBlockSendBuffer)
|
|
|
|
memcpy(gBlockSendBuffer, src, size);
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.sendBlock.payload = gBlockSendBuffer;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x8800);
|
|
|
|
Rfu.callback = HandleBlockSend;
|
2020-02-16 19:49:36 +01:00
|
|
|
Rfu.unk_5b = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void HandleBlockSend(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (gSendCmd[0] == 0)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x8800);
|
|
|
|
if (Rfu.parentChild == MODE_PARENT)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (++Rfu.unk_5b > 2)
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = SendNextBlock;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if ((gRecvCmds[GetMultiplayerId()][0] & 0xff00) == RFU_COMMAND_0x8800)
|
|
|
|
Rfu.callback = SendNextBlock;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void SendNextBlock(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
2020-06-08 06:45:06 +02:00
|
|
|
const u8 *src = Rfu.sendBlock.payload;
|
|
|
|
gSendCmd[0] = RFU_COMMAND_0x8900 | Rfu.sendBlock.next;
|
|
|
|
for (i = 0; i < CMD_LENGTH - 1; i++)
|
|
|
|
gSendCmd[i + 1] = (src[(i << 1) + Rfu.sendBlock.next * 12 + 1] << 8) | src[(i << 1) + Rfu.sendBlock.next * 12 + 0];
|
|
|
|
Rfu.sendBlock.next++;
|
|
|
|
if (Rfu.sendBlock.count <= Rfu.sendBlock.next)
|
|
|
|
{
|
|
|
|
Rfu.sendBlock.sending = FALSE;
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = SendLastBlock;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void SendLastBlock(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
const u8 *src = Rfu.sendBlock.payload;
|
2020-02-16 19:49:36 +01:00
|
|
|
u8 mpId = GetMultiplayerId();
|
|
|
|
s32 i;
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.parentChild == MODE_CHILD)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
gSendCmd[0] = RFU_COMMAND_0x8900 | (Rfu.sendBlock.count - 1);
|
|
|
|
for (i = 0; i < CMD_LENGTH - 1; i++)
|
|
|
|
gSendCmd[i + 1] = (src[(i << 1) + (Rfu.sendBlock.count - 1) * 12 + 1] << 8) | src[(i << 1) + (Rfu.sendBlock.count - 1) * 12 + 0];
|
|
|
|
if ((u8)gRecvCmds[mpId][0] == Rfu.sendBlock.count - 1)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
if (Rfu.recvBlock[mpId].receivedFlags != sAllBlocksReceived[Rfu.recvBlock[mpId].count])
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-08 06:45:06 +02:00
|
|
|
HandleSendFailure(mpId, Rfu.recvBlock[mpId].receivedFlags);
|
|
|
|
sRfuDebug.unk_64++;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
else
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = NULL;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = NULL;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
bool8 sub_8010100(u8 blockRequestType)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.unk_5a = blockRequestType;
|
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0xA100);
|
2020-02-16 19:49:36 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_801011C(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
rfu_clearAllSlot();
|
|
|
|
rfu_LMAN_powerDownRFU();
|
|
|
|
gReceivedRemoteLinkPlayers = 0;
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.isShuttingDown = TRUE;
|
|
|
|
Rfu.callback = NULL;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8010148(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
rfu_REQ_disconnect(gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag);
|
|
|
|
rfu_waitREQComplete();
|
|
|
|
sub_801011C();
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8010168(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.parentChild == MODE_CHILD)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
rfu_LMAN_requestChangeAgbClockMaster();
|
|
|
|
Rfu.unk_ce4 = 2;
|
|
|
|
}
|
|
|
|
else
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = sub_8010148;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LinkRfu_FatalError(void)
|
|
|
|
{
|
|
|
|
rfu_LMAN_requestChangeAgbClockMaster();
|
|
|
|
Rfu.unk_ce4 = 1;
|
|
|
|
Rfu.unk_ce3 = gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_80101CC(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
u8 playerCount = Rfu.playerCount;
|
|
|
|
s32 count = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
|
|
|
{
|
|
|
|
if (Rfu.unk_e4[i])
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (count == playerCount)
|
|
|
|
{
|
|
|
|
gBattleTypeFlags &= ~BATTLE_TYPE_20;
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.parentChild == MODE_CHILD)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.errorState = 3;
|
2020-02-16 19:49:36 +01:00
|
|
|
sub_8010168();
|
|
|
|
}
|
|
|
|
else
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = sub_8010168;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_801022C(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (gSendCmd[0] == 0 && Rfu.unk_ce8 == 0)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x5F00);
|
|
|
|
Rfu.callback = sub_80101CC;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8010264(u8 taskId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.callback == NULL)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
Rfu.unk_cd9 = 1;
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = sub_801022C;
|
2020-02-16 19:49:36 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void task_add_05_task_del_08FA224_when_no_RfuFunc(void)
|
|
|
|
{
|
|
|
|
if (!FuncIsActiveTask(sub_8010264))
|
|
|
|
CreateTask(sub_8010264, 5);
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_80102B8(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 playerCount;
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
if (GetMultiplayerId() != 0)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.recvQueue.count == 0 && Rfu.unk_fe > 60)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x6600);
|
|
|
|
Rfu.unk_fe = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
playerCount = GetLinkPlayerCount();
|
|
|
|
for (i = 0; i < playerCount; i++)
|
|
|
|
{
|
|
|
|
if (Rfu.unk_e9[i] == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == playerCount)
|
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
|
|
|
Rfu.unk_e9[i] = 0;
|
|
|
|
Rfu.unk_100++;
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = NULL;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
Rfu.unk_fe++;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8010358(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.recvQueue.count == 0 && gSendCmd[0] == 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x6600);
|
|
|
|
Rfu.callback = sub_80102B8;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8010390(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 playerCount;
|
|
|
|
|
|
|
|
if (GetMultiplayerId() != 0)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.recvQueue.count == 0 && gSendCmd[0] == 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x6600);
|
|
|
|
Rfu.callback = sub_80102B8;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playerCount = GetLinkPlayerCount();
|
|
|
|
for (i = 1; i < playerCount; i++)
|
|
|
|
{
|
|
|
|
if (Rfu.unk_e9[i] == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == playerCount)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.recvQueue.count == 0 && gSendCmd[0] == 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x6600);
|
|
|
|
Rfu.callback = sub_8010358;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_8010434(void)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.callback == NULL)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = sub_8010390;
|
2020-02-16 19:49:36 +01:00
|
|
|
Rfu.unk_fe = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:37:09 +02:00
|
|
|
bool32 IsRfuSerialNumberValid(u32 serialNo)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; sAcceptedSerialNos[i] != serialNo; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (sAcceptedSerialNos[i] == 0xFFFF)
|
2020-02-16 19:49:36 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 sub_801048C(bool32 a0)
|
|
|
|
{
|
|
|
|
if (a0 == FALSE)
|
|
|
|
return rfu_LMAN_setLinkRecovery(0, 0);
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_LMAN_setLinkRecovery(1, 600);
|
2020-02-16 19:49:36 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_80104B0(void)
|
|
|
|
{
|
|
|
|
Rfu.unk_cd9 = 1;
|
|
|
|
rfu_LMAN_stopManager(FALSE);
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 Rfu_GetMultiplayerId(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.parentChild == MODE_PARENT)
|
2020-02-16 19:49:36 +01:00
|
|
|
return 0;
|
2020-06-06 22:46:19 +02:00
|
|
|
return Rfu.multiplayerId;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 Rfu_GetLinkPlayerCount(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
return Rfu.playerCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 IsLinkRfuTaskFinished(void)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.status == RFU_STATUS_CONNECTION_ERROR)
|
2020-02-16 19:49:36 +01:00
|
|
|
return FALSE;
|
2020-06-06 22:46:19 +02:00
|
|
|
return Rfu.callback ? FALSE : TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void CallRfuFunc(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.callback)
|
|
|
|
Rfu.callback();
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
static bool8 CheckForLeavingGroupMembers(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
2020-06-09 00:16:57 +02:00
|
|
|
bool8 memberLeft = FALSE;
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.partnerSendStatuses[i] < RFU_STATUS_JOIN_GROUP_OK
|
|
|
|
|| Rfu.partnerSendStatuses[i] > RFU_STATUS_JOIN_GROUP_NO)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS
|
|
|
|
|| gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_LEAVE_GROUP_NOTICE)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
Rfu.partnerSendStatuses[i] = RFU_STATUS_LEAVE_GROUP;
|
|
|
|
Rfu.partnerRecvStatuses[i] = RFU_STATUS_10;
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_clearSlot(TYPE_NI_RECV, i);
|
2020-06-09 00:16:57 +02:00
|
|
|
rfu_NI_setSendData(1 << i, 8, &Rfu.partnerSendStatuses[i], 1);
|
|
|
|
memberLeft = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-06-07 23:37:09 +02:00
|
|
|
else if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_FAILED)
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_clearSlot(TYPE_NI_RECV, i);
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
return memberLeft;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool32 sub_80105EC(void)
|
|
|
|
{
|
|
|
|
u8 flags = 0;
|
|
|
|
s32 i;
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_11)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
flags |= (1 << i);
|
2020-06-09 00:16:57 +02:00
|
|
|
Rfu.partnerRecvStatuses[i] = RFU_STATUS_OK;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags)
|
|
|
|
{
|
|
|
|
rfu_REQ_disconnect(flags);
|
|
|
|
rfu_waitREQComplete();
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_10
|
|
|
|
|| Rfu.partnerRecvStatuses[i] == RFU_STATUS_11)
|
2020-02-16 19:49:36 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
bool32 HasTrainerLeftPartnersList(u16 trainerId, const u8 *name)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
u8 idx = GetPartnerIndexByNameAndTrainerID(name, trainerId);
|
2020-06-06 22:46:19 +02:00
|
|
|
if (idx == 0xFF)
|
2020-02-16 19:49:36 +01:00
|
|
|
return TRUE;
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.partnerSendStatuses[idx] == RFU_STATUS_LEAVE_GROUP)
|
2020-02-16 19:49:36 +01:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
void SendRfuStatusToPartner(u8 status, u16 trainerId, const u8 *name)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
u8 idx = GetPartnerIndexByNameAndTrainerID(name, trainerId);
|
|
|
|
Rfu.partnerSendStatuses[idx] = status;
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_clearSlot(TYPE_NI_SEND, idx);
|
2020-06-09 00:16:57 +02:00
|
|
|
rfu_NI_setSendData(1 << idx, 8, &Rfu.partnerSendStatuses[idx], 1);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
void SendLeaveGroupNotice(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
Rfu.unk_c85 = RFU_STATUS_LEAVE_GROUP_NOTICE;
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_clearSlot(TYPE_NI_SEND, Rfu.childSlot);
|
|
|
|
rfu_NI_setSendData(1 << Rfu.childSlot, 8, &Rfu.unk_c85, 1);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
u32 WaitSendRfuStatusToPartner(u16 trainerId, const u8 *name)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
u8 idx = GetPartnerIndexByNameAndTrainerID(name, trainerId);
|
2020-06-06 22:46:19 +02:00
|
|
|
if (idx == 0xFF)
|
2020-02-16 19:49:36 +01:00
|
|
|
return 2;
|
2020-06-06 22:46:19 +02:00
|
|
|
if (gRfuSlotStatusNI[idx]->send.state == 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
static void UpdateChildStatuses(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
CheckForLeavingGroupMembers();
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (gRfuSlotStatusNI[i]->send.state == SLOT_STATE_SEND_SUCCESS
|
|
|
|
|| gRfuSlotStatusNI[i]->send.state == SLOT_STATE_SEND_FAILED)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_10)
|
|
|
|
Rfu.partnerRecvStatuses[i] = RFU_STATUS_11;
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_clearSlot(TYPE_NI_SEND, i);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static s32 sub_80107A0(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
s32 status = RFU_STATUS_OK;
|
2020-02-16 19:49:36 +01:00
|
|
|
if (Rfu.unk_c85 == 8)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (gRfuSlotStatusNI[Rfu.childSlot]->send.state == SLOT_STATE_SEND_SUCCESS
|
|
|
|
|| gRfuSlotStatusNI[Rfu.childSlot]->send.state == SLOT_STATE_SEND_FAILED)
|
|
|
|
rfu_clearSlot(TYPE_NI_SEND, Rfu.childSlot);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_SUCCESS
|
|
|
|
|| gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_clearSlot(TYPE_NI_RECV, Rfu.childSlot);
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(Rfu.recvStatus, 0);
|
|
|
|
status = Rfu.recvStatus;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-07 23:37:09 +02:00
|
|
|
else if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_FAILED)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_clearSlot(TYPE_NI_RECV, Rfu.childSlot);
|
2020-06-09 00:16:57 +02:00
|
|
|
status = RFU_STATUS_JOIN_GROUP_NO;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
return status;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_801084C(u8 taskId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.status == RFU_STATUS_FATAL_ERROR || Rfu.status == RFU_STATUS_CONNECTION_ERROR)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
Rfu.unk_ce8 = 0;
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
switch (gTasks[taskId].data[0])
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case 0:
|
2020-06-07 23:37:09 +02:00
|
|
|
if (AreNoPlayersReceiving())
|
2020-06-06 22:46:19 +02:00
|
|
|
{
|
|
|
|
ResetBlockReceivedFlags();
|
|
|
|
sub_800B348();
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (Rfu.parentChild == MODE_PARENT)
|
|
|
|
{
|
|
|
|
if (gReceivedRemoteLinkPlayers)
|
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x7800);
|
2020-02-16 19:49:36 +01:00
|
|
|
else
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x7700);
|
|
|
|
gTasks[taskId].data[0] = 101;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gTasks[taskId].data[0] = 2;
|
|
|
|
break;
|
|
|
|
case 101:
|
|
|
|
if (gSendCmd[0] == 0)
|
|
|
|
gTasks[taskId].data[0] = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (Rfu.playerCount)
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (Rfu.parentChild == MODE_PARENT)
|
|
|
|
{
|
2020-06-07 23:37:09 +02:00
|
|
|
if (AreNoPlayersReceiving())
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.unk_5a = 0;
|
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0xA100);
|
2020-02-16 19:49:36 +01:00
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
}
|
|
|
|
else
|
2020-02-16 19:49:36 +01:00
|
|
|
gTasks[taskId].data[0]++;
|
2020-06-06 22:46:19 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (sub_800FC88())
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
for (i = 0; i < Rfu.playerCount; i++)
|
|
|
|
{
|
|
|
|
LinkPlayerFromBlock(i);
|
|
|
|
Rfu_ResetBlockReceivedFlag(i);
|
|
|
|
}
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
DestroyTask(taskId);
|
|
|
|
gReceivedRemoteLinkPlayers = TRUE;
|
|
|
|
Rfu.unk_ce8 = FALSE;
|
|
|
|
rfu_LMAN_setLinkRecovery(1, 600);
|
|
|
|
if (Rfu.unk_ce6)
|
|
|
|
{
|
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if ((Rfu.unk_ce6 >> i) & 1)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.unk_ce5 = 1 << i;
|
|
|
|
Rfu.unk_ce6 ^= (1 << i);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:37:09 +02:00
|
|
|
static void ClearSelectedLinkPlayerIds(u16 selected)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-07 23:37:09 +02:00
|
|
|
if ((selected >> i) & 1)
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.linkPlayerIdx[i] = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void ReceiveRfuLinkPlayers(const struct SioInfo *sioInfo)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.playerCount = sioInfo->playerCount;
|
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
|
|
|
Rfu.linkPlayerIdx[i] = sioInfo->linkPlayerIdx[i];
|
2020-02-16 19:49:36 +01:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
gLinkPlayers[i] = sioInfo->linkPlayers[i];
|
2020-02-16 19:49:36 +01:00
|
|
|
sub_800B524(gLinkPlayers + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void ValidateAndReceivePokemonSioInfo(void *recvBuffer)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (strcmp(sASCII_PokemonSioInfo, recvBuffer) == 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
ReceiveRfuLinkPlayers(recvBuffer);
|
|
|
|
CpuFill16(0, recvBuffer, sizeof(struct SioInfo));
|
2020-02-16 19:49:36 +01:00
|
|
|
ResetBlockReceivedFlag(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Task_ExchangeLinkPlayers(u8 taskId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
struct LinkPlayerBlock *r2;
|
2020-06-06 22:46:19 +02:00
|
|
|
struct SioInfo *r5;
|
|
|
|
u8 r4 = Rfu.linkPlayerIdx[sUnknown_082ED68C[Rfu.unk_ce9]];
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.status == RFU_STATUS_FATAL_ERROR || Rfu.status == RFU_STATUS_CONNECTION_ERROR)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
Rfu.unk_ce8 = 0;
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
switch (gTasks[taskId].data[0])
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case 0:
|
|
|
|
if (gSendCmd[0] == 0)
|
|
|
|
{
|
|
|
|
ResetBlockReceivedFlag(r4);
|
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0x7800);
|
2020-02-16 19:49:36 +01:00
|
|
|
gTasks[taskId].data[0]++;
|
2020-06-06 22:46:19 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (gSendCmd[0] == 0)
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if ((GetBlockReceivedStatus() >> r4) & 1)
|
|
|
|
{
|
|
|
|
ResetBlockReceivedFlag(r4);
|
|
|
|
r2 = (struct LinkPlayerBlock *)gBlockRecvBuffer[r4];
|
|
|
|
gLinkPlayers[r4] = r2->linkPlayer;
|
|
|
|
sub_800B524(gLinkPlayers + r4);
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
r5 = (struct SioInfo *)gBlockSendBuffer;
|
|
|
|
memcpy(r5->magic, sASCII_PokemonSioInfo, sizeof sASCII_PokemonSioInfo);
|
|
|
|
r5->playerCount = Rfu.playerCount;
|
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
|
|
|
r5->linkPlayerIdx[i] = Rfu.linkPlayerIdx[i];
|
|
|
|
memcpy(r5->linkPlayers, gLinkPlayers, sizeof gLinkPlayers);
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
// fallthrough
|
|
|
|
case 4:
|
|
|
|
r5 = (struct SioInfo *)gBlockSendBuffer;
|
|
|
|
r5->playerCount = Rfu.playerCount;
|
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
|
|
|
r5->linkPlayerIdx[i] = Rfu.linkPlayerIdx[i];
|
|
|
|
memcpy(r5->linkPlayers, gLinkPlayers, sizeof gLinkPlayers);
|
|
|
|
if (SendBlock(0, gBlockSendBuffer, 0xa0))
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
if (IsLinkTaskFinished() && GetBlockReceivedStatus() & 1)
|
|
|
|
{
|
|
|
|
CpuFill16(0, gBlockRecvBuffer, sizeof(struct SioInfo));
|
|
|
|
ResetBlockReceivedFlag(0);
|
|
|
|
Rfu.unk_ce8 = 0;
|
|
|
|
if (Rfu.unk_ce6)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if ((Rfu.unk_ce6 >> i) & 1)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.unk_ce5 = 1 << i;
|
|
|
|
Rfu.unk_ce6 ^= (1 << i);
|
|
|
|
Rfu.unk_ce8 = 1;
|
|
|
|
break;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
break;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8010D0C(u8 taskId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.status == RFU_STATUS_FATAL_ERROR || Rfu.status == RFU_STATUS_CONNECTION_ERROR)
|
2020-02-16 19:49:36 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
switch (gTasks[taskId].data[0])
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case 0:
|
|
|
|
if (Rfu.playerCount)
|
|
|
|
{
|
|
|
|
sub_800B348();
|
|
|
|
SendBlock(0, gBlockSendBuffer, sizeof(struct LinkPlayerBlock));
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (IsLinkTaskFinished())
|
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (GetBlockReceivedStatus() & 1)
|
|
|
|
{
|
|
|
|
ReceiveRfuLinkPlayers((const struct SioInfo *)gBlockRecvBuffer);
|
|
|
|
ResetBlockReceivedFlag(0);
|
|
|
|
gReceivedRemoteLinkPlayers = 1;
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
break;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void RfuCheckErrorStatus(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.errorState == 1 && lman.childClockSlave_flag == 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (gMain.callback2 == c2_mystery_gift_e_reader_run || lman.init_param->mboot_flag)
|
|
|
|
gWirelessCommType = 2;
|
|
|
|
SetMainCallback2(CB2_LinkError);
|
|
|
|
gMain.savedCallback = CB2_LinkError;
|
2020-06-09 00:16:57 +02:00
|
|
|
BufferLinkErrorInfo((Rfu.linkmanMsg << 16) | (Rfu.unk_10 << 8) | Rfu.unk_12, Rfu.recvQueue.count, Rfu.sendQueue.count, RfuGetStatus() == RFU_STATUS_CONNECTION_ERROR);
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.errorState = 2;
|
2020-02-16 19:49:36 +01:00
|
|
|
CloseLink();
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
else if (Rfu.sendQueue.full == TRUE || Rfu.recvQueue.full == TRUE)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (lman.childClockSlave_flag)
|
|
|
|
rfu_LMAN_requestChangeAgbClockMaster();
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_FATAL_ERROR, 0x7000);
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(0x7000);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void rfu_REQ_recvData_then_sendData(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (lman.parent_child == 1)
|
|
|
|
{
|
|
|
|
rfu_REQ_recvData();
|
|
|
|
rfu_waitREQComplete();
|
|
|
|
rfu_LMAN_REQ_sendData(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 sub_8010EC0(void)
|
|
|
|
{
|
|
|
|
bool32 retval = FALSE;
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.parentId = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_LMAN_manager_entity(Random2());
|
2020-06-06 22:46:19 +02:00
|
|
|
if (!Rfu.isShuttingDown)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
switch (Rfu.parentChild)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case MODE_PARENT:
|
|
|
|
sub_800F0F8();
|
|
|
|
break;
|
|
|
|
case MODE_CHILD:
|
|
|
|
retval = RfuProcessEnqueuedRecvBlock();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rfu_REQ_recvData_then_sendData();
|
|
|
|
break;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 sub_8010F1C(void)
|
|
|
|
{
|
|
|
|
bool32 retval = FALSE;
|
2020-06-06 22:46:19 +02:00
|
|
|
if (!Rfu.isShuttingDown)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.parentChild == MODE_PARENT)
|
2020-02-16 19:49:36 +01:00
|
|
|
retval = sub_800F1E0();
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuCheckErrorStatus();
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void CopyPlayerNameToUnameBuffer(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
StringCopy(gHostRFUtgtUnameBuffer, gSaveBlock2Ptr->playerName);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void ClearAndInitHostRFUtgtGname(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
memset(&gHostRFUtgtGnameBuffer, 0, RFU_GAME_NAME_LENGTH);
|
2020-06-08 06:45:06 +02:00
|
|
|
InitHostRFUtgtGname(&gHostRFUtgtGnameBuffer, ACTIVITY_NONE, FALSE, 0);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
void SetHostRFUtgtGname(u8 activity, u32 child_sprite_genders, bool32 started)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-07 23:37:09 +02:00
|
|
|
InitHostRFUtgtGname(&gHostRFUtgtGnameBuffer, activity, started, child_sprite_genders);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void SetGnameBufferWonderFlags(bool32 hasNews, bool32 hasCard)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
gHostRFUtgtGnameBuffer.unk_00.hasNews = hasNews;
|
|
|
|
gHostRFUtgtGnameBuffer.unk_00.hasCard = hasCard;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void SetTradeBoardRegisteredMonInfo(u32 type, u32 species, u32 level)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
gHostRFUtgtGnameBuffer.type = type;
|
|
|
|
gHostRFUtgtGnameBuffer.species = species;
|
|
|
|
gHostRFUtgtGnameBuffer.level = level;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u8 sub_801100C(s32 a0)
|
|
|
|
{
|
|
|
|
u8 retval = 0x80;
|
|
|
|
retval |= (gLinkPlayers[a0].gender << 3);
|
|
|
|
retval |= (gLinkPlayers[a0].trainerId & 7);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_801103C(void)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
struct GFtgtGname *r5 = &gHostRFUtgtGnameBuffer;
|
2020-02-16 19:49:36 +01:00
|
|
|
s32 i;
|
|
|
|
|
|
|
|
for (i = 1; i < GetLinkPlayerCount(); i++)
|
|
|
|
r5->child_sprite_gender[i - 1] = sub_801100C(i);
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
void UpdateGameData_GroupLockedIn(bool8 started)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
gHostRFUtgtGnameBuffer.started = started;
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_REQ_configGameData(0, 2, (void *)&gHostRFUtgtGnameBuffer, gHostRFUtgtUnameBuffer);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
void UpdateGameData_SetActivity(u8 activity, u32 flags, bool32 started)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (activity != ACTIVITY_NONE)
|
|
|
|
SetHostRFUtgtGname(activity, flags, started);
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_REQ_configGameData(0, 2, (void *)&gHostRFUtgtGnameBuffer, gHostRFUtgtUnameBuffer);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sub_80110B8(u32 a0)
|
|
|
|
{
|
|
|
|
s32 i;
|
2020-06-06 22:46:19 +02:00
|
|
|
u32 numConnectedChildren;
|
|
|
|
u32 child_sprite_genders;
|
2020-02-16 19:49:36 +01:00
|
|
|
s32 r8;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM))
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
numConnectedChildren = 0;
|
|
|
|
child_sprite_genders = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
r8 = Rfu.unk_ce2 ^ Rfu.unk_ce3;
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if ((r8 >> i) & 1)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
child_sprite_genders |= ((0x80 | ((gLinkPlayers[Rfu.linkPlayerIdx[i]].gender & 1) << 3) | (gLinkPlayers[Rfu.linkPlayerIdx[i]].trainerId & 7)) << (numConnectedChildren << 3));
|
|
|
|
numConnectedChildren++;
|
|
|
|
if (numConnectedChildren == a0 - 1)
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
UpdateGameData_SetActivity((ACTIVITY_CHAT | IN_UNION_ROOM), child_sprite_genders, FALSE);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void GetLinkmanErrorParams(u32 msg)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.errorState == 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
Rfu.unk_10 = lman.param[0];
|
|
|
|
Rfu.unk_12 = lman.param[1];
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.linkmanMsg = msg;
|
|
|
|
Rfu.errorState = 1;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void ResetErrorState(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.errorState = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sub_80111B0(bool32 a0)
|
|
|
|
{
|
|
|
|
if (!a0)
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.errorState = 0;
|
2020-02-16 19:49:36 +01:00
|
|
|
else
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.errorState = 4;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_80111DC(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
sub_8011E94(lman.acceptSlot_flag, 1);
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = NULL;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_80111FC(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.callback = sub_80111DC;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_801120C(u8 msg, u8 paramCount)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 disconnectFlag = 0;
|
|
|
|
switch (msg)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_INITIALIZE_COMPLETED:
|
|
|
|
Rfu.state = 2;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_NEW_CHILD_CONNECT_ACCEPTED:
|
2020-02-16 19:49:36 +01:00
|
|
|
sub_80115EC(lman.param[0]);
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if ((lman.param[0] >> i) & 1)
|
|
|
|
{
|
|
|
|
struct GFtgtGname *structPtr = (void *)gRfuLinkStatus->partner[i].gname;
|
2020-05-30 10:09:21 +02:00
|
|
|
if (structPtr->activity == GetHostRFUtgtGname()->activity)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
Rfu.partnerSendStatuses[i] = RFU_STATUS_OK;
|
|
|
|
Rfu.partnerRecvStatuses[i] = RFU_STATUS_OK;
|
|
|
|
rfu_setRecvBuffer(TYPE_NI, i, &Rfu.partnerRecvStatuses[i], 1);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
disconnectFlag |= (1 << i);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
if (disconnectFlag)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_REQ_disconnect(disconnectFlag);
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_waitREQComplete();
|
|
|
|
}
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_NEW_CHILD_CONNECT_REJECTED:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_SEARCH_CHILD_PERIOD_EXPIRED:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_END_WAIT_CHILD_NAME:
|
|
|
|
if (Rfu.acceptSlot_flag != lman.acceptSlot_flag)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_REQ_disconnect(Rfu.acceptSlot_flag ^ lman.acceptSlot_flag);
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_waitREQComplete();
|
|
|
|
}
|
2020-06-07 23:37:09 +02:00
|
|
|
Rfu.state = 17;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY:
|
|
|
|
Rfu.linkLossRecoveryState = 1;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_RECOVERY_SUCCESSED:
|
|
|
|
Rfu.linkLossRecoveryState = 3;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED:
|
|
|
|
case LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED:
|
|
|
|
Rfu.linkLossRecoveryState = 4;
|
2020-02-16 19:49:36 +01:00
|
|
|
Rfu.unk_ce2 &= ~lman.param[0];
|
|
|
|
if (gReceivedRemoteLinkPlayers == 1)
|
|
|
|
{
|
|
|
|
if (Rfu.unk_ce2 == 0)
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(msg);
|
2020-02-16 19:49:36 +01:00
|
|
|
else
|
|
|
|
sub_80111FC();
|
|
|
|
}
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
|
|
|
case 0x34:
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_RFU_POWER_DOWN:
|
|
|
|
case LMAN_MSG_MANAGER_STOPPED:
|
|
|
|
case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LMAN_API_ERROR_RETURN:
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg);
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(msg);
|
|
|
|
Rfu.isShuttingDown = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_REQ_API_ERROR:
|
|
|
|
case LMAN_MSG_WATCH_DOG_TIMER_ERROR:
|
|
|
|
case LMAN_MSG_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA:
|
|
|
|
case LMAN_MSG_RFU_FATAL_ERROR:
|
|
|
|
GetLinkmanErrorParams(msg);
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg);
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_cdb = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void sub_8011404(u8 msg, u8 unused1)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
switch (msg)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_INITIALIZE_COMPLETED:
|
|
|
|
Rfu.state = 6;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_PARENT_FOUND:
|
|
|
|
Rfu.parentId = lman.param[0];
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_SEARCH_PARENT_PERIOD_EXPIRED:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_CONNECT_PARENT_SUCCESSED:
|
|
|
|
Rfu.childSlot = lman.param[0];
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_CONNECT_PARENT_FAILED:
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_CHILD_NAME_SEND_COMPLETED:
|
|
|
|
Rfu.state = 11;
|
2020-02-16 19:49:36 +01:00
|
|
|
Rfu.unk_c85 = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
Rfu.recvStatus = RFU_STATUS_OK;
|
|
|
|
rfu_setRecvBuffer(TYPE_NI, Rfu.childSlot, &Rfu.recvStatus, 1);
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, 70);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_CHILD_NAME_SEND_FAILED_AND_DISCONNECTED:
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED:
|
|
|
|
Rfu.linkLossRecoveryState = 2;
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.recvStatus == RFU_STATUS_JOIN_GROUP_NO)
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED:
|
|
|
|
if (Rfu.linkLossRecoveryState != 2)
|
|
|
|
Rfu.linkLossRecoveryState = 4;
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.recvStatus != RFU_STATUS_LEAVE_GROUP)
|
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg);
|
2020-06-06 22:46:19 +02:00
|
|
|
Debug_PrintString(sASCII_LinkLossDisconnect, 5, 5);
|
2020-02-16 19:49:36 +01:00
|
|
|
if (gReceivedRemoteLinkPlayers == 1)
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(msg);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY:
|
|
|
|
Rfu.linkLossRecoveryState = 1;
|
|
|
|
Debug_PrintString(sASCII_LinkLossRecoveryNow, 5, 5);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_RECOVERY_SUCCESSED:
|
|
|
|
Rfu.linkLossRecoveryState = 3;
|
2020-06-07 23:37:09 +02:00
|
|
|
Rfu.linkRecovered = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
|
|
|
case 0x34:
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_RFU_POWER_DOWN:
|
|
|
|
case LMAN_MSG_MANAGER_STOPPED:
|
|
|
|
case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LMAN_API_ERROR_RETURN:
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg);
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(msg);
|
|
|
|
Rfu.isShuttingDown = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_REQ_API_ERROR:
|
|
|
|
case LMAN_MSG_WATCH_DOG_TIMER_ERROR:
|
|
|
|
case LMAN_MSG_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA:
|
|
|
|
case LMAN_MSG_RFU_FATAL_ERROR:
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg);
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(msg);
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_cdb = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_80115EC(s32 a0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if ((a0 >> i) & 1)
|
|
|
|
{
|
|
|
|
Rfu.unk_cea[i] = 0;
|
|
|
|
Rfu.unk_cee[i] = 0xFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static u8 GetNewChildrenInUnionRoomChat(s32 a0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 ret = 0;
|
|
|
|
u8 i;
|
|
|
|
|
2020-06-07 23:37:09 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if ((a0 >> i) & 1)
|
|
|
|
{
|
|
|
|
struct GFtgtGname *structPtr = (void *)gRfuLinkStatus->partner[i].gname;
|
2020-06-06 22:46:19 +02:00
|
|
|
if (structPtr->activity == (ACTIVITY_CHAT | IN_UNION_ROOM))
|
2020-02-16 19:49:36 +01:00
|
|
|
ret |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8011674(u8 msg, u8 paramCount)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 r1;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
switch (msg)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_INITIALIZE_COMPLETED:
|
|
|
|
Rfu.state = 17;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED:
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_NEW_CHILD_DETECTED, 0);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_NEW_CHILD_CONNECT_ACCEPTED:
|
|
|
|
if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && Rfu.unk_cd9 == 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 idx = GetNewChildrenInUnionRoomChat(lman.param[0]);
|
2020-02-16 19:49:36 +01:00
|
|
|
if (idx != 0)
|
|
|
|
{
|
|
|
|
r1 = 1 << sub_800E87C(idx);
|
|
|
|
if (Rfu.unk_ce6 == 0 && Rfu.unk_ce8 == 0)
|
|
|
|
{
|
|
|
|
Rfu.unk_ce5 = r1;
|
|
|
|
Rfu.unk_ce6 |= (r1 ^ idx);
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.unk_ce8 = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Rfu.unk_ce6 |= idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (idx != lman.param[0])
|
|
|
|
{
|
|
|
|
Rfu.unk_ce3 |= (idx ^ lman.param[0]);
|
|
|
|
Rfu.unk_ce4 = 2;
|
|
|
|
}
|
|
|
|
}
|
2020-06-08 06:45:06 +02:00
|
|
|
else if (GetHostRFUtgtGname()->activity == (ACTIVITY_PLYRTALK | IN_UNION_ROOM))
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
rfu_REQ_disconnect(lman.acceptSlot_flag);
|
|
|
|
rfu_waitREQComplete();
|
|
|
|
}
|
|
|
|
sub_80115EC(lman.param[0]);
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_NEW_CHILD_CONNECT_REJECTED:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_SEARCH_CHILD_PERIOD_EXPIRED:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_END_WAIT_CHILD_NAME:
|
|
|
|
if (GetHostRFUtgtGname()->activity != (ACTIVITY_CHAT | IN_UNION_ROOM) && lman.acceptCount > 1)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
r1 = 1 << sub_800E87C(lman.param[0]);
|
|
|
|
rfu_REQ_disconnect(lman.acceptSlot_flag ^ r1);
|
|
|
|
rfu_waitREQComplete();
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.state == 15)
|
|
|
|
Rfu.state = 16;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_PARENT_FOUND:
|
|
|
|
Rfu.parentId = lman.param[0];
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_SEARCH_PARENT_PERIOD_EXPIRED:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_CONNECT_PARENT_SUCCESSED:
|
|
|
|
Rfu.childSlot = lman.param[0];
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_CONNECT_PARENT_FAILED:
|
|
|
|
Rfu.state = 18;
|
2020-02-16 19:49:36 +01:00
|
|
|
if (Rfu.unk_ccf < 2)
|
|
|
|
{
|
|
|
|
Rfu.unk_ccf++;
|
|
|
|
CreateTask(sub_801209C, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_CHILD_NAME_SEND_COMPLETED:
|
|
|
|
Rfu.state = 13;
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CHILD_SEND_COMPLETE, 0);
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, 70);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_CHILD_NAME_SEND_FAILED_AND_DISCONNECTED:
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY:
|
2020-02-16 19:49:36 +01:00
|
|
|
if (lman.acceptSlot_flag & lman.param[0])
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.linkLossRecoveryState = 1;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_RECOVERY_SUCCESSED:
|
|
|
|
Rfu.linkLossRecoveryState = 3;
|
|
|
|
if (gRfuLinkStatus->parentChild == MODE_CHILD)
|
2020-06-07 23:37:09 +02:00
|
|
|
Rfu.linkRecovered = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED:
|
|
|
|
Rfu.linkLossRecoveryState = 2;
|
|
|
|
case LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED:
|
|
|
|
if (Rfu.linkLossRecoveryState != 2)
|
|
|
|
Rfu.linkLossRecoveryState = 4;
|
|
|
|
if (Rfu.parentChild == MODE_PARENT)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (gReceivedRemoteLinkPlayers == 1)
|
|
|
|
{
|
|
|
|
Rfu.unk_ce2 &= ~(lman.param[0]);
|
|
|
|
if (Rfu.unk_ce2 == 0)
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(msg);
|
2020-02-16 19:49:36 +01:00
|
|
|
else
|
|
|
|
sub_80111FC();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Rfu.unk_ce4 != 2 && gReceivedRemoteLinkPlayers == 1)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(msg);
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_LMAN_stopManager(0);
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
if (gRfuLinkStatus->parentChild == MODE_NEUTRAL && lman.pcswitch_flag == 0 && FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE)
|
|
|
|
Rfu.state = 17;
|
2020-02-16 19:49:36 +01:00
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg);
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LINK_DISCONNECTED_BY_USER:
|
2020-02-16 19:49:36 +01:00
|
|
|
Rfu.unk_ce3 = 0;
|
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_RFU_POWER_DOWN:
|
|
|
|
case LMAN_MSG_MANAGER_STOPPED:
|
|
|
|
case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET:
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_LMAN_API_ERROR_RETURN:
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg);
|
2020-06-06 22:46:19 +02:00
|
|
|
GetLinkmanErrorParams(msg);
|
|
|
|
Rfu.isShuttingDown = TRUE;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
2020-06-06 22:46:19 +02:00
|
|
|
case LMAN_MSG_REQ_API_ERROR:
|
|
|
|
case LMAN_MSG_WATCH_DOG_TIMER_ERROR:
|
|
|
|
case LMAN_MSG_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA:
|
|
|
|
case LMAN_MSG_RFU_FATAL_ERROR:
|
|
|
|
GetLinkmanErrorParams(msg);
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg);
|
2020-06-08 06:45:06 +02:00
|
|
|
Rfu.unk_cdb = FALSE;
|
2020-02-16 19:49:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_8011A50(void)
|
|
|
|
{
|
|
|
|
Rfu.unk_ce4 = 2;
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
void RfuSetStatus(u8 status, u16 msg)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
Rfu.status = status;
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.linkmanMsg = msg;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
u8 RfuGetStatus(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
return Rfu.status;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
bool32 RfuHasErrored(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
// RFU_STATUS_OK will underflow here intentionally
|
|
|
|
u32 var = RfuGetStatus() - 1;
|
|
|
|
if (var < RFU_STATUS_CONNECTION_ERROR)
|
2020-02-16 19:49:36 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 sub_8011A9C(void)
|
|
|
|
{
|
|
|
|
return Rfu.unk_ce8;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 Rfu_IsMaster(void)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
return Rfu.parentChild;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RfuVSync(void)
|
|
|
|
{
|
|
|
|
rfu_LMAN_syncVBlank();
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_8011AC8(void)
|
|
|
|
{
|
|
|
|
CpuFill32(0, gRecvCmds, sizeof(gRecvCmds));
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8011AE8(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
LoadOam();
|
|
|
|
ProcessSpriteCopyRequests();
|
|
|
|
TransferPlttBuffer();
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8011AFC(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
ResetSpriteData();
|
|
|
|
FreeAllSpritePalettes();
|
|
|
|
ResetTasks();
|
|
|
|
ResetPaletteFade();
|
|
|
|
SetVBlankCallback(sub_8011AE8);
|
|
|
|
if (IsWirelessAdapterConnected())
|
|
|
|
{
|
2020-06-04 00:00:53 +02:00
|
|
|
gLinkType = LINKTYPE_TRADE;
|
2020-05-30 10:09:21 +02:00
|
|
|
SetWirelessCommType1();
|
2020-02-16 19:49:36 +01:00
|
|
|
OpenLink();
|
|
|
|
SeedRng(gMain.vblankCounter2);
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
gSaveBlock2Ptr->playerTrainerId[i] = Random() % 256;
|
|
|
|
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG0_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_1D_MAP);
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
2020-06-06 22:46:19 +02:00
|
|
|
CreateTask_RfuIdle();
|
2020-02-16 19:49:36 +01:00
|
|
|
SetMainCallback2(sub_8011BF8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
bool32 IsUnionRoomListenTaskActive(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
return FuncIsActiveTask(Task_LinkRfu_UnionRoomListen);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void CreateTask_RfuIdle(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (!FuncIsActiveTask(Task_Idle))
|
|
|
|
Rfu.idleTaskId = CreateTask(Task_Idle, 0);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void DestroyTask_RfuIdle(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (FuncIsActiveTask(Task_Idle) == TRUE)
|
|
|
|
DestroyTask(Rfu.idleTaskId);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8011BF8(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void InitializeRfuLinkManager_LinkLeader(u32 a0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.parentChild = MODE_PARENT;
|
|
|
|
CopyPlayerNameToUnameBuffer();
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_LMAN_initializeManager(sub_801120C, NULL);
|
2020-06-06 22:46:19 +02:00
|
|
|
sRfuReqConfig = sRfuReqConfigTemplate;
|
|
|
|
sRfuReqConfig.availSlot_flag = sAvailSlots[a0 - 1];
|
|
|
|
CreateTask_LinkLeaderSearchForChildren();
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void InitializeRfuLinkManager_JoinGroup(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.parentChild = MODE_CHILD;
|
|
|
|
CopyPlayerNameToUnameBuffer();
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_LMAN_initializeManager(sub_8011404, sub_800ED34);
|
2020-06-06 22:46:19 +02:00
|
|
|
CreateTask_JoinGroupSearchForParent();
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 10:09:21 +02:00
|
|
|
void InitializeRfuLinkManager_EnterUnionRoom(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.parentChild = 2;
|
|
|
|
CopyPlayerNameToUnameBuffer();
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_LMAN_initializeManager(sub_8011674, NULL);
|
2020-06-06 22:46:19 +02:00
|
|
|
sRfuReqConfig = sRfuReqConfigTemplate;
|
|
|
|
sRfuReqConfig.linkRecovery_enable = 0;
|
|
|
|
sRfuReqConfig.linkRecovery_period = 600;
|
|
|
|
Rfu.searchTaskId = CreateTask(Task_LinkRfu_UnionRoomListen, 1);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static u16 ReadU16(const void *ptr)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
const u8 *ptr_ = ptr;
|
|
|
|
return (ptr_[1] << 8) | (ptr_[0]);
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static u8 GetPartnerIndexByNameAndTrainerID(const u8 *name, u16 id)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 idx = 0xFF;
|
2020-02-16 19:49:36 +01:00
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u16 trainerId = ReadU16(gRfuLinkStatus->partner[i].gname + 2);
|
2020-06-07 23:37:09 +02:00
|
|
|
if (IsRfuSerialNumberValid(gRfuLinkStatus->partner[i].serialNo)
|
2020-06-06 22:46:19 +02:00
|
|
|
&& !StringCompare(name, gRfuLinkStatus->partner[i].uname)
|
|
|
|
&& id == trainerId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
idx = i;
|
2020-02-16 19:49:36 +01:00
|
|
|
if (gRfuLinkStatus->partner[i].slot != 0xFF)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
return idx;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void RfuReqDisconnectSlot(u32 slot)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_REQ_disconnect(slot);
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_waitREQComplete();
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.unk_ce2 &= ~(slot);
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_clearSlot(1, Rfu.unk_cda);
|
2020-06-06 22:46:19 +02:00
|
|
|
rfu_UNI_setSendData(Rfu.unk_ce2, Rfu.recvCmds, 70);
|
2020-02-16 19:49:36 +01:00
|
|
|
Rfu.unk_cda = sub_800E87C(Rfu.unk_ce2);
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void RequestDisconnectSlotByTrainerNameAndId(const u8 *name, u16 id)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 var = GetPartnerIndexByNameAndTrainerID(name, id);
|
2020-02-16 19:49:36 +01:00
|
|
|
if (var != 0xFF)
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuReqDisconnectSlot(1 << var);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sub_8011DE0(u32 a0)
|
|
|
|
{
|
|
|
|
if (a0 != 0)
|
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
u8 var = 0;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.linkPlayerIdx[i] == a0 && (Rfu.unk_ce2 >> i) & 1)
|
2020-02-16 19:49:36 +01:00
|
|
|
var |= 1 << i;
|
|
|
|
}
|
|
|
|
if (var)
|
|
|
|
sub_8011E94(var, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8011E2C(u8 taskId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (gSendCmd[0] == 0 && Rfu.unk_ce8 == 0)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
RfuPrepareSendBuffer(RFU_COMMAND_0xED00);
|
2020-02-16 19:49:36 +01:00
|
|
|
gSendCmd[1] = gTasks[taskId].data[0];
|
|
|
|
gSendCmd[2] = gTasks[taskId].data[1];
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.playerCount -= sUnknown_082ED695[gTasks[taskId].data[0]];
|
2020-02-16 19:49:36 +01:00
|
|
|
gSendCmd[3] = Rfu.playerCount;
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_8011E94(u32 a0, u32 a1)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 taskId = FindTaskIdByFunc(sub_8011E2C);
|
|
|
|
if (taskId == 0xFF)
|
|
|
|
{
|
|
|
|
taskId = CreateTask(sub_8011E2C, 5);
|
|
|
|
gTasks[taskId].data[0] = a0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gTasks[taskId].data[0] |= a0;
|
|
|
|
}
|
|
|
|
|
|
|
|
gTasks[taskId].data[1] = a1;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Task_RfuReconnectWithParent(u8 taskId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
if (sub_800EE94())
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 id = GetPartnerIndexByNameAndTrainerID((u8*)data, ReadU16(&data[8]));
|
2020-02-16 19:49:36 +01:00
|
|
|
if (id != 0xFF)
|
|
|
|
{
|
|
|
|
if (gRfuLinkStatus->partner[id].slot != 0xFF)
|
|
|
|
{
|
|
|
|
Rfu.unk_c3d = id;
|
2020-06-06 22:46:19 +02:00
|
|
|
if (IsParentSuccessfullyReconnected())
|
2020-02-16 19:49:36 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
else if (GetHostRFUtgtGname()->activity == ACTIVITY_WONDER_CARD2
|
|
|
|
|| GetHostRFUtgtGname()->activity == ACTIVITY_WONDER_NEWS2)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
data[15]++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x7000);
|
2020-02-16 19:49:36 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data[15]++;
|
|
|
|
Rfu.unk_c3d = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data[15]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data[15] > 240)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x7000);
|
2020-02-16 19:49:36 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void CreateTask_RfuReconnectWithParent(const u8 *name, u16 trainerId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 taskId;
|
|
|
|
s16 *data;
|
|
|
|
|
2020-06-09 00:16:57 +02:00
|
|
|
Rfu.status = RFU_STATUS_OK;
|
2020-06-06 22:46:19 +02:00
|
|
|
taskId = CreateTask(Task_RfuReconnectWithParent, 3);
|
2020-02-16 19:49:36 +01:00
|
|
|
data = gTasks[taskId].data;
|
2020-06-06 22:46:19 +02:00
|
|
|
StringCopy((u8*)(data), name);
|
2020-02-16 19:49:36 +01:00
|
|
|
data[8] = trainerId;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static bool32 ShouldRejectPartnerConnectionBasedOnActivity(s16 activity, struct GFtgtGname *partnerGname)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM))
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (partnerGname->activity != (ACTIVITY_CHAT | IN_UNION_ROOM))
|
2020-02-16 19:49:36 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
else if (partnerGname->activity != IN_UNION_ROOM)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
else if (activity == (ACTIVITY_TRADE | IN_UNION_ROOM))
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
struct GFtgtGname *tradeGname = &Rfu.unk_10A;
|
|
|
|
if (tradeGname->species == SPECIES_EGG)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (partnerGname->species == tradeGname->species)
|
2020-02-16 19:49:36 +01:00
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
else if (partnerGname->species != tradeGname->species
|
|
|
|
|| partnerGname->level != tradeGname->level
|
|
|
|
|| partnerGname->type != tradeGname->type)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void sub_801209C(u8 taskId)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if (Rfu.status == RFU_STATUS_NEW_CHILD_DETECTED)
|
2020-02-16 19:49:36 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
|
|
|
|
if (++gTasks[taskId].data[0] > 300)
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x7000);
|
2020-02-16 19:49:36 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.parentId != 0 && lman.parent_child == 0)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u16 trainerId = ReadU16(Rfu.unk_10A.unk_00.playerTrainerId);
|
2020-06-06 22:46:19 +02:00
|
|
|
u8 id = GetPartnerIndexByNameAndTrainerID(Rfu.playerName, trainerId);
|
2020-02-16 19:49:36 +01:00
|
|
|
if (id != 0xFF)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (!ShouldRejectPartnerConnectionBasedOnActivity(gTasks[taskId].data[1], (void *)gRfuLinkStatus->partner[id].gname))
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (gRfuLinkStatus->partner[id].slot != 0xFF && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[id].id, 0x5A))
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Rfu.state = 0xA;
|
2020-02-16 19:49:36 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x7000);
|
2020-02-16 19:49:36 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
void sub_8012188(const u8 *name, struct GFtgtGname *structPtr, u8 activity)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
u8 taskId, taskId2;
|
|
|
|
|
|
|
|
Rfu.unk_ccf = 0;
|
2020-06-09 00:16:57 +02:00
|
|
|
Rfu.status = RFU_STATUS_OK;
|
2020-02-16 19:49:36 +01:00
|
|
|
StringCopy(Rfu.playerName, name);
|
2020-06-06 22:46:19 +02:00
|
|
|
memcpy(&Rfu.unk_10A, structPtr, RFU_GAME_NAME_LENGTH);
|
2020-02-16 19:49:36 +01:00
|
|
|
rfu_LMAN_forceChangeSP();
|
|
|
|
taskId = CreateTask(sub_801209C, 2);
|
2020-06-06 22:46:19 +02:00
|
|
|
gTasks[taskId].data[1] = activity;
|
|
|
|
taskId2 = FindTaskIdByFunc(Task_LinkRfu_UnionRoomListen);
|
|
|
|
if (activity == (ACTIVITY_CHAT | IN_UNION_ROOM))
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if (taskId2 != 0xFF)
|
|
|
|
gTasks[taskId2].data[7] = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (taskId2 != 0xFF)
|
|
|
|
gTasks[taskId2].data[7] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:37:09 +02:00
|
|
|
bool8 IsRfuRecoveringFromLinkLoss(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
if (Rfu.linkLossRecoveryState == 1)
|
2020-02-16 19:49:36 +01:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 sub_8012240(void)
|
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
if ((lman.acceptSlot_flag >> i) & 1 && Rfu.partnerSendStatuses[i] == RFU_STATUS_OK)
|
2020-02-16 19:49:36 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Debug_PrintEmpty(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < 20; i++)
|
2020-06-06 22:46:19 +02:00
|
|
|
Debug_PrintString(sASCII_30Commas, 0, i);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Debug_PrintStatus(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
s32 i, j;
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
Debug_PrintNum(GetBlockReceivedStatus(), 0x1C, 0x13, 2);
|
|
|
|
Debug_PrintNum(gRfuLinkStatus->connSlotFlag, 0x14, 1, 1);
|
|
|
|
Debug_PrintNum(gRfuLinkStatus->linkLossSlotFlag, 0x17, 1, 1);
|
|
|
|
if (Rfu.parentChild == MODE_PARENT)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
|
|
|
if ((gRfuLinkStatus->getNameFlag >> i) & 1)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Debug_PrintNum(gRfuLinkStatus->partner[i].serialNo, 1, i + 3, 4);
|
|
|
|
Debug_PrintString((void*)gRfuLinkStatus->partner[i].gname, 6, i + 3);
|
|
|
|
Debug_PrintString(gRfuLinkStatus->partner[i].uname, 0x16, i + 3);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-09 00:16:57 +02:00
|
|
|
for (j = 0; j < (int)ARRAY_COUNT(Rfu.unk_14[0]); j++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Debug_PrintNum(Rfu.unk_14[i][j], j * 2, i + 11, 2);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
Debug_PrintString(sASCII_NowSlot, 1, 0xF);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
else if (gRfuLinkStatus->connSlotFlag != 0 && gRfuLinkStatus->getNameFlag != 0)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
for (i = 0; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Debug_PrintNum(0, 1, i + 3, 4);
|
|
|
|
Debug_PrintString(sASCII_15Commas, 6, i + 3);
|
|
|
|
Debug_PrintString(sASCII_8Commas, 0x16, i + 3);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
Debug_PrintNum(gRfuLinkStatus->partner[Rfu.childSlot].serialNo, 1, 3, 4);
|
|
|
|
Debug_PrintString((void*)gRfuLinkStatus->partner[Rfu.childSlot].gname, 6, 3);
|
|
|
|
Debug_PrintString(gRfuLinkStatus->partner[Rfu.childSlot].uname, 0x16, 3);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < gRfuLinkStatus->findParentCount; i++)
|
|
|
|
{
|
|
|
|
if (gRfuLinkStatus->partner[i].slot != 0xFF)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Debug_PrintNum(gRfuLinkStatus->partner[i].serialNo, 1, i + 3, 4);
|
|
|
|
Debug_PrintNum(gRfuLinkStatus->partner[i].id, 6, i + 3, 4);
|
|
|
|
Debug_PrintString(gRfuLinkStatus->partner[i].uname, 0x16, i + 3);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 22:46:19 +02:00
|
|
|
for (; i < RFU_CHILD_MAX; i++)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
Debug_PrintNum(0, 1, i + 3, 4);
|
|
|
|
Debug_PrintString(sASCII_15Commas, 6, i + 3);
|
|
|
|
Debug_PrintString(sASCII_8Commas, 0x16, i + 3);
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static u32 GetRfuSendQueueLength(void)
|
2020-02-16 19:49:36 +01:00
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
return Rfu.sendQueue.count;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 GetRfuRecvQueueLength(void)
|
|
|
|
{
|
2020-06-06 22:46:19 +02:00
|
|
|
return Rfu.recvQueue.count;
|
2020-02-16 19:49:36 +01:00
|
|
|
}
|
2020-02-16 20:34:58 +01:00
|
|
|
|
2020-06-06 22:46:19 +02:00
|
|
|
static void Task_Idle(u8 taskId)
|
2020-02-16 20:34:58 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|