From a1228bfad9bcd8644706f4f12abf8f3f94f76527 Mon Sep 17 00:00:00 2001 From: ThreeMustyFears <87553242+ThreeMustyFears@users.noreply.github.com> Date: Sat, 24 Jul 2021 16:07:08 -0300 Subject: [PATCH] Match func_800397E8 (#342) * Match func_800397E8 * Fix function prototype * Delete func_800397E8.s * add spaces * Style changes * Add flags in enum.h * Added flags --- include/enums.h | 2 + src/npc.c | 41 ++++++++- src/npc.h | 2 +- ver/us/asm/nonmatchings/npc/func_800397E8.s | 93 --------------------- 4 files changed, 43 insertions(+), 95 deletions(-) delete mode 100644 ver/us/asm/nonmatchings/npc/func_800397E8.s diff --git a/include/enums.h b/include/enums.h index f5b04b5432..691c867326 100644 --- a/include/enums.h +++ b/include/enums.h @@ -1564,8 +1564,10 @@ enum NpcFlags { NPC_FLAG_40 = 0x00000040, NPC_FLAG_100 = 0x00000100, // TODO NPC_FLAG_GRAVITY = 0x00000200, ///< Enables gravity. Does nothing if NPC_FLAG_NO_Y_MOVEMENT is set. + NPC_FLAG_208 = 0x00000208, NPC_FLAG_LOCK_ANIMS = 0x00000400, ///< Do not allow scripts to change animation NPC_FLAG_NO_Y_MOVEMENT = 0x00000800, ///< Causes NpcMoveTo() to ignore stairs + NPC_FLAG_1000 = 0x00001000, NPC_FLAG_NO_PROJECT_SHADOW = 0x00002000, ///< Draw shadow at base of sprite instead of projecting to ground NPC_FLAG_4000 = 0x00004000, NPC_FLAG_8000 = 0x00008000, diff --git a/src/npc.c b/src/npc.c index 3215251476..8f188409b9 100644 --- a/src/npc.c +++ b/src/npc.c @@ -358,7 +358,46 @@ INCLUDE_ASM(s32, "npc", npc_do_player_collision, Npc* npc); INCLUDE_ASM(void, "npc", npc_do_gravity, Npc* npc); -INCLUDE_ASM(s32, "npc", func_800397E8); +s32 func_800397E8(Npc* npc, f32 arg1) { + if (!(npc->flags & NPC_FLAG_208)) { + f32 x; + f32 y; + f32 z; + f32 subroutine_arg; + f32 temp_v1; + s32 phi_v0; + + if (npc->flags & NPC_FLAG_NO_Y_MOVEMENT) { + npc->flags &= ~NPC_FLAG_1000; + return 0; + } + + temp_v1 = fabsf(arg1) + 16; + subroutine_arg = temp_v1; + x = npc->pos.x; + y = npc->pos.y + 13; + z = npc->pos.z; + + if (!(npc->flags & NPC_FLAG_PARTICLE)) { + phi_v0 = npc_raycast_down_sides(npc->unk_80, &x, &y, &z, &subroutine_arg); + } else { + phi_v0 = npc_raycast_down_ahead(npc->unk_80, &x, &y, &z, &subroutine_arg, npc->yaw, + npc->collisionRadius); + } + + if (phi_v0 != 0 && subroutine_arg <= temp_v1) { + npc->pos.y = y; + npc->unk_84 = D_8010C97A; + npc->flags |= NPC_FLAG_1000; + return 1; + } + } else { + return 0; + } + + npc->flags &= ~NPC_FLAG_1000; + return 0; +} INCLUDE_ASM(void, "npc", update_npcs, void); diff --git a/src/npc.h b/src/npc.h index 5ad7dc402c..48aecf7d75 100644 --- a/src/npc.h +++ b/src/npc.h @@ -43,7 +43,7 @@ s32 npc_do_player_collision(Npc* npc); void npc_do_gravity(Npc* npc); -s32 func_800397E8(); +s32 func_800397E8(Npc* npc, f32 arg1); /// Updates all NPCs. void update_npcs(void); diff --git a/ver/us/asm/nonmatchings/npc/func_800397E8.s b/ver/us/asm/nonmatchings/npc/func_800397E8.s deleted file mode 100644 index 0529692557..0000000000 --- a/ver/us/asm/nonmatchings/npc/func_800397E8.s +++ /dev/null @@ -1,93 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel func_800397E8 -/* 14BE8 800397E8 27BDFFC0 */ addiu $sp, $sp, -0x40 -/* 14BEC 800397EC AFB00030 */ sw $s0, 0x30($sp) -/* 14BF0 800397F0 0080802D */ daddu $s0, $a0, $zero -/* 14BF4 800397F4 AFBF0034 */ sw $ra, 0x34($sp) -/* 14BF8 800397F8 F7B40038 */ sdc1 $f20, 0x38($sp) -/* 14BFC 800397FC 8E030000 */ lw $v1, ($s0) -/* 14C00 80039800 44852000 */ mtc1 $a1, $f4 -/* 14C04 80039804 30620208 */ andi $v0, $v1, 0x208 -/* 14C08 80039808 14400044 */ bnez $v0, .L8003991C -/* 14C0C 8003980C 0000102D */ daddu $v0, $zero, $zero -/* 14C10 80039810 30620800 */ andi $v0, $v1, 0x800 -/* 14C14 80039814 10400005 */ beqz $v0, .L8003982C -/* 14C18 80039818 2402EFFF */ addiu $v0, $zero, -0x1001 -/* 14C1C 8003981C 00621024 */ and $v0, $v1, $v0 -/* 14C20 80039820 AE020000 */ sw $v0, ($s0) -/* 14C24 80039824 0800E647 */ j .L8003991C -/* 14C28 80039828 0000102D */ daddu $v0, $zero, $zero -.L8003982C: -/* 14C2C 8003982C C6000038 */ lwc1 $f0, 0x38($s0) -/* 14C30 80039830 3C014180 */ lui $at, 0x4180 -/* 14C34 80039834 44811000 */ mtc1 $at, $f2 -/* 14C38 80039838 E7A00020 */ swc1 $f0, 0x20($sp) -/* 14C3C 8003983C 46002005 */ abs.s $f0, $f4 -/* 14C40 80039840 46020500 */ add.s $f20, $f0, $f2 -/* 14C44 80039844 C600003C */ lwc1 $f0, 0x3c($s0) -/* 14C48 80039848 3C014150 */ lui $at, 0x4150 -/* 14C4C 8003984C 44811000 */ mtc1 $at, $f2 -/* 14C50 80039850 C6040040 */ lwc1 $f4, 0x40($s0) -/* 14C54 80039854 46020000 */ add.s $f0, $f0, $f2 -/* 14C58 80039858 E7A40028 */ swc1 $f4, 0x28($sp) -/* 14C5C 8003985C E7B4002C */ swc1 $f20, 0x2c($sp) -/* 14C60 80039860 E7A00024 */ swc1 $f0, 0x24($sp) -/* 14C64 80039864 8E020000 */ lw $v0, ($s0) -/* 14C68 80039868 3C030400 */ lui $v1, 0x400 -/* 14C6C 8003986C 00431024 */ and $v0, $v0, $v1 -/* 14C70 80039870 14400009 */ bnez $v0, .L80039898 -/* 14C74 80039874 27A2002C */ addiu $v0, $sp, 0x2c -/* 14C78 80039878 27A50020 */ addiu $a1, $sp, 0x20 -/* 14C7C 8003987C 27A60024 */ addiu $a2, $sp, 0x24 -/* 14C80 80039880 AFA20010 */ sw $v0, 0x10($sp) -/* 14C84 80039884 8E040080 */ lw $a0, 0x80($s0) -/* 14C88 80039888 0C0372DF */ jal npc_raycast_down_sides -/* 14C8C 8003988C 27A70028 */ addiu $a3, $sp, 0x28 -/* 14C90 80039890 0800E633 */ j .L800398CC -/* 14C94 80039894 00000000 */ nop -.L80039898: -/* 14C98 80039898 AFA20010 */ sw $v0, 0x10($sp) -/* 14C9C 8003989C C600000C */ lwc1 $f0, 0xc($s0) -/* 14CA0 800398A0 27A50020 */ addiu $a1, $sp, 0x20 -/* 14CA4 800398A4 E7A00014 */ swc1 $f0, 0x14($sp) -/* 14CA8 800398A8 860200A6 */ lh $v0, 0xa6($s0) -/* 14CAC 800398AC 27A60024 */ addiu $a2, $sp, 0x24 -/* 14CB0 800398B0 44820000 */ mtc1 $v0, $f0 -/* 14CB4 800398B4 00000000 */ nop -/* 14CB8 800398B8 46800020 */ cvt.s.w $f0, $f0 -/* 14CBC 800398BC E7A00018 */ swc1 $f0, 0x18($sp) -/* 14CC0 800398C0 8E040080 */ lw $a0, 0x80($s0) -/* 14CC4 800398C4 0C0371DE */ jal npc_raycast_down_ahead -/* 14CC8 800398C8 27A70028 */ addiu $a3, $sp, 0x28 -.L800398CC: -/* 14CCC 800398CC 1040000F */ beqz $v0, .L8003990C -/* 14CD0 800398D0 0000102D */ daddu $v0, $zero, $zero -/* 14CD4 800398D4 C7A0002C */ lwc1 $f0, 0x2c($sp) -/* 14CD8 800398D8 4614003E */ c.le.s $f0, $f20 -/* 14CDC 800398DC 00000000 */ nop -/* 14CE0 800398E0 45000009 */ bc1f .L80039908 -/* 14CE4 800398E4 24020001 */ addiu $v0, $zero, 1 -/* 14CE8 800398E8 C7A00024 */ lwc1 $f0, 0x24($sp) -/* 14CEC 800398EC 8E030000 */ lw $v1, ($s0) -/* 14CF0 800398F0 3C048011 */ lui $a0, %hi(D_8010C97A) -/* 14CF4 800398F4 9484C97A */ lhu $a0, %lo(D_8010C97A)($a0) -/* 14CF8 800398F8 34631000 */ ori $v1, $v1, 0x1000 -/* 14CFC 800398FC E600003C */ swc1 $f0, 0x3c($s0) -/* 14D00 80039900 0800E646 */ j .L80039918 -/* 14D04 80039904 A6040084 */ sh $a0, 0x84($s0) -.L80039908: -/* 14D08 80039908 0000102D */ daddu $v0, $zero, $zero -.L8003990C: -/* 14D0C 8003990C 8E030000 */ lw $v1, ($s0) -/* 14D10 80039910 2404EFFF */ addiu $a0, $zero, -0x1001 -/* 14D14 80039914 00641824 */ and $v1, $v1, $a0 -.L80039918: -/* 14D18 80039918 AE030000 */ sw $v1, ($s0) -.L8003991C: -/* 14D1C 8003991C 8FBF0034 */ lw $ra, 0x34($sp) -/* 14D20 80039920 8FB00030 */ lw $s0, 0x30($sp) -/* 14D24 80039924 D7B40038 */ ldc1 $f20, 0x38($sp) -/* 14D28 80039928 03E00008 */ jr $ra -/* 14D2C 8003992C 27BD0040 */ addiu $sp, $sp, 0x40