Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd committed Jun 19, 2024
2 parents 9c19509 + f5b599c commit 75c36ed
Show file tree
Hide file tree
Showing 113 changed files with 2,317 additions and 1,375 deletions.
5 changes: 3 additions & 2 deletions Client/cefweb/CWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,9 @@ bool CWebView::OnJSDialog(CefRefPtr<CefBrowser> browser, const CefString& origin
// //
// //
////////////////////////////////////////////////////////////////////
bool CWebView::OnFileDialog(CefRefPtr<CefBrowser> browser, CefDialogHandler::FileDialogMode mode, const CefString& title, const CefString& default_file_path,
const std::vector<CefString>& accept_filters, CefRefPtr<CefFileDialogCallback> callback)
bool CWebView::OnFileDialog(CefRefPtr<CefBrowser> browser, FileDialogMode mode, const CefString& title, const CefString& default_file_path,
const std::vector<CefString>& accept_filters, const std::vector<CefString>& accept_extensions, const std::vector<CefString>& accept_descriptions,
CefRefPtr<CefFileDialogCallback> callback)
{
// Don't show the dialog
return true;
Expand Down
5 changes: 3 additions & 2 deletions Client/cefweb/CWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ class CWebView : public CWebViewInterface,
bool& suppress_message) override;

// CefDialogHandler methods
virtual bool OnFileDialog(CefRefPtr<CefBrowser> browser, CefDialogHandler::FileDialogMode mode, const CefString& title, const CefString& default_file_path,
const std::vector<CefString>& accept_filters, CefRefPtr<CefFileDialogCallback> callback) override;
virtual bool OnFileDialog(CefRefPtr<CefBrowser> browser, FileDialogMode mode, const CefString& title, const CefString& default_file_path,
const std::vector<CefString>& accept_filters, const std::vector<CefString>& accept_extensions, const std::vector<CefString>& accept_descriptions,
CefRefPtr<CefFileDialogCallback> callback) override;

// CefDisplayHandler methods
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title) override;
Expand Down
719 changes: 719 additions & 0 deletions Client/game_sa/CBuildingRemovalSA.cpp

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions Client/game_sa/CBuildingRemovalSA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CBuildingRemovalSA.h
* PURPOSE: Header file for building removal class
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

#pragma once

#include <CVector.h>
#include <CVector2D.h>

#include <game/CBuildingRemoval.h>

class CBuildingRemovalSA : public CBuildingRemoval
{
public:
CBuildingRemovalSA();

SBuildingRemoval* GetBuildingRemoval(CEntitySAInterface* pInterface) override;

void RemoveBuilding(uint16_t usModelToRemove, float fDistance, float fX, float fY, float fZ, char cInterior, size_t* pOutAmount = NULL) override;
bool RestoreBuilding(uint16_t usModelToRestore, float fDistance, float fX, float fY, float fZ, char cInterior, size_t* pOutAmount = NULL) override;
bool IsRemovedModelInRadius(SIPLInst* pInst) override;
bool IsModelRemoved(uint16_t modelID) override;
void ClearRemovedBuildingLists(uint* pOutAmount = NULL) override;
void AddDataBuilding(CEntitySAInterface* pInterface) override;
void RemoveWorldBuildingFromLists(CEntitySAInterface* pInterface) override;
void AddBinaryBuilding(CEntitySAInterface* pInterface) override;
bool IsObjectRemoved(CEntitySAInterface* pInterface) override;
bool IsDataModelRemoved(uint16_t usModelID) override;
bool IsEntityRemoved(CEntitySAInterface* pInterface) override;
void DropCaches();

private:
std::multimap<uint16_t, SBuildingRemoval*>* m_pBuildingRemovals;
std::multimap<uint16_t, sDataBuildingRemovalItem*>* m_pDataBuildings;
std::multimap<uint16_t, sBuildingRemovalItem*>* m_pBinaryBuildings;
std::map<DWORD, bool> m_pRemovedEntities;
std::map<DWORD, bool> m_pAddedEntities;
};
19 changes: 11 additions & 8 deletions Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ inline bool CBuildingsPoolSA::AddBuildingToPool(CClientBuilding* pClientBuilding
if (dwElementIndexInPool == UINT_MAX)
return false;

m_buildingPool.arrayOfClientEntities[dwElementIndexInPool] = {pBuilding, (CClientEntity*)pClientBuilding};
m_buildingPool.entities[dwElementIndexInPool] = {pBuilding, (CClientEntity*)pClientBuilding};

// Increase the count of objects
++m_buildingPool.ulCount;
++m_buildingPool.count;

return true;
}
Expand Down Expand Up @@ -108,8 +108,8 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding)
modelInfo->RemoveColRef();

// Remove from BuildingSA pool
auto* pBuildingSA = m_buildingPool.arrayOfClientEntities[dwElementIndexInPool].pEntity;
m_buildingPool.arrayOfClientEntities[dwElementIndexInPool] = {nullptr, nullptr};
auto* pBuildingSA = m_buildingPool.entities[dwElementIndexInPool].pEntity;
m_buildingPool.entities[dwElementIndexInPool] = {nullptr, nullptr};

// Delete it from memory
delete pBuildingSA;
Expand All @@ -118,7 +118,7 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding)
(*m_ppBuildingPoolInterface)->Release(dwElementIndexInPool);

// Decrease the count of elements in the pool
--m_buildingPool.ulCount;
--m_buildingPool.count;
}

void CBuildingsPoolSA::RemoveAllBuildings()
Expand Down Expand Up @@ -191,7 +191,9 @@ void CBuildingsPoolSA::RemoveBuildingFromWorld(CBuildingSAInterface* pBuilding)
bool CBuildingsPoolSA::Resize(int size)
{
auto* pool = (*m_ppBuildingPoolInterface);
const int curretnSize = pool->m_nSize;
const int currentSize = pool->m_nSize;

m_buildingPool.entities.resize(size);

void* oldPool = pool->m_pObjects;

Expand All @@ -210,15 +212,15 @@ bool CBuildingsPoolSA::Resize(int size)
CBuildingSAInterface* newObjects = MemSA::malloc_struct<CBuildingSAInterface>(size);
if (newObjects == nullptr)
{
Resize(curretnSize);
Resize(currentSize);
return false;
}

tPoolObjectFlags* newBytemap = MemSA::malloc_struct<tPoolObjectFlags>(size);
if (newBytemap == nullptr)
{
MemSA::free(newObjects);
Resize(curretnSize);
Resize(currentSize);
return false;
}

Expand Down Expand Up @@ -322,6 +324,7 @@ void CBuildingsPoolSA::RemovePedsContactEnityLinks()
CPedSAInterface* ped = pedLinks->pEntity->GetPedInterface();
ped->m_pCollidedEntity = nullptr;
ped->pContactEntity = nullptr;
ped->pLastContactEntity = nullptr;
ped->pLastContactedEntity[0] = nullptr;
ped->pLastContactedEntity[1] = nullptr;
ped->pLastContactedEntity[2] = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions Client/game_sa/CBuildingsPoolSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class CBuildingsPoolSA : public CBuildingsPool
void RemovePedsContactEnityLinks();

private:
SPoolData<CBuildingSA, CBuildingSAInterface, MAX_BUILDINGS> m_buildingPool;
CPoolSAInterface<CBuildingSAInterface>** m_ppBuildingPoolInterface;
SVectorPoolData<CBuildingSA> m_buildingPool{MAX_BUILDINGS};
CPoolSAInterface<CBuildingSAInterface>** m_ppBuildingPoolInterface;

std::unique_ptr<std::array<std::pair<bool, CBuildingSAInterface>, MAX_BUILDINGS>> m_pOriginalBuildingsBackup;
};
90 changes: 90 additions & 0 deletions Client/game_sa/CFxSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,93 @@ void CFxSA::TriggerFootSplash(CVector& vecPosition)
call dwFunc
}
}

void CFxSA::AddParticle(eFxParticleSystems eFxParticle, const CVector& vecPosition, const CVector& vecDirection, float fR, float fG, float fB, float fA, bool bRandomizeColors, std::uint32_t iCount, float fBrightness, float fSize, bool bRandomizeSizes, float fLife)
{
// Init our own FxPrtMult struct
FxPrtMult_c fxPrt{{fR,fG,fB,fA}, fSize, 0, fLife};
CVector newDirection;

FxSystem_c* fxParticleSystem;

switch (eFxParticle)
{
case eFxParticleSystems::PRT_BLOOD:
fxParticleSystem = m_pInterface->m_fxSysBlood;
break;
case eFxParticleSystems::PRT_BOATSPLASH:
fxParticleSystem = m_pInterface->m_fxSysBoatSplash;
break;
case eFxParticleSystems::PRT_BUBBLE:
fxParticleSystem = m_pInterface->m_fxSysBubble;
break;
case eFxParticleSystems::PRT_DEBRIS:
fxParticleSystem = m_pInterface->m_fxSysDebris;
break;
case eFxParticleSystems::PRT_GUNSHELL:
fxParticleSystem = m_pInterface->m_fxSysGunshell;
break;
case eFxParticleSystems::PRT_SAND:
fxParticleSystem = m_pInterface->m_fxSysSand;
break;
case eFxParticleSystems::PRT_SAND2:
fxParticleSystem = m_pInterface->m_fxSysSand2;
break;
case eFxParticleSystems::PRT_SMOKE:
fxParticleSystem = m_pInterface->m_fxSysSmoke;
break;
case eFxParticleSystems::PRT_SMOKEHUGE:
fxParticleSystem = m_pInterface->m_fxSysSmokeHuge;
break;
case eFxParticleSystems::PRT_SMOKE2:
fxParticleSystem = m_pInterface->m_fxSysSmoke2;
break;
case eFxParticleSystems::PRT_SPARK:
fxParticleSystem = m_pInterface->m_fxSysSpark;
break;
case eFxParticleSystems::PRT_SPARK2:
fxParticleSystem = m_pInterface->m_fxSysSpark2;
break;
case eFxParticleSystems::PRT_SPLASH:
fxParticleSystem = m_pInterface->m_fxSysSplash;
break;
case eFxParticleSystems::PRT_WAKE:
fxParticleSystem = m_pInterface->m_fxSysWake;
break;
case eFxParticleSystems::PRT_WATERSPLASH:
fxParticleSystem = m_pInterface->m_fxSysWaterSplash;
break;
case eFxParticleSystems::PRT_WHEELDIRT:
fxParticleSystem = m_pInterface->m_fxSysWheelDirt;
break;
case eFxParticleSystems::PRT_GLASS:
fxParticleSystem = m_pInterface->m_fxSysGlass;
break;
default:
fxParticleSystem = m_pInterface->m_fxSysBlood;
}

for (size_t i = 0; i < iCount; i++)
{
if (bRandomizeColors)
{
// 0x49EECB
fxPrt.m_color.red = (rand() % 10000) * 0.0001f * fR + 0.13f;
fxPrt.m_color.green = (rand() % 10000) * 0.0001f * fG + 0.12f;
fxPrt.m_color.blue = (rand() % 10000) * 0.0001f * fB + 0.04f;
}

if (bRandomizeSizes)
// 0x49EF21 - Calculate random size for each particle
fxPrt.m_fSize = (rand() % 10000) * 0.0001f * fSize + 0.3f;

// 0x49EF4C - Calculate random direction for each particle
newDirection = CVector(vecDirection.fX * 4, vecDirection.fY * 4, vecDirection.fZ * 4);
newDirection.fX = (rand() % 10000) * 0.0001f * 4 - 2 + newDirection.fX;
newDirection.fY = (rand() % 10000) * 0.0001f * 4 - 2 + newDirection.fY;
newDirection.fZ = (rand() % 10000) * 0.0001f * 4 - 2 + newDirection.fZ;

// Call FxSystem_c::AddParticle
((int(__thiscall*)(FxSystem_c*, const CVector*, const CVector*, float, FxPrtMult_c*, float, float, float, int))FUNC_FXSystem_c_AddParticle)(fxParticleSystem, &vecPosition, &newDirection, 0, &fxPrt, -1.0f, fBrightness, 0, 0);
}
}
37 changes: 37 additions & 0 deletions Client/game_sa/CFxSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <game/CFx.h>

struct RwColor;
class FxSystem_c;

#define FUNC_CFx_AddBlood 0x49eb00
#define FUNC_CFx_AddWood 0x49ee10
Expand All @@ -29,10 +30,30 @@ struct RwColor;
#define FUNC_CFx_TriggerWaterSplash 0x4a1070
#define FUNC_CFx_TriggerBulletSplash 0x4a10e0
#define FUNC_CFx_TriggerFootSplash 0x4a1150
#define FUNC_FXSystem_c_AddParticle 0x4AA440

class CFxSAInterface
{
public:
FxSystem_c* m_fxSysBlood;
FxSystem_c* m_fxSysBoatSplash;
FxSystem_c* m_fxSysBubble;
FxSystem_c* m_fxSysDebris;
FxSystem_c* m_fxSysSmoke;
FxSystem_c* m_fxSysGunshell;
FxSystem_c* m_fxSysSand;
FxSystem_c* m_fxSysSand2;
FxSystem_c* m_fxSysSmokeHuge;
FxSystem_c* m_fxSysSmoke2;
FxSystem_c* m_fxSysSpark;
FxSystem_c* m_fxSysSpark2;
FxSystem_c* m_fxSysSplash;
FxSystem_c* m_fxSysWake;
FxSystem_c* m_fxSysWaterSplash;
FxSystem_c* m_fxSysWheelDirt;
FxSystem_c* m_fxSysGlass;

private:
};

class CFxSA : public CFx
Expand All @@ -55,7 +76,23 @@ class CFxSA : public CFx
void TriggerWaterSplash(CVector& vecPosition);
void TriggerBulletSplash(CVector& vecPosition);
void TriggerFootSplash(CVector& vecPosition);
void AddParticle(eFxParticleSystems eFxParticle, const CVector& vecPosition, const CVector& vecDirection, float fR, float fG, float fB, float fA, bool bRandomizeColors, std::uint32_t iCount, float fBrightness, float fSize, bool bRandomizeSizes, float fLife);

private:
CFxSAInterface* m_pInterface;

struct FxPrtMult_c
{
struct
{
float red;
float green;
float blue;
float alpha;
} m_color;

float m_fSize;
float unk;
float m_fLife;
};
};
4 changes: 4 additions & 0 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "CWorldSA.h"
#include "D3DResourceSystemSA.h"
#include "CIplStoreSA.h"
#include "CBuildingRemovalSA.h"

extern CGameSA* pGame;

Expand Down Expand Up @@ -141,6 +142,7 @@ CGameSA::CGameSA()
m_pIplStore = new CIplStoreSA();
m_pCoverManager = new CCoverManagerSA();
m_pPlantManager = new CPlantManagerSA();
m_pBuildingRemoval = new CBuildingRemovalSA();

// Normal weapon types (WEAPONSKILL_STD)
for (int i = 0; i < NUM_WeaponInfosStdSkill; i++)
Expand Down Expand Up @@ -278,6 +280,7 @@ CGameSA::~CGameSA()
delete reinterpret_cast<CPointLightsSA*>(m_pPointLights);
delete static_cast<CColStoreSA*>(m_collisionStore);
delete static_cast<CIplStore*>(m_pIplStore);
delete static_cast<CBuildingRemovalSA*>(m_pBuildingRemoval);
delete m_pCoverManager;
delete m_pPlantManager;

Expand Down Expand Up @@ -1003,6 +1006,7 @@ bool CGameSA::SetBuildingPoolSize(size_t size)
RemoveAllBuildings();
}

((CBuildingRemovalSA*)GetBuildingRemoval())->DropCaches();
bool status = m_pPools->GetBuildingsPool().Resize(size);

if (shouldRemoveBuilding)
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class CGameSA : public CGame
CIplStore* GetIplStore() { return m_pIplStore; };
CCoverManagerSA* GetCoverManager() const noexcept { return m_pCoverManager; };
CPlantManagerSA* GetPlantManager() const noexcept { return m_pPlantManager; };
CBuildingRemoval* GetBuildingRemoval() { return m_pBuildingRemoval; }

CWeaponInfo* GetWeaponInfo(eWeaponType weapon, eWeaponSkill skill = WEAPONSKILL_STD);
CModelInfo* GetModelInfo(DWORD dwModelID, bool bCanBeInvalid = false);
Expand Down Expand Up @@ -339,6 +340,7 @@ class CGameSA : public CGame
CObjectGroupPhysicalProperties* m_pObjectGroupPhysicalProperties;
CCoverManagerSA* m_pCoverManager;
CPlantManagerSA* m_pPlantManager;
CBuildingRemoval* m_pBuildingRemoval;

CPad* m_pPad;
CAERadioTrackManager* m_pCAERadioTrackManager;
Expand Down
6 changes: 1 addition & 5 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1992,11 +1992,7 @@ void CModelInfoSA::SetObjectPropertiesGroup(unsigned short usNewGroup)

unsigned short CModelInfoSA::GetObjectPropertiesGroup()
{
unsigned short usGroup = GetInterface()->usDynamicIndex;
if (usGroup == 0xFFFF)
usGroup = 0;

return usGroup;
return GetInterface()->usDynamicIndex;
}

void CModelInfoSA::RestoreObjectPropertiesGroup()
Expand Down
4 changes: 2 additions & 2 deletions Client/game_sa/CPedSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ class CPedSAInterface : public CPhysicalSAInterface // +1420 = curre
float fTargetRotation;
float fRotationSpeed;
float fMoveAnim;
CPedSAInterface* unkPed;
CEntitySAInterface* pContactEntity;
CVector unk_56C;
CVector unk_578;

CEntitySAInterface* pContactEntity;
CEntitySAInterface* pLastContactEntity;
CVehicleSAInterface* pLastVehicle;
CVehicleSAInterface* pVehicle;

Expand Down
13 changes: 13 additions & 0 deletions Client/game_sa/CPoolSAInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,16 @@ struct SPoolData
}
}
};

template <class T>
struct SVectorPoolData
{
std::vector<SClientEntity<T>> entities;
size_t count;

public:
SVectorPoolData(size_t defaultSize) : count(0)
{
entities.resize(defaultSize, {nullptr, nullptr});
}
};
Loading

0 comments on commit 75c36ed

Please sign in to comment.