1212#include " StdInc.h"
1313#include " CCameraSA.h"
1414#include " CGameSA.h"
15- #include < mutex>
16- #include < cmath>
1715
1816extern CGameSA* pGame;
1917
20- static std::mutex s_cameraClipMutex;
2118static bool bCameraClipObjects;
2219static bool bCameraClipVehicles;
2320
@@ -31,54 +28,19 @@ void HOOK_Camera_CollisionDetection();
3128
3229CCameraSA::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
7339CCameraSA::~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
239197CMatrix* 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
287235void 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
402335void 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
447370RwMatrix* 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
463376CEntity* CCameraSA::GetTargetEntity ()
@@ -473,16 +386,12 @@ CEntity* CCameraSA::GetTargetEntity()
473386
474387void 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
482393void 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