@@ -23,75 +23,97 @@ void CCameraRPCs::LoadFunctions()
23
23
void CCameraRPCs::SetCameraMatrix (NetBitStreamInterface& bitStream)
24
24
{
25
25
uchar ucTimeContext;
26
- if (bitStream.Read (ucTimeContext))
26
+ if (!bitStream.Read (ucTimeContext))
27
+ return ;
28
+
29
+ if (m_pCamera)
27
30
m_pCamera->SetSyncTimeContext (ucTimeContext);
28
31
29
32
CVector vecPosition, vecLookAt;
30
33
float fRoll = 0 .0f ;
31
34
float fFOV = 70 .0f ;
32
- if (bitStream.Read (vecPosition.fX ) && bitStream.Read (vecPosition.fY ) && bitStream.Read (vecPosition.fZ ) && bitStream.Read (vecLookAt.fX ) &&
33
- bitStream.Read (vecLookAt.fY ) && bitStream.Read (vecLookAt.fZ ))
35
+
36
+ if (!bitStream.Read (vecPosition.fX ) || !bitStream.Read (vecPosition.fY ) || !bitStream.Read (vecPosition.fZ ) ||
37
+ !bitStream.Read (vecLookAt.fX ) || !bitStream.Read (vecLookAt.fY ) || !bitStream.Read (vecLookAt.fZ ))
34
38
{
35
- bitStream. Read ( fRoll );
36
- bitStream. Read ( fFOV );
39
+ return ; // Invalid data
40
+ }
37
41
38
- if (!m_pCamera-> IsInFixedMode ())
39
- m_pCamera-> ToggleCameraFixedMode ( true );
42
+ bitStream. Read ( fRoll );
43
+ bitStream. Read ( fFOV );
40
44
41
- // Put the camera there
42
- m_pCamera->SetPosition (vecPosition);
43
- m_pCamera->SetFixedTarget (vecLookAt, fRoll );
44
- m_pCamera->SetFOV (fFOV );
45
- }
45
+ // Validate camera pointer before use
46
+ if (!m_pCamera)
47
+ return ;
48
+
49
+ if (!m_pCamera->IsInFixedMode ())
50
+ m_pCamera->ToggleCameraFixedMode (true );
51
+
52
+ // Put the camera there
53
+ m_pCamera->SetPosition (vecPosition);
54
+ m_pCamera->SetFixedTarget (vecLookAt, fRoll );
55
+ m_pCamera->SetFOV (fFOV );
46
56
}
47
57
48
58
void CCameraRPCs::SetCameraTarget (NetBitStreamInterface& bitStream)
49
59
{
50
60
uchar ucTimeContext;
51
- if (bitStream.Read (ucTimeContext))
61
+ if (!bitStream.Read (ucTimeContext))
62
+ return ;
63
+
64
+ if (m_pCamera)
52
65
m_pCamera->SetSyncTimeContext (ucTimeContext);
53
66
54
67
ElementID targetID;
55
- if (bitStream.Read (targetID))
68
+ if (!bitStream.Read (targetID))
69
+ return ;
70
+
71
+ // Validate camera pointer
72
+ if (!m_pCamera)
73
+ return ;
74
+
75
+ CClientEntity* pEntity = CElementIDs::GetElement (targetID);
76
+ if (!pEntity)
77
+ return ;
78
+
79
+ switch (pEntity->GetType ())
56
80
{
57
- CClientEntity* pEntity = CElementIDs::GetElement (targetID);
58
- if (pEntity)
81
+ case CCLIENTPLAYER:
59
82
{
60
- switch (pEntity->GetType ())
83
+ CClientPlayer* pPlayer = static_cast <CClientPlayer*>(pEntity);
84
+ if (pPlayer->IsLocalPlayer ())
85
+ {
86
+ // Return the focus to the local player
87
+ m_pCamera->SetFocusToLocalPlayer ();
88
+ }
89
+ else
61
90
{
62
- case CCLIENTPLAYER:
63
- {
64
- CClientPlayer* pPlayer = static_cast <CClientPlayer*>(pEntity);
65
- if (pPlayer->IsLocalPlayer ())
66
- {
67
- // Return the focus to the local player
68
- m_pCamera->SetFocusToLocalPlayer ();
69
- }
70
- else
71
- {
72
- // Put the focus on that player
73
- m_pCamera->SetFocus (pPlayer, MODE_CAM_ON_A_STRING, false );
74
- }
75
- break ;
76
- }
77
- case CCLIENTPED:
78
- case CCLIENTVEHICLE:
79
- {
80
- m_pCamera->SetFocus (pEntity, MODE_CAM_ON_A_STRING, false );
81
- break ;
82
- }
83
- default :
84
- return ;
91
+ // Put the focus on that player
92
+ m_pCamera->SetFocus (pPlayer, MODE_CAM_ON_A_STRING, false );
85
93
}
94
+ break ;
86
95
}
96
+ case CCLIENTPED:
97
+ case CCLIENTVEHICLE:
98
+ {
99
+ m_pCamera->SetFocus (pEntity, MODE_CAM_ON_A_STRING, false );
100
+ break ;
101
+ }
102
+ default :
103
+ // Invalid entity type for camera target
104
+ return ;
87
105
}
88
106
}
89
107
90
108
void CCameraRPCs::SetCameraInterior (NetBitStreamInterface& bitStream)
91
109
{
92
- // Read out the camera mode
110
+ // Read out the camera interior
93
111
unsigned char ucInterior;
94
- if (bitStream.Read (ucInterior))
112
+ if (!bitStream.Read (ucInterior))
113
+ return ;
114
+
115
+ // Validate game pointer before use
116
+ if (g_pGame && g_pGame->GetWorld ())
95
117
{
96
118
g_pGame->GetWorld ()->SetCurrentArea (ucInterior);
97
119
}
@@ -101,26 +123,41 @@ void CCameraRPCs::FadeCamera(NetBitStreamInterface& bitStream)
101
123
{
102
124
unsigned char ucFadeIn;
103
125
float fFadeTime = 1 .0f ;
104
- if (bitStream.Read (ucFadeIn) && bitStream.Read (fFadeTime ))
105
- {
106
- g_pClientGame->SetInitiallyFadedOut (false );
126
+
127
+ if (!bitStream.Read (ucFadeIn) || !bitStream.Read (fFadeTime ))
128
+ return ;
129
+
130
+ // Validate pointers before use
131
+ if (!m_pCamera || !g_pClientGame)
132
+ return ;
133
+
134
+ g_pClientGame->SetInitiallyFadedOut (false );
107
135
108
- if (ucFadeIn)
136
+ if (ucFadeIn)
137
+ {
138
+ m_pCamera->FadeIn (fFadeTime );
139
+
140
+ // Validate game and HUD pointers
141
+ if (g_pGame && g_pGame->GetHud ())
109
142
{
110
- m_pCamera->FadeIn (fFadeTime );
111
143
g_pGame->GetHud ()->SetComponentVisible (HUD_AREA_NAME, !g_pClientGame->GetHudAreaNameDisabled ());
112
144
}
113
- else
114
- {
115
- unsigned char ucRed = 0 ;
116
- unsigned char ucGreen = 0 ;
117
- unsigned char ucBlue = 0 ;
145
+ }
146
+ else
147
+ {
148
+ unsigned char ucRed = 0 ;
149
+ unsigned char ucGreen = 0 ;
150
+ unsigned char ucBlue = 0 ;
118
151
119
- if (bitStream.Read (ucRed) && bitStream.Read (ucGreen) && bitStream.Read (ucBlue))
120
- {
121
- m_pCamera->FadeOut (fFadeTime , ucRed, ucGreen, ucBlue);
122
- g_pGame->GetHud ()->SetComponentVisible (HUD_AREA_NAME, false );
123
- }
152
+ if (!bitStream.Read (ucRed) || !bitStream.Read (ucGreen) || !bitStream.Read (ucBlue))
153
+ return ;
154
+
155
+ m_pCamera->FadeOut (fFadeTime , ucRed, ucGreen, ucBlue);
156
+
157
+ // Validate game and HUD pointers
158
+ if (g_pGame && g_pGame->GetHud ())
159
+ {
160
+ g_pGame->GetHud ()->SetComponentVisible (HUD_AREA_NAME, false );
124
161
}
125
162
}
126
163
}
0 commit comments