Skip to content

Commit

Permalink
Merge branch 'master' into 230924_Add_C++20_Deathmatch
Browse files Browse the repository at this point in the history
  • Loading branch information
TracerDS authored Dec 14, 2024
2 parents 5dd42f5 + 12c8097 commit bb2b4b9
Show file tree
Hide file tree
Showing 23 changed files with 285 additions and 144 deletions.
12 changes: 11 additions & 1 deletion Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1
if (!HasFreeBuildingSlot())
return nullptr;

auto modelInfo = pGame->GetModelInfo(modelId);

// Change the properties group to force dynamic models to be created as buildings instead of dummies
auto prevGroup = modelInfo->GetObjectPropertiesGroup();
if (prevGroup != MODEL_PROPERTIES_GROUP_STATIC)
modelInfo->SetObjectPropertiesGroup(MODEL_PROPERTIES_GROUP_STATIC);

// Load building
SFileObjectInstance instance;
instance.modelID = modelId;
Expand All @@ -70,9 +77,12 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1
pBuilding->m_pLod = nullptr;
pBuilding->m_iplIndex = 0;

// Restore changed properties group
if (prevGroup != MODEL_PROPERTIES_GROUP_STATIC)
modelInfo->SetObjectPropertiesGroup(prevGroup);

// Always stream model collosion
// TODO We can setup collison bounding box and use GTA streamer for it
auto modelInfo = pGame->GetModelInfo(modelId);
modelInfo->AddColRef();

// Add building in world
Expand Down
93 changes: 56 additions & 37 deletions Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <game/Common.h>
#include <game/CModelInfo.h>
#include "CRenderWareSA.h"
#include "game/RenderWare.h"

class CPedModelInfoSA;
class CPedModelInfoSAInterface;
Expand Down Expand Up @@ -231,6 +232,11 @@ class CBaseModelInfoSAInterface
// +726 = Word array as referenced in CVehicleModelInfo::GetVehicleUpgrade(int)
// +762 = Array of WORD containing something relative to paintjobs
// +772 = Anim file index

void Shutdown()
{
((void(*)())VFTBL->Shutdown)();
}
};
static_assert(sizeof(CBaseModelInfoSAInterface) == 0x20, "Invalid size for CBaseModelInfoSAInterface");

Expand Down Expand Up @@ -259,53 +265,66 @@ class CTimeModelInfoSAInterface : public CBaseModelInfoSAInterface
CTimeInfoSAInterface timeInfo;
};

class CVehicleModelUpgradePosnDesc
{
CVector m_vPosition;
RtQuat m_vRotation;
int m_iParentId;
};

class CVehicleModelVisualInfoSAInterface // Not sure about this name. If somebody knows more, please change
{
public:
CVector vecDummies[15];
char m_sUpgrade[18];
CVector vecDummies[15];
CVehicleModelUpgradePosnDesc m_sUpgrade[18];
RpAtomic* m_pExtra[6];
std::uint8_t m_numExtras;
std::uint8_t _pad[3];
int m_maskComponentDamagable;
};

class CVehicleModelInfoSAInterface : public CBaseModelInfoSAInterface
class CVehicleModelInfoSAInterface : public CClumpModelInfoSAInterface
{
public:
uint32 pad1; // +32
RpMaterial* pPlateMaterial; // +36
RpMaterial* pPlateMaterial;
char plateText[8];
char pad[2];
std::uint8_t field_30;
std::uint8_t plateType;
char gameName[8];
char pad2[2];
unsigned int uiVehicleType;
std::uint8_t field_3A[2];
std::uint32_t vehicleType;
float fWheelSizeFront;
float fWheelSizeRear;
short sWheelModel;
short sHandlingID;
byte ucNumDoors;
byte ucVehicleList;
byte ucVehicleFlags;
byte ucWheelUpgradeClass;
byte ucTimesUsed;
short sVehFrequency;
unsigned int uiComponentRules;
float fSteeringAngle;
CVehicleModelVisualInfoSAInterface* pVisualInfo; // +92
char pad3[464];
char pDirtMaterial[64]; // *RwMaterial
char pad4[64];
char primColors[8];
char secondColors[8];
char treeColors[8];
char fourColors[8];
unsigned char ucNumOfColorVariations;
unsigned char ucLastColorVariation;
unsigned char ucPrimColor;
unsigned char ucSecColor;
unsigned char ucTertColor;
unsigned char ucQuatColor;
char upgrades[36];
char anRemapTXDs[8];
char pad5[2];
char pAnimBlock[4];
std::int16_t wheelModelID;
std::int16_t handlingID;
std::uint8_t numDoors;
std::uint8_t vehicleClass;
std::uint8_t vehicleFlags;
std::uint8_t wheelUpgradeClass;
std::uint8_t timesUsed;
std::uint8_t field_51;
std::int16_t vehFrequency;
std::uint32_t componentRules;
float bikeSteeringAngle;
CVehicleModelVisualInfoSAInterface* pVisualInfo; // vehicleStruct
std::uint8_t field_60[464];
RpMaterial** m_dirtMaterials;
std::size_t m_numDirtMaterials;
RpMaterial* m_staticDirtMaterials[30];
std::uint8_t primColors[8];
std::uint8_t secondColors[8];
std::uint8_t treeColors[8];
std::uint8_t fourColors[8];
std::uint8_t numOfColorVariations;
std::uint8_t lastColorVariation;
std::uint8_t primColor;
std::uint8_t secColor;
std::uint8_t tertColor;
std::uint8_t quatColor;
std::uint8_t upgrades[36];
std::uint8_t anRemapTXDs[8];
std::uint8_t field_302[2];
void* pAnimBlock; // CAnimBlock*
};

