Skip to content

Commit

Permalink
Fix DRAW_ functions in next generation graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Aug 22, 2024
1 parent 265f3e6 commit ce38b44
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/game/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};
Expand Down
5 changes: 5 additions & 0 deletions src/game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/game/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions src/modules/Patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> each call
static Patches* s_patches;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ce38b44

Please sign in to comment.