Skip to content

Commit

Permalink
Add damageable objects support
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Oct 13, 2024
1 parent 550a152 commit 3eee671
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 1 deletion.
33 changes: 32 additions & 1 deletion Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,24 @@ void CModelInfoSA::MakeObjectModel(ushort usBaseID)
CopyStreamingInfoFromModel(usBaseID);
}

void CModelInfoSA::MakeObjectDamagableModel(std::uint16_t baseModel)
{
CDamageableModelInfoSAInterface* m_pInterface = new CDamageableModelInfoSAInterface();

CDamageableModelInfoSAInterface* pBaseObjectInfo = static_cast<CDamageableModelInfoSAInterface*>(ppModelInfo[baseModel]);
MemCpyFast(m_pInterface, pBaseObjectInfo, sizeof(CDamageableModelInfoSAInterface));
m_pInterface->usNumberOfRefs = 0;
m_pInterface->pRwObject = nullptr;
m_pInterface->usUnknown = 65535;
m_pInterface->usDynamicIndex = 65535;
m_pInterface->m_damagedAtomic = nullptr;

ppModelInfo[m_dwModelID] = m_pInterface;

m_dwParentID = baseModel;
CopyStreamingInfoFromModel(baseModel);
}

void CModelInfoSA::MakeTimedObjectModel(ushort usBaseID)
{
CTimeModelInfoSAInterface* m_pInterface = new CTimeModelInfoSAInterface();
Expand Down Expand Up @@ -1809,7 +1827,14 @@ void CModelInfoSA::DeallocateModel(void)
delete reinterpret_cast<CPedModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
break;
case eModelInfoType::ATOMIC:
delete reinterpret_cast<CBaseModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
if (IsDamageableAtomic())
{
delete reinterpret_cast<CDamageableModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
}
else
{
delete reinterpret_cast<CBaseModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
}
break;
case eModelInfoType::CLUMP:
delete reinterpret_cast<CClumpModelInfoSAInterface*>(ppModelInfo[m_dwModelID]);
Expand Down Expand Up @@ -2064,6 +2089,12 @@ bool CModelInfoSA::IsTowableBy(CModelInfo* towingModel)
return isTowable;
}

bool CModelInfoSA::IsDamageableAtomic()
{
void* asDamagable = ((void* (*)())m_pInterface->VFTBL->AsDamageAtomicModelInfoPtr)();
return asDamagable != nullptr;
}

//////////////////////////////////////////////////////////////////////////////////////////
//
// CModelInfoSA::ForceUnload
Expand Down
8 changes: 8 additions & 0 deletions Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ class CTimeModelInfoSAInterface : public CBaseModelInfoSAInterface
CTimeInfoSAInterface timeInfo;
};

class CDamageableModelInfoSAInterface : public CBaseModelInfoSAInterface
{
public:
void* m_damagedAtomic;
};

class CVehicleModelVisualInfoSAInterface // Not sure about this name. If somebody knows more, please change
{
public:
Expand Down Expand Up @@ -447,6 +453,7 @@ class CModelInfoSA : public CModelInfo
// CModelInfoSA methods
void MakePedModel(char* szTexture);
void MakeObjectModel(ushort usBaseModelID);
void MakeObjectDamagableModel(std::uint16_t usBaseModelID) override;
void MakeVehicleAutomobile(ushort usBaseModelID);
void MakeTimedObjectModel(ushort usBaseModelID);
void MakeClumpModel(ushort usBaseModelID);
Expand All @@ -467,6 +474,7 @@ class CModelInfoSA : public CModelInfo
bool IsTowableBy(CModelInfo* towingModel) override;

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

private:
void CopyStreamingInfoFromModel(ushort usCopyFromModelID);
Expand Down
13 changes: 13 additions & 0 deletions Client/mods/deathmatch/logic/CClientModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ bool CClientModel::Allocate(ushort usParentID)
return true;
}
break;
case eClientModelType::OBJECT_DAMAGEABLE:
{
bool isValidModel = g_pClientGame->GetObjectManager()->IsValidModel(usParentID);
bool isDamagable = pParentModelInfo->IsDamageableAtomic();
if (isValidModel && isDamagable)
{
pModelInfo->MakeObjectDamagableModel(usParentID);
return true;
}
break;
}
case eClientModelType::CLUMP:
if (g_pClientGame->GetObjectManager()->IsValidModel(usParentID))
{
Expand Down Expand Up @@ -109,6 +120,7 @@ void CClientModel::RestoreEntitiesUsingThisModel()
{
case eClientModelType::PED:
case eClientModelType::OBJECT:
case eClientModelType::OBJECT_DAMAGEABLE:
case eClientModelType::CLUMP:
case eClientModelType::TIMED_OBJECT:
case eClientModelType::VEHICLE:
Expand Down Expand Up @@ -174,6 +186,7 @@ void CClientModel::RestoreDFF(CModelInfo* pModelInfo)
}
case eClientModelType::CLUMP:
case eClientModelType::OBJECT:
case eClientModelType::OBJECT_DAMAGEABLE:
case eClientModelType::TIMED_OBJECT:
{
const auto& objects = &g_pClientGame->GetManager()->GetObjectManager()->GetObjects();
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CClientModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class eClientModelType
{
PED,
OBJECT,
OBJECT_DAMAGEABLE,
VEHICLE,
TIMED_OBJECT,
CLUMP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ IMPLEMENT_ENUM_END("surface-adhesion-group")
IMPLEMENT_ENUM_CLASS_BEGIN(eClientModelType)
ADD_ENUM(eClientModelType::PED, "ped")
ADD_ENUM(eClientModelType::OBJECT, "object")
ADD_ENUM(eClientModelType::OBJECT_DAMAGEABLE, "object-damageable")
ADD_ENUM(eClientModelType::VEHICLE, "vehicle")
ADD_ENUM(eClientModelType::TIMED_OBJECT, "timed-object")
ADD_ENUM(eClientModelType::CLUMP, "clump")
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,9 @@ int CLuaEngineDefs::EngineRequestModel(lua_State* luaVM)
case eClientModelType::OBJECT:
usParentID = 1337; // BinNt07_LA (trash can)
break;
case eClientModelType::OBJECT_DAMAGEABLE:
usParentID = 994; // lhouse_barrier2
break;
case eClientModelType::VEHICLE:
usParentID = VT_LANDSTAL;
break;
Expand Down
2 changes: 2 additions & 0 deletions Client/sdk/game/CModelInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class CModelInfo
virtual RwObject* GetRwObject() = 0;
virtual void MakePedModel(char* szTexture) = 0;
virtual void MakeObjectModel(unsigned short usBaseID) = 0;
virtual void MakeObjectDamagableModel(std::uint16_t baseID) = 0;
virtual void MakeVehicleAutomobile(unsigned short usBaseID) = 0;
virtual void MakeTimedObjectModel(unsigned short usBaseID) = 0;
virtual void MakeClumpModel(unsigned short usBaseID) = 0;
Expand All @@ -249,4 +250,5 @@ class CModelInfo

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

0 comments on commit 3eee671

Please sign in to comment.