decompile map object and field message box code

This commit is contained in:
YamaArashi 2016-09-23 19:26:57 -07:00
parent c3c7432d2e
commit bbc0da892f
12 changed files with 698 additions and 1589 deletions

1588
asm/rom4.s

File diff suppressed because it is too large Load Diff

View File

@ -5777,7 +5777,7 @@ gUnknown_08375694:: @ 8375694
.4byte MetatileBehavior_IsWestBlocked
.align 1
gUnknown_083756A4:: @ 83756A4
gDirectionToVector:: @ 83756A4
.2byte 0, 0
.2byte 0, 1
.2byte 0, -1

View File

@ -37,6 +37,10 @@ gSaveBlock1 = 0x2025734;
gMapHeader = 0x202E828;
gPlayerAvatar = 0x202E858;
unk_202E87C = 0x202E87C;
gUnknown_0202E8AC = 0x202E8AC;
gUnknown_0202E8B0 = 0x202E8B0;
gUnknown_0202E8B4 = 0x202E8B4;
@ -49,8 +53,10 @@ gUnknown_0202E8C6 = 0x202E8C6;
gUnknown_0202E8C8 = 0x202E8C8;
gUnknown_0202E8CC = 0x202E8CC;
gScriptResult = 0x202E8DC;
gUnknown_0202E8E0 = 0x202E8E0;
gMenuWindow = 0x202E908;
word_202E9D2 = 0x202E9D2;
gMenuWindowPtr = 0x202E9C8;
gMenuMultistepInitState = 0x202E9CC;
gMenuTextTileOffset = 0x202E9CE;
@ -68,6 +74,8 @@ gPaletteFade = 0x202F388;
word_202FF5E = 0x202FF5E;
gUnknown_0202FF84 = 0x202FF84;
gUnknown_0202FF88 = 0x202FF88;
gUnknown_0202FF8C = 0x202FF8C;
gPokemonStorage = 0x20300A0;

View File

@ -35,11 +35,76 @@ struct MapHeader
struct MapObject
{
u32 active:1;
u8 filler[0x20];
u32 mapobj_bit_1:1;
u32 mapobj_bit_2:1;
u32 mapobj_bit_3:1;
u32 mapobj_bit_4:1;
u32 mapobj_bit_5:1;
u32 mapobj_bit_6:1;
u32 mapobj_bit_7:1;
u32 mapobj_bit_8:1;
u32 mapobj_bit_9:1;
u32 mapobj_bit_10:1;
u32 mapobj_bit_11:1;
u32 mapobj_bit_12:1;
u32 mapobj_bit_13:1;
u32 mapobj_bit_14:1;
u32 mapobj_bit_15:1;
u32 mapobj_bit_16:1;
u32 mapobj_bit_17:1;
u32 mapobj_bit_18:1;
u32 mapobj_bit_19:1;
u32 mapobj_bit_20:1;
u32 mapobj_bit_21:1;
u32 mapobj_bit_22:1;
u32 mapobj_bit_23:1;
u32 mapobj_bit_24:1;
u32 mapobj_bit_25:1;
u32 mapobj_bit_26:1;
u32 mapobj_bit_27:1;
u32 mapobj_bit_28:1;
u32 mapobj_bit_29:1;
u32 mapobj_bit_30:1;
u32 mapobj_bit_31:1;
u8 spriteId;
u8 graphicsId;
u8 filler[0x1E];
};
struct MapObjectGraphicsInfo
{
u16 tileTag;
u16 paletteTag1;
u16 paletteTag2;
u16 size;
s16 width;
s16 height;
u8 paletteSlot:4;
u8 shadowSize:2;
u8 inanimate:1;
u8 disableReflectionPaletteLoad:1;
u8 tracks;
struct OamData *oam;
struct SubspriteTable *subspriteTables;
union AnimCmd **anims;
struct SpriteFrameImage *images;
union AffineAnimCmd **affineAnims;
};
struct PlayerAvatar
{
u8 bitfield;
u8 bike;
u8 running2;
u8 running1;
u8 spriteId;
u8 mapObjectId;
// TODO: rest of struct
};
extern struct MapObject gMapObjects[];
extern u8 gSelectedMapObject;
extern struct MapHeader gMapHeader;
extern struct PlayerAvatar gPlayerAvatar;
#endif // GUARD_FIELDMAP_H

View File

