Skip to content

Commit

Permalink
Add portal drawing for TR8
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Mar 11, 2024
1 parent 97d84b6 commit 317fa3f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ void Hook::RegisterModules()
RegisterModule<ModLoader>();
RegisterModule<Patches>();
RegisterModule<FreeCamera>();
RegisterModule<Draw>();

#ifndef TR8
RegisterModule<LevelModule>();
RegisterModule<Frontend>();
RegisterModule<Render>();
RegisterModule<Draw>();
RegisterModule<Debug>();
#else
RegisterModule<ScriptLog>();
Expand Down
30 changes: 30 additions & 0 deletions src/level/Level.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct TerrainGroup
char pad1[116];
};

#ifndef TR8
struct StreamUnitPortal
{
char tolevelname[30];
Expand Down Expand Up @@ -126,6 +127,35 @@ struct Terrain
TerrainGroup* signalTerrainGroup;
Signal* signals;
};
#else
struct StreamUnitPortal
{
char tolevelname[128];

__int16 field_80;
__int16 field_82;

__int16 streamID;

__int16 field_86;
__int16 field_88;
__int16 field_8A;
__int16 field_8C;
__int16 field_8E;

cdc::Vector3 min;
cdc::Vector3 max;
cdc::Vector3 quad[4];
cdc::Vector3 normal;
};

struct Terrain
{
__int16 field_0;
__int16 numStreamUnitPortals;
StreamUnitPortal* streamUnitPortals;
};
#endif

struct Level
{
Expand Down
22 changes: 14 additions & 8 deletions src/modules/Draw.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#ifndef TR8

#include <utility>
#include <string>
#include <imgui.h>
Expand Down Expand Up @@ -148,6 +146,7 @@ void Draw::DrawInstances()

void Draw::DrawInstance(Instance* instance)
{
#ifndef TR8
auto name = instance->object->name;
auto data = (ObjectData*)instance->data;

Expand Down Expand Up @@ -225,10 +224,12 @@ void Draw::DrawInstance(Instance* instance)
}
}
}
#endif
}

void Draw::DrawEnemyRoute(Instance* instance)
{
#ifndef TR8
auto data = (ObjectData*)instance->data;

// Check if the instance is an enemy
Expand All @@ -251,6 +252,7 @@ void Draw::DrawEnemyRoute(Instance* instance)

x = y;
}
#endif
}

void Draw::DrawMarkUp()
Expand Down Expand Up @@ -317,6 +319,7 @@ void Draw::DrawMarkUp()

void Draw::DrawCollision(Level* level)
{
#ifndef TR8
auto terrain = level->terrain;

// Draw the collision mesh for all terrain groups
Expand All @@ -339,6 +342,7 @@ void Draw::DrawCollision(Level* level)
DrawCollision(terrainGroup);
}
}
#endif
}

void Draw::DrawCollision(TerrainGroup* terrainGroup)
Expand Down Expand Up @@ -379,6 +383,7 @@ void Draw::DrawPortals(Level* level)
position += &portal->max;
position /= 2;

#ifndef TR8
TRANS_RotTransPersVectorf(&position, &position);

// Check if the portal is on screen
Expand All @@ -387,15 +392,17 @@ void Draw::DrawPortals(Level* level)
// Draw the portal destination
font->SetCursor(position.x, position.y);
font->PrintCentered("Portal to %s", portal->tolevelname);

// Draw the portal bounds
DrawPlane(&portal->min, &portal->max, RGBA(0, 0, 255, 10));
}
#endif

// Draw the portal bounds
DrawPlane(&portal->min, &portal->max, RGBA(0, 0, 255, 10));
}
}

void Draw::DrawSignals(Level* level)
{
#ifndef TR8
auto terrain = level->terrain;
auto terrainGroup = terrain->signalTerrainGroup;

Expand All @@ -420,6 +427,7 @@ void Draw::DrawSignals(Level* level)
// Draw the face
DrawTriangle(&x, &y, &z, RGBA(255, 0, 0, 10));
}
#endif
}

std::string Draw::FlagsToString(unsigned int flags)
Expand All @@ -441,6 +449,4 @@ std::string Draw::FlagsToString(unsigned int flags)
result.erase(result.end() - 3, result.end());

return result;
}

#endif
}
5 changes: 1 addition & 4 deletions src/modules/Draw.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#ifndef TR8

#include "Module.h"

Expand Down Expand Up @@ -46,6 +45,4 @@ class Draw : public Module
void OnMenu();
void OnDraw();
void OnFrame();
};

#endif
};
2 changes: 1 addition & 1 deletion src/render/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void TRANS_TransToDrawVertexV4f(DRAWVERTEX* v, cdc::Vector3* vec)

void TRANS_RotTransPersVectorf(cdc::Vector3* srcvector, cdc::Vector3* dstvector)
{
auto addr = GET_ADDRESS(0x402B20, 0x402B50, 0x000000);
auto addr = GET_ADDRESS(0x402B20, 0x402B50, 0x49F630);

Hooking::Call(addr, srcvector, dstvector);
}
Expand Down

0 comments on commit 317fa3f

Please sign in to comment.