From 01fc98d161c47163817151fc27d85d18fb63dc59 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Sun, 13 Mar 2022 05:37:52 +0200 Subject: [PATCH] Decompile object37 --- asm/object/object37.s | 88 ------------------------------------ data/const/object/object37.s | 9 ---- linker.ld | 4 +- src/object/bigIceBlock.c | 3 +- src/object/object37.c | 51 +++++++++++++++++++++ src/object/object68.c | 3 +- src/object/smallIceBlock.c | 5 +- 7 files changed, 60 insertions(+), 103 deletions(-) delete mode 100644 asm/object/object37.s delete mode 100644 data/const/object/object37.s create mode 100644 src/object/object37.c diff --git a/asm/object/object37.s b/asm/object/object37.s deleted file mode 100644 index 40535c2b..00000000 --- a/asm/object/object37.s +++ /dev/null @@ -1,88 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start Object37 -Object37: @ 0x0808BDE8 - push {lr} - ldr r2, _0808BDFC @ =gUnk_08121480 - ldrb r1, [r0, #0xc] - lsls r1, r1, #2 - adds r1, r1, r2 - ldr r1, [r1] - bl _call_via_r1 - pop {pc} - .align 2, 0 -_0808BDFC: .4byte gUnk_08121480 - - thumb_func_start sub_0808BE00 -sub_0808BE00: @ 0x0808BE00 - push {r4, r5, lr} - adds r5, r0, #0 - adds r0, #0x38 - ldrb r0, [r0] - bl GetLayerByIndex - adds r4, r0, #0 - adds r0, r5, #0 - bl sub_0806F798 - lsls r0, r0, #1 - adds r0, #4 - adds r4, r4, r0 - str r4, [r5, #0x78] - ldrh r1, [r4] - adds r0, r5, #0 - adds r0, #0x70 - strh r1, [r0] - movs r0, #1 - strb r0, [r5, #0xc] - pop {r4, r5, pc} - .align 2, 0 - - thumb_func_start sub_0808BE2C -sub_0808BE2C: @ 0x0808BE2C - push {r4, lr} - adds r2, r0, #0 - ldr r0, _0808BE78 @ =gSave - ldr r1, _0808BE7C @ =0x0000024E - adds r4, r0, r1 - ldrb r0, [r4] - cmp r0, #0 - beq _0808BE74 - adds r0, r2, #0 - adds r0, #0x70 - ldr r1, [r2, #0x78] - ldrh r0, [r0] - ldrh r1, [r1] - cmp r0, r1 - beq _0808BE74 - adds r0, r2, #0 - movs r1, #0x58 - movs r2, #0 - bl CreateGroundItem - adds r1, r0, #0 - cmp r1, #0 - beq _0808BE6C - ldr r0, _0808BE80 @ =gPlayerEntity - ldrb r0, [r0, #0x14] - lsls r0, r0, #2 - strb r0, [r1, #0x15] - movs r0, #0x80 - strh r0, [r1, #0x24] - movs r0, #0x80 - lsls r0, r0, #0xa - str r0, [r1, #0x20] -_0808BE6C: - movs r0, #1 - strb r0, [r4] - bl DeleteThisEntity -_0808BE74: - pop {r4, pc} - .align 2, 0 -_0808BE78: .4byte gSave -_0808BE7C: .4byte 0x0000024E -_0808BE80: .4byte gPlayerEntity diff --git a/data/const/object/object37.s b/data/const/object/object37.s deleted file mode 100644 index 1c6c757b..00000000 --- a/data/const/object/object37.s +++ /dev/null @@ -1,9 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - .align 2 - -gUnk_08121480:: @ 08121480 - .4byte sub_0808BE00 - .4byte sub_0808BE2C diff --git a/linker.ld b/linker.ld index 2d19b8fe..8aeb00a2 100644 --- a/linker.ld +++ b/linker.ld @@ -675,7 +675,7 @@ SECTIONS { src/object/warpPoint.o(.text); src/object/object35.o(.text); asm/object/object36.o(.text); - asm/object/object37.o(.text); + src/object/object37.o(.text); src/object/jarPortal.o(.text); src/object/bossDoor.o(.text); src/object/object3A.o(.text); @@ -1406,7 +1406,7 @@ SECTIONS { src/object/object35.o(.rodata); data/animations/object/object35.o(.rodata); data/const/object/object36.o(.rodata); - data/const/object/object37.o(.rodata); + src/object/object37.o(.rodata); data/const/object/jarPortal.o(.rodata); data/animations/object/jarPortal.o(.rodata); src/object/bossDoor.o(.rodata); diff --git a/src/object/bigIceBlock.c b/src/object/bigIceBlock.c index c7d7a2bd..09407bc4 100644 --- a/src/object/bigIceBlock.c +++ b/src/object/bigIceBlock.c @@ -10,6 +10,7 @@ #include "object.h" #include "functions.h" #include "hitbox.h" +#include "item.h" typedef struct { /*0x00*/ Entity base; @@ -91,7 +92,7 @@ void BigIceBlock_Action2(BigIceBlockEntity* this) { if (super->type != 2) { SetFlag(this->unk_86); } else { - CreateGroundItemWithFlags(super, 0x53, 0, this->unk_86); + CreateGroundItemWithFlags(super, ITEM_SMALL_KEY, 0, this->unk_86); } } super->action = 3; diff --git a/src/object/object37.c b/src/object/object37.c new file mode 100644 index 00000000..99eca229 --- /dev/null +++ b/src/object/object37.c @@ -0,0 +1,51 @@ +#define NENT_DEPRECATED +#include "entity.h" +#include "functions.h" +#include "save.h" +#include "item.h" + +typedef struct { + Entity base; + u8 filler[0x8]; + u16 unk70; + u8 filler2[0x6]; + u16* unk78; +} Object37Entity; + +extern u32 sub_0806F798(Entity*); + +void Object37_Init(Object37Entity*); +void Object37_Action1(Object37Entity*); + +void Object37(Entity* this) { + static void (*const actionFuncs[])(Object37Entity*) = { + Object37_Init, + Object37_Action1, + }; + + actionFuncs[this->action]((Object37Entity*)this); +} + +void Object37_Init(Object37Entity* this) { + u16* puVar1; + + puVar1 = GetLayerByIndex(super->collisionLayer)->mapData + sub_0806F798(super); + this->unk78 = puVar1; + this->unk70 = *puVar1; + super->action = 1; +} + +void Object37_Action1(Object37Entity* this) { + Entity* item; + + if ((gSave.unk24E[0] != 0) && (this->unk70 != *this->unk78)) { + item = CreateGroundItem(super, ITEM_RUPEE100, 0); + if (item != 0) { + item->direction = gPlayerEntity.animationState << 2; + item->speed = 0x80; + item->zVelocity = 0x20000; + } + gSave.unk24E[0] = 1; + DeleteThisEntity(); + } +} diff --git a/src/object/object68.c b/src/object/object68.c index e5265aa9..d26bb550 100644 --- a/src/object/object68.c +++ b/src/object/object68.c @@ -10,6 +10,7 @@ #include "global.h" #include "object.h" #include "functions.h" +#include "item.h" typedef struct { /*0x00*/ Entity base; @@ -66,7 +67,7 @@ void sub_08094774(Object68Entity* this) { } break; case 2: - child = CreateGroundItem(&gPlayerEntity, 0x60, 0); + child = CreateGroundItem(&gPlayerEntity, ITEM_FAIRY, 0); super->child = child; if (child != NULL) { child->actionDelay = 1; diff --git a/src/object/smallIceBlock.c b/src/object/smallIceBlock.c index 9e2cf781..3ffedb89 100644 --- a/src/object/smallIceBlock.c +++ b/src/object/smallIceBlock.c @@ -10,6 +10,7 @@ #include "object.h" #include "functions.h" #include "hitbox.h" +#include "item.h" typedef struct { /*0x00*/ Entity base; @@ -138,10 +139,10 @@ void SmallIceBlock_Action3(SmallIceBlockEntity* this) { } sub_0805EC9C(super, 0x100, gUnk_08123748[super->actionDelay >> 5], 0); if (super->type == 1) { - CreateGroundItemWithFlags(super, 0x53, 0, this->unk_86); + CreateGroundItemWithFlags(super, ITEM_SMALL_KEY, 0, this->unk_86); SoundReq(SFX_SECRET); } else if (super->type == 2) { - CreateGroundItemWithFlags(super, 0x52, 0, this->unk_86); + CreateGroundItemWithFlags(super, ITEM_BIG_KEY, 0, this->unk_86); SoundReq(SFX_SECRET); } super->action = 4;