From ce38b44f5dbcbd95775d9838c9618cc6ddfda1e9 Mon Sep 17 00:00:00 2001 From: TheIndra55 Date: Thu, 22 Aug 2024 22:23:53 +0200 Subject: [PATCH] Fix DRAW_ functions in next generation graphics --- src/game/Camera.h | 12 +++++++++++- src/game/Game.cpp | 5 +++++ src/game/Game.h | 2 ++ src/modules/Patches.cpp | 18 ++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/game/Camera.h b/src/game/Camera.h index 83f2965..da34ad9 100644 --- a/src/game/Camera.h +++ b/src/game/Camera.h @@ -7,7 +7,17 @@ struct CameraCore { cdc::Vector3 position; - char pad1[608]; + cdc::Vector3 effectPosition; + + cdc::Matrix vvNormalWorVecMatf[2]; + cdc::Matrix defaultvvNormalWorVecMatf[2]; + cdc::Matrix wcTransformf; + cdc::Matrix wcTransformNoShakef; + cdc::Matrix wcTransform2f; + cdc::Matrix cwTransform2f; + + cdc::Vector3 viewVolumeNormal[5]; + cdc::Euler rotation; char pad2[128]; }; diff --git a/src/game/Game.cpp b/src/game/Game.cpp index 3f14602..49c19cf 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -17,6 +17,11 @@ STracker* Game::GetStreamTracker() noexcept return (STracker*)GET_ADDRESS(0x11582F8, 0x8AE378, 0xDBAB40); } +bool Game::IsInNextGenMode() noexcept +{ + return *(bool*)GET_ADDRESS(0x10024E8, 0x7545B4, 0x000000); +} + void GAMELOOP_RequestLevelChangeByName(char* name, GameTracker* gameTracker, int doneType) { auto addr = GET_ADDRESS(0x451970, 0x4543C0, 0x5DF8C0); diff --git a/src/game/Game.h b/src/game/Game.h index 4f73ac1..5d1f4b5 100644 --- a/src/game/Game.h +++ b/src/game/Game.h @@ -170,6 +170,8 @@ class Game static Instance* GetPlayerInstance() noexcept; static GameTracker* GetGameTracker() noexcept; static STracker* GetStreamTracker() noexcept; + + static bool IsInNextGenMode() noexcept; }; void GAMELOOP_RequestLevelChangeByName(char* name, GameTracker* gameTracker, int doneType); diff --git a/src/modules/Patches.cpp b/src/modules/Patches.cpp index 0555782..1b5fe82 100644 --- a/src/modules/Patches.cpp +++ b/src/modules/Patches.cpp @@ -7,6 +7,7 @@ #include "MainMenu.h" #include "patches/Reloc.h" #include "patches/ErrorHandler.h" +#include "game/Camera.h" // Instance of patches so we can get it in our hooks without calling GetModule each call static Patches* s_patches; @@ -16,6 +17,7 @@ static MainMenu* s_menu; // Original functions static void(*s_RenderG2_MotionBlur)(int, int, int); static void(*s_GAMELOOP_HandleScreenWipes)(); +static void(*s_TRANS_SetTransformMatrixf)(cdc::Matrix*); static void RenderG2_MotionBlur(int blur, int time, int timeout) { @@ -44,6 +46,19 @@ static void GAMELOOP_HandleScreenWipes() s_GAMELOOP_HandleScreenWipes(); } + +static void TRANS_SetTransformMatrixf(cdc::Matrix* m) +{ + auto camera = CAMERA_GetCamera(); + + // Use the right transform in next generation graphics + if (Game::IsInNextGenMode() && m == &camera->wcTransformf) + { + m = &camera->wcTransform2f; + } + + s_TRANS_SetTransformMatrixf(m); +} #endif // No death fade code @@ -108,6 +123,9 @@ Patches::Patches() #ifdef TR7 // NOP the exception handler in Legend Hooking::Nop((void*)0x401F53, 26); + + // Fix DRAW_ functions in next generation graphics + MH_CreateHook((void*)0x402B10, TRANS_SetTransformMatrixf, (void**)&s_TRANS_SetTransformMatrixf); #endif // Patches