From c357062de8746c2e78d46a4eb1088a2c5fa5e84c Mon Sep 17 00:00:00 2001 From: RadiantDerg <9061202+RadiantDerg@users.noreply.github.com> Date: Sun, 19 Jan 2025 04:22:12 -0600 Subject: [PATCH] Partial ratio text implementation --- UnleashedRecomp/api/SWA.h | 2 + .../api/SWA/Path/Animation/PathAnimation.h | 22 +++++++++ UnleashedRecomp/api/SWA/Path/PathController.h | 13 +++++ UnleashedRecomp/api/SWA/System/StageManager.h | 16 ++++--- UnleashedRecomp/patches/debug_patches.cpp | 47 +++++++++++++++---- 5 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 UnleashedRecomp/api/SWA/Path/Animation/PathAnimation.h create mode 100644 UnleashedRecomp/api/SWA/Path/PathController.h diff --git a/UnleashedRecomp/api/SWA.h b/UnleashedRecomp/api/SWA.h index 85b652bc..78cf2f3b 100644 --- a/UnleashedRecomp/api/SWA.h +++ b/UnleashedRecomp/api/SWA.h @@ -78,6 +78,8 @@ #include "SWA/Inspire/InspireTextureOverlayInfo.h" #include "SWA/Movie/MovieDisplayer.h" #include "SWA/Movie/MovieManager.h" +#include "SWA/Path/PathController.h" +#include "SWA/Path/Animation/PathAnimation.h" #include "SWA/Player/Character/EvilSonic/EvilSonic.h" #include "SWA/Player/Character/EvilSonic/EvilSonicContext.h" #include "SWA/Player/Character/EvilSonic/Hud/EvilHudGuide.h" diff --git a/UnleashedRecomp/api/SWA/Path/Animation/PathAnimation.h b/UnleashedRecomp/api/SWA/Path/Animation/PathAnimation.h new file mode 100644 index 00000000..7e52998e --- /dev/null +++ b/UnleashedRecomp/api/SWA/Path/Animation/PathAnimation.h @@ -0,0 +1,22 @@ +#pragma once + + +namespace SWA::PathAnimation +{ + class Entity + { + public: + xpointer m_pVftable; + SWA_INSERT_PADDING(0x18); + }; + + + class Controller + { + public: + xpointer m_pVftable; + SWA_INSERT_PADDING(0x1C); + be m_DistanceAlongPath; + }; + SWA_ASSERT_OFFSETOF(Controller, m_DistanceAlongPath, 0x20); +} diff --git a/UnleashedRecomp/api/SWA/Path/PathController.h b/UnleashedRecomp/api/SWA/Path/PathController.h new file mode 100644 index 00000000..e56ed2b7 --- /dev/null +++ b/UnleashedRecomp/api/SWA/Path/PathController.h @@ -0,0 +1,13 @@ +#pragma once +#include "Animation/PathAnimation.h" + +namespace SWA +{ + class CPathController + { + public: + be m_Field000; + be m_Field004; + boost::shared_ptr m_spPathAnimationController; + }; +} diff --git a/UnleashedRecomp/api/SWA/System/StageManager.h b/UnleashedRecomp/api/SWA/System/StageManager.h index 48b0eb1a..641841c6 100644 --- a/UnleashedRecomp/api/SWA/System/StageManager.h +++ b/UnleashedRecomp/api/SWA/System/StageManager.h @@ -11,16 +11,20 @@ namespace SWA class CStageManager //: public SWA::CGameObject, public Hedgehog::Base::CSynchronizedObject { public: - SWA_INSERT_PADDING(0xD0); - Hedgehog::Math::CVector m_PlayerPosition; //0xD0 - SWA_INSERT_PADDING(0x40); - be m_StageGuidePathRatioMaybe; // @ 0x11C - be m_StageGuidePathLength; // @ 0x120 + SWA_INSERT_PADDING(0xC4); + boost::shared_ptr m_spStageGuidePathController; //xpointer m_pStageGuidePathController; + SWA_INSERT_PADDING(0x4); + Hedgehog::Math::CVector m_PlayerPosition; + be m_Field0DC; // Sonic's air distance from path?? + SWA_INSERT_PADDING(0x3C); + be m_StageGuidePathRatio; // Not updated in retail + be m_StageGuidePathLength; SWA_INSERT_PADDING(0x9C); }; + SWA_ASSERT_OFFSETOF(CStageManager, m_spStageGuidePathController, 0xC4); SWA_ASSERT_OFFSETOF(CStageManager, m_PlayerPosition, 0xD0); - SWA_ASSERT_OFFSETOF(CStageManager, m_StageGuidePathRatioMaybe, 0x11C); + SWA_ASSERT_OFFSETOF(CStageManager, m_StageGuidePathRatio, 0x11C); SWA_ASSERT_OFFSETOF(CStageManager, m_StageGuidePathLength, 0x120); SWA_ASSERT_SIZEOF(CStageManager, 0x1C0); } diff --git a/UnleashedRecomp/patches/debug_patches.cpp b/UnleashedRecomp/patches/debug_patches.cpp index 5c5e4a41..ba4b13f7 100644 --- a/UnleashedRecomp/patches/debug_patches.cpp +++ b/UnleashedRecomp/patches/debug_patches.cpp @@ -41,24 +41,53 @@ PPC_FUNC(sub_82522040) { auto a1 = static_cast(g_memory.Translate(ctx.r3.u32)); + __imp__sub_82522040(ctx, base); + // Draw player position if (Reddog::DebugDraw::GetIsDrawPosition()) { + // TODO (RadiantDerg): Reimplement SWA::CStageManager ability to draw progress ratio + // NOTE: Currently does not work, is the API mapping horribly misaligned/misunderstood? + if (a1->m_spStageGuidePathController) + { + if (a1->m_spStageGuidePathController->m_spPathAnimationController) + { + auto PAC = a1->m_spStageGuidePathController->m_spPathAnimationController; + //Reddog::DebugDraw::DrawTextLog(fmt::format("m_DistanceAlongPath = {:.2f}", PAC->m_DistanceAlongPath.get()).c_str()); + } + + // Ratio + if (a1->m_StageGuidePathLength.get() > 0.0f) + { + //float distance = 0; // GetDistanceAlongPath(a1->m_StageGuidePathController) + //a1->m_StageGuidePathRatio = distance / a1->m_StageGuidePathLength; + + const Reddog::SDrawText ratioText{ + {Scale(g_aspectRatioOffsetX + 720), Scale(g_aspectRatioOffsetY + 36)}, + fmt::format("{:.1f}m [{:.1f}/100.0]", a1->m_StageGuidePathLength.get(), a1->m_StageGuidePathRatio.get()), + 0, + 3.25f, + 0xFFFFFFFF, + Reddog::eDrawTextFlags_NoShadow + }; + + Reddog::DebugDraw::DrawText2D(ratioText); + } + } + + // Position const Reddog::SDrawText positionText{ - {Scale(g_aspectRatioOffsetX + 750), Scale(g_aspectRatioOffsetY + 120)}, - fmt::format("( {:.2f}, {:.2f}, {:.2f} )", a1->m_PlayerPosition.X.get(), a1->m_PlayerPosition.Y.get(), a1->m_PlayerPosition.Z.get()), - 0, - 1.5f, - 0xFFFFFFFF, - Reddog::eDrawTextFlags_NoShadow + {Scale(g_aspectRatioOffsetX + 750), Scale(g_aspectRatioOffsetY + 120)}, + fmt::format("( {:.2f}, {:.2f}, {:.2f} )", a1->m_PlayerPosition.X.get(), a1->m_PlayerPosition.Y.get(), a1->m_PlayerPosition.Z.get()), + 0, + 2.0f, + 0xFFFFFFFF, + Reddog::eDrawTextFlags_NoShadow }; Reddog::DebugDraw::DrawText2D(positionText); } - - // TODO (RadiantDerg): Reimplement SWA::CStageManager ability to draw progress ratio - __imp__sub_82522040(ctx, base); } // GetIsDebugRenderForGameObject()