Decompile treeItem.c

This commit is contained in:
Marcus Huderle 2020-09-24 19:33:05 -05:00
parent c9c88c1d56
commit 82654cd402
6 changed files with 183 additions and 214 deletions

View File

@ -2,35 +2,64 @@
.set GUARD_ASM_MACROS_ENTITY_INC, 1
.set ENTITY_TYPE_ENEMY, 0x3
.set ENTITY_OCTOROK, 0x0
.set ENTITY_CHUCHU, 0x1
.set ENTITY_TREE_ITEM, 0x65
.set ENTITY_TYPE_SIGN, 0x5
.set ENTITY_TYPE_OBJECT, 0x6
.macro entity_octorok x, y, bound_x, bound_y, bound_tile_width, bound_tile_height
.byte ENTITY_TYPE_ENEMY
.set OBJECT_ITEM, 0x0
.set OBJECT_MINISH_LILYPAD, 0x73
.set ENEMY_OCTOROK, 0x0
.set ENEMY_CHUCHU, 0x1
.set ENEMY_TREE_ITEM, 0x65
.macro object_minish_lilypad x, y, room_property, collision=0
.byte ENTITY_TYPE_OBJECT | ((\collision) << 4)
.byte 0x0F
.byte ENTITY_OCTOROK
.byte OBJECT_MINISH_LILYPAD
.byte 0x00
.byte \room_property
.byte 0x00, 0x00, 0x00
.2byte \x, \y
.2byte 0x0, 0x0
.endm
.macro object_item x, y, item, flag, collision=0
.byte ENTITY_TYPE_OBJECT | ((\collision) << 4)
.byte 0x0F
.byte OBJECT_ITEM
.byte \item
.byte 0x00
.byte 0x04 @ stationary item
.byte 0x00, 0x00
.2byte \x, \y
.2byte 0x0, \flag
.endm
.macro enemy_octorok x, y, bound_x, bound_y, bound_tile_width, bound_tile_height, collision=0
.byte ENTITY_TYPE_ENEMY | ((\collision) << 4)
.byte 0x0F
.byte ENEMY_OCTOROK
.byte 0x00, 0x00, 0x00
.byte \bound_tile_width, \bound_tile_height
.2byte \x, \y
.2byte \bound_x, \bound_y
.endm
.macro entity_chuchu x, y, bound_x, bound_y, bound_tile_width, bound_tile_height
.byte ENTITY_TYPE_ENEMY
.macro enemy_chuchu x, y, bound_x, bound_y, bound_tile_width, bound_tile_height, collision=0
.byte ENTITY_TYPE_ENEMY | ((\collision) << 4)
.byte 0x0F
.byte ENTITY_CHUCHU
.byte ENEMY_CHUCHU
.byte 0x00, 0x00, 0x00
.byte \bound_tile_width, \bound_tile_height
.2byte \x, \y
.2byte \bound_x, \bound_y
.endm
.macro entity_tree_item x, y, unused
.byte ENTITY_TYPE_ENEMY
.macro enemy_tree_item x, y, unknown, collision=0
.byte ENTITY_TYPE_ENEMY | ((\collision) << 4)
.byte 0x0F
.byte ENTITY_TREE_ITEM
.byte \unused, 0x00, 0x00, 0x00, 0x00
.byte ENEMY_TREE_ITEM
.byte \unknown, 0x00, 0x00, 0x00, 0x00
.2byte \x, \y
.2byte 0x00, 0x00
.endm

View File

