Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions Client/mods/deathmatch/logic/CClientIMG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ struct tImgHeader
unsigned int uiFilesCount;
};

// SetStreamingInfo force-removes the model's RwObject, and the streamer no longer tracks it
// after the archive change, so entities still using it have to be streamed out first
static void StreamOutModelUsers(unsigned int uiModelID)
{
if (CClientVehicleManager::IsValidModel(uiModelID))
g_pClientGame->GetVehicleManager()->RestreamVehicles(static_cast<unsigned short>(uiModelID));

if (CClientPedManager::IsValidWeaponModel(uiModelID))
g_pClientGame->GetPedManager()->RestreamWeapon(static_cast<unsigned short>(uiModelID));
}

CClientIMG::CClientIMG(class CClientManager* pManager, ElementID ID)
: ClassInit(this), CClientEntity(ID), m_pImgManager(pManager->GetIMGManager()), m_ucArchiveID(INVALID_ARCHIVE_ID), m_LargestFileSizeBlocks(0)
{
Expand Down Expand Up @@ -180,6 +191,7 @@ bool CClientIMG::StreamDisable()
// Unlink all models
for (const auto& v : m_restoreInfo)
{
StreamOutModelUsers(v.uiModelID);
g_pGame->GetStreaming()->SetStreamingInfo(v.uiModelID, v.ucStreamID, v.uiOffset, v.usSize);
}
m_restoreInfo.clear();
Expand Down Expand Up @@ -219,15 +231,7 @@ bool CClientIMG::LinkModel(unsigned int uiModelID, size_t uiFileID)

m_restoreInfo.emplace_back(uiModelID, pCurrInfo->offsetInBlocks, pCurrInfo->sizeInBlocks, pCurrInfo->archiveId);

// Internally stream out the vehicle before calling CStreamingSA::RemoveModel
// otherwise a crash will occur if the player is inside a vehicle that gets unloaded by the streamer
if (CClientVehicleManager::IsValidModel(uiModelID))
g_pClientGame->GetVehicleManager()->RestreamVehicles(static_cast<unsigned short>(uiModelID));

// Weapon models already in a ped's hand keep their old RW clump until the weapon slot is
// re-requested, same as vehicles above (see CClientDFF::ReplaceWeaponModel for the equivalent case)
if (CClientPedManager::IsValidWeaponModel(uiModelID))
g_pClientGame->GetPedManager()->RestreamWeapon(static_cast<unsigned short>(uiModelID));
StreamOutModelUsers(uiModelID);

g_pGame->GetStreaming()->SetStreamingInfo(uiModelID, m_ucArchiveID, pFileInfo->uiOffset, pFileInfo->usSize);

Expand All @@ -242,6 +246,7 @@ bool CClientIMG::UnlinkModel(unsigned int uiModelID)
if (it == m_restoreInfo.end())
return false;

StreamOutModelUsers(uiModelID);
g_pGame->GetStreaming()->SetStreamingInfo(uiModelID, it->ucStreamID, it->uiOffset, it->usSize);

m_restoreInfo.erase(it);
Expand Down
Loading