11
11
#include " CClient2DFXManager.h"
12
12
13
13
#define mask (n ) ((1 << (n)) - 1 )
14
+ static constexpr std::size_t roadsignTextSize = 64 ;
14
15
15
16
CClient2DFXManager::CClient2DFXManager (CClientManager* mainManager) : m_mainManager(mainManager)
16
17
{
@@ -68,134 +69,22 @@ bool CClient2DFXManager::Set2DFXProperties(C2DEffectSAInterface* effect, const e
68
69
if (!effect)
69
70
return false ;
70
71
71
- // Set properties
72
- switch (effect->type )
73
- {
74
- case e2dEffectType::LIGHT:
75
- {
76
- t2dEffectLight& light = effect->effect .light ;
77
-
78
- auto * drawDistance = MapFind (effectData, " drawDistance" );
79
- light.coronaFarClip = std::get<float >(*drawDistance);
80
-
81
- auto * lightRange = MapFind (effectData, " lightRange" );
82
- light.pointLightRange = std::get<float >(*lightRange);
83
-
84
- auto * coronaSize = MapFind (effectData, " coronaSize" );
85
- light.coronaSize = std::get<float >(*coronaSize);
86
-
87
- auto * shadowSize = MapFind (effectData, " shadowSize" );
88
- light.shadowSize = std::get<float >(*shadowSize);
89
-
90
- auto * shadowMultiplier = MapFind (effectData, " shadowMultiplier" );
91
- light.shadowColorMultiplier = static_cast <std::uint8_t >(std::get<float >(*shadowMultiplier));
92
-
93
- auto * showMode = MapFind (effectData, " showMode" );
94
- e2dCoronaFlashType flashType;
95
- StringToEnum (std::get<std::string>(*showMode), flashType);
96
- light.coronaFlashType = flashType;
97
-
98
- auto * coronaReflection = MapFind (effectData, " coronaReflection" );
99
- light.coronaEnableReflection = std::get<bool >(*coronaReflection);
100
-
101
- auto * coronaFlareType = MapFind (effectData, " flareType" );
102
- light.coronaFlareType = static_cast <std::uint8_t >(std::get<float >(*coronaFlareType));
103
-
104
- auto * flags = MapFind (effectData, " flags" );
105
- light.flags = static_cast <std::uint16_t >(std::get<float >(*flags));
106
-
107
- auto * shadowZDistance = MapFind (effectData, " shadowDistance" );
108
- light.shadowZDistance = static_cast <std::int8_t >(std::get<float >(*shadowZDistance));
109
-
110
- auto * offsetX = MapFind (effectData, " offsetX" );
111
- light.offsetX = static_cast <std::int8_t >(std::get<float >(*offsetX));
112
-
113
- auto * offsetY = MapFind (effectData, " offsetY" );
114
- light.offsetY = static_cast <std::int8_t >(std::get<float >(*offsetY));
115
-
116
- auto * offsetZ = MapFind (effectData, " offsetZ" );
117
- light.offsetZ = static_cast <std::int8_t >(std::get<float >(*offsetZ));
118
-
119
- auto * color = MapFind (effectData, " color" );
120
- unsigned long colorValue = static_cast <unsigned long >(std::get<float >(*color));
121
- light.color = RwColor{static_cast <std::uint8_t >((colorValue >> 16 ) & mask (8 )), static_cast <std::uint8_t >((colorValue >> 8 ) & mask (8 )), static_cast <std::uint8_t >((colorValue >> 0 ) & mask (8 )), static_cast <std::uint8_t >((colorValue >> 24 ) & mask (8 ))};
72
+ bool success = true ;
122
73
123
- auto * coronaTexture = MapFind (effectData, " coronaName" );
124
- auto * shadowTexture = MapFind (effectData, " shadowName" );
125
- PrepareTexturesForLightEffect (light.coronaTex , light.shadowTex , std::get<std::string>(*coronaTexture).c_str (), std::get<std::string>(*shadowTexture).c_str (), true );
126
- break ;
127
- }
128
- case e2dEffectType::PARTICLE:
74
+ for (const auto & [k, v] : effectData)
75
+ {
76
+ e2dEffectProperty property;
77
+ if (!StringToEnum (k, property))
129
78
{
130
- auto * particleName = MapFind (effectData, " name" );
131
- std::strncpy (effect->effect .particle .szName , std::get<std::string>(*particleName).c_str (), sizeof (effect->effect .particle .szName ) - 1 );
132
-
133
- break ;
79
+ success = false ;
80
+ continue ;
134
81
}
135
- case e2dEffectType::ROADSIGN:
136
- {
137
- t2dEffectRoadsign& roadsign = effect->effect .roadsign ;
138
-
139
- auto * sizeX = MapFind (effectData, " sizeX" );
140
- auto * sizeY = MapFind (effectData, " sizeY" );
141
- roadsign.size = RwV2d{std::get<float >(*sizeX), std::get<float >(*sizeY)};
142
82
143
- auto * rotX = MapFind (effectData, " rotX" );
144
- auto * rotY = MapFind (effectData, " rotY" );
145
- auto * rotZ = MapFind (effectData, " rotZ" );
146
- roadsign.rotation = RwV3d{std::get<float >(*rotX), std::get<float >(*rotY), std::get<float >(*rotZ)};
147
-
148
- auto * flags = MapFind (effectData, " flags" );
149
- roadsign.flags = static_cast <std::uint8_t >(std::get<float >(*flags));
150
-
151
- auto * text = MapFind (effectData, " text" );
152
- auto * text2 = MapFind (effectData, " text2" );
153
- auto * text3 = MapFind (effectData, " text3" );
154
- auto * text4 = MapFind (effectData, " text4" );
155
-
156
- roadsign.text = static_cast <char *>(malloc (64 ));
157
- if (roadsign.text )
158
- {
159
- std::memcpy (roadsign.text , std::get<std::string>(*text).c_str (), 4 );
160
- std::memcpy (roadsign.text + 4 , std::get<std::string>(*text2).c_str (), 4 );
161
- std::memcpy (roadsign.text + 8 , std::get<std::string>(*text3).c_str (), 4 );
162
- std::memcpy (roadsign.text + 12 , std::get<std::string>(*text4).c_str (), 4 );
163
- }
164
-
165
- roadsign.atomic = nullptr ;
166
-
167
- break ;
168
- }
169
- case e2dEffectType::ESCALATOR:
170
- {
171
- t2dEffectEscalator& escalator = effect->effect .escalator ;
172
-
173
- auto * bottomX = MapFind (effectData, " bottomX" );
174
- auto * bottomY = MapFind (effectData, " bottomY" );
175
- auto * bottomZ = MapFind (effectData, " bottomZ" );
176
- escalator.bottom = RwV3d{std::get<float >(*bottomX), std::get<float >(*bottomY), std::get<float >(*bottomZ)};
177
-
178
- auto * topX = MapFind (effectData, " topX" );
179
- auto * topY = MapFind (effectData, " topY" );
180
- auto * topZ = MapFind (effectData, " topZ" );
181
- escalator.top = RwV3d{std::get<float >(*topX), std::get<float >(*topY), std::get<float >(*topZ)};
182
-
183
- auto * endX = MapFind (effectData, " endX" );
184
- auto * endY = MapFind (effectData, " endY" );
185
- auto * endZ = MapFind (effectData, " endZ" );
186
- escalator.end = RwV3d{std::get<float >(*endX), std::get<float >(*endY), std::get<float >(*endZ)};
187
-
188
- auto * dir = MapFind (effectData, " direction" );
189
- escalator.direction = static_cast <std::uint8_t >(std::get<float >(*dir));
190
-
191
- break ;
192
- }
193
- case e2dEffectType::SUN_GLARE: // This effect has no properties but works in MTA
194
- default :
195
- break ;
83
+ if (!Set2DFXProperty (effect, property, v))
84
+ success = false ;
196
85
}
197
86
198
- return true ;
87
+ return success ;
199
88
}
200
89
201
90
effectDataMap CClient2DFXManager::Get2DFXProperties (C2DEffectSAInterface* effect) const
@@ -276,7 +165,7 @@ effectDataMap CClient2DFXManager::Get2DFXProperties(C2DEffectSAInterface* effect
276
165
return properties;
277
166
}
278
167
279
- bool CClient2DFXManager::Set2DFXProperty (C2DEffectSAInterface* effect, const e2dEffectProperty& property, const std::variant<float , bool , std::string>& propertyValue)
168
+ bool CClient2DFXManager::Set2DFXProperty (C2DEffectSAInterface* effect, const e2dEffectProperty& property, const std::variant<bool , float , std::string>& propertyValue)
280
169
{
281
170
if (!effect)
282
171
return false ;
@@ -366,7 +255,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
366
255
}
367
256
break ;
368
257
}
369
- case e2dEffectProperty::CORONA_FLAGS :
258
+ case e2dEffectProperty::FLAGS :
370
259
{
371
260
if (std::holds_alternative<float >(propertyValue))
372
261
{
@@ -431,7 +320,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
431
320
e2dEffectTextureName coronaName;
432
321
if (StringToEnum (std::get<std::string>(propertyValue), coronaName))
433
322
{
434
- PrepareTexturesForLightEffect (light.coronaTex , light.shadowTex , std::get<std::string>(propertyValue).c_str (), light.shadowTex ->name , true );
323
+ PrepareTexturesForLightEffect (light.coronaTex , light.shadowTex , std::get<std::string>(propertyValue).c_str (), light.shadowTex ? light. shadowTex ->name : nullptr , true );
435
324
return true ;
436
325
}
437
326
}
@@ -445,7 +334,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
445
334
e2dEffectTextureName shadowName;
446
335
if (StringToEnum (std::get<std::string>(propertyValue), shadowName))
447
336
{
448
- PrepareTexturesForLightEffect (light.coronaTex , light.shadowTex , light.coronaTex ->name , std::get<std::string>(propertyValue).c_str (), true );
337
+ PrepareTexturesForLightEffect (light.coronaTex , light.shadowTex , light.coronaTex ? light. coronaTex ->name : nullptr , std::get<std::string>(propertyValue).c_str (), true );
449
338
return true ;
450
339
}
451
340
}
@@ -465,6 +354,8 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
465
354
if (std::holds_alternative<std::string>(propertyValue))
466
355
{
467
356
std::strncpy (effect->effect .particle .szName , std::get<std::string>(propertyValue).c_str (), sizeof (effect->effect .particle .szName ) - 1 );
357
+ effect->effect .particle .szName [sizeof (effect->effect .particle .szName ) - 1 ] = ' \0 ' ;
358
+
468
359
return true ;
469
360
}
470
361
}
@@ -527,7 +418,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
527
418
528
419
break ;
529
420
}
530
- case e2dEffectProperty::ROADSIGN_FLAGS :
421
+ case e2dEffectProperty::FLAGS :
531
422
{
532
423
if (std::holds_alternative<float >(propertyValue))
533
424
{
@@ -542,9 +433,13 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
542
433
if (std::holds_alternative<std::string>(propertyValue))
543
434
{
544
435
if (!roadsign.text )
545
- roadsign.text = static_cast <char *>(malloc (64 ));
436
+ roadsign.text = static_cast <char *>(malloc (roadsignTextSize));
437
+
438
+ if (!roadsign.text )
439
+ break ;
546
440
547
441
std::memcpy (roadsign.text , std::get<std::string>(propertyValue).c_str (), 4 );
442
+ roadsign.text [roadsignTextSize - 1 ] = ' \0 ' ;
548
443
return true ;
549
444
}
550
445
@@ -555,9 +450,13 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
555
450
if (std::holds_alternative<std::string>(propertyValue))
556
451
{
557
452
if (!roadsign.text )
558
- roadsign.text = static_cast <char *>(malloc (64 ));
453
+ roadsign.text = static_cast <char *>(malloc (roadsignTextSize));
454
+
455
+ if (!roadsign.text )
456
+ break ;
559
457
560
458
std::memcpy (roadsign.text + 4 , std::get<std::string>(propertyValue).c_str (), 4 );
459
+ roadsign.text [roadsignTextSize - 1 ] = ' \0 ' ;
561
460
return true ;
562
461
}
563
462
@@ -568,9 +467,13 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
568
467
if (std::holds_alternative<std::string>(propertyValue))
569
468
{
570
469
if (!roadsign.text )
571
- roadsign.text = static_cast <char *>(malloc (64 ));
470
+ roadsign.text = static_cast <char *>(malloc (roadsignTextSize));
471
+
472
+ if (!roadsign.text )
473
+ break ;
572
474
573
475
std::memcpy (roadsign.text + 8 , std::get<std::string>(propertyValue).c_str (), 4 );
476
+ roadsign.text [roadsignTextSize - 1 ] = ' \0 ' ;
574
477
return true ;
575
478
}
576
479
@@ -581,9 +484,13 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
581
484
if (std::holds_alternative<std::string>(propertyValue))
582
485
{
583
486
if (!roadsign.text )
584
- roadsign.text = static_cast <char *>(malloc (64 ));
487
+ roadsign.text = static_cast <char *>(malloc (roadsignTextSize));
488
+
489
+ if (!roadsign.text )
490
+ break ;
585
491
586
492
std::memcpy (roadsign.text + 12 , std::get<std::string>(propertyValue).c_str (), 4 );
493
+ roadsign.text [roadsignTextSize - 1 ] = ' \0 ' ;
587
494
return true ;
588
495
}
589
496
@@ -740,7 +647,7 @@ std::variant<float, bool, std::string> CClient2DFXManager::Get2DFXProperty(C2DEf
740
647
return light.coronaEnableReflection ;
741
648
case e2dEffectProperty::FLARE_TYPE:
742
649
return static_cast <float >(light.coronaFlareType );
743
- case e2dEffectProperty::CORONA_FLAGS :
650
+ case e2dEffectProperty::FLAGS :
744
651
return static_cast <float >(light.flags );
745
652
case e2dEffectProperty::SHADOW_DISTANCE:
746
653
return static_cast <float >(light.shadowZDistance );
@@ -786,7 +693,7 @@ std::variant<float, bool, std::string> CClient2DFXManager::Get2DFXProperty(C2DEf
786
693
return roadsign.rotation .y ;
787
694
case e2dEffectProperty::ROT_Z:
788
695
return roadsign.rotation .z ;
789
- case e2dEffectProperty::ROADSIGN_FLAGS :
696
+ case e2dEffectProperty::FLAGS :
790
697
return static_cast <float >(roadsign.flags );
791
698
case e2dEffectProperty::TEXT:
792
699
case e2dEffectProperty::TEXT_2:
@@ -1018,7 +925,7 @@ const char* CClient2DFXManager::IsValidEffectData(const e2dEffectType& effectTyp
1018
925
return " Invalid \" endZ\" value" ;
1019
926
1020
927
auto * direction = MapFind (effectData, " direction" );
1021
- if (!direction || !std::holds_alternative<float >(*direction) || (std::get<float >(*direction) < 0 || std::get<float >(*direction) > 1 .0f ))
928
+ if (!direction || !std::holds_alternative<float >(*direction) || (std::get<float >(*direction) < 0 . 0f || std::get<float >(*direction) > 1 .0f ))
1022
929
return " Invalid \" direction\" value" ;
1023
930
1024
931
break ;
0 commit comments