Skip to content

Commit 42b95b5

Browse files
authored
Potential fix of #1613 (#2198)
Test crashfix for pools / custom map crashes 0x0013368b, 0x00144bc8 and 0x00142721 Read both #1613 and #2198 for more info
1 parent 26a3009 commit 42b95b5

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed

Client/game_sa/CEntitySA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class CPlaceableSAInterface // 20 bytes
120120
{
121121
public:
122122
CSimpleTransformSAInterface m_transform;
123-
CMatrix_Padded* matrix; // This is actually XYZ*, change later
123+
CMatrix_Padded* matrix; // This is actually XYZ*, change later
124124
};
125125

126126
class CEntitySAInterface

Client/game_sa/CFileLoaderSA.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void CFileLoaderSA::StaticSetHooks()
1515
{
1616
HookInstall(0x5371F0, (DWORD)CFileLoader_LoadAtomicFile, 5);
1717
HookInstall(0x537150, (DWORD)CFileLoader_SetRelatedModelInfoCB, 5);
18+
HookInstall(0x538690, (DWORD)CFileLoader_LoadObjectInstance, 5);
1819
}
1920

2021
class CAtomicModelInfo
@@ -159,3 +160,35 @@ RpAtomic* CFileLoader_SetRelatedModelInfoCB(RpAtomic* atomic, SRelatedModelInfo*
159160
}
160161
return atomic;
161162
}
163+
164+
CEntitySAInterface* CFileLoader_LoadObjectInstance(const char* szLine)
165+
{
166+
char szModelName[24];
167+
SFileObjectInstance inst;
168+
169+
sscanf(
170+
szLine,
171+
"%d %s %d %f %f %f %f %f %f %f %d",
172+
&inst.modelID,
173+
szModelName,
174+
&inst.interiorID,
175+
&inst.position.fX,
176+
&inst.position.fY,
177+
&inst.position.fZ,
178+
&inst.rotation.fX,
179+
&inst.rotation.fY,
180+
&inst.rotation.fZ,
181+
&inst.rotation.fW,
182+
&inst.lod
183+
);
184+
185+
/*
186+
A quaternion is must be normalized. GTA is relying on an internal R* exporter and everything is OK,
187+
but custom exporters might not contain the normalization. And we must do it yourself.
188+
*/
189+
const float fLenSq = inst.rotation.LengthSquared();
190+
if (fLenSq > 0.0f && std::fabs(fLenSq - 1.0f) > std::numeric_limits<float>::epsilon())
191+
inst.rotation /= std::sqrt(fLenSq);
192+
193+
return ((CEntitySAInterface*(__cdecl*)(SFileObjectInstance*))0x538090)(&inst);
194+
}

Client/game_sa/CFileLoaderSA.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ struct SRelatedModelInfo
66
bool bDeleteOldRwObject;
77
};
88

9+
struct SFileObjectInstance
10+
{
11+
CVector position;
12+
CVector4D rotation;
13+
int modelID;
14+
int interiorID;
15+
int lod;
16+
};
17+
918
class CFileLoaderSA
1019
{
1120
public:
@@ -17,3 +26,4 @@ class CFileLoaderSA
1726

1827
bool CFileLoader_LoadAtomicFile(RwStream *stream, unsigned int modelId);
1928
RpAtomic* CFileLoader_SetRelatedModelInfoCB(RpAtomic* atomic, SRelatedModelInfo* pRelatedModelInfo);
29+
CEntitySAInterface* CFileLoader_LoadObjectInstance(const char* szLine);

Client/game_sa/CGameSA.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ CGameSA::CGameSA()
196196
m_pPools->SetPoolCapacity(ENV_MAP_ATOMIC_POOL, 4000); // Default is 1024
197197
m_pPools->SetPoolCapacity(SPEC_MAP_MATERIAL_POOL, 16000); // Default is 4096
198198
m_pPools->SetPoolCapacity(ENTRY_INFO_NODE_POOL, MAX_ENTRY_INFO_NODES); // Default is 500
199+
m_pPools->SetPoolCapacity(POINTER_SINGLE_LINK_POOL, MAX_POINTER_SINGLE_LINKS); // Default is 70000
199200
m_pPools->SetPoolCapacity(POINTER_DOUBLE_LINK_POOL, MAX_POINTER_DOUBLE_LINKS); // Default is 3200
200201
dassert(m_pPools->GetPoolCapacity(POINTER_SINGLE_LINK_POOL) == MAX_POINTER_SINGLE_LINKS);
201202

Client/sdk/game/Common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define MAX_PEDS_MTA 110 // Real limit is 140
2020
#define MAX_OBJECTS_MTA 1000 // Real limit is 1200
2121
#define MAX_ENTRY_INFO_NODES_MTA 72000 // Real limit is 72600 ( MAX_OBJECTS_MTA * 72 ) [Large col models are the cause of high usage]
22-
#define MAX_POINTER_SINGLE_LINKS_MTA 65000 // Real limit is 70000
22+
#define MAX_POINTER_SINGLE_LINKS_MTA 85000 // Real limit is 90000 [Large col models are the cause of high usage]
2323
#define MAX_POINTER_DOUBLE_LINKS_MTA 74000 // Real limit is 74800 ( MAX_OBJECTS_MTA * 72 + 2000 )
2424

2525
// Real limits for GTA
@@ -28,7 +28,7 @@
2828
#define MAX_OBJECTS ( MAX_OBJECTS_MTA + 200 ) // 1200
2929
#define MAX_BUILDINGS 13000
3030
#define MAX_ENTRY_INFO_NODES ( MAX_ENTRY_INFO_NODES_MTA + 600 ) // 72600
31-
#define MAX_POINTER_SINGLE_LINKS ( MAX_POINTER_SINGLE_LINKS_MTA + 5000 ) // 70000
31+
#define MAX_POINTER_SINGLE_LINKS ( MAX_POINTER_SINGLE_LINKS_MTA + 5000 ) // 90000
3232
#define MAX_POINTER_DOUBLE_LINKS ( MAX_POINTER_DOUBLE_LINKS_MTA + 800 ) // 74800
3333
#define MAX_RWOBJECT_INSTANCES 2500
3434

0 commit comments

Comments
 (0)