Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d30527a
Object models allocating
TheNormalnij Sep 28, 2020
8a6e551
Changed models validating.
TheNormalnij Sep 28, 2020
541177b
Allow spawn weapons
TheNormalnij Sep 28, 2020
93af5cb
Fix data type
TheNormalnij Sep 29, 2020
fd01672
Changed enum to enum class
TheNormalnij Sep 29, 2020
01dee3a
Used "auto" for loops
TheNormalnij Sep 29, 2020
3bc996f
Used a safe way to copy model data.
TheNormalnij Sep 29, 2020
e6f038a
Used enum class fro eClientModelType
TheNormalnij Sep 30, 2020
e340846
Changed syntax in GetStreamingInfoFromModelId
TheNormalnij Oct 1, 2020
1f3ae20
Used const_iterator for pObjectManager
TheNormalnij Oct 1, 2020
c6f9af7
Call event "onClientElementModelChange" when we deallocate model
TheNormalnij Oct 1, 2020
033ab31
fix CModelInfoSA::IsValid() formating
TheNormalnij Oct 1, 2020
4e48b48
Fix typo
TheNormalnij Oct 1, 2020
3d29ddd
Added "Reset" method for CStreamingInfo.
TheNormalnij Oct 1, 2020
8834f65
Used early return in CClientObjectManager::IsValidModel again
TheNormalnij Oct 1, 2020
55313e7
Used ReadEnumString in CLuaEngineDefs::EngineRequestModel
TheNormalnij Oct 1, 2020
74f649f
Fix debug message in CMultiplayerSA_CrashFixHacks.cpp
TheNormalnij Oct 1, 2020
06718e7
Used early return in CClientObjectManager::IsValidModel
TheNormalnij Oct 1, 2020
ac6678b
Used clean way to reset streaming info in CModelInfoSA::DeallocateModel
TheNormalnij Oct 2, 2020
b214b4b
Init CStreamingInfo array in CStreamingSA.h
TheNormalnij Oct 2, 2020
bbfa21e
Fix syntax in CModelInfoSA::IsValid
TheNormalnij Oct 2, 2020
9c94810
Init CStreamingSA::ms_aInfoForModel in .cpp
TheNormalnij Oct 2, 2020
ed1057e
Fix crash when resource stopped.
TheNormalnij Oct 12, 2020
4763304
Merge branch 'master' into new_objects_allocating
TheNormalnij Oct 30, 2020
9637767
Fix build
TheNormalnij Oct 30, 2020
477be31
Fix missing model type in IsValidObject
TheNormalnij Oct 30, 2020
13dca7f
Add CModelInfoSA::CopyStreamingInfoFromModel function
TheNormalnij Oct 31, 2020
2d43105
Used proper types for CStreamingInfo struct
TheNormalnij Nov 1, 2020
97c892f
Fix formating
TheNormalnij Nov 1, 2020
81f2bbf
Used clang formatting
TheNormalnij Nov 1, 2020
0297ae7
Merge remote-tracking branch 'origin/new_objects_allocating' into new…
TheNormalnij Nov 1, 2020
e1089c2
Used another types for CStreamingInfo
TheNormalnij Nov 1, 2020
d026fbe
Update Client/mods/deathmatch/logic/CClientObjectManager.h
TheNormalnij Nov 1, 2020
881da14
Fix "Streamig" typo
TheNormalnij Nov 1, 2020
2ddf187
Merge remote-tracking branch 'origin/new_objects_allocating' into new…
TheNormalnij Nov 1, 2020
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
51 changes: 42 additions & 9 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,12 @@ bool CModelInfoSA::IsValid()
{
if (m_dwModelID >= 20000 && m_dwModelID < MODELINFO_MAX)
return true;
return ppModelInfo[m_dwModelID] != 0;

if (!ppModelInfo[m_dwModelID])
return false;

auto sizeInBlocks = pGame->GetStreaming()->GetStreamingInfoFromModelId(m_dwModelID)->sizeInBlocks;
return sizeInBlocks > 0;
}

