Skip to content

Commit c321082

Browse files
committed
Add wireframe for TR8
1 parent 37ef54e commit c321082

5 files changed

Lines changed: 62 additions & 3 deletions

File tree

src/Hook.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ void Hook::RegisterModules()
139139
RegisterModule<FreeCamera>();
140140
RegisterModule<Draw>();
141141
RegisterModule<Frontend>();
142+
RegisterModule<Render>();
142143

143144
#ifndef TR8
144145
RegisterModule<LevelModule>();
145-
RegisterModule<Render>();
146146
RegisterModule<Debug>();
147147
#else
148148
RegisterModule<ScriptLog>();

src/cdc/render/PCStateManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "PCStateManager.h"
2+
3+
#include "util/Hooking.h"
4+
5+
void cdc::PCStateManager::SetRenderState(D3DRENDERSTATETYPE state, unsigned int value)
6+
{
7+
Hooking::ThisCall(0x502B70, this, state, value);
8+
}

src/cdc/render/PCStateManager.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include <d3d9.h>
4+
5+
#include "PCInternalResource.h"
6+
7+
namespace cdc
8+
{
9+
class PCStateManager : public PCInternalResource
10+
{
11+
public:
12+
IDirect3DDevice9* m_pD3DDevice;
13+
14+
void SetRenderState(D3DRENDERSTATETYPE state, unsigned int value);
15+
};
16+
}

src/cdc/script/ScriptObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
void cdc::ScriptObject::CallFunction(Function* function, int numArgs, void* args, void* retVal)
66
{
7-
return Hooking::ThisCall(0x57B380, this, function, numArgs, args, retVal);
7+
Hooking::ThisCall(0x57B380, this, function, numArgs, args, retVal);
88
}

src/modules/Render.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include "Render.h"
55
#include "util/Hooking.h"
66

7+
#include "cdc/render/PCDeviceManager.h"
8+
#include "cdc/render/PCStateManager.h"
9+
10+
#ifndef TR8
711
static bool s_terrainWireframe = false;
812

913
// Code for terrain wireframe
@@ -27,21 +31,52 @@ static TerrainDrawable* __fastcall TerrainDrawable_TerrainDrawable(TerrainDrawab
2731

2832
return ret;
2933
}
34+
#else
35+
static bool s_wireframe = false;
36+
37+
static void(__thiscall* s_PCScene_Draw)(int, int, int);
38+
39+
static void __fastcall PCScene_Draw(int a1, void*, int a2, int a3)
40+
{
41+
auto device = cdc::PCDeviceManager::GetInstance();
42+
auto state = *(cdc::PCStateManager**)((char*)device + 644); // TODO
43+
44+
if (s_wireframe)
45+
{
46+
state->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
47+
}
48+
49+
s_PCScene_Draw(a1, a2, a3);
50+
51+
// Reset
52+
if (s_wireframe)
53+
{
54+
state->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
55+
}
56+
}
57+
#endif
3058

3159
Render::Render()
3260
{
61+
#ifndef TR8
3362
// Insert terrain wireframe hook
3463
MH_CreateHook((void*)GET_ADDRESS(0x40ACF0, 0x40B9B0, 0x000000), TerrainDrawable_TerrainDrawable, (void**)&s_TerrainDrawable_TerrainDrawable);
64+
#else
65+
MH_CreateHook((void*)0x5150E0, PCScene_Draw, (void**)&s_PCScene_Draw);
66+
#endif
3567
MH_EnableHook(MH_ALL_HOOKS);
3668
}
3769

3870
void Render::OnMenu()
3971
{
4072
if (ImGui::BeginMenu("Render"))
4173
{
42-
// TODO Wireframe for Underworld
74+
#ifndef TR8
4375
ImGui::MenuItem("Wireframe", nullptr, (bool*)GET_ADDRESS(0x1075BD4, 0x7C7CD4, 0x000000));
4476
ImGui::MenuItem("Terrain wireframe", nullptr, &s_terrainWireframe);
77+
#else
78+
ImGui::MenuItem("Wireframe", nullptr, &s_wireframe);
79+
#endif
4580

4681
ImGui::EndMenu();
4782
}

0 commit comments

Comments
 (0)