class CModelInfoSA : public CModelInfo
Expand Down Expand Up @@ -466,7 +485,7 @@ class CModelInfoSA : public CModelInfo
// Vehicle towing functions
bool IsTowableBy(CModelInfo* towingModel) override;

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

private:
void CopyStreamingInfoFromModel(ushort usCopyFromModelID);
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CPlayerPedSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CPlayerInfoSA.h"
#include "CPlayerPedSA.h"
#include "CWorldSA.h"
#include "CProjectileInfoSA.h"

extern CCoreInterface* g_pCore;
extern CGameSA* pGame;
Expand Down Expand Up @@ -137,6 +138,7 @@ CPlayerPedSA::~CPlayerPedSA()
if ((DWORD)GetInterface()->vtbl != VTBL_CPlaceable)
{
CWorldSA* world = (CWorldSA*)pGame->GetWorld();
pGame->GetProjectileInfo()->RemoveEntityReferences(this);
world->Remove(m_pInterface, CPlayerPed_Destructor);

DWORD dwThis = (DWORD)m_pInterface;
Expand Down
15 changes: 15 additions & 0 deletions Client/game_sa/CProjectileInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,18 @@ DWORD CProjectileInfoSA::GetCounter()
{
return internalInterface->dwCounter - pGame->GetSystemTime();
}

void CProjectileInfoSA::RemoveEntityReferences(CEntity* entity)
{
const CEntitySAInterface* entityInterface = entity->GetInterface();
for (int i = 0; i < PROJECTILE_INFO_COUNT; i++)
{
auto projectileInterface = projectileInfo[i]->internalInterface;

if (projectileInterface->pEntProjectileOwner == entityInterface)
projectileInterface->pEntProjectileOwner = nullptr;

if (projectileInterface->pEntProjectileTarget == entityInterface)
projectileInterface->pEntProjectileTarget = nullptr;
}
}
4 changes: 3 additions & 1 deletion Client/game_sa/CProjectileInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class CProjectileInfoSAInterface
};
// #pragma pack(pop)

class CProjectileInfoSA : public CProjectileInfo
// TODO extract manager class
class CProjectileInfoSA final : public CProjectileInfo
{
private:
CProjectileInfoSA* projectileInfo[PROJECTILE_INFO_COUNT];
Expand All @@ -65,6 +66,7 @@ class CProjectileInfoSA : public CProjectileInfo
CProjectileInfo* GetProjectileInfo(DWORD dwIndex);
bool AddProjectile(CEntity* creator, eWeaponType eWeapon, CVector vecOrigin, float fForce, CVector* target, CEntity* targetEntity);
CProjectile* GetProjectile(void* projectilePointer);
void RemoveEntityReferences(CEntity* entity);

CEntity* GetTarget();
void SetTarget(CEntity* pEntity);
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ CVehicleSA::~CVehicleSA()
}