float CModelInfoSA::GetDistanceFromCentreOfMassToBaseOfModel()
Expand Down Expand Up @@ -571,7 +576,7 @@ bool CModelInfoSA::SetTime(char cHourOn, char cHourOff)
if (!m_pInterface)
return false;

if (GetModelType() != MODEL_INFO_TYPE_TIME)
if (GetModelType() != eModelInfoType::TIME)
return false;

CTimeInfoSAInterface* pTime = &static_cast<CTimeModelInfoSAInterface*>(m_pInterface)->timeInfo;
Expand All @@ -590,7 +595,7 @@ bool CModelInfoSA::GetTime(char& cHourOn, char& cHourOff)
if (!m_pInterface)
return false;

if (GetModelType() != MODEL_INFO_TYPE_TIME)
if (GetModelType() != eModelInfoType::TIME)
return false;

CTimeInfoSAInterface* pTime = &static_cast<CTimeModelInfoSAInterface*>(m_pInterface)->timeInfo;
Expand Down Expand Up @@ -1166,15 +1171,15 @@ void CModelInfoSA::SetCustomModel(RpClump* pClump)
{
switch (GetModelType())
{
case MODEL_INFO_TYPE_PED:
case eModelInfoType::PED:
return pGame->GetRenderWare()->ReplacePedModel(pClump, static_cast<unsigned short>(m_dwModelID));
case MODEL_INFO_TYPE_WEAPON:
case eModelInfoType::WEAPON:
return pGame->GetRenderWare()->ReplaceWeaponModel(pClump, static_cast<unsigned short>(m_dwModelID));
case MODEL_INFO_TYPE_VEHICLE:
case eModelInfoType::VEHICLE:
return pGame->GetRenderWare()->ReplaceVehicleModel(pClump, static_cast<unsigned short>(m_dwModelID));
case MODEL_INFO_TYPE_ATOMIC:
case MODEL_INFO_TYPE_LOD_ATOMIC:
case MODEL_INFO_TYPE_TIME:
case eModelInfoType::ATOMIC:
case eModelInfoType::LOD_ATOMIC:
case eModelInfoType::TIME:
return pGame->GetRenderWare()->ReplaceAllAtomicsInModel(pClump, static_cast<unsigned short>(m_dwModelID));
}
}
Expand Down Expand Up @@ -1365,6 +1370,17 @@ void CModelInfoSA::SetVoice(const char* szVoiceType, const char* szVoice)
SetVoice(sVoiceType, sVoiceID);
}

void CModelInfoSA::CopyStreamingInfoFromModel(ushort usBaseModelID)
{
CStreamingInfo* pBaseModelStreamingInfo = pGame->GetStreaming()->GetStreamingInfoFromModelId(usBaseModelID);
CStreamingInfo* pTargetModelStreamingInfo = pGame->GetStreaming()->GetStreamingInfoFromModelId(m_dwModelID);

pTargetModelStreamingInfo->Reset();
pTargetModelStreamingInfo->archiveId = pBaseModelStreamingInfo->archiveId;
pTargetModelStreamingInfo->offsetInBlocks = pBaseModelStreamingInfo->offsetInBlocks;
pTargetModelStreamingInfo->sizeInBlocks = pBaseModelStreamingInfo->sizeInBlocks;
}

void CModelInfoSA::MakePedModel(char* szTexture)
{
// Create a new CPedModelInfo
Expand All @@ -1375,10 +1391,27 @@ void CModelInfoSA::MakePedModel(char* szTexture)
pGame->GetStreaming()->RequestSpecialModel(m_dwModelID, szTexture, 0);
}

void CModelInfoSA::MakeObjectModel(ushort usBaseID)
{
CBaseModelInfoSAInterface* m_pInterface = new CBaseModelInfoSAInterface();

CBaseModelInfoSAInterface* pBaseObjectInfo = ppModelInfo[usBaseID];
MemCpyFast(m_pInterface, pBaseObjectInfo, sizeof(CBaseModelInfoSAInterface));
m_pInterface->usNumberOfRefs = 0;
m_pInterface->pRwObject = nullptr;
m_pInterface->usUnknown = 65535;
m_pInterface->usDynamicIndex = 65535;

ppModelInfo[m_dwModelID] = m_pInterface;

CopyStreamingInfoFromModel(usBaseID);
}

