Repository navigation
Expand file tree
/
Copy pathModelExtrasAPI.cpp
More file actions
executable file
·1568 lines (1384 loc) · 53.9 KB
/
Copy pathModelExtrasAPI.cpp
File metadata and controls
executable file
·1568 lines (1384 loc) · 53.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "pch.h"
#include "ModelExtrasAPI.h"
#include "defines.h"
#include "loader.h"
#include "utils/datamgr.h"
#include "utils/modelinfomgr.h"
#include "utils/car.h"
#include "utils/render.h"
#include "features/sirens.h"
#include "features/lights/data.h"
#include "features/lights/manager.h"
#include "features/lights/components/headlight.h"
#include "features/plate.h"
#include "features/carcols.h"
#include "features/dirtfx.h"
#include "features/remap.h"
#include "features/roof.h"
#include "features/spoiler.h"
#include "features/rollbackbed.h"
#include "features/spotlights.h"
#include "features/gauge.h"
#include "features/leds.h"
#include "features/exhausts.h"
#include "features/backfire.h"
#include "features/pedcols.h"
#include "features/soundeffects.h"
#include "features/slidedoor.h"
#include "features/rotatedoor.h"
#include "features/wheel.h"
#include "features/neon.h"
#include "features/wheelhub.h"
#include "features/chain.h"
#include "features/clock.h"
#include "enums/lightingmode.h"
#include "utils/audiomgr.h"
#include <algorithm>
#include <cstring>
namespace {
static void SafeStrCopy(char *dst, int maxLen, const std::string &src) {
if (dst && maxLen > 0) {
strncpy_s(dst, maxLen, src.c_str(), _TRUNCATE);
}
}
}
extern "C" {
// Core & Lifecycle
int ME_GetAPIVersion() { return ME_API_VERSION; }
int ME_GetVersion() { return MOD_VERSION_NUMBER; }
bool ME_IsFeatureAvail(ME_FeatureID featureId) {
auto idx = static_cast<int>(featureId);
if (idx < 0 || idx >= static_cast<int>(eFeatureMatrix::FeatureCount)) {
return false;
}
return ModelExtras::m_bEnabledFeatures.test(idx);
}
bool ME_IsFeatureEnabled(ME_FeatureID featureId) {
auto idx = static_cast<int>(featureId);
if (idx < 0 || idx >= static_cast<int>(eFeatureMatrix::FeatureCount)) {
return false;
}
return CBaseFeature::IsEnabled(static_cast<eFeatureMatrix>(idx));
}
void ME_Reload() {
ModelExtras::Reload();
}
void ME_ReloadVehicle(CVehicle *pVeh) {
if (pVeh) {
for (const auto &pFeature : ModelExtras::m_Features) {
if (pFeature) {
pFeature->Reload(pVeh);
}
}
ModelInfoMgr::Reload(pVeh);
}
}
// Dummy function to show on crash logs
int __declspec(dllexport) ignore1(int i) { return 1; }
// Vehicle Lights API
bool ME_GetVehicleLightState(CVehicle *pVeh, ME_LightID lightId) {
if (!pVeh) return false;
auto matType = static_cast<eMaterialType>(lightId);
if (matType < 0 || matType >= eMaterialType::TotalMaterial) return false;
auto &data = LightManager::m_VehData.Get(pVeh);
return data.bLightStates[matType];
}
void ME_SetVehicleLightState(CVehicle *pVeh, ME_LightID lightId, bool state) {
if (!pVeh) return;
auto matType = static_cast<eMaterialType>(lightId);
if (matType < 0 || matType >= eMaterialType::TotalMaterial) return;
auto &data = LightManager::m_VehData.Get(pVeh);
data.bLightStates[matType] = state;
if (state) {
ModelInfoMgr::EnableMaterial(pVeh, matType);
}
}
bool ME_IsLightAvailable(CVehicle *pVeh, ME_LightID lightId) {
if (!pVeh) return false;
auto matType = static_cast<eMaterialType>(lightId);
return ModelInfoMgr::IsMaterialAvailable(pVeh, matType);
}
int ME_GetIndicatorState(CVehicle *pVeh) {
if (!pVeh) return 0;
auto &data = LightManager::m_VehData.Get(pVeh);
return static_cast<int>(data.nIndicatorState);
}
void ME_SetIndicatorState(CVehicle *pVeh, int state) {
if (!pVeh) return;
if (state < 0 || state > 3) return;
auto &data = LightManager::m_VehData.Get(pVeh);
data.nIndicatorState = static_cast<eIndicatorState>(state);
}
int ME_GetLightOverride(CVehicle *pVeh) {
if (!pVeh) return 0;
return pVeh->m_nOverrideLights;
}
void ME_SetLightOverride(CVehicle *pVeh, int overrideMode) {
if (!pVeh) return;
if (overrideMode >= 0 && overrideMode <= 2) {
pVeh->m_nOverrideLights = static_cast<unsigned char>(overrideMode);
}
}
bool ME_GetFogLights(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = LightManager::m_VehData.Get(pVeh);
return data.bFogLightsOn;
}
void ME_SetFogLights(CVehicle *pVeh, bool on) {
if (!pVeh) return;
auto &data = LightManager::m_VehData.Get(pVeh);
data.bFogLightsOn = on;
if (on) {
ModelInfoMgr::EnableMaterial(pVeh, eMaterialType::FogLightLeft);
ModelInfoMgr::EnableMaterial(pVeh, eMaterialType::FogLightRight);
}
}
float ME_GetLightInertia(CVehicle *pVeh, ME_LightID lightId) {
if (!pVeh) return 0.0f;
auto matType = static_cast<eMaterialType>(lightId);
if (matType < 0 || matType >= eMaterialType::TotalMaterial) return 0.0f;
auto &data = LightManager::m_VehData.Get(pVeh);
return LightManager::GetLightInertia(pVeh, data, matType);
}
bool ME_GetLightColor(CVehicle *pVeh, ME_LightID lightId, ME_Color *onColor, ME_Color *offColor) {
if (!pVeh) return false;
auto matType = static_cast<eMaterialType>(lightId);
if (matType < 0 || matType >= eMaterialType::TotalMaterial) return false;
MatStateColor col = LightManager::GetMaterialColor(pVeh, matType);
if (onColor) *onColor = {col.on.r, col.on.g, col.on.b, col.on.a};
if (offColor) *offColor = {col.off.r, col.off.g, col.off.b, col.off.a};
return true;
}
float ME_GetLightFactor(CVehicle *pVeh, ME_LightID lightId) {
if (!pVeh) return 0.0f;
auto matType = static_cast<eMaterialType>(lightId);
if (matType < 0 || matType >= eMaterialType::TotalMaterial) return 0.0f;
auto &data = LightManager::m_VehData.Get(pVeh);
return data.fLightFactor[matType];
}
int ME_GetLightDummyCount(CVehicle *pVeh, ME_LightID lightId) {
if (!pVeh) return 0;
auto matType = static_cast<eMaterialType>(lightId);
if (matType < 0 || matType >= eMaterialType::TotalMaterial) return 0;
auto &data = LightManager::m_VehData.Get(pVeh);
return static_cast<int>(data.dummies[matType].size());
}
bool ME_GetLightDummyData(CVehicle *pVeh, ME_LightID lightId, int dummyIndex, ME_LightDummyInfo *outInfo) {
if (!pVeh || !outInfo || dummyIndex < 0) return false;
auto matType = static_cast<eMaterialType>(lightId);
if (matType < 0 || matType >= eMaterialType::TotalMaterial) return false;
auto &data = LightManager::m_VehData.Get(pVeh);
if (dummyIndex >= static_cast<int>(data.dummies[matType].size())) return false;
const auto &c = data.dummies[matType][dummyIndex]->GetRef();
outInfo->pFrame = c.frame;
outInfo->pos = c.position;
outInfo->color = {c.corona.color.r, c.corona.color.g, c.corona.color.b, c.corona.color.a};
outInfo->fSize = c.corona.size;
outInfo->fAngle = c.rotation.angle;
outInfo->lightingType = static_cast<int>(c.corona.lightingType);
return true;
}
bool ME_IsLightDamaged(CVehicle *pVeh, ME_LightID lightId, int dummyIndex) {
if (!pVeh) return false;
auto matType = static_cast<eMaterialType>(lightId);
if (matType < 0 || matType >= eMaterialType::TotalMaterial) return false;
auto &data = LightManager::m_VehData.Get(pVeh);
if (dummyIndex >= 0 && dummyIndex < static_cast<int>(data.dummies[matType].size())) {
return CarUtil::IsDummyDamaged(pVeh, data.dummies[matType][dummyIndex]->GetRef());
}
if (matType == eMaterialType::HeadLightLeft) return CarUtil::IsLightDamaged(pVeh, eLights::LIGHT_FRONT_LEFT);
if (matType == eMaterialType::HeadLightRight) return CarUtil::IsLightDamaged(pVeh, eLights::LIGHT_FRONT_RIGHT);
if (matType == eMaterialType::TailLightLeft || matType == eMaterialType::BrakeLightLeft) return CarUtil::IsLightDamaged(pVeh, eLights::LIGHT_REAR_LEFT);
if (matType == eMaterialType::TailLightRight || matType == eMaterialType::BrakeLightRight) return CarUtil::IsLightDamaged(pVeh, eLights::LIGHT_REAR_RIGHT);
return false;
}
bool ME_ArePopUpHeadlightsOpen(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = LightManager::m_VehData.Get(pVeh);
return HeadlightComponent::AreHeadlightsOpen(pVeh, data);
}
bool ME_HasPopUpHeadlights(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = LightManager::m_VehData.Get(pVeh);
if (pVeh->m_nModelIndex == MODEL_ZR350) return true;
return data.bHasVehFuncsPopUp;
}
bool ME_IsLightRendered(CVehicle *pVeh, ME_LightID lightId) {
if (!pVeh) return false;
auto matType = static_cast<eMaterialType>(lightId);
if (matType < 0 || matType >= eMaterialType::TotalMaterial) return false;
auto &data = LightManager::m_VehData.Get(pVeh);
return data.bLightRenderedThisFrame[matType];
}
float ME_GetRealisticSpeed(CVehicle *pVeh) {
if (!pVeh) return 0.0f;
return CarUtil::GetVehicleSpeedRealistic(pVeh);
}
// Sirens API
int ME_GetSirenStateCount(CVehicle *pVeh) {
if (!pVeh) return 0;
auto *pModelData = Sirens::GetModelData(pVeh->m_nModelIndex);
if (!pModelData) return 0;
return static_cast<int>(pModelData->States.size());
}
int ME_GetSirenStateCountByModel(int modelIndex) {
if (modelIndex < 0 || modelIndex >= 20000) return 0;
auto *pModelData = Sirens::GetModelData(modelIndex);
if (!pModelData) return 0;
return static_cast<int>(pModelData->States.size());
}
int ME_GetSirenState(CVehicle *pVeh) {
if (!pVeh) return -1;
auto *pModelData = Sirens::GetModelData(pVeh->m_nModelIndex);
if (!pModelData || pModelData->States.empty()) return -1;
auto *pData = Sirens::GetVehicleData(pVeh);
if (!pData) return -1;
return pData->State;
}
bool ME_SetSirenState(CVehicle *pVeh, int state) {
if (!pVeh) return false;
auto *pModelData = Sirens::GetModelData(pVeh->m_nModelIndex);
if (!pModelData || pModelData->States.empty()) return false;
if (state < 0 || state >= static_cast<int>(pModelData->States.size())) return false;
auto *pData = Sirens::GetVehicleData(pVeh);
if (!pData) return false;
pData->vehicle = pVeh;
pData->State = state;
return true;
}
int ME_GetSirenSoundMode(CVehicle *pVeh) {
if (!pVeh) return -1;
auto *pData = Sirens::GetVehicleData(pVeh);
if (!pData) return -1;
return pData->SoundMode;
}
bool ME_SetSirenSoundMode(CVehicle *pVeh, int soundMode) {
if (!pVeh) return false;
if (soundMode < 0 || soundMode > 8) return false;
auto *pData = Sirens::GetVehicleData(pVeh);
if (!pData) return false;
pData->vehicle = pVeh;
pData->SoundMode = soundMode;
return true;
}
bool ME_GetSirenMute(CVehicle *pVeh) {
if (!pVeh) return false;
auto *pData = Sirens::GetVehicleData(pVeh);
if (!pData) return false;
return pData->Mute;
}
void ME_SetSirenMute(CVehicle *pVeh, bool mute) {
if (!pVeh) return;
auto *pData = Sirens::GetVehicleData(pVeh);
if (!pData) return;
pData->vehicle = pVeh;
pData->Mute = mute;
if (mute) {
pVeh->bSirenOrAlarm = false;
}
}
bool ME_IsSirenActive(CVehicle *pVeh) {
if (!pVeh) return false;
auto *pData = Sirens::GetVehicleData(pVeh);
if (!pData) return false;
return pData->GetSirenState();
}
bool ME_IsSirenVehicle(CVehicle *pVeh) {
if (!pVeh) return false;
return Sirens::IsSirenModel(pVeh->m_nModelIndex);
}
bool ME_IsCustomSirenPlaying(CVehicle *pVeh) {
if (!pVeh) return false;
return Sirens::IsPlayingCustomSiren(pVeh);
}
bool ME_HasSirens(CVehicle *pVeh) {
if (!pVeh) return false;
return Sirens::IsSirenModel(pVeh->m_nModelIndex);
}
int ME_GetSirenSoundState(CVehicle *pVeh) {
if (!pVeh) return -1;
auto *pData = Sirens::GetVehicleData(pVeh);
if (!pData) return -1;
return pData->m_nActiveSirenSoundState;
}
// License Plate API
bool ME_GetPlateText(CVehicle *pVeh, char *outBuffer, int maxLen) {
if (!pVeh || !outBuffer || maxLen <= 0) return false;
auto &data = LicensePlate::m_VehData.Get(pVeh);
if (!data.m_szLastPlateText.empty()) {
strncpy_s(outBuffer, maxLen, data.m_szLastPlateText.c_str(), _TRUNCATE);
return true;
}
return false;
}
bool ME_SetPlateText(CVehicle *pVeh, const char *text) {
if (!pVeh || !text) return false;
auto &data = LicensePlate::m_VehData.Get(pVeh);
data.m_szLastPlateText = text;
return true;
}
bool ME_HasCustomPlate(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = LicensePlate::m_VehData.Get(pVeh);
return data.m_pCustomPlateTex != nullptr || !data.m_szLastPlateText.empty();
}
bool ME_GetPlateColors(CVehicle *pVeh, ME_Color *onColor, ME_Color *offColor) {
if (!pVeh) return false;
if (!DataMgr::Has(pVeh->m_nModelIndex)) return false;
const auto &json = DataMgr::Get(pVeh->m_nModelIndex);
const nlohmann::json *pSec = nullptr;
if (json.contains("plate")) pSec = &json["plate"];
else if (json.contains("license_plate")) pSec = &json["license_plate"];
else if (json.contains("lights")) {
if (json["lights"].contains("plate")) pSec = &json["lights"]["plate"];
else if (json["lights"].contains("license_plate")) pSec = &json["lights"]["license_plate"];
}
if (!pSec) return false;
auto parseCol = [](const nlohmann::json &sec, const char *key, ME_Color *outCol) -> bool {
if (!outCol) return false;
const nlohmann::json *val = nullptr;
if (sec.contains("material") && sec["material"].contains(key)) val = &sec["material"][key];
if (!val) return false;
if (val->is_array() && val->size() >= 3) {
outCol->r = (*val)[0].get<uint8_t>();
outCol->g = (*val)[1].get<uint8_t>();
outCol->b = (*val)[2].get<uint8_t>();
outCol->a = val->size() >= 4 ? (*val)[3].get<uint8_t>() : 255;
return true;
}
if (val->is_object()) {
outCol->r = val->value("red", val->value("r", 255));
outCol->g = val->value("green", val->value("g", 255));
outCol->b = val->value("blue", val->value("b", 255));
outCol->a = val->value("alpha", val->value("a", 255));
return true;
}
return false;
};
bool foundOn = parseCol(*pSec, "color", onColor);
bool foundOff = parseCol(*pSec, "color_off", offColor);
return foundOn || foundOff;
}
int ME_GetPlateCity(CVehicle *pVeh) {
if (!pVeh) return -1;
auto &data = LicensePlate::m_VehData.Get(pVeh);
return data.cityId;
}
void ME_SetPlateCity(CVehicle *pVeh, int cityId) {
if (!pVeh) return;
auto &data = LicensePlate::m_VehData.Get(pVeh);
data.cityId = cityId;
}
bool ME_IsPlateNightIlluminated(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = LicensePlate::m_VehData.Get(pVeh);
return data.m_bNightTexture;
}
// Carcols & Colors API
bool ME_GetVehicleColors(CVehicle *pVeh, ME_Color *col1, ME_Color *col2, ME_Color *col3, ME_Color *col4) {
if (!pVeh) return false;
auto &data = Carcols::m_VehData.Get(pVeh);
if (col1) *col1 = {data.m_Colors.primary.r, data.m_Colors.primary.g, data.m_Colors.primary.b, data.m_Colors.primary.a};
if (col2) *col2 = {data.m_Colors.secondary.r, data.m_Colors.secondary.g, data.m_Colors.secondary.b, data.m_Colors.secondary.a};
if (col3) *col3 = {data.m_Colors.tert.r, data.m_Colors.tert.g, data.m_Colors.tert.b, data.m_Colors.tert.a};
if (col4) *col4 = {data.m_Colors.quart.r, data.m_Colors.quart.g, data.m_Colors.quart.b, data.m_Colors.quart.a};
return true;
}
bool ME_SetVehicleColors(CVehicle *pVeh, ME_Color col1, ME_Color col2, ME_Color col3, ME_Color col4) {
if (!pVeh) return false;
auto &data = Carcols::m_VehData.Get(pVeh);
data.m_Colors.primary = {col1.r, col1.g, col1.b, col1.a};
data.m_Colors.secondary = {col2.r, col2.g, col2.b, col2.a};
data.m_Colors.tert = {col3.r, col3.g, col3.b, col3.a};
data.m_Colors.quart = {col4.r, col4.g, col4.b, col4.a};
data.m_bPri = data.m_bSec = data.m_bTer = data.m_bQuat = true;
return true;
}
int ME_GetCarcolVariationCount(int modelIndex) {
if (modelIndex < 0 || modelIndex >= 20000) return 0;
auto jsonData = DataMgr::Get(modelIndex);
if (jsonData.contains("carcols") && jsonData["carcols"].is_array()) {
return static_cast<int>(jsonData["carcols"].size());
}
return 0;
}
int ME_GetCarcolVariation(CVehicle *pVeh) {
if (!pVeh) return -1;
auto &data = Carcols::m_VehData.Get(pVeh);
return data.randId;
}
bool ME_SetCarcolVariation(CVehicle *pVeh, int variationIndex) {
if (!pVeh || variationIndex < 0) return false;
auto &data = Carcols::m_VehData.Get(pVeh);
data.randId = variationIndex;
return true;
}
// Exhausts & Nitro API
unsigned int ME_GetExhaustCount(CVehicle *pVeh) {
if (!pVeh) return 0;
auto &data = ExhaustFx::m_VehData.Get(pVeh);
return static_cast<unsigned int>(data.m_pDummies.size());
}
ME_ExhaustInfo ME_GetExhaustData(CVehicle *pVeh, int index) {
ME_ExhaustInfo info{};
if (!pVeh) return info;
auto &data = ExhaustFx::m_VehData.Get(pVeh);
if (index >= 0 && index < static_cast<int>(data.m_pDummies.size())) {
const auto &ex = data.m_pDummies[index].second;
info.pFrame = ex.pFrame;
info.Color = {ex.Color.r, ex.Color.g, ex.Color.b, ex.Color.a};
info.fSpeedMul = ex.fSpeedMul;
info.fLifeTime = ex.fLifeTime;
info.fSizeMul = ex.fSizeMul;
info.bNitroEffect = ex.bNitroEffect;
}
return info;
}
void ME_SetExhaustData(CVehicle *pVeh, int index, ME_ExhaustInfo &data) {
if (!pVeh) return;
auto &vData = ExhaustFx::m_VehData.Get(pVeh);
if (index >= 0 && index < static_cast<int>(vData.m_pDummies.size())) {
auto &ex = vData.m_pDummies[index].second;
ex.pFrame = data.pFrame;
ex.Color = {data.Color.r, data.Color.g, data.Color.b, data.Color.a};
ex.fSpeedMul = data.fSpeedMul;
ex.fLifeTime = data.fLifeTime;
ex.fSizeMul = data.fSizeMul;
ex.bNitroEffect = data.bNitroEffect;
}
}
void ME_TriggerNitro(CVehicle *pVeh, bool enable) {
if (!pVeh) return;
if (pVeh->m_nVehicleSubClass == VEHICLE_AUTOMOBILE) {
auto *pAuto = reinterpret_cast<CAutomobile *>(pVeh);
pAuto->m_fNitroValue = enable ? -1.0f : 0.0f;
}
}
bool ME_IsNitroFiring(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = ExhaustFx::m_VehData.Get(pVeh);
return (CTimer::m_FrameCounter - data.lastNitroFrame) <= 1;
}
// Backfire API
void ME_TriggerBackfire(CVehicle *pVeh, bool bPlaySound) {
if (!pVeh) return;
BackFireEffect::BackFireSingle(pVeh, bPlaySound);
}
void ME_TriggerBackfireBurst(CVehicle *pVeh, bool bPlaySound) {
if (!pVeh) return;
BackFireEffect::BackFireMulti(pVeh, bPlaySound);
}
bool ME_IsBackfireActive(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = BackFireEffect::m_VehData.Get(pVeh);
return data.m_nleftFires > 0;
}
// Dashboard, Gauges & Clock API
float ME_GetVehicleMileage(CVehicle *pVeh) {
if (!pVeh) return 0.0f;
auto &data = MileageIndicator::m_VehData.Get(pVeh);
if (!data.vecIndicatorData.empty()) {
return static_cast<float>(data.vecIndicatorData.begin()->second.dCurrentDistance);
}
return 0.0f;
}
void ME_SetVehicleMileage(CVehicle *pVeh, float mileageKm) {
if (!pVeh) return;
auto &data = MileageIndicator::m_VehData.Get(pVeh);
for (auto &pair : data.vecIndicatorData) {
pair.second.dCurrentDistance = mileageKm;
}
}
bool ME_HasOdometer(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = MileageIndicator::m_VehData.Get(pVeh);
return !data.vecIndicatorData.empty();
}
float ME_GetSpeedometerValue(CVehicle *pVeh) {
if (!pVeh) return 0.0f;
auto &data = SpeedGauge::m_VehData.Get(pVeh);
if (!data.vecGaugeData.empty()) {
return data.vecGaugeData.begin()->second.fCurRotation;
}
return 0.0f;
}
bool ME_HasSpeedometer(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = SpeedGauge::m_VehData.Get(pVeh);
return !data.vecGaugeData.empty();
}
float ME_GetRPMValue(CVehicle *pVeh) {
if (!pVeh) return 0.0f;
auto &data = RPMGauge::m_VehData.Get(pVeh);
if (!data.vecGaugeData.empty()) {
return data.vecGaugeData.begin()->second.fCurRotation;
}
return 0.0f;
}
bool ME_HasRPMGauge(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = RPMGauge::m_VehData.Get(pVeh);
return !data.vecGaugeData.empty();
}
float ME_GetTurboValue(CVehicle *pVeh) {
if (!pVeh) return 0.0f;
auto &data = TurboGauge::m_VehData.Get(pVeh);
if (!data.vecGaugeData.empty()) {
return data.vecGaugeData.begin()->second.fCurRotation;
}
return 0.0f;
}
bool ME_HasTurboGauge(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = TurboGauge::m_VehData.Get(pVeh);
return !data.vecGaugeData.empty();
}
bool ME_HasGearIndicator(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = GearIndicator::m_VehData.Get(pVeh);
return !data.vecIndicatorData.empty();
}
int ME_GetGearIndicatorValue(CVehicle *pVeh) {
if (!pVeh) return 0;
auto &data = GearIndicator::m_VehData.Get(pVeh);
if (!data.vecIndicatorData.empty()) {
return static_cast<int>(data.vecIndicatorData[0].iCurrent);
}
return 0;
}
void ME_SetGearIndicatorValue(CVehicle *pVeh, int gear) {
if (!pVeh || gear < 0) return;
auto &data = GearIndicator::m_VehData.Get(pVeh);
for (auto &ind : data.vecIndicatorData) {
ind.iCurrent = static_cast<uint>(gear);
}
}
bool ME_GetDashboardLEDState(CVehicle *pVeh, ME_LightID ledId) {
if (!pVeh) return false;
auto matType = static_cast<eMaterialType>(ledId);
return ModelInfoMgr::IsMaterialAvailable(pVeh, matType);
}
void ME_SetDashboardLEDState(CVehicle *pVeh, ME_LightID ledId, bool state) {
if (!pVeh) return;
auto matType = static_cast<eMaterialType>(ledId);
if (state) {
ModelInfoMgr::EnableMaterial(pVeh, matType);
}
}
bool ME_IsClockAvailable(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = DigitalClockFeature::m_VehData.Get(pVeh);
return data.m_pRootFrame != nullptr || data.m_pDigitsRoot != nullptr;
}
bool ME_IsClock12HourFormat(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = DigitalClockFeature::m_VehData.Get(pVeh);
return data.m_b12HourFormat;
}
void ME_SetClock12HourFormat(CVehicle *pVeh, bool is12Hour) {
if (!pVeh) return;
auto &data = DigitalClockFeature::m_VehData.Get(pVeh);
data.m_b12HourFormat = is12Hour;
}
// Dirt FX API
float ME_GetDirtLevel(CVehicle *pVeh) {
return pVeh ? pVeh->m_fDirtLevel : 0.0f;
}
void ME_SetDirtLevel(CVehicle *pVeh, float dirtLevel) {
if (pVeh) pVeh->m_fDirtLevel = std::clamp(dirtLevel, 0.0f, 15.0f);
}
// Remap API
int ME_GetRemapIndex(CVehicle *pVeh) {
return pVeh ? Remap::GetRemapIndex(pVeh) : -1;
}
void ME_SetRemapIndex(CVehicle *pVeh, int remapIndex) {
if (pVeh) Remap::SetRemapIndex(pVeh, remapIndex);
}
bool ME_HasRemaps(int modelIndex) {
if (modelIndex < 0) return false;
return Remap::HasRemaps(modelIndex);
}
int ME_GetRemapCount(CVehicle *pVeh) {
if (!pVeh) return 0;
return Remap::GetRemapCount(pVeh->m_nModelIndex);
}
int ME_GetRemapCountByModel(int modelIndex) {
if (modelIndex < 0) return 0;
return Remap::GetRemapCount(modelIndex);
}
// Spoilers & Convertible Roof API
bool ME_IsRoofOpen(CVehicle *pVeh) {
if (!pVeh) return false;
return ConvertibleRoof::IsRoofOpen(pVeh);
}
void ME_SetRoofOpen(CVehicle *pVeh, bool open) {
if (!pVeh) return;
auto &data = ConvertibleRoof::m_VehData.Get(pVeh);
if (!data.m_bInit) return;
data.m_bRoofTargetExpanded = !open;
}
bool ME_HasConvertibleRoof(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = ConvertibleRoof::m_VehData.Get(pVeh);
return !data.m_Roofs.empty() || !data.m_Boots.empty();
}
int ME_GetRoofAnimPhase(CVehicle *pVeh) {
if (!pVeh) return 0;
auto &data = ConvertibleRoof::m_VehData.Get(pVeh);
return static_cast<int>(data.m_phase);
}
int ME_GetSpoilerCount(CVehicle *pVeh) {
if (!pVeh) return 0;
auto &data = Spoiler::m_VehData.Get(pVeh);
return static_cast<int>(data.m_Spoilers.size());
}
float ME_GetSpoilerAngle(CVehicle *pVeh, int spoilerIndex) {
if (!pVeh) return 0.0f;
auto &data = Spoiler::m_VehData.Get(pVeh);
if (spoilerIndex >= 0 && spoilerIndex < static_cast<int>(data.m_Spoilers.size())) {
return data.m_Spoilers[spoilerIndex].m_fCurrentRotation;
}
return 0.0f;
}
void ME_SetSpoilerAngle(CVehicle *pVeh, int spoilerIndex, float angle) {
if (!pVeh) return;
auto &data = Spoiler::m_VehData.Get(pVeh);
if (spoilerIndex >= 0 && spoilerIndex < static_cast<int>(data.m_Spoilers.size())) {
data.m_Spoilers[spoilerIndex].m_fCurrentRotation = angle;
}
}
// Doors & Animation API
bool ME_HasSlideDoors(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = SlideDoor::m_VehData.Get(pVeh);
return !data.leftFront.empty() || !data.rightFront.empty() || !data.leftRear.empty() || !data.rightRear.empty();
}
bool ME_HasRotateDoors(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = RotateDoor::m_VehData.Get(pVeh);
return !data.leftFront.empty() || !data.rightFront.empty() || !data.leftRear.empty() || !data.rightRear.empty() || !data.boot.empty() || !data.bonnet.empty();
}
// Wheels, Hubs & Chain API
bool ME_HasExtraWheels(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = ExtraWheel::m_VehData.Get(pVeh);
for (int i = 0; i < static_cast<int>(eWheelPos::COUNT); ++i) {
if (!data.pExtras[i].empty()) return true;
}
return false;
}
int ME_GetExtraWheelCount(CVehicle *pVeh, int wheelPos) {
if (!pVeh || wheelPos < 0 || wheelPos >= static_cast<int>(eWheelPos::COUNT)) return 0;
auto &data = ExtraWheel::m_VehData.Get(pVeh);
return static_cast<int>(data.pExtras[wheelPos].size());
}
bool ME_HasWheelHubs(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = WheelHub::m_VehData.Get(pVeh);
return data.m_pWRF || data.m_pHRF || data.m_pWRM || data.m_pHRM || data.m_pWRR || data.m_pHRR ||
data.m_pWLF || data.m_pHLF || data.m_pWLM || data.m_pHLM || data.m_pWLR || data.m_pHLR;
}
bool ME_HasAnimatedChain(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = ChainFeature::m_VehData.Get(pVeh);
return data.m_pRootFrame != nullptr || !data.m_FrameList.empty();
}
int ME_GetChainFrameIndex(CVehicle *pVeh) {
if (!pVeh) return 0;
auto &data = ChainFeature::m_VehData.Get(pVeh);
return static_cast<int>(data.m_nCurChain);
}
int ME_GetChainFrameCount(CVehicle *pVeh) {
if (!pVeh) return 0;
auto &data = ChainFeature::m_VehData.Get(pVeh);
return static_cast<int>(data.m_FrameList.size());
}
// Rollback Bed API
bool ME_IsRollbackBedExpanded(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = RollbackBed::m_VehData.Get(pVeh);
return data.bExpanded;
}
void ME_SetRollbackBedExpanded(CVehicle *pVeh, bool expanded) {
if (!pVeh) return;
auto &data = RollbackBed::m_VehData.Get(pVeh);
data.bExpanded = expanded;
}
bool ME_HasRollbackBed(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = RollbackBed::m_VehData.Get(pVeh);
return data.pBedFrame != nullptr;
}
float ME_GetRollbackBedTilt(CVehicle *pVeh) {
if (!pVeh) return 0.0f;
auto &data = RollbackBed::m_VehData.Get(pVeh);
return data.fBedCurRot;
}
int ME_GetRollbackBedPistonCount(CVehicle *pVeh) {
if (!pVeh) return 0;
auto &data = RollbackBed::m_VehData.Get(pVeh);
return static_cast<int>(data.m_Pistons.size());
}
float ME_GetRollbackBedPistonMove(CVehicle *pVeh, int pistonIndex) {
if (!pVeh) return 0.0f;
auto &data = RollbackBed::m_VehData.Get(pVeh);
if (pistonIndex >= 0 && pistonIndex < static_cast<int>(data.m_Pistons.size())) {
return data.m_Pistons[pistonIndex].fCurMove;
}
return 0.0f;
}
// Spotlights API
bool ME_IsSpotlightActive(CVehicle *pVeh) {
if (!pVeh) return false;
return SpotLights::IsEnabled(pVeh);
}
void ME_SetSpotlightActive(CVehicle *pVeh, bool active) {
if (!pVeh) return;
auto &data = SpotLights::m_VehData.Get(pVeh);
data.bEnabled = active;
}
bool ME_HasSpotlight(CVehicle *pVeh) {
if (!pVeh) return false;
auto &data = SpotLights::m_VehData.Get(pVeh);
return data.pFrame != nullptr;
}
// Ped Colors API
int ME_GetPedVariationCount(int modelIndex) {
if (modelIndex < 0 || modelIndex >= 20000) return 0;
auto jsonData = DataMgr::Get(modelIndex);
if (jsonData.contains("pedcols") && jsonData["pedcols"].contains("variations") && jsonData["pedcols"]["variations"].is_array()) {
return static_cast<int>(jsonData["pedcols"]["variations"].size());
}
return 0;
}
bool ME_GetPedColors(CPed *pPed, ME_Color *col1, ME_Color *col2, ME_Color *col3, ME_Color *col4) {
if (!pPed) return false;
auto &data = PedColors::GetPedData().Get(pPed);
if (!data.m_bUsingPedCols || data.m_Colors.size() < 4) return false;
if (col1) *col1 = {data.m_Colors[0].r, data.m_Colors[0].g, data.m_Colors[0].b, data.m_Colors[0].a};
if (col2) *col2 = {data.m_Colors[1].r, data.m_Colors[1].g, data.m_Colors[1].b, data.m_Colors[1].a};
if (col3) *col3 = {data.m_Colors[2].r, data.m_Colors[2].g, data.m_Colors[2].b, data.m_Colors[2].a};
if (col4) *col4 = {data.m_Colors[3].r, data.m_Colors[3].g, data.m_Colors[3].b, data.m_Colors[3].a};
return true;
}
bool ME_SetPedColors(CPed *pPed, ME_Color col1, ME_Color col2, ME_Color col3, ME_Color col4) {
if (!pPed) return false;
auto &data = PedColors::GetPedData().Get(pPed);
if (data.m_Colors.size() < 4) {
data.m_Colors.resize(4);
}
data.m_Colors[0] = CRGBA(col1.r, col1.g, col1.b, col1.a);
data.m_Colors[1] = CRGBA(col2.r, col2.g, col2.b, col2.a);
data.m_Colors[2] = CRGBA(col3.r, col3.g, col3.b, col3.a);
data.m_Colors[3] = CRGBA(col4.r, col4.g, col4.b, col4.a);
data.m_bUsingPedCols = true;
return true;
}
// Audio & Sounds API
bool ME_PlaySound(CVehicle *pVeh, const char *soundPath, float volume) {
if (!pVeh || !soundPath) return false;
AudioMgr::Play3DSound(soundPath, pVeh->GetPosition(), pVeh, volume);
return true;
}
void ME_StopVehicleSounds(CVehicle *pVeh) {
if (!pVeh) return;
auto &sData = SoundEffects::m_VehData.Get(pVeh);
if (sData.m_hDoorChimeStream) {
AudioMgr::StopLoopStream(sData.m_hDoorChimeStream);
sData.m_hDoorChimeStream = 0;
}
}
bool ME_IsDoorChimePlaying(CVehicle *pVeh) {
if (!pVeh) return false;
auto &sData = SoundEffects::m_VehData.Get(pVeh);
return sData.m_hDoorChimeStream != 0;
}
float ME_GetBrakePressure(CVehicle *pVeh) {
if (!pVeh) return 0.0f;
auto &sData = SoundEffects::m_VehData.Get(pVeh);
return sData.m_fBrakePressure;
}
bool ME_PlayFileSound(const char *soundPath, float volume) {
if (!soundPath) return false;
AudioMgr::PlayFileSound(soundPath, volume);
return true;
}
void ME_PlaySwitchSound(CVehicle *pVeh) {
AudioMgr::PlaySwitchSound(pVeh);
}
bool ME_GetSirenAudioPath(int modeIndex, char *outBuffer, int maxLen) {
if (!outBuffer || maxLen <= 0) return false;
std::string path = AudioMgr::GetSirenAudioPath(modeIndex);
if (path.empty()) return false;
SafeStrCopy(outBuffer, maxLen, path);
return true;
}
// Visual & Render Configuration
float ME_GetMaterialAmbientMul() {
return ModelInfoMgr::GetMaterialAmbientMul();
}
void ME_SetMaterialAmbientMul(float mul) {
ModelInfoMgr::gfMaterialAmbientMul = std::max(0.0f, mul);
}
float ME_GetHeadLightCoronaDistanceMul() {
return RenderUtil::GetHeadLightCoronaDistanceMul();
}
float ME_GetTailLightCoronaDistanceMul() {
return RenderUtil::GetTailLightCoronaDistanceMul();
}
float ME_GetCoronaDistanceMul() {
return RenderUtil::GetCoronaDistanceMul();
}
float ME_GetCoronaNearClip() {
return RenderUtil::GetCoronaNearClip();
}
float ME_GetLightShadowDistance() {
return RenderUtil::GetLightShadowDistance();
}
float ME_GetSirenPointLightMul() {
return LightsConfig::Get().fSirenPointLightMul;
}
float ME_GetPointLightIntensity() {
return LightsConfig::Get().fPointLightIntensity;
}
bool ME_IsAutoIndicatorsOnSteerEnabled() {
return LightsConfig::Get().bAutoIndicatorsOnSteer;
}
bool ME_IsFoglightTiedToHeadlight() {
return LightsConfig::Get().bFoglightTiedToHeadlight;
}
bool ME_IsPlayerIdleBrakeLightsEnabled() {
return LightsConfig::Get().bPlayerIdleBrakeLights;
}
// Vehicle Physics & Auxiliary
float ME_GetVehiclePitch(CVehicle *pVeh) {
if (!pVeh) return 0.0f;
return CarUtil::GetVehiclePitch(pVeh);
}
bool ME_IsVehicleDoingWheelie(CVehicle *pVeh) {
if (!pVeh) return false;
return CarUtil::IsVehicleDoingWheelie(pVeh);
}