@@ -22,122 +22,82 @@ void CCameraRPCs::LoadFunctions()
2222
2323void CCameraRPCs::SetCameraMatrix (NetBitStreamInterface& bitStream)
2424{
25- if (!m_pCamera)
26- return ;
27-
2825 if (bitStream.Version () >= 0x5E )
2926 {
3027 uchar ucTimeContext;
31- if (!bitStream.Read (ucTimeContext))
32- {
33- return ;
34- }
35- m_pCamera->SetSyncTimeContext (ucTimeContext);
28+ if (bitStream.Read (ucTimeContext))
29+ m_pCamera->SetSyncTimeContext (ucTimeContext);
3630 }
3731
3832 CVector vecPosition, vecLookAt;
3933 float fRoll = 0 .0f ;
4034 float fFOV = 70 .0f ;
41-
42- if (!bitStream.Read (vecPosition.fX ) || !bitStream.Read (vecPosition.fY ) || !bitStream.Read (vecPosition.fZ ) ||
43- !bitStream.Read (vecLookAt.fX ) || !bitStream.Read (vecLookAt.fY ) || !bitStream.Read (vecLookAt.fZ ))
35+ if (bitStream.Read (vecPosition.fX ) && bitStream.Read (vecPosition.fY ) && bitStream.Read (vecPosition.fZ ) && bitStream.Read (vecLookAt.fX ) &&
36+ bitStream.Read (vecLookAt.fY ) && bitStream.Read (vecLookAt.fZ ))
4437 {
45- return ; // Invalid data
46- }
38+ bitStream. Read ( fRoll );
39+ bitStream. Read ( fFOV );
4740
48- bitStream. Read ( fRoll );
49- bitStream. Read ( fFOV );
41+ if (!m_pCamera-> IsInFixedMode ())
42+ m_pCamera-> ToggleCameraFixedMode ( true );
5043
51- // Validate float values to prevent potential issues
52- if (!std::isfinite (fRoll ) || !std::isfinite (fFOV ) ||
53- !std::isfinite (vecPosition.fX ) || !std::isfinite (vecPosition.fY ) || !std::isfinite (vecPosition.fZ ) ||
54- !std::isfinite (vecLookAt.fX ) || !std::isfinite (vecLookAt.fY ) || !std::isfinite (vecLookAt.fZ ))
55- {
56- return ; // Invalid float values (NaN, infinity, etc.)
44+ // Put the camera there
45+ m_pCamera->SetPosition (vecPosition);
46+ m_pCamera->SetFixedTarget (vecLookAt, fRoll );
47+ m_pCamera->SetFOV (fFOV );
5748 }
58-
59- // Validate camera pointer before use
60- if (!m_pCamera)
61- return ;
62-
63- if (!m_pCamera->IsInFixedMode ())
64- m_pCamera->ToggleCameraFixedMode (true );
65-
66- // Put the camera there
67- m_pCamera->SetPosition (vecPosition);
68- m_pCamera->SetFixedTarget (vecLookAt, fRoll );
69- m_pCamera->SetFOV (fFOV );
7049}
7150
7251void CCameraRPCs::SetCameraTarget (NetBitStreamInterface& bitStream)
7352{
74- if (!m_pCamera)
75- return ;
76-
7753 if (bitStream.Version () >= 0x5E )
7854 {
7955 uchar ucTimeContext;
80- if (!bitStream.Read (ucTimeContext))
81- {
82- return ;
83- }
84- m_pCamera->SetSyncTimeContext (ucTimeContext);
56+ if (bitStream.Read (ucTimeContext))
57+ m_pCamera->SetSyncTimeContext (ucTimeContext);
8558 }
8659
8760 ElementID targetID;
88- if (!bitStream.Read (targetID))
89- return ;
90-
91- // Validate camera pointer
92- if (!m_pCamera)
93- return ;
94-
95- CClientEntity* pEntity = CElementIDs::GetElement (targetID);
96- if (!pEntity)
97- return ;
98-
99- // Check if entity is being deleted - critical memory safety check
100- if (pEntity->IsBeingDeleted ())
101- return ;
102-
103- switch (pEntity->GetType ())
61+ if (bitStream.Read (targetID))
10462 {
105- case CCLIENTPLAYER:
63+ CClientEntity* pEntity = CElementIDs::GetElement (targetID);
64+ if (pEntity)
10665 {
107- CClientPlayer* pPlayer = static_cast <CClientPlayer*>(pEntity);
108- if (pPlayer->IsLocalPlayer ())
66+ switch (pEntity->GetType ())
10967 {
110- // Return the focus to the local player
111- m_pCamera->SetFocusToLocalPlayer ();
68+ case CCLIENTPLAYER:
69+ {
70+ CClientPlayer* pPlayer = static_cast <CClientPlayer*>(pEntity);
71+ if (pPlayer->IsLocalPlayer ())
72+ {
73+ // Return the focus to the local player
74+ m_pCamera->SetFocusToLocalPlayer ();
75+ }
76+ else
77+ {
78+ // Put the focus on that player
79+ m_pCamera->SetFocus (pPlayer, MODE_CAM_ON_A_STRING, false );
80+ }
81+ break ;
82+ }
83+ case CCLIENTPED:
84+ case CCLIENTVEHICLE:
85+ {
86+ m_pCamera->SetFocus (pEntity, MODE_CAM_ON_A_STRING, false );
87+ break ;
88+ }
89+ default :
90+ return ;
11291 }
113- else
114- {
115- // Put the focus on that player
116- m_pCamera->SetFocus (pPlayer, MODE_CAM_ON_A_STRING, false );
117- }
118- break ;
119- }
120- case CCLIENTPED:
121- case CCLIENTVEHICLE:
122- {
123- m_pCamera->SetFocus (pEntity, MODE_CAM_ON_A_STRING, false );
124- break ;
12592 }
126- default :
127- // Invalid entity type for camera target
128- return ;
12993 }
13094}
13195
13296void CCameraRPCs::SetCameraInterior (NetBitStreamInterface& bitStream)
13397{
134- // Read out the camera interior
98+ // Read out the camera mode
13599 unsigned char ucInterior;
136- if (!bitStream.Read (ucInterior))
137- return ;
138-
139- // Validate game pointer before use
140- if (g_pGame && g_pGame->GetWorld ())
100+ if (bitStream.Read (ucInterior))
141101 {
142102 g_pGame->GetWorld ()->SetCurrentArea (ucInterior);
143103 }
@@ -147,41 +107,26 @@ void CCameraRPCs::FadeCamera(NetBitStreamInterface& bitStream)
147107{
148108 unsigned char ucFadeIn;
149109 float fFadeTime = 1 .0f ;
150-
151- if (!bitStream.Read (ucFadeIn) || !bitStream.Read (fFadeTime ))
152- return ;
153-
154- // Validate pointers before use
155- if (!m_pCamera || !g_pClientGame)
156- return ;
157-
158- g_pClientGame->SetInitiallyFadedOut (false );
159-
160- if (ucFadeIn)
110+ if (bitStream.Read (ucFadeIn) && bitStream.Read (fFadeTime ))
161111 {
162- m_pCamera->FadeIn (fFadeTime );
163-
164- // Validate game and HUD pointers
165- if (g_pGame && g_pGame->GetHud ())
112+ g_pClientGame->SetInitiallyFadedOut (false );
113+
114+ if (ucFadeIn)
166115 {
116+ m_pCamera->FadeIn (fFadeTime );
167117 g_pGame->GetHud ()->SetComponentVisible (HUD_AREA_NAME, !g_pClientGame->GetHudAreaNameDisabled ());
168118 }
169- }
170- else
171- {
172- unsigned char ucRed = 0 ;
173- unsigned char ucGreen = 0 ;
174- unsigned char ucBlue = 0 ;
175-
176- if (!bitStream.Read (ucRed) || !bitStream.Read (ucGreen) || !bitStream.Read (ucBlue))
177- return ;
178-
179- m_pCamera->FadeOut (fFadeTime , ucRed, ucGreen, ucBlue);
180-
181- // Validate game and HUD pointers
182- if (g_pGame && g_pGame->GetHud ())
119+ else
183120 {
184- g_pGame->GetHud ()->SetComponentVisible (HUD_AREA_NAME, false );
121+ unsigned char ucRed = 0 ;
122+ unsigned char ucGreen = 0 ;
123+ unsigned char ucBlue = 0 ;
124+
125+ if (bitStream.Read (ucRed) && bitStream.Read (ucGreen) && bitStream.Read (ucBlue))
126+ {
127+ m_pCamera->FadeOut (fFadeTime , ucRed, ucGreen, ucBlue);
128+ g_pGame->GetHud ()->SetComponentVisible (HUD_AREA_NAME, false );
129+ }
185130 }
186131 }
187132}
0 commit comments