Skip to content

Commit 0f8cbc1

Browse files
committed
Cleanup 1/2
1 parent a26b3e6 commit 0f8cbc1

File tree

8 files changed

+58
-150
lines changed

8 files changed

+58
-150
lines changed

Client/game_sa/C2DEffectSAInterface.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,19 @@ static void PrepareTexturesForLightEffect(RwTexture*& coronaTex, RwTexture*& sha
288288
{
289289
using RwTextureDestroy = void(__cdecl*)(RwTexture*);
290290

291-
if (coronaTex)
291+
if (coronaTex && coronaName)
292292
((RwTextureDestroy)FUNC_RwTextureDestroy)(coronaTex);
293-
if (shadowTex)
293+
if (shadowTex && shadowName)
294294
((RwTextureDestroy)FUNC_RwTextureDestroy)(shadowTex);
295295
}
296296

297297
// Call RwReadTexture
298298
using RwReadTexture = RwTexture*(__cdecl*)(const char*, const char*);
299-
coronaTex = ((RwReadTexture)FUNC_RwReadTexture)(coronaName, nullptr);
300-
shadowTex = ((RwReadTexture)FUNC_RwReadTexture)(shadowName, nullptr);
299+
if (coronaName)
300+
coronaTex = ((RwReadTexture)FUNC_RwReadTexture)(coronaName, nullptr);
301+
302+
if (shadowName)
303+
shadowTex = ((RwReadTexture)FUNC_RwReadTexture)(shadowName, nullptr);
301304

302305
// Call CTxdStore::PopCurrentTxd
303306
((void(__cdecl*)())FUNC_PopCurrentTxd)();

Client/game_sa/CModelInfoSA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,9 +2175,10 @@ bool CModelInfoSA::Reset2DFXEffects(bool removeCustomEffects)
21752175
it = map.erase(it);
21762176
}
21772177

2178-
// Clear both maps
2178+
// Clear maps
21792179
map.clear();
21802180
ms_DefaultEffectsMap.clear();
2181+
removedDefaultEffects.clear();
21812182

21822183
// Remove all custom effects
21832184
if (removeCustomEffects)
@@ -2352,7 +2353,6 @@ bool CModelInfoSA::RemoveAll2DFXEffects(bool includeDefault)
23522353
return false;
23532354

23542355
std::uint32_t numEffects = m_pInterface->ucNumOf2DEffects;
2355-
23562356
for (std::uint32_t i = 0; i < numEffects; i++)
23572357
{
23582358
C2DEffectSAInterface* effect = Get2DFXFromIndex(i);

Client/mods/deathmatch/logic/CClient2DFXManager.cpp

Lines changed: 41 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "CClient2DFXManager.h"
1212

1313
#define mask(n) ((1 << (n)) - 1)
14+
static constexpr std::size_t roadsignTextSize = 64;
1415

1516
CClient2DFXManager::CClient2DFXManager(CClientManager* mainManager) : m_mainManager(mainManager)
1617
{
@@ -68,134 +69,22 @@ bool CClient2DFXManager::Set2DFXProperties(C2DEffectSAInterface* effect, const e
6869
if (!effect)
6970
return false;
7071

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;
12273

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))
12978
{
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;
13481
}
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)};
14282

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;
19685
}
19786

198-
return true;
87+
return success;
19988
}
20089

20190
effectDataMap CClient2DFXManager::Get2DFXProperties(C2DEffectSAInterface* effect) const
@@ -276,7 +165,7 @@ effectDataMap CClient2DFXManager::Get2DFXProperties(C2DEffectSAInterface* effect
276165
return properties;
277166
}
278167

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)
280169
{
281170
if (!effect)
282171
return false;
@@ -366,7 +255,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
366255
}
367256
break;
368257
}
369-
case e2dEffectProperty::CORONA_FLAGS:
258+
case e2dEffectProperty::FLAGS:
370259
{
371260
if (std::holds_alternative<float>(propertyValue))
372261
{
@@ -431,7 +320,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
431320
e2dEffectTextureName coronaName;
432321
if (StringToEnum(std::get<std::string>(propertyValue), coronaName))
433322
{
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);
435324
return true;
436325
}
437326
}
@@ -445,7 +334,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
445334
e2dEffectTextureName shadowName;
446335
if (StringToEnum(std::get<std::string>(propertyValue), shadowName))
447336
{
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);
449338
return true;
450339
}
451340
}
@@ -465,6 +354,8 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
465354
if (std::holds_alternative<std::string>(propertyValue))
466355
{
467356
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+
468359
return true;
469360
}
470361
}
@@ -527,7 +418,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
527418

