From 00e148b182edc932e0e90640beaca1c4f0ae44bf Mon Sep 17 00:00:00 2001 From: RadiantDerg <9061202+RadiantDerg@users.noreply.github.com> Date: Tue, 14 Jan 2025 20:10:15 -0600 Subject: [PATCH] Draw position, Move patches to debug_patches.cpp --- UnleashedRecomp/CMakeLists.txt | 3 +- UnleashedRecomp/api/SWA.h | 1 + UnleashedRecomp/api/SWA/System/StageManager.h | 26 +++++++ UnleashedRecomp/patches/debug_patches.cpp | 67 +++++++++++++++++++ UnleashedRecomp/patches/misc_patches.cpp | 3 +- UnleashedRecomp/ui/reddog/debug_draw.cpp | 47 ++++++++----- UnleashedRecomp/ui/reddog/debug_draw.h | 20 +++--- .../ui/reddog/windows/view_window.cpp | 10 +-- 8 files changed, 142 insertions(+), 35 deletions(-) create mode 100644 UnleashedRecomp/api/SWA/System/StageManager.h create mode 100644 UnleashedRecomp/patches/debug_patches.cpp diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 9426920..5ead30c 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -153,7 +153,8 @@ set(SWA_PATCHES_CXX_SOURCES "patches/ui/CTitleStateMenu_patches.cpp" "patches/ui/frontend_listener.cpp" "patches/audio_patches.cpp" - "patches/camera_patches.cpp" + "patches/camera_patches.cpp" + "patches/debug_patches.cpp" "patches/fps_patches.cpp" "patches/inspire_patches.cpp" "patches/misc_patches.cpp" diff --git a/UnleashedRecomp/api/SWA.h b/UnleashedRecomp/api/SWA.h index dc28c27..85b652b 100644 --- a/UnleashedRecomp/api/SWA.h +++ b/UnleashedRecomp/api/SWA.h @@ -103,6 +103,7 @@ #include "SWA/System/GammaController.h" #include "SWA/System/InputState.h" #include "SWA/System/PadState.h" +#include "SWA/System/StageManager.h" #include "SWA/System/World.h" #include "boost/smart_ptr/make_shared_object.h" #include "boost/smart_ptr/shared_ptr.h" diff --git a/UnleashedRecomp/api/SWA/System/StageManager.h b/UnleashedRecomp/api/SWA/System/StageManager.h new file mode 100644 index 0000000..48b0eb1 --- /dev/null +++ b/UnleashedRecomp/api/SWA/System/StageManager.h @@ -0,0 +1,26 @@ +#pragma once + +#include "SWA.inl" +#include "Hedgehog/Base/Thread/hhSynchronizedObject.h" +#include "Hedgehog/Universe/Engine/hhMessageActor.h" +#include "SWA/System/GameObject.h" + + +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(0x9C); + }; + + SWA_ASSERT_OFFSETOF(CStageManager, m_PlayerPosition, 0xD0); + SWA_ASSERT_OFFSETOF(CStageManager, m_StageGuidePathRatioMaybe, 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 new file mode 100644 index 0000000..6ef48d6 --- /dev/null +++ b/UnleashedRecomp/patches/debug_patches.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include + + +// boost::~::SWA::CDebugDraw::CMember::SDrawLine +PPC_FUNC_IMPL(__imp__sub_822C9398); +PPC_FUNC(sub_822C9398) +{ + auto a2 = (Hedgehog::Math::CVector*)g_memory.Translate(ctx.r4.u32); + auto a3 = (Hedgehog::Math::CVector*)g_memory.Translate(ctx.r5.u32); + auto a4 = (be*)g_memory.Translate(ctx.r6.u32); + + Reddog::Vector3 start(a2->X, a2->Y, a2->Z); + Reddog::Vector3 end(a3->X, a3->Y, a3->Z); + + const Reddog::SDrawLine line{ + start, end, a4->value + }; + + Reddog::DebugDraw::DrawLine(line); + + __imp__sub_822C9398(ctx, base); +} + + +// SWA::CStageManager::UpdateParallel +//PPC_FUNC_IMPL(__imp__sub_82521C68); +//PPC_FUNC(sub_82521C68) +//{ +// __imp__sub_82521C68(ctx, base); +//} + + +// SWA::CStageManager::UpdateSerial +PPC_FUNC_IMPL(__imp__sub_82522040); +PPC_FUNC(sub_82522040) +{ + auto a1 = static_cast(g_memory.Translate(ctx.r3.u32)); + + // Draw player position + if (Reddog::DebugDraw::GetIsDrawPosition()) + { + const Reddog::SDrawText positionText{ + {Scale(750), Scale(120)}, + fmt::format("( {:.2f}, {:.2f}, {:.2f} )", a1->m_PlayerPosition.X.get(), a1->m_PlayerPosition.Y.get(), a1->m_PlayerPosition.Z.get()), + 0, + Scale(1.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() +PPC_FUNC(sub_82512BF8) +{ + ctx.r3.u8 = 1; // Always return true +} diff --git a/UnleashedRecomp/patches/misc_patches.cpp b/UnleashedRecomp/patches/misc_patches.cpp index b0e64db..a6af264 100644 --- a/UnleashedRecomp/patches/misc_patches.cpp +++ b/UnleashedRecomp/patches/misc_patches.cpp @@ -2,7 +2,6 @@ #include #include #include -#include void AchievementManagerUnlockMidAsmHook(PPCRegister& id) { @@ -125,4 +124,4 @@ PPC_FUNC(sub_822C9398) Reddog::DebugDraw::DrawLine(line); __imp__sub_822C9398(ctx, base); -} +} \ No newline at end of file diff --git a/UnleashedRecomp/ui/reddog/debug_draw.cpp b/UnleashedRecomp/ui/reddog/debug_draw.cpp index e47e7c4..8b93900 100644 --- a/UnleashedRecomp/ui/reddog/debug_draw.cpp +++ b/UnleashedRecomp/ui/reddog/debug_draw.cpp @@ -23,7 +23,7 @@ namespace Reddog return result; } - static ImVec2 GetNDCCoordinate(const Vector3& in_rVec) + static ImVec2 GetNDCCoordinate(const Vector3& in_rPosition) { auto& res = ImGui::GetIO().DisplaySize; @@ -90,9 +90,9 @@ namespace Reddog if (freeText->Position >= ImVec2(0, 0) && freeText->Position <= canvasSize) { if ((freeText->Flags & eDrawTextFlags_NoShadow) == eDrawTextFlags_NoShadow) - drawList->AddText(font, fontSize * freeText->Scale, freeText->Position, freeText->Colour, freeText->Text); + drawList->AddText(font, fontSize * freeText->Scale, freeText->Position, freeText->Colour, freeText->Text.c_str()); else - DrawTextWithShadow(drawList, font, fontSize * freeText->Scale, freeText->Position, freeText->Colour, freeText->Text, 1.0f, 1.0f, IM_COL32(0, 0, 0, 128)); + DrawTextWithShadow(drawList, font, fontSize * freeText->Scale, freeText->Position, freeText->Colour, freeText->Text.c_str(), 1.0f, 1.0f, IM_COL32(0, 0, 0, 128)); } // Decrement timer @@ -134,7 +134,7 @@ namespace Reddog if (useColor) ImGui::PushStyleColor(ImGuiCol_Text, logText->Colour); - ImGui::TextUnformatted(logText->Text); + ImGui::TextUnformatted(logText->Text.c_str()); if (useColor) ImGui::PopStyleColor(); @@ -160,35 +160,35 @@ namespace Reddog void DebugDraw::DrawLine(const SDrawLine& in_rLine) { - if (!ms_IsRendering && ms_IsDrawLine) + if (!ms_IsRendering && GetIsDrawDebug()) ms_LineList.push_back(in_rLine); } void DebugDraw::DrawText2D(const SDrawText& in_rText) { - if (!ms_IsRendering && ms_IsDrawText) + if (!ms_IsRendering && GetIsDrawText()) ms_FreeTextList.push_back(in_rText); } - void DebugDraw::DrawText2D(const SDrawText& in_rText, const Vector3& in_rVec) + void DebugDraw::DrawText2D(const SDrawText& in_rText, const Vector3& in_rPosition) { - if (!ms_IsRendering && ms_IsDrawText) + if (!ms_IsRendering && GetIsDrawText()) { auto txt = in_rText; - txt.Position = GetNDCCoordinate(in_rVec); + txt.Position = GetNDCCoordinate(in_rPosition); ms_FreeTextList.push_back(txt); } } void DebugDraw::DrawTextLog(const SDrawText& in_rText) { - if (!ms_IsRendering && ms_IsDrawText) + if (!ms_IsRendering && GetIsDrawText()) ms_LogTextList.push_back(in_rText); } void DebugDraw::DrawTextLog(const char* in_Text, float in_Time, ImU32 in_Colour, ImU16 in_Priority) { - if (!ms_IsRendering && ms_IsDrawText) + if (!ms_IsRendering && GetIsDrawText()) ms_LogTextList.push_back({ ImVec2(0,0), in_Text, in_Time, 0, in_Colour, eDrawTextFlags_None, in_Priority}); } @@ -204,12 +204,12 @@ namespace Reddog DrawText2D({ ImVec2(Scale(50), Scale(350)), "TEST3 SCALE", 0, 5, 0xFF37C800 }); DrawTextLog("TEST1 NORMAL"); - DrawTextLog("TEST2 COLORED", 0, 0xFF37C800); - - auto form = fmt::format("- Stats -\nLines: {}\nTexts: {}\nLogs: {}", ms_LineList.size(), ms_FreeTextList.size(), ms_LogTextList.size()); - SDrawText text = { ImVec2(Scale(40), Scale(75)), form.c_str(), 0, 0.75f }; - DrawText2D(text);*/ + DrawTextLog("TEST2 COLORED", 0, 0xFF37C800);*/ + auto stats = fmt::format("== Stats ==\nLines: {}\nTexts: {}\nLogs: {}", ms_LineList.size(), ms_FreeTextList.size(), ms_LogTextList.size()); + SDrawText text = { ImVec2(Scale(40), Scale(75)), stats, 0, 0.75f }; + DrawText2D(text); + ms_IsRendering = true; Exec_DrawLines(drawList, res, deltaTime); @@ -218,4 +218,19 @@ namespace Reddog ms_IsRendering = false; } + + bool DebugDraw::GetIsDrawDebug() + { + return *SWA::SGlobals::ms_IsRenderDebugDraw; + } + + bool DebugDraw::GetIsDrawText() + { + return *SWA::SGlobals::ms_IsRenderDebugDrawText; + } + + bool DebugDraw::GetIsDrawPosition() + { + return *SWA::SGlobals::ms_IsRenderDebugPositionDraw; + } } diff --git a/UnleashedRecomp/ui/reddog/debug_draw.h b/UnleashedRecomp/ui/reddog/debug_draw.h index 02e10a3..4e65764 100644 --- a/UnleashedRecomp/ui/reddog/debug_draw.h +++ b/UnleashedRecomp/ui/reddog/debug_draw.h @@ -28,12 +28,12 @@ namespace Reddog struct SDrawText { ImVec2 Position { 0,0 }; - const char* Text { "" }; + std::string Text; float Time { 0 }; float Scale { 1 }; ImU32 Colour { IM_COL32(255, 255, 255, 255) }; SDrawTextFlags Flags { eDrawTextFlags_None }; - ImU16 Priority { 0xFFFF }; + ImU16 Priority { 0 }; }; @@ -44,21 +44,23 @@ namespace Reddog { public: static inline bool ms_IsRendering = false; - static inline bool ms_IsDrawLine = false; - static inline bool ms_IsDrawText = false; static inline std::vector ms_LineList = {}; static inline std::vector ms_FreeTextList = {}; static inline std::vector ms_LogTextList = {}; - static void DrawLine(const SDrawLine& in_Line); + static void DrawLine(const SDrawLine& in_rLine); - static void DrawText2D(const SDrawText& in_Text); - static void DrawText2D(const SDrawText& in_Text, const Vector3& in_Position); + static void DrawText2D(const SDrawText& in_rText); + static void DrawText2D(const SDrawText& in_rText, const Vector3& in_rPosition); - static void DrawTextLog(const SDrawText& in_Text); - static void DrawTextLog(const char* in_Text, float in_Time = 0, ImU32 in_Colour = IM_COL32(255, 255, 255, 255), ImU16 in_Priority = 0xFFFF); + static void DrawTextLog(const SDrawText& in_rText); + static void DrawTextLog(const char* in_Text, float in_Time = 0, ImU32 in_Colour = IM_COL32(255, 255, 255, 255), ImU16 in_Priority = 0); static void Render(ImFont* font); + + static bool GetIsDrawDebug(); + static bool GetIsDrawText(); + static bool GetIsDrawPosition(); }; } diff --git a/UnleashedRecomp/ui/reddog/windows/view_window.cpp b/UnleashedRecomp/ui/reddog/windows/view_window.cpp index 391e294..1ca020f 100644 --- a/UnleashedRecomp/ui/reddog/windows/view_window.cpp +++ b/UnleashedRecomp/ui/reddog/windows/view_window.cpp @@ -23,13 +23,9 @@ void ViewWindow::Draw() Reddog::Separator(); - Reddog::Checkbox("Render Debug Lines", &Reddog::DebugDraw::ms_IsDrawLine); - Reddog::Checkbox("Render Debug Text", &Reddog::DebugDraw::ms_IsDrawText); - - // TODO (RadiantDerg): respect these in Reddog::DebugDraw, rather than duplicating them. - // Reddog::Checkbox("Render Debug Draw", SWA::SGlobals::ms_IsRenderDebugDraw); - // Reddog::Checkbox("Render Debug Draw Text", SWA::SGlobals::ms_IsRenderDebugDrawText); - // Reddog::Checkbox("Render Debug Position Draw", SWA::SGlobals::ms_IsRenderDebugPositionDraw); + Reddog::Checkbox("Render Debug Draw", SWA::SGlobals::ms_IsRenderDebugDraw); + Reddog::Checkbox("Render Debug Draw Text", SWA::SGlobals::ms_IsRenderDebugDrawText); + Reddog::Checkbox("Render Debug Position Draw", SWA::SGlobals::ms_IsRenderDebugPositionDraw); Reddog::Separator();