From dd0ff42a3d462a08f3cb5b3b84046231f60258b1 Mon Sep 17 00:00:00 2001 From: Josh Sanchez Date: Tue, 11 Feb 2025 09:38:13 -0600 Subject: [PATCH 1/5] zLasso: 100% code match on fizzical functions --- src/SB/Game/zLasso.cpp | 92 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/src/SB/Game/zLasso.cpp b/src/SB/Game/zLasso.cpp index f118774b4..1c38bf43b 100644 --- a/src/SB/Game/zLasso.cpp +++ b/src/SB/Game/zLasso.cpp @@ -4,6 +4,8 @@ #include +static s32 negativeHondaX = 1; + void zLasso_InitTimer(zLasso* lasso, F32 interpTime) { lasso->secsTotal = interpTime; @@ -35,4 +37,92 @@ void zLasso_InitTimer(zLasso* lasso, F32 interpTime) lasso->reindex[2] = 2; lasso->reindex[3] = 3; lasso->reindex[4] = 4; -} \ No newline at end of file +} + +void fizzicalRadius(zLasso* lasso, f32 arg1, xVec3* arg2) +{ + lasso->crRadius = -((2.0f * (0.75f - lasso->crSlack) * arg1) - lasso->crRadius); + if (lasso->crRadius < 0.0f) + { + lasso->crRadius = 0.0f; + } +} + +void fizzicalCenter(zLasso* lasso, f32 arg1, xVec3* arg2) +{ + xVec3AddScaled(&lasso->crCenter, &lasso->lastRefs[lasso->reindex[4]], -0.2f); + xVec3AddScaled(&lasso->crCenter, arg2, 0.2f); +} + +void fizzicalNormal(zLasso* lasso, f32 arg1, xVec3* arg2) +{ + xVec3 sp8; + f32 temp_f31; + + xVec3Sub(&sp8, &lasso->lastRefs[lasso->reindex[0]], &lasso->lastRefs[lasso->reindex[1]]); + temp_f31 = xVec3Dot(&lasso->crNormal, &sp8); + xVec3AddScaled(&lasso->crNormal, &sp8, 1.1f * (-temp_f31 / xVec3Length(&sp8))); + xVec3Normalize(&lasso->crNormal, &lasso->crNormal); +} + +void fizzicalHonda(zLasso* lasso, f32 arg1, xVec3* arg2) +{ + xVec3* temp_r3; + + xVec3SMul(&lasso->honda, arg2, -1.0f); + xVec3AddScaled(&lasso->honda, &lasso->lastRefs[lasso->reindex[0]], 0.571429f); + xVec3AddScaled(&lasso->honda, &lasso->lastRefs[lasso->reindex[1]], 0.285714f); + xVec3AddScaled(&lasso->honda, &lasso->lastRefs[lasso->reindex[2]], 0.142857f); + xVec3AddScaled(&lasso->honda, &lasso->crNormal, -xVec3Dot(&lasso->crNormal, &lasso->honda)); + temp_r3 = &lasso->honda; + xVec3Normalize(temp_r3, temp_r3); + xVec3SMulBy(&lasso->honda, lasso->crRadius); + if (((s32)negativeHondaX != 0) && (lasso->honda.x > 0.0f)) + { + xSndPlay3D(xStrHash(&"rope\0sound_rope_windup"[5]), 0.77f, 0.0f, 0U, 0x10000U, + &lasso->anchor, 100.0f, (sound_category)0, 0.0f); + negativeHondaX = 0; + } + if (lasso->honda.x < 0.0f) + { + negativeHondaX = 1; + } + xVec3AddTo(&lasso->honda, &lasso->crCenter); +} + +void nonfizzicalHonda(zLasso* lasso, f32 arg1, xVec3* arg2) +{ + f32 temp_f1; + + xVec3Sub(&lasso->honda, arg2, &lasso->crCenter); + xVec3AddScaled(&lasso->honda, &lasso->crNormal, -xVec3Dot(&lasso->honda, &lasso->crNormal)); + temp_f1 = xVec3Length2(&lasso->honda); + if (temp_f1 < 0.00001f) + { + lasso->honda.x = lasso->crNormal.y; + lasso->honda.y = -lasso->crNormal.x; + lasso->honda.z = 0.0f; + xVec3SMulBy(&lasso->honda, lasso->crRadius / xsqrt(xVec3Length2(&lasso->honda))); + xVec3AddTo(&lasso->honda, &lasso->crCenter); + return; + } + xVec3SMulBy(&lasso->honda, lasso->crRadius / xsqrt(temp_f1)); + xVec3AddTo(&lasso->honda, &lasso->crCenter); +} + +void fizzicalSlack(zLasso* lasso, f32 arg1, xVec3* arg2) +{ + f32 temp_f1; + + lasso->crSlack += (2.0f * (lasso->lastDist - lasso->currDist)) - (0.6f * arg1); + temp_f1 = lasso->crSlack; + if (temp_f1 < 0.0f) + { + lasso->crSlack = 0.0f; + return; + } + if (temp_f1 > 1.0f) + { + lasso->crSlack = 1.0f; + } +} From f636674811d9b1210ba59316268ed654209894b5 Mon Sep 17 00:00:00 2001 From: Josh Sanchez Date: Thu, 13 Feb 2025 21:49:26 -0600 Subject: [PATCH 2/5] Add missing xSndPlay3D override definition --- src/SB/Core/x/xSnd.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/SB/Core/x/xSnd.h b/src/SB/Core/x/xSnd.h index f49476621..58abe1c63 100644 --- a/src/SB/Core/x/xSnd.h +++ b/src/SB/Core/x/xSnd.h @@ -128,6 +128,8 @@ U32 xSndPlay(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, U32 parentID, sound_category category, F32 delay); U32 xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, xEnt* parent, F32 innerRadius, F32 outerRadius, sound_category category, F32 delay); +U32 xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, const xVec3* pos, F32 radius, + sound_category category, F32 delay); U32 xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, const xVec3* pos, F32 innerRadius, F32 outerRadius, sound_category category, F32 delay); U32 xSndPlayInternal(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, U32 parentID, From c2766bbb95aa8c7ccabfe2830f1b248939b7f012 Mon Sep 17 00:00:00 2001 From: Josh Sanchez Date: Thu, 13 Feb 2025 21:51:25 -0600 Subject: [PATCH 3/5] zLasso: 100% match on scenePrepare, ResetTimer functions --- src/SB/Game/zLasso.cpp | 31 +++++++++++++++++++++++++++++++ src/SB/Game/zLasso.h | 17 +++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/SB/Game/zLasso.cpp b/src/SB/Game/zLasso.cpp index 1c38bf43b..91c3ad39c 100644 --- a/src/SB/Game/zLasso.cpp +++ b/src/SB/Game/zLasso.cpp @@ -4,6 +4,13 @@ #include +static u32 sLassoRaster; +static u32 sNumGuideLists; +static zLassoGuide* sCurrentGuide; +static void* lnverts; + +static zLassoGuideList sGuideList[64]; + static s32 negativeHondaX = 1; void zLasso_InitTimer(zLasso* lasso, F32 interpTime) @@ -39,6 +46,24 @@ void zLasso_InitTimer(zLasso* lasso, F32 interpTime) lasso->reindex[4] = 4; } +void zLasso_ResetTimer(zLasso* lasso, F32 interpTime) +{ + f32 temp_f0; + f32 temp_f0_2; + + lasso->secsTotal = interpTime; + lasso->secsLeft = interpTime; + temp_f0 = lasso->crRadius; + lasso->stRadius = temp_f0; + lasso->tgRadius = temp_f0; + temp_f0_2 = lasso->crSlack; + lasso->stSlack = temp_f0_2; + lasso->tgSlack = temp_f0_2; + xVec3Copy(&lasso->stNormal, &lasso->crNormal); + xVec3Copy(&lasso->tgNormal, &lasso->crNormal); + xVec3Add(&lasso->stCenter, &lasso->crCenter, &lasso->anchor); +} + void fizzicalRadius(zLasso* lasso, f32 arg1, xVec3* arg2) { lasso->crRadius = -((2.0f * (0.75f - lasso->crSlack) * arg1) - lasso->crRadius); @@ -126,3 +151,9 @@ void fizzicalSlack(zLasso* lasso, f32 arg1, xVec3* arg2) lasso->crSlack = 1.0f; } } + +void zLasso_scenePrepare() +{ + sNumGuideLists = 0; + sCurrentGuide = NULL; +} diff --git a/src/SB/Game/zLasso.h b/src/SB/Game/zLasso.h index 78647a84b..5c8d86538 100644 --- a/src/SB/Game/zLasso.h +++ b/src/SB/Game/zLasso.h @@ -3,6 +3,8 @@ #include "xMath3.h" #include "xModel.h" +#include "xSnd.h" +#include "xString.h" struct zLasso { @@ -33,9 +35,24 @@ struct zLasso xModelInstance* model; }; +struct zLassoGuide +{ + xModelInstance* poly; + xAnimState* lassoAnim; + S32 vertMap[16]; +}; + +struct zLassoGuideList // Size: 0xE0 +{ + xEnt* target; + U32 numGuides; + zLassoGuide guide[3]; +}; + void zLasso_scenePrepare(); void zLasso_InitTimer(zLasso* lasso, F32 interpTime); void zLasso_ResetTimer(zLasso* lasso, F32 interpTime); +void zLasso_AddGuide(xEnt* ent, xAnimState* lassoAnim, xModelInstance modelInst); void zLasso_SetGuide(xEnt* ent, xAnimState* lassoAnim); void zLasso_InterpToGuide(zLasso* lasso); From 47c4d39a36673065357447f8cd84705ae5dae0f7 Mon Sep 17 00:00:00 2001 From: Josh Sanchez Date: Sat, 15 Feb 2025 10:33:07 -0600 Subject: [PATCH 4/5] Add and implement weak xSndPlay3D function in zAssetTypes.h --- src/SB/Core/x/xSnd.h | 2 -- src/SB/Game/zAssetTypes.cpp | 7 +++++++ src/SB/Game/zAssetTypes.h | 4 ++++ src/SB/Game/zLasso.h | 14 +++++++------- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/SB/Core/x/xSnd.h b/src/SB/Core/x/xSnd.h index 58abe1c63..f49476621 100644 --- a/src/SB/Core/x/xSnd.h +++ b/src/SB/Core/x/xSnd.h @@ -128,8 +128,6 @@ U32 xSndPlay(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, U32 parentID, sound_category category, F32 delay); U32 xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, xEnt* parent, F32 innerRadius, F32 outerRadius, sound_category category, F32 delay); -U32 xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, const xVec3* pos, F32 radius, - sound_category category, F32 delay); U32 xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, const xVec3* pos, F32 innerRadius, F32 outerRadius, sound_category category, F32 delay); U32 xSndPlayInternal(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, U32 parentID, diff --git a/src/SB/Game/zAssetTypes.cpp b/src/SB/Game/zAssetTypes.cpp index 44186f3ce..0841ae140 100644 --- a/src/SB/Game/zAssetTypes.cpp +++ b/src/SB/Game/zAssetTypes.cpp @@ -73,3 +73,10 @@ U8 dummyEffectCB(U32, xAnimActiveEffect*, xAnimSingle*, void*) { return 0; } + + +U32 xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, + xEnt* ent, F32 radius, sound_category category, F32 delay) +{ + return xSndPlay3D(id, vol, pitch, priority, flags, ent, radius / 4.0f, radius, category, delay); +} diff --git a/src/SB/Game/zAssetTypes.h b/src/SB/Game/zAssetTypes.h index 091718d3c..022e676db 100644 --- a/src/SB/Game/zAssetTypes.h +++ b/src/SB/Game/zAssetTypes.h @@ -4,6 +4,7 @@ #include #include #include +#include "xSnd.h" #include "xJSP.h" @@ -16,4 +17,7 @@ struct RwMemory void FootstepHackSceneEnter(); void jsp_shadow_hack(xJSPHeader* param_1); +U32 xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, xEnt* pos, F32 radius, + sound_category category, F32 delay); + #endif diff --git a/src/SB/Game/zLasso.h b/src/SB/Game/zLasso.h index 5c8d86538..f307d4311 100644 --- a/src/SB/Game/zLasso.h +++ b/src/SB/Game/zLasso.h @@ -3,8 +3,8 @@ #include "xMath3.h" #include "xModel.h" -#include "xSnd.h" #include "xString.h" +#include "zEnt.h" struct zLasso { @@ -12,14 +12,14 @@ struct zLasso F32 secsTotal; F32 secsLeft; F32 stRadius; - F32 tgRadius; + F32 tgRadius; // 0x10 F32 crRadius; - xVec3 stCenter; - xVec3 tgCenter; - xVec3 crCenter; - xVec3 stNormal; + xVec3 stCenter; // 0x18 + xVec3 tgCenter; // 0x24 + xVec3 crCenter; // 0x30 + xVec3 stNormal; // 0x3C xVec3 tgNormal; - xVec3 crNormal; + xVec3 crNormal; // 0x48 xVec3 honda; F32 stSlack; F32 stSlackDist; From ab18ea9718116821a81cf10a093f834bb2916ed3 Mon Sep 17 00:00:00 2001 From: Josh Sanchez Date: Sat, 15 Feb 2025 10:34:30 -0600 Subject: [PATCH 5/5] Fix weird assignment in xSndPlay3D weak func in zEnt --- src/SB/Game/zEnt.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/SB/Game/zEnt.cpp b/src/SB/Game/zEnt.cpp index f97a79e98..c73543b60 100644 --- a/src/SB/Game/zEnt.cpp +++ b/src/SB/Game/zEnt.cpp @@ -925,9 +925,7 @@ xMat4x3* xEntGetFrame(const xEnt* ent) void xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, const xVec3* pos, F32 radius, sound_category category, F32 delay) { - // This is UB to assign radius in the function call like this, but the assembly matches a *= - // so maybe HI made a mistake here. - xSndPlay3D(id, vol, pitch, priority, flags, pos, radius *= 0.25f, radius, category, delay); + xSndPlay3D(id, vol, pitch, priority, flags, pos, radius / 4.0f, radius, category, delay); } S32 xNPCBasic::SelfType() const