Skip to content

Commit 34b4a61

Browse files
authored
Resolve remaining collisionless objects (Fixes #927) (PR #2296)
1 parent 4d1ba12 commit 34b4a61

24 files changed

+706
-205
lines changed

Client/game_sa/CColLineSA.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

Client/game_sa/CColModelSA.h

Lines changed: 139 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,77 +11,165 @@
1111

1212
#pragma once
1313

14-
#include <windows.h>
1514
#include <game/CColModel.h>
15+
#include "CCompressedVectorSA.h"
1616

1717
#define FUNC_CColModel_Constructor 0x40FB60
1818
#define FUNC_CColModel_Destructor 0x40F700
1919

20-
typedef struct
20+
struct CBoxSA
2121
{
22-
CVector vecMin;
23-
CVector vecMax;
24-
CVector vecOffset;
25-
FLOAT fRadius;
26-
} CBoundingBoxSA;
22+
CVector m_vecMin;
23+
CVector m_vecMax;
24+
};
25+
static_assert(sizeof(CBoxSA) == 0x18, "Invalid size for CBoxSA");
2726

28-
typedef struct
27+
struct CBoundingBoxSA : CBoxSA
2928
{
30-
CVector vecCenter;
31-
float fRadius;
32-
} CColSphereSA;
29+
};
30+
static_assert(sizeof(CBoundingBoxSA) == 0x18, "Invalid size for CBoundingBoxSA");
3331

34-
typedef struct
32+
struct CColBoxSA : CBoxSA
3533
{
36-
CVector min;
37-
CVector max;
38-
} CColBoxSA;
34+
EColSurface m_material;
35+
std::uint8_t m_flags;
36+
CColLighting m_lighting;
37+
std::uint8_t m_brightness;
38+
};
39+
static_assert(sizeof(CColBoxSA) == 0x1C, "Invalid size for CColBoxSA");
3940

40-
typedef struct
41+
struct CColLineSA
4142
{
42-
unsigned short v1;
43-
unsigned short v2;
44-
unsigned short v3;
45-
EColSurface material;
46-
CColLighting lighting;
47-
} CColTriangleSA;
48-
49-
typedef struct
43+
CVector m_vecStart;
44+
float m_startSize;
45+
CVector m_vecStop;
46+
float m_stopSize;
47+
};
48+
static_assert(sizeof(CColLineSA) == 0x20, "Invalid size for CColLineSA");
49+
50+
struct CColDiskSA
51+
{
52+
CVector m_startPosition;
53+
float m_startRadius;
54+
std::uint8_t m_material;
55+
std::uint8_t m_piece;
56+
std::uint8_t m_lighting;
57+
CVector m_stopPosition;
58+
float m_stopRadius;
59+
};
60+
static_assert(sizeof(CColDiskSA) == 0x24, "Invalid size for CColDiskSA");
61+
62+
struct CSphereSA
5063
{
51-
BYTE pad0[12];
52-
} CColTrianglePlaneSA;
64+
CVector m_center;
65+
float m_radius;
66+
};
67+
static_assert(sizeof(CSphereSA) == 0x10, "Invalid size for CSphereSA");
5368

54-
typedef struct
69+
struct CColSphereSA : CSphereSA
70+
{
71+
union
72+
{
73+
EColSurface m_material;
74+
std::uint8_t m_collisionSlot;
75+
};
76+
77+
union
78+
{
79+
std::uint8_t m_flags;
80+
81+
struct
82+
{
83+
std::uint8_t m_hasSpheresBoxesTriangles : 1;
84+
std::uint8_t m_isSingleAllocationCollisionData : 1;
85+
std::uint8_t m_isActive: 1;
86+
std::uint8_t m_flag0x08 : 1;
87+
std::uint8_t m_flag0x10 : 1;
88+
std::uint8_t m_flag0x20 : 1;
89+
std::uint8_t m_flag0x40 : 1;
90+
std::uint8_t m_flag0x80 : 1;
91+
};
92+
};
93+
94+
std::uint8_t m_lighting;
95+
std::uint8_t m_light;
96+
97+
CColSphereSA()
98+
{
99+
m_collisionSlot = 0;
100+
m_flags = 0;
101+
m_lighting = 0;
102+
m_light = 0;
103+
}
104+
};
105+
static_assert(sizeof(CColSphereSA) == 0x14, "Invalid size for CColSphereSA");
106+
107+
struct CColTriangleSA
108+
{
109+
std::uint16_t m_indices[3];
110+
EColSurface m_material;
111+
CColLighting m_lighting;
112+
};
113+
static_assert(sizeof(CColTriangleSA) == 0x8, "Invalid size for CColTriangleSA");
114+
115+
struct CColTrianglePlaneSA
116+
{
117+
CCompressedVectorSA m_normal;
118+
std::uint16_t m_distance;
119+
std::uint8_t m_orientation;
120+
};
121+
static_assert(sizeof(CColTrianglePlaneSA) == 0xA, "Invalid size for CColTrianglePlaneSA");
122+
123+
struct ColModelFileHeader
55124
{
56125
char version[4];
57126
DWORD size;
58127
char name[0x18];
59-
} ColModelFileHeader;
128+
};
60129

