Skip to content

Commit e17a7a1

Browse files
committed
Revert "Addendum to 9ff02d5"
1 parent 737d587 commit e17a7a1

File tree

3 files changed

+26
-214
lines changed

3 files changed

+26
-214
lines changed

Client/game_sa/CCamSA.cpp

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,14 @@
1212
#include "StdInc.h"
1313
#include "CCamSA.h"
1414
#include "CGameSA.h"
15-
#include <cmath>
1615

1716
extern CGameSA* pGame;
1817

1918
CEntity* CCamSA::GetTargetEntity() const
2019
{
21-
22-
if (!m_pInterface)
23-
return nullptr;
24-
2520
CEntitySAInterface* pInterface = m_pInterface->CamTargetEntity;
2621
if (pInterface)
27-
{
22+
{
2823
CPools* pPools = pGame->GetPools();
2924
return pPools->GetEntity((DWORD*)pInterface);
3025
}
@@ -33,16 +28,9 @@ CEntity* CCamSA::GetTargetEntity() const
3328

3429
void CCamSA::SetTargetEntity(CEntity* pEntity)
3530
{
36-
if (!m_pInterface)
37-
return;
38-
3931
if (pEntity)
4032
{
41-
auto pEntityInterface = pEntity->GetInterface();
42-
if (!pEntityInterface)
43-
return;
44-
45-
m_pInterface->CamTargetEntity = pEntityInterface;
33+
m_pInterface->CamTargetEntity = pEntity->GetInterface();
4634
}
4735
else
4836
{
@@ -52,45 +40,13 @@ void CCamSA::SetTargetEntity(CEntity* pEntity)
5240

5341
void CCamSA::GetDirection(float& fHorizontal, float& fVertical)
5442
{
55-
if (!m_pInterface)
56-
{
57-
fHorizontal = 0.0f;
58-
fVertical = 0.0f;
59-
return;
60-
}
61-
62-
float fHoriz = m_pInterface->m_fHorizontalAngle;
63-
float fVert = m_pInterface->m_fVerticalAngle;
64-
65-
if (!std::isfinite(fHoriz) || !std::isfinite(fVert))
66-
{
67-
fHorizontal = 0.0f;
68-
fVertical = 0.0f;
69-
return;
70-
}
71-
72-
fHorizontal = fHoriz;
73-
fVertical = fVert;
43+
fHorizontal = m_pInterface->m_fHorizontalAngle;
44+
fVertical = m_pInterface->m_fVerticalAngle;
7445
}
7546

7647
void CCamSA::SetDirection(float fHorizontal, float fVertical)
7748
{
78-
if (!m_pInterface)
79-
return;
80-
81-
// Validate input float values
82-
if (!std::isfinite(fHorizontal) || !std::isfinite(fVertical))
83-
return;
84-
85-
// Clamp angle values to prevent overflow
86-
constexpr float MIN_ANGLE = -360.0f;
87-
constexpr float MAX_ANGLE = 360.0f;
88-
89-
if (fHorizontal < MIN_ANGLE || fHorizontal > MAX_ANGLE ||
90-
fVertical < MIN_ANGLE || fVertical > MAX_ANGLE)
91-
return;
92-
9349
// Calculation @ sub 0x50F970
9450
m_pInterface->m_fHorizontalAngle = fHorizontal;
9551
m_pInterface->m_fVerticalAngle = fVertical;
96-
}
52+
}

Client/game_sa/CCamSA.h

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -162,75 +162,22 @@ class CCamSA : public CCam
162162
CCamSAInterface* m_pInterface;
163163

164164
public:
165-
CCamSA(CCamSAInterface* pInterface) : m_pInterface(pInterface)
166-
{
167-
if (!pInterface)
168-
{
169-
m_pInterface = nullptr;
170-
}
171-
}
172-
165+
CCamSA(CCamSAInterface* pInterface) { m_pInterface = pInterface; }
173166
CCamSAInterface* GetInterface() { return m_pInterface; }
174167

175-
CVector* GetFront() const override
176-
{
177-
return m_pInterface ? &m_pInterface->Front : nullptr;
178-
}
179-
180-
CVector* GetUp() const override
181-
{
182-
return m_pInterface ? &m_pInterface->Up : nullptr;
183-
}
184-
185-
CVector* GetSource() const override
186-
{
187-
return m_pInterface ? &m_pInterface->Source : nullptr;
188-
}
189-
190-
unsigned int GetMode() const override
191-
{
192-
return m_pInterface ? static_cast<unsigned int>(m_pInterface->Mode) : 0;
193-
}
194-
195-
float GetFOV() const override
196-
{
197-
if (!m_pInterface)
198-
return 70.0f; // Default FOV
199-
200-
float fov = m_pInterface->FOV;
201-
return std::isfinite(fov) ? fov : 70.0f;
202-
}
203-
204-
void SetFOV(float fFOV) override
205-
{
206-
if (!m_pInterface)
207-
return;
208-
209-
// Validate FOV range
210-
if (!std::isfinite(fFOV) || fFOV <= 0.0f || fFOV >= 180.0f)
211-
return;
212-
213-
m_pInterface->FOV = fFOV;
214-
}
215-
216-
void GetDirection(float& fHorizontal, float& fVertical) override;
217-
void SetDirection(float fHorizontal, float fVertical) override;
218-
219-
CVector* GetFixedModeSource() const override
220-
{
221-
return m_pInterface ? &m_pInterface->m_cvecCamFixedModeSource : nullptr;
222-
}
223-
224-
CVector* GetFixedModeVector() const override
225-
{
226-
return m_pInterface ? &m_pInterface->m_cvecCamFixedModeVector : nullptr;
227-
}
228-
229-
CVector* GetTargetHistoryPos() const override
230-
{
231-
return m_pInterface ? m_pInterface->m_aTargetHistoryPos : nullptr;
232-
}
168+
CVector* GetFront() const override { return &m_pInterface->Front; }
169+
CVector* GetUp() const override { return &m_pInterface->Up; }
170+
CVector* GetSource() const override { return &m_pInterface->Source; }
171+
unsigned int GetMode() const override { return m_pInterface->Mode; }
172+
float GetFOV() const override { return m_pInterface->FOV; }
173+
void SetFOV(float fFOV) override { m_pInterface->FOV = fFOV; }
174+
void GetDirection(float& fHorizontal, float& fVertical) override;
175+
void SetDirection(float fHorizontal, float fVertical) override;
176+
177+
CVector* GetFixedModeSource() const override { return &m_pInterface->m_cvecCamFixedModeSource; }
178+
CVector* GetFixedModeVector() const override { return &m_pInterface->m_cvecCamFixedModeVector; }
179+
CVector* GetTargetHistoryPos() const override { return m_pInterface->m_aTargetHistoryPos; }
233180

234181
CEntity* GetTargetEntity() const override;
235182
void SetTargetEntity(CEntity* pEntity) override;
236-
};
183+
};

Client/game_sa/CCameraSA.cpp

Lines changed: 7 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
#include "StdInc.h"
1313
#include "CCameraSA.h"
1414
#include "CGameSA.h"
15-
#include <mutex>
16-
#include <cmath>
1715

1816
extern CGameSA* pGame;
1917

20-
static std::mutex s_cameraClipMutex;
2118
static bool bCameraClipObjects;
2219
static bool bCameraClipVehicles;
2320

@@ -31,54 +28,19 @@ void HOOK_Camera_CollisionDetection();
3128

3229
CCameraSA::CCameraSA(CCameraSAInterface* cameraInterface)
3330
{
34-
if (!cameraInterface)
35-
{
36-
internalInterface = nullptr;
37-
// Initialize all camera pointers to null
38-
for (int i = 0; i < MAX_CAMS; i++)
39-
Cams[i] = nullptr;
40-
return;
41-
}
42-
4331
internalInterface = cameraInterface;
44-
4532
for (int i = 0; i < MAX_CAMS; i++)
46-
{
47-
try {
48-
Cams[i] = new CCamSA(&internalInterface->Cams[i]);
49-
}
50-
catch (...)
51-
{
52-
// Clean up on failure
53-
for (int j = 0; j < i; j++)
54-
{
55-
delete Cams[j];
56-
Cams[j] = nullptr;
57-
}
58-
internalInterface = nullptr;
59-
throw;
60-
}
61-
}
62-
63-
// Thread-safe initialization
64-
{
65-
std::lock_guard<std::mutex> lock(s_cameraClipMutex);
66-
bCameraClipObjects = true;
67-
bCameraClipVehicles = true;
68-
}
69-
33+
Cams[i] = new CCamSA(&internalInterface->Cams[i]);
34+
bCameraClipObjects = true;
35+
bCameraClipVehicles = true;
7036
HookInstall(HOOKPOS_Camera_CollisionDetection, (DWORD)HOOK_Camera_CollisionDetection, 5);
7137
}
7238

7339
CCameraSA::~CCameraSA()
7440
{
7541
for (int i = 0; i < MAX_CAMS; i++)
7642
{
77-
if (Cams[i])
78-
{
79-
delete Cams[i];
80-
Cams[i] = nullptr;
81-
}
43+
delete Cams[i];
8244
}
8345
}
8446

@@ -127,11 +89,7 @@ void CCameraSA::TakeControl(CEntity* entity, eCamMode CamMode, int CamSwitchStyl
12789
return;
12890

12991
CCameraSAInterface* cameraInterface = GetInterface();
130-
if (!cameraInterface)
131-
return;
132-
133-
if (CamSwitchStyle < 0 || CamSwitchStyle > 10)
134-
return;
92+
// __thiscall
13593

13694
DWORD CCamera__TakeControl = FUNC_TakeControl;
13795
_asm
@@ -238,17 +196,7 @@ void CCameraSA::RestoreLastGoodState()
238196

239197
CMatrix* CCameraSA::GetMatrix(CMatrix* matrix)
240198
{
241-
if (!matrix)
242-
return nullptr;
243-
244-
CCameraSAInterface* cameraInterface = GetInterface();
245-
if (!cameraInterface)
246-
{
247-
*matrix = CMatrix();
248-
return matrix;
249-
}
250-
251-
CMatrix_Padded* pCamMatrix = &cameraInterface->m_cameraMatrix;
199+
CMatrix_Padded* pCamMatrix = &GetInterface()->m_cameraMatrix; // ->matrix;
252200
if (pCamMatrix)
253201
{
254202
matrix->vFront = pCamMatrix->vFront;
@@ -286,26 +234,11 @@ void CCameraSA::SetMatrix(CMatrix* matrix)
286234

287235
void CCameraSA::Find3rdPersonCamTargetVector(float fDistance, CVector* vecGunMuzzle, CVector* vecSource, CVector* vecTarget)
288236
{
289-
if (!vecGunMuzzle || !vecSource || !vecTarget)
290-
return;
291-
292-
// Validate float parameter to prevent NaN/infinity issues
293-
if (!std::isfinite(fDistance) || fDistance < 0.0f)
294-
return;
295-
296237
float fOriginX = vecGunMuzzle->fX;
297238
float fOriginY = vecGunMuzzle->fY;
298239
float fOriginZ = vecGunMuzzle->fZ;
299-
300-
if (!std::isfinite(fOriginX) || !std::isfinite(fOriginY) || !std::isfinite(fOriginZ))
301-
return;
302-
303240
DWORD dwFunc = FUNC_Find3rdPersonCamTargetVector;
304241
CCameraSAInterface* cameraInterface = GetInterface();
305-
306-
if (!cameraInterface)
307-
return;
308-
309242
_asm
310243
{
311244
mov ecx, cameraInterface
@@ -401,18 +334,8 @@ int CCameraSA::GetFadingDirection()
401334

402335
void CCameraSA::Fade(float fFadeOutTime, int iOutOrIn)
403336
{
404-
if (!std::isfinite(fFadeOutTime) || fFadeOutTime < 0.0f || fFadeOutTime > 60.0f)
405-
return;
406-
407-
if (iOutOrIn < 0 || iOutOrIn > 1)
408-
return;
409-
410337
DWORD dwFunc = FUNC_Fade;
411338
CCameraSAInterface* cameraInterface = GetInterface();
412-
413-
if (!cameraInterface)
414-
return;
415-
416339
_asm
417340
{
418341
mov ecx, cameraInterface
@@ -446,18 +369,8 @@ float CCameraSA::GetCameraRotation()
446369

447370
RwMatrix* CCameraSA::GetLTM()
448371
{
449-
CCameraSAInterface* cameraInterface = GetInterface();
450-
if (!cameraInterface)
451-
return nullptr;
452-
453-
if (!cameraInterface->m_pRwCamera)
454-
return nullptr;
455-
456-
if (!cameraInterface->m_pRwCamera->object.object.parent)
457-
return nullptr;
458-
459372
// RwFrameGetLTM
460-
return ((RwMatrix*(_cdecl*)(void*))0x7F0990)(cameraInterface->m_pRwCamera->object.object.parent);
373+
return ((RwMatrix*(_cdecl*)(void*))0x7F0990)(GetInterface()->m_pRwCamera->object.object.parent);
461374
}
462375

463376
CEntity* CCameraSA::GetTargetEntity()
@@ -473,16 +386,12 @@ CEntity* CCameraSA::GetTargetEntity()
473386

474387
void CCameraSA::SetCameraClip(bool bObjects, bool bVehicles)
475388
{
476-
// Thread-safe access to static variables
477-
std::lock_guard<std::mutex> lock(s_cameraClipMutex);
478389
bCameraClipObjects = bObjects;
479390
bCameraClipVehicles = bVehicles;
480391
}
481392

482393
void CCameraSA::GetCameraClip(bool& bObjects, bool& bVehicles)
483394
{
484-
// Thread-safe access to static variables
485-
std::lock_guard<std::mutex> lock(s_cameraClipMutex);
486395
bObjects = bCameraClipObjects;
487396
bVehicles = bCameraClipVehicles;
488397
}

0 commit comments

Comments
 (0)