From fbf7f49146a3887cf79c40d2a4798c08e1e932f3 Mon Sep 17 00:00:00 2001 From: TauNeutrino <1tauneutrino@gmail.com> Date: Thu, 29 Oct 2020 16:39:13 +0100 Subject: [PATCH 1/3] Decompile smallPesto.c --- asm/smallPesto.s | 183 ----------------------------------------- linker.ld | 2 +- src/enemy/smallPesto.c | 83 +++++++++++++++++++ 3 files changed, 84 insertions(+), 184 deletions(-) delete mode 100644 asm/smallPesto.s diff --git a/asm/smallPesto.s b/asm/smallPesto.s deleted file mode 100644 index 37b369bd..00000000 --- a/asm/smallPesto.s +++ /dev/null @@ -1,183 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_08031714 -sub_08031714: @ 0x08031714 - push {r4, lr} - adds r4, r0, #0 - bl sub_080317B4 - ldrb r0, [r4, #0xf] - subs r0, #1 - strb r0, [r4, #0xf] - lsls r0, r0, #0x18 - cmp r0, #0 - bne _0803176E - bl Random - movs r1, #0xf - ands r0, r1 - adds r0, #0x10 - strb r0, [r4, #0xf] - adds r0, r4, #0 - bl sub_08049FA0 - cmp r0, #0 - bne _08031750 - ldrb r1, [r4, #0xf] - movs r0, #1 - ands r0, r1 - cmp r0, #0 - beq _08031750 - adds r0, r4, #0 - bl sub_08049EE4 - b _08031766 -_08031750: - ldrb r0, [r4, #0x15] - adds r0, #0x18 - strb r0, [r4, #0x15] - bl Random - movs r1, #0xe - ands r0, r1 - ldrb r1, [r4, #0x15] - adds r0, r0, r1 - movs r1, #0x1f - ands r0, r1 -_08031766: - strb r0, [r4, #0x15] - adds r0, r4, #0 - bl sub_080317E0 -_0803176E: - pop {r4, pc} - - thumb_func_start sub_08031770 -sub_08031770: @ 0x08031770 - push {r4, lr} - adds r1, r0, #0 - adds r4, r1, #0 - adds r4, #0x80 - ldrh r0, [r4] - cmp r0, #0 - beq _08031790 - subs r0, #1 - strh r0, [r4] - lsls r0, r0, #0x10 - cmp r0, #0 - bne _080317B2 - adds r0, r1, #0 - bl sub_08031840 - b _080317B2 -_08031790: - ldr r0, [r1, #0x54] - cmp r0, #0 - bne _080317AA - bl Random - movs r1, #0x7f - ands r0, r1 - movs r2, #0x80 - lsls r2, r2, #2 - adds r1, r2, #0 - orrs r0, r1 - strh r0, [r4] - b _080317B2 -_080317AA: - ldr r0, [r0, #4] - cmp r0, #0 - bne _080317B2 - str r0, [r1, #0x54] -_080317B2: - pop {r4, pc} - - thumb_func_start sub_080317B4 -sub_080317B4: @ 0x080317B4 - push {r4, lr} - adds r4, r0, #0 - bl Random - movs r1, #0x30 - ands r1, r0 - movs r2, #0xd - rsbs r2, r2, #0 - adds r0, r2, #0 - cmp r1, #0 - beq _080317D0 - movs r1, #0xc - rsbs r1, r1, #0 - adds r0, r1, #0 -_080317D0: - strh r0, [r4, #0x36] - adds r0, r4, #0 - bl sub_0806F69C - adds r0, r4, #0 - bl GetNextFrame - pop {r4, pc} - - thumb_func_start sub_080317E0 -sub_080317E0: @ 0x080317E0 - push {lr} - ldrb r1, [r0, #0x15] - adds r1, #2 - movs r2, #0x1c - ands r1, r2 - lsrs r1, r1, #2 - strb r1, [r0, #0x14] - ldrb r1, [r0, #0x14] - bl InitializeAnimation - pop {pc} - .align 2, 0 - - thumb_func_start sub_080317F8 -sub_080317F8: @ 0x080317F8 - push {r4, r5, r6, lr} - adds r4, r0, #0 - bl Random - movs r1, #0x18 - ands r0, r1 - movs r5, #1 - strb r5, [r4, #0xc] - movs r6, #0 - ldr r1, _08031838 @ =0x0000FFF4 - strh r1, [r4, #0x36] - adds r1, r4, #0 - adds r1, #0x38 - strb r5, [r1] - adds r3, r4, #0 - adds r3, #0x3c - ldrb r2, [r3] - movs r1, #0x10 - orrs r1, r2 - strb r1, [r3] - strb r5, [r4, #0x1c] - strb r0, [r4, #0x15] - ldr r0, _0803183C @ =gUnk_080CE560 - str r0, [r4, #0x48] - adds r0, r4, #0 - bl sub_080317E0 - strb r6, [r4, #0xe] - movs r0, #0x20 - strb r0, [r4, #0xf] - pop {r4, r5, r6, pc} - .align 2, 0 -_08031838: .4byte 0x0000FFF4 -_0803183C: .4byte gUnk_080CE560 - - thumb_func_start sub_08031840 -sub_08031840: @ 0x08031840 - push {r4, r5, lr} - adds r5, r0, #0 - ldrb r1, [r5, #0xa] - movs r0, #0x2d - bl CreateEnemy - adds r4, r0, #0 - cmp r4, #0 - beq _08031862 - adds r0, r5, #0 - adds r1, r4, #0 - bl CopyPosition - str r5, [r4, #0x50] - str r4, [r5, #0x54] - movs r0, #1 - strb r0, [r4, #0xb] -_08031862: - pop {r4, r5, pc} diff --git a/linker.ld b/linker.ld index 655db65e..72be4378 100644 --- a/linker.ld +++ b/linker.ld @@ -304,6 +304,7 @@ SECTIONS { src/code_08018C58.o(.text); src/item11.o(.text); asm/item11.o(.text); + src/createBowEntity.o(.text); asm/createBowEntity.o(.text); asm/bowUse.o(.text); asm/sub_08019410.o(.text); @@ -373,7 +374,6 @@ SECTIONS { asm/eyegore.o(.text); asm/rope.o(.text); src/enemy/smallPesto.o(.text); - asm/smallPesto.o(.text); src/enemy/acroBandits.o(.text); src/enemy/bladeTrap.o(.text); src/enemy/keaton.o(.text); diff --git a/src/enemy/smallPesto.c b/src/enemy/smallPesto.c index 94eb8822..441cb09d 100644 --- a/src/enemy/smallPesto.c +++ b/src/enemy/smallPesto.c @@ -8,11 +8,22 @@ extern u32 sub_0806F3E4(); extern void sub_0804A7D4(Entity*); extern void sub_0804A720(Entity*); extern void sub_080317F8(Entity*); +extern u32 sub_08049FA0(Entity*); +extern u32 Random(); +extern u32 sub_08049EE4(Entity*); +extern void sub_0806F69C(Entity*); extern void (*gUnk_080CE530[])(Entity*); extern void (*gUnk_080CE548[])(Entity*); extern void (*gUnk_080CE554[])(Entity*); +void sub_080317B4(Entity*); +void sub_080317E0(Entity*); +void sub_080317F8(Entity*); +void sub_08031840(Entity*); + +extern BoundingBox gUnk_080CE560; + void SmallPesto(Entity *this) { gUnk_080CE530[GetNextFunction(this)](this); @@ -66,3 +77,75 @@ void sub_08031704(Entity *this) sub_0804A720(this); sub_080317F8(this); } + +void sub_08031714(Entity* entity){ + u8 newDirection; + sub_080317B4(entity); + if(--entity->field_0xf == 0){ + entity->field_0xf = (Random() & 0xf) + 0x10; + if(sub_08049FA0(entity) == 0){ + if((entity->field_0xf & 1) != 0){ + entity->direction = sub_08049EE4(entity); + goto _08031766; + } + } + entity->direction += 0x18; + entity->direction = ((Random() & 0xe) + entity->direction) & 0x1f; + _08031766: + sub_080317E0(entity); + + } +} + +void sub_08031770(Entity* entity){ + if(entity->field_0x80.HWORD != 0){ + if(--entity->field_0x80.HWORD == 0){ + sub_08031840(entity); + } + }else if(entity->attachedEntity == NULL){ + entity->field_0x80.HWORD = (Random() & 0x7f) | (0x80 << 2); + }else{ + if(entity->attachedEntity->next == NULL){ + entity->attachedEntity = NULL; + } + } + return; +} + +void sub_080317B4(Entity* entity){ + + entity->height.HALF.HI = ((Random() & 0x30) != 0) ? -0xc : -0xd; + sub_0806F69C(entity); + GetNextFrame(entity); +} + + +void sub_080317E0(Entity *entity){ + entity->animationState = ((u8)(entity->direction + 2) & 0x1c) >> 2; + InitializeAnimation(entity, entity->animationState); +} + +void sub_080317F8(Entity *entity){ + u8 newDirection = Random() & 0x18; + entity->action = 1; + entity->height.HALF.HI = 0x0000FFF4; + entity->collisionLayer = 1; + entity->field_0x3c |= 0x10; + entity->field_0x1c = 1; + entity->direction = newDirection; + entity->boundingBox = &gUnk_080CE560; + sub_080317E0(entity); + entity->actionDelay = 0; + entity->field_0xf = 0x20; +} + +void sub_08031840(Entity* entity){ + Entity *enemy = CreateEnemy(0x2d, entity->entityType.form); + if(enemy!= NULL){ + CopyPosition(entity, enemy); + enemy->parent = entity; + entity->attachedEntity = enemy; + enemy->entityType.parameter = 1; + } +} + From e5bee591c9c55f22bf05b8ccdd994f611ce89bc7 Mon Sep 17 00:00:00 2001 From: TauNeutrino <1tauneutrino@gmail.com> Date: Thu, 29 Oct 2020 21:47:37 +0100 Subject: [PATCH 2/3] start createBowEntity.c --- asm/createBowEntity.s | 13 ------------- src/createBowEntity.c | 8 ++++++++ 2 files changed, 8 insertions(+), 13 deletions(-) create mode 100644 src/createBowEntity.c diff --git a/asm/createBowEntity.s b/asm/createBowEntity.s index 554d68a7..cefbb1e6 100644 --- a/asm/createBowEntity.s +++ b/asm/createBowEntity.s @@ -6,19 +6,6 @@ .text - thumb_func_start sub_08018FCC -sub_08018FCC: @ 0x08018FCC - push {lr} - ldr r2, _08018FE0 @ =gUnk_080B3E30 - ldrb r1, [r0, #0xc] - lsls r1, r1, #2 - adds r1, r1, r2 - ldr r1, [r1] - bl _call_via_r1 - pop {pc} - .align 2, 0 -_08018FE0: .4byte gUnk_080B3E30 - thumb_func_start sub_08018FE4 sub_08018FE4: @ 0x08018FE4 push {r4, r5, r6, lr} diff --git a/src/createBowEntity.c b/src/createBowEntity.c new file mode 100644 index 00000000..5f3c4f39 --- /dev/null +++ b/src/createBowEntity.c @@ -0,0 +1,8 @@ +#include "global.h" + +extern long (*gUnk_080B3E30[])(u8*); + +long sub_08018FCC(u8 *r0) +{ + return gUnk_080B3E30[(r0[0xC])](r0); +} From 9087b487c57cb1202e1488bb8811cc25c211c3eb Mon Sep 17 00:00:00 2001 From: TauNeutrino <1tauneutrino@gmail.com> Date: Sun, 1 Nov 2020 13:03:33 +0100 Subject: [PATCH 3/3] Update smallPesto.c createBowEntity.c --- src/createBowEntity.c | 8 ++-- src/enemy/smallPesto.c | 105 +++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 61 deletions(-) diff --git a/src/createBowEntity.c b/src/createBowEntity.c index 5f3c4f39..0e1f0ef8 100644 --- a/src/createBowEntity.c +++ b/src/createBowEntity.c @@ -1,8 +1,8 @@ #include "global.h" +#include "entity.h" -extern long (*gUnk_080B3E30[])(u8*); +extern void (*const gUnk_080B3E30[])(Entity*); -long sub_08018FCC(u8 *r0) -{ - return gUnk_080B3E30[(r0[0xC])](r0); +void sub_08018FCC(Entity* this){ + gUnk_080B3E30[(this->action)](this); } diff --git a/src/enemy/smallPesto.c b/src/enemy/smallPesto.c index 441cb09d..299d9219 100644 --- a/src/enemy/smallPesto.c +++ b/src/enemy/smallPesto.c @@ -24,20 +24,17 @@ void sub_08031840(Entity*); extern BoundingBox gUnk_080CE560; -void SmallPesto(Entity *this) -{ +void SmallPesto(Entity *this){ gUnk_080CE530[GetNextFunction(this)](this); } -void sub_08031680(Entity *this) -{ +void sub_08031680(Entity *this){ gUnk_080CE548[this->action](this); } void nullsub_152(){} -void sub_0803169C(Entity *this) -{ +void sub_0803169C(Entity *this){ s32 iVar1; GetNextFrame(this); @@ -54,97 +51,91 @@ void sub_0803169C(Entity *this) } } -void sub_080316DC(Entity *this) -{ +void sub_080316DC(Entity *this){ this->previousActionFlag = 1; this->field_0x1d = 0x3c; } -void sub_080316E8(Entity *this) -{ +void sub_080316E8(Entity *this){ sub_0806F4E8(this); } -void sub_080316F0(Entity *this) -{ +void sub_080316F0(Entity *this){ if (sub_0806F3E4()) { sub_0804A7D4(this); } } -void sub_08031704(Entity *this) -{ +void sub_08031704(Entity *this){ sub_0804A720(this); sub_080317F8(this); } -void sub_08031714(Entity* entity){ +void sub_08031714(Entity* this){ u8 newDirection; - sub_080317B4(entity); - if(--entity->field_0xf == 0){ - entity->field_0xf = (Random() & 0xf) + 0x10; - if(sub_08049FA0(entity) == 0){ - if((entity->field_0xf & 1) != 0){ - entity->direction = sub_08049EE4(entity); + sub_080317B4(this); + if(--this->field_0xf == 0){ + this->field_0xf = (Random() & 0xf) + 0x10; + if(sub_08049FA0(this) == 0){ + if((this->field_0xf & 1) != 0){ + this->direction = sub_08049EE4(this); goto _08031766; } } - entity->direction += 0x18; - entity->direction = ((Random() & 0xe) + entity->direction) & 0x1f; + this->direction += 0x18; + this->direction = ((Random() & 0xe) + this->direction) & 0x1f; _08031766: - sub_080317E0(entity); - + sub_080317E0(this); } } -void sub_08031770(Entity* entity){ - if(entity->field_0x80.HWORD != 0){ - if(--entity->field_0x80.HWORD == 0){ - sub_08031840(entity); +void sub_08031770(Entity* this){ + if(this->field_0x80.HWORD != 0){ + if(--this->field_0x80.HWORD == 0){ + sub_08031840(this); } - }else if(entity->attachedEntity == NULL){ - entity->field_0x80.HWORD = (Random() & 0x7f) | (0x80 << 2); + }else if(this->attachedEntity == NULL){ + this->field_0x80.HWORD = (Random() & 0x7f) | (0x80 << 2); }else{ - if(entity->attachedEntity->next == NULL){ - entity->attachedEntity = NULL; + if(this->attachedEntity->next == NULL){ + this->attachedEntity = NULL; } } return; } -void sub_080317B4(Entity* entity){ - - entity->height.HALF.HI = ((Random() & 0x30) != 0) ? -0xc : -0xd; - sub_0806F69C(entity); - GetNextFrame(entity); +void sub_080317B4(Entity* this){ + this->height.HALF.HI = ((Random() & 0x30) != 0) ? -0xc : -0xd; + sub_0806F69C(this); + GetNextFrame(this); } -void sub_080317E0(Entity *entity){ - entity->animationState = ((u8)(entity->direction + 2) & 0x1c) >> 2; - InitializeAnimation(entity, entity->animationState); +void sub_080317E0(Entity *this){ + this->animationState = ((u8)(this->direction + 2) & 0x1c) >> 2; + InitializeAnimation(this, this->animationState); } -void sub_080317F8(Entity *entity){ +void sub_080317F8(Entity *this){ u8 newDirection = Random() & 0x18; - entity->action = 1; - entity->height.HALF.HI = 0x0000FFF4; - entity->collisionLayer = 1; - entity->field_0x3c |= 0x10; - entity->field_0x1c = 1; - entity->direction = newDirection; - entity->boundingBox = &gUnk_080CE560; - sub_080317E0(entity); - entity->actionDelay = 0; - entity->field_0xf = 0x20; + this->action = 1; + this->height.HALF.HI = 0x0000FFF4; + this->collisionLayer = 1; + this->field_0x3c |= 0x10; + this->field_0x1c = 1; + this->direction = newDirection; + this->boundingBox = &gUnk_080CE560; + sub_080317E0(this); + this->actionDelay = 0; + this->field_0xf = 0x20; } -void sub_08031840(Entity* entity){ - Entity *enemy = CreateEnemy(0x2d, entity->entityType.form); +void sub_08031840(Entity* this){ + Entity *enemy = CreateEnemy(0x2d, this->entityType.form); if(enemy!= NULL){ - CopyPosition(entity, enemy); - enemy->parent = entity; - entity->attachedEntity = enemy; + CopyPosition(this, enemy); + enemy->parent = this; + this->attachedEntity = enemy; enemy->entityType.parameter = 1; } }