Skip to content

Commit

Permalink
Fix collision filtering in Underworld
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Aug 18, 2024
1 parent c621e98 commit 4fb82e9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Instance* Game::GetPlayerInstance() noexcept

GameTracker* Game::GetGameTracker() noexcept
{
return (GameTracker*)GET_ADDRESS(0x10E5370, 0x838330, 0x00E7F088);
return (GameTracker*)GET_ADDRESS(0x10E5370, 0x838330, 0xE7F088);
}

STracker* Game::GetStreamTracker() noexcept
Expand Down
19 changes: 12 additions & 7 deletions src/level/Level.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,28 @@ struct Terrain
Signal* signals;
};
#else
struct TerrainGroupExtra
{
int flags;
};

struct TerrainGroup
{
cdc::Vector3 globalOffset;
cdc::Vector3 localOffset;

int flags;
int field_24;
int field_28;
int field_20;
int ID;
int uniqueID;
int field_2C;
int field_30;

TerrainGroupExtra* extra;
Level* level;
Mesh* mesh;

int field_3C;
int field_40;
int field_44;
float field_3C;
float field_40;
float field_44;
int field_48;
int field_4C;
};
Expand Down
14 changes: 10 additions & 4 deletions src/modules/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,24 @@ void Draw::DrawCollision(Level* level)
continue;
}

#ifndef TR8
auto flags = terrainGroup->flags;
#else
auto flags = terrainGroup->extra->flags;
#endif

// Filter on player/enemy collision
auto flag = terrainGroup->flags & 0x4000;
auto flag = flags & kEnemyCollision;
auto filter = (m_drawPlayerCollision && flag == 0) || (m_drawEnemyCollision && flag != 0);

if (terrainGroup->mesh && filter)
{
DrawCollision(terrainGroup);
DrawCollision(terrainGroup, flags);
}
}
}

void Draw::DrawCollision(TerrainGroup* terrainGroup)
void Draw::DrawCollision(TerrainGroup* terrainGroup, int flags)
{
auto mesh = terrainGroup->mesh;

Expand All @@ -381,7 +387,7 @@ void Draw::DrawCollision(TerrainGroup* terrainGroup)
auto z = GetVertice(face->i2, mesh, &mesh->m_position);

// Draw the face
auto color = terrainGroup->flags & 0x4000 ? RGBA(255, 0, 255, 10) : RGBA(0, 255, 0, 10);
auto color = flags & kEnemyCollision ? RGBA(255, 0, 255, 10) : RGBA(0, 255, 0, 10);
DrawTriangle(&x, &y, &z, color);

// Draw the face outlines
Expand Down
10 changes: 8 additions & 2 deletions src/modules/Draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Draw : public Module
void DrawEnemyRoute(Instance* instance);
void DrawMarkUp();
void DrawCollision(Level* level);
void DrawCollision(TerrainGroup* group);
void DrawCollision(TerrainGroup* group, int flags);
void DrawPortals(Level* level);
void DrawSignals(Level* level);
void DrawTriggers();
Expand All @@ -47,4 +47,10 @@ class Draw : public Module
void OnMenu();
void OnDraw();
void OnFrame();
};
};

#ifndef TR8
constexpr auto kEnemyCollision = 0x4000;
#else
constexpr auto kEnemyCollision = 0x800;
#endif

0 comments on commit 4fb82e9

Please sign in to comment.