@ -1,170 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start TreeItem
TreeItem: @ 0x08049B70
push {r4, r5, lr}
adds r5, r0, #0
ldrb r0, [r5, #0xc]
cmp r0, #0
bne _08049BB0
adds r0, #1
strb r0, [r5, #0xc]
ldrb r0, [r5, #0xa]
lsls r0, r0, #4
ldr r1, _08049BEC @ =gUnk_080D29E0
adds r0, r0, r1
bl sub_080028F4
adds r4, r5, #0
adds r4, #0x68
strb r0, [r4]
lsls r0, r0, #0x18
lsrs r0, r0, #0x18
cmp r0, #8
bls _08049B9C
bl DeleteThisEntity
_08049B9C:
ldrb r0, [r4]
cmp r0, #7
bhi _08049BB0
movs r0, #0x67 @ Kinstone Bag
bl GetInventoryValue
cmp r0, #0
bne _08049BB0
movs r0, #8
strb r0, [r4]
_08049BB0:
adds r0, r5, #0
bl sub_08049C2C
cmp r0, #0
beq _08049C20
adds r0, r5, #0
adds r0, #0x68
ldrb r1, [r0]
cmp r1, #0
blt _08049C16
cmp r1, #7
ble _08049BF0
cmp r1, #8
bne _08049C16
movs r0, #0x40 @ Small Fairy
movs r1, #0x60
movs r2, #0
bl CreateObject
adds r4, r0, #0
cmp r4, #0
beq _08049C16
movs r0, #0
strb r0, [r4, #0xe]
adds r0, r5, #0
adds r1, r4, #0
bl CopyPosition
b _08049C16
.align 2, 0
_08049BEC: .4byte gUnk_080D29E0
_08049BF0:
ldr r0, _08049C24 @ =gUnk_080D2AB0
adds r0, r1, r0
ldrb r2, [r0]
movs r0, #0x96 @ Kinstone
movs r1, #7
bl CreateObject
adds r4, r0, #0
cmp r4, #0
beq _08049C16
adds r0, r5, #0
adds r1, r4, #0
bl CopyPosition
ldrh r0, [r4, #0x32]
adds r0, #0x10
strh r0, [r4, #0x32]
ldr r0, _08049C28 @ =0x0000FFE0
strh r0, [r4, #0x36]
_08049C16:
adds r0, r5, #0
bl sub_08049CF4
bl DeleteThisEntity
_08049C20:
pop {r4, r5, pc}
.align 2, 0
_08049C24: .4byte gUnk_080D2AB0
_08049C28: .4byte 0x0000FFE0
thumb_func_start sub_08049C2C
sub_08049C2C: @ 0x08049C2C
push {r4, r5, r6, lr}
adds r2, r0, #0
ldr r3, _08049CA4 @ =gPlayerEntity
ldrb r0, [r3, #0xc]
cmp r0, #6
bne _08049CA8
movs r0, #0x2e
ldrsh r1, [r3, r0]
movs r4, #0x2e
ldrsh r0, [r2, r4]
subs r1, r1, r0
movs r5, #6
movs r4, #0x80
lsls r4, r4, #8
adds r0, r1, #0
ands r0, r4
cmp r0, #0
beq _08049C52
movs r5, #2
_08049C52:
adds r1, #0x28
lsls r0, r1, #0x10
lsrs r0, r0, #0x10
cmp r0, #0x4f
bhi _08049CA8
movs r6, #0x32
ldrsh r1, [r3, r6]
movs r6, #0x32
ldrsh r0, [r2, r6]
subs r1, r1, r0
adds r0, r1, #0
ands r0, r4
rsbs r0, r0, #0
asrs r2, r0, #0x1f
movs r0, #4
ands r2, r0
adds r1, #0x28
lsls r0, r1, #0x10
lsrs r0, r0, #0x10
cmp r0, #0x4f
bhi _08049CA8
ldrb r0, [r3, #0x14]
cmp r0, #0
bne _08049C86
cmp r2, #0
beq _08049C9E
_08049C86:
cmp r0, #4
bne _08049C8E
cmp r2, #4
beq _08049C9E
_08049C8E:
cmp r0, #6
bne _08049C96
cmp r5, #6
beq _08049C9E
_08049C96:
cmp r0, #2
bne _08049CA8
cmp r5, #2
bne _08049CA8
_08049C9E:
movs r0, #1
b _08049CAA
.align 2, 0
_08049CA4: .4byte gPlayerEntity
_08049CA8:
movs r0, #0
_08049CAA:
pop {r4, r5, r6, pc}

View File

@ -4906,10 +4906,22 @@ gUnk_080D29C0:: @ 080D29C0
.incbin "baserom.gba", 0x0D29C0, 0x0000020
gUnk_080D29E0:: @ 080D29E0
.incbin "baserom.gba", 0x0D29E0, 0x00000D0
.byte 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
gUnk_080D2AB0:: @ 080D2AB0
.incbin "baserom.gba", 0x0D2AB0, 0x000000C
.byte 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x00, 0x00, 0x00, 0x00
gUnk_080D2ABC:: @ 080D2ABC
.incbin "baserom.gba", 0x0D2ABC, 0x000019C

View File

@ -8975,11 +8975,11 @@ gUnk_080F4CDC:: @ 080F4CDC
.incbin "baserom.gba", 0x0F4CDC, 0x0000024
gEntityList0_MinishWoods_0:: @ 080F4D00
.byte 0x06, 0x0F, 0x73, 0x00, 0x12, 0x00, 0x00, 0x00, 0xF8, 0x01, 0xD8, 0x03, 0x00, 0x00, 0x00, 0x00
.byte 0x06, 0x0F, 0x73, 0x00, 0x13, 0x00, 0x00, 0x00, 0xA8, 0x01, 0xB8, 0x03, 0x00, 0x00, 0x00, 0x00
.byte 0x16, 0x0F, 0x00, 0x63, 0x00, 0x04, 0x00, 0x00, 0xC8, 0x00, 0x34, 0x01, 0x00, 0x00, 0x3C, 0x00
.byte 0x16, 0x0F, 0x00, 0x63, 0x00, 0x04, 0x00, 0x00, 0x98, 0x01, 0xB4, 0x02, 0x00, 0x00, 0x3D, 0x00
.byte 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
object_minish_lilypad x=0x1F8, y=0x3D8, room_property=0x12
object_minish_lilypad x=0x1A8, y=0x3B8, room_property=0x13
object_item x=0xC8, y=0x134, item=0x63, flag=0x3C, collision=1
object_item x=0x198, y=0x2B4, item=0x63, flag=0x3D, collision=1
entity_list_end
gUnk_080F4D50:: @ 080F4D50
.incbin "baserom.gba", 0x0F4D50, 0x0000060
@ -9013,29 +9013,29 @@ gUnk_080F4F10:: @ 080F4F10
.incbin "baserom.gba", 0x0F4F10, 0x0000020
gEntityList2_MinishWoods_0:: @ 080F4F30
entity_octorok 0x148, 0x38, 0xA0, 0x20, 0x1A, 0x16
entity_octorok 0x118, 0x98, 0xA0, 0x20, 0x1A, 0x16
entity_octorok 0x1B8, 0x1A8, 0x160, 0x160, 0x1C, 0x14
entity_octorok 0x208, 0x1F8, 0x1C0, 0x1B0, 0x12, 0xA
entity_octorok 0x288, 0x188, 0x250, 0x140, 0xC, 0x1A
entity_octorok 0x148, 0x1E8, 0x120, 0x180, 0x10, 0x12
entity_octorok 0xA8, 0x198, 0x30, 0x180, 0x1A, 0xC
entity_chuchu 0x3A0, 0x1D0, 0x320, 0x1D0, 0x14, 0xC
entity_chuchu 0x3A0, 0x250, 0x330, 0x200, 0x12, 0xE
entity_chuchu 0x340, 0x270, 0x320, 0x240, 0x20, 0x12
entity_chuchu 0x380, 0x2E0, 0x350, 0x2B0, 0xC, 0xA
entity_chuchu 0x1A8, 0x2C8, 0x190, 0x2B0, 0xE, 0x6
entity_chuchu 0x280, 0x2F0, 0x240, 0x2C0, 0xC, 0xE
entity_chuchu 0x3B0, 0x100, 0x390, 0xE0, 0x6, 0x14
entity_chuchu 0x248, 0x2D8, 0x0, 0x0, 0x0, 0x0
entity_tree_item 0x120, 0x60, 0x5
entity_tree_item 0xE0, 0xB0, 0x6
entity_tree_item 0x190, 0x1A0, 0x7
entity_tree_item 0x1B0, 0x1E0, 0x8
entity_tree_item 0x250, 0x180, 0x9
entity_tree_item 0x280, 0x1C0, 0xA
entity_tree_item 0x380, 0x210, 0xB
entity_tree_item 0x370, 0x290, 0xC
enemy_octorok x=0x148, y=0x38, bound_x=0xA0, bound_y=0x20, bound_tile_width=0x1A, bound_tile_height=0x16
enemy_octorok x=0x118, y=0x98, bound_x=0xA0, bound_y=0x20, bound_tile_width=0x1A, bound_tile_height=0x16
enemy_octorok x=0x1B8, y=0x1A8, bound_x=0x160, bound_y=0x160, bound_tile_width=0x1C, bound_tile_height=0x14
enemy_octorok x=0x208, y=0x1F8, bound_x=0x1C0, bound_y=0x1B0, bound_tile_width=0x12, bound_tile_height=0xA
enemy_octorok x=0x288, y=0x188, bound_x=0x250, bound_y=0x140, bound_tile_width=0xC, bound_tile_height=0x1A
enemy_octorok x=0x148, y=0x1E8, bound_x=0x120, bound_y=0x180, bound_tile_width=0x10, bound_tile_height=0x12
enemy_octorok x=0xA8, y=0x198, bound_x=0x30, bound_y=0x180, bound_tile_width=0x1A, bound_tile_height=0xC
enemy_chuchu x=0x3A0, y=0x1D0, bound_x=0x320, bound_y=0x1D0, bound_tile_width=0x14, bound_tile_height=0xC
enemy_chuchu x=0x3A0, y=0x250, bound_x=0x330, bound_y=0x200, bound_tile_width=0x12, bound_tile_height=0xE
enemy_chuchu x=0x340, y=0x270, bound_x=0x320, bound_y=0x240, bound_tile_width=0x20, bound_tile_height=0x12
enemy_chuchu x=0x380, y=0x2E0, bound_x=0x350, bound_y=0x2B0, bound_tile_width=0xC, bound_tile_height=0xA
enemy_chuchu x=0x1A8, y=0x2C8, bound_x=0x190, bound_y=0x2B0, bound_tile_width=0xE, bound_tile_height=0x6
enemy_chuchu x=0x280, y=0x2F0, bound_x=0x240, bound_y=0x2C0, bound_tile_width=0xC, bound_tile_height=0xE
enemy_chuchu x=0x3B0, y=0x100, bound_x=0x390, bound_y=0xE0, bound_tile_width=0x6, bound_tile_height=0x14
enemy_chuchu x=0x248, y=0x2D8, bound_x=0x0, bound_y=0x0, bound_tile_width=0x0, bound_tile_height=0x0
enemy_tree_item x=0x120, y=0x60, unknown=0x5
enemy_tree_item x=0xE0, y=0xB0, unknown=0x6
enemy_tree_item x=0x190, y=0x1A0, unknown=0x7
enemy_tree_item x=0x1B0, y=0x1E0, unknown=0x8
enemy_tree_item x=0x250, y=0x180, unknown=0x9
enemy_tree_item x=0x280, y=0x1C0, unknown=0xA
enemy_tree_item x=0x380, y=0x210, unknown=0xB
enemy_tree_item x=0x370, y=0x290, unknown=0xC
entity_list_end
gUnk_080F50B0:: @ 080F50B0

View File

@ -432,7 +432,7 @@ SECTIONS {
asm/enemy62.o(.text);
asm/gyorgFemaleMouth.o(.text);
asm/enemy64.o(.text);
asm/treeItem.o(.text);
src/enemy/treeItem.o(.text);
asm/enemy66.o(.text);
/* END enemies */
asm/code_08049CD4.o(.text);

98
src/enemy/treeItem.c Executable file
View File

@ -0,0 +1,98 @@
#include "global.h"
#include "enemy.h"
#include "entity.h"
#include "functions.h"
static bool32 ShouldSpawnTreeItem(Entity*);
extern u32 sub_080028F4(const u8*);
extern void sub_08049CF4(Entity*);
extern const u8 gUnk_080D29E0[][16];
extern const u8 gUnk_080D2AB0[];
void TreeItem(Entity* this) {
Entity* itemEntity;
int var0;
if (this->action == 0) {
this->action++;
this->field_0x68.HALF.LO = sub_080028F4(gUnk_080D29E0[this->entityType.form]);
if (this->field_0x68.HALF.LO > 8) {
DeleteThisEntity();
}
if (this->field_0x68.HALF.LO < 8 && GetInventoryValue(0x67) == 0) {
this->field_0x68.HALF.LO = 8;
}
}
if (!ShouldSpawnTreeItem(this)) {
return;
}
var0 = this->field_0x68.HALF.LO;
if (var0 >= 0) {
if (var0 > 7) {
if (var0 == 8) {
itemEntity = CreateObject(0x40, 0x60, 0);
if (itemEntity) {
itemEntity->actionDelay = 0;
CopyPosition(this, itemEntity);
}
}
} else {
itemEntity = CreateObject(0x96, 0x7, gUnk_080D2AB0[var0]);
if (itemEntity) {
CopyPosition(this, itemEntity);
itemEntity->y.HALF.HI += 16;
itemEntity->height.HALF.HI = -32;
}
}
}
sub_08049CF4(this);
DeleteThisEntity();
}
static bool32 ShouldSpawnTreeItem(Entity* this) {
int diff;
int expectedStateX, expectedStateY;
int playerState;
if (gPlayerEntity.action != 0x6) {
return FALSE;
}
diff = gPlayerEntity.x.HALF.HI - this->x.HALF.HI;
expectedStateX = 6;
if (diff & 0x8000) {
expectedStateX = 2;
}
diff += 40;
if ((u16)diff >= 80) {
return FALSE;
}
diff = gPlayerEntity.y.HALF.HI - this->y.HALF.HI;
expectedStateY = 0;
if (diff & 0x8000) {
expectedStateY = 4;
}
diff += 40;
if ((u16)diff >= 80) {
return FALSE;
}
playerState = gPlayerEntity.animationState;
if ((playerState == 0 && expectedStateY == 0) ||
(playerState == 4 && expectedStateY == 4) ||
(playerState == 6 && expectedStateX == 6) ||
(playerState == 2 && expectedStateX == 2)) {
return TRUE;
}
return FALSE;
}