mevent_server_ish

This commit is contained in:
PikalaxALT 2019-04-02 11:43:29 -04:00 committed by huderlem
parent dabd1f6177
commit 03badd9c40
7 changed files with 340 additions and 628 deletions

View File

@ -1,567 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start mevent_srv_ish_do_init
mevent_srv_ish_do_init: @ 801D484
push {r4,r5,lr}
adds r5, r0, 0
ldr r4, =s_mevent_srv_ish_ptr
movs r0, 0x50
bl AllocZeroed
str r0, [r4]
movs r1, 0x1
movs r2, 0
bl mevent_srv_ish_init
ldr r0, [r4]
str r5, [r0, 0x4C]
pop {r4,r5}
pop {r0}
bx r0
.pool
thumb_func_end mevent_srv_ish_do_init
thumb_func_start mevent_srv_ish_do_exec
mevent_srv_ish_do_exec: @ 801D4A8
push {r4-r6,lr}
adds r6, r0, 0
ldr r4, =s_mevent_srv_ish_ptr
ldr r0, [r4]
cmp r0, 0
bne _0801D4BC
movs r0, 0x6
b _0801D4DC
.pool
_0801D4BC:
bl mevent_srv_ish_exec
adds r5, r0, 0
cmp r5, 0x6
bne _0801D4DA
ldr r0, [r4]
ldr r1, [r0, 0x4]
strh r1, [r6]
bl mevent_srv_ish_free_resources
ldr r0, [r4]
bl Free
movs r0, 0
str r0, [r4]
_0801D4DA:
adds r0, r5, 0
_0801D4DC:
pop {r4-r6}
pop {r1}
bx r1
thumb_func_end mevent_srv_ish_do_exec
thumb_func_start mevent_srv_ish_inc_flag
mevent_srv_ish_inc_flag: @ 801D4E4
ldr r0, =s_mevent_srv_ish_ptr
ldr r1, [r0]
ldr r0, [r1, 0xC]
adds r0, 0x1
str r0, [r1, 0xC]
bx lr
.pool
thumb_func_end mevent_srv_ish_inc_flag
thumb_func_start mevent_srv_ish_get_buffer
mevent_srv_ish_get_buffer: @ 801D4F4
ldr r0, =s_mevent_srv_ish_ptr
ldr r0, [r0]
ldr r0, [r0, 0x20]
bx lr
.pool
thumb_func_end mevent_srv_ish_get_buffer
thumb_func_start mevent_srv_ish_set_param
mevent_srv_ish_set_param: @ 801D500
ldr r1, =s_mevent_srv_ish_ptr
ldr r1, [r1]
str r0, [r1, 0x4]
bx lr
.pool
thumb_func_end mevent_srv_ish_set_param
thumb_func_start mevent_srv_ish_init
mevent_srv_ish_init: @ 801D50C
push {r4-r6,lr}
mov r6, r8
push {r6}
adds r4, r0, 0
adds r6, r1, 0
mov r8, r2
movs r0, 0
str r0, [r4]
str r0, [r4, 0x8]
str r0, [r4, 0xC]
movs r5, 0x80
lsls r5, 3
adds r0, r5, 0
bl AllocZeroed
str r0, [r4, 0x14]
adds r0, r5, 0
bl AllocZeroed
str r0, [r4, 0x18]
adds r0, r5, 0
bl AllocZeroed
str r0, [r4, 0x1C]
movs r0, 0x40
bl AllocZeroed
str r0, [r4, 0x20]
adds r4, 0x24
adds r0, r4, 0
adds r1, r6, 0
mov r2, r8
bl mevent_srv_sub_init
pop {r3}
mov r8, r3
pop {r4-r6}
pop {r0}
bx r0
thumb_func_end mevent_srv_ish_init
thumb_func_start mevent_srv_ish_free_resources
mevent_srv_ish_free_resources: @ 801D55C
push {r4,lr}
adds r4, r0, 0
ldr r0, [r4, 0x14]
bl Free
ldr r0, [r4, 0x18]
bl Free
ldr r0, [r4, 0x1C]
bl Free
ldr r0, [r4, 0x20]
bl Free
pop {r4}
pop {r0}
bx r0
thumb_func_end mevent_srv_ish_free_resources
thumb_func_start mevent_srv_ish_jmp_buffer
mevent_srv_ish_jmp_buffer: @ 801D580
push {r4,lr}
adds r4, r0, 0
ldr r0, [r4, 0x1C]
ldr r1, [r4, 0x18]
movs r2, 0x80
lsls r2, 3
bl memcpy
movs r0, 0
str r0, [r4, 0x10]
pop {r4}
pop {r0}
bx r0
thumb_func_end mevent_srv_ish_jmp_buffer
thumb_func_start sub_801D59C
sub_801D59C: @ 801D59C
push {r4-r6,lr}
sub sp, 0x4
adds r4, r0, 0
adds r6, r1, 0
adds r5, r2, 0
movs r0, 0
str r0, [sp]
ldr r1, [r4, 0x14]
ldr r2, =0x05000100
mov r0, sp
bl CpuSet
ldr r2, [r4, 0x14]
str r5, [r2]
adds r4, 0x24
adds r0, r4, 0
adds r1, r6, 0
movs r3, 0x4
bl mevent_srv_sub_init_send
add sp, 0x4
pop {r4-r6}
pop {r0}
bx r0
.pool
thumb_func_end sub_801D59C
thumb_func_start sub_801D5D0
sub_801D5D0: @ 801D5D0
push {r4,lr}
adds r4, r0, 0
ldr r0, [r4, 0x1C]
ldr r1, =gUnknown_082F2598
movs r2, 0x80
lsls r2, 3
bl memcpy
movs r1, 0
str r1, [r4, 0x10]
movs r0, 0x4
str r0, [r4, 0x8]
str r1, [r4, 0xC]
movs r0, 0
pop {r4}
pop {r1}
bx r1
.pool
thumb_func_end sub_801D5D0
thumb_func_start sub_801D5F8
sub_801D5F8: @ 801D5F8
movs r0, 0x6
bx lr
thumb_func_end sub_801D5F8
thumb_func_start sub_801D5FC
sub_801D5FC: @ 801D5FC
push {r4,lr}
adds r4, r0, 0
adds r0, 0x24
bl mevent_srv_sub_recv
cmp r0, 0
beq _0801D612
movs r0, 0x4
str r0, [r4, 0x8]
movs r0, 0
str r0, [r4, 0xC]
_0801D612:
movs r0, 0x1
pop {r4}
pop {r1}
bx r1
thumb_func_end sub_801D5FC
thumb_func_start sub_801D61C
sub_801D61C: @ 801D61C
push {r4,lr}
adds r4, r0, 0
adds r0, 0x24
bl mevent_srv_sub_send
cmp r0, 0
beq _0801D632
movs r0, 0x4
str r0, [r4, 0x8]
movs r0, 0
str r0, [r4, 0xC]
_0801D632:
movs r0, 0x1
pop {r4}
pop {r1}
bx r1
thumb_func_end sub_801D61C
thumb_func_start sub_801D63C
sub_801D63C: @ 801D63C
push {r4,lr}
adds r4, r0, 0
ldr r0, [r4, 0x10]
lsls r2, r0, 3
ldr r1, [r4, 0x1C]
adds r2, r1, r2
adds r0, 0x1
str r0, [r4, 0x10]
ldr r0, [r2]
cmp r0, 0x15
bls _0801D654
b _0801D804
_0801D654:
lsls r0, 2
ldr r1, =_0801D664
adds r0, r1
ldr r0, [r0]
mov pc, r0
.pool
.align 2, 0
_0801D664:
.4byte _0801D804
.4byte _0801D6BC
.4byte _0801D6C4
.4byte _0801D6D4
.4byte _0801D70E
.4byte _0801D716
.4byte _0801D6FE
.4byte _0801D708
.4byte _0801D764
.4byte _0801D790
.4byte _0801D788
.4byte _0801D72C
.4byte _0801D742
.4byte _0801D758
.4byte _0801D77C
.4byte _0801D7B8
.4byte _0801D7BC
.4byte _0801D7C4
.4byte _0801D7D0
.4byte _0801D6EA
.4byte _0801D6D8
.4byte _0801D7F0
_0801D6BC:
ldr r0, [r2, 0x4]
str r0, [r4, 0x4]
movs r0, 0x1
b _0801D7FE
_0801D6C4:
adds r0, r4, 0
adds r0, 0x24
ldr r1, [r2, 0x4]
ldr r2, [r4, 0x18]
bl mevent_srv_sub_init_recv
movs r0, 0x2
b _0801D7FE
_0801D6D4:
movs r0, 0x3
b _0801D7FE
_0801D6D8:
adds r0, r4, 0
adds r0, 0x24
ldr r2, [r4, 0x14]
movs r1, 0x14
movs r3, 0
bl mevent_srv_sub_init_send
movs r0, 0x3
b _0801D7FE
_0801D6EA:
ldrb r0, [r2, 0x4]
bl GetGameStat
adds r2, r0, 0
adds r0, r4, 0
movs r1, 0x12
bl sub_801D59C
movs r0, 0x3
b _0801D7FE
_0801D6FE:
ldr r0, [r4, 0x4]
cmp r0, 0
beq _0801D706
b _0801D804
_0801D706:
b _0801D70E
_0801D708:
ldr r0, [r4, 0x4]
cmp r0, 0x1
bne _0801D804
_0801D70E:
adds r0, r4, 0
bl mevent_srv_ish_jmp_buffer
b _0801D804
_0801D716:
ldr r0, [r4, 0x20]
ldr r1, [r4, 0x18]
movs r2, 0x40
bl memcpy
movs r0, 0x5
str r0, [r4, 0x8]
movs r0, 0
str r0, [r4, 0xC]
movs r0, 0x2
b _0801D806
_0801D72C:
ldr r0, [r4, 0x20]
ldr r1, [r4, 0x18]
movs r2, 0x40
bl memcpy
movs r0, 0x5
str r0, [r4, 0x8]
movs r0, 0
str r0, [r4, 0xC]
movs r0, 0x3
b _0801D806
_0801D742:
ldr r0, [r4, 0x20]
ldr r1, [r4, 0x18]
movs r2, 0x40
bl memcpy
movs r0, 0x5
str r0, [r4, 0x8]
movs r0, 0
str r0, [r4, 0xC]
movs r0, 0x5
b _0801D806
_0801D758:
movs r0, 0x5
str r0, [r4, 0x8]
movs r0, 0
str r0, [r4, 0xC]
movs r0, 0x4
b _0801D806
_0801D764:
ldr r0, [r4, 0x14]
ldr r1, [r4, 0x4C]
bl sub_801B580
adds r0, r4, 0
adds r0, 0x24
ldr r2, [r4, 0x14]
movs r1, 0x11
movs r3, 0x64
bl mevent_srv_sub_init_send
b _0801D804
_0801D77C:
ldr r2, [r4, 0x4]
adds r0, r4, 0
movs r1, 0x13
bl sub_801D59C
b _0801D804
_0801D788:
ldr r0, [r4, 0x18]
bl sub_801B21C
b _0801D804
_0801D790:
ldr r0, [r4, 0x18]
bl sub_801B1A4
cmp r0, 0
bne _0801D7AC
ldr r0, [r4, 0x18]
bl sub_801B078
adds r0, r4, 0
movs r1, 0x13
movs r2, 0
bl sub_801D59C
b _0801D804
_0801D7AC:
adds r0, r4, 0
movs r1, 0x13
movs r2, 0x1
bl sub_801D59C
b _0801D804
_0801D7B8:
movs r0, 0x6
b _0801D7FE
_0801D7BC:
ldr r0, [r4, 0x18]
bl sub_801B508
b _0801D804
_0801D7C4:
ldr r0, [r4, 0x18]
movs r1, 0xFA
lsls r1, 2
bl sub_80992A0
b _0801D804
_0801D7D0:
ldr r0, =gSaveBlock2Ptr
ldr r0, [r0]
ldr r1, =0x00000bec
adds r0, r1
ldr r1, [r4, 0x18]
movs r2, 0xBC
bl memcpy
bl ValidateEReaderTrainer
b _0801D804
.pool
_0801D7F0:
ldr r0, =gDecompressionBuffer
ldr r1, [r4, 0x18]
movs r2, 0x80
lsls r2, 3
bl memcpy
movs r0, 0x7
_0801D7FE:
str r0, [r4, 0x8]
movs r0, 0
str r0, [r4, 0xC]
_0801D804:
movs r0, 0x1
_0801D806:
pop {r4}
pop {r1}
bx r1
.pool
thumb_func_end sub_801D63C
thumb_func_start sub_801D810
sub_801D810: @ 801D810
push {lr}
adds r1, r0, 0
ldr r0, [r1, 0xC]
cmp r0, 0
beq _0801D822
movs r0, 0x4
str r0, [r1, 0x8]
movs r0, 0
str r0, [r1, 0xC]
_0801D822:
movs r0, 0x1
pop {r1}
bx r1
thumb_func_end sub_801D810
thumb_func_start sub_801D828
sub_801D828: @ 801D828
push {r4,lr}
adds r4, r0, 0
ldr r0, [r4, 0xC]
cmp r0, 0
beq _0801D838
cmp r0, 0x1
beq _0801D846
b _0801D858
_0801D838:
ldr r0, [r4, 0x18]
bl sub_8153870
ldr r0, [r4, 0xC]
adds r0, 0x1
str r0, [r4, 0xC]
b _0801D858
_0801D846:
adds r0, r4, 0x4
bl sub_8153884
adds r1, r0, 0
cmp r1, 0
bne _0801D858
movs r0, 0x4
str r0, [r4, 0x8]
str r1, [r4, 0xC]
_0801D858:
movs r0, 0x1
pop {r4}
pop {r1}
bx r1
thumb_func_end sub_801D828
thumb_func_start sub_801D860
sub_801D860: @ 801D860
push {r4,lr}
adds r4, r0, 0
ldr r3, =gDecompressionBuffer
adds r0, r4, 0x4
ldr r1, =gSaveBlock2Ptr
ldr r1, [r1]
ldr r2, =gSaveBlock1Ptr
ldr r2, [r2]
bl _call_via_r3
cmp r0, 0x1
bne _0801D880
movs r0, 0x4
str r0, [r4, 0x8]
movs r0, 0
str r0, [r4, 0xC]
_0801D880:
movs r0, 0x1
pop {r4}
pop {r1}
bx r1
.pool
thumb_func_end sub_801D860
thumb_func_start mevent_srv_ish_exec
mevent_srv_ish_exec: @ 801D894
push {r4,r5,lr}
sub sp, 0x20
mov r2, sp
ldr r1, =gUnknown_082F255C
ldm r1!, {r3-r5}
stm r2!, {r3-r5}
ldm r1!, {r3-r5}
stm r2!, {r3-r5}
ldm r1!, {r3,r4}
stm r2!, {r3,r4}
ldr r1, [r0, 0x8]
lsls r1, 2
add r1, sp
ldr r1, [r1]
bl _call_via_r1
add sp, 0x20
pop {r4,r5}
pop {r1}
bx r1
.pool
thumb_func_end mevent_srv_ish_exec
.align 2, 0 @ don't pad with nop

View File

@ -3,17 +3,6 @@
.section .rodata
.align 2
gUnknown_082F255C:: @ 82F255C
.4byte sub_801D5D0
.4byte sub_801D5F8
.4byte sub_801D5FC
.4byte sub_801D61C
.4byte sub_801D63C
.4byte sub_801D810
.4byte sub_801D828
.4byte sub_801D860
.align 2
gText_CanceledReadingCard:: @ 82F257C
.string "Canceled reading\nthe Card.$"

View File

@ -1,53 +1,7 @@
#ifndef GUARD_MEVENT_SERVER_H
#define GUARD_MEVENT_SERVER_H
#define ME_SEND_BUF_SIZE 0x400
struct mevent_srv_sub
{
s32 seqno;
u8 sendPlayerNo;
u8 recvPlayerNo;
u16 recvIdent;
u16 recvCounter;
u16 recvCRC;
u16 recvSize;
u16 sendIdent;
u16 sendCounter;
u16 sendCRC;
u16 sendSize;
void * recvBfr;
const void * sendBfr;
u32 (*recvFunc)(struct mevent_srv_sub *);
u32 (*sendFunc)(struct mevent_srv_sub *);
};
struct send_recv_header
{
u16 ident;
u16 crc;
u16 size;
};
struct mevent_cmd_ish
{
u32 instr;
u32 parameter;
};
struct mevent_srv_ish
{
u32 unk_00;
u32 param;
u32 mainseqno;
u32 flag;
u32 cmdidx;
void * sendBuffer;
void * recvBuffer;
struct mevent_cmd_ish * cmdBuffer;
void * buffer;
struct mevent_srv_sub manager;
};
#include "mevent_server_helpers.h"
struct mevent_cmd
{

View File

@ -1,6 +1,34 @@
#ifndef GUARD_MEVENT_SERVER_HELPERS_H
#define GUARD_MEVENT_SERVER_HELPERS_H
#define ME_SEND_BUF_SIZE 0x400
struct mevent_srv_sub
{
s32 seqno;
u8 sendPlayerNo;
u8 recvPlayerNo;
u16 recvIdent;
u16 recvCounter;
u16 recvCRC;
u16 recvSize;
u16 sendIdent;
u16 sendCounter;
u16 sendCRC;
u16 sendSize;
void * recvBfr;
const void * sendBfr;
u32 (*recvFunc)(struct mevent_srv_sub *);
u32 (*sendFunc)(struct mevent_srv_sub *);
};
struct send_recv_header
{
u16 ident;
u16 crc;
u16 size;
};
void mevent_srv_sub_init(struct mevent_srv_sub *, u32, u32);
void mevent_srv_sub_init_send(struct mevent_srv_sub * manager, u32 ident, const void * src, u32 size);
bool32 mevent_srv_sub_recv(struct mevent_srv_sub * manager);

View File

@ -1,6 +1,29 @@
#ifndef GUARD_MEVENT_SERVER_ISH_H
#define GUARD_MEVENT_SERVER_ISH_H
#include "mevent_server_helpers.h"
struct mevent_cmd_ish
{
u32 instr;
u32 parameter;
};
struct mevent_srv_ish
{
u32 unk_00;
u32 param;
u32 mainseqno;
u32 flag;
u32 cmdidx;
void * sendBuffer;
void * recvBuffer;
struct mevent_cmd_ish * cmdBuffer;
void * buffer;
struct mevent_srv_sub manager;
u32 unk_4C;
};
void mevent_srv_ish_do_init(u32 arg);
u32 mevent_srv_ish_do_exec(u16 * a0);
void mevent_srv_ish_inc_flag(void);

View File

@ -62,7 +62,6 @@ SECTIONS {
src/mevent_801BAAC.o(.text);
src/mevent_server.o(.text);
src/mevent_server_ish.o(.text);
asm/mevent_server_ish.o(.text);
asm/mevent_server_helpers.o(.text);
src/mevent_news.o(.text);
src/union_room_chat.o(.text);

View File

@ -1,7 +1,293 @@
#include "global.h"
#include "alloc.h"
#include "decompress.h"
#include "overworld.h"
#include "script.h"
#include "battle_tower.h"
#include "mevent.h"
#include "mevent_server.h"
#include "mevent_server_helpers.h"
#include "mystery_event_script.h"
#include "mevent_server_ish.h"
EWRAM_DATA struct mevent_srv_ish * s_mevent_srv_ish_ptr = NULL;
static void mevent_srv_ish_init(struct mevent_srv_ish *, u32, u32);
static u32 mevent_srv_ish_exec(struct mevent_srv_ish *);
static void mevent_srv_ish_free_resources(struct mevent_srv_ish *);
extern const u8 gUnknown_082F2598[];
extern const struct mevent_cmd gUnknown_8468B6C[];
extern const struct mevent_cmd gUnknown_8468BCC[];
void mevent_srv_ish_do_init(u32 arg)
{
s_mevent_srv_ish_ptr = AllocZeroed(sizeof(struct mevent_srv_ish));
mevent_srv_ish_init(s_mevent_srv_ish_ptr, 1, 0);
s_mevent_srv_ish_ptr->unk_4C = arg;
}
u32 mevent_srv_ish_do_exec(u16 * a0)
{
u32 result;
if (s_mevent_srv_ish_ptr == NULL)
return 6;
result = mevent_srv_ish_exec(s_mevent_srv_ish_ptr);
if (result == 6)
{
*a0 = s_mevent_srv_ish_ptr->param;
mevent_srv_ish_free_resources(s_mevent_srv_ish_ptr);
Free(s_mevent_srv_ish_ptr);
s_mevent_srv_ish_ptr = NULL;
}
return result;
}
void mevent_srv_ish_inc_flag(void)
{
s_mevent_srv_ish_ptr->flag++;
}
void * mevent_srv_ish_get_buffer(void)
{
return s_mevent_srv_ish_ptr->buffer;
}
void mevent_srv_ish_set_param(u32 a0)
{
s_mevent_srv_ish_ptr->param = a0;
}
static void mevent_srv_ish_init(struct mevent_srv_ish * svr, u32 sendPlayerNo, u32 recvPlayerNo)
{
svr->unk_00 = 0;
svr->mainseqno = 0;
svr->flag = 0;
svr->sendBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->recvBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->cmdBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->buffer = AllocZeroed(0x40);
mevent_srv_sub_init(&svr->manager, sendPlayerNo, recvPlayerNo);
}
static void mevent_srv_ish_free_resources(struct mevent_srv_ish * svr)
{
Free(svr->sendBuffer);
Free(svr->recvBuffer);
Free(svr->cmdBuffer);
Free(svr->buffer);
}
static void mevent_srv_ish_jmp_buffer(struct mevent_srv_ish * svr)
{
memcpy(svr->cmdBuffer, svr->recvBuffer, ME_SEND_BUF_SIZE);
svr->cmdidx = 0;
}
static void mevent_srv_ish_send_word(struct mevent_srv_ish * svr, u32 ident, u32 word)
{
CpuFill32(0, svr->sendBuffer, ME_SEND_BUF_SIZE);
*(u32 *)svr->sendBuffer = word;
mevent_srv_sub_init_send(&svr->manager, ident, svr->sendBuffer, sizeof(u32));
}
static u32 ish_mainseq_0(struct mevent_srv_ish * svr)
{
// init
memcpy(svr->cmdBuffer, gUnknown_082F2598, ME_SEND_BUF_SIZE);
svr->cmdidx = 0;
svr->mainseqno = 4;
svr->flag = 0;
return 0;
}
static u32 ish_mainseq_1(struct mevent_srv_ish * svr)
{
// done
return 6;
}
static u32 ish_mainseq_2(struct mevent_srv_ish * svr)
{
// do recv
if (mevent_srv_sub_recv(&svr->manager))
{
svr->mainseqno = 4;
svr->flag = 0;
}
return 1;
}
static u32 ish_mainseq_3(struct mevent_srv_ish * svr)
{
// do send
if (mevent_srv_sub_send(&svr->manager))
{
svr->mainseqno = 4;
svr->flag = 0;
}
return 1;
}
static u32 ish_mainseq_4(struct mevent_srv_ish * svr)
{
// process command
struct mevent_cmd_ish * cmd = &svr->cmdBuffer[svr->cmdidx];
++svr->cmdidx;
switch (cmd->instr)
{
case 0:
break;
case 1:
svr->param = cmd->parameter;
svr->mainseqno = 1;
svr->flag = 0;
break;
case 2:
mevent_srv_sub_init_recv(&svr->manager, cmd->parameter, svr->recvBuffer);
svr->mainseqno = 2;
svr->flag = 0;
break;
case 3:
svr->mainseqno = 3;
svr->flag = 0;
break;
case 20:
mevent_srv_sub_init_send(&svr->manager, 0x14, svr->sendBuffer, 0);
svr->mainseqno = 3;
svr->flag = 0;
break;
case 19:
mevent_srv_ish_send_word(svr, 0x12, GetGameStat(cmd->parameter));
svr->mainseqno = 3;
svr->flag = 0;
break;
case 6:
if (svr->param == 0)
mevent_srv_ish_jmp_buffer(svr);
break;
case 7:
if (svr->param == 1)
mevent_srv_ish_jmp_buffer(svr);
break;
case 4:
mevent_srv_ish_jmp_buffer(svr);
break;
case 5:
memcpy(svr->buffer, svr->recvBuffer, 0x40);
svr->mainseqno = 5;
svr->flag = 0;
return 2;
case 11:
memcpy(svr->buffer, svr->recvBuffer, 0x40);
svr->mainseqno = 5;
svr->flag = 0;
return 3;
case 12:
memcpy(svr->buffer, svr->recvBuffer, 0x40);
svr->mainseqno = 5;
svr->flag = 0;
return 5;
case 13:
svr->mainseqno = 5;
svr->flag = 0;
return 4;
case 8:
sub_801B580(svr->sendBuffer, svr->unk_4C);
mevent_srv_sub_init_send(&svr->manager, 0x11, svr->sendBuffer, sizeof(struct MEventStruct_Unk1442CC));
break;
case 14:
mevent_srv_ish_send_word(svr, 0x13, svr->param);
break;
case 10:
sub_801B21C(svr->recvBuffer);
break;
case 9:
if (!sub_801B1A4(svr->recvBuffer))
{
sub_801B078(svr->recvBuffer);
mevent_srv_ish_send_word(svr, 0x13, 0);
}
else
mevent_srv_ish_send_word(svr, 0x13, 1);
break;
case 15:
svr->mainseqno = 6;
svr->flag = 0;
break;
case 16:
sub_801B508(svr->recvBuffer);
break;
case 17:
sub_80992A0(svr->recvBuffer, 1000);
break;
case 18:
memcpy(&gSaveBlock2Ptr->frontier.ereaderTrainer, svr->recvBuffer, 0xbc);
ValidateEReaderTrainer();
break;
case 21:
memcpy(gDecompressionBuffer, svr->recvBuffer, ME_SEND_BUF_SIZE);
svr->mainseqno = 7;
svr->flag = 0;
break;
}
return 1;
}
static u32 ish_mainseq_5(struct mevent_srv_ish * svr)
{
// wait flag
if (svr->flag)
{
svr->mainseqno = 4;
svr->flag = 0;
}
return 1;
}
static u32 ish_mainseq_6(struct mevent_srv_ish * svr)
{
// ???
switch (svr->flag)
{
case 0:
sub_8153870(svr->recvBuffer);
++svr->flag;
break;
case 1:
if (!sub_8153884(&svr->param))
{
svr->mainseqno = 4;
svr->flag = 0;
}
break;
}
return 1;
}
static u32 ish_mainseq_7(struct mevent_srv_ish * svr)
{
// exec arbitrary code
u32 (*func)(u32 *, struct SaveBlock2 *, struct SaveBlock1 *) = (void *)gDecompressionBuffer;
if (func(&svr->param, gSaveBlock2Ptr, gSaveBlock1Ptr) == 1)
{
svr->mainseqno = 4;
svr->flag = 0;
}
return 1;
}
static u32 mevent_srv_ish_exec(struct mevent_srv_ish * svr)
{
u32 (*funcs[])(struct mevent_srv_ish *) = {
ish_mainseq_0,
ish_mainseq_1,
ish_mainseq_2,
ish_mainseq_3,
ish_mainseq_4,
ish_mainseq_5,
ish_mainseq_6,
ish_mainseq_7
};
return funcs[svr->mainseqno](svr);
}