void CModelInfoSA::DeallocateModel(void)
{
Remove();
ppModelInfo[m_dwModelID] = nullptr;
pGame->GetStreaming()->GetStreamingInfoFromModelId(m_dwModelID)->Reset();
}
//////////////////////////////////////////////////////////////////////////////////////////
//
Expand Down
13 changes: 2 additions & 11 deletions Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,6 @@ class CVehicleModelInfoSAInterface : public CBaseModelInfoSAInterface
CVehicleModelVisualInfoSAInterface* pVisualInfo; // +92
};

enum eModelInfoType : unsigned char
{
MODEL_INFO_TYPE_ATOMIC = 1,
MODEL_INFO_TYPE_TIME = 3,
MODEL_INFO_TYPE_WEAPON = 4,
MODEL_INFO_TYPE_CLUMP = 5,
MODEL_INFO_TYPE_VEHICLE = 6,
MODEL_INFO_TYPE_PED = 7,
MODEL_INFO_TYPE_LOD_ATOMIC = 8,
};

/**
* \todo Someone move GetLevelFromPosition out of here or delete it entirely please
*/
Expand Down Expand Up @@ -396,7 +385,9 @@ class CModelInfoSA : public CModelInfo
RwObject* GetRwObject() { return m_pInterface ? m_pInterface->pRwObject : NULL; }

// CModelInfoSA methods
void CopyStreamingInfoFromModel(ushort usBaseModelID);
void MakePedModel(char* szTexture);
void MakeObjectModel(ushort usBaseModelID);
void DeallocateModel(void);