528419
break;
529420
}
530-
case e2dEffectProperty::ROADSIGN_FLAGS:
421+
case e2dEffectProperty::FLAGS:
531422
{
532423
if (std::holds_alternative<float>(propertyValue))
533424
{
@@ -542,9 +433,13 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
542433
if (std::holds_alternative<std::string>(propertyValue))
543434
{
544435
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;
546440

547441
std::memcpy(roadsign.text, std::get<std::string>(propertyValue).c_str(), 4);
442+
roadsign.text[roadsignTextSize - 1] = '\0';
548443
return true;
549444
}
550445

@@ -555,9 +450,13 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
555450
if (std::holds_alternative<std::string>(propertyValue))
556451
{
557452
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;
559457

560458
std::memcpy(roadsign.text + 4, std::get<std::string>(propertyValue).c_str(), 4);
459+
roadsign.text[roadsignTextSize - 1] = '\0';
561460
return true;
562461
}
563462

@@ -568,9 +467,13 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
568467
if (std::holds_alternative<std::string>(propertyValue))
569468
{
570469
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;
572474

573475
std::memcpy(roadsign.text + 8, std::get<std::string>(propertyValue).c_str(), 4);
476+
roadsign.text[roadsignTextSize - 1] = '\0';
574477
return true;
575478
}
576479

@@ -581,9 +484,13 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
581484
if (std::holds_alternative<std::string>(propertyValue))
582485
{
583486
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;
585491

586492
std::memcpy(roadsign.text + 12, std::get<std::string>(propertyValue).c_str(), 4);
493+
roadsign.text[roadsignTextSize - 1] = '\0';
587494
return true;
588495
}
589496

@@ -740,7 +647,7 @@ std::variant<float, bool, std::string> CClient2DFXManager::Get2DFXProperty(C2DEf
740647
return light.coronaEnableReflection;
741648
case e2dEffectProperty::FLARE_TYPE:
742649
return static_cast<float>(light.coronaFlareType);
743-
case e2dEffectProperty::CORONA_FLAGS:
650+
case e2dEffectProperty::FLAGS:
744651
return static_cast<float>(light.flags);
745652
case e2dEffectProperty::SHADOW_DISTANCE:
746653
return static_cast<float>(light.shadowZDistance);
@@ -786,7 +693,7 @@ std::variant<float, bool, std::string> CClient2DFXManager::Get2DFXProperty(C2DEf
786693
return roadsign.rotation.y;
787694
case e2dEffectProperty::ROT_Z:
788695
return roadsign.rotation.z;
789-
case e2dEffectProperty::ROADSIGN_FLAGS:
696+
case e2dEffectProperty::FLAGS:
790697
return static_cast<float>(roadsign.flags);
791698
case e2dEffectProperty::TEXT:
792699
case e2dEffectProperty::TEXT_2:
@@ -1018,7 +925,7 @@ const char* CClient2DFXManager::IsValidEffectData(const e2dEffectType& effectTyp
1018925
return "Invalid \"endZ\" value";
1019926

1020927
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))
1022929
return "Invalid \"direction\" value";
1023930

1024931
break;

Client/mods/deathmatch/logic/CClient2DFXManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CClient2DFXManager
2727
bool Set2DFXProperties(C2DEffectSAInterface* effect, const effectDataMap& effectData);
2828
effectDataMap Get2DFXProperties(C2DEffectSAInterface* effect) const;
2929

30-
bool Set2DFXProperty(C2DEffectSAInterface* effect, const e2dEffectProperty& property, const std::variant<float, bool, std::string>& propertyValue);
30+
bool Set2DFXProperty(C2DEffectSAInterface* effect, const e2dEffectProperty& property, const std::variant<bool, float, std::string>& propertyValue);
3131
std::variant<float, bool, std::string> Get2DFXProperty(C2DEffectSAInterface* effect, const e2dEffectProperty& property);
3232

3333
void Set2DFXPosition(C2DEffectSAInterface* effect, const CVector& position);

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,14 +984,14 @@ ADD_ENUM(e2dEffectProperty::SHADOW_MULT, "shadowMultiplier")
984984
ADD_ENUM(e2dEffectProperty::FLASH_TYPE, "showMode")
985985
ADD_ENUM(e2dEffectProperty::CORONA_REFLECTION, "coronaReflection")
986986
ADD_ENUM(e2dEffectProperty::FLARE_TYPE, "flareType")
987-
ADD_ENUM(e2dEffectProperty::CORONA_FLAGS, "flags")
988987
ADD_ENUM(e2dEffectProperty::SHADOW_DISTANCE, "shadowDistance")
989988
ADD_ENUM(e2dEffectProperty::OFFSET_X, "offsetX")
990989
ADD_ENUM(e2dEffectProperty::OFFSET_Y, "offsetY")
991990
ADD_ENUM(e2dEffectProperty::OFFSET_Z, "offsetZ")
992991
ADD_ENUM(e2dEffectProperty::COLOR, "color")
993992
ADD_ENUM(e2dEffectProperty::CORONA_NAME, "coronaName")
994993
ADD_ENUM(e2dEffectProperty::SHADOW_NAME, "shadowName")
994+
ADD_ENUM(e2dEffectProperty::FLAGS, "flags")
995995

996996
ADD_ENUM(e2dEffectProperty::PRT_NAME, "name")
997997

@@ -1000,7 +1000,6 @@ ADD_ENUM(e2dEffectProperty::SIZE_Y, "sizeY")
10001000
ADD_ENUM(e2dEffectProperty::ROT_X, "rotX")
10011001
ADD_ENUM(e2dEffectProperty::ROT_Y, "rotY")
10021002
ADD_ENUM(e2dEffectProperty::ROT_Z, "rotZ")
1003-
ADD_ENUM(e2dEffectProperty::ROADSIGN_FLAGS, "flags")
10041003
ADD_ENUM(e2dEffectProperty::TEXT, "text1")
10051004
ADD_ENUM(e2dEffectProperty::TEXT_2, "text2")
10061005
ADD_ENUM(e2dEffectProperty::TEXT_3, "text3")

Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,7 +2674,7 @@ bool CLuaEngineDefs::EngineSet2DFXProperties(CClient2DFX* effect, effectDataMap
26742674
return m_p2DFXManager->Set2DFXProperties(effect->Get2DFX(), effectData);
26752675
}
26762676

2677-
bool CLuaEngineDefs::EngineSetModel2DFXProperty(std::uint32_t modelID, std::uint32_t index, e2dEffectProperty property, std::variant<float, bool, std::string> propertyValue)
2677+
bool CLuaEngineDefs::EngineSetModel2DFXProperty(std::uint32_t modelID, std::uint32_t index, e2dEffectProperty property, std::variant<bool, float, std::string> propertyValue)
26782678
{
26792679
if (!CClient2DFXManager::IsValidModel(modelID))
26802680
throw std::invalid_argument("Invalid model ID");
@@ -2694,7 +2694,7 @@ bool CLuaEngineDefs::EngineSetModel2DFXProperty(std::uint32_t modelID, std::uint
26942694
return m_p2DFXManager->Set2DFXProperty(effect, property, propertyValue);
26952695
}
26962696

2697-
bool CLuaEngineDefs::EngineSet2DFXProperty(CClient2DFX* effect, e2dEffectProperty property, std::variant<float, bool, std::string> propertyValue)
2697+
bool CLuaEngineDefs::EngineSet2DFXProperty(CClient2DFX* effect, e2dEffectProperty property, std::variant<bool, float, std::string> propertyValue)
26982698
{
26992699
return m_p2DFXManager->Set2DFXProperty(effect->Get2DFX(), property, propertyValue);
27002700
}

0 commit comments

Comments
 (0)