CWorldSA* pWorld = (CWorldSA*)pGame->GetWorld();
pGame->GetProjectileInfo()->RemoveEntityReferences(this);
pWorld->Remove(m_pInterface, CVehicle_Destructor);
pWorld->RemoveReferencesToDeletedObject(m_pInterface);

Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/gamesa_renderware.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ typedef RpHAnimHierarchy*(__cdecl* GetAnimHierarchyFromSkinClump_t)(RpClump*);
typedef int(__cdecl* RpHAnimIDGetIndex_t)(RpHAnimHierarchy*, int);
typedef RwMatrix*(__cdecl* RpHAnimHierarchyGetMatrixArray_t)(RpHAnimHierarchy*);
typedef RtQuat*(__cdecl* RtQuatRotate_t)(RtQuat* quat, const RwV3d* axis, float angle, RwOpCombineType combineOp);
typedef RpGeometry*(__cdecl* RpGeometryForAllMaterials_t)(RpGeometry* geom, void* callback, void* data);

/*****************************************************************************/
/** Renderware function mappings **/
Expand Down Expand Up @@ -195,6 +196,7 @@ RWFUNC(GetAnimHierarchyFromSkinClump_t GetAnimHierarchyFromSkinClump, (GetAnimHi
RWFUNC(RpHAnimIDGetIndex_t RpHAnimIDGetIndex, (RpHAnimIDGetIndex_t)0xDEAD)
RWFUNC(RpHAnimHierarchyGetMatrixArray_t RpHAnimHierarchyGetMatrixArray, (RpHAnimHierarchyGetMatrixArray_t)0xDEAD)
RWFUNC(RtQuatRotate_t RtQuatRotate, (RtQuatRotate_t)0xDEAD)
RWFUNC(RpGeometryForAllMaterials_t RpGeometryForAllMaterials, (RpGeometryForAllMaterials_t)0xDEAD)

/*****************************************************************************/
/** GTA function definitions and mappings **/
Expand Down
3 changes: 2 additions & 1 deletion Client/game_sa/gamesa_renderware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ void InitRwFunctions()
RpHAnimIDGetIndex = (RpHAnimIDGetIndex_t)0x7C51A0;
RpHAnimHierarchyGetMatrixArray = (RpHAnimHierarchyGetMatrixArray_t)0x7C5120;
RtQuatRotate = (RtQuatRotate_t)0x7EB7C0;

RpGeometryForAllMaterials = (RpGeometryForAllMaterials_t)0x74C790;

SetTextureDict = (SetTextureDict_t)0x007319C0;
LoadClumpFile = (LoadClumpFile_t)0x005371F0;
LoadModel = (LoadModel_t)0x0040C6B0;
Expand Down
27 changes: 1 addition & 26 deletions Client/mods/deathmatch/logic/CClientBuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ bool CClientBuildingManager::IsValidModel(uint16_t modelId)
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);
}
Expand Down Expand Up @@ -106,29 +101,9 @@ void CClientBuildingManager::RestoreDestroyed()
{
const CClientBuilding* highLodBuilding = building->GetHighLodBuilding();
if (highLodBuilding && !highLodBuilding->IsValid())
{
hasInvalidLods = true;
}
else
{
CModelInfo* modelInfo = building->GetModelInfo();
const uint16_t physicalGroup = modelInfo->GetObjectPropertiesGroup();

if (physicalGroup == -1)
{
building->Create();
}
else
{
// GTA creates dynamic models as dummies.
// It's possible that the physical group was changes after
// creating a new building. We can avoid crashes in this case.
modelInfo->SetObjectPropertiesGroup(-1);
building->Create();
modelInfo->SetObjectPropertiesGroup(physicalGroup);
}

}
building->Create();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientGUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void CClientGUIManager::DeleteAll()

bool CClientGUIManager::Exists(CClientGUIElement* pGUIElement)
{
return m_Elements.Contains(pGUIElement);
return pGUIElement ? m_Elements.Contains(pGUIElement) : false;
}

bool CClientGUIManager::Exists(CGUIElement* pCGUIElement)
Expand Down
5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <game/Task.h>
#include <game/CBuildingRemoval.h>
#include "game/CClock.h"
#include <game/CProjectileInfo.h>
#include <windowsx.h>
#include "CServerInfo.h"

Expand Down Expand Up @@ -403,6 +404,10 @@ CClientGame::CClientGame(bool bLocalPlay) : m_ServerInfo(new CServerInfo())
CClientGame::~CClientGame()
{
m_bBeingDeleted = true;
// Remove active projectile references to local player
if (auto pLocalPlayer = g_pClientGame->GetLocalPlayer())
g_pGame->GetProjectileInfo()->RemoveEntityReferences(pLocalPlayer->GetGameEntity());

// Stop all explosions. Unfortunately this doesn't fix the crash
// if a vehicle is destroyed while it explodes.
g_pGame->GetExplosionManager()->RemoveAllExplosions();
Expand Down
Loading

0 comments on commit bb2b4b9

Please sign in to comment.