From 42cf7ea569adb8ab8851b856740deb7985034e30 Mon Sep 17 00:00:00 2001 From: theo3 Date: Wed, 30 Mar 2022 19:27:53 -0700 Subject: [PATCH 1/5] sub_08064B88 ok --- asm/non_matching/sturgeon/sub_08064B88.inc | 83 ---------------------- src/npc/sturgeon.c | 40 ++++++++++- 2 files changed, 39 insertions(+), 84 deletions(-) delete mode 100644 asm/non_matching/sturgeon/sub_08064B88.inc diff --git a/asm/non_matching/sturgeon/sub_08064B88.inc b/asm/non_matching/sturgeon/sub_08064B88.inc deleted file mode 100644 index c1b3a290..00000000 --- a/asm/non_matching/sturgeon/sub_08064B88.inc +++ /dev/null @@ -1,83 +0,0 @@ - .syntax unified - push {r4, r5, lr} - adds r4, r0, #0 - adds r5, r4, #0 - adds r5, #0x39 - movs r0, #0 - ldrsb r0, [r5, r0] - cmp r0, #1 - beq _08064BFA - cmp r0, #1 - bgt _08064BA2 - cmp r0, #0 - beq _08064BA8 - b _08064BFA -_08064BA2: - cmp r0, #2 - beq _08064BCE - b _08064BFA -_08064BA8: - adds r0, r4, #0 - bl sub_0806EE20 - adds r2, r0, #0 - adds r0, r4, #0 - adds r0, #0x3e - ldrb r0, [r0] - strb r0, [r4, #0x14] - cmp r2, #0 - beq _08064BC6 - movs r1, #0x7f - ands r1, r2 - adds r0, r4, #0 - bl InitializeAnimation -_08064BC6: - adds r0, r4, #0 - bl GetNextFrame - b _08064C28 -_08064BCE: - movs r0, #3 - strb r0, [r4, #0xc] - adds r0, r4, #0 - bl GetAnimationState - adds r1, r0, #0 - cmp r1, #0 - bge _08064BE0 - ldrb r1, [r4, #0x14] -_08064BE0: - adds r0, r4, #0 - adds r0, #0x58 - ldrb r0, [r0] - strb r0, [r4, #0xf] - adds r0, r4, #0 - bl InitializeAnimation - movs r0, #0 - strb r0, [r5] - adds r0, r4, #0 - bl sub_0806F118 - b _08064C28 -_08064BFA: - movs r0, #2 - strb r0, [r4, #0xc] - adds r0, r4, #0 - bl GetAnimationState - adds r1, r0, #0 - cmp r1, #0 - bge _08064C0C - ldrb r1, [r4, #0x14] -_08064C0C: - adds r0, r4, #0 - adds r0, #0x58 - ldrb r0, [r0] - strb r0, [r4, #0xf] - adds r0, r4, #0 - bl InitializeAnimation - adds r1, r4, #0 - adds r1, #0x39 - movs r0, #0 - strb r0, [r1] - adds r0, r4, #0 - bl sub_08064CD8 -_08064C28: - pop {r4, r5, pc} - .align 2, 0 - .syntax divided diff --git a/src/npc/sturgeon.c b/src/npc/sturgeon.c index 90903566..89e06fbb 100644 --- a/src/npc/sturgeon.c +++ b/src/npc/sturgeon.c @@ -14,6 +14,8 @@ void sub_08064CC0(Entity* this); extern void (*const gUnk_0810FA44[])(Entity*); void sub_08064C9C(Entity* this); +void sub_08064CD8(Entity* this); + void Sturgeon(Entity* this) { if ((this->flags & ENT_SCRIPTED) == 0) { gUnk_0810FA44[this->action](this); @@ -57,7 +59,43 @@ void sub_08064B44(Entity* this) { } } -ASM_FUNC("asm/non_matching/sturgeon/sub_08064B88.inc", void sub_08064B88(Entity* this)) +void sub_08064B88(Entity* this) { + s32 temp; + s32 temp2; + + switch (this->interactType) { + case 0: + temp = sub_0806EE20(this); + this->animationState = this->knockbackDirection; + if (temp != 0) { + InitializeAnimation(this, temp & 0x7f); + } + GetNextFrame(this); + break; + case 2: + this->action = 3; + temp2 = GetAnimationState(this); + if (temp2 < 0) { + temp2 = this->animationState; + } + this->subtimer = this->animIndex; + InitializeAnimation(this, temp2); + this->interactType = 0; + sub_0806F118(this); + break; + case 1: + default: + this->action = 2; + temp2 = GetAnimationState(this); + if (temp2 < 0) { + temp2 = this->animationState; + } + this->subtimer = this->animIndex; + InitializeAnimation(this, temp2); + this->interactType = 0; + sub_08064CD8(this); + } +} void sub_08064C2C(Entity* this) { if ((gMessage.doTextBox & 0x7f) == 0) { From 12e5608104c4fa141858715bc1e4c1fa912b44c0 Mon Sep 17 00:00:00 2001 From: theo3 Date: Wed, 30 Mar 2022 19:31:09 -0700 Subject: [PATCH 2/5] sub_080385CC ok --- .../cloudPiranha/sub_080385CC.inc | 65 ------------------- src/enemy/cloudPiranha.c | 9 +-- 2 files changed, 2 insertions(+), 72 deletions(-) delete mode 100644 asm/non_matching/cloudPiranha/sub_080385CC.inc diff --git a/asm/non_matching/cloudPiranha/sub_080385CC.inc b/asm/non_matching/cloudPiranha/sub_080385CC.inc deleted file mode 100644 index 1c1502d3..00000000 --- a/asm/non_matching/cloudPiranha/sub_080385CC.inc +++ /dev/null @@ -1,65 +0,0 @@ - .syntax unified - push {r4, r5, r6, lr} - adds r4, r0, #0 - bl sub_080387F0 - adds r0, r4, #0 - movs r1, #0x60 - bl sub_0803872C - cmp r0, #0 - beq _08038604 - movs r0, #3 - strb r0, [r4, #0xc] - movs r0, #0xc - strb r0, [r4, #0xf] - movs r0, #0x80 - strh r0, [r4, #0x24] - ldr r1, [r4, #0x54] - adds r0, r4, #0 - bl sub_0806FCAC - strb r0, [r4, #0x14] - lsls r0, r0, #2 - strb r0, [r4, #0x15] - ldrb r1, [r4, #0x14] - adds r0, r4, #0 - bl InitializeAnimation - b _08038648 -_08038604: - ldrb r0, [r4, #0xf] - subs r0, #1 - strb r0, [r4, #0xf] - lsls r0, r0, #0x18 - cmp r0, #0 - bne _08038648 - movs r6, #0x10 - strb r6, [r4, #0xf] - ldr r1, [r4, #0x54] - cmp r1, #0 - beq _08038622 - adds r0, r4, #0 - bl sub_0806FCAC - b _08038638 -_08038622: - ldrb r5, [r4, #0x14] - bl Random - ands r0, r6 - cmp r0, #0 - beq _08038632 - adds r1, r5, #2 - b _08038634 -_08038632: - adds r1, r5, #6 -_08038634: - movs r0, #7 - ands r0, r1 -_08038638: - strb r0, [r4, #0x14] - ldrb r0, [r4, #0x14] - lsls r0, r0, #2 - strb r0, [r4, #0x15] - ldrb r1, [r4, #0x14] - adds r0, r4, #0 - bl InitializeAnimation -_08038648: - pop {r4, r5, r6, pc} - .align 2, 0 - .syntax divided diff --git a/src/enemy/cloudPiranha.c b/src/enemy/cloudPiranha.c index 5f4eb371..9e519d4b 100644 --- a/src/enemy/cloudPiranha.c +++ b/src/enemy/cloudPiranha.c @@ -128,7 +128,7 @@ void CloudPiranha_Action1(CloudPiranhaEntity* this) { } } -NONMATCH("asm/non_matching/cloudPiranha/sub_080385CC.inc", void sub_080385CC(CloudPiranhaEntity* this)) { +void sub_080385CC(CloudPiranhaEntity* this) { u32 tmp; sub_080387F0(this); if (sub_0803872C(this, 0x60)) { @@ -145,18 +145,13 @@ NONMATCH("asm/non_matching/cloudPiranha/sub_080385CC.inc", void sub_080385CC(Clo super->animationState = sub_0806FCAC(super, super->child); } else { tmp = super->animationState; - if ((Random() & 0x10) != 0) { - super->animationState = (tmp + 2) & 7; - } else { - super->animationState = (tmp + 6) & 7; - } + super->animationState = (Random() & 0x10) ? ((tmp + 2) & 7) : ((tmp + 6) & 7); } super->direction = super->animationState << 2; InitializeAnimation(super, super->animationState); } } } -END_NONMATCH void CloudPiranha_Action3(CloudPiranhaEntity* this) { s32 tmp; From 3d2577eddf3b336a5664ee2089e6c8ade2c15716 Mon Sep 17 00:00:00 2001 From: theo3 Date: Wed, 30 Mar 2022 20:32:34 -0700 Subject: [PATCH 3/5] postman matching attempts --- src/npc/postman.c | 78 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/src/npc/postman.c b/src/npc/postman.c index d8c61312..bced68a9 100644 --- a/src/npc/postman.c +++ b/src/npc/postman.c @@ -9,6 +9,8 @@ extern void sub_080604DC(Entity*); extern void sub_080606D8(Entity*); extern void sub_080606C0(Entity*); +extern const s8 gUnk_0810AA70[]; + typedef struct { s16 x; s16 y; @@ -192,9 +194,81 @@ void sub_0806075C(Entity* this) { this->field_0x68.HALF.HI = 0xff; } -ASM_FUNC("asm/non_matching/postman/sub_0806076C.inc", void sub_0806076C(Entity* this, ScriptExecutionContext* context)) +NONMATCH("asm/non_matching/postman/sub_0806076C.inc", + void sub_0806076C(Entity* this, ScriptExecutionContext* context)) { + s8* p; + u32 tmp, size; + int i; -ASM_FUNC("asm/non_matching/postman/sub_080608E4.inc", void sub_080608E4(Entity* this, ScriptExecutionContext* context)) + if (this->z.WORD < 0) { + gActiveScriptInfo.commandSize = 0; + return; + } + + this->field_0x68.HALF.HI++; + this->collisionLayer = 1; + sub_080606C0(this); + p = &gUnk_0810A918[this->field_0x68.HALF.LO][this->field_0x68.HALF.HI]; + do { + switch (p[0] + 5) { + case 5: + this->field_0x68.HALF.LO = p[(s32)Random() % p[1] + 2]; + this->field_0x68.HALF.HI = 0; + return; + case 4: + this->field_0x6a.HWORD = 300; + break; + case 3: + this->collisionLayer = 1; + break; + case 2: + this->collisionLayer = 2; + break; + case 1: + context->wait = 30; + this->spriteSettings.draw = 0; + break; + case 0: + size = p[1]; + tmp = Random() % size; + for (i = 0; i < size; ++i) { + this->field_0x68.HALF.HI = p[i + 2]; + this->x.HALF.HI = + gUnk_0810A66C[gUnk_0810A918[this->field_0x68.HALF.LO][0]].x + gRoomControls.origin_x; + this->y.HALF.HI = + gUnk_0810A66C[gUnk_0810A918[this->field_0x68.HALF.LO][0]].y + gRoomControls.origin_y; + if (!CheckOnScreen(this)) { + break; + } + tmp = (tmp + 1) % size; + } + this->field_0x68.HALF.LO = 0; + return; + default: + return; + } + this->field_0x68.HALF.LO++; + p++; + } while (1); +} +END_NONMATCH + +NONMATCH("asm/non_matching/postman/sub_080608E4.inc", + void sub_080608E4(Entity* this, ScriptExecutionContext* context)) { + context->condition = 0; + if (this->z.WORD >= 0) { + if ((this->collisionLayer != 1 || gPlayerEntity.collisionLayer != 2) && + (this->collisionLayer != 2 || gPlayerEntity.collisionLayer != 1)) { + const s8* ptr = &gUnk_0810AA70[context->intVariable * 16 + (this->animationState >> 1) * 4]; + if (ptr[0] + gPlayerEntity.x.HALF.HI + ptr[2] - this->x.HALF.HI < ptr[2] * 2 && + ptr[1] + gPlayerEntity.y.HALF.HI + ptr[3] - this->y.HALF.HI < ptr[3] * 2) { + context->condition = 1; + this->field_0x6a.HWORD += 2; + } + } + } +} +END_NONMATCH void Postman_Fusion(Entity* this) { if (this->action == 0) { From 00b400a26f81b86643aae37714d8dcc5d526711a Mon Sep 17 00:00:00 2001 From: theo3 Date: Wed, 30 Mar 2022 21:09:58 -0700 Subject: [PATCH 4/5] npc23 match attempt --- src/npc/npc23.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/npc/npc23.c b/src/npc/npc23.c index c0b01efb..c684da71 100644 --- a/src/npc/npc23.c +++ b/src/npc/npc23.c @@ -101,6 +101,51 @@ void sub_08066474(void) { ASM_FUNC("asm/non_matching/npc23/sub_08066490.inc", void sub_08066490(Entity* this, Entity* entity)) -ASM_FUNC("asm/non_matching/npc23/sub_0806650C.inc", bool32 sub_0806650C(Entity* this)) +// px needs to be used in both r5 and r7 +NONMATCH("asm/non_matching/npc23/sub_0806650C.inc", bool32 sub_0806650C(Entity* this)) { + u32 dir = 0; + s32 px = gPlayerEntity.x.HALF_U.HI; + s32 py = gPlayerEntity.y.HALF_U.HI; -ASM_FUNC("asm/non_matching/npc23/sub_08066570.inc", void sub_08066570(Entity* this)) + if (py < this->field_0x80.HWORD + 16) { + dir = 4; + } else { + if (px < this->field_0x7c.HALF_U.HI + 2) { + dir = 2; + } + if (px > this->field_0x7c.HALF_U.HI + 6) { + dir = 6; + } + if (dir == 0) { + gPlayerEntity.speed = 0; + } + } + + if (gPlayerEntity.action != PLAYER_ROOM_EXIT) { + if (dir == 0) { + return 0; + } + sub_08078AC0(8, 0, 0); + gPlayerEntity.animationState = dir; + gPlayerEntity.direction = Direction8FromAnimationState(dir); + } + return 1; +} +END_NONMATCH + +NONMATCH("asm/non_matching/npc23/sub_08066570.inc", void sub_08066570(Entity* this)) { + if (this->frame & ANIM_DONE) { + return; + } + + if (this->action == 3 && sub_0806FC80(this, &gPlayerEntity, 0x50)) { + u32 direction = GetFacingDirection(this, &gPlayerEntity); + bool32 cond = (this->direction & 0x18) == (direction & 0x18) && ((this->direction + 5) & 7) < 3 && + ((direction + 5) & 7) < 3; + if (!cond) { + this->direction = direction; + InitializeAnimation(this, ((u32)(this->direction + 4) & 0x18) >> 3); + } + } +} +END_NONMATCH From 5fedcc4e27d42be05644cbba29a793ad60a6dec8 Mon Sep 17 00:00:00 2001 From: theo3 Date: Wed, 30 Mar 2022 21:17:53 -0700 Subject: [PATCH 5/5] cf --- src/npc/sturgeon.c | 60 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/npc/sturgeon.c b/src/npc/sturgeon.c index 89e06fbb..a181b50c 100644 --- a/src/npc/sturgeon.c +++ b/src/npc/sturgeon.c @@ -64,36 +64,36 @@ void sub_08064B88(Entity* this) { s32 temp2; switch (this->interactType) { - case 0: - temp = sub_0806EE20(this); - this->animationState = this->knockbackDirection; - if (temp != 0) { - InitializeAnimation(this, temp & 0x7f); - } - GetNextFrame(this); - break; - case 2: - this->action = 3; - temp2 = GetAnimationState(this); - if (temp2 < 0) { - temp2 = this->animationState; - } - this->subtimer = this->animIndex; - InitializeAnimation(this, temp2); - this->interactType = 0; - sub_0806F118(this); - break; - case 1: - default: - this->action = 2; - temp2 = GetAnimationState(this); - if (temp2 < 0) { - temp2 = this->animationState; - } - this->subtimer = this->animIndex; - InitializeAnimation(this, temp2); - this->interactType = 0; - sub_08064CD8(this); + case 0: + temp = sub_0806EE20(this); + this->animationState = this->knockbackDirection; + if (temp != 0) { + InitializeAnimation(this, temp & 0x7f); + } + GetNextFrame(this); + break; + case 2: + this->action = 3; + temp2 = GetAnimationState(this); + if (temp2 < 0) { + temp2 = this->animationState; + } + this->subtimer = this->animIndex; + InitializeAnimation(this, temp2); + this->interactType = 0; + sub_0806F118(this); + break; + case 1: + default: + this->action = 2; + temp2 = GetAnimationState(this); + if (temp2 < 0) { + temp2 = this->animationState; + } + this->subtimer = this->animIndex; + InitializeAnimation(this, temp2); + this->interactType = 0; + sub_08064CD8(this); } }