@ -52,6 +52,12 @@ struct Coords16
s16 y;
};
struct UCoords16
{
u16 x;
u16 y;
};
struct SecretBaseRecord
{
u8 sbr_field_0; // ID?

View File

@ -1,6 +1,8 @@
#ifndef GUARD_SPRITE_H
#define GUARD_SPRITE_H
#define MAX_SPRITES 64
struct SpriteSheet
{
u8 *data;
@ -183,6 +185,11 @@ struct Sprite
u8 subpriority;
};
extern s16 gSpriteCoordOffsetX;
extern s16 gSpriteCoordOffsetY;
extern struct Sprite gSprites[];
void ResetSpriteData(void);
void AnimateSprites(void);
void BuildOamBuffer(void);

View File

@ -2,6 +2,8 @@
gPlayTimeCounterState = 0x300057C;
byte_30005A8 = 0x30005A8;
sScriptContext1Status = 0x30005B0;
sScriptContext1 = 0x30005B8;
sScriptContext2 = 0x3000630;

View File

@ -87,6 +87,9 @@ SECTIONS {
asm/rom_8040EB4.o(.text);
src/play_time.o(.text);
asm/rom4.o(.text);
src/map_obj_80643A4.o(.text);
src/field_message_box.o(.text);
src/map_obj_lock.o(.text);
src/text_window.o(.text);
src/script.o(.text);
src/scrcmd.o(.text);

153
src/field_message_box.c Normal file
View File

@ -0,0 +1,153 @@
#include "global.h"
#include "text.h"
#include "text_window.h"
#include "task.h"
#include "string_util.h"
extern struct Window unk_202E87C;
extern u16 word_202E9D2;
extern u16 gMenuTextTileOffset;
extern u8 byte_30005A8;
void textbox_fdecode_auto_and_task_add(u8 *);
void textbox_auto_and_task_add(void);
void sub_8064A74(void)
{
byte_30005A8 = 0;
SetMessageBoxBaseTileNum(word_202E9D2);
InitWindowFromConfig(&unk_202E87C, (struct WindowConfig *)&gWindowConfig_81E6CE4);
}
void sub_8064AA0(u8 taskId)
{
struct Task *task = &gTasks[taskId];
switch (task->data[0])
{
case 0:
LoadMessageBoxTiles(&unk_202E87C);
task->data[0]++;
break;
case 1:
DrawStandardMessageBox(&unk_202E87C);
task->data[0]++;
break;
case 2:
switch (byte_30005A8)
{
case 2:
if (!sub_80035AC(&unk_202E87C))
return;
break;
case 3:
if (!sub_8003778(&unk_202E87C))
return;
break;
}
byte_30005A8 = 0;
DestroyTask(taskId);
}
}
void task_add_textbox(void)
{
CreateTask(sub_8064AA0, 80);
}
void task_del_textbox()
{
u8 taskId = FindTaskIdByFunc(sub_8064AA0);
if (taskId != 0xFF)
DestroyTask(taskId);
}
bool8 box_related_two__2(u8 *a1)
{
if (byte_30005A8)
{
return FALSE;
}
else
{
textbox_fdecode_auto_and_task_add(a1);
byte_30005A8 = 2;
return TRUE;
}
}
bool8 box_related_two__3(u8 *a1)
{
if (byte_30005A8)
{
return FALSE;
}
else
{
byte_30005A8 = 3;
textbox_fdecode_auto_and_task_add(a1);
return TRUE;
}
}
bool8 unref_sub_8064BB8(u8 *a1)
{
byte_30005A8 = 3;
textbox_fdecode_auto_and_task_add(a1);
return TRUE;
}
bool8 unref_sub_8064BD0(u8 *a1)
{
if (byte_30005A8)
{
return FALSE;
}
else
{
byte_30005A8 = 2;
textbox_auto_and_task_add();
return TRUE;
}
}
void textbox_fdecode_auto_and_task_add(u8 *a1)
{
StringExpandPlaceholders(gStringVar4, a1);
sub_8002EB0(&unk_202E87C, gStringVar4, gMenuTextTileOffset, 2, 15);
task_add_textbox();
}
void textbox_auto_and_task_add(void)
{
sub_8002EB0(&unk_202E87C, gStringVar4, gMenuTextTileOffset, 2, 15);
task_add_textbox();
}
void textbox_close()
{
task_del_textbox();
sub_806536C(&unk_202E87C);
byte_30005A8 = 0;
}
u8 textbox_any_visible()
{
return byte_30005A8;
}
bool8 sub_8064C84()
{
if (byte_30005A8 == 0)
return TRUE;
else
return FALSE;
}
void unref_sub_8064CA0()
{
task_del_textbox();
DrawStandardMessageBox(&unk_202E87C);
byte_30005A8 = 0;
}

324
src/map_obj_80643A4.c Normal file
View File

@ -0,0 +1,324 @@
#include "global.h"
#include "sprite.h"
#include "fieldmap.h"
extern void SetObjectSubpriorityByZCoord(u8, struct Sprite *, u8);
extern u8 FieldObjectDirectionToImageAnimId(u8);
extern u32 FieldEffectStart(u8);
extern void FieldObjectGetLocalIdAndMap(struct MapObject *, u8 *, u8 *, u8 *);
extern struct MapObjectGraphicsInfo *GetFieldObjectGraphicsInfo(u8);
typedef void (*SpriteStepFunc)(struct Sprite *sprite, u8 dir);
extern u32 gUnknown_0202FF84[];
extern struct UCoords16 gDirectionToVector[];
extern s16 gUnknown_08376194[];
extern SpriteStepFunc *gUnknown_08376180[];
extern s8 *gUnknown_083761D0[];
extern s16 gUnknown_083761DC[];
extern u8 gUnknown_083761E2[];
extern s16 gUnknown_083761E6[];
extern u8 gUnknown_083761EC[];
bool8 sub_80643A4(struct MapObject *mapObject)
{
if (mapObject->mapobj_bit_6 || mapObject->mapobj_bit_8)
{
return TRUE;
}
else
{
mapObject->mapobj_bit_8 = 1;
mapObject->mapobj_bit_23 = gSprites[mapObject->spriteId].animPaused;
mapObject->mapobj_bit_24 = gSprites[mapObject->spriteId].affineAnimPaused;
gSprites[mapObject->spriteId].animPaused = 1;
gSprites[mapObject->spriteId].affineAnimPaused = 1;
return FALSE;
}
}
void player_bitmagic()
{
u8 i;
for (i = 0; i < 16; i++)
if (gMapObjects[i].active && i != gPlayerAvatar.mapObjectId)
sub_80643A4(&gMapObjects[i]);
}
void sub_8064470(u8 a1)
{
u8 i;
for (i = 0; i < 16; i++)
if (i != a1 && gMapObjects[i].active && i != gPlayerAvatar.mapObjectId)
sub_80643A4(&gMapObjects[i]);
}
void npc_sync_anim_pause_bits(struct MapObject *mapObject)
{
if (mapObject->active && mapObject->mapobj_bit_8)
{
mapObject->mapobj_bit_8 = 0;
gSprites[mapObject->spriteId].animPaused = mapObject->mapobj_bit_23;
gSprites[mapObject->spriteId].affineAnimPaused = mapObject->mapobj_bit_24;
}
}
void sub_806451C(void)
{
u8 i;
for (i = 0; i < 16; i++)
if (gMapObjects[i].active)
npc_sync_anim_pause_bits(&gMapObjects[i]);
}
void little_step(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += gDirectionToVector[dir].x;
sprite->pos1.y += gDirectionToVector[dir].y;
}
void sub_806456C(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 2 * gDirectionToVector[dir].x;
sprite->pos1.y += 2 * gDirectionToVector[dir].y;
}
void sub_8064590(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 2 * gDirectionToVector[dir].x + gDirectionToVector[dir].x;
sprite->pos1.y += 2 * gDirectionToVector[dir].y + gDirectionToVector[dir].y;
}
void sub_80645B8(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 4 * gDirectionToVector[dir].x;
sprite->pos1.y += 4 * gDirectionToVector[dir].y;
}
void sub_80645DC(struct Sprite *sprite, u8 dir)
{
sprite->pos1.x += 8 * gDirectionToVector[dir].x;
sprite->pos1.y += 8 * gDirectionToVector[dir].y;
}
void oamt_npc_ministep_reset(struct Sprite *sprite, u8 a2, u8 a3)
{
sprite->data3 = a2;
sprite->data4 = a3;
sprite->data5 = 0;
}
bool8 obj_npc_ministep(struct Sprite *sprite)
{
if (sprite->data5 >= gUnknown_08376194[sprite->data4])
return FALSE;
gUnknown_08376180[sprite->data4][sprite->data5](sprite, sprite->data3);
sprite->data5++;
if (sprite->data5 < gUnknown_08376194[sprite->data4])
return FALSE;
return TRUE;
}
void sub_806467C(struct Sprite *sprite, u8 a2)
{
sprite->data3 = a2;
sprite->data4 = 0;
sprite->data5 = 0;
}
bool8 sub_806468C(struct Sprite *sprite)
{
if (!(sprite->data4 & 1))
{
little_step(sprite, sprite->data3);
sprite->data5++;
}
sprite->data4++;
if (sprite->data5 > 15)
return TRUE;
else
return FALSE;
}
s16 sub_80646C8(s16 a1, u8 a2)
{
return gUnknown_083761D0[a2][a1];
}
void sub_80646E4(struct Sprite *sprite, u8 a2, u8 a3, u8 a4)
{
sprite->data3 = a2;
sprite->data4 = a3;
sprite->data5 = a4;
sprite->data6 = 0;
}
u8 sub_8064704(struct Sprite *sprite)
{
u8 v2;
s16 v5[3];
u8 v6[3];
memcpy(v5, gUnknown_083761DC, 6);
memcpy(v6, gUnknown_083761E2, 3);
v2 = 0;
if (sprite->data4)
little_step(sprite, sprite->data3);
sprite->pos2.y = sub_80646C8(sprite->data6 >> v6[sprite->data4], sprite->data5);
sprite->data6++;
if (sprite->data6 == (v5[sprite->data4] >> 1))
v2 = 1;
if (sprite->data6 >= v5[sprite->data4])
{
sprite->pos2.y = 0;
v2 = -1;
}
return v2;
}
u8 sub_806478C(struct Sprite *sprite)
{
u8 v2;
s16 v5[3];
u8 v6[3];
memcpy(v5, gUnknown_083761E6, 6);
memcpy(v6, gUnknown_083761EC, 3);
v2 = 0;
if (sprite->data4 && !(sprite->data6 & 1))
little_step(sprite, sprite->data3);
sprite->pos2.y = sub_80646C8(sprite->data6 >> v6[sprite->data4], sprite->data5);
sprite->data6++;
if (sprite->data6 == (v5[sprite->data4] >> 1))
v2 = 1;
if (sprite->data6 >= v5[sprite->data4])
{
sprite->pos2.y = 0;
v2 = -1;
}
return v2;
}
void sub_8064820(struct Sprite *sprite, u16 a2)
{
sprite->data3 = a2;
}
bool8 sub_8064824(struct Sprite *sprite)
{
sprite->data3--;
if (sprite->data3 == 0)
return TRUE;
else
return FALSE;
}
void obj_anim_image_set_and_seek(struct Sprite *sprite, u8 a2, u8 a3)
{
sprite->animNum = a2;
sprite->animPaused = 0 ;
SeekSpriteAnim(sprite, a3);
}
bool8 sub_8064864(struct Sprite *sprite)
{
if (sprite->animEnded)
return TRUE;
else
return FALSE;
}
void sub_806487C(struct Sprite *sprite, bool8 invisible)
{
u16 x, y;
s16 x2, y2;
sprite->invisible = invisible;
if (sprite->coordOffsetEnabled)
{
x = sprite->pos1.x + sprite->pos2.x + sprite->centerToCornerVecX + gSpriteCoordOffsetX;
y = sprite->pos1.y + sprite->pos2.y + sprite->centerToCornerVecY + gSpriteCoordOffsetY;
}
else
{
x = sprite->pos1.x + sprite->pos2.x + sprite->centerToCornerVecX;
y = sprite->pos1.y + sprite->pos2.y + sprite->centerToCornerVecY;
}
x2 = x - (sprite->centerToCornerVecX >> 1);
y2 = y - (sprite->centerToCornerVecY >> 1);
if ((s16)x > 255 || x2 < -16)
sprite->invisible = 1;
if ((s16)y > 175 || y2 < -16)
sprite->invisible = 1;
}
void sub_8064970(struct Sprite *sprite)
{
SetObjectSubpriorityByZCoord(sprite->data1, sprite, 1);
sub_806487C(sprite, 0);
}
void sub_8064990(u8 a1, u8 dir)
{
u8 i;
for (i = 0; i < MAX_SPRITES; i++)
{
struct Sprite *sprite = &gSprites[i];
if (sprite->inUse && sprite->callback == sub_8064970 && (u8)sprite->data0 == a1)
{
u8 animNum = FieldObjectDirectionToImageAnimId(dir);
StartSpriteAnim(sprite, animNum);
break;
}
}
}
u32 oe_exec_and_other_stuff(u8 fieldEffectId, struct MapObject *mapObject)
{
FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gUnknown_0202FF84[0], (u8 *)&gUnknown_0202FF84[1], (u8 *)&gUnknown_0202FF84[2]);
return FieldEffectStart(fieldEffectId);
}
void DoShadowFieldEffect(struct MapObject *mapObject)
{
if (!mapObject->mapobj_bit_22)
{
mapObject->mapobj_bit_22 = 1;
oe_exec_and_other_stuff(3, mapObject);
}
}
void DoRippleFieldEffect(struct MapObject *mapObject, struct Sprite *sprite)
{
struct MapObjectGraphicsInfo *gfxInfo = GetFieldObjectGraphicsInfo(mapObject->graphicsId);
gUnknown_0202FF84[0] = sprite->pos1.x;
gUnknown_0202FF84[1] = sprite->pos1.y + (gfxInfo->height >> 1) - 2;
gUnknown_0202FF84[2] = 151;
gUnknown_0202FF84[3] = 3;
FieldEffectStart(5);
}

125
src/map_obj_lock.c Normal file
View File

@ -0,0 +1,125 @@
#include "global.h"
#include "task.h"
#include "fieldmap.h"
extern void sub_80594C0(void);
extern void sub_80597F4(void);
extern void player_bitmagic(void);
extern void sub_80643A4(struct MapObject *);
extern void sub_8064470(u8);
extern u8 GetFieldObjectIdByLocalIdAndMap(u8, u8, u8);
extern u8 FieldObjectClearAnimIfSpecialAnimFinished(void *);
extern void sub_80A2178(void);
extern void sub_806451C(void);
extern u8 FieldObjectFaceOppositeDirection(void *, u8);
extern u16 gUnknown_0202E8E0;
bool8 walkrun_is_standing_still(void)
{
if (gPlayerAvatar.running1 == 1)
return FALSE;
else
return TRUE;
}
void sub_8064CDC(u8 taskId)
{
if (walkrun_is_standing_still())
{
sub_80594C0();
DestroyTask(taskId);
}
}
bool8 sub_8064CFC(void)
{
if (FuncIsActiveTask(sub_8064CDC))
{
return FALSE;
}
else
{
sub_80597F4();
return TRUE;
}
}
void sub_8064D20(void)
{
player_bitmagic();
CreateTask(sub_8064CDC, 80);
}
void sub_8064D38(u8 taskId)
{
struct Task *task = &gTasks[taskId];
if (!task->data[0] && walkrun_is_standing_still() == TRUE)
{
sub_80594C0();
task->data[0] = 1;
}
if (!task->data[1] && !gMapObjects[gSelectedMapObject].mapobj_bit_1)
{
sub_80643A4(&gMapObjects[gSelectedMapObject]);
task->data[1] = 1;
}
if (task->data[0] && task->data[1])
DestroyTask(taskId);
}
bool8 sub_8064DB4(void)
{
if (FuncIsActiveTask(sub_8064D38))
{
return FALSE;
}
else
{
sub_80597F4();
return TRUE;
}
}
void sub_8064DD8(void)
{
u8 taskId;
sub_8064470(gSelectedMapObject);
taskId = CreateTask(sub_8064D38, 80);
if (!gMapObjects[gSelectedMapObject].mapobj_bit_1)
{
sub_80643A4(&gMapObjects[gSelectedMapObject]);
gTasks[taskId].data[1] = 1;
}
}
void sub_8064E2C(void)
{
u8 objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0);
FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]);
sub_80A2178();
sub_806451C();
}
void unref_sub_8064E5C(void)
{
u8 objectId;
if (gMapObjects[gSelectedMapObject].active)
FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[gSelectedMapObject]);
objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0);
FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]);
sub_80A2178();
sub_806451C();
}
void sub_8064EAC(void)
{
FieldObjectFaceOppositeDirection(&gMapObjects[gSelectedMapObject], gUnknown_0202E8E0);
}
void sub_8064ED4(void)
{
FieldObjectClearAnimIfSpecialAnimActive(&gMapObjects[gSelectedMapObject]);
}

View File

@ -2,8 +2,6 @@
#include "main.h"
#include "sprite.h"
#define MAX_SPRITES 64
#define MAX_SPRITE_COPY_REQUESTS 64
#define OAM_MATRIX_COUNT 32