@@ -41,6 +41,8 @@ std::ofstream logfile;
4141std::set<std::pair<unsigned int , std::string>> modulesSet;
4242std::set<std::pair<unsigned int , std::string>> callChecks;
4343
44+ CIniReader iniPed;
45+ CIniReader iniWeap;
4446CIniReader iniVeh;
4547CIniReader iniSettings;
4648
@@ -105,6 +107,8 @@ int cloneRemoverVehicleOccupants = 0;
105107int cloneRemoverIncludeVariations = 0 ;
106108int spawnDelay = 3 ;
107109
110+ bool keyDown = false ;
111+
108112void getLoadedModules ()
109113{
110114 modulesSet.clear ();
@@ -223,11 +227,11 @@ void drugDealerFix(void)
223227 }
224228}
225229
226- void updateVariations (CZone* zInfo, CIniReader* iniPed )
230+ void updateVariations (CZone* zInfo)
227231{
228232 // zInfo->m_szTextKey = BLUEB | zInfo->m_szLabel = BLUEB1
229233
230- if (zInfo == NULL || iniPed == NULL )
234+ if (zInfo == NULL )
231235 return ;
232236
233237 currentTown = (BYTE)CTheZones::m_CurrLevel;
@@ -255,15 +259,15 @@ void updateVariations(CZone* zInfo, CIniReader* iniPed)
255259
256260 CWanted* wanted = FindPlayerWanted (-1 );
257261
258- for (auto & i : iniPed-> data )
262+ for (auto & i : iniPed. data )
259263 if (i.first [0 ] >= ' 0' && i.first [0 ] <= ' 9' )
260264 {
261265 int modelid = std::stoi (i.first );
262266 if (modelid > 0 && modelid < 300 )
263267 {
264268 vectorUnion (pedVariations[modelid][4 ], pedVariations[modelid][currentTown], pedCurrentVariations[modelid]);
265269
266- std::vector<unsigned short > vec = iniLineParser (i.first , ((lastZone[0 ] == 0 ) ? zInfo->m_szLabel : lastZone), iniPed);
270+ std::vector<unsigned short > vec = iniLineParser (i.first , ((lastZone[0 ] == 0 ) ? zInfo->m_szLabel : lastZone), & iniPed);
267271 if (!vec.empty ())
268272 {
269273 if (pedMergeZones.find ((unsigned short )modelid) != pedMergeZones.end ())
@@ -272,7 +276,7 @@ void updateVariations(CZone* zInfo, CIniReader* iniPed)
272276 pedCurrentVariations[modelid] = vec;
273277 }
274278
275- vec = iniLineParser (i.first , currentInterior, iniPed);
279+ vec = iniLineParser (i.first , currentInterior, & iniPed);
276280 if (!vec.empty ())
277281 pedCurrentVariations[modelid] = vectorUnion (pedCurrentVariations[modelid], vec);
278282
@@ -408,80 +412,79 @@ void installHooks()
408412 installVehicleHooks ();
409413}
410414
411- void loadIniData (CIniReader* iniPed, bool firstTime)
415+ void loadIniData (bool firstTime)
412416{
413- if (iniPed != NULL )
417+
418+ for (unsigned short i = 0 ; i < 300 ; i++)
414419 {
415- for (unsigned short i = 0 ; i < 300 ; i++)
416- {
417- std::string section = std::to_string (i);
420+ std::string section = std::to_string (i);
418421
419- if (iniPed-> data .find (section) != iniPed-> data .end ())
420- {
421- pedVariations[i][0 ] = iniLineParser (section, " Countryside" , iniPed);
422- pedVariations[i][1 ] = iniLineParser (section, " LosSantos" , iniPed);
423- pedVariations[i][2 ] = iniLineParser (section, " SanFierro" , iniPed);
424- pedVariations[i][3 ] = iniLineParser (section, " LasVenturas" , iniPed);
425- pedVariations[i][4 ] = iniLineParser (section, " Global" , iniPed);
426- pedVariations[i][5 ] = iniLineParser (section, " Desert" , iniPed);
422+ if (iniPed. data .find (section) != iniPed. data .end ())
423+ {
424+ pedVariations[i][0 ] = iniLineParser (section, " Countryside" , & iniPed);
425+ pedVariations[i][1 ] = iniLineParser (section, " LosSantos" , & iniPed);
426+ pedVariations[i][2 ] = iniLineParser (section, " SanFierro" , & iniPed);
427+ pedVariations[i][3 ] = iniLineParser (section, " LasVenturas" , & iniPed);
428+ pedVariations[i][4 ] = iniLineParser (section, " Global" , & iniPed);
429+ pedVariations[i][5 ] = iniLineParser (section, " Desert" , & iniPed);
427430
428- std::vector<unsigned short > vec = iniLineParser (section, " TierraRobada" , iniPed);
429- pedVariations[i][6 ] = vectorUnion (vec, pedVariations[i][5 ]);
431+ std::vector<unsigned short > vec = iniLineParser (section, " TierraRobada" , & iniPed);
432+ pedVariations[i][6 ] = vectorUnion (vec, pedVariations[i][5 ]);
430433
431- vec = iniLineParser (section, " BoneCounty" , iniPed);
432- pedVariations[i][7 ] = vectorUnion (vec, pedVariations[i][5 ]);
434+ vec = iniLineParser (section, " BoneCounty" , & iniPed);
435+ pedVariations[i][7 ] = vectorUnion (vec, pedVariations[i][5 ]);
433436
434- vec = iniLineParser (section, " RedCounty" , iniPed);
435- pedVariations[i][8 ] = vectorUnion (vec, pedVariations[i][0 ]);
437+ vec = iniLineParser (section, " RedCounty" , & iniPed);
438+ pedVariations[i][8 ] = vectorUnion (vec, pedVariations[i][0 ]);
436439
437- vec = iniLineParser (section, " Blueberry" , iniPed);
438- pedVariations[i][9 ] = vectorUnion (vec, pedVariations[i][8 ]);
440+ vec = iniLineParser (section, " Blueberry" , & iniPed);
441+ pedVariations[i][9 ] = vectorUnion (vec, pedVariations[i][8 ]);
439442
440- vec = iniLineParser (section, " Montgomery" , iniPed);
441- pedVariations[i][10 ] = vectorUnion (vec, pedVariations[i][8 ]);
443+ vec = iniLineParser (section, " Montgomery" , & iniPed);
444+ pedVariations[i][10 ] = vectorUnion (vec, pedVariations[i][8 ]);
442445
443- vec = iniLineParser (section, " Dillimore" , iniPed);
444- pedVariations[i][11 ] = vectorUnion (vec, pedVariations[i][8 ]);
446+ vec = iniLineParser (section, " Dillimore" , & iniPed);
447+ pedVariations[i][11 ] = vectorUnion (vec, pedVariations[i][8 ]);
445448
446- vec = iniLineParser (section, " PalominoCreek" , iniPed);
447- pedVariations[i][12 ] = vectorUnion (vec, pedVariations[i][8 ]);
449+ vec = iniLineParser (section, " PalominoCreek" , & iniPed);
450+ pedVariations[i][12 ] = vectorUnion (vec, pedVariations[i][8 ]);
448451
449- vec = iniLineParser (section, " FlintCounty" , iniPed);
450- pedVariations[i][13 ] = vectorUnion (vec, pedVariations[i][0 ]);
452+ vec = iniLineParser (section, " FlintCounty" , & iniPed);
453+ pedVariations[i][13 ] = vectorUnion (vec, pedVariations[i][0 ]);
451454
452- vec = iniLineParser (section, " Whetstone" , iniPed);
453- pedVariations[i][14 ] = vectorUnion (vec, pedVariations[i][0 ]);
455+ vec = iniLineParser (section, " Whetstone" , & iniPed);
456+ pedVariations[i][14 ] = vectorUnion (vec, pedVariations[i][0 ]);
454457
455- vec = iniLineParser (section, " AngelPine" , iniPed);
456- pedVariations[i][15 ] = vectorUnion (vec, pedVariations[i][14 ]);
458+ vec = iniLineParser (section, " AngelPine" , & iniPed);
459+ pedVariations[i][15 ] = vectorUnion (vec, pedVariations[i][14 ]);
457460
458461
459- pedWantedVariations[i][0 ] = iniLineParser (section, " Wanted1" , iniPed);
460- pedWantedVariations[i][1 ] = iniLineParser (section, " Wanted2" , iniPed);
461- pedWantedVariations[i][2 ] = iniLineParser (section, " Wanted3" , iniPed);
462- pedWantedVariations[i][3 ] = iniLineParser (section, " Wanted4" , iniPed);
463- pedWantedVariations[i][4 ] = iniLineParser (section, " Wanted5" , iniPed);
464- pedWantedVariations[i][5 ] = iniLineParser (section, " Wanted6" , iniPed);
462+ pedWantedVariations[i][0 ] = iniLineParser (section, " Wanted1" , & iniPed);
463+ pedWantedVariations[i][1 ] = iniLineParser (section, " Wanted2" , & iniPed);
464+ pedWantedVariations[i][2 ] = iniLineParser (section, " Wanted3" , & iniPed);
465+ pedWantedVariations[i][3 ] = iniLineParser (section, " Wanted4" , & iniPed);
466+ pedWantedVariations[i][4 ] = iniLineParser (section, " Wanted5" , & iniPed);
467+ pedWantedVariations[i][5 ] = iniLineParser (section, " Wanted6" , & iniPed);
465468
466469
467- for (unsigned int j = 0 ; j < 16 ; j++)
468- for (unsigned int k = 0 ; k < pedVariations[i][j].size (); k++)
469- if (pedVariations[i][j][k] > 0 && pedVariations[i][j][k] < 32000 && pedVariations[i][j][k] != i)
470- pedOriginalModels.insert ({ pedVariations[i][j][k], i });
470+ for (unsigned int j = 0 ; j < 16 ; j++)
471+ for (unsigned int k = 0 ; k < pedVariations[i][j].size (); k++)
472+ if (pedVariations[i][j][k] > 0 && pedVariations[i][j][k] < 32000 && pedVariations[i][j][k] != i)
473+ pedOriginalModels.insert ({ pedVariations[i][j][k], i });
471474
472- if (iniPed->ReadInteger (section, " MergeZonesWithCities" , 0 ) == 1 )
473- pedMergeZones.insert (i);
474- }
475+ if (iniPed.ReadInteger (section, " MergeZonesWithCities" , 0 ) == 1 )
476+ pedMergeZones.insert (i);
475477 }
476478 }
477479
480+
478481 if (firstTime)
479482 {
480- enableCloneRemover = iniPed-> ReadInteger (" Settings" , " EnableCloneRemover" , 0 );
481- cloneRemoverIncludeVariations = iniPed-> ReadInteger (" Settings" , " CloneRemoverIncludeVariations" , 0 );
482- cloneRemoverVehicleOccupants = iniPed-> ReadInteger (" Settings" , " CloneRemoverIncludeVehicleOccupants" , 0 );
483- cloneRemoverExclusions = iniLineParser (" Settings" , " CloneRemoverExcludeModels" , iniPed);
484- spawnDelay = iniPed-> ReadInteger (" Settings" , " SpawnDelay" , 3 );
483+ enableCloneRemover = iniPed. ReadInteger (" Settings" , " EnableCloneRemover" , 0 );
484+ cloneRemoverIncludeVariations = iniPed. ReadInteger (" Settings" , " CloneRemoverIncludeVariations" , 0 );
485+ cloneRemoverVehicleOccupants = iniPed. ReadInteger (" Settings" , " CloneRemoverIncludeVehicleOccupants" , 0 );
486+ cloneRemoverExclusions = iniLineParser (" Settings" , " CloneRemoverExcludeModels" , & iniPed);
487+ spawnDelay = iniPed. ReadInteger (" Settings" , " SpawnDelay" , 3 );
485488 enableVehicles = iniVeh.ReadInteger (" Settings" , " Enable" , 0 );
486489 }
487490
@@ -545,6 +548,16 @@ void clearEverything()
545548 }
546549 vehCarGenExclude.clear ();
547550 vehInheritExclude.clear ();
551+
552+ iniPed.data .clear ();
553+ iniWeap.data .clear ();
554+ iniSettings.data .clear ();
555+ iniVeh.data .clear ();
556+
557+ iniPed.SetIniPath (pedIniPath);
558+ iniWeap.SetIniPath (pedWepIniPath);
559+ iniSettings.SetIniPath (settingsIniPath);
560+ iniVeh.SetIniPath (vehIniPath);
548561}
549562
550563class ModelVariations {
@@ -563,8 +576,8 @@ class ModelVariations {
563576 if (!fileExists (settingsIniPath))
564577 settingsIniPath = " ModelVariations\\ " + settingsIniPath;
565578
566- static CIniReader iniPed (pedIniPath);
567- static CIniReader iniWeap (pedWepIniPath);
579+ iniPed. SetIniPath (pedIniPath);
580+ iniWeap. SetIniPath (pedWepIniPath);
568581 iniSettings.SetIniPath (settingsIniPath);
569582 iniVeh.SetIniPath (vehIniPath);
570583
@@ -651,7 +664,7 @@ class ModelVariations {
651664
652665 Events::initRwEvent += []
653666 {
654- loadIniData (&iniPed, true );
667+ loadIniData (true );
655668 installHooks ();
656669
657670 if (logfile.is_open ())
@@ -727,18 +740,34 @@ class ModelVariations {
727740
728741 Events::gameProcessEvent += []
729742 {
743+
730744 if (disableKey > 0 && KeyPressed (disableKey))
731745 {
732- CMessages::AddMessageJumpQ ((char *)" Model variations disabled." , 2000 , 0 , false );
733- clearEverything ();
746+ if (!keyDown)
747+ {
748+ keyDown = true ;
749+ CMessages::AddMessageJumpQ ((char *)" ~y~Model Variations~s~: Mod disabled." , 2000 , 0 , false );
750+ if (logfile.is_open ())
751+ logfile << " Disabling mod... " ;
752+ clearEverything ();
753+ if (logfile.is_open ())
754+ logfile << " OK" << std::endl;
755+ }
734756 }
735-
736- if (reloadKey > 0 && KeyPressed (reloadKey))
757+ else if (reloadKey > 0 && KeyPressed (reloadKey))
737758 {
738- clearEverything ();
739- loadIniData (&iniPed, false );
740- CMessages::AddMessageJumpQ ((char *)" Model variations settings reloaded." , 2000 , 0 , false );
759+ if (!keyDown)
760+ {
761+ keyDown = true ;
762+ if (logfile.is_open ())
763+ logfile << " Reloading settings..." << std::endl;
764+ clearEverything ();
765+ loadIniData (false );
766+ CMessages::AddMessageJumpQ ((char *)" ~y~Model Variations~s~: Settings reloaded." , 2000 , 0 , false );
767+ }
741768 }
769+ else
770+ keyDown = false ;
742771
743772 if (framesSinceCallsChecked < 1000 )
744773 framesSinceCallsChecked++;
@@ -776,7 +805,7 @@ class ModelVariations {
776805 }
777806
778807 strncpy (lastInterior, currentInterior, 15 );
779- updateVariations (zInfo, &iniPed );
808+ updateVariations (zInfo);
780809
781810 if (enableLog == 1 )
782811 printCurrentVariations ();
@@ -796,7 +825,7 @@ class ModelVariations {
796825 }
797826
798827 currentWanted = (int )wanted->m_nWantedLevel ;
799- updateVariations (zInfo, &iniPed );
828+ updateVariations (zInfo);
800829
801830 if (enableLog == 1 )
802831 printCurrentVariations ();
@@ -821,7 +850,7 @@ class ModelVariations {
821850 }
822851
823852 strncpy (currentZone, zInfo->m_szLabel , 7 );
824- updateVariations (zInfo, &iniPed );
853+ updateVariations (zInfo);
825854
826855 if (enableLog == 1 )
827856 printCurrentVariations ();
0 commit comments