Skip to content

Commit 642438e

Browse files
authored
Allow dynamic models to be created as buildings (#3880)
1 parent 35cb2e7 commit 642438e

File tree

4 files changed

+16
-28
lines changed

4 files changed

+16
-28
lines changed

Client/game_sa/CBuildingsPoolSA.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1
5353
if (!HasFreeBuildingSlot())
5454
return nullptr;
5555

56+
auto modelInfo = pGame->GetModelInfo(modelId);
57+
58+
// Change the properties group to force dynamic models to be created as buildings instead of dummies
59+
auto prevGroup = modelInfo->GetObjectPropertiesGroup();
60+
if (prevGroup != MODEL_PROPERTIES_GROUP_STATIC)
61+
modelInfo->SetObjectPropertiesGroup(MODEL_PROPERTIES_GROUP_STATIC);
62+
5663
// Load building
5764
SFileObjectInstance instance;
5865
instance.modelID = modelId;
@@ -70,9 +77,12 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1
7077
pBuilding->m_pLod = nullptr;
7178
pBuilding->m_iplIndex = 0;
7279

80+
// Restore changed properties group
81+
if (prevGroup != MODEL_PROPERTIES_GROUP_STATIC)
82+
modelInfo->SetObjectPropertiesGroup(prevGroup);
83+
7384
// Always stream model collosion
7485
// TODO We can setup collison bounding box and use GTA streamer for it
75-
auto modelInfo = pGame->GetModelInfo(modelId);
7686
modelInfo->AddColRef();
7787

7888
// Add building in world

Client/game_sa/CModelInfoSA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ class CModelInfoSA : public CModelInfo
485485
// Vehicle towing functions
486486
bool IsTowableBy(CModelInfo* towingModel) override;
487487

488-
bool IsDynamic() { return m_pInterface ? m_pInterface->usDynamicIndex != 0xffff : false; };
488+
bool IsDynamic() { return m_pInterface ? m_pInterface->usDynamicIndex != MODEL_PROPERTIES_GROUP_STATIC : false; };
489489

490490
private:
491491
void CopyStreamingInfoFromModel(ushort usCopyFromModelID);

Client/mods/deathmatch/logic/CClientBuildingManager.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ bool CClientBuildingManager::IsValidModel(uint16_t modelId)
7373
if (!pModelInfo->IsAllocatedInArchive())
7474
return false;
7575

76-
if (pModelInfo->IsDynamic())
77-
{
78-
return false;
79-
}
80-
8176
eModelInfoType eType = pModelInfo->GetModelType();
8277
return (eType == eModelInfoType::CLUMP || eType == eModelInfoType::ATOMIC || eType == eModelInfoType::WEAPON || eType == eModelInfoType::TIME);
8378
}
@@ -106,29 +101,9 @@ void CClientBuildingManager::RestoreDestroyed()
106101
{
107102
const CClientBuilding* highLodBuilding = building->GetHighLodBuilding();
108103
if (highLodBuilding && !highLodBuilding->IsValid())
109-
{
110104
hasInvalidLods = true;
111-
}
112105
else
113-
{
114-
CModelInfo* modelInfo = building->GetModelInfo();
115-
const uint16_t physicalGroup = modelInfo->GetObjectPropertiesGroup();
116-
117-
if (physicalGroup == -1)
118-
{
119-
building->Create();
120-
}
121-
else
122-
{
123-
// GTA creates dynamic models as dummies.
124-
// It's possible that the physical group was changes after
125-
// creating a new building. We can avoid crashes in this case.
126-
modelInfo->SetObjectPropertiesGroup(-1);
127-
building->Create();
128-
modelInfo->SetObjectPropertiesGroup(physicalGroup);
129-
}
130-
131-
}
106+
building->Create();
132107
}
133108
}
134109
}

Client/sdk/game/CModelInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "CAnimBlock.h"
1616
#include "Common.h"
1717

18+
constexpr std::uint16_t MODEL_PROPERTIES_GROUP_STATIC = 0xFFFF;
19+
1820
class CBaseModelInfoSAInterface;
1921
class CColModel;
2022
class CPedModelInfo;
@@ -131,6 +133,7 @@ struct SVehicleSupportedUpgrades
131133
bool m_bMisc;
132134
bool m_bInitialised;
133135
};
136+
134137
class CModelInfo
135138
{
136139
public:

0 commit comments

Comments
 (0)