SVehicleSupportedUpgrades GetVehicleSupportedUpgrades() { return m_ModelSupportedUpgrades; }
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CRenderWareSA.TextureReplacing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ CModelTexturesInfo* CRenderWareSA::GetModelTexturesInfo(ushort usModelId)
else
{
CTxdStore_AddRef(usTxdId);
if (pModelInfo->GetModelType() == MODEL_INFO_TYPE_PED)
if (pModelInfo->GetModelType() == eModelInfoType::PED)
{
// Mystery fix for #9336: (MTA sometimes fails at loading custom textures)
// Possibly forces the ped model to be reloaded in some way
Expand Down
7 changes: 7 additions & 0 deletions Client/game_sa/CStreamingSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "StdInc.h"

CStreamingInfo (&CStreamingSA::ms_aInfoForModel)[26316] = *(CStreamingInfo(*)[26316])0x8E4CC0;

namespace
{
//
Expand Down Expand Up @@ -135,6 +137,11 @@ void CStreamingSA::RequestSpecialModel(DWORD model, const char* szTexture, DWORD
}
}

CStreamingInfo* CStreamingSA::GetStreamingInfoFromModelId(ushort id)
{
return &ms_aInfoForModel[id];
}

void CStreamingSA::ReinitStreaming()
{
typedef int(__cdecl * Function_ReInitStreaming)();
Expand Down
3 changes: 3 additions & 0 deletions Client/game_sa/CStreamingSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ class CStreamingSA : public CStreaming
BOOL HasModelLoaded(DWORD dwModelID);
void RequestSpecialModel(DWORD model, const char* szTexture, DWORD channel);
void ReinitStreaming();
CStreamingInfo* GetStreamingInfoFromModelId(ushort id);
private:
static CStreamingInfo (&ms_aInfoForModel)[26316];
};
53 changes: 44 additions & 9 deletions Client/mods/deathmatch/logic/CClientModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ bool CClientModel::Allocate(void)
// Allocate only on free IDs
if (!pModelInfo->IsValid())
{
pModelInfo->MakePedModel("PSYCHO");
switch (m_eModelType)
{
case eClientModelType::PED:
pModelInfo->MakePedModel("PSYCHO");
break;
case eClientModelType::OBJECT:
pModelInfo->MakeObjectModel(1337);
break;
default:
return false;
}
return true;
}
return false;
Expand All @@ -53,20 +63,45 @@ bool CClientModel::Deallocate(void)
// ModelInfo must be valid
if (pModelInfo->IsValid())
{
if (m_eModelType == CCLIENTMODELPED)
if (m_eModelType == eClientModelType::PED)
{
// If some ped is using this ID, change him to CJ
CClientPedManager* pPedManager = g_pClientGame->GetManager()->GetPedManager();
std::vector<CClientPed*>::const_iterator iter = pPedManager->IterBegin();
for (; iter != pPedManager->IterEnd(); iter++)
for (auto iter = pPedManager->IterBegin(); iter != pPedManager->IterEnd(); iter++)
{
CClientPed* pPed = *iter;
if (pPed->GetModel() == m_iModelID)
{
if (pPed->IsStreamedIn())
{
pPed->StreamOutForABit();
}
pPed->SetModel(0);

CLuaArguments Arguments;
Arguments.PushNumber(m_iModelID);
Arguments.PushNumber(0);
pPed->CallEvent("onClientElementModelChange", Arguments, true);
}
}
}
else if (m_eModelType == eClientModelType::OBJECT)
{
CClientObjectManager* pObjectManager = g_pClientGame->GetManager()->GetObjectManager();
for (auto* pObject : pObjectManager->GetObjects())
{
if ((*iter)->GetModel() == m_iModelID)
if (pObject->GetModel() == m_iModelID)
{
if ((*iter)->IsStreamedIn())
if (pObject->IsStreamedIn())
{
(*iter)->StreamOutForABit();
pObject->StreamOutForABit();
}
(*iter)->SetModel(0);
pObject->SetModel(1337);

CLuaArguments Arguments;
Arguments.PushNumber(m_iModelID);
Arguments.PushNumber(1337);
pObject->CallEvent("onClientElementModelChange", Arguments, true);
}
}
}
Expand All @@ -75,7 +110,7 @@ bool CClientModel::Deallocate(void)
g_pClientGame->GetManager()->GetDFFManager()->RestoreModel(m_iModelID);

// Restore COL (for non ped models)
if (m_eModelType != CCLIENTMODELPED)
if (m_eModelType != eClientModelType::PED)
{
g_pClientGame->GetManager()->GetColModelManager()->RestoreModel(m_iModelID);
}
Expand Down
5 changes: 3 additions & 2 deletions Client/mods/deathmatch/logic/CClientModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ class CClientModel;
#include <list>
#include "CClientModelManager.h"

enum eClientModelType
enum class eClientModelType
{
CCLIENTMODELPED
PED,
OBJECT,
};

class CClientModel
Expand Down
72 changes: 7 additions & 65 deletions Client/mods/deathmatch/logic/CClientObjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,6 @@

#include "StdInc.h"

// Generated by MTA10\utils\gentable\gentable_objmodels.cpp
// (Currently excludes peds (below 300) and vehicles)
static const int g_iValidObjectModels[] = {
2, 0, 0, 0, 0, 0, 0, 0, 0, -4096, -1053185, 4194303, 16127, 0,
0, 0, 0, 0, 0, -128, -515899393, -134217729, -1, -1, 33554431, -1, -1, -1,
-14337, -1, -1, -129, -1, 1073741823, -1, -1, -1, -8387585, -1, -1, -1, -1,
-1, -2146435649, -1, -1, -1, -1, -1, -1, -1, -1, -1, -9, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -25, -1, -1, -1, -1, -1, -1, -16385,
-1, 34080767, 2113536, -4825600, -5, -1, -3145729, -1, -16777217, -33, -1, -1, -1, -131,
-201326593, -1, -1, -1, -1, -1, -1, -1, 1073741823, -133121, -1, -1, -65, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 1073741823, -64, -1, -1, -1, -1, -1, 134217727, 0, -64, -1, -1, -1,
-1, -1, -1, -1, -536870913, -131069, -1, -1, -1, -1, -1, -1, -1, -1,
-16384, -1, -1, -1, -1, -1, -1, -1, -1, 524287, -128, -1, -1, -1,
-1, -1, -1, -1, -1, 134217727, -524288, -1, -1, -1, -1, -1, -1, 245759,
-256, -1, -4097, -1, -1, -1, -1, 1073741823, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, -32768, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -8388607, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -961, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -2096129, -1, -1, -1, -1, -1, -1,
-1, -1, -897, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1921, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1040187393,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -201326593, -1, -1, -1, -1, -1, -1, -1,
-1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 268435455, -4194304, -1, -1, -241, -1, -1, -1, -1, -1, -1,
7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, -32768, -1, -1, -1, -1, -671088643, -1, -1, -66060289, -13, -1793, -32257, -245761,
-1, -1, -513, 16252911, 0, 0, 0, -131072, 33554431, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -3585, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 8388607, 0, 0, 0, 0, 0, 0, -256,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-268435449, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 92274687, -65536, -2097153, -1, 595591167, 1, 0, -16777216, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 127, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};

// Breakable model list
// Generated by:
// 1. Extracting model names from object.dat which have a 'Collision Damage Effect' greater than 0
Expand Down Expand Up @@ -142,23 +92,15 @@ CClientObject* CClientObjectManager::Get(ElementID ID)

bool CClientObjectManager::IsValidModel(unsigned long ulObjectModel)
{
bool bIsValid = false;

if (ulObjectModel < 20001)
{
unsigned int uiChunk = ulObjectModel / (sizeof(unsigned int) * 8);
unsigned int shift = ulObjectModel - (uiChunk * sizeof(unsigned int) * 8);
unsigned int bit = 1 << shift;
bIsValid = !!(g_iValidObjectModels[uiChunk] & bit);
if (ulObjectModel >= 20000)
return false;

// Return whether we can grab the model information or not
if (bIsValid && !g_pGame->GetModelInfo(ulObjectModel))
{
bIsValid = false;
}
}
CModelInfo* pModelInfo = g_pGame->GetModelInfo(ulObjectModel);
if (!pModelInfo || !pModelInfo->GetInterface())
return false;

return bIsValid;
eModelInfoType eType = pModelInfo->GetModelType();
return (eType == eModelInfoType::CLUMP || eType == eModelInfoType::ATOMIC || eType == eModelInfoType::WEAPON || eType == eModelInfoType::TIME);
}

bool CClientObjectManager::IsBreakableModel(unsigned long ulObjectModel)
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CClientObjectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CClientObjectManager

void DeleteAll();

const CMappedArray<CClientObject*>& GetObjects() const { return m_Objects; };
unsigned int Count() { return static_cast<unsigned int>(m_Objects.size()); };
unsigned int CountCreatedObjects() { return static_cast<unsigned int>(g_pGame->GetPools()->GetObjectCount()); };
static CClientObject* Get(ElementID ID);
Expand Down
9 changes: 6 additions & 3 deletions Client/mods/deathmatch/logic/CResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ CResource::CResource(unsigned short usNetID, const char* szResourceName, CClient

CResource::~CResource()
{
// Deallocate all models that this resource allocated earlier
g_pClientGame->GetManager()->GetModelManager()->DeallocateModelsAllocatedByResource(this);

// Delete all the resource's locally created children (the server won't do that)
DeleteClientChildren();

CIdArray::PushUniqueId(this, EIdClass::RESOURCE, m_uiScriptID);
// Make sure we don't force the cursor on
ShowCursor(false);
Expand Down Expand Up @@ -121,9 +127,6 @@ CResource::~CResource()
g_pClientGame->GetElementDeleter()->DeleteRecursive(m_pResourceGUIEntity);
m_pResourceGUIEntity = NULL;

// Deallocate all models that this resource allocated earlier
g_pClientGame->GetManager()->GetModelManager()->DeallocateModelsAllocatedByResource(this);

// Undo all changes to water
g_pGame->GetWaterManager()->UndoChanges(this);

Expand Down
3 changes: 0 additions & 3 deletions Client/mods/deathmatch/logic/CResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ void CResourceManager::Remove(CResource* pResource)
// Triggger the onStop event, and set resource state to 'stopping'
pResource->Stop();

// Delete all the resource's locally created children (the server won't do that)
pResource->DeleteClientChildren();

// Delete the resource
m_resources.remove(pResource);
assert(MapContains(m_NetIdResourceMap, pResource->GetNetID()));
Expand Down
Loading