From bdd03151f421bf5402d5a5186e1fe1df45ed3614 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 18 Oct 2023 00:00:23 -0400 Subject: [PATCH] Link CScriptVisorGoo Former-commit-id: d9cca4a39ffa6c89af5687310229bcd1cdf60d74 --- config/GM8E01_00/symbols.txt | 20 ++++----- configure.py | 2 +- include/Kyoto/Basics/CCast.hpp | 1 + .../ScriptObjects/CScriptVisorGoo.hpp | 42 ++++++++++++------- .../ScriptObjects/CScriptVisorGoo.cpp | 42 ++++++++++--------- 5 files changed, 61 insertions(+), 46 deletions(-) diff --git a/config/GM8E01_00/symbols.txt b/config/GM8E01_00/symbols.txt index 6de06e6d..15be7b30 100644 --- a/config/GM8E01_00/symbols.txt +++ b/config/GM8E01_00/symbols.txt @@ -16984,7 +16984,7 @@ lbl_803CE488 = .rodata:0x803CE488; // type:object size:0x14 data:string lbl_803CE49C = .rodata:0x803CE49C; // type:object size:0x9 data:string lbl_803CE4A5 = .rodata:0x803CE4A5; // type:object size:0xD data:string lbl_803CE4B2 = .rodata:0x803CE4B2; // type:object size:0x76 -lbl_803CE528 = .rodata:0x803CE528; // type:object size:0x8 +@stringBase0 = .rodata:0x803CE528; // type:object size:0x7 scope:local data:string_table @stringBase0 = .rodata:0x803CE530; // type:object size:0x13 scope:local data:string_table @stringBase0 = .rodata:0x803CE548; // type:object size:0x1C scope:local data:string_table lbl_803CE568 = .rodata:0x803CE568; // type:object size:0x30 @@ -17238,7 +17238,7 @@ lbl_803D08C4 = .rodata:0x803D08C4; // type:object size:0x34 lbl_803D08F8 = .rodata:0x803D08F8; // type:object size:0xC data:string lbl_803D0904 = .rodata:0x803D0904; // type:object size:0xE data:string lbl_803D0912 = .rodata:0x803D0912; // type:object size:0x2E -lbl_803D0940 = .rodata:0x803D0940; // type:object size:0x8 +@stringBase0 = .rodata:0x803D0940; // type:object size:0x7 scope:local data:string_table lbl_803D0948 = .rodata:0x803D0948; // type:object size:0x8C lbl_803D09D4 = .rodata:0x803D09D4; // type:object size:0x1C lbl_803D09F0 = .rodata:0x803D09F0; // type:object size:0x40 @@ -17811,7 +17811,7 @@ lbl_803D7398 = .rodata:0x803D7398; // type:object size:0x8 indMtx$267 = .rodata:0x803D73A0; // type:object size:0x18 scope:local vtxDescList$288 = .rodata:0x803D73B8; // type:object size:0x10 scope:local lbl_803D73C8 = .rodata:0x803D73C8; // type:object size:0x20 -lbl_803D73E8 = .rodata:0x803D73E8; // type:object size:0x8 +@stringBase0 = .rodata:0x803D73E8; // type:object size:0x7 scope:local data:string_table lbl_803D73F0 = .rodata:0x803D73F0; // type:object size:0x10 data:4byte @stringBase0 = .rodata:0x803D7400; // type:object size:0x8 scope:local data:string_table gkCRC32Table = .rodata:0x803D7408; // type:object size:0x400 scope:local @@ -20436,7 +20436,7 @@ lbl_805A7A98 = .sdata:0x805A7A98; // type:object size:0x8 data:float lbl_805A7AA0 = .sdata:0x805A7AA0; // type:object size:0x4 data:4byte lbl_805A7AA4 = .sdata:0x805A7AA4; // type:object size:0x4 data:float @191 = .sdata:0x805A7AA8; // type:object size:0x4 scope:local data:4byte -lbl_805A7AB0 = .sdata:0x805A7AB0; // type:object size:0x8 data:4byte +lbl_805A7AB0 = .sdata:0x805A7AB0; // type:object size:0x4 data:4byte lbl_805A7AB8 = .sdata:0x805A7AB8; // type:object size:0x4 lbl_805A7ABC = .sdata:0x805A7ABC; // type:object size:0x4 lbl_805A7AC0 = .sdata:0x805A7AC0; // type:object size:0x4 data:float @@ -20606,8 +20606,8 @@ lbl_805A7D6C = .sdata:0x805A7D6C; // type:object size:0x1 data:byte lbl_805A7D6D = .sdata:0x805A7D6D; // type:object size:0x1 data:byte lbl_805A7D6E = .sdata:0x805A7D6E; // type:object size:0x2 lbl_805A7D70 = .sdata:0x805A7D70; // type:object size:0x8 -lbl_805A7D78 = .sdata:0x805A7D78; // type:object size:0x8 data:4byte -lbl_805A7D80 = .sdata:0x805A7D80; // type:object size:0x8 data:float +lbl_805A7D78 = .sdata:0x805A7D78; // type:object size:0x4 data:4byte +lbl_805A7D80 = .sdata:0x805A7D80; // type:object size:0x4 data:float lbl_805A7D88 = .sdata:0x805A7D88; // type:object size:0x4 lbl_805A7D8C = .sdata:0x805A7D8C; // type:object size:0x4 lbl_805A7D90 = .sdata:0x805A7D90; // type:object size:0x8 data:4byte @@ -24303,8 +24303,8 @@ lbl_805ABE70 = .sdata2:0x805ABE70; // type:object size:0x4 data:float lbl_805ABE74 = .sdata2:0x805ABE74; // type:object size:0x4 data:float lbl_805ABE78 = .sdata2:0x805ABE78; // type:object size:0x4 data:float lbl_805ABE80 = .sdata2:0x805ABE80; // type:object size:0x8 align:8 data:double -lbl_805ABE88 = .sdata2:0x805ABE88; // type:object size:0x8 data:float -lbl_805ABE90 = .sdata2:0x805ABE90; // type:object size:0x8 data:float +lbl_805ABE88 = .sdata2:0x805ABE88; // type:object size:0x4 data:float +lbl_805ABE90 = .sdata2:0x805ABE90; // type:object size:0x4 data:float lbl_805ABE98 = .sdata2:0x805ABE98; // type:object size:0x4 data:float lbl_805ABE9C = .sdata2:0x805ABE9C; // type:object size:0x4 data:float lbl_805ABEA0 = .sdata2:0x805ABEA0; // type:object size:0x4 data:float @@ -24482,7 +24482,7 @@ lbl_805AC19C = .sdata2:0x805AC19C; // type:object size:0x4 data:float lbl_805AC1A0 = .sdata2:0x805AC1A0; // type:object size:0x4 data:float lbl_805AC1A4 = .sdata2:0x805AC1A4; // type:object size:0x4 data:float lbl_805AC1A8 = .sdata2:0x805AC1A8; // type:object size:0x8 data:float -lbl_805AC1B0 = .sdata2:0x805AC1B0; // type:object size:0x8 data:float +lbl_805AC1B0 = .sdata2:0x805AC1B0; // type:object size:0x4 data:float lbl_805AC1B8 = .sdata2:0x805AC1B8; // type:object size:0x4 data:float lbl_805AC1BC = .sdata2:0x805AC1BC; // type:object size:0x4 data:float lbl_805AC1C0 = .sdata2:0x805AC1C0; // type:object size:0x4 data:float @@ -24906,7 +24906,7 @@ lbl_805AC950 = .sdata2:0x805AC950; // type:object size:0x8 align:8 data:double lbl_805AC958 = .sdata2:0x805AC958; // type:object size:0x8 align:8 data:double lbl_805AC960 = .sdata2:0x805AC960; // type:object size:0x4 data:float lbl_805AC964 = .sdata2:0x805AC964; // type:object size:0x4 data:float -lbl_805AC968 = .sdata2:0x805AC968; // type:object size:0x8 data:float +lbl_805AC968 = .sdata2:0x805AC968; // type:object size:0x4 data:float lbl_805AC970 = .sdata2:0x805AC970; // type:object size:0x4 data:float lbl_805AC974 = .sdata2:0x805AC974; // type:object size:0x4 data:float lbl_805AC978 = .sdata2:0x805AC978; // type:object size:0x4 data:float diff --git a/configure.py b/configure.py index bb4c286c..28a18137 100755 --- a/configure.py +++ b/configure.py @@ -552,7 +552,7 @@ config.libs = [ Object(NonMatching, "MetroidPrime/Player/CGameState.cpp"), Object(Matching, "MetroidPrime/ScriptObjects/CScriptVisorFlare.cpp"), Object(Matching, "MetroidPrime/ScriptObjects/CScriptWorldTeleporter.cpp"), - Object(NonMatching, "MetroidPrime/ScriptObjects/CScriptVisorGoo.cpp"), + Object(Matching, "MetroidPrime/ScriptObjects/CScriptVisorGoo.cpp"), Object(NonMatching, "MetroidPrime/Enemies/CJellyZap.cpp"), Object(Matching, "MetroidPrime/ScriptObjects/CScriptControllerAction.cpp"), Object(NonMatching, "MetroidPrime/Weapons/GunController/CGunMotion.cpp"), diff --git a/include/Kyoto/Basics/CCast.hpp b/include/Kyoto/Basics/CCast.hpp index 4887035a..efaa87a6 100644 --- a/include/Kyoto/Basics/CCast.hpp +++ b/include/Kyoto/Basics/CCast.hpp @@ -61,6 +61,7 @@ inline float LtoF(int in) { return static_cast< float >(in); } #endif inline int ToInt32(float in) { return static_cast< int >(in); } +inline unsigned short ToUint16(unsigned short in) { return static_cast< short >(in); } inline char ToChar(int c) { return ToUint8(c) ; } } // namespace CCast diff --git a/include/MetroidPrime/ScriptObjects/CScriptVisorGoo.hpp b/include/MetroidPrime/ScriptObjects/CScriptVisorGoo.hpp index 3dc36354..5315c93f 100644 --- a/include/MetroidPrime/ScriptObjects/CScriptVisorGoo.hpp +++ b/include/MetroidPrime/ScriptObjects/CScriptVisorGoo.hpp @@ -9,9 +9,9 @@ class CElectricDescription; class CScriptVisorGoo : public CActor { public: CScriptVisorGoo(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, - const CTransform4f& xf, CAssetId particle, CAssetId electric, float minDist, - float maxDist, float nearProb, float farProb, const CColor& color, int sfx, - bool forceShow, bool active); + const CTransform4f& xf, CAssetId particle, CAssetId electric, float minRange, + float maxRange, float chanceMinRange, float chanceMaxRange, const CColor& color, + int sfx, bool noViewCheck, bool active); ~CScriptVisorGoo(); void Accept(IVisitor& visitor) override; @@ -22,18 +22,28 @@ public: rstl::optional_object< CAABox > GetTouchBounds() const override; void Touch(CActor&, CStateManager&) override; -private: - TToken< CGenDescription > xe8_particleDesc; - TToken< CElectricDescription > xf0_electricDesc; - ushort xf8_sfx; - CAssetId xfc_particleId; - CAssetId x100_electricId; - float x104_minDist; - float x108_maxDist; - float x10c_nearProb; - float x110_farProb; - CColor x114_color; - bool x118_24_angleTest : 1; -}; + float GetMinRange() const { return x104_minRange; } + float GetMaxRange() const { return x108_maxRange; } + bool GetViewCheck() const { return x118_24_viewCheck; } + float GetChanceMinRange() const { return x10c_chanceMinRange; } + float GetChanceMaxRange() const { return x110_chanceMaxRange; } + const CColor& GetColor() const { return x114_color; } + + const TToken< CGenDescription >& GetParticleDesc() const { return xe8_particleDesc; } + const TToken< CElectricDescription >& GetElectricDesc() const { return xf0_electricDesc; } + + private: + TToken< CGenDescription > xe8_particleDesc; + TToken< CElectricDescription > xf0_electricDesc; + ushort xf8_sfx; + CAssetId xfc_particleId; + CAssetId x100_electricId; + float x104_minRange; + float x108_maxRange; + float x10c_chanceMinRange; + float x110_chanceMaxRange; + CColor x114_color; + bool x118_24_viewCheck : 1; + }; #endif // _CSCRIPTVISORGOO diff --git a/src/MetroidPrime/ScriptObjects/CScriptVisorGoo.cpp b/src/MetroidPrime/ScriptObjects/CScriptVisorGoo.cpp index e0d2d270..7edaed3e 100644 --- a/src/MetroidPrime/ScriptObjects/CScriptVisorGoo.cpp +++ b/src/MetroidPrime/ScriptObjects/CScriptVisorGoo.cpp @@ -12,8 +12,9 @@ CScriptVisorGoo::CScriptVisorGoo(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, const CTransform4f& xf, CAssetId particle, CAssetId electric, - float minDist, float maxDist, float nearProb, float farProb, - const CColor& color, int sfx, bool forceShow, bool active) + float minRange, float maxRange, float chanceMinRange, + float chanceMaxRange, const CColor& color, int sfx, + bool noViewCheck, bool active) : CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(), CActorParameters::None(), kInvalidUniqueId) , xe8_particleDesc(nullptr) @@ -21,12 +22,12 @@ CScriptVisorGoo::CScriptVisorGoo(TUniqueId uid, const rstl::string& name, const , xf8_sfx(CSfxManager::TranslateSFXID(sfx)) , xfc_particleId(particle) , x100_electricId(electric) -, x104_minDist(minDist) -, x108_maxDist(rstl::max_val(maxDist, minDist + 0.01f)) -, x10c_nearProb(nearProb) -, x110_farProb(farProb) +, x104_minRange(minRange) +, x108_maxRange(rstl::max_val(maxRange, minRange + 0.01f)) +, x10c_chanceMinRange(chanceMinRange) +, x110_chanceMaxRange(chanceMaxRange) , x114_color(color) { - x118_24_angleTest = !forceShow; + x118_24_viewCheck = !noViewCheck; if (particle != kInvalidAssetId) { xe8_particleDesc = gpSimplePool->GetObj(SObjectTag('PART', particle)); } @@ -40,10 +41,12 @@ CScriptVisorGoo::~CScriptVisorGoo() {} void CScriptVisorGoo::Think(float, CStateManager& mgr) { if (GetActive()) { bool loaded = false; + // MPR has IsElectricLoaded()/IsElectricValid(), + // but no IsParticleLoaded()/IsParticleValid()? if (xfc_particleId != kInvalidAssetId) { - if (xe8_particleDesc.IsLoaded()) { + if (GetParticleDesc().IsLoaded()) { if (x100_electricId != kInvalidAssetId) { - if (xf0_electricDesc.IsLoaded()) { + if (GetElectricDesc().IsLoaded()) { loaded = true; } } else { @@ -51,7 +54,7 @@ void CScriptVisorGoo::Think(float, CStateManager& mgr) { } } } else { - if (xf0_electricDesc.IsLoaded()) { + if (GetElectricDesc().IsLoaded()) { loaded = true; } } @@ -61,14 +64,14 @@ void CScriptVisorGoo::Think(float, CStateManager& mgr) { if (mgr.GetPlayer()->GetCameraState() == CPlayer::kCS_FirstPerson) { const CVector3f eyeToGoo = GetTranslation() - mgr.GetPlayer()->GetEyePosition(); const float eyeToGooDist = eyeToGoo.Magnitude(); - if (eyeToGooDist >= x104_minDist && eyeToGooDist <= x108_maxDist) { - if (x118_24_angleTest) { + if (eyeToGooDist >= GetMinRange() && eyeToGooDist <= GetMaxRange()) { + if (GetViewCheck()) { CVector3f colNorm = mgr.GetCameraManager() ->GetCurrentCameraTransform(mgr) .GetColumn(kDY) .AsNormalized(); float angleThresh = 45.f; - float angle = CMath::Rad2Deg(CMath::FastArcCosR( + float angle = CMath::Rad2Rev(CMath::FastArcCosR( CVector3f::Dot(eyeToGoo.AsNormalized(), colNorm))) * 360.f; if (eyeToGooDist < 4.f) { @@ -82,21 +85,22 @@ void CScriptVisorGoo::Think(float, CStateManager& mgr) { showGoo = true; } if (showGoo) { - const float t = (x108_maxDist - eyeToGooDist) / (x108_maxDist - x104_minDist); - float prob = t * x10c_nearProb + (1.0f - t) * x110_farProb; + const float t = (GetMaxRange() - eyeToGooDist) / (GetMaxRange() - GetMinRange()); + float prob = t * GetChanceMinRange() + (1.0f - t) * GetChanceMaxRange(); if (mgr.Random()->Float() * 100.f <= prob) { mgr.AddObject(rs_new CHUDBillboardEffect( xfc_particleId != kInvalidAssetId - ? rstl::optional_object< TToken< CGenDescription > >(xe8_particleDesc) + ? rstl::optional_object< TToken< CGenDescription > >(GetParticleDesc()) : rstl::optional_object_null(), x100_electricId != kInvalidAssetId - ? rstl::optional_object< TToken< CElectricDescription > >(xf0_electricDesc) + ? rstl::optional_object< TToken< CElectricDescription > >(GetElectricDesc()) : rstl::optional_object_null(), mgr.AllocateUniqueId(), true, rstl::string_l("VisorGoo"), CHUDBillboardEffect::GetNearClipDistance(mgr), - CHUDBillboardEffect::GetScaleForPOV(mgr), x114_color, CVector3f(1.f, 1.f, 1.f), + CHUDBillboardEffect::GetScaleForPOV(mgr), GetColor(), CVector3f(1.f, 1.f, 1.f), CVector3f(0.f, 0.f, 0.f))); - CSfxManager::SfxStart(xf8_sfx, 0x7f, 0x40, false, CSfxManager::kMedPriority); + CSfxManager::SfxStart(CCast::ToUint16(xf8_sfx), 0x7f, 0x40, false, + CSfxManager::kMedPriority); } } }