61-
typedef struct
130+
struct CColDataSA
62131
{
63-
WORD numColSpheres;
64-
WORD numColBoxes;
65-
WORD numColTriangles;
66-
BYTE ucNumWheels;
67-
BYTE pad3;
68-
CColSphereSA* pColSpheres;
69-
CColBoxSA* pColBoxes;
70-
void* pSuspensionLines;
71-
void* pUnknown;
72-
CColTriangleSA* pColTriangles;
73-
CColTrianglePlaneSA* pColTrianglePlanes;
74-
} CColDataSA;
75-
76-
class CColModelSAInterface
132+
std::uint16_t m_numSpheres;
133+
std::uint16_t m_numBoxes;
134+
std::uint16_t m_numTriangles;
135+
std::uint8_t m_numSuspensionLines;
136+
union
137+
{
138+
std::uint8_t m_flags;
139+
140+
struct
141+
{
142+
std::uint8_t m_usesDisks : 1;
143+
std::uint8_t m_notEmpty : 1;
144+
std::uint8_t m_hasShadowInfo : 1;
145+
std::uint8_t m_hasFaceGroups : 1;
146+
std::uint8_t m_hasShadow : 1;
147+
};
148+
};
149+
CColSphereSA* m_spheres;
150+
CColBoxSA* m_boxes;
151+
union
152+
{
153+
CColLineSA* m_suspensionLines;
154+
CColDiskSA* m_disks;
155+
};
156+
CCompressedVectorSA* m_vertices;
157+
CColTriangleSA* m_triangles;
158+
CColTrianglePlaneSA* m_trianglePlanes;
159+
std::uint32_t m_numShadowTriangles;
160+
std::uint32_t m_numShadowVertices;
161+
CCompressedVectorSA* m_shadowVertices;
162+
CColTriangleSA* m_shadowTriangles;
163+
};
164+
static_assert(sizeof(CColDataSA) == 0x30, "Invalid size for CColDataSA");
165+
166+
struct CColModelSAInterface
77167
{
78-
public:
79-
CBoundingBoxSA boundingBox;
80-
BYTE level;
81-
BYTE unknownFlags;
82-
BYTE pad[2];
83-
CColDataSA* pColData;
168+
CBoundingBoxSA m_bounds;
169+
CColSphereSA m_sphere;
170+
CColDataSA* m_data;
84171
};
172+
static_assert(sizeof(CColModelSAInterface) == 0x30, "Invalid size for CColModelSAInterface");
85173

