diff --git a/asm/non_matching/common/sub_0801E6C8.inc b/asm/non_matching/common/sub_0801E6C8.inc deleted file mode 100644 index 7bb2b576..00000000 --- a/asm/non_matching/common/sub_0801E6C8.inc +++ /dev/null @@ -1,59 +0,0 @@ - .syntax unified - push {r4, r5, r6, lr} - adds r4, r0, #0 - subs r0, r4, #1 - cmp r0, #0x63 - bhi _0801E722 - movs r1, #0 - ldr r5, _0801E724 @ =gFuseInfo - ldr r3, _0801E728 @ =gUnk_02002C01 - movs r2, #0xf1 -_0801E6DA: - adds r0, r1, r3 - ldrb r6, [r0] - cmp r4, r6 - bne _0801E6E4 - strb r2, [r0] -_0801E6E4: - adds r1, #1 - cmp r1, #0x7f - bls _0801E6DA - ldr r0, [r5, #0xc] - bl sub_08002632 - adds r1, r0, #0 - subs r0, r1, #1 - cmp r0, #0x7e - bhi _0801E70A - ldr r0, _0801E72C @ =gSave - ldr r2, _0801E730 @ =0x000001C1 - adds r0, r0, r2 - adds r1, r1, r0 - ldrb r0, [r1] - cmp r0, #0xf1 - bne _0801E70A - movs r0, #0xf2 - strb r0, [r1] -_0801E70A: - movs r1, #0 - ldr r0, _0801E734 @ =gUnk_03003DF0 - movs r2, #0xf1 - adds r0, #0xb -_0801E712: - ldrb r3, [r0] - cmp r4, r3 - bne _0801E71A - strb r2, [r0] -_0801E71A: - adds r0, #0xc - adds r1, #1 - cmp r1, #0x1f - bls _0801E712 -_0801E722: - pop {r4, r5, r6, pc} - .align 2, 0 -_0801E724: .4byte gFuseInfo -_0801E728: .4byte gUnk_02002C01 -_0801E72C: .4byte gSave -_0801E730: .4byte 0x000001C1 -_0801E734: .4byte gUnk_03003DF0 - .syntax divided diff --git a/asm/non_matching/likeLike/sub_0802810C.inc b/asm/non_matching/likeLike/sub_0802810C.inc deleted file mode 100644 index 9e04fd00..00000000 --- a/asm/non_matching/likeLike/sub_0802810C.inc +++ /dev/null @@ -1,81 +0,0 @@ - - .syntax unified - - .text - - push {r4, r5, lr} - adds r4, r0, #0 - ldr r2, _08028198 @ =gPlayerState - movs r1, #0 - movs r0, #0x41 - strb r0, [r2, #2] - strb r1, [r2, #0xa] - ldr r0, [r2, #0x30] - subs r1, #0x11 - ands r0, r1 - str r0, [r2, #0x30] - ldr r0, _0802819C @ =gPlayerEntity - mov ip, r0 - ldrb r0, [r0, #0x10] - movs r1, #0x80 - orrs r0, r1 - mov r1, ip - strb r0, [r1, #0x10] - movs r0, #0xc0 - lsls r0, r0, #9 - str r0, [r1, #0x20] - adds r1, #0x3d - movs r0, #0xc4 - strb r0, [r1] - movs r3, #0 - mov r2, ip - ldrb r0, [r2, #0x14] - lsls r0, r0, #2 - strb r0, [r2, #0x15] - adds r0, r4, #0 - adds r0, #0x83 - ldrb r0, [r0] - mov r5, ip - adds r5, #0x29 - movs r1, #7 - ands r1, r0 - lsls r1, r1, #3 - ldrb r2, [r5] - movs r0, #0x39 - rsbs r0, r0, #0 - ands r0, r2 - orrs r0, r1 - strb r0, [r5] - mov r1, ip - adds r1, #0x63 - movs r0, #0 - ldrsb r0, [r1, r0] - mov r2, ip - strh r0, [r2, #0x36] - strb r3, [r1] - movs r0, #4 - strb r0, [r4, #0xc] - movs r0, #0x50 - strb r0, [r4, #0xe] - strb r3, [r4, #0xf] - adds r2, r4, #0 - adds r2, #0x3b - ldrb r1, [r2] - movs r0, #2 - orrs r0, r1 - strb r0, [r2] - adds r1, r4, #0 - adds r1, #0x3d - movs r0, #0 - ldrsb r0, [r1, r0] - cmp r0, #0 - bne _08028196 - movs r0, #0xee - strb r0, [r1] -_08028196: - pop {r4, r5, pc} - .align 2, 0 -_08028198: .4byte gPlayerState -_0802819C: .4byte gPlayerEntity - - .syntax divided diff --git a/asm/non_matching/stalfos/sub_08039B28.inc b/asm/non_matching/stalfos/sub_08039B28.inc deleted file mode 100644 index 92b41bf7..00000000 --- a/asm/non_matching/stalfos/sub_08039B28.inc +++ /dev/null @@ -1,62 +0,0 @@ - .syntax unified - push {r4, r5, r6, lr} - adds r6, r0, #0 - ldr r0, [r6, #0x54] - cmp r0, #0 - bne _08039B84 - ldrb r2, [r6, #0x14] - lsls r2, r2, #1 - ldr r0, _08039B88 @ =gUnk_080CF930 - adds r2, r2, r0 - movs r1, #0x2e - ldrsh r0, [r6, r1] - movs r1, #0 - ldrsb r1, [r2, r1] - adds r0, r0, r1 - ldr r4, _08039B8C @ =gRoomControls - ldrh r1, [r4, #6] - subs r0, r0, r1 - asrs r5, r0, #4 - movs r3, #0x3f - ands r5, r3 - movs r1, #0x32 - ldrsh r0, [r6, r1] - movs r1, #1 - ldrsb r1, [r2, r1] - adds r0, r0, r1 - ldrh r1, [r4, #8] - subs r0, r0, r1 - asrs r0, r0, #4 - ands r0, r3 - lsls r0, r0, #6 - orrs r5, r0 - adds r0, r6, #0 - adds r0, #0x38 - ldrb r1, [r0] - adds r0, r5, #0 - bl GetTileType - adds r2, r0, #0 - ldr r1, _08039B90 @ =gUnk_080CF938 -_08039B76: - ldrh r0, [r1] - cmp r0, r2 - beq _08039B98 - adds r1, #4 - ldrh r0, [r1] - cmp r0, #0 - bne _08039B76 -_08039B84: - ldr r0, _08039B94 @ =0x0000FFFF - b _08039B9E - .align 2, 0 -_08039B88: .4byte gUnk_080CF930 -_08039B8C: .4byte gRoomControls -_08039B90: .4byte gUnk_080CF938 -_08039B94: .4byte 0x0000FFFF -_08039B98: - ldrh r0, [r1, #2] - strb r0, [r6, #0xb] - adds r0, r5, #0 -_08039B9E: - pop {r4, r5, r6, pc} - .syntax divided diff --git a/include/collision.h b/include/collision.h index 9e17ae2d..bc7a632b 100644 --- a/include/collision.h +++ b/include/collision.h @@ -30,5 +30,6 @@ bool32 IsColliding(Entity*, Entity*); bool32 IsCollidingPlayer(Entity*); void CalculateEntityTileCollisions(Entity*, u32, u32); bool32 ProcessMovementInternal(Entity*, s32, s32, u32); +u32 sub_080176E4(Entity*); #endif // COLLISION_H diff --git a/src/beanstalkSubtask.c b/src/beanstalkSubtask.c index f9e54925..543accd0 100644 --- a/src/beanstalkSubtask.c +++ b/src/beanstalkSubtask.c @@ -39,6 +39,7 @@ extern const u16* gUnk_080B4550[]; extern const u16 gUnk_080B77C0[]; extern BgAnimationFrame* gUnk_080B7278[]; +void sub_0801AD6C(u16*, u32); bool32 sub_0801A4F8(void); bool32 sub_0801AA58(Entity*, u32, u32); void sub_0801AB08(u16*, LayerStruct*); @@ -138,10 +139,17 @@ NONMATCH("asm/non_matching/beanstalkSubtask/sub_0801A2B0.inc", u32 uVar2; bool32 bVar3; u32 pos; + s16 temp; + s16 temp2; + u16 temp3; + u16 temp4; + u32 temp5; uVar1 = gUnk_080B4488[gPlayerEntity.animationState >> 1]; if ((((gPlayerState.field_0x35 | gPlayerState.field_0xd) & 0x80) == 0) && ((gPlayerEntity.frame & 1) != 0)) { - switch ((s32)sub_080B1B54(GetTileType(position + uVar1, gPlayerEntity.collisionLayer))) { + position = (u16)(position + uVar1); + temp4 = sub_080B1B54(GetTileType(position, gPlayerEntity.collisionLayer)); + switch (temp4) { case 0x52: break; case 0x26: @@ -152,13 +160,12 @@ NONMATCH("asm/non_matching/beanstalkSubtask/sub_0801A2B0.inc", case 0x74: return FALSE; default: - if ((layer->collisionData[(position + uVar1)] != 0x28) && - (!IsTileCollision( - layer->collisionData, - (s32)((((position + uVar1) & 0x3f) * 0x10 + (u32)gRoomControls.origin_x) * 0x10000) >> 0x10, - (s32)((((position + uVar1) >> 6) * 0x10 + (u32)gRoomControls.origin_y) * 0x10000) >> 0x10, - collisionType))) { - return TRUE; + if ((layer->collisionData[(position)] != 0x28)) { + temp = (((position & 0x3f) * 0x10 + (u32)gRoomControls.origin_x)); + temp2 = (((position >> 6) * 0x10 + (u32)gRoomControls.origin_y)); + if ((!IsTileCollision(layer->collisionData, temp, temp2, collisionType))) { + return TRUE; + } } break; } @@ -404,7 +411,50 @@ u32 sub_0801AC68(u32 position, u32 data) { return data << 2; } -ASM_FUNC("asm/non_matching/beanstalkSubtask/sub_0801AC98.inc", void sub_0801AC98()) +extern const u16 gUnk_080B44C0[]; +extern const u16 gUnk_080B44C2[]; +extern const u32 gUnk_080B44B8[]; + +NONMATCH("asm/non_matching/beanstalkSubtask/sub_0801AC98.inc", void sub_0801AC98()) { + u32 height; + u32 indexX; + u32 width; + u32 indexY; + const u16* puVar7; + u32 position; + const u32* ptr; + u32 tmp; + + width = gRoomControls.width >> 4; + height = gRoomControls.height >> 4; + position = 0; + + for (indexY = 0; indexY < height; indexY++) { + for (indexX = 0; indexX < width; indexX++, position++) { + for (puVar7 = gUnk_080B44C0; puVar7[0] != 0xffff; puVar7 += 6) { + if (puVar7[0] == GetTileType(position, 1)) { + ptr = gUnk_080B44B8 + puVar7[5]; + if (ptr[0] != 0) { + sub_0801AD6C((u16*)puVar7, position); + break; + } + } + } + for (puVar7 = gUnk_080B44C2; puVar7[0] != 0xffff; puVar7 += 6) { + if (puVar7[0] == GetTileType(position, 2)) { + ptr = gUnk_080B44B8 + puVar7[5]; + if (ptr[0] != 0) { + sub_0801AD6C((u16*)puVar7, position); + break; + } + } + } + } + tmp = (position + 0x40); + position = tmp - width; + } +} +END_NONMATCH void sub_0801AD6C(u16* param_1, u32 param_2) { Entity* entity; diff --git a/src/color.c b/src/color.c index 20c2d321..28a16e93 100644 --- a/src/color.c +++ b/src/color.c @@ -152,7 +152,31 @@ u32 FindFreeObjPalette(u32 a1) { return 0xffffffff; } -ASM_FUNC("asm/non_matching/color/SetEntityObjPalette.inc", void SetEntityObjPalette(Entity* entity, u32 palette)); +NONMATCH("asm/non_matching/color/SetEntityObjPalette.inc", void SetEntityObjPalette(Entity* entity, u32 palette)) { + u32 uVar1; + Palette* pPVar1; + + if (palette < 0) { + palette = 0; + } + if (0x7e < (u8)(entity->spriteAnimation[2] - 1)) { + entity->spriteAnimation[1] = palette; + } + entity->palette.b.b0 = palette; + entity->palette.b.b4 = palette; + pPVar1 = &gPaletteList[palette]; + if ((s8)pPVar1->_0_0 != 4) { + pPVar1->_1++; + uVar1 = pPVar1->_0_4; + pPVar1->_0_0 = 3; + while (uVar1 = uVar1 - 1, uVar1 != 0) { + pPVar1 = pPVar1 + 1; + pPVar1->_0_4 = uVar1; + pPVar1->_0_0 = 2; + } + } +} +END_NONMATCH void UnloadOBJPalette(Entity* entity) { u8* p = &entity->spriteAnimation[1]; diff --git a/src/common.c b/src/common.c index 89220604..ecd82763 100644 --- a/src/common.c +++ b/src/common.c @@ -562,7 +562,26 @@ ASM_FUNC("asm/non_matching/common/sub_0801E49C.inc", void sub_0801E49C(u32 a1, u ASM_FUNC("asm/non_matching/common/sub_0801E64C.inc", void sub_0801E64C(u32 a1, u32 a2, u32 a3, u32 a4, u32 a5)); -ASM_FUNC("asm/non_matching/common/sub_0801E6C8.inc", void sub_0801E6C8(u32 a1)); +void sub_0801E6C8(u32 param_1) { + u32 tmp; + u32 index; + if (param_1 - 1 < 100) { + for (index = 0; index < 0x80; index++) { + if (param_1 == gSave.unk1C1[index]) { + gSave.unk1C1[index] = 0xf1; + } + } + tmp = sub_08002632(gFuseInfo.ent); + if ((tmp - 1 < 0x7f) && (gSave.unk1C1[tmp] == 0xf1)) { + gSave.unk1C1[tmp] = 0xf2; + } + for (index = 0; index < 0x20; index++) { + if (param_1 == gUnk_03003DF0.array[index].unk_3) { + gUnk_03003DF0.array[index].unk_3 = 0xf1; + } + } + } +} void sub_0801E738(u32 param_1) { s32 index; diff --git a/src/enemy/fallingBoulder.c b/src/enemy/fallingBoulder.c index b8395ee5..36ebaa39 100644 --- a/src/enemy/fallingBoulder.c +++ b/src/enemy/fallingBoulder.c @@ -69,7 +69,7 @@ NONMATCH("asm/non_matching/fallingBoulder/sub_0802C334.inc", void sub_0802C334(E u32 tmp = gRoomControls.origin_y; if (&gPlayerEntity == NULL) return; - if (tmp - gPlayerEntity.y.HALF.HI <= 0x38) { + if (gPlayerEntity.y.HALF.HI - tmp <= 0x38) { return; } this->field_0x7c.HALF.LO = 1; diff --git a/src/enemy/likeLike.c b/src/enemy/likeLike.c index 9fb8e750..e271cc66 100644 --- a/src/enemy/likeLike.c +++ b/src/enemy/likeLike.c @@ -209,26 +209,32 @@ void sub_0802805C(Entity* this) { } } -NONMATCH("asm/non_matching/likeLike/sub_0802810C.inc", void sub_0802810C(Entity* this)) { +void sub_0802810C(Entity* this) { +// This matches but ugly +#ifndef NON_MATCHING + register u32 tmp asm("r3"); +#else + u32 tmp; +#endif gPlayerState.jump_status = 0x41; gPlayerState.field_0xa = 0; - gPlayerState.flags &= PL_CAPTURED; - gPlayerEntity.flags |= ENT_COLLIDE; - gPlayerEntity.zVelocity = Q_16_16(1.5); + gPlayerState.flags &= 0xffffffef; + gPlayerEntity.flags |= 0x80; + gPlayerEntity.zVelocity = 0x18000; gPlayerEntity.iframes = -60; + tmp = 0; gPlayerEntity.direction = gPlayerEntity.animationState << 2; gPlayerEntity.spritePriority.b1 = this->field_0x82.HALF.HI; gPlayerEntity.z.HALF.HI = gPlayerEntity.spriteOffsetY; - gPlayerEntity.spriteOffsetY = 0; + gPlayerEntity.spriteOffsetY = tmp; this->action = 4; - this->timer = 80; - this->subtimer = 0; + this->timer = 0x50; + this->subtimer = tmp; this->flags2 |= 2; if (this->iframes == 0) { this->iframes = -18; } } -END_NONMATCH void sub_080281A0(Entity* this) { this->subtimer = 25; diff --git a/src/enemy/moldorm.c b/src/enemy/moldorm.c index a38eec1e..a03a934c 100644 --- a/src/enemy/moldorm.c +++ b/src/enemy/moldorm.c @@ -149,9 +149,47 @@ void sub_08022DE8(Entity* this) { // this definition is only here, so clang-tidy does not mess gUnk_080CBBBC up. extern void sub_08022E40(Entity* this); -ASM_FUNC("asm/non_matching/moldorm/sub_08022E40.inc", void sub_08022E40(Entity* this)) +NONMATCH("asm/non_matching/moldorm/sub_08022E40.inc", void sub_08022E40(Entity* this)) { + u32 bVar1; + u32 bVar2; + u32 tmp; + u32 tmp2; + u8* ptr; -ASM_FUNC("asm/non_matching/moldorm/sub_08022EAC.inc", void sub_08022EAC(Entity* this)) + this->field_0x74.HWORD = this->x.HALF.HI; + this->field_0x76.HWORD = this->y.HALF.HI; + tmp2 = (this->parent->field_0x78.HALF.HI + 1) & 7; + bVar1 = ((u8*)&this->field_0x7c)[tmp2]; + tmp = (bVar1 & 0xf) - 8; + bVar1 >>= 4; + this->x.HALF.HI = ((short)((tmp * 0x100)) >> 8) + this->x.HALF.HI; + bVar1 -= 8; + this->y.HALF.HI = bVar1 + this->y.HALF.HI; + bVar2 = (u8)(*(u32*)&this->cutsceneBeh >> (((this->parent->field_0x78.HALF.HI + 1) & 7) << 2)) & 7; + this->animationState = bVar2; + if (this->type == 3) { + this->frameIndex = bVar2 + 10; + } else { + sub_08022EAC(this); + } +} +END_NONMATCH + +NONMATCH("asm/non_matching/moldorm/sub_08022EAC.inc", void sub_08022EAC(Entity* this)) { + int iVar1; + u32 tmp; + u32 tmp2; + if (this->child != NULL) { + tmp2 = ((this->parent->field_0x78.HALF.HI) & 7); + ((u8*)&this->child->field_0x7c)[tmp2] = ((this->x.HALF_U.HI - this->field_0x74.HALF.LO + 8) & (0xf)) + + ((this->y.HALF_U.HI - this->field_0x76.HALF.LO + 8) /*& 0xf*/) * 0x10; + iVar1 = ((this->parent->field_0x78.HALF.HI) & 7) << 2; + tmp = (this->animationState & 7) << iVar1; + tmp |= ~(0xf << iVar1) & (*(u32*)&this->child->cutsceneBeh); + *(u32*)&this->child->cutsceneBeh = tmp; + } +} +END_NONMATCH void sub_08022F14(Entity* this) { if (sub_08049FA0(this) == 0) { diff --git a/src/enemy/mulldozer.c b/src/enemy/mulldozer.c index 17c9a495..44404582 100644 --- a/src/enemy/mulldozer.c +++ b/src/enemy/mulldozer.c @@ -436,7 +436,30 @@ void sub_08033320(MulldozerEntity* this) { } } -ASM_FUNC("asm/non_matching/mulldozer/sub_08033364.inc", bool32 sub_08033364(MulldozerEntity* this)) +NONMATCH("asm/non_matching/mulldozer/sub_08033364.inc", bool32 sub_08033364(MulldozerEntity* this)) { + Entity* entity; + u32 radius; + u32 tmp; + + entity = (Entity*)sub_08049DF4(1); + if (entity != NULL) { + if (super->type != 0) { + radius = 0x48; + } else { + radius = 0x38; + } + if (EntityInRectRadius(super, entity, radius, radius) != 0) { + if (super->type != 0) { + return TRUE; + } + if (((GetFacingDirection(super, gUnk_020000B0) + 2) & 0x1c) >> 2 == super->animationState) { + return TRUE; + } + } + } + return FALSE; +} +END_NONMATCH void (*const Mulldozer_Functions[])(MulldozerEntity*) = { Mulldozer_OnInit, diff --git a/src/enemy/spearMoblin.c b/src/enemy/spearMoblin.c index a44ef967..6a2874e9 100644 --- a/src/enemy/spearMoblin.c +++ b/src/enemy/spearMoblin.c @@ -248,21 +248,28 @@ NONMATCH("asm/non_matching/spearMoblin/sub_08028604.inc", void sub_08028604(Enti this->timer = gUnk_080CC7BC[Random() & 3]; this->speed = 0x80; if (sub_08049FA0(this) != 0) { - this->direction = gUnk_080CC7D0[Random() & 7] + 0x18 + (this->direction & 0x18); + u32 rand = Random(); + u32 tmp; + tmp = gUnk_080CC7D0[rand & 7] + 0x18; + tmp += this->direction; + tmp &= 0x18; + this->direction = tmp; } else { u32 iVar3 = sub_08049EE4(this); - u32 uVar1; + s8 uVar1; if (this->field_0x82.HALF.HI == 0) { - uVar1 = gUnk_080CC7C0[Random() & 0xf]; + u32 rand = Random(); + iVar3 += gUnk_080CC7C0[rand & 0xf]; } else { - uVar1 = gUnk_080CC7C0[Random() & 7]; - this->timer = this->timer + 16; + u32 rand = Random(); + iVar3 += gUnk_080CC7C0[rand & 7]; + this->timer = this->timer + 0x10; this->field_0x82.HALF.HI--; } - this->direction = iVar3 + uVar1 + (4U & 0x18); + this->direction = (iVar3 + 4U) & 0x18; } } else { - this->timer = 12; + this->timer = 0xc; this->speed = 0; } diff --git a/src/enemy/stalfos.c b/src/enemy/stalfos.c index eb87e265..848f0d38 100644 --- a/src/enemy/stalfos.c +++ b/src/enemy/stalfos.c @@ -75,8 +75,8 @@ void Stalfos_OnTick(StalfosEntity* this) { NONMATCH("asm/non_matching/stalfos/sub_0803933C.inc", void sub_0803933C(StalfosEntity* this)) { if (super->hitType == 0x44) { - if ((super->contactFlags & 0x7f) < 7) { - if ((super->contactFlags & 0x7f) > 3) { + switch (super->contactFlags & 0x7f) { + case 4 ... 6: if (super->iframes < 1) { super->action = 4; super->direction = super->knockbackDirection; @@ -84,7 +84,7 @@ NONMATCH("asm/non_matching/stalfos/sub_0803933C.inc", void sub_0803933C(StalfosE super->speed = 0x120; sub_0803981C(this); } - } + break; } } if (super->contactFlags == 0x9d) { @@ -441,7 +441,32 @@ void sub_08039AD4(StalfosEntity* this) { } sub_08039A48(this); } -ASM_FUNC("asm/non_matching/stalfos/sub_08039B28.inc", u32 sub_08039B28(StalfosEntity* this)) + +u32 sub_08039B28(StalfosEntity* this) { + u32 tileType; + u32 pos; + const u16* ptr; + const s8* ptr2; + + if (super->child == NULL) { + ptr2 = &gUnk_080CF930[super->animationState * 2]; + pos = COORD_TO_TILE_OFFSET(super, -ptr2[0], -ptr2[1]); + + tileType = GetTileType(pos, (u32)super->collisionLayer); + ptr = gUnk_080CF938; + do { + if (ptr[0] != tileType) { + ptr += 2; + } else { + goto found; + } + } while (ptr[0] != 0); + } + return 0xffff; +found: + super->type2 = ptr[1]; + return pos; +} void (*const Stalfos_Functions[])(StalfosEntity*) = { Stalfos_OnTick, diff --git a/src/enemy/vaatiArm.c b/src/enemy/vaatiArm.c index 264cf441..d20adbf2 100644 --- a/src/enemy/vaatiArm.c +++ b/src/enemy/vaatiArm.c @@ -865,7 +865,7 @@ static ASM_FUNC("asm/non_matching/vaati/sub_080432A8.inc", void sub_080432A8(Ent Entity* entity; VaatiArm_HeapStruct1* s; u32 i; - u8* ptr; + VaatiArm_HeapStruct1* ptr; if (this->timer != 0) { if (--this->timer != 0) { @@ -886,10 +886,10 @@ static ASM_FUNC("asm/non_matching/vaati/sub_080432A8.inc", void sub_080432A8(Ent } sub_08043B9C(this); for (i = 0; i < 5; i++) { - ptr = ((u8*)((VaatiArm_HeapStruct*)this->myHeap)->s1) + 0x10 * i; - if (gUnk_080D1414[i] > ptr[0xc]) { - ptr[0xc]++; - if (gUnk_080D1414[i] != ptr[0xc]) { + ptr = &(((VaatiArm_HeapStruct*)this->myHeap)->s1)[i]; + if (gUnk_080D1414[i] > ptr->unk0c) { + ptr->unk0c++; + if (gUnk_080D1414[i] != ptr->unk0c) { return; } SoundReq(SFX_15E); diff --git a/src/enemy/wallMaster2.c b/src/enemy/wallMaster2.c index 5f07b006..696b36ad 100644 --- a/src/enemy/wallMaster2.c +++ b/src/enemy/wallMaster2.c @@ -165,7 +165,23 @@ void sub_0802CF64(Entity* this) { sub_0802CF8C(this); } -ASM_FUNC("asm/non_matching/wallMaster2/sub_0802CF8C.inc", void sub_0802CF8C(Entity* this)) +NONMATCH("asm/non_matching/wallMaster2/sub_0802CF8C.inc", void sub_0802CF8C(Entity* this)) { + int iVar1; + u32 uVar2; + const u16* ptr; + u16* ptr2; + + uVar2 = (this->direction + 2) & 0x1c; + if ((uVar2 - this->animationState * 4 + 6 > 0xc) || + ((((this->direction + 1) & 7) > 2 && (uVar2 >> 2 != this->animationState)))) { + this->animationState = (uVar2 >> 2); + iVar1 = (uVar2 >> 3) * 2; + ptr = &gUnk_080CD730[iVar1]; + this->field_0x74.HWORD = ptr[0]; + this->field_0x76.HWORD = ptr[1]; + } +} +END_NONMATCH void sub_0802CFD8(Entity* this) { u32 unk = gUnk_080CD740[(this->field_0x7a.HALF.LO++ >> 3) & 7]; diff --git a/src/main.c b/src/main.c index cf9de720..f84ddb26 100644 --- a/src/main.c +++ b/src/main.c @@ -188,7 +188,11 @@ NONMATCH("asm/non_matching/sub_080560B8.inc", /*static*/ void sub_080560B8(void) } } - b = (gUnk_02000010.signature ^ SIGNATURE) != 0; + if (gUnk_02000010.signature ^ SIGNATURE) { + b = TRUE; + } else { + b = FALSE; + } if ((gUnk_02000010.field_0x4 != 0) && (gUnk_02000010.field_0x4 != 0xc1)) { b = TRUE; diff --git a/src/npc/npc23.c b/src/npc/npc23.c index 68f785e6..6879c6a9 100644 --- a/src/npc/npc23.c +++ b/src/npc/npc23.c @@ -106,7 +106,42 @@ void sub_08066474(Entity* this) { } } -ASM_FUNC("asm/non_matching/npc23/sub_08066490.inc", void sub_08066490(Entity* this, Entity* entity)) +NONMATCH("asm/non_matching/npc23/sub_08066490.inc", void sub_08066490(Entity* this, Entity* entity)) { + u32 uVar1; + u32 uVar2; + u32 uVar3; + u32 uVar4; + + if ((this->type2 & 0x10) != 0) { + this->field_0x86.HWORD = this->x.HALF.HI; + uVar2 = this->field_0x7c.HALF_U.HI; + uVar3 = uVar2 + this->field_0x82.HWORD; + uVar4 = uVar2 - this->field_0x82.HWORD; + if (((entity->x.HALF.HI < (int)uVar3) && (entity->x.HALF.HI > (int)uVar4))) { + uVar2 = entity->x.HALF.HI; + } else { + if (entity->x.HALF.HI >= (int)uVar3) { + uVar2 = uVar3; + } else { + uVar2 = uVar4; + } + } + + if (this->field_0x86.HWORD == uVar2) { + if (this->cutsceneBeh.HWORD == 1) { + this->cutsceneBeh.HWORD = 0; + InitializeAnimation(this, 2); + } + } else { + this->x.HALF.HI = (short)uVar2; + if (this->cutsceneBeh.HWORD == 0) { + this->cutsceneBeh.HWORD = 1; + InitializeAnimation(this, 6); + } + } + } +} +END_NONMATCH bool32 sub_0806650C(Entity* this) { u32 dir = 0; diff --git a/src/object/figurineDevice.c b/src/object/figurineDevice.c index 0f2ae319..562424c1 100644 --- a/src/object/figurineDevice.c +++ b/src/object/figurineDevice.c @@ -376,8 +376,77 @@ void sub_080880D8(FigurineDeviceEntity* this) { } } -ASM_FUNC("asm/non_matching/figurineDevice/sub_08088160.inc", - bool32 sub_08088160(FigurineDeviceEntity* this, s32 param_2)) +NONMATCH("asm/non_matching/figurineDevice/sub_08088160.inc", + bool32 sub_08088160(FigurineDeviceEntity* this, s32 param_2)) { + u8 bVar1; + bool32 condition; + u32 uVar3; + bool32 result; + const struct_080FC3E4* ptr; + u32 tmp; + + ptr = &gUnk_080FC3E4[param_2]; + result = FALSE; + if (this->unk_7c >= ptr->unk_6) { + result = TRUE; + } else { + switch (ptr->unk_6) { + case 0x8: + case 0x40: + if (CheckLocalFlagByBank(ptr->unk_0, ptr->unk_4)) { + result = TRUE; + } + return result; + break; + case 0x10: + if (CheckKinstoneFused(gUnk_080FC3E4[param_2].unk_4)) { + result = TRUE; + } + return result; + break; + default: + return result; + case 0x20: + switch (gUnk_080FC3E4[param_2].unk_4) { + case 0: + if (CheckKinstoneFused(0x20) || CheckKinstoneFused(0x10) || CheckKinstoneFused(0x19)) { + result = TRUE; + } + break; + case 1: + if ((u8)this->unk_7c >= 5 && CheckKinstoneFused(0x28)) { + result = TRUE; + } + + break; + case 2: + if (CheckKinstoneFused(0x54) || CheckKinstoneFused(0x56) || CheckKinstoneFused(0x3d)) { + result = TRUE; + } + break; + case 3: + if (CheckKinstoneFused(0x3b) || CheckKinstoneFused(0x4a) || CheckKinstoneFused(0xd)) { + result = TRUE; + } + break; + case 4: + if (CheckKinstoneFused(0x49) || CheckKinstoneFused(0x55) || CheckKinstoneFused(0x3c)) { + result = TRUE; + } + break; + case 5: + if (this->unk_7c >= 2 && CheckGlobalFlag(MACHI_MACHIHOKORI)) { + result = TRUE; + } + default: + return result; + } + break; + } + } + return result; +} +END_NONMATCH void sub_0808826C(FigurineDeviceEntity* this) { s32 tmp = 0x64; diff --git a/src/object/frozenOctorok.c b/src/object/frozenOctorok.c index 82db2f4b..646a1045 100644 --- a/src/object/frozenOctorok.c +++ b/src/object/frozenOctorok.c @@ -54,7 +54,95 @@ const u8 gUnk_08123DDC[] = { 9, 4, 0, 0, 1, 5, 0, 0, 1, 4, 0, 0, 1, 3, 0, 0, 1, 2, 0, 0, 2, 1, 0, 0, 10, 4, 0, 0, }; -ASM_FUNC("asm/non_matching/frozenOctorok/FrozenOctorok_Init.inc", void FrozenOctorok_Init(FrozenOctorokEntity* this)) +NONMATCH("asm/non_matching/frozenOctorok/FrozenOctorok_Init.inc", void FrozenOctorok_Init(FrozenOctorokEntity* this)) { + OctorokBossHeap* heap; + Entity*** pppEVar2; + FrozenOctorokEntity* pEVar3; + FrozenOctorokEntity* obj1; + FrozenOctorokEntity* obj2; + u32 uVar3; + u32 type; + + super->action = 1; + switch (super->type) { + case 0: + SetDefaultPriority(super, 6); + this->unk_7e = 0; + case 6: + super->timer = 1; + super->direction = 0x10; + this->unk_79 = 0xf0; + super->x.HALF.HI = gRoomControls.origin_x + 0x108; + super->y.HALF.HI = gRoomControls.origin_y + 0x168; + super->spriteRendering.b0 = 3; + this->unk_76 = 0xa0; + this->unk_74 = 0xa0; + this->unk_7b = -0x80; + if (super->type == 0) { + super->spriteOffsetX = 0x29; + super->spriteOffsetY = -0x20; + heap = (OctorokBossHeap*)zMalloc(sizeof(OctorokBossHeap)); + this->heap = heap; + if (heap == NULL) { + DeleteThisEntity(); + return; + } + super->myHeap = heap; + this->heap->tailCount = 5; + + for (uVar3 = 0; uVar3 < 4; uVar3++) { + super->child = CreateObjectWithParent(super, FROZEN_OCTOROK, uVar3 + 1, 0); + if (super->child != NULL) { + ((FrozenOctorokEntity*)super->child)->heap = this->heap; + this->heap->legObjects[uVar3] = (OctorokBossEntity*)super->child; + } + } + obj1 = (FrozenOctorokEntity*)CreateObjectWithParent(super, FROZEN_OCTOROK, 5, 0); + super->child = (Entity*)obj1; + if (obj1 != NULL) { + obj1->heap = this->heap; + } + obj2 = (FrozenOctorokEntity*)CreateObjectWithParent(super, FROZEN_OCTOROK, 6, 0); + super->parent = (Entity*)obj2; + if (obj2 != NULL) { + obj2->heap = this->heap; + } + } else { + super->spriteOffsetX = 0xd7; + super->spriteOffsetY = -0x20; + } + break; + case 1: + case 2: + case 3: + case 4: + super->timer = 0x10; + this->unk_79 = 0; + if ((super->type & 2) == 0) { + super->subtimer = 2; + } else { + super->subtimer = 0xfe; + } + this->unk_74 = 0x100; + if ((super->type & 1) == 0) { + this->unk_76 = 0xff00; + } else { + this->unk_76 = 0x100; + } + break; + case 5: + this->unk_76 = 0x100; + this->unk_74 = 0x100; + this->unk_79 = 0x1c; + this->heap->mouthObject = (OctorokBossEntity*)this; + break; + case 7: + return; + } + InitializeAnimation(super, gUnk_08123DDC[super->type * 4]); + FrozenOctorok_Action1(this); +} +END_NONMATCH void (*const FrozenOctorok_Action1SubActions[])(FrozenOctorokEntity*) = { FrozenOctorok_Action1SubAction0, FrozenOctorok_Action1SubAction1, FrozenOctorok_Action1SubAction2, diff --git a/src/object/object6A.c b/src/object/object6A.c index 5fbeef59..8fa98e51 100644 --- a/src/object/object6A.c +++ b/src/object/object6A.c @@ -1118,14 +1118,14 @@ NONMATCH("asm/non_matching/object6A/sub_08095EAC.inc", b = 0xF; vel = 0x40000; speed = gUnk_08122B0E[Random() & 7]; - super->type2 = -1; + e->type2 = -1; } x = a - (Random() & b); y = a - (Random() & b); - PositionRelative(super, e, Q_16_16(x), Q_16_16(y)); - super->zVelocity = vel; - super->speed = speed; + PositionRelative(super, e, x << 16, y << 16); + e->zVelocity = vel; + e->speed = speed; } } END_NONMATCH diff --git a/src/object/pushableFurniture.c b/src/object/pushableFurniture.c index 3685a0e4..9bef57d6 100644 --- a/src/object/pushableFurniture.c +++ b/src/object/pushableFurniture.c @@ -58,7 +58,88 @@ void PushableFurniture(PushableFurnitureEntity* this) { } } -ASM_FUNC("asm/non_matching/pushableFurniture/sub_0808F990.inc", void sub_0808F990(PushableFurnitureEntity* this)) +NONMATCH("asm/non_matching/pushableFurniture/sub_0808F990.inc", void sub_0808F990(PushableFurnitureEntity* this)) { + s32 uVar1; + bool32 bVar2; + u32 uVar3; + u32 sVar4; + u16 uVar5; + SpritePriority* pSVar6; + Entity* pEVar7; + + super->action = 1; + super->speed = 0x80; + super->subtimer = super->timer; + super->timer = 0; + super->updatePriority = 3; + this->unk_81 = 0; + this->unk_83 = 0; + super->spriteRendering.b3 = 2; + if (super->type == 1) { + super->spritePriority.b0 = 4; + this->unk_80 = 0; + } else { + this->unk_80 = 1; + super->spritePriority.b0 = 5; + if ((super->type == 2) || (super->type == 4)) { + super->y.HALF.HI += 2; + super->spriteOffsetY = -2; + super->subAction = 0; + super->frameIndex = 0; + } + } + switch (super->subtimer) { + + default: + bVar2 = FALSE; + if (*(u16*)&super->type == 0x101) { + uVar1 = (s8)super->subtimer; + sVar4 = super->y.HALF_U.HI; + } else { + uVar1 = (s8)super->subtimer; + sVar4 = super->x.HALF_U.HI; + } + this->unk_7e = sVar4 + (u32)uVar1; + if (super->parent == NULL) { + uVar3 = CheckFlags((u32)this->unk_86); + } else { + if ((this->unk_82 & 0x80) != 0) { + if (super->parent->action == 2) { + bVar2++; + } + break; + } + uVar3 = CheckLocalFlag((u32)this->unk_82); + } + if (uVar3 != 0) { + bVar2++; + } + break; + case 0: + bVar2 = FALSE; + break; + case 0x80: + bVar2 = TRUE; + if (*(u16*)&super->type == 0x101) { + uVar5 = super->y.HALF.HI; + } else { + uVar5 = super->x.HALF.HI; + } + this->unk_7e = uVar5; + break; + } + + if (bVar2) { + this->unk_81 = 1; + if (*(u16*)&super->type == 0x101) { + super->y.HALF.HI = this->unk_7e; + } else { + super->x.HALF.HI = this->unk_7e; + } + } + sub_0808FF50(this); +} +END_NONMATCH void PushableFurniture_Action1(PushableFurnitureEntity* this) { if (this->unk_81 == 0) { diff --git a/src/object/pushableStatue.c b/src/object/pushableStatue.c index 2a7fbf3e..7e815deb 100644 --- a/src/object/pushableStatue.c +++ b/src/object/pushableStatue.c @@ -251,7 +251,36 @@ u32 sub_0808968C(u32 param_1) { return 0; } -ASM_FUNC("asm/non_matching/pushableStatue/sub_080896B0.inc", bool32 sub_080896B0(void)) +NONMATCH("asm/non_matching/pushableStatue/sub_080896B0.inc", bool32 sub_080896B0(void)) { + s16 uVar1; + s16 iVar2; + u8* puVar3; + LayerStruct* puVar5; + u32 uVar4; + const s16* ptr; + u32 tmp1; + u32 tmp2; + u32 val; + + if (((gPlayerState.heldObject & 0x1f) == 0x12) && ((gPlayerEntity.frame & 1) != 0)) { + ptr = &gUnk_080B4468[gPlayerEntity.animationState & 6]; + uVar1 = gUnk_080B4488[gPlayerEntity.animationState >> 1]; + uVar4 = COORD_TO_TILE_OFFSET(&gPlayerEntity, -ptr[0], -ptr[1]) - uVar1; + val = sub_080B1AE0(uVar4, gPlayerEntity.collisionLayer); + if ((1 < val - 0x26) && (val != 0x29)) { + puVar5 = GetLayerByIndex((u32)gPlayerEntity.collisionLayer); + iVar2 = (s32)(uVar4 * 0x10000) >> 0x10; + puVar3 = puVar5->collisionData; + tmp1 = puVar3[iVar2]; + tmp2 = puVar3[(iVar2 - uVar1)]; + if ((tmp1 == 0) && (tmp2 == 0)) { + return TRUE; + } + } + } + return FALSE; +} +END_NONMATCH void (*const PushableStatue_Actions[])(PushableStatueEntity*) = { PushableStatue_Init, PushableStatue_Action1, PushableStatue_Action2, PushableStatue_Action3, PushableStatue_Action4, diff --git a/src/playerItem/playerItemShield.c b/src/playerItem/playerItemShield.c index 34558bb1..1b1d67b0 100644 --- a/src/playerItem/playerItemShield.c +++ b/src/playerItem/playerItemShield.c @@ -2,6 +2,8 @@ #include "entity.h" #include "player.h" #include "functions.h" +#include "sound.h" +#include "collision.h" extern void (*const gUnk_081271D4[])(Entity*); extern u8 gUnk_081271DC[]; @@ -33,4 +35,101 @@ void sub_080A2D98(Entity* this) { sub_080A2E00(this); } -ASM_FUNC("asm/non_matching/playerItemShield/sub_080A2E00.inc", void sub_080A2E00(Entity* this)) +extern Hitbox* gUnk_08127240[]; +extern u8 gUnk_08127220[]; + +NONMATCH("asm/non_matching/playerItemShield/sub_080A2E00.inc", void sub_080A2E00(Entity* this)) { + Entity* pEVar1; + u8* iVar2; + u8* pbVar3; + u8 uVar4; + int iVar5; + u32 tmp; + + if ((gPlayerEntity.iframes == 0) || ((u8)gPlayerEntity.iframes == 0x81)) { + gPlayerEntity.iframes = this->iframes; + gPlayerEntity.knockbackDirection = this->knockbackDirection; + gPlayerEntity.knockbackDuration = this->knockbackDuration; + this->knockbackDuration = 0; + this->iframes = 0; + } + + uVar4 = gPlayerState.field_0x3[0]; + if ((uVar4 != 0) && (this == gPlayerState.item)) { + if ((uVar4 & 0x80) != 0) { + this->hitbox = gUnk_08127240[this->animationState >> 1]; + this->collisionFlags = (gPlayerEntity.collisionFlags + 1) | 0x20; + this->flags = this->flags | 0x80; + gPlayerState.field_0x3[0] = uVar4 & 0x7f; + sub_080176E4(this); + } else { + if ((this->contactFlags & 0x80) != 0) { + if ((((this->contactFlags & 0x7f) == 0x42) && (*(char*)&this->field_0x68 == 0xe)) && + ((uVar4 & 0x40) == 0)) { + pEVar1 = CreatePlayerItem(0x15, 0, 0, *(char*)&this->field_0x68); + this->child = pEVar1; + if (pEVar1 != NULL) { + pEVar1->subtimer = 1; + this->child->direction = this->knockbackDirection ^ 0x10; + this->child->parent = this; + } + *(u32*)&this->field_0x78 = gUnk_08127220[1]; + *(u32*)&this->field_0x74 = uVar4 & 0x40; + *(u8**)&this->field_0x7c = gUnk_08127220; + gPlayerState.field_0x3[0] = gPlayerState.field_0x3[0] | 0x40; + } + if (*(int*)&this->field_0x6c == 0) { + SoundReq(0x118); + *(u32*)&this->field_0x6c = 8; + } + } + } + } else { + gPlayerState.field_0x3[0] = 0; + if (gPlayerState.item == this) { + gPlayerState.item = NULL; + } + DeleteThisEntity(); + } + + if (((gPlayerEntity.spriteIndex == 1U) || (gPlayerEntity.spriteIndex == 4U)) && + ((u8)(gPlayerEntity.frameIndex - 0x25) < 0x3f)) { + this->spriteSettings.flipX = gPlayerEntity.spriteSettings.flipX; + this->spriteSettings.flipY = gPlayerEntity.spriteSettings.flipY; + if ((gPlayerEntity.frameIndex - 0x25 + this->field_0x70.WORD != (u32)this->frameIndex) && + ((this->frameIndex = gPlayerEntity.frameIndex - 0x25 + this->field_0x70.WORD, + *(char*)&this->field_0x68 != 0xe || ((gPlayerEntity.frame & 0x7f) == 0)))) { + sub_080042D0(this, this->frameIndex, (u16)this->spriteIndex); + } + if (((*(char*)&this->field_0x68 == 0xe) && ((gPlayerEntity.frame & 0x7f) != 0))) { + (*(int*)&this->field_0x78)--; + if ((*(int*)&this->field_0x78) == 0) { + (*(int*)&this->field_0x74)++; + iVar5 = (*(int*)&this->field_0x74) * 4; + iVar2 = *(u8**)&this->field_0x7c; + if (iVar2[iVar5] == 0xff) { + if ((gPlayerState.field_0x3[0] & 0x40) != 0) { + *(u8**)&this->field_0x7c = gUnk_081271DC; + gPlayerState.field_0x3[0] = gPlayerState.field_0x3[0] & 0xbf; + } + *(u32*)&this->field_0x74 = 0; + iVar2 = *(u8**)&this->field_0x7c; + } + pbVar3 = &iVar2[*(int*)&this->field_0x74 * 4]; + *(u32*)&this->field_0x78 = pbVar3[1]; + if ((gPlayerState.field_0x3[0] & 0x40) != 0) { + u32 temp = (gPlayerEntity.frame & 0x7f) + 8; + sub_080042D0(this, temp + *pbVar3, (u16)this->spriteIndex); + } else { + sub_080042D0(this, (gPlayerEntity.frame & 0x7f) + *pbVar3, (u16)this->spriteIndex); + } + } + } + this->frame = gPlayerEntity.frame; + this->frameSpriteSettings = gPlayerEntity.frameSpriteSettings; + sub_08078E84(this, &gPlayerEntity); + } else { + this->frameIndex = 0xff; + } +} +END_NONMATCH diff --git a/src/playerUtils.c b/src/playerUtils.c index 2d2536c1..d9293851 100644 --- a/src/playerUtils.c +++ b/src/playerUtils.c @@ -27,7 +27,9 @@ extern void sub_0809D738(Entity*); extern s32 Mod(s32, s32); extern void sub_08003FDE(Entity*, u32, u32, u32); extern u32 sub_080B1B84(u32, u32); +extern void sub_08080BC4(void); void sub_080790E4(Entity* this); +void sub_08079064(Entity*); typedef struct { u8 unk0[4]; @@ -1297,7 +1299,53 @@ bool32 sub_08078F74(Entity* this) { } } -ASM_FUNC("asm/non_matching/playerUtils/sub_08078FB0.inc", void sub_08078FB0(Entity* a)) +NONMATCH("asm/non_matching/playerUtils/sub_08078FB0.inc", void sub_08078FB0(Entity* this)) { + u32 bVar2; + u32 animation; + + if ((gPlayerState.pushedObject & 0x80) == 0) { + gPlayerState.field_0x35 = 0xff; + } + sub_08079064(this); + if ((gPlayerState.flags & 8) != 0) { + bVar2 = 0x58; + } else { + if ((gPlayerState.flags & 0x80) != 0) { + bVar2 = 0x18; + } else { + if (gPlayerState.animation >> 8 == 7) { + bVar2 = 0x34; + } else { + bVar2 = 0xb8; + } + } + } + + if (bVar2 > gPlayerState.animation) { + u32 temp = this->animationState; + bVar2 = temp; + if (bVar2 >= 5) { + this->spriteSettings.flipX = 1; + } else { + this->spriteSettings.flipX = 0; + } + + if ((gPlayerState.flags & PL_MOLDWORM_CAPTURED) != 0) { + bVar2 = gPlayerState.animation + this->animationState; + } else { + bVar2 = (((u8)bVar2) >> 1) + gPlayerState.animation; + } + } else { + bVar2 = gPlayerState.animation; + } + + if (bVar2 != (((u16)this->spriteIndex << 8) | this->animIndex)) { + this->spriteIndex = bVar2 >> 8; + bVar2 &= 0xff; + InitAnimationForceUpdate(this, bVar2); + } +} +END_NONMATCH void sub_08079064(Entity* this) { u32 i; @@ -2963,11 +3011,155 @@ void sub_0807C5B0(void) { roomControls->scroll_flags |= 2; } -ASM_FUNC("asm/non_matching/playerUtils/sub_0807C5F4.inc", void sub_0807C5F4(u16* a, u16* b)) +NONMATCH("asm/non_matching/playerUtils/sub_0807C5F4.inc", void sub_0807C5F4(u16* param_1, u16* param_2)) { + s32 iVar1; + u16* puVar2; + u16* puVar3; + u32 uVar4; + u32 index; + u32 innerIndex; + + /* + for (index = 0; index < 0x20; index++) { + for (innerIndex = 0; innerIndex < 0x20; innerIndex++) { + param_1[index*0x81+innerIndex] = param_2[innerIndex]; + } + } + + */ + puVar2 = param_1; + iVar1 = 0x20; + do { + uVar4 = 0; + iVar1--; + do { + *puVar2 = *param_2; + param_2++; + puVar2++; + uVar4++; + } while (uVar4 < 0x20); + puVar2 += 0x60; + } while (iVar1 != 0); + + if (0xff < gRoomControls.width) { + puVar2 = param_1 + 0x20; + iVar1 = 0x20; + do { + uVar4 = 0; + iVar1--; + do { + *puVar2 = *param_2; + param_2++; + puVar2++; + uVar4++; + } while (uVar4 < 0x20); + puVar2 += 0x60; + } while (iVar1 != 0); + } + if (0xff < gRoomControls.height) { + puVar2 = param_1 + 0x1000; + iVar1 = 0x20; + do { + uVar4 = 0; + iVar1--; + do { + *puVar2 = *param_2; + param_2++; + puVar2++; + uVar4++; + } while (uVar4 < 0x20); + puVar2 += 0x60; + } while (iVar1 != 0); + } + if ((0xff < gRoomControls.width) && (0xff < gRoomControls.height)) { + param_1 += 0x1020; + puVar2 = param_1; + iVar1 = 0x20; + do { + uVar4 = 0; + iVar1--; + do { + *puVar2 = *param_2; + param_2++; + puVar2++; + uVar4++; + } while (uVar4 < 0x20); + puVar2 += 0x60; + } while (iVar1 != 0); + } +} +END_NONMATCH ASM_FUNC("asm/non_matching/playerUtils/sub_0807C69C.inc", void sub_0807C69C(u8* a, u32 b, u32 c)) -ASM_FUNC("asm/non_matching/playerUtils/sub_0807C740.inc", void InitializeCamera()) +NONMATCH("asm/non_matching/playerUtils/sub_0807C740.inc", void InitializeCamera()) { + s32 targetX; + s32 targetY; + Entity* target; + RoomControls* roomControls; + u32 tmp1; + u32 tmp2; + u32 tmp3; + u32 tmp4; + + sub_0807BFD0(); + LoadRoomGfx(); + roomControls = &gRoomControls; + target = gRoomControls.camera_target; + if (target != NULL) { + if ((target->x.HALF_U.HI * 0x10000) < 0) { + tmp3 = (target->x.HALF.HI & 0x7fff); + tmp3 -= gRoomControls.origin_x; + target->x.HALF.HI = tmp3; + } + targetX = target->x.HALF.HI; + if ((target->y.HALF_U.HI * 0x10000) < 0) { + tmp4 = (target->y.HALF.HI & 0x7fff); + tmp4 -= gRoomControls.origin_y; + target->y.HALF.HI = tmp4; + } + targetY = target->y.HALF.HI; + } else { + targetX = 0; + targetY = 0; + } + + if (targetX < 0x78) { + roomControls->scroll_x = 0; + } else { + if (targetX >= (roomControls->width - 0x78)) { + tmp1 = roomControls->width - 0x78; + } else { + tmp1 = targetX; + } + roomControls->scroll_x = tmp1 - 0x78; + } + roomControls->scroll_x = roomControls->origin_x + roomControls->scroll_x; + + if (targetY < 0x50) { + roomControls->scroll_y = 0; + } else { + if (targetY >= (roomControls->height - 0x50)) { + tmp2 = roomControls->height - 0x50; + } else { + tmp2 = targetY; + } + roomControls->scroll_y = tmp2 - 0x50; + } + roomControls->scroll_y = roomControls->scroll_y + roomControls->origin_y; + + if (roomControls->camera_target != NULL) { + roomControls->camera_target->x.HALF.HI += roomControls->origin_x; + roomControls->camera_target->y.HALF.HI += roomControls->origin_y; + if ((gRoomControls.scroll_flags & 2) != 0) { + roomControls->camera_target->collisionLayer = 1; + UpdateSpriteForCollisionLayer(roomControls->camera_target); + } + } + roomControls->scroll_flags &= 0xfb; + sub_08080BC4(); +} +END_NONMATCH void sub_0807C810(void) { DiggingCaveEntranceTransition* ptr; diff --git a/src/projectile/gyorgTail.c b/src/projectile/gyorgTail.c index 866d9c22..c3657692 100644 --- a/src/projectile/gyorgTail.c +++ b/src/projectile/gyorgTail.c @@ -179,23 +179,24 @@ NONMATCH("asm/non_matching/gyorgTail/sub_080AC5E4.inc", bool32 sub_080AC5E4(Enti if (this->type == 0) { if (0x43 < gEntCount) { - return 0; + return FALSE; } this->field_0x78.HALF.HI = 0x11; - entity = CreateProjectile(GYORG_TAIL); + entity = CreateProjectile(0x22); entity->type = this->type; entity->type2 = 1; entity->parent = this->parent; entity->field_0x78.HALF.HI = 0x12; this->child = entity; - entity2 = CreateProjectile(GYORG_TAIL); + entity2 = CreateProjectile(0x22); entity2->type = this->type; entity2->type2 = 2; entity2->parent = this->parent; entity2->field_0x78.HALF.HI = 0x14; uVar3 = entity2->field_0x78.HALF.HI; + entity2->field_0x78.HALF.HI = uVar3; entity->child = entity2; - entity3 = CreateProjectile(GYORG_TAIL); + entity3 = CreateProjectile(0x22); entity3->type = this->type; entity3->type2 = 3; entity3->parent = this->parent; @@ -204,17 +205,18 @@ NONMATCH("asm/non_matching/gyorgTail/sub_080AC5E4.inc", bool32 sub_080AC5E4(Enti entity2->child = entity3; } else { if (0x44 < gEntCount) { - return 0; + return FALSE; } this->field_0x78.HALF.HI = 0xf; - entity = CreateProjectile(GYORG_TAIL); + entity = CreateProjectile(0x22); entity->type = this->type; entity->type2 = 1; entity->parent = this->parent; entity->field_0x78.HALF.HI = 0x10; uVar3 = entity->field_0x78.HALF.HI; + entity->field_0x78.HALF.HI = uVar3; this->child = entity; - entity2 = CreateProjectile(GYORG_TAIL); + entity2 = CreateProjectile(0x22); entity2->type = this->type; entity2->type2 = 2; entity2->parent = this->parent; @@ -222,13 +224,13 @@ NONMATCH("asm/non_matching/gyorgTail/sub_080AC5E4.inc", bool32 sub_080AC5E4(Enti entity2->field_0x78.HALF.HI = 0x20; entity->child = entity2; } - entity4 = CreateProjectile(GYORG_TAIL); - entity4->type = this->type; - entity4->type2 = 4; - entity4->parent = this->parent; - entity4->child = this; - entity4->field_0x78.HALF.HI = uVar3; - return 1; + entity = CreateProjectile(0x22); + entity->type = this->type; + entity->type2 = 4; + entity->parent = this->parent; + entity->child = this; + entity->field_0x78.HALF.HI = uVar3; + return TRUE; } END_NONMATCH diff --git a/src/scroll.c b/src/scroll.c index 7a4abdc0..8943a153 100644 --- a/src/scroll.c +++ b/src/scroll.c @@ -10,6 +10,9 @@ #include "fileselect.h" #include "screen.h" #include "manager/diggingCaveEntranceManager.h" +#include "kinstone.h" +#include "effects.h" +#include "object.h" extern void sub_08080BC4(void); extern void sub_080197D4(const void*); @@ -78,7 +81,100 @@ void sub_0807FC64(RoomControls* controls) { UpdateIsDiggingCave(); } -ASM_FUNC("asm/non_matching/scroll/sub_0807FC7C.inc", void sub_0807FC7C(RoomControls* controls)) +NONMATCH("asm/non_matching/scroll/sub_0807FC7C.inc", void sub_0807FC7C(RoomControls* controls)) { + u32 uVar1; + u32 uVar2; + u32 uVar3; + int iVar4; + u32 uVar5; + u32 temp; + u32 temp2; + u32 uVar6; + + if (controls->camera_target != NULL) { + iVar4 = (int)controls->scroll_x; + temp = controls->camera_target->x.HALF.HI - 0x78; + uVar3 = iVar4 - temp; + if (uVar3 != 0) { + uVar1 = (u16)controls->scroll_x; + uVar5 = uVar1 & 7; + uVar6 = uVar1; + if ((int)uVar3 >= 1) { + uVar2 = controls->origin_x; + if ((int)uVar2 < iVar4) { + if ((int)controls->unk5 <= (int)uVar3) { + uVar3 = controls->unk5; + controls->scroll_flags = controls->scroll_flags | 4; + } + controls->scroll_x = uVar6 - uVar3; + if ((int)((uVar5)-uVar3) < 1) { + gUpdateVisibleTiles = 1; + } + if ((int)uVar2 >= (int)controls->scroll_x) { + controls->scroll_x = (s16)uVar2; + } + } + } else { + uVar2 = (controls->origin_x + controls->width) - 0xf0; + if (iVar4 < (int)uVar2) { + if ((int)-controls->unk5 >= (int)uVar3) { + uVar3 = -controls->unk5; + controls->scroll_flags |= 4; + } + controls->scroll_x = uVar1 - (short)uVar3; + if (7 < (int)((uVar5)-uVar3)) { + gUpdateVisibleTiles = 1; + } + if ((int)controls->scroll_x >= (int)uVar2) { + controls->scroll_x = (s16)uVar2; + } + } + } + } + + iVar4 = (int)controls->scroll_y; + temp = controls->camera_target->y.HALF.HI - 0x50; + uVar3 = iVar4 - (temp); + if (uVar3 != 0) { + uVar1 = (u16)controls->scroll_y; + uVar5 = uVar1 & 7; + uVar6 = uVar1; + if ((int)uVar3 >= 1) { + uVar2 = temp2 = (u16)controls->origin_y; + if ((int)uVar2 < iVar4) { + if ((int)controls->unk5 <= (int)uVar3) { + uVar3 = controls->unk5; + controls->scroll_flags |= 4; + } + controls->scroll_y = uVar6 - uVar3; + if ((int)((uVar5)-uVar3) < 1) { + gUpdateVisibleTiles = 1; + } + if ((int)uVar2 >= (int)controls->scroll_y) { + controls->scroll_y = (s16)uVar2; + } + } + } else { + uVar2 = (controls->origin_y + controls->height) - 0xa0; + if (iVar4 < (int)uVar2) { + if ((int)-controls->unk5 >= (int)uVar3) { + uVar3 = -controls->unk5; + controls->scroll_flags = controls->scroll_flags | 4; + } + controls->scroll_y = uVar1 - (short)uVar3; + if (7 < (int)((uVar1 & 7) - uVar3)) { + gUpdateVisibleTiles = 1; + } + if ((int)controls->scroll_y >= (int)uVar2) { + controls->scroll_y = (s16)uVar2; + } + } + } + } + } + sub_08080BC4(); +} +END_NONMATCH void sub_0807FDB0(RoomControls* controls) { static void (*const gUnk_0811E780[])(RoomControls*) = { @@ -631,7 +727,44 @@ void sub_080809D4(void) { gUpdateVisibleTiles = 1; } -ASM_FUNC("asm/non_matching/scroll/UpdateDoorTransition.inc", void UpdateDoorTransition()) +NONMATCH("asm/non_matching/scroll/UpdateDoorTransition.inc", void UpdateDoorTransition()) { + u32 uVar1; + u32 uVar2; + u32 uVar3; + u32 uVar4; + Entity* target; + + if (gRoomControls.camera_target != &gPlayerEntity) { + return; + } + if (gPlayerState.jump_status != 0) { + return; + } + switch (gRoomControls.camera_target->action) { + case 0x0f: + if (gRoomControls.area == 0x48) { + return; + } + case 1: + case 9: + case 0x18: + case 0x1d: + uVar4 = gRoomControls.camera_target->y.HALF.HI - gRoomControls.origin_y; + uVar3 = gRoomControls.camera_target->x.HALF.HI - gRoomControls.origin_x; + uVar1 = + sub_080B1AE0(COORD_TO_TILE(gRoomControls.camera_target), gRoomControls.camera_target->collisionLayer); + gRoomTransition.stairs_idx = sub_080B1A48(uVar3, uVar4, gRoomControls.camera_target->collisionLayer); + switch (uVar1) { + case 0x3f: + case 0xf1: + case 0x28: + case 0x29: + sub_080806BC(uVar3, uVar4, 0xff, 10); + break; + } + } +} +END_NONMATCH ASM_FUNC("asm/non_matching/scroll/sub_08080B60.inc", void sub_08080B60(LayerStruct* param_1)) @@ -675,4 +808,48 @@ void sub_08080C80(u32* param_1) { sub_0807C8B0(gMapTop.mapData, gRoomControls.width >> 4, gRoomControls.height >> 4); } -ASM_FUNC("asm/non_matching/scroll/sub_08080CB4.inc", void sub_08080CB4(Entity* a)) +NONMATCH("asm/non_matching/scroll/sub_08080CB4.inc", void sub_08080CB4(Entity* this)) { + Entity* effect; + u32 tmp; + u32 tmp2; + + if (this->type != this->animIndex) { + InitAnimationForceUpdate(this, this->type); + if (this->type == 0x5c) { + struct_080C9CBC* ptr = &gUnk_080C9CBC[this->type2]; + this->palette.raw = ((ptr->unk0 & 0xf) << 4) | ptr->unk0; + } + + } else { + + UpdateAnimationSingleFrame(this); + if (this->spriteSettings.draw != 0) { + switch (this->type) { + case 0x60: + if (this->field_0x6a.HALF.LO != 0) { + this->field_0x6a.HALF.LO--; + } else { + this->field_0x6a.HALF.LO = (Random() & 0x1f) + 10; + effect = CreateFx(this, FX_SPARKLE, 0); + if (effect != NULL) { + effect->spriteOffsetX = this->spriteOffsetX; + effect->spriteOffsetY = this->spriteOffsetY; + SortEntityAbove(this, effect); + } + } + break; + case 0x40: + case 0x41: + case 0x42: + case 0x43: + case 0x5c: + case 0x62: + if ((gRoomTransition.frameCount & 0xf) == 0) { + CreateSparkle(this); + } + break; + } + } + } +} +END_NONMATCH