Skip to content

Add possibility of modifying dynamic objects behavior #784

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d609a55
Merge remote-tracking branch 'multitheftauto/master'
Jan 10, 2019
c14fbdc
Merge remote-tracking branch 'multitheftauto/master'
Jan 11, 2019
2bc8a83
Merge remote-tracking branch 'multitheftauto/master'
Jan 13, 2019
177332c
Merge remote-tracking branch 'multitheftauto/master'
Jan 15, 2019
fc2c5a1
Basic implementation of required classes
Jan 16, 2019
4cfec48
Possibility to get object properties group from CModelInfo
Jan 16, 2019
1f4dd9e
Ability to change model id -> object properties group relations
Jan 16, 2019
26091b0
enum definition
Jan 16, 2019
e2f08f9
moved function to the end of CGame*, small cleanup
Jan 16, 2019
553724a
Fixed issues with not starting, a lot of changes
Jan 17, 2019
c7340b0
Basic functions, starting renaming
Jan 17, 2019
c616185
The giant renaming
Jan 17, 2019
4ffc705
model update
Jan 17, 2019
4c37121
model/naming changes, rest of setters from lua.
Jan 17, 2019
e8c2573
naming, code shortening thanks to botder
Jan 17, 2019
597ffa8
Enums cleanup, to their own namespace they go
Jan 17, 2019
d1be9dd
Added missing restore function, naming changes
Jan 18, 2019
626b468
enums namespace change
Jan 18, 2019
73d6ede
Ability to get properties from lua
Jan 18, 2019
837f198
enum memory layout issues fix
Jan 18, 2019
04454c4
Added ability to change fx system used by object group
Jan 19, 2019
1eea8fe
Additional safety checks in lua functions
Jan 19, 2019
99e46b9
Restore object data changes, refactored lua methods
Jan 19, 2019
232f896
adjust properties count to real 160, instead of 255,
Jan 19, 2019
6b4911b
Ability to restore default group properties from lua
Jan 19, 2019
5df9c3d
Enum class name change
Jan 20, 2019
9e0d668
Stuff i've noticed when making pull request
Jan 20, 2019
4af17e6
Moved stuff
Jan 20, 2019
45ee1d5
Formatting fix
Jan 20, 2019
abe4e5e
Merge latest master, resolve conflicts
Feb 23, 2019
72cf365
Clean up project comments
patrikjuvonen Feb 23, 2019
f0aa2bd
Changes recommended in code review
Feb 23, 2019
fbff885
Merge remote-tracking branch 'multitheftauto/master' into setModelGro…
Apr 14, 2019
9f56b4f
Changes suggested in pull request review
Apr 14, 2019
b352e3e
Merge branch 'master' into setModelGroupDynamicProperty
forkerer Sep 1, 2019
1ffcba2
Merge remote-tracking branch 'multitheftauto/master' into setModelGro…
forkerer Sep 2, 2019
fabc619
Change warnings to errors
forkerer Sep 2, 2019
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
12 changes: 12 additions & 0 deletions Client/game_sa/CFxManagerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ void CFxManagerSA::OnFxSystemSAInterfaceDestroyed(CFxSystemSAInterface* pFxSyste
delete pFxSystemSA;
}

CFxSystemBPSAInterface* CFxManagerSA::GetFxSystemBlueprintByName(SString sName)
{
using func_t = CFxSystemBPSAInterface*(__thiscall*)(CFxManagerSAInterface * pInterface, const char* pChars);
auto func = reinterpret_cast<func_t>(FUNC_FxManager_c__GetSystemByName);
return func(m_pInterface, sName);
}

bool CFxManagerSA::IsValidFxSystemBlueprintName(SString sName)
{
return GetFxSystemBlueprintByName(sName) != nullptr;
}

//
// AddToList/RemoveFromList called from CFxSystemSA constructor/destructor
//
Expand Down
11 changes: 7 additions & 4 deletions Client/game_sa/CFxManagerSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#define FUNC_FxManager_c__CreateFxSystem 0x4A9BE0
#define FUNC_FxManager_c__DestroyFxSystem 0x4A9810
#define FUNC_FxManager_c__GetSystemByName 0x4A9360

class CFxSystemBPSAInterface;
class CFxSystemSAInterface;
Expand Down Expand Up @@ -61,10 +62,12 @@ class CFxManagerSA : public CFxManager
public:
CFxManagerSA(CFxManagerSAInterface* pInterface) { m_pInterface = pInterface; }
// CFxManager interface
CFxSystem* CreateFxSystem(const char* szBlueprint, const CVector& vecPosition, RwMatrix* pRwMatrixTag, unsigned char bSkipCameraFrustumCheck,
bool bSoundEnable);
void DestroyFxSystem(CFxSystem* pFxSystem);
void OnFxSystemSAInterfaceDestroyed(CFxSystemSAInterface* pFxSystemSAInterface);
CFxSystem* CreateFxSystem(const char* szBlueprint, const CVector& vecPosition, RwMatrix* pRwMatrixTag, unsigned char bSkipCameraFrustumCheck,
bool bSoundEnable);
void DestroyFxSystem(CFxSystem* pFxSystem);
void OnFxSystemSAInterfaceDestroyed(CFxSystemSAInterface* pFxSystemSAInterface);
CFxSystemBPSAInterface* GetFxSystemBlueprintByName(SString sName);
bool IsValidFxSystemBlueprintName(SString sName);

// CFxManagerSA methods
CFxSystemSA* GetFxSystem(CFxSystemSAInterface* pFxSystemSAInterface);
Expand Down
18 changes: 18 additions & 0 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ CGameSA::CGameSA()
ModelInfo[i].SetModelID(i);
}

// Prepare all object dynamic infos for CObjectGroupPhysicalPropertiesSA instances
for (int i = 0; i < OBJECTDYNAMICINFO_MAX; i++)
{
ObjectGroupsInfo[i].SetGroup(i);
}

DEBUG_TRACE("CGameSA::CGameSA()");
this->m_pAudioEngine = new CAudioEngineSA((CAudioEngineSAInterface*)CLASS_CAudioEngine);
this->m_pAEAudioHardware = new CAEAudioHardwareSA((CAEAudioHardwareSAInterface*)CLASS_CAEAudioHardware);
Expand Down Expand Up @@ -464,6 +470,9 @@ void CGameSA::Reset()

// Restore model dummies' positions
CModelInfoSA::ResetAllVehicleDummies();
CModelInfoSA::RestoreAllObjectsPropertiesGroups();
// restore default properties of all CObjectGroupPhysicalPropertiesSA instances
CObjectGroupPhysicalPropertiesSA::RestoreDefaultValues();
}
}

Expand Down Expand Up @@ -862,3 +871,12 @@ CPed* CGameSA::GetPedContext()
m_pPedContext = pGame->GetPools()->GetPedFromRef((DWORD)1);
return m_pPedContext;
}

CObjectGroupPhysicalProperties* CGameSA::GetObjectGroupPhysicalProperties(unsigned char ucObjectGroup)
{
DEBUG_TRACE("CObjectGroupPhysicalProperties * CGameSA::GetObjectGroupPhysicalProperties(unsigned char ucObjectGroup)");
if (ucObjectGroup < OBJECTDYNAMICINFO_MAX && ObjectGroupsInfo[ucObjectGroup].IsValid())
return &ObjectGroupsInfo[ucObjectGroup];

return nullptr;
}
75 changes: 40 additions & 35 deletions Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma once

#include "CModelInfoSA.h"
#include "CObjectGroupPhysicalPropertiesSA.h"
#include "CFxManagerSA.h"

#define MAX_MEMORY_OFFSET_1_0 0xCAF008
Expand All @@ -33,6 +34,7 @@
#define NUM_WeaponInfosTotal (NUM_WeaponInfosStdSkill + (3*NUM_WeaponInfosOtherSkill)) // std, (poor, pro, special)

#define MODELINFO_MAX 26000 // Actual max is 25755
#define OBJECTDYNAMICINFO_MAX 160

#define FUNC_GetLevelFromPosition 0x4DD300

Expand Down Expand Up @@ -103,6 +105,7 @@ class CGameSA : public CGame
private:
CWeaponInfo* WeaponInfos[NUM_WeaponInfosTotal];
CModelInfoSA ModelInfo[MODELINFO_MAX];
CObjectGroupPhysicalPropertiesSA ObjectGroupsInfo[OBJECTDYNAMICINFO_MAX];

public:
ZERO_ON_NEW
Expand Down Expand Up @@ -305,8 +308,9 @@ class CGameSA : public CGame
CRenderWareSA* GetRenderWareSA() { return m_pRenderWare; }
CFxManagerSA* GetFxManagerSA() { return m_pFxManager; }

CWeaponInfo* GetWeaponInfo(eWeaponType weapon, eWeaponSkill skill = WEAPONSKILL_STD);
CModelInfo* GetModelInfo(DWORD dwModelID);
CWeaponInfo* GetWeaponInfo(eWeaponType weapon, eWeaponSkill skill = WEAPONSKILL_STD);
CModelInfo* GetModelInfo(DWORD dwModelID);
CObjectGroupPhysicalProperties* GetObjectGroupPhysicalProperties(unsigned char ucObjectGroup);

DWORD GetSystemTime()
{
Expand Down Expand Up @@ -429,39 +433,40 @@ class CGameSA : public CGame
TaskSimpleBeHitHandler* m_pTaskSimpleBeHitHandler;

private:
CPools* m_pPools;
CPlayerInfo* m_pPlayerInfo;
CProjectileInfo* m_pProjectileInfo;
CRadar* m_pRadar;
CRestart* m_pRestart;
CClock* m_pClock;
CCoronas* m_pCoronas;
CCheckpoints* m_pCheckpoints;
CEventList* m_pEventList;
CFireManager* m_pFireManager;
CGarages* m_pGarages;
CHud* m_pHud;
CWanted* m_pWanted;
CWeather* m_pWeather;
CWorld* m_pWorld;
CCamera* m_pCamera;
CModelInfo* m_pModelInfo;
CPickups* m_pPickups;
CWeaponInfo* m_pWeaponInfo;
CExplosionManager* m_pExplosionManager;
C3DMarkers* m_p3DMarkers;
CRenderWareSA* m_pRenderWare;
CHandlingManager* m_pHandlingManager;
CAnimManager* m_pAnimManager;
CStreaming* m_pStreaming;
CVisibilityPlugins* m_pVisibilityPlugins;
CKeyGen* m_pKeyGen;
CRopes* m_pRopes;
CFx* m_pFx;
CFxManagerSA* m_pFxManager;
CWaterManager* m_pWaterManager;
CWeaponStatManager* m_pWeaponStatsManager;
CPointLights* m_pPointLights;
CPools* m_pPools;
CPlayerInfo* m_pPlayerInfo;
CProjectileInfo* m_pProjectileInfo;
CRadar* m_pRadar;
CRestart* m_pRestart;
CClock* m_pClock;
CCoronas* m_pCoronas;
CCheckpoints* m_pCheckpoints;
CEventList* m_pEventList;
CFireManager* m_pFireManager;
CGarages* m_pGarages;
CHud* m_pHud;
CWanted* m_pWanted;
CWeather* m_pWeather;
CWorld* m_pWorld;
CCamera* m_pCamera;
CModelInfo* m_pModelInfo;
CPickups* m_pPickups;
CWeaponInfo* m_pWeaponInfo;
CExplosionManager* m_pExplosionManager;
C3DMarkers* m_p3DMarkers;
CRenderWareSA* m_pRenderWare;
CHandlingManager* m_pHandlingManager;
CAnimManager* m_pAnimManager;
CStreaming* m_pStreaming;
CVisibilityPlugins* m_pVisibilityPlugins;
CKeyGen* m_pKeyGen;
CRopes* m_pRopes;
CFx* m_pFx;
CFxManagerSA* m_pFxManager;
CWaterManager* m_pWaterManager;
CWeaponStatManager* m_pWeaponStatsManager;
CPointLights* m_pPointLights;
CObjectGroupPhysicalProperties* m_pObjectGroupPhysicalProperties;

CPad* m_pPad;
CTheCarGenerators* m_pTheCarGenerators;
Expand Down
41 changes: 41 additions & 0 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ std::map<unsigned short, int>
std::map<DWORD, float> CModelInfoSA::ms_ModelDefaultLodDistanceMap;
std::map<DWORD, BYTE> CModelInfoSA::ms_ModelDefaultAlphaTransparencyMap;
std::unordered_map<CVehicleModelInfoSAInterface*, std::map<eVehicleDummies, CVector>> CModelInfoSA::ms_ModelDefaultDummiesPosition;
std::unordered_map<DWORD, unsigned short> CModelInfoSA::ms_OriginalObjectPropertiesGroups;

CModelInfoSA::CModelInfoSA()
{
Expand Down Expand Up @@ -1373,6 +1374,46 @@ void CModelInfoSA::ResetSupportedUpgrades()
m_ModelSupportedUpgrades.Reset();
}

void CModelInfoSA::SetObjectPropertiesGroup(unsigned short usNewGroup)
{
unsigned short usOrgGroup = GetObjectPropertiesGroup();
if (usOrgGroup == usNewGroup)
return;

if (!MapFind(ms_OriginalObjectPropertiesGroups, m_dwModelID))
MapSet(ms_OriginalObjectPropertiesGroups, m_dwModelID, usOrgGroup);

GetInterface()->usDynamicIndex = usNewGroup;
}

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

return usGroup;
}

void CModelInfoSA::RestoreObjectPropertiesGroup()
{
unsigned short* usGroupInMap = MapFind(ms_OriginalObjectPropertiesGroups, m_dwModelID);
if (usGroupInMap)
{
GetInterface()->usDynamicIndex = *usGroupInMap;
MapRemove(ms_OriginalObjectPropertiesGroups, m_dwModelID);
}
}

void CModelInfoSA::RestoreAllObjectsPropertiesGroups()
{
for (const auto& pair : ms_OriginalObjectPropertiesGroups)
{
pGame->GetModelInfo(pair.first)->GetInterface()->usDynamicIndex = pair.second;
}
ms_OriginalObjectPropertiesGroups.clear();
}

eModelInfoType CModelInfoSA::GetModelType()
{
return ((eModelInfoType(*)())m_pInterface->VFTBL->GetModelType)();
Expand Down
17 changes: 7 additions & 10 deletions Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,7 @@ class CBaseModelInfoSAInterface
unsigned char ucNumOf2DEffects : 8; // +13
unsigned short usUnknown : 16; // +14 Something with 2d effects

unsigned char ucDynamicIndex : 8; // +16

unsigned char dwUnknownFlag9 : 1; // +17
unsigned char dwUnknownFlag10 : 1;
unsigned char dwUnknownFlag11 : 1;
unsigned char dwUnknownFlag12 : 1;
unsigned char dwUnknownFlag13 : 1;
unsigned char dwUnknownFlag14 : 1;
unsigned char dwUnknownFlag15 : 1;
unsigned char dwUnknownFlag16 : 1;
unsigned short usDynamicIndex : 16; // +16

// Flags used by CBaseModelInfo
unsigned char bHasBeenPreRendered : 1; // +18
Expand Down Expand Up @@ -277,6 +268,7 @@ class CModelInfoSA : public CModelInfo
static std::map<DWORD, float> ms_ModelDefaultLodDistanceMap;
static std::map<DWORD, BYTE> ms_ModelDefaultAlphaTransparencyMap;
static std::unordered_map<CVehicleModelInfoSAInterface*, std::map<eVehicleDummies, CVector>> ms_ModelDefaultDummiesPosition;
static std::unordered_map<DWORD, unsigned short> ms_OriginalObjectPropertiesGroups;
bool m_bAddedRefForCollision;
SVehicleSupportedUpgrades m_ModelSupportedUpgrades;

Expand Down Expand Up @@ -375,6 +367,11 @@ class CModelInfoSA : public CModelInfo
void InitialiseSupportedUpgrades(RpClump* pClump);
void ResetSupportedUpgrades();

void SetObjectPropertiesGroup(unsigned short usObjectGroup);
unsigned short GetObjectPropertiesGroup();
void RestoreObjectPropertiesGroup();
static void RestoreAllObjectsPropertiesGroups();

private:
void RwSetSupportedUpgrades(RwFrame* parent, DWORD dwModel);
};
Loading