86174
class CColModelSA : public CColModel
87175
{
@@ -90,8 +178,8 @@ class CColModelSA : public CColModel
90178
CColModelSA(CColModelSAInterface* pInterface);
91179
~CColModelSA();
92180

93-
CColModelSAInterface* GetInterface() { return m_pInterface; }
94-
void Destroy() { delete this; }
181+
CColModelSAInterface* GetInterface() override { return m_pInterface; }
182+
void Destroy() override { delete this; }
95183

96184
private:
97185
CColModelSAInterface* m_pInterface;

Client/game_sa/CColStoreSA.cpp

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: game_sa/CColStoreSA.cpp
6+
*
7+
* Multi Theft Auto is available from https://multitheftauto.com/
8+
*
9+
*****************************************************************************/
10+
11+
#include "StdInc.h"
12+
#include "CColStoreSA.h"
13+
14+
void CColStoreSA::Initialise()
15+
{
16+
using Signature = void(__cdecl*)();
17+
const auto function = reinterpret_cast<Signature>(0x4113F0);
18+
function();
19+
}
20+
21+
void CColStoreSA::Shutdown()
22+
{
23+
using Signature = void(__cdecl*)();
24+
const auto function = reinterpret_cast<Signature>(0x4114D0);
25+
function();
26+
}
27+
28+
void CColStoreSA::BoundingBoxesPostProcess()
29+
{
30+
using Signature = void(__cdecl*)();
31+
const auto function = reinterpret_cast<Signature>(0x410EC0);
32+
function();
33+
}
34+
35+
int CColStoreSA::AddColSlot(const char* name)
36+
{
37+
using Signature = int(__cdecl*)(const char*);
38+
const auto function = reinterpret_cast<Signature>(0x411140);
39+
return function(name);
40+
}
41+
42+
bool CColStoreSA::IsValidSlot(CollisionSlot slot)
43+
{
44+
using Signature = bool(__cdecl*)(CollisionSlot);
45+
const auto function = reinterpret_cast<Signature>(0x410660);
46+
return function(slot);
47+
}
48+
49+
void CColStoreSA::AddCollisionNeededAtPosition(const CVector& position)
50+
{
51+
using Signature = void(__cdecl*)(const CVector&);
52+
const auto function = reinterpret_cast<Signature>(0x4103A0);
53+
function(position);
54+
}
55+
56+
void CColStoreSA::EnsureCollisionIsInMemory(const CVector& position)
57+
{
58+
using Signature = void(__cdecl*)(const CVector&);
59+
const auto function = reinterpret_cast<Signature>(0x410AD0);
60+
function(position);
61+
}
62+
63+
bool CColStoreSA::HasCollisionLoaded(const CVector& position, int areaCode)
64+
{
65+
using Signature = bool(__cdecl*)(const CVector&, int);
66+
const auto function = reinterpret_cast<Signature>(0x410CE0);
67+
return function(position, areaCode);
68+
}
69+
70+
void CColStoreSA::RequestCollision(const CVector& position, int areaCode)
71+
{
72+
using Signature = void(__cdecl*)(const CVector&, int);
73+
const auto function = reinterpret_cast<Signature>(0x410C00);
74+
function(position, areaCode);
75+
}
76+
77+
void CColStoreSA::SetCollisionRequired(const CVector& position, int areaCode)
78+
{
79+
using Signature = void(__cdecl*)(const CVector&, int);
80+
const auto function = reinterpret_cast<Signature>(0x4104E0);
81+
function(position, areaCode);
82+
}
83+
84+
void CColStoreSA::RemoveAllCollision()
85+
{
86+
using Signature = void(__cdecl*)();
87+
const auto function = reinterpret_cast<Signature>(0x410E00);
88+
function();
89+
}
90+
91+
void CColStoreSA::AddRef(CollisionSlot slot)
92+
{
93+
using Signature = void(__cdecl*)(CollisionSlot);
94+
const auto function = reinterpret_cast<Signature>(0x4107A0);
95+
function(slot);
96+
}
97+
98+
void CColStoreSA::RemoveRef(CollisionSlot slot)
99+
{
100+
using Signature = void(__cdecl*)(CollisionSlot);
101+
const auto function = reinterpret_cast<Signature>(0x4107D0);
102+
function(slot);
103+
}
104+
105+
void CColStoreSA::RemoveCol(CollisionSlot slot)
106+
{
107+
using Signature = void(__cdecl*)(CollisionSlot);
108+
const auto function = reinterpret_cast<Signature>(0x410730);
109+
function(slot);
110+
}
111+
112+
void CColStoreSA::RemoveColSlot(CollisionSlot slot)
113+
{
114+
using Signature = void(__cdecl*)(CollisionSlot);
115+
const auto function = reinterpret_cast<Signature>(0x411330);
116+
function(slot);
117+
}
118+
119+
void CColStoreSA::LoadAllBoundingBoxes()
120+
{
121+
using Signature = void(__cdecl*)();
122+
const auto function = reinterpret_cast<Signature>(0x4113D0);
123+
function();
124+
}
125+
126+
CColStore::BoundingBox CColStoreSA::GetBoundingBox(CollisionSlot slot)
127+
{
128+
using Signature = BoundingBox&(__cdecl*)(CollisionSlot);
129+
const auto function = reinterpret_cast<Signature>(0x410800);
130+
return function(slot);
131+
}
132+
133+
void CColStoreSA::IncludeModelIndex(CollisionSlot slot, std::uint16_t model)
134+
{
135+
using Signature = void(__cdecl*)(CollisionSlot, int);
136+
const auto function = reinterpret_cast<Signature>(0x410820);
137+
function(slot, model);
138+
}
139+
140+
int CColStoreSA::GetFirstModel(CollisionSlot slot)
141+
{
142+
using Signature = int(__cdecl*)(CollisionSlot);
143+
const auto function = reinterpret_cast<Signature>(0x537A80);
144+
return function(slot);
145+
}
146+
147+
int CColStoreSA::GetLastModel(CollisionSlot slot)
148+
{
149+
using Signature = int(__cdecl*)(CollisionSlot);
150+
const auto function = reinterpret_cast<Signature>(0x537AB0);
151+
return function(slot);
152+
}

0 commit comments

Comments
 (0)