From 9d78c47057463540d92c7ba5b610e8fd4dc430bb Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Thu, 20 Oct 2022 14:18:42 +0300 Subject: [PATCH] Match and link CProjectileInfo Former-commit-id: 928ade01755a1d96f1fe22f3198cec55123e85d9 --- asm/MetroidPrime/CSteeringBehaviors.s | 9 +-- asm/MetroidPrime/Enemies/CFlyingPirate.s | 4 +- asm/MetroidPrime/Enemies/CSpacePirate.s | 4 +- asm/MetroidPrime/Weapons/CProjectileInfo.s | 9 +-- configure.py | 2 +- include/Kyoto/TToken.hpp | 1 + include/MetroidPrime/CSteeringBehaviors.hpp | 20 +++++ include/MetroidPrime/Player/CPlayer.hpp | 5 ++ .../MetroidPrime/Weapons/CProjectileInfo.hpp | 25 ++++++ .../Weapons/CProjectileWeapon.hpp | 2 + include/Weapons/CWeaponDescription.hpp | 23 ++++++ obj_files.mk | 2 +- src/MetroidPrime/Weapons/CProjectileInfo.cpp | 76 +++++++++++++++++++ 13 files changed, 166 insertions(+), 16 deletions(-) create mode 100644 include/MetroidPrime/CSteeringBehaviors.hpp create mode 100644 include/MetroidPrime/Weapons/CProjectileInfo.hpp create mode 100644 include/Weapons/CWeaponDescription.hpp create mode 100644 src/MetroidPrime/Weapons/CProjectileInfo.cpp diff --git a/asm/MetroidPrime/CSteeringBehaviors.s b/asm/MetroidPrime/CSteeringBehaviors.s index 57909db3..2831f5c6 100644 --- a/asm/MetroidPrime/CSteeringBehaviors.s +++ b/asm/MetroidPrime/CSteeringBehaviors.s @@ -219,8 +219,8 @@ lbl_8013CCC4: /* 8013CD48 00139CA8 38 21 01 30 */ addi r1, r1, 0x130 /* 8013CD4C 00139CAC 4E 80 00 20 */ blr -.global ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3ffRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f -ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3ffRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f: +.global ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3fffRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f +ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3fffRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f: /* 8013CD50 00139CB0 94 21 FE 80 */ stwu r1, -0x180(r1) /* 8013CD54 00139CB4 7C 08 02 A6 */ mflr r0 /* 8013CD58 00139CB8 90 01 01 84 */ stw r0, 0x184(r1) @@ -492,8 +492,8 @@ lbl_8013D0D8: /* 8013D164 0013A0C4 38 21 01 80 */ addi r1, r1, 0x180 /* 8013D168 0013A0C8 4E 80 00 20 */ blr -.global ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3ffRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f -ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3ffRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f: +.global ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3fffRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f +ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3fffRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f: /* 8013D16C 0013A0CC 94 21 FE 80 */ stwu r1, -0x180(r1) /* 8013D170 0013A0D0 7C 08 02 A6 */ mflr r0 /* 8013D174 0013A0D4 90 01 01 84 */ stw r0, 0x184(r1) @@ -2567,4 +2567,3 @@ lbl_805AB840: # ROM: 0x3F80E0 .4byte 0x3FC90FDB .4byte 0 - diff --git a/asm/MetroidPrime/Enemies/CFlyingPirate.s b/asm/MetroidPrime/Enemies/CFlyingPirate.s index b073b9a9..3002f130 100644 --- a/asm/MetroidPrime/Enemies/CFlyingPirate.s +++ b/asm/MetroidPrime/Enemies/CFlyingPirate.s @@ -12399,7 +12399,7 @@ sub_801fec6c: /* 801FECB4 001FBC14 90 7D 00 08 */ stw r3, 8(r29) /* 801FECB8 001FBC18 7F C4 F3 78 */ mr r4, r30 /* 801FECBC 001FBC1C 38 7D 00 0C */ addi r3, r29, 0xc -/* 801FECC0 001FBC20 48 01 D3 51 */ bl sub_8021c010 +/* 801FECC0 001FBC20 48 01 D3 51 */ bl __ct__15CProjectileInfoFR12CInputStream /* 801FECC4 001FBC24 7F C3 F3 78 */ mr r3, r30 /* 801FECC8 001FBC28 48 13 FF BD */ bl ReadLong__12CInputStreamFv /* 801FECCC 001FBC2C 54 63 04 3E */ clrlwi r3, r3, 0x10 @@ -12407,7 +12407,7 @@ sub_801fec6c: /* 801FECD4 001FBC34 B0 7D 00 34 */ sth r3, 0x34(r29) /* 801FECD8 001FBC38 7F C4 F3 78 */ mr r4, r30 /* 801FECDC 001FBC3C 38 7D 00 38 */ addi r3, r29, 0x38 -/* 801FECE0 001FBC40 48 01 D3 31 */ bl sub_8021c010 +/* 801FECE0 001FBC40 48 01 D3 31 */ bl __ct__15CProjectileInfoFR12CInputStream /* 801FECE4 001FBC44 88 01 00 0C */ lbz r0, 0xc(r1) /* 801FECE8 001FBC48 38 A0 00 00 */ li r5, 0 /* 801FECEC 001FBC4C 50 A0 3E 30 */ rlwimi r0, r5, 7, 0x18, 0x18 diff --git a/asm/MetroidPrime/Enemies/CSpacePirate.s b/asm/MetroidPrime/Enemies/CSpacePirate.s index f120a4f1..468f9bf6 100644 --- a/asm/MetroidPrime/Enemies/CSpacePirate.s +++ b/asm/MetroidPrime/Enemies/CSpacePirate.s @@ -12774,7 +12774,7 @@ __ct__Q212CSpacePirate16CSpacePirateDataFR12CInputStreamUi: /* 8012B0D4 00128034 98 7D 00 1C */ stb r3, 0x1c(r29) /* 8012B0D8 00128038 7F C4 F3 78 */ mr r4, r30 /* 8012B0DC 0012803C 38 7D 00 20 */ addi r3, r29, 0x20 -/* 8012B0E0 00128040 48 0F 0F 31 */ bl sub_8021c010 +/* 8012B0E0 00128040 48 0F 0F 31 */ bl __ct__15CProjectileInfoFR12CInputStream /* 8012B0E4 00128044 7F C3 F3 78 */ mr r3, r30 /* 8012B0E8 00128048 48 21 3B 9D */ bl ReadLong__12CInputStreamFv /* 8012B0EC 0012804C 54 63 04 3E */ clrlwi r3, r3, 0x10 @@ -12788,7 +12788,7 @@ __ct__Q212CSpacePirate16CSpacePirateDataFR12CInputStreamUi: /* 8012B10C 0012806C D0 3D 00 68 */ stfs f1, 0x68(r29) /* 8012B110 00128070 7F C4 F3 78 */ mr r4, r30 /* 8012B114 00128074 38 7D 00 6C */ addi r3, r29, 0x6c -/* 8012B118 00128078 48 0F 0E F9 */ bl sub_8021c010 +/* 8012B118 00128078 48 0F 0E F9 */ bl __ct__15CProjectileInfoFR12CInputStream /* 8012B11C 0012807C 7F C3 F3 78 */ mr r3, r30 /* 8012B120 00128080 48 21 3B 09 */ bl ReadFloat__12CInputStreamFv /* 8012B124 00128084 D0 3D 00 94 */ stfs f1, 0x94(r29) diff --git a/asm/MetroidPrime/Weapons/CProjectileInfo.s b/asm/MetroidPrime/Weapons/CProjectileInfo.s index 7df37c70..3d34aaf5 100644 --- a/asm/MetroidPrime/Weapons/CProjectileInfo.s +++ b/asm/MetroidPrime/Weapons/CProjectileInfo.s @@ -63,7 +63,7 @@ PredictInterceptPos__15CProjectileInfoFRC9CVector3fRC9CVector3fRC7CPlayerbff: /* 8021BD78 00218CD8 38 A1 00 44 */ addi r5, r1, 0x44 /* 8021BD7C 00218CDC 38 C1 00 38 */ addi r6, r1, 0x38 /* 8021BD80 00218CE0 39 01 00 50 */ addi r8, r1, 0x50 -/* 8021BD84 00218CE4 4B F2 0F CD */ bl ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3ffRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f +/* 8021BD84 00218CE4 4B F2 0F CD */ bl ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3fffRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f /* 8021BD88 00218CE8 48 00 00 E0 */ b lbl_8021BE68 lbl_8021BD8C: /* 8021BD8C 00218CEC 38 61 00 44 */ addi r3, r1, 0x44 @@ -102,7 +102,7 @@ lbl_8021BDE0: /* 8021BE08 00218D68 D0 01 00 30 */ stfs f0, 0x30(r1) /* 8021BE0C 00218D6C C0 08 00 08 */ lfs f0, 8(r8) /* 8021BE10 00218D70 D0 01 00 34 */ stfs f0, 0x34(r1) -/* 8021BE14 00218D74 4B F2 13 59 */ bl ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3ffRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f +/* 8021BE14 00218D74 4B F2 13 59 */ bl ProjectOrbitalIntersection__18CSteeringBehaviorsFRC9CVector3fffRC9CVector3fRC9CVector3fRC9CVector3fR9CVector3f /* 8021BE18 00218D78 48 00 00 50 */ b lbl_8021BE68 lbl_8021BE1C: /* 8021BE1C 00218D7C 57 A0 06 3F */ clrlwi. r0, r29, 0x18 @@ -241,8 +241,8 @@ lbl_8021BFE8: /* 8021C008 00218F68 38 21 00 30 */ addi r1, r1, 0x30 /* 8021C00C 00218F6C 4E 80 00 20 */ blr -.global sub_8021c010 -sub_8021c010: +.global __ct__15CProjectileInfoFR12CInputStream +__ct__15CProjectileInfoFR12CInputStream: /* 8021C010 00218F70 94 21 FF E0 */ stwu r1, -0x20(r1) /* 8021C014 00218F74 7C 08 02 A6 */ mflr r0 /* 8021C018 00218F78 90 01 00 24 */ stw r0, 0x24(r1) @@ -349,4 +349,3 @@ lbl_805AD108: # ROM: 0x3F99A8 .4byte 0x472FC800 .4byte 0 - diff --git a/configure.py b/configure.py index f111a6d1..a7259375 100755 --- a/configure.py +++ b/configure.py @@ -318,7 +318,7 @@ LIBS = [ "MetroidPrime/CEnvFxManager", "MetroidPrime/Weapons/CEnergyProjectile", "MetroidPrime/ScriptObjects/CScriptGunTurret", - "MetroidPrime/Weapons/CProjectileInfo", + ["MetroidPrime/Weapons/CProjectileInfo", True], "MetroidPrime/CInGameTweakManager", "MetroidPrime/Enemies/CBabygoth", "MetroidPrime/Enemies/CEyeBall", diff --git a/include/Kyoto/TToken.hpp b/include/Kyoto/TToken.hpp index b8588db4..7ea670b8 100644 --- a/include/Kyoto/TToken.hpp +++ b/include/Kyoto/TToken.hpp @@ -19,6 +19,7 @@ public: T* GetT() { return reinterpret_cast< T* >(CToken::GetObj()->GetContents()); } T* operator*() { return GetT(); } + T* operator->() { return GetT(); } static inline rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetIObjObjectFor(const rstl::auto_ptr< T >& obj) { diff --git a/include/MetroidPrime/CSteeringBehaviors.hpp b/include/MetroidPrime/CSteeringBehaviors.hpp new file mode 100644 index 00000000..f740d295 --- /dev/null +++ b/include/MetroidPrime/CSteeringBehaviors.hpp @@ -0,0 +1,20 @@ +#ifndef _CSTEERINGBEHAVIORS +#define _CSTEERINGBEHAVIORS + +class CVector3f; +class CSteeringBehaviors { +public: + static bool ProjectLinearIntersection(const CVector3f& v0, float f1, const CVector3f& v1, + const CVector3f& v2, CVector3f& v3); + static bool ProjectLinearIntersection(const CVector3f& v0, float f1, const CVector3f& v1, + const CVector3f& v2, const CVector3f& v3, CVector3f& v4); + + static bool ProjectOrbitalIntersection(const CVector3f& v0, float f1, float f2, + const CVector3f& v1, const CVector3f& v2, + const CVector3f& v3, CVector3f& v4); + static bool ProjectOrbitalIntersection(const CVector3f& v0, float f1, float f2, + const CVector3f& v1, const CVector3f& v2, + const CVector3f& v3, const CVector3f& v4, CVector3f& v5); +}; + +#endif // _CSTEERINGBEHAVIORS diff --git a/include/MetroidPrime/Player/CPlayer.hpp b/include/MetroidPrime/Player/CPlayer.hpp index 6d7e755d..3694f6e4 100644 --- a/include/MetroidPrime/Player/CPlayer.hpp +++ b/include/MetroidPrime/Player/CPlayer.hpp @@ -175,6 +175,7 @@ public: } TUniqueId GetOrbitTargetId() const { return x310_orbitTargetId; } + const CVector3f& GetOrbitPoint() const { return x314_orbitPoint; } TUniqueId GetOrbitNextTargetId() const { return x33c_orbitNextTargetId; } TUniqueId GetScanningObjectId() const { return x3b4_scanningObject; } EGrappleState GetGrappleState() const { return x3b8_grappleState; } @@ -187,6 +188,10 @@ public: void Teleport(const CTransform4f& xf, CStateManager& mgr, bool resetBallCam); void SetSpawnedMorphBallState(EPlayerMorphBallState state, CStateManager& mgr); + CVector3f GetDampedClampedVelocityWR() const; + float GetAverageSpeed() const; + float GetGravity() const; + private: struct CVisorSteam { float x0_curTargetAlpha; diff --git a/include/MetroidPrime/Weapons/CProjectileInfo.hpp b/include/MetroidPrime/Weapons/CProjectileInfo.hpp new file mode 100644 index 00000000..377211e8 --- /dev/null +++ b/include/MetroidPrime/Weapons/CProjectileInfo.hpp @@ -0,0 +1,25 @@ +#ifndef _CPROJECTILEINFO +#define _CPROJECTILEINFO + +#include "MetroidPrime/CDamageInfo.hpp" + +#include "Kyoto/TToken.hpp" +#include "Kyoto/Math/CVector3f.hpp" + +class CPlayer; +class CWeaponDescription; + +class CProjectileInfo { + TCachedToken x0_weaponDescription; + CDamageInfo xc_damageInfo; + +public: + CProjectileInfo(CAssetId, const CDamageInfo&); + explicit CProjectileInfo(CInputStream&); + + float GetProjectileSpeed() const; + CVector3f PredictInterceptPos(const CVector3f& gunPos, const CVector3f& aimPos, const CPlayer& player, bool gravity, float dt); + static CVector3f PredictInterceptPos(const CVector3f& gunPos, const CVector3f& aimPos, const CPlayer& player, bool gravity, float speed, float dt); +}; + +#endif // _CPROJECTILEINFO diff --git a/include/MetroidPrime/Weapons/CProjectileWeapon.hpp b/include/MetroidPrime/Weapons/CProjectileWeapon.hpp index 6105ca4a..9278527f 100644 --- a/include/MetroidPrime/Weapons/CProjectileWeapon.hpp +++ b/include/MetroidPrime/Weapons/CProjectileWeapon.hpp @@ -27,6 +27,8 @@ public: virtual void Render(); virtual CVector3f GetTranslation() const; virtual CTransform4f GetTransform() const; + + static float GetTickPeriod(); // { return 0.0166667f; } private: TLockedToken< CWeaponDescription > x4_weaponDesc; diff --git a/include/Weapons/CWeaponDescription.hpp b/include/Weapons/CWeaponDescription.hpp new file mode 100644 index 00000000..bacfc691 --- /dev/null +++ b/include/Weapons/CWeaponDescription.hpp @@ -0,0 +1,23 @@ +#ifndef _CWEAPONDESCRIPTION +#define _CWEAPONDESCRIPTION + +#include "Kyoto/Particles/CVectorElement.hpp" +#include "Kyoto/Particles/CModVectorElement.hpp" + +#include "rstl/single_ptr.hpp" + +class CWeaponDescription { + public: + rstl::single_ptr x0_IORN; + rstl::single_ptr x4_IVEC; + rstl::single_ptr x8_PSOV; + rstl::single_ptr xc_PSVM; + bool x10_VMD2; + rstl::single_ptr x14_PSLT; + rstl::single_ptr x18_PSCL; + rstl::single_ptr x1c_PCOL; + rstl::single_ptr x20_POFS; + rstl::single_ptr x24_OFST; +}; + +#endif // _CWEAPONDESCRIPTION diff --git a/obj_files.mk b/obj_files.mk index 95ff563f..ac0c14a5 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -285,7 +285,7 @@ METROIDPRIME :=\ $(BUILD_DIR)/asm/MetroidPrime/CEnvFxManager.o\ $(BUILD_DIR)/asm/MetroidPrime/Weapons/CEnergyProjectile.o\ $(BUILD_DIR)/asm/MetroidPrime/ScriptObjects/CScriptGunTurret.o\ - $(BUILD_DIR)/asm/MetroidPrime/Weapons/CProjectileInfo.o\ + $(BUILD_DIR)/src/MetroidPrime/Weapons/CProjectileInfo.o\ $(BUILD_DIR)/asm/MetroidPrime/CInGameTweakManager.o\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CBabygoth.o\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CEyeBall.o\ diff --git a/src/MetroidPrime/Weapons/CProjectileInfo.cpp b/src/MetroidPrime/Weapons/CProjectileInfo.cpp new file mode 100644 index 00000000..406b0491 --- /dev/null +++ b/src/MetroidPrime/Weapons/CProjectileInfo.cpp @@ -0,0 +1,76 @@ +#include "MetroidPrime/Weapons/CProjectileInfo.hpp" + +#include "MetroidPrime/CSteeringBehaviors.hpp" +#include "MetroidPrime/Player/CPlayer.hpp" +#include "MetroidPrime/Weapons/CProjectileWeapon.hpp" + +#include "Weapons/CWeaponDescription.hpp" + +#include "Kyoto/Streams/CInputStream.hpp" + +CProjectileInfo::CProjectileInfo(CAssetId proj, const CDamageInfo& dInfo) +: x0_weaponDescription(gpSimplePool->GetObj(SObjectTag('WPSC', proj))), xc_damageInfo(dInfo) {} + +CProjectileInfo::CProjectileInfo(CInputStream& in ) +: x0_weaponDescription(gpSimplePool->GetObj(SObjectTag('WPSC', CAssetId(in.ReadLong())))), xc_damageInfo(in) {} + +float CProjectileInfo::GetProjectileSpeed() const { + float result = 45000.0f; + TToken< CWeaponDescription > token(x0_weaponDescription); + + if (!token->x4_IVEC.null()) { + CVector3f vec = CVector3f::Zero(); + token->x4_IVEC->GetValue(0, vec); + result = vec.Magnitude() / CProjectileWeapon::GetTickPeriod(); + } + return result; +} + +CVector3f CProjectileInfo::PredictInterceptPos(const CVector3f& gunPos, const CVector3f& aimPos, + const CPlayer& player, bool gravity, float dt) { + return PredictInterceptPos(gunPos, aimPos, player, gravity, GetProjectileSpeed(), dt); +} + +CVector3f CProjectileInfo::PredictInterceptPos(const CVector3f& gunPos, const CVector3f& aimPos, + const CPlayer& player, bool gravity, float speed, + float dt) { + CVector3f ret = CVector3f::Zero(); + const CVector3f playerVel = player.GetDampedClampedVelocityWR(); + const CVector3f gravVec(0.f, 0.f, player.GetGravity()); + bool result = false; + + switch (player.GetOrbitState()) { + case CPlayer::kOS_OrbitObject: + case CPlayer::kOS_OrbitPoint: + case CPlayer::kOS_OrbitCarcass: + case CPlayer::kOS_ForcedOrbitObject: + case CPlayer::kOS_Grapple: { + const CVector3f& orbitPoint = player.GetOrbitPoint(); + if (gravity && player.GetPlayerMovementState() == NPlayer::kMS_ApplyJump) { + result = CSteeringBehaviors::ProjectOrbitalIntersection(gunPos, speed, dt, aimPos, playerVel, + gravVec, orbitPoint, ret); + break; + } + CVector3f vel = playerVel.CanBeNormalized() + ? (player.GetAverageSpeed() * playerVel.AsNormalized()) + : playerVel; + result = CSteeringBehaviors::ProjectOrbitalIntersection(gunPos, speed, dt, aimPos, vel, + orbitPoint, ret); + break; + } + case CPlayer::kOS_NoOrbit: + if (gravity && player.GetPlayerMovementState() == NPlayer::kMS_ApplyJump) { + result = CSteeringBehaviors::ProjectLinearIntersection(gunPos, speed, aimPos, playerVel, + gravVec, ret); + } else { + result = CSteeringBehaviors::ProjectLinearIntersection(gunPos, speed, aimPos, playerVel, ret); + } + break; + } + + if (!result) { + ret = aimPos + playerVel * 1.5f; + } + + return ret; +}