From 31669e142453758d8ee4278043943329ac830984 Mon Sep 17 00:00:00 2001 From: Aetias Date: Sun, 26 May 2024 10:49:32 +0200 Subject: [PATCH] Decomp `Actor` --- include/Actor/Actor.hpp | 21 ++++---- include/Actor/FilterActorBase.hpp | 17 +++++++ include/Item/ItemManager.hpp | 2 +- include/Player/EquipRope.hpp | 2 + include/Player/PlayerBase.hpp | 2 +- include/lib/math.h | 6 +++ src/00_Core/Actor/Actor.cpp | 83 +++++++++++++++---------------- src/00_Core/Item/ItemManager.cpp | 4 +- src/00_Core/Player/PlayerBase.cpp | 2 +- 9 files changed, 80 insertions(+), 59 deletions(-) diff --git a/include/Actor/Actor.hpp b/include/Actor/Actor.hpp index cd59bde4..90b04746 100644 --- a/include/Actor/Actor.hpp +++ b/include/Actor/Actor.hpp @@ -49,20 +49,13 @@ struct Actor_UnkStruct_0a4 { Actor_UnkStruct_0a4(q20 x, q20 y, q20 z, s32 unk_10); }; -class KillPickupsFilter : public FilterActorBase { +class KillPickupsFilter: FilterActorReturn, public FilterActorBase { public: /* 00 (base) */ - /* 04 */ ActorRef mUnk_4[10]; - /* a4 */ + /* 04 */ /* 0 */ virtual bool Filter(Actor *actor) override; /* 4 */ - - inline KillPickupsFilter() { - for (s32 i = 0; i < 10; ++i) { - mUnk_4[i].Reset(); - } - } }; typedef u32 PlayerCollide; @@ -78,7 +71,13 @@ struct Knockback { /* 00 */ u8 mUnk_00; /* 04 */ Vec3p vec; /* 10 */ unk32 mUnk_10; - /* 14 */ unk32 mUnk_14; + /* 14 */ Actor *actor; + + inline Knockback(): + mUnk_00(0), + mUnk_10(0xb), + actor(NULL) + {} }; class Actor : public SysObject { @@ -139,7 +138,7 @@ public: /* 120 */ s16 mUnk_120; /* 122 */ unk16 mUnk_122; /* 124 */ u8 mUnk_124; - /* 125 */ unk8 mUnk_125; + /* 125 */ u8 mUnk_125; /* 126 */ u16 mUnk_126; /* 128 */ bool mUnk_128; /* 129 */ bool mUnk_129; diff --git a/include/Actor/FilterActorBase.hpp b/include/Actor/FilterActorBase.hpp index 6a969411..092987a7 100644 --- a/include/Actor/FilterActorBase.hpp +++ b/include/Actor/FilterActorBase.hpp @@ -3,6 +3,8 @@ #include "global.h" #include "types.h" +#include "Actor/ActorRef.hpp" + class Actor; class FilterActorBase { @@ -13,3 +15,18 @@ public: /* 0 */ virtual bool Filter(Actor *actor) = 0; /* 4 */ }; + +class FilterActorReturn { +public: + /* 00 */ ActorRef refs[20]; + + inline FilterActorReturn() { + ActorRef *ref = refs; + ActorRef *end; + do { + end = &refs[20]; + ref->Reset(); + ref++; + } while (ref < end); + } +}; diff --git a/include/Item/ItemManager.hpp b/include/Item/ItemManager.hpp index 24bcdb05..3dcb77b9 100644 --- a/include/Item/ItemManager.hpp +++ b/include/Item/ItemManager.hpp @@ -252,7 +252,7 @@ public: void Shield_vfunc_38(unk32 param1); void EquipItem_vfunc_38(unk32 param1); bool EquipCollidesWith(Cylinder *cylinder, ItemFlag equipId); - void EquipItem_vfunc_2c(ItemFlag equipId); + s32 EquipItem_vfunc_2c(ItemFlag equipId); EquipItem* GetEquipItem(ItemFlag equipId); bool func_ov00_020ad790(unk32 param1); bool SetEquippedItem(ItemFlag equipId); diff --git a/include/Player/EquipRope.hpp b/include/Player/EquipRope.hpp index a1ea4089..19aa6997 100644 --- a/include/Player/EquipRope.hpp +++ b/include/Player/EquipRope.hpp @@ -14,6 +14,8 @@ struct EquipRope_Unk_18 { /* 1c */ }; +class Actor; + class EquipRope : public EquipItem { public: /* 00 (base) */ diff --git a/include/Player/PlayerBase.hpp b/include/Player/PlayerBase.hpp index 0bb534ff..0b6a5187 100644 --- a/include/Player/PlayerBase.hpp +++ b/include/Player/PlayerBase.hpp @@ -56,7 +56,7 @@ public: bool CollidesWith(Cylinder *cylinder); bool func_ov00_020a7c60(Vec3p *param1, Vec3p *param2, s32 param3); bool EquipCollidesWith(Cylinder *cylinder, ItemFlag equipId); - void EquipItem_vfunc_2c(); + s32 EquipItem_vfunc_2c(); void SetHealth(s16 health); }; diff --git a/include/lib/math.h b/include/lib/math.h index a11f5583..8242284e 100644 --- a/include/lib/math.h +++ b/include/lib/math.h @@ -65,6 +65,12 @@ inline void Vec3p_CopyXZ(Vec3p *vec, Vec3p *out) { out->z = z; } +inline void Vec3p_Copy(Vec3p *vec, Vec3p *out) { + out->x = vec->x; + out->y = vec->y; + out->z = vec->z; +} + typedef struct { /* 00 */ q20 x; /* 04 */ q20 y; diff --git a/src/00_Core/Actor/Actor.cpp b/src/00_Core/Actor/Actor.cpp index 34dfa10b..d780afd2 100644 --- a/src/00_Core/Actor/Actor.cpp +++ b/src/00_Core/Actor/Actor.cpp @@ -80,6 +80,7 @@ ARM Actor::Actor(): mUnk_106(0), mUnk_107(0), mUnk_108(0), + mUnk_109(0), mUnk_110(0), mUnk_111(0), mUnk_112(0), @@ -367,7 +368,7 @@ ARM bool Actor::IsNearLink() { } ARM void Actor::func_ov00_020c1cf8() { - if ((!mUnk_0a4.mUnk_00 && !mUnk_0a4.mUnk_01) || !(mUnk_129 != true && mUnk_11d != true && mUnk_11b != true)) { + if (mUnk_0a4.mUnk_00 || mUnk_0a4.mUnk_01 || mUnk_129 == true || mUnk_11d == true || mUnk_11b == true) { mInactive = 0; } else { if (this->IsNearLink()) { @@ -439,45 +440,39 @@ ARM bool Actor::func_ov00_020c1fc8(PlayerCollide flags) { Vec3p_Sub(&mPos, &gPlayerPos, &vecFromPlayer); if (this->CollidesWithPlayer(flags & PlayerCollide_Sword)) { Knockback knockback; - knockback.mUnk_00 = 0; - knockback.mUnk_10 = 0xb; - knockback.mUnk_14 = 0; - gPlayer->EquipItem_vfunc_2c(); + knockback.mUnk_00 = gPlayer->EquipItem_vfunc_2c(); knockback.vec = vecFromPlayer; + knockback.mUnk_10 = 0; + knockback.actor = NULL; result = this->vfunc_48(&knockback); } else if (this->CollidesWithPlayer(flags & PlayerCollide_Shield)) { Knockback knockback; - knockback.mUnk_10 = 0xb; - knockback.mUnk_14 = 0; knockback.mUnk_00 = 0; knockback.vec = vecFromPlayer; - s32 wisdomLvl = gItemManager->GetActiveFairyLevel(FairyId_Wisdom); - if (wisdomLvl >= 1) { + if ((s32) gItemManager->GetActiveFairyLevel(FairyId_Wisdom) >= 1) { knockback.mUnk_10 = 3; } else { knockback.mUnk_10 = 2; } + knockback.actor = NULL; result = this->vfunc_48(&knockback); } else if (this->CollidesWithPlayer(flags & PlayerCollide_Hammer)) { Knockback knockback; - knockback.mUnk_00 = 0; - knockback.mUnk_10 = 0xb; - knockback.mUnk_14 = 0; - gPlayer->EquipItem_vfunc_2c(); + knockback.mUnk_00 = gPlayer->EquipItem_vfunc_2c(); knockback.vec = vecFromPlayer; + knockback.mUnk_10 = 4; + knockback.actor = NULL; result = this->vfunc_48(&knockback); } else if (this->CollidesWithPlayer(flags & PlayerCollide_Gongoron)) { Knockback knockback; - knockback.mUnk_00 = 0; - knockback.mUnk_10 = 0xb; - knockback.mUnk_14 = 0; - u8 unk1 = gPlayerLink->vfunc_78(); + knockback.mUnk_00 = gPlayerLink->vfunc_78(); knockback.vec = vecFromPlayer; - if (unk1 != 0) { + if (knockback.mUnk_00 != 0) { knockback.mUnk_10 = 9; } else { knockback.mUnk_10 = 2; } + knockback.actor = NULL; result = this->vfunc_48(&knockback); } } @@ -533,25 +528,26 @@ ARM void Actor::func_ov00_020c23d4(ActorRef *ref, Actor *actor, Cylinder *cylind gActorManager->func_ov00_020c399c(actor->mRef.index, cylinder); } -ARM bool Actor::func_ov00_020c243c(ActorTypeId *actorTypes, Actor **result) { - if (result) *result = NULL; +ARM bool Actor::func_ov00_020c243c(ActorTypeId *actorTypes, Actor **out) { + if (out) *out = NULL; if (gAdventureFlags->func_ov00_02097738()) return false; + + bool result = false; if (mHitbox.size >= 0) { Actor *actor = gActorManager->func_ov00_020c39ac(mRef.index, actorTypes, false); if (actor) { Knockback knockback; - knockback.mUnk_10 = 0xb; - knockback.mUnk_00 = 0; - knockback.mUnk_14 = 0; - - Vec3p vec; - if (actor->mType != ActorTypeId_Arrow && actor->mType != ActorTypeId_SBEM) { - Vec3p_Sub(&mPos, &actor->mPrevPos, &vec); + if (actor->mType == ActorTypeId_Arrow || actor->mType == ActorTypeId_SBEM) { + q20 cos = COS(actor->mAngle); + q20 sin = SIN(actor->mAngle); + knockback.vec.x = sin; + knockback.vec.y = 0; + knockback.vec.z = cos; } else { - vec.x = SIN(actor->mAngle); - vec.z = COS(actor->mAngle); - vec.y = 0; + Vec3p_Sub(&mPos, &actor->mPrevPos, &knockback.vec); } + knockback.mUnk_00 = actor->mUnk_125; + knockback.actor = actor; switch (actor->mType) { case ActorTypeId_SBEM: { @@ -585,6 +581,7 @@ ARM bool Actor::func_ov00_020c243c(ActorTypeId *actorTypes, Actor **result) { case ActorTypeId_BKEY: case ActorTypeId_FORC: case ActorTypeId_FLTB: + case ActorTypeId_TSUB: { knockback.mUnk_10 = 10; } break; @@ -593,19 +590,19 @@ ARM bool Actor::func_ov00_020c243c(ActorTypeId *actorTypes, Actor **result) { knockback.mUnk_10 = 4; } break; - case ActorTypeId_TSUB: { + default: { knockback.mUnk_10 = 11; } break; } - if (this->vfunc_48(&knockback)) { + result = this->vfunc_48(&knockback); + if (result) { actor->mUnk_040 = this->mRef; - if (result) *result = actor; - return true; + if (out) *out = actor; } } - } - return false; + } + return result; } ARM bool Actor::CollidesWith(Actor *other) { @@ -713,7 +710,11 @@ ARM void Actor::GetHitbox(Cylinder *hitbox) { q20 sin = SIN(angle); q20 cos = COS(angle); - Vec3p_Rotate(&mHitbox.pos, sin, cos, &hitbox->pos); + // Vec3p_Rotate(&mHitbox.pos, sin, cos, &hitbox->pos); + hitbox->pos.x += MUL_Q20(mHitbox.pos.z, sin); + hitbox->pos.z += MUL_Q20(mHitbox.pos.z, cos); + hitbox->pos.x += MUL_Q20(mHitbox.pos.x, cos); + hitbox->pos.z += MUL_Q20(mHitbox.pos.x, -sin); } ARM void Actor::GetUnk_08c(Cylinder *param1) { @@ -876,12 +877,8 @@ ARM void Actor::ApplyGravity() { ARM bool Actor::func_ov00_020c3094() { bool result = false; Vec3p pos, prevPos; - pos.x = mPos.x; - pos.y = mPos.y; - pos.z = mPos.z; - prevPos.x = mPrevPos.x; - prevPos.y = mPrevPos.y; - prevPos.z = mPrevPos.z; + Vec3p_Copy(&mPos, &pos); + Vec3p_Copy(&mPrevPos, &prevPos); s32 unk1 = gMapManager->func_ov00_02083ef8(&pos, &prevPos); if (mPos.y <= unk1) { result = true; diff --git a/src/00_Core/Item/ItemManager.cpp b/src/00_Core/Item/ItemManager.cpp index 3cc1e185..e20081d4 100644 --- a/src/00_Core/Item/ItemManager.cpp +++ b/src/00_Core/Item/ItemManager.cpp @@ -211,8 +211,8 @@ ARM bool ItemManager::EquipCollidesWith(Cylinder *hitbox, ItemFlag equipId) { return false; } -ARM void ItemManager::EquipItem_vfunc_2c(ItemFlag equipId) { - (*mEquipItems)[equipId]->vfunc_2c(); +ARM s32 ItemManager::EquipItem_vfunc_2c(ItemFlag equipId) { + return (*mEquipItems)[equipId]->vfunc_2c(); } ARM EquipItem* ItemManager::GetEquipItem(ItemFlag equipId) { diff --git a/src/00_Core/Player/PlayerBase.cpp b/src/00_Core/Player/PlayerBase.cpp index c5a93674..dfdb4eb5 100644 --- a/src/00_Core/Player/PlayerBase.cpp +++ b/src/00_Core/Player/PlayerBase.cpp @@ -14,7 +14,7 @@ bool PlayerBase::func_ov00_020a7c00(s32 param1) {} bool PlayerBase::CollidesWith(Cylinder *cylinder) {} bool PlayerBase::func_ov00_020a7c60(Vec3p *param1, Vec3p *param2, s32 param3) {} void PlayerBase::EquipItem_vfunc_3c(Cylinder *cylinder, ItemFlag equipId) {} -void PlayerBase::EquipItem_vfunc_2c() {} +s32 PlayerBase::EquipItem_vfunc_2c() {} void PlayerBase::SetHealth(s16 health) {} void PlayerBase::AddHealth(s16 amount) {} bool PlayerBase::Teleport(Vec3p *pos, s16 angle, unk32 param3, bool param4, bool param5) {}