Skip to content

Commit 35b2b84

Browse files
authored
Merge pull request #11 from TheIndra55/underworld-draw
Add Underworld draw options
2 parents 4ca6675 + 8f411b6 commit 35b2b84

File tree

14 files changed

+446
-42
lines changed

14 files changed

+446
-42
lines changed

docs/features.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ This will visualize all portals which are between levels.
159159

160160
This will draw all signals (triggers) in the current level.
161161

162+
### Draw triggers
163+
164+
This will draw all trigger volumes and planes in the current level. This feature only exists in Underworld.
165+
162166
## Debug
163167

164168
The debug menu has some restored event debug features.

src/Hook.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ void Hook::RegisterModules()
130130
RegisterModule<ModLoader>();
131131
RegisterModule<Patches>();
132132
RegisterModule<FreeCamera>();
133+
RegisterModule<Draw>();
133134

134135
#ifndef TR8
135136
RegisterModule<LevelModule>();
136137
RegisterModule<Frontend>();
137138
RegisterModule<Render>();
138-
RegisterModule<Draw>();
139139
RegisterModule<Debug>();
140140
#else
141141
RegisterModule<ScriptLog>();

src/cdc/math/Math.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,20 @@ cdc::Vector3 cdc::Mul3x3(Matrix* matA, Vector3* vecB)
1010
_mm_mul_ps(matA->col1.vec128, _mm_shuffle_ps(vecB->vec128, vecB->vec128, _MM_SHUFFLE(1, 1, 1, 1))),
1111
_mm_mul_ps(matA->col2.vec128, _mm_shuffle_ps(vecB->vec128, vecB->vec128, _MM_SHUFFLE(2, 2, 2, 2)))));
1212

13+
return result;
14+
}
15+
16+
cdc::Vector3 cdc::Mul3x4(Matrix* matA, Vector3* vecB)
17+
{
18+
cdc::Vector3 result;
19+
20+
result.vec128 = _mm_add_ps(
21+
_mm_mul_ps(matA->col0.vec128, _mm_shuffle_ps(vecB->vec128, vecB->vec128, _MM_SHUFFLE(0, 0, 0, 0))),
22+
_mm_add_ps(
23+
_mm_mul_ps(matA->col1.vec128, _mm_shuffle_ps(vecB->vec128, vecB->vec128, _MM_SHUFFLE(1, 1, 1, 1))),
24+
_mm_add_ps(
25+
_mm_mul_ps(matA->col2.vec128, _mm_shuffle_ps(vecB->vec128, vecB->vec128, _MM_SHUFFLE(2, 2, 2, 2))),
26+
matA->col3.vec128)));
27+
1328
return result;
1429
}

src/cdc/math/Math.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
namespace cdc
77
{
88
Vector3 Mul3x3(Matrix* matA, Vector3* vecB);
9+
Vector3 Mul3x4(Matrix* matA, Vector3* vecB);
910
}

src/cdc/math/Matrix.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@ void cdc::Matrix::Build(Euler* euler)
66
// Too lazy to implement myself
77
auto addr = GET_ADDRESS(0x000000, 0x000000, 0x49DD70);
88

9+
Hooking::ThisCall(addr, this, euler);
10+
}
11+
12+
void cdc::Matrix::Build_XYZOrder(cdc::Euler* euler)
13+
{
14+
// Too lazy to implement myself
15+
auto addr = GET_ADDRESS(0x000000, 0x000000, 0x49D500);
16+
917
Hooking::ThisCall(addr, this, euler);
1018
}

src/cdc/math/Matrix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ namespace cdc
1313
Vector col3;
1414

1515
void Build(Euler* euler);
16+
void Build_XYZOrder(cdc::Euler* euler);
1617
};
1718
}

src/level/Level.h

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct StreamUnit;
1010

1111
struct IndexedFace
1212
{
13+
#ifndef TR8
1314
unsigned __int16 i0;
1415
unsigned __int16 i1;
1516
unsigned __int16 i2;
@@ -18,21 +19,42 @@ struct IndexedFace
1819
unsigned __int8 collisionFlags;
1920
unsigned __int8 clientFlags;
2021
unsigned __int8 materialType;
22+
#else
23+
unsigned int i0;
24+
unsigned int i1;
25+
unsigned int i2;
26+
27+
unsigned __int8 adjacencyFlags;
28+
unsigned __int8 collisionFlags;
29+
unsigned __int16 clientFlags;
30+
unsigned int materialType;
31+
#endif
2132
};
2233

2334
struct SignalFace
2435
{
36+
#ifndef TR8
2537
unsigned __int16 i0;
2638
unsigned __int16 i1;
2739
unsigned __int16 i2;
2840

29-
char adjacencyFlags;
30-
char collisionFlags;
41+
unsigned __int8 adjacencyFlags;
42+
unsigned __int8 collisionFlags;
3143

3244
unsigned __int16 id;
45+
#else
46+
unsigned int i0;
47+
unsigned int i1;
48+
unsigned int i2;
49+
50+
unsigned __int8 adjacencyFlags;
51+
unsigned __int8 collisionFlags;
52+
53+
unsigned __int16 id;
54+
#endif
3355
};
3456

35-
struct MeshVertex
57+
struct MeshVertex16
3658
{
3759
__int16 x;
3860
__int16 y;
@@ -53,6 +75,12 @@ struct BBox
5375
cdc::Vector3 bMax;
5476
};
5577

78+
enum VertexType
79+
{
80+
VERTEX_INT16,
81+
VERTEX_FLOAT32
82+
};
83+
5684
struct Mesh
5785
{
5886
BBox m_box;
@@ -64,17 +92,28 @@ struct Mesh
6492

6593
void* m_clientData;
6694

95+
#ifndef TR8
6796
unsigned __int16 m_vertexType;
6897
unsigned __int16 m_numNodes;
6998
unsigned __int16 m_numFaces;
7099
unsigned __int16 m_numVertices;
71100
unsigned __int16 m_height;
72101
unsigned __int16 m_numDegenerateFaces;
73102
unsigned __int16 m_numNonManifoldEdges;
103+
#else
104+
unsigned int m_numNodes;
105+
unsigned int m_numFaces;
106+
unsigned int m_numVertices;
107+
unsigned int m_numDegenerateFaces;
108+
unsigned int m_numNonManifoldEdges;
109+
unsigned __int16 m_vertexType;
110+
unsigned __int16 m_height;
111+
#endif
74112
};
75113

76114
struct Level;
77115

116+
#ifndef TR8
78117
struct TerrainGroup
79118
{
80119
cdc::Vector3 globalOffset;
@@ -126,6 +165,61 @@ struct Terrain
126165
TerrainGroup* signalTerrainGroup;
127166
Signal* signals;
128167
};
168+
#else
169+
struct TerrainGroup
170+
{
171+
cdc::Vector3 globalOffset;
172+
cdc::Vector3 localOffset;
173+
174+
int flags;
175+
int field_24;
176+
int field_28;
177+
int field_2C;
178+
int field_30;
179+
180+
Level* level;
181+
Mesh* mesh;
182+
183+
int field_3C;
184+
int field_40;
185+
int field_44;
186+
int field_48;
187+
int field_4C;
188+
};
189+
190+
struct StreamUnitPortal
191+
{
192+
char tolevelname[128];
193+
194+
__int16 field_80;
195+
__int16 field_82;
196+
197+
__int16 streamID;
198+
199+
__int16 field_86;
200+
__int16 field_88;
201+
__int16 field_8A;
202+
__int16 field_8C;
203+
__int16 field_8E;
204+
205+
cdc::Vector3 min;
206+
cdc::Vector3 max;
207+
cdc::Vector3 quad[4];
208+
cdc::Vector3 normal;
209+
};
210+
211+
struct Terrain
212+
{
213+
__int16 field_0;
214+
__int16 numStreamUnitPortals;
215+
StreamUnitPortal* streamUnitPortals;
216+
217+
int numTerrainGroups;
218+
TerrainGroup* terrainGroups;
219+
220+
TerrainGroup* signalTerrainGroup;
221+
};
222+
#endif
129223

130224
struct Level
131225
{

src/level/Markup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
MarkupManager* MarkupManager::GetInstance() noexcept
55
{
6-
return *(MarkupManager**)GET_ADDRESS(0x1117544, 0x86CD14, 0x000000);
6+
return *(MarkupManager**)GET_ADDRESS(0x1117544, 0x86CD14, 0xDB94CC);
77
}
88

99
cdc::Vector3* MarkUpBox::GetSegmentPos(cdc::Vector3* result, int n) const noexcept
1010
{
11-
auto addr = GET_ADDRESS(0x45F3A0, 0x462D90, 0x000000);
11+
auto addr = GET_ADDRESS(0x45F3A0, 0x462D90, 0x5C39D0);
1212

1313
return Hooking::ThisCallReturn<cdc::Vector3*>(addr, this, result, n);
1414
}

src/level/Markup.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ struct SAPBox;
88
class MarkupManager
99
{
1010
public:
11+
#ifndef TR8
1112
SweepAndPrune* m_sap;
13+
#endif
1214

1315
NodeType m_freeBoxList;
1416
NodeType m_dynamicBoxList;
@@ -62,6 +64,7 @@ enum MUD_FLAGS : unsigned int
6264
MUD_FLAG_ALL = 0xFFFFFFFF,
6365
};
6466

67+
#ifndef TR8
6568
struct MarkUp
6669
{
6770
int OverrideMovementCamera;
@@ -83,6 +86,28 @@ struct MarkUp
8386

8487
PolyLine* polyLine;
8588
};
89+
#else
90+
struct MarkUp
91+
{
92+
int field_0;
93+
int field_4;
94+
int field_8;
95+
int field_C;
96+
int field_10;
97+
int field_14;
98+
int field_18;
99+
int field_1C;
100+
int field_20;
101+
int field_24;
102+
int field_28;
103+
int field_2C;
104+
int field_30;
105+
float pos[3];
106+
float bbox[6];
107+
PolyLine* polyLine;
108+
};
109+
110+
#endif
86111

87112
#pragma pack(push, 16)
88113
class MarkUpBox : NodeType
@@ -101,6 +126,9 @@ class MarkUpBox : NodeType
101126
MarkUp* markup;
102127
#endif
103128

129+
#ifdef TR8
130+
int field_24;
131+
#endif
104132
unsigned int flags;
105133

106134
float attach_delay;

src/level/Trigger.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
3+
#include "instance/Instance.h"
4+
5+
enum TriggerShape
6+
{
7+
TriggerShape_Box = 1,
8+
TriggerShape_Sphere = 2
9+
};
10+
11+
struct IntroDataTrigger : IntroData
12+
{
13+
char pad1[44];
14+
15+
TriggerShape shape;
16+
float LocalXExtent;
17+
float LocalYExtent;
18+
float LocalZExtent;
19+
float Radius;
20+
};
21+
22+
struct NsInstance
23+
{
24+
char pad1[32];
25+
26+
Instance* m_instance;
27+
};
28+
29+
struct NsTriggerPlaneBase : NsInstance
30+
{
31+
unsigned int m_flags;
32+
};
33+
34+
struct NsTriggerVolumeBase : NsInstance
35+
{
36+
unsigned int m_flags;
37+
};

0 commit comments

Comments
 (0)