Skip to content

Commit

Permalink
Fix dynamic model spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Dec 25, 2023
1 parent 1d89b6d commit a27cbc7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ class CModelInfoSA : public CModelInfo
// Vehicle towing functions
bool IsTowableBy(CModelInfo* towingModel) override;

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

private:
void CopyStreamingInfoFromModel(ushort usCopyFromModelID);
void RwSetSupportedUpgrades(RwFrame* parent, DWORD dwModel);
Expand Down
25 changes: 25 additions & 0 deletions Client/mods/deathmatch/logic/CClientBuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,28 @@ void CClientBuildingManager::RemoveFromList(CClientBuilding* pBuilding)
m_List.remove(pBuilding);
}
}

bool CClientBuildingManager::IsValidModel(uint16_t modelId)
{
if (modelId >= static_cast<uint16_t>(g_pGame->GetBaseIDforTXD()))
return false;

// Clothes and hands cause artefacts
if (384 <= modelId && modelId <= 397)
return false;

CModelInfo* pModelInfo = g_pGame->GetModelInfo(modelId);
if (!pModelInfo || !pModelInfo->GetInterface())
return false;

if (!pModelInfo->IsAllocatedInArchive())
return false;

if (pModelInfo->IsDynamic())
{
return false;
}

eModelInfoType eType = pModelInfo->GetModelType();
return (eType == eModelInfoType::CLUMP || eType == eModelInfoType::ATOMIC || eType == eModelInfoType::WEAPON || eType == eModelInfoType::TIME);
}
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientBuildingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CClientBuildingManager

const std::list<CClientBuilding*>& GetBuildings() { return m_List; };

static bool IsValidModel(uint16_t modelId);

private:
void AddToList(CClientBuilding* pBuilding) { m_List.push_back(pBuilding); }
void RemoveFromList(CClientBuilding* pBuilding);
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ CClientBuilding* CLuaBuildingDefs::CreateBuilding(lua_State* const luaVM, uint16
if (!pResource)
return false;

if (!CClientObjectManager::IsValidModel(modelId))
throw std::invalid_argument("Invalid model id");
if (!CClientBuildingManager::IsValidModel(modelId))
throw std::invalid_argument("Invalid building model id");

if (!g_pGame->GetPools()->HasFreeBuildingSlot())
throw std::invalid_argument("No free slot in buildings pool");
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/game/CModelInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,5 @@ class CModelInfo
virtual bool IsTowableBy(CModelInfo* towingModel) = 0;

virtual unsigned int GetParentID() = 0;
virtual bool IsDynamic() = 0;
};

0 comments on commit a27cbc7

Please sign in to comment.