Skip to content

Commit 9464fe7

Browse files
committed
Init
1 parent 7bf6af1 commit 9464fe7

31 files changed

+1250
-449
lines changed

Client/game_sa/CGameSA.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ CGameSA::CGameSA()
250250
CFireSA::StaticSetHooks();
251251
CPtrNodeSingleLinkPoolSA::StaticSetHooks();
252252
CVehicleAudioSettingsManagerSA::StaticSetHooks();
253+
CAutomobileSA::StaticSetHooks();
254+
CProjectileInfoSA::StaticSetHooks();
253255
}
254256
catch (const std::bad_alloc& e)
255257
{

Client/game_sa/CMatrixSA.cpp

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ CMatrixSAInterface::CMatrixSAInterface(RwMatrix* matrix, bool temporary)
2424
// destructor detaches matrix if attached
2525
CMatrixSAInterface::~CMatrixSAInterface()
2626
{
27-
((void(__thiscall*)(CMatrixSAInterface*))0x59ACD0)(this);
27+
if (m_bOwnsAttachedMatrix && m_pAttachMatrix)
28+
((void(__cdecl*)(RwMatrix*))0x7F2A20)(m_pAttachMatrix);
29+
30+
//((void(__thiscall*)(CMatrixSAInterface*))0x59ACD0)(this);
2831
}
2932

3033
void CMatrixSAInterface::ConvertToEulerAngles(float& x, float& y, float& z, std::int32_t flags)
@@ -36,7 +39,67 @@ void CMatrixSAInterface::ConvertFromEulerAngles(float x, float y, float z, std::
3639
((void(__thiscall*)(CMatrixSAInterface*, float, float, float, std::int32_t))0x59AA40)(this, x, y, z, flags);
3740
}
3841

42+
void CMatrixSAInterface::UpdateRwMatrix(RwMatrix* rwMatrix)
43+
{
44+
rwMatrix->right.x = m_right.fX;
45+
rwMatrix->right.y = m_right.fY;
46+
rwMatrix->right.z = m_right.fZ;
47+
48+
rwMatrix->up.x = m_forward.fX;
49+
rwMatrix->up.y = m_forward.fY;
50+
rwMatrix->up.z = m_forward.fZ;
51+
52+
rwMatrix->at.x = m_up.fX;
53+
rwMatrix->at.y = m_up.fY;
54+
rwMatrix->at.z = m_up.fZ;
55+
56+
rwMatrix->pos.x = m_pos.fX;
57+
rwMatrix->pos.y = m_pos.fY;
58+
rwMatrix->pos.z = m_pos.fZ;
59+
60+
((void(__cdecl*)(RwMatrix*))0x7F18A0)(rwMatrix);
61+
//RwMatrixUpdate(rwMatrix);
62+
}
63+
3964
void CMatrixSAInterface::UpdateRW()
4065
{
41-
((void(__thiscall*)(CMatrixSAInterface*))0x59BBB0)(this);
66+
if (!m_pAttachMatrix)
67+
return;
68+
69+
UpdateRwMatrix(m_pAttachMatrix);
70+
}
71+
72+
void CMatrixSAInterface::SetTranslate(const CVector& position)
73+
{
74+
m_right.fX = 1.0f;
75+
m_right.fY = 0;
76+
m_right.fZ = 0;
77+
78+
m_forward.fX = 0;
79+
m_forward.fY = 1.0f;
80+
m_forward.fZ = 0;
81+
82+
m_up.fX = 0;
83+
m_up.fY = 0;
84+
m_up.fZ = 1.0f;
85+
86+
m_pos = position;
87+
}
88+
89+
void CMatrixSAInterface::RotateZ(float angle)
90+
{
91+
float cos = std::cos(angle);
92+
float sin = std::sin(angle);
93+
94+
m_right.fX = cos * m_right.fX - sin * m_right.fY;
95+
m_right.fY = cos * m_right.fY + sin * m_right.fX;
96+
97+
m_forward.fX = cos * m_forward.fX - sin * m_forward.fY;
98+
m_forward.fY = cos * m_forward.fY + sin * m_forward.fX;
99+
100+
m_up.fX = cos * m_up.fX - sin * m_up.fY;
101+
m_up.fY = cos * m_up.fY + sin * m_up.fX;
102+
103+
m_pos.fX = cos * m_pos.fX - sin * m_pos.fY;
104+
m_pos.fY = cos * m_pos.fY + sin * m_pos.fX;
42105
}

Client/game_sa/CMatrixSA.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,37 @@ class CMatrixSAInterface
3636

3737
void ConvertToEulerAngles(float& x, float& y, float& z, std::int32_t flags);
3838
void ConvertFromEulerAngles(float x, float y, float z, std::int32_t flags);
39+
40+
void UpdateRwMatrix(RwMatrix* rwMatrix);
3941
void UpdateRW();
42+
43+
void SetTranslate(const CVector& position); // 0x59AF40 (CMatrix::Translate)
44+
45+
void RotateZ(float angle);
46+
4047
void SetTranslateOnly(CVector position) { m_pos = position; }
48+
49+
CVector GetPosition() const noexcept { return m_pos; }
50+
CVector GetRight() const noexcept { return m_right; }
51+
CVector GetForward() const noexcept { return m_forward; }
52+
CVector GetUp() const noexcept { return m_up; }
53+
4154
void SetMatrix(const CVector& right, const CVector& forward, const CVector& up, const CVector& pos)
4255
{
4356
m_right = right;
4457
m_forward = forward;
4558
m_up = up;
4659
m_pos = pos;
4760
}
61+
62+
CMatrixSAInterface* operator=(const void* m)
63+
{
64+
RwMatrix* attachedMatrix = m_pAttachMatrix;
65+
std::memcpy(this, m, 64);
66+
67+
if (attachedMatrix)
68+
UpdateRwMatrix(attachedMatrix);
69+
70+
return this;
71+
}
4872
};

Client/game_sa/CPedSA.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,6 @@ void CPedSA::SetModelIndex(std::uint32_t modelIndex)
7979
GetPedInterface()->pedSound.m_bIsFemale = type == 5 || type == 22;
8080
}
8181

82-
bool CPedSA::AddProjectile(eWeaponType weaponType, CVector origin, float force, CVector* target, CEntity* targetEntity)
83-
{
84-
CProjectileInfo* projectileInfo = pGame->GetProjectileInfo();
85-
if (!projectileInfo)
86-
return false;
87-
88-
return projectileInfo->AddProjectile(static_cast<CEntitySA*>(this), weaponType, origin, force, const_cast<CVector*>(target), const_cast<CEntity*>(targetEntity));
89-
}
90-
9182
void CPedSA::DetachPedFromEntity()
9283
{
9384
// void __thiscall CPed::DettachPedFromEntity(CPed *this)
@@ -546,12 +537,12 @@ void CPedSA::Say(const ePedSpeechContext& speechId, float probability)
546537
void CPedSA::GetAttachedSatchels(std::vector<SSatchelsData>& satchelsList) const
547538
{
548539
// Array of projectiles objects
549-
auto** projectilesArray = reinterpret_cast<CProjectileSAInterface**>(ARRAY_CProjectile);
550-
CProjectileSAInterface* projectileInterface = nullptr;
540+
auto** projectilesArray = reinterpret_cast<CProjectileSA**>(ARRAY_CProjectile);
541+
CProjectileSA* projectileInterface = nullptr;
551542

552543
// Array of projectiles infos
553-
auto* projectilesInfoArray = reinterpret_cast<CProjectileInfoSAInterface*>(ARRAY_CProjectileInfo);
554-
CProjectileInfoSAInterface* projectileInfoInterface = nullptr;
544+
auto* projectilesInfoArray = reinterpret_cast<CProjectileInfoSA*>(ARRAY_CProjectileInfo);
545+
CProjectileInfoSA* projectileInfoInterface = nullptr;
555546

556547
satchelsList.reserve(PROJECTILE_COUNT);
557548

@@ -561,18 +552,18 @@ void CPedSA::GetAttachedSatchels(std::vector<SSatchelsData>& satchelsList) const
561552
projectileInterface = projectilesArray[i];
562553

563554
// is attached to our ped?
564-
if (!projectileInterface || projectileInterface->m_pAttachedEntity != m_pInterface)
555+
if (!projectileInterface || projectileInterface->m_object->m_pAttachedEntity != m_pInterface)
565556
continue;
566557

567558
// index is always the same for both arrays
568559
projectileInfoInterface = &projectilesInfoArray[i];
569560

570561
// We are only interested in satchels
571-
if (!projectileInfoInterface || projectileInfoInterface->dwProjectileType != eWeaponType::WEAPONTYPE_REMOTE_SATCHEL_CHARGE)
562+
if (!projectileInfoInterface || projectileInfoInterface->GetType() != eWeaponType::WEAPONTYPE_REMOTE_SATCHEL_CHARGE)
572563
continue;
573564

574565
// Push satchel into the array. There is no need to check the counter because for satchels it restarts until the player detonates the charges
575-
satchelsList.emplace_back(projectileInterface, &projectileInterface->m_vecAttachedOffset, &projectileInterface->m_vecAttachedRotation);
566+
satchelsList.emplace_back(projectileInterface, &projectileInterface->m_object->m_vecAttachedOffset, &projectileInterface->m_object->m_vecAttachedRotation);
576567
}
577568
}
578569

Client/game_sa/CPedSA.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
374374
float GetOxygenLevel() const override;
375375
void SetOxygenLevel(float oxygen) override;
376376

377-
bool AddProjectile(eWeaponType weaponType, CVector origin, float force, CVector* target, CEntity* targetEntity) override;
378377
CWeapon* GiveWeapon(eWeaponType weaponType, std::uint32_t ammo, eWeaponSkill skill) override;
379378
CWeapon* GetWeapon(eWeaponSlot weaponSlot) const noexcept override;
380379
CWeapon* GetWeapon(eWeaponType weaponType) const override;

Client/game_sa/CPhysicalSA.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class CPhysicalSAInterface : public CEntitySAInterface
6868
uint32 bAttachedToEntity : 1;
6969
uint32 b0x4000000 : 1;
7070
uint32 bTouchingWater : 1;
71+
7172
uint32 bEnableCollision : 1;
7273
uint32 bDestroyed : 1;
7374
uint32 b0x40000000 : 1;
@@ -107,7 +108,8 @@ class CPhysicalSAInterface : public CEntitySAInterface
107108
CVector m_vecAttachedRotation; // 268
108109
CVector m_vecUnk; // 280
109110
uint32 m_pad4; // 292
110-
CPtrNodeDoubleLink<void>* m_pControlCodeNodeLink; // 296
111+
//CPtrNodeDoubleLink<void>* m_pControlCodeNodeLink; // 296
112+
CEntitySAInterface* m_entityIgnoredCollision;
111113
float m_fLighting; // 300 surface brightness
112114
float m_fLighting2; // 304 dynamic lighting (unused, always set to 0 in the GTA code)
113115
class CShadowDataSA* m_pShadowData; // 308

Client/game_sa/CPlaceableSA.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <CMatrix_Pad.h>
1111
#include <CVector.h>
12+
#include "CMatrixSA.h"
1213

1314
class CSimpleTransformSAInterface // 16 bytes
1415
{
@@ -29,6 +30,12 @@ class CPlaceableSAInterface
2930
bool HasMatrix() const noexcept { return matrix != nullptr; }
3031
void RemoveMatrix() { ((void(__thiscall*)(void*))0x54F3B0)(this); }
3132

33+
// Since the m_matrix field has an incorrect type, we currently call the GetMatrix method directly.
34+
// In the future, after a refactor, we can reimplement this method here without needing to call the external function.
35+
CMatrixSAInterface* GetMatrix() { return ((CMatrixSAInterface*(__thiscall*)(CPlaceableSAInterface*))0x411990)(this); }
36+
37+
void SetMatrix(CMatrixSAInterface* matrix) { ((void(__thiscall*)(CPlaceableSAInterface*, CMatrixSAInterface*))0x54F610)(this, matrix); }
38+
3239
void SetOrientation(float x, float y, float z) { ((void(__thiscall*)(CPlaceableSAInterface * pEntity, float, float, float))0x439A80)(this, x, y, z); }
3340

3441
public:

Client/game_sa/CPoolsSA.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,3 +1089,20 @@ void CPoolsSA::InvalidateLocalPlayerClientEntity()
10891089
{
10901090
m_pedPool.arrayOfClientEntities[0] = {m_pedPool.arrayOfClientEntities[0].pEntity, nullptr};
10911091
}
1092+
1093+
std::uint16_t CPoolsSA::GetObjectHandle(CObjectSAInterface* object) const
1094+
{
1095+
auto pool = *reinterpret_cast<CPoolSAInterface<CObjectSAInterface>**>(CLASS_CPool_Object);
1096+
if (!pool || !pool->m_pObjects || !pool->m_byteMap)
1097+
return 0xFFFF;
1098+
1099+
int index = static_cast<int>((reinterpret_cast<std::uintptr_t>(object) - reinterpret_cast<std::uintptr_t>(pool->m_pObjects)) / (sizeof(CObjectSAInterface) + 32));
1100+
if (index < 0 || index >= pool->m_nSize)
1101+
return 0xFFFF;
1102+
1103+
const tPoolObjectFlags& flags = pool->m_byteMap[index];
1104+
if (flags.bEmpty)
1105+
return 0xFFFF;
1106+
1107+
return static_cast<std::uint16_t>((index << 8) | flags.nId);
1108+
}

Client/game_sa/CPoolsSA.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ class CPoolsSA : public CPools
100100
CTxdPool& GetTxdPool() noexcept { return m_TxdPool; };
101101
CPtrNodeSingleLinkPool& GetPtrNodeSingleLinkPool() noexcept override { return m_PtrNodeSingleLinkPool; };
102102

103+
[[nodiscard]]
104+
std::uint16_t GetObjectHandle(CObjectSAInterface* object) const override;
105+
103106
private:
104107
// Pools
105108
SPoolData<CVehicleSA, CVehicleSAInterface, MAX_VEHICLES> m_vehiclePool;

0 commit comments

Comments
 (0)