From fb40c0cb7c083df9da2b9ecdfe3cafc127d107ac Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 18 Sep 2025 21:44:22 -0400 Subject: [PATCH 1/2] Initial hooks Signed-off-by: Isaac Marovitz --- MarathonRecomp/gpu/video.cpp | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/MarathonRecomp/gpu/video.cpp b/MarathonRecomp/gpu/video.cpp index 8829d9e6a..006725376 100644 --- a/MarathonRecomp/gpu/video.cpp +++ b/MarathonRecomp/gpu/video.cpp @@ -345,6 +345,8 @@ static Backend g_backend; #endif static bool g_triangleStripWorkaround = false; +static bool g_conditionalSurveyActive = false; +static bool g_conditionalRenderingActive = false; static std::unique_ptr g_interface; static std::unique_ptr g_device; @@ -4961,6 +4963,9 @@ static void DrawPrimitive(GuestDevice* device, uint32_t primitiveType, uint32_t LocalRenderCommandQueue queue; FlushRenderStateForMainThread(device, queue); + if (g_conditionalRenderingActive) + return; + auto& cmd = queue.enqueue(); cmd.type = RenderCommandType::DrawPrimitive; cmd.drawPrimitive.primitiveType = primitiveType; @@ -4987,6 +4992,9 @@ static void DrawIndexedPrimitive(GuestDevice* device, uint32_t primitiveType, in LocalRenderCommandQueue queue; FlushRenderStateForMainThread(device, queue); + if (g_conditionalRenderingActive) + return; + auto& cmd = queue.enqueue(); cmd.type = RenderCommandType::DrawIndexedPrimitive; cmd.drawIndexedPrimitive.primitiveType = primitiveType; @@ -5012,6 +5020,9 @@ static void DrawPrimitiveUP(GuestDevice* device, uint32_t primitiveType, uint32_ LocalRenderCommandQueue queue; FlushRenderStateForMainThread(device, queue); + if (g_conditionalRenderingActive) + return; + auto& cmd = queue.enqueue(); cmd.type = RenderCommandType::DrawPrimitiveUP; cmd.drawPrimitiveUP.primitiveType = primitiveType; @@ -8437,3 +8448,31 @@ GUEST_FUNCTION_STUB(sub_8254D7B0); // BeginConditional GUEST_FUNCTION_STUB(sub_8254D9D0); // BeginConditional GUEST_FUNCTION_STUB(sub_8254DB90); // BeginConditional GUEST_FUNCTION_STUB(sub_8254DD40); // SetScreenExtentQueryMode + +PPC_FUNC_IMPL(__imp__sub_82636BF8); +PPC_FUNC(sub_82636BF8) { + g_conditionalSurveyActive = true; + + __imp__sub_82636BF8(ctx, base); +} + +PPC_FUNC_IMPL(__imp__sub_82636C08); +PPC_FUNC(sub_82636C08) { + g_conditionalSurveyActive = false; + + __imp__sub_82636C08(ctx, base); +} + +PPC_FUNC_IMPL(__imp__sub_82636C10); +PPC_FUNC(sub_82636C10) { + g_conditionalRenderingActive = true; + + __imp__sub_82636C10(ctx, base); +} + +PPC_FUNC_IMPL(__imp__sub_82636C18); +PPC_FUNC(sub_82636C18) { + g_conditionalRenderingActive = false; + + __imp__sub_82636C18(ctx, base); +} From b524283edfbf3dc4df53899c73bd440aac7ef100 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 19 Sep 2025 22:12:26 -0400 Subject: [PATCH 2/2] Sonicteam::SoX::Graphics::Vertex Signed-off-by: Isaac Marovitz --- MarathonRecomp/api/Marathon.h | 1 + .../api/Sonicteam/CObjBalloonIconDrawable.h | 14 +----- .../api/Sonicteam/SoX/Graphics/Vertex.h | 17 +++++++ MarathonRecomp/api/Sonicteam/TextEntity.h | 20 +++------ .../patches/aspect_ratio_patches.cpp | 44 +++++++++---------- 5 files changed, 47 insertions(+), 49 deletions(-) create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Graphics/Vertex.h diff --git a/MarathonRecomp/api/Marathon.h b/MarathonRecomp/api/Marathon.h index da9000e00..b1a444524 100644 --- a/MarathonRecomp/api/Marathon.h +++ b/MarathonRecomp/api/Marathon.h @@ -107,6 +107,7 @@ #include "Sonicteam/SoX/Graphics/Technique.h" #include "Sonicteam/SoX/Graphics/TechniqueFXL.h" #include "Sonicteam/SoX/Graphics/Transforms.h" +#include "Sonicteam/SoX/Graphics/Vertex.h" #include "Sonicteam/SoX/Graphics/Xenon/DeviceXenon.h" #include "Sonicteam/SoX/Graphics/Xenon/TextureXenon.h" #include "Sonicteam/SoX/IResource.h" diff --git a/MarathonRecomp/api/Sonicteam/CObjBalloonIconDrawable.h b/MarathonRecomp/api/Sonicteam/CObjBalloonIconDrawable.h index 8ce6a771b..efb792b32 100644 --- a/MarathonRecomp/api/Sonicteam/CObjBalloonIconDrawable.h +++ b/MarathonRecomp/api/Sonicteam/CObjBalloonIconDrawable.h @@ -2,6 +2,7 @@ #include #include +#include #include namespace Sonicteam @@ -9,19 +10,8 @@ namespace Sonicteam class CObjBalloonIconDrawable : public SoX::Scenery::Drawable { public: - struct Vertex - { - be X; - be Y; - MARATHON_INSERT_PADDING(0x10); - be Colour; // ARGB8888 - be U; - be V; - MARATHON_INSERT_PADDING(0x18); - }; - xpointer m_pMyGraphicsDevice; MARATHON_INSERT_PADDING(0x24); - Vertex m_Vertices[4]; // BL, TL, BR, TR + SoX::Graphics::Vertex m_Vertices[4]; // BL, TL, BR, TR }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Graphics/Vertex.h b/MarathonRecomp/api/Sonicteam/SoX/Graphics/Vertex.h new file mode 100644 index 000000000..a3c111294 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Graphics/Vertex.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +namespace Sonicteam::SoX::Graphics +{ + struct Vertex + { + Math::Vector3 m_position; + MARATHON_INSERT_PADDING(0xB); + be m_colour; // ARGB8888 + Math::Vector2 m_uv; + Math::Vector2 m_unknown; + MARATHON_INSERT_PADDING(0x10); + }; +} diff --git a/MarathonRecomp/api/Sonicteam/TextEntity.h b/MarathonRecomp/api/Sonicteam/TextEntity.h index 810a204ed..6d995a204 100644 --- a/MarathonRecomp/api/Sonicteam/TextEntity.h +++ b/MarathonRecomp/api/Sonicteam/TextEntity.h @@ -2,6 +2,7 @@ #include #include +#include #include namespace Sonicteam @@ -12,17 +13,6 @@ namespace Sonicteam class TextEntity : public CsdLink { public: - struct Vertex - { - be X; - be Y; - MARATHON_INSERT_PADDING(0x10); - be Colour; // ARGB8888 - be U; - be V; - MARATHON_INSERT_PADDING(0x18); - }; - MARATHON_INSERT_PADDING(4); boost::shared_ptr m_spTextFont; boost::shared_ptr m_spTextBoard; @@ -47,10 +37,10 @@ namespace Sonicteam bool m_FieldDC; bool m_FieldDD; MARATHON_INSERT_PADDING(2); - xpointer m_FieldE0; // Only present when there's character vertices. - xpointer m_FieldE4; // Only present when there's image vertices. - xpointer m_pCharacterVertices; // BL/TL/TR BL/TR/BR (two triangles per character) - xpointer m_pImageVertices; // BL/TL/TR BL/TR/BR (two triangles per image) + xpointer m_FieldE0; // Only present when there's character vertices. + xpointer m_FieldE4; // Only present when there's image vertices. + xpointer m_pCharacterVertices; // BL/TL/TR BL/TR/BR (two triangles per character) + xpointer m_pImageVertices; // BL/TL/TR BL/TR/BR (two triangles per image) be m_CharacterVertexCount; be m_ImageVertexCount; be m_TextLength; diff --git a/MarathonRecomp/patches/aspect_ratio_patches.cpp b/MarathonRecomp/patches/aspect_ratio_patches.cpp index 7aad517d6..da40cfa4d 100644 --- a/MarathonRecomp/patches/aspect_ratio_patches.cpp +++ b/MarathonRecomp/patches/aspect_ratio_patches.cpp @@ -1316,14 +1316,14 @@ PPC_FUNC(sub_82352220) if (g_aspectRatio > WIDE_ASPECT_RATIO) scale = g_aspectRatio / WIDE_ASPECT_RATIO; - pCObjBalloonIconDrawable->m_Vertices[0].X = -1.0f / scale; - pCObjBalloonIconDrawable->m_Vertices[0].Y = 0.0f; - pCObjBalloonIconDrawable->m_Vertices[1].X = -1.0f / scale; - pCObjBalloonIconDrawable->m_Vertices[1].Y = g_aspectRatio / scale; - pCObjBalloonIconDrawable->m_Vertices[2].X = 1.0f / scale; - pCObjBalloonIconDrawable->m_Vertices[2].Y = 0.0f; - pCObjBalloonIconDrawable->m_Vertices[3].X = 1.0f / scale; - pCObjBalloonIconDrawable->m_Vertices[3].Y = g_aspectRatio / scale; + pCObjBalloonIconDrawable->m_Vertices[0].m_position.X = -1.0f / scale; + pCObjBalloonIconDrawable->m_Vertices[0].m_position.Y = 0.0f; + pCObjBalloonIconDrawable->m_Vertices[1].m_position.X = -1.0f / scale; + pCObjBalloonIconDrawable->m_Vertices[1].m_position.Y = g_aspectRatio / scale; + pCObjBalloonIconDrawable->m_Vertices[2].m_position.X = 1.0f / scale; + pCObjBalloonIconDrawable->m_Vertices[2].m_position.Y = 0.0f; + pCObjBalloonIconDrawable->m_Vertices[3].m_position.X = 1.0f / scale; + pCObjBalloonIconDrawable->m_Vertices[3].m_position.Y = g_aspectRatio / scale; __imp__sub_82352220(ctx, base); } @@ -1489,42 +1489,42 @@ void ReplaceTextVariables(Sonicteam::TextEntity* pTextEntity) auto& v4 = pTextEntity->m_pImageVertices[vi + 4]; auto& v5 = pTextEntity->m_pImageVertices[vi + 5]; - auto centreX = (v0.X + v2.X) / 2.0f; + auto centreX = (v0.m_position.X + v2.m_position.X) / 2.0f; auto widthAdjust = (float)newParams.Width / (float)baseParams.Width; auto adjust = [&](auto& vertex) { - vertex.X = centreX + (vertex.X - centreX) * widthAdjust; + vertex.m_position.X = centreX + (vertex.m_position.X - centreX) * widthAdjust; }; // Bottom Left (Triangle 1) adjust(v0); - v0.U = min.x; - v0.V = min.y; + v0.m_uv.X = min.x; + v0.m_uv.Y = min.y; // Top Left (Triangle 1) adjust(v1); - v1.U = min.x; - v1.V = max.y; + v1.m_uv.X = min.x; + v1.m_uv.Y = max.y; // Top Right (Triangle 1) adjust(v2); - v2.U = max.x; - v2.V = max.y; + v2.m_uv.X = max.x; + v2.m_uv.Y = max.y; // Bottom Left (Triangle 2) adjust(v3); - v3.U = min.x; - v3.V = min.y; + v3.m_uv.X = min.x; + v3.m_uv.Y = min.y; // Top Right (Triangle 2) adjust(v4); - v4.U = max.x; - v4.V = max.y; + v4.m_uv.X = max.x; + v4.m_uv.Y = max.y; // Bottom Right (Triangle 2) adjust(v5); - v5.U = max.x; - v5.V = min.y; + v5.m_uv.X = max.x; + v5.m_uv.Y = min.y; pictureIndex++; }