Finish decompiling ereader.c

This commit is contained in:
Marcus Huderle 2019-03-22 13:36:06 -05:00
parent 7118462b9f
commit f4f666f5af
14 changed files with 914 additions and 2202 deletions

File diff suppressed because it is too large Load Diff

View File

@ -47,7 +47,7 @@ gUnknown_08625B6C:: @ 8625B6C
.byte 0xa5, 0x94, 0x52, 0x0a, 0x96, 0x00, 0x00, 0x00, 0x5b, 0x72, 0x6a, 0x91, 0xae, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7a, 0x01, 0x8d, 0x00, 0x5e, 0x00, 0xf7, 0x00, 0x55, 0x00, 0x05, 0x01
.byte 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x10, 0xa5, 0x94, 0x52, 0x0a, 0x96, 0x00, 0x00, 0x00, 0x8d, 0x85, 0x9e, 0xa0, 0x60, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
gUnknown_0862608C:: @ 862608C
gFarawayIslandRockCoords:: @ 862608C
.2byte 21, 16
.2byte 25, 16
.2byte 16, 17

View File

@ -38,7 +38,7 @@ FarawayIsland_Interior_EventScript_267D5E:: @ 8267D5E
return
FarawayIsland_Interior_MapScript1_267D72: @ 8267D72
setvar VAR_NEVER_READ_0x403A, 0
setvar VAR_FARAWAY_ISLAND_STEP_COUNTER, 0
setvar VAR_TEMP_1, 1
call_if_unset FLAG_CAUGHT_MEW, FarawayIsland_Interior_EventScript_267D86
end

View File

@ -74,7 +74,7 @@
#define VAR_UNUSUAL_WEATHER_LOCATION 0x4037
#define VAR_UNUSUAL_WEATHER_STEP_COUNTER 0x4038
#define VAR_SHOULD_END_UNUSUAL_WEATHER 0x4039
#define VAR_NEVER_READ_0x403A 0x403A // Var is written to, but never checked
#define VAR_FARAWAY_ISLAND_STEP_COUNTER 0x403A
#define VAR_REGICE_STEPS_1 0x403B
#define VAR_REGICE_STEPS_2 0x403C
#define VAR_REGICE_STEPS_3 0x403D

View File

@ -4,6 +4,8 @@
bool32 sub_81D3B34(void);
u32 sub_81D427C(void);
bool8 sub_81D4A58(struct EventObject*);
void UpdateFarawayIslandStepCounter(void);
bool8 EventObjectIsFarawayIslandMew(struct EventObject *);
bool8 IsMewPlayingHideAndSeek(void);
#endif // GUARD_EREADER_H

View File

@ -230,7 +230,6 @@ bool8 IsLinkMaster(void);
void CB2_LinkError(void);
u8 GetSioMultiSI(void);
bool8 IsLinkConnectionEstablished(void);
void SetSuppressLinkErrorMessage(bool8);
bool8 HasLinkErrorOccurred(void);
void ResetSerial(void);
u32 LinkMain1(u8 *shouldAdvanceLinkState, u16 *sendCmd, u16 (*recvCmds)[CMD_LENGTH]);

View File

@ -3,7 +3,6 @@
#include "list_menu.h"
bool8 sub_81D312C(void *arg0);
void sub_81D4998(void);
void CB2_InitPokeNav(void);
#endif //GUARD_POKENAV_H

View File

@ -20,4 +20,8 @@ bool32 sub_802C908(u16);
void nullsub_89(u8 taskId);
void var_800D_set_xB(void);
bool32 mevent_0814257C(u8 *textState, const u8 *str);
void sub_8018884(const u8 *src);
void sub_80186A4(void);
#endif //GUARD_rom_8011DC0_H

View File

@ -2563,4 +2563,24 @@ extern const u8 gUnknown_0862BAC4[];
extern const u8 gUnknown_0862BACF[];
extern const u8 gUnknown_0862BADA[];
// E-Reader
extern const u8 gUnknown_085EDFD6[];
extern const u8 gUnknown_085EDFF5[];
extern const u8 gUnknown_085EE014[];
extern const u8 gUnknown_085EE035[];
extern const u8 gUnknown_085EE05C[];
extern const u8 gUnknown_085EE06B[];
extern const u8 gUnknown_085EE080[];
extern const u8 gUnknown_085EE097[];
extern const u8 gUnknown_085EE0A3[];
extern const u8 gUnknown_085EE0BF[];
extern const u8 gUnknown_085EE0DC[];
extern const u8 gUnknown_085EE0FA[];
extern const u8 gUnknown_085EE107[];
extern const u8 gUnknown_085EE120[];
extern const u8 gUnknown_085EE12D[];
extern const u8 gUnknown_085EE14B[];
extern const u8 gUnknown_085EE14F[];
extern const u8 gUnknown_085EE154[];
#endif // GUARD_STRINGS_H

View File

@ -292,7 +292,6 @@ SECTIONS {
src/menu_specialized.o(.text);
asm/menu_specialized.o(.text);
src/ereader.o(.text);
asm/ereader.o(.text);
src/trainer_hill.o(.text);
src/rayquaza_scene.o(.text);
src/walda_phrase.o(.text);

1
porymap.project.cfg Executable file
View File

@ -0,0 +1 @@
base_game_version=pokeemerald

View File

@ -1,9 +1,26 @@
#include "global.h"
#include "alloc.h"
#include "decompress.h"
#include "event_data.h"
#include "event_object_movement.h"
#include "field_weather.h"
#include "fieldmap.h"
#include "link.h"
#include "main.h"
#include "metatile_behavior.h"
#include "rom_8011DC0.h"
#include "save.h"
#include "sound.h"
#include "sprite.h"
#include "task.h"
#include "strings.h"
#include "util.h"
#include "constants/event_objects.h"
#include "constants/flags.h"
#include "constants/maps.h"
#include "constants/metatile_behaviors.h"
#include "constants/songs.h"
#include "constants/vars.h"
struct Unk81D38FC
{
@ -20,6 +37,29 @@ struct Unknown030012C8
int unk14;
};
struct Unk03006370
{
u16 unk0;
u32 unk4;
u32 *unk8;
};
struct Unk81D5014
{
u16 unk0;
u16 unk2;
u16 unk4;
u16 unk6;
u8 unk8;
u8 unk9;
u8 unkA;
u8 unkB;
u8 unkC;
u8 unkD;
u8 unkE;
u8 *unk10;
};
void sub_81D41A0(void);
static void sub_81D4170(void);
int sub_81D3D70(u8, u32, u32*, u32*);
@ -29,6 +69,14 @@ static void sub_81D413C(void);
static void sub_81D414C(void);
static void sub_81D3F1C(u32, u32*, u32*);
static void sub_81D3F68(void);
bool8 sub_81D4834(s16, s16);
static bool8 sub_81D4C14(struct EventObject*, u8);
static u8 sub_81D4C9C(struct EventObject*, u8);
static u8 sub_81D4C58(struct EventObject*, u8);
static u8 sub_81D4CE0(struct EventObject*, u8);
static u8 sub_81D4D24(u8);
static u8 sub_81D4890(u8);
void sub_81D5084(u8);
extern struct Unknown030012C8 gUnknown_030012C8;
extern u16 gUnknown_030012E0;
@ -41,8 +89,19 @@ extern u16 gUnknown_030012EE;
extern u16 gUnknown_030012F0;
extern u16 gUnknown_030012F2;
extern u16 gUnknown_030012F4;
extern s16 gUnknown_030012F8;
extern s16 gUnknown_030012FA;
extern u8 gUnknown_030012FC[4];
extern u8 gUnknown_0203CF50;
extern struct Unk03006370 gUnknown_03006370;
extern const u8 gUnknown_08625B6C[];
extern const u8 gUnknown_089A3470[];
extern const u8 gMultiBootProgram_BerryGlitchFix_Start[];
extern const s16 gFarawayIslandRockCoords[4][2];
extern const struct SpritePalette gFieldEffectObjectPaletteInfo1;
extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[];
static u8 sub_81D38D4(void)
{
@ -562,3 +621,825 @@ u8 sub_81D4258(void)
TryGetEventObjectIdByLocalIdAndMap(1, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &eventObjectId);
return eventObjectId;
}
u32 sub_81D427C(void)
{
u8 i;
int skip;
struct EventObject *mew = &gEventObjects[sub_81D4258()];
gUnknown_030012F8 = gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x - mew->currentCoords.x;
gUnknown_030012FA = gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y - mew->currentCoords.y;
for (i = 0; i < ARRAY_COUNT(gUnknown_030012FC); i++)
gUnknown_030012FC[i] = DIR_NONE;
if (gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x == gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.x
&& gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y == gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.y)
{
return DIR_NONE;
}
if (VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % 8 == 0)
mew->invisible = 0;
else
mew->invisible = 1;
if (VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % 9 == 0)
return DIR_NONE;
for (i = 0; i < ARRAY_COUNT(gFarawayIslandRockCoords); i++)
{
if (gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x == gFarawayIslandRockCoords[i][0])
{
skip = 0;
if (gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y < gFarawayIslandRockCoords[i][1])
{
if (mew->currentCoords.y <= gFarawayIslandRockCoords[i][1])
skip = 1;
}
else
{
if (mew->currentCoords.y >= gFarawayIslandRockCoords[i][1])
skip = 1;
}
if (!skip)
{
if (gUnknown_030012F8 > 0)
{
if (mew->currentCoords.x + 1 == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x)
{
if (sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y))
return DIR_EAST;
}
}
else if (gUnknown_030012F8 < 0)
{
if (mew->currentCoords.x - 1 == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x)
{
if (sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y))
return DIR_WEST;
}
}
if (mew->currentCoords.x == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x)
{
if (gUnknown_030012FA > 0)
{
if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1))
return DIR_NORTH;
}
else
{
if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1))
return DIR_SOUTH;
}
}
}
}
if (gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y == gFarawayIslandRockCoords[i][1])
{
skip = 0;
if (gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x < gFarawayIslandRockCoords[i][0])
{
if (mew->currentCoords.x <= gFarawayIslandRockCoords[i][0])
skip = 1;
}
else
{
if (mew->currentCoords.x >= gFarawayIslandRockCoords[i][0])
skip = 1;
}
if (!skip)
{
if (gUnknown_030012FA > 0)
{
if (mew->currentCoords.y + 1 == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y)
{
if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1))
return DIR_SOUTH;
}
}
else if (gUnknown_030012FA < 0)
{
if (mew->currentCoords.y - 1 == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y)
{
if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1))
return DIR_NORTH;
}
}
if (mew->currentCoords.y == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y)
{
if (gUnknown_030012F8 > 0)
{
if (sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y))
return DIR_WEST;
}
else
{
if (sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y))
return DIR_EAST;
}
}
}
}
}
if (sub_81D4C14(mew, 0))
{
if (sub_81D4C58(mew, 1))
return sub_81D4D24(2);
else if (sub_81D4CE0(mew, 1))
return sub_81D4D24(2);
else
return DIR_NORTH;
}
if (sub_81D4C9C(mew, 0))
{
if (sub_81D4C58(mew, 1))
return sub_81D4D24(2);
else if (sub_81D4CE0(mew, 1))
return sub_81D4D24(2);
else
return DIR_SOUTH;
}
if (sub_81D4C58(mew, 0))
{
if (sub_81D4C14(mew, 1))
return sub_81D4D24(2);
else if (sub_81D4C9C(mew, 1))
return sub_81D4D24(2);
else
return DIR_EAST;
}
if (sub_81D4CE0(mew, 0))
{
if (sub_81D4C14(mew, 1))
return sub_81D4D24(2);
else if (sub_81D4C9C(mew, 1))
return sub_81D4D24(2);
else
return DIR_WEST;
}
if (gUnknown_030012FA == 0)
{
if (gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.y > mew->currentCoords.y)
{
if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1))
return DIR_NORTH;
}
if (gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.y < mew->currentCoords.y)
{
if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1))
return DIR_SOUTH;
}
if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1))
return DIR_NORTH;
if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1))
return DIR_SOUTH;
}
if (gUnknown_030012F8 == 0)
{
if (gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.x > mew->currentCoords.x)
{
if (sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y))
return DIR_WEST;
}
if (gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.x < mew->currentCoords.x)
{
if (sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y))
return DIR_EAST;
}
if (sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y))
return DIR_EAST;
if (sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y))
return DIR_WEST;
}
return sub_81D4890(DIR_NONE);
}
bool8 sub_81D4834(s16 x, s16 y)
{
if (gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.x == x
&& gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.y == y)
{
return FALSE;
}
return MetatileBehavior_IsPokeGrass(MapGridGetMetatileBehaviorAt(x, y));
}
static u8 sub_81D4890(u8 ignoredDir)
{
u8 i;
u8 count = 0;
struct EventObject *mew = &gEventObjects[sub_81D4258()];
for (i = 0; i < ARRAY_COUNT(gUnknown_030012FC); i++)
gUnknown_030012FC[i] = DIR_NONE;
if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1) == TRUE && ignoredDir != DIR_NORTH)
{
gUnknown_030012FC[count] = DIR_NORTH;
count++;
}
if (sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_EAST)
{
gUnknown_030012FC[count] = DIR_EAST;
count++;
}
if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1) == TRUE && ignoredDir != DIR_SOUTH)
{
gUnknown_030012FC[count] = DIR_SOUTH;
count++;
}
if (sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_WEST)
{
gUnknown_030012FC[count] = DIR_WEST;
count++;
}
if (count > 1)
return gUnknown_030012FC[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % count];
else
return gUnknown_030012FC[0];
}
void UpdateFarawayIslandStepCounter(void)
{
u16 steps = VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER);
if (gSaveBlock1Ptr->location.mapNum == MAP_NUM(FARAWAY_ISLAND_INTERIOR)
&& gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(FARAWAY_ISLAND_INTERIOR))
{
steps++;
if (steps >= 9999)
VarSet(VAR_FARAWAY_ISLAND_STEP_COUNTER, 0);
else
VarSet(VAR_FARAWAY_ISLAND_STEP_COUNTER, steps);
}
}
bool8 EventObjectIsFarawayIslandMew(struct EventObject *eventObject)
{
if (gSaveBlock1Ptr->location.mapNum == MAP_NUM(FARAWAY_ISLAND_INTERIOR)
&& gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(FARAWAY_ISLAND_INTERIOR))
{
if (eventObject->graphicsId == EVENT_OBJ_GFX_MEW)
return TRUE;
}
return FALSE;
}
bool8 IsMewPlayingHideAndSeek(void)
{
if (gSaveBlock1Ptr->location.mapNum == MAP_NUM(FARAWAY_ISLAND_INTERIOR)
&& gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(FARAWAY_ISLAND_INTERIOR))
{
if (FlagGet(FLAG_CAUGHT_MEW) != TRUE && FlagGet(FLAG_HIDE_MEW) != TRUE)
return TRUE;
}
return FALSE;
}
bool8 sub_81D4A58(struct EventObject *eventObject)
{
if (VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) != 0xFFFF
&& VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % 4 == 0)
return TRUE;
return FALSE;
}
void sub_81D4A90(void)
{
s16 x;
s16 y;
u8 spriteId;
struct EventObject *mew = &gEventObjects[sub_81D4258()];
mew->invisible = 0;
if (gSpecialVar_0x8004 == 1)
{
mew->fixedPriority = 1;
gSprites[mew->spriteId].subspriteMode = SUBSPRITES_IGNORE_PRIORITY;
gSprites[mew->spriteId].subpriority = 1;
}
else
{
VarSet(VAR_FARAWAY_ISLAND_STEP_COUNTER, 0xFFFF);
mew->fixedPriority = 1;
gSprites[mew->spriteId].subspriteMode = SUBSPRITES_IGNORE_PRIORITY;
if (gSpecialVar_Facing != DIR_NORTH)
gSprites[mew->spriteId].subpriority = 1;
LoadSpritePalette(&gFieldEffectObjectPaletteInfo1);
UpdateSpritePaletteWithWeather(IndexOfSpritePaletteTag(gFieldEffectObjectPaletteInfo1.tag));
x = mew->currentCoords.x;
y = mew->currentCoords.y;
sub_80930E0(&x, &y, 8, 8);
gUnknown_0203CF50 = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[15], x, y, gSprites[mew->spriteId].subpriority - 1);
if (gUnknown_0203CF50 != MAX_SPRITES)
{
struct Sprite *sprite = &gSprites[gUnknown_0203CF50];
sprite->coordOffsetEnabled = 1;
sprite->oam.priority = 2;
sprite->callback = SpriteCallbackDummy;
}
}
}
void sub_81D4BEC(void)
{
if (gUnknown_0203CF50 != MAX_SPRITES)
DestroySprite(&gSprites[gUnknown_0203CF50]);
}
static bool8 sub_81D4C14(struct EventObject *mew, u8 index)
{
if (gUnknown_030012FA > 0 && sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1))
{
gUnknown_030012FC[index] = DIR_NORTH;
return TRUE;
}
return FALSE;
}
static u8 sub_81D4C58(struct EventObject *mew, u8 index)
{
if (gUnknown_030012F8 < 0 && sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y))
{
gUnknown_030012FC[index] = DIR_EAST;
return TRUE;
}
return FALSE;
}
static u8 sub_81D4C9C(struct EventObject *mew, u8 index)
{
if (gUnknown_030012FA < 0 && sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1))
{
gUnknown_030012FC[index] = DIR_SOUTH;
return TRUE;
}
return FALSE;
}
static u8 sub_81D4CE0(struct EventObject *mew, u8 index)
{
if (gUnknown_030012F8 > 0 && sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y))
{
gUnknown_030012FC[index] = DIR_WEST;
return TRUE;
}
return FALSE;
}
static u8 sub_81D4D24(u8 mod)
{
return gUnknown_030012FC[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % mod];
}
void sub_81D4D50(struct Unk03006370 *arg0, int arg1, u32 *arg2)
{
volatile u16 backupIME = REG_IME;
REG_IME = 0;
gIntrTable[1] = sub_81D3FAC;
gIntrTable[2] = sub_81D3F9C;
sub_81D41A0();
sub_81D4238();
REG_IE |= INTR_FLAG_VCOUNT;
REG_IME = backupIME;
arg0->unk0 = 0;
arg0->unk4 = arg1;
arg0->unk8 = arg2;
}
void sub_81D4DB8(struct Unk03006370 *arg0)
{
volatile u16 backupIME = REG_IME;
REG_IME = 0;
sub_81D4238();
sub_81D41F4();
RestoreSerialTimer3IntrHandlers();
REG_IME = backupIME;
}
u8 sub_81D4DE8(struct Unk03006370 *arg0)
{
u8 var0 = 0;
arg0->unk0 = sub_81D3D70(1, arg0->unk4, arg0->unk8, NULL);
if ((arg0->unk0 & 0x13) == 0x10)
var0 = 1;
if (arg0->unk0 & 0x8)
var0 = 2;
if (arg0->unk0 & 0x4)
var0 = 3;
gShouldAdvanceLinkState = 0;
return var0;
}
void sub_81D4E30(void)
{
memset(gDecompressionBuffer, 0, 0x2000);
gLinkType = 0x5503;
OpenLink();
SetSuppressLinkErrorMessage(TRUE);
}
bool32 sub_81D4E60(void)
{
volatile u16 backupIME;
u16 sp4[4];
backupIME = REG_IME;
REG_IME = 0;
*(u64 *)sp4 = *(u64 *)gLink.tempRecvBuffer;
REG_IME = backupIME;
if (sp4[0] == 0xB9A0 && sp4[1] == 0xCCD0
&& sp4[2] == 0xFFFF && sp4[3] == 0xFFFF)
{
return TRUE;
}
return FALSE;
}
bool32 sub_81D4EC0(void)
{
if (IsLinkMaster() && GetLinkPlayerCount_2() == 2)
return TRUE;
return FALSE;
}
u32 sub_81D4EE4(u8 *arg0, u16 *arg1)
{
u8 var0;
var0 = *arg0 - 3;
if (var0 < 3 && HasLinkErrorOccurred())
{
*arg0 = 0;
return 3;
}
switch (*arg0)
{
case 0:
if (IsLinkMaster() && GetLinkPlayerCount_2() > 1)
{
*arg0 = 1;
}
else if (gMain.newKeys & B_BUTTON)
{
*arg0 = 0;
return 1;
}
break;
case 1:
if (++(*arg1) > 5)
{
*arg1 = 0;
*arg0 = 2;
}
break;
case 2:
if (GetLinkPlayerCount_2() == 2)
{
PlaySE(SE_PINPON);
CheckShouldAdvanceLinkState();
*arg1 = 0;
*arg0 = 3;
}
else if (gMain.newKeys & B_BUTTON)
{
*arg0 = 0;
return 1;
}
break;
case 3:
if (++(*arg1) > 30)
{
*arg0 = 0;
return 5;
}
if (IsLinkConnectionEstablished())
{
if (gReceivedRemoteLinkPlayers)
{
if (IsLinkPlayerDataExchangeComplete())
{
*arg0 = 0;
return 2;
}
else
{
*arg0 = 4;
}
}
else
{
*arg0 = 3;
}
}
break;
case 4:
sub_800ABF4(0);
*arg0 = 5;
break;
case 5:
if (!gReceivedRemoteLinkPlayers)
{
*arg0 = 0;
return 4;
}
break;
default:
return 0;
}
return 0;
}
void sub_81D5014(void)
{
int value;
struct Unk81D5014 *data;
u8 taskId = CreateTask(sub_81D5084, 0);
data = (struct Unk81D5014 *)gTasks[taskId].data;
data->unk8 = 0;
data->unk9 = 0;
data->unkA = 0;
data->unkB = 0;
data->unkC = 0;
data->unkD = 0;
data->unk0 = 0;
data->unk2 = 0;
data->unk4 = 0;
data->unk6 = 0;
data->unkE = 0;
data->unk10 = AllocZeroed(0x40);
}
void sub_81D505C(u16 *arg0)
{
*arg0 = 0;
}
bool32 sub_81D5064(u16 *arg0, u16 arg1)
{
if (++(*arg0) > arg1)
{
*arg0 = 0;
return TRUE;
}
return FALSE;
}
void sub_81D5084(u8 taskId)
{
struct Unk81D5014 *data = (struct Unk81D5014 *)gTasks[taskId].data;
switch (data->unk8)
{
case 0:
if (mevent_0814257C(&data->unk9, gUnknown_085EDFD6))
data->unk8 = 1;
break;
case 1:
sub_81D4E30();
sub_81D505C(&data->unk0);
data->unk8 = 2;
break;
case 2:
if (sub_81D5064(&data->unk0, 10))
data->unk8 = 3;
break;
case 3:
if (!sub_81D4EC0())
{
CloseLink();
data->unk8 = 4;
}
else
{
data->unk8 = 13;
}
break;
case 4:
if (mevent_0814257C(&data->unk9, gUnknown_085EDFF5))
{
sub_8018884(gUnknown_085EE014);
sub_81D505C(&data->unk0);
data->unk8 = 5;
}
break;
case 5:
if (sub_81D5064(&data->unk0, 90))
{
sub_81D4E30();
data->unk8 = 6;
}
else if (gMain.newKeys & B_BUTTON)
{
sub_81D505C(&data->unk0);
PlaySE(SE_SELECT);
data->unk8 = 23;
}
break;
case 6:
if (gMain.newKeys & B_BUTTON)
{
PlaySE(SE_SELECT);
CloseLink();
sub_81D505C(&data->unk0);
data->unk8 = 23;
}
else if (GetLinkPlayerCount_2() > 1)
{
sub_81D505C(&data->unk0);
CloseLink();
data->unk8 = 7;
}
else if (sub_81D4E60())
{
PlaySE(SE_SELECT);
CloseLink();
sub_81D505C(&data->unk0);
data->unk8 = 8;
}
else if (sub_81D5064(&data->unk0, 10))
{
CloseLink();
sub_81D4E30();
sub_81D505C(&data->unk0);
}
break;
case 7:
if (mevent_0814257C(&data->unk9, gUnknown_085EE05C))
data->unk8 = 4;
break;
case 8:
sub_8018884(gUnknown_085EE097);
// XXX: This (u32*) cast is discarding the const qualifier from gUnknown_089A3470
sub_81D4D50(&gUnknown_03006370, gMultiBootProgram_BerryGlitchFix_Start - gUnknown_089A3470, (u32*)gUnknown_089A3470);
data->unk8 = 9;
break;
case 9:
data->unkE = sub_81D4DE8(&gUnknown_03006370);
if (data->unkE)
data->unk8 = 10;
break;
case 10:
sub_81D4DB8(&gUnknown_03006370);
if (data->unkE == 3)
{
data->unk8 = 20;
}
else if (data->unkE == 1)
{
sub_81D505C(&data->unk0);
sub_8018884(gUnknown_085EE120);
data->unk8 = 11;
}
else
{
data->unk8 = 0;
}
break;
case 11:
if (sub_81D5064(&data->unk0, 840))
data->unk8 = 12;
break;
case 12:
sub_81D4E30();
sub_8018884(gUnknown_085EE0DC);
data->unk8 = 13;
break;
case 13:
switch (sub_81D4EE4(&data->unk9, &data->unk0))
{
case 0:
break;
case 2:
sub_8018884(gUnknown_085EE097);
data->unk8 = 14;
break;
case 1:
PlaySE(SE_SELECT);
CloseLink();
data->unk8 = 23;
break;
case 5:
CloseLink();
data->unk8 = 21;
break;
case 3:
case 4:
CloseLink();
data->unk8 = 20;
break;
}
break;
case 14:
if (HasLinkErrorOccurred())
{
CloseLink();
data->unk8 = 20;
}
else if (GetBlockReceivedStatus())
{
ResetBlockReceivedFlags();
data->unk8 = 15;
}
break;
case 15:
data->unkE = sub_81D3920(gDecompressionBuffer);
sub_800ABF4(data->unkE);
data->unk8 = 16;
break;
case 16:
if (!gReceivedRemoteLinkPlayers)
{
if (data->unkE == 1)
data->unk8 = 17;
else
data->unk8 = 20;
}
break;
case 17:
if (sub_81D3AB0((struct Unk81D38FC *)&gDecompressionBuffer))
{
sub_8018884(gUnknown_085EE0FA);
sub_81D505C(&data->unk0);
data->unk8 = 18;
}
else
{
data->unk8 = 22;
}
break;
case 18:
if (sub_81D5064(&data->unk0, 120))
{
sub_8018884(gUnknown_085EE107);
PlayFanfare(MUS_FANFA4);
data->unk8 = 19;
}
break;
case 19:
if (IsFanfareTaskInactive() && (gMain.newKeys & (A_BUTTON | B_BUTTON)))
data->unk8 = 26;
break;
case 23:
if (mevent_0814257C(&data->unk9,gUnknown_085EE06B))
data->unk8 = 26;
break;
case 20:
if (mevent_0814257C(&data->unk9, gUnknown_085EE0A3))
data->unk8 = 0;
break;
case 21:
if (mevent_0814257C(&data->unk9, gUnknown_085EE0BF))
data->unk8 = 0;
break;
case 22:
if (mevent_0814257C(&data->unk9, gUnknown_085EE12D))
data->unk8 = 0;
break;
case 26:
Free(data->unk10);
DestroyTask(taskId);
SetMainCallback2(sub_80186A4);
break;
}
}

View File

@ -3,6 +3,7 @@
#include "bike.h"
#include "coord_event_weather.h"
#include "daycare.h"
#include "ereader.h"
#include "event_data.h"
#include "event_object_movement.h"
#include "event_scripts.h"
@ -18,7 +19,6 @@
#include "metatile_behavior.h"
#include "overworld.h"
#include "pokemon.h"
#include "pokenav.h"
#include "safari_zone.h"
#include "script.h"
#include "secret_base.h"
@ -541,7 +541,7 @@ static bool8 TryStartStepCountScript(u16 metatileBehavior)
IncrementRematchStepCounter();
UpdateHappinessStepCounter();
sub_81D4998();
UpdateFarawayIslandStepCounter();
if (!(gPlayerAvatar.flags & PLAYER_AVATAR_FLAG_6) && !MetatileBehavior_IsForcedMovementTile(metatileBehavior))
{

View File

@ -1,4 +1,5 @@
#include "global.h"
#include "ereader.h"
#include "event_obj_lock.h"
#include "event_object_movement.h"
#include "field_camera.h"
@ -20,8 +21,6 @@
#include "constants/field_effects.h"
#include "constants/songs.h"
extern bool8 IsMewPlayingHideAndSeek(void);
extern struct MapPosition gPlayerFacingPosition;
extern const u8 Route103_EventScript_290705[];