Skip to content

Commit 635de71

Browse files
authored
Merge branch 'master' into commandhandler-controlling
2 parents c4b97a5 + ffcde8e commit 635de71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+6730
-5078
lines changed

Client/core/Graphics/CVideoModeManager.cpp

Lines changed: 163 additions & 67 deletions
Large diffs are not rendered by default.

Client/game_sa/CCamSA.cpp

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

1617
extern CGameSA* pGame;
1718

1819
CEntity* CCamSA::GetTargetEntity() const
1920
{
21+
22+
if (!m_pInterface)
23+
return nullptr;
24+
2025
CEntitySAInterface* pInterface = m_pInterface->CamTargetEntity;
2126
if (pInterface)
22-
{
27+
{
2328
CPools* pPools = pGame->GetPools();
2429
return pPools->GetEntity((DWORD*)pInterface);
2530
}
@@ -28,18 +33,64 @@ CEntity* CCamSA::GetTargetEntity() const
2833

2934
void CCamSA::SetTargetEntity(CEntity* pEntity)
3035
{
31-
m_pInterface->CamTargetEntity = pEntity->GetInterface();
36+
if (!m_pInterface)
37+
return;
38+
39+
if (pEntity)
40+
{
41+
auto pEntityInterface = pEntity->GetInterface();
42+
if (!pEntityInterface)
43+
return;
44+
45+
m_pInterface->CamTargetEntity = pEntityInterface;
46+
}
47+
else
48+
{
49+
m_pInterface->CamTargetEntity = nullptr;
50+
}
3251
}
3352

3453
void CCamSA::GetDirection(float& fHorizontal, float& fVertical)
3554
{
36-
fHorizontal = m_pInterface->m_fHorizontalAngle;
37-
fVertical = m_pInterface->m_fVerticalAngle;
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;
3874
}
3975

4076
void CCamSA::SetDirection(float fHorizontal, float fVertical)
4177
{
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+
4293
// Calculation @ sub 0x50F970
4394
m_pInterface->m_fHorizontalAngle = fHorizontal;
4495
m_pInterface->m_fVerticalAngle = fVertical;
45-
}
96+
}

Client/game_sa/CCamSA.h

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

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

168-
CVector* GetFront() const { return &m_pInterface->Front; }
169-
CVector* GetUp() const { return &m_pInterface->Up; }
170-
CVector* GetSource() const { return &m_pInterface->Source; }
171-
unsigned int GetMode() const { return m_pInterface->Mode; }
172-
float GetFOV() const { return m_pInterface->FOV; }
173-
void SetFOV(float fFOV) { m_pInterface->FOV = fFOV; }
174-
void GetDirection(float& fHorizontal, float& fVertical);
175-
void SetDirection(float fHorizontal, float fVertical);
176-
177-
CVector* GetFixedModeSource() const { return &m_pInterface->m_cvecCamFixedModeSource; }
178-
CVector* GetFixedModeVector() const { return &m_pInterface->m_cvecCamFixedModeVector; }
179-
CVector* GetTargetHistoryPos() const { return m_pInterface->m_aTargetHistoryPos; }
180-
181-
CEntity* GetTargetEntity() const;
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+
}
233+
234+
CEntity* GetTargetEntity() const override;
182235
void SetTargetEntity(CEntity* pEntity) override;
183-
};
236+
};

0 commit comments

Comments
 (0)