55#include " ../../injector/assembly.hpp"
66
77#include " CBoat.h"
8+ #include " CCarCtrl.h"
89#include " CCarGenerator.h"
910#include " CCoronas.h"
1011#include " CGeneral.h"
@@ -83,13 +84,20 @@ int getVariationOriginalModel(int modelIndex)
8384 return originalModel;
8485}
8586
86- int getRandomVariation (int modelid)
87+ int getRandomVariation (int modelid, bool parked = false )
8788{
8889 if (modelid < 400 || modelid > 611 )
8990 return modelid;
9091 if (vehCurrentVariations[modelid - 400 ].empty ())
9192 return modelid;
9293
94+ if (parked == false )
95+ {
96+ auto it = parkedCars.find (modelid);
97+ if (it != parkedCars.end ())
98+ return modelid;
99+ }
100+
93101 int random = CGeneral::GetRandomNumberInRange (0 , vehCurrentVariations[modelid - 400 ].size ());
94102 int variationModel = vehCurrentVariations[modelid - 400 ][random];
95103 if (variationModel > -1 )
@@ -106,6 +114,9 @@ void readVehicleIni()
106114{
107115 for (int i = 400 ; i < 612 ; i++)
108116 {
117+ if (iniVeh.ReadInteger (std::to_string (i), " ChangeOnlyParked" , 0 ) == 1 )
118+ parkedCars.insert (i);
119+
109120 std::vector<short > vec = iniLineParser (VEHICLE_VARIATION, i, " Countryside" , &iniVeh);
110121 vehVariations[i - 400 ][0 ] = vec;
111122 std::sort (vehVariations[i - 400 ][0 ].begin (), vehVariations[i - 400 ][0 ].end ());
@@ -362,7 +373,7 @@ signed int __fastcall PickRandomCarHooked(CLoadedCarGroup* cargrp, void*, char a
362373{
363374 if (cargrp == NULL )
364375 return -1 ;
365- return getRandomVariation (callMethodOriginalAndReturn<signed int , address>(cargrp, a2, a3));
376+ return getRandomVariation (callMethodOriginalAndReturn<signed int , address>(cargrp, a2, a3), true );
366377}
367378
368379template <unsigned int address>
@@ -380,7 +391,7 @@ void __fastcall DoInternalProcessingHooked(CCarGenerator* park) //for non-random
380391 return ;
381392 }
382393
383- park->m_nModelId = getRandomVariation (park->m_nModelId );
394+ park->m_nModelId = getRandomVariation (park->m_nModelId , true );
384395 callMethodOriginal<address>(park);
385396 park->m_nModelId = model;
386397 return ;
@@ -405,7 +416,7 @@ void __fastcall DoInternalProcessingHooked(CCarGenerator* park) //for non-random
405416 case 430 : // Predator
406417 case 496 : // Police Maverick
407418 case 488 : // News Chopper
408- park->m_nModelId = getRandomVariation (park->m_nModelId );
419+ park->m_nModelId = getRandomVariation (park->m_nModelId , true );
409420 callMethodOriginal<address>(park);
410421 park->m_nModelId = model;
411422 break ;
@@ -775,6 +786,12 @@ void __cdecl PossiblyRemoveVehicleHooked(CVehicle* car)
775786
776787}
777788
789+ template <unsigned int address>
790+ CVehicle* __cdecl CreateCarForScriptHooked (int modelId, float posX, float posY, float posZ, char doMissionCleanup)
791+ {
792+ return callOriginalAndReturn<CVehicle*, address>(getRandomVariation (modelId), posX, posY, posZ, doMissionCleanup);
793+ }
794+
778795/*
7797960x053A926
780797void __declspec(naked) ()
@@ -1036,8 +1053,7 @@ void __fastcall CAutomobileRenderHooked(CAutomobile* veh)
10361053void installVehicleHooks ()
10371054{
10381055 if (enableLog == 1 )
1039- logfile << " Installing vehicle hooks..." << std::endl;
1040-
1056+ logfile << " Installing vehicle hooks... " ;
10411057
10421058 hookCall (0x43022A , ChooseModelHooked<0x43022A >); // CCarCtrl::GenerateOneRandomCar
10431059 // patch::RedirectJump(0x424E20, ChoosePoliceCarModelHooked);
@@ -1104,18 +1120,10 @@ void installVehicleHooks()
11041120 hookCall (0x60C4E8 , PossiblyRemoveVehicleHooked<0x60C4E8 >); // CPlayerPed::KeepAreaAroundPlayerClear
11051121 hookCall (0x42CD55 , PossiblyRemoveVehicleHooked<0x42CD55 >); // CCarCtrl::RemoveDistantCars
11061122
1123+ if (changeScriptedCars = iniVeh.ReadInteger (" Settings" , " ChangeScriptedCars" , 0 ))
1124+ hookCall (0x467B01 , CreateCarForScriptHooked<0x467B01 >);
11071125
1108- if (enableLights == 1 )
1109- {
1110- hookCall (0x6ABA60 , RegisterCoronaHooked<0x6ABA60 >); // CAutomobile::PreRender
1111- hookCall (0x6ABB35 , RegisterCoronaHooked<0x6ABB35 >); // CAutomobile::PreRender
1112- hookCall (0x6ABC69 , RegisterCoronaHooked<0x6ABC69 >); // CAutomobile::PreRender
1113-
1114- hookCall (0x6AB80F , AddLightHooked<0x6AB80F >); // CAutomobile::PreRender
1115- hookCall (0x6ABBA6 , AddLightHooked<0x6ABBA6 >); // CAutomobile::PreRender
1116- }
1117-
1118- if (iniVeh.ReadInteger (" Settings" , " EnableSpecialFeatures" , 0 ))
1126+ if (enableSpecialFeatures = iniVeh.ReadInteger (" Settings" , " EnableSpecialFeatures" , 0 ))
11191127 {
11201128 void (__fastcall **p)(CAutomobile*) = reinterpret_cast <void (__fastcall**)(CAutomobile*)>(0x871148 );
11211129 ProcessControlOriginal = *p;
@@ -1161,6 +1169,16 @@ void installVehicleHooks()
11611169 if ((enableSiren = iniVeh.ReadInteger (" Settings" , " EnableSiren" , 0 )) == 1 )
11621170 patch::RedirectCall (0x6D8492 , HasCarSiren); // CVehicle::UsesSiren
11631171
1172+ if (enableLights == 1 && enableSpecialFeatures == 1 && enableSiren == 1 )
1173+ {
1174+ hookCall (0x6ABA60 , RegisterCoronaHooked<0x6ABA60 >); // CAutomobile::PreRender
1175+ hookCall (0x6ABB35 , RegisterCoronaHooked<0x6ABB35 >); // CAutomobile::PreRender
1176+ hookCall (0x6ABC69 , RegisterCoronaHooked<0x6ABC69 >); // CAutomobile::PreRender
1177+
1178+ hookCall (0x6AB80F , AddLightHooked<0x6AB80F >); // CAutomobile::PreRender
1179+ hookCall (0x6ABBA6 , AddLightHooked<0x6ABBA6 >); // CAutomobile::PreRender
1180+ }
1181+
11641182 if ((disablePayAndSpray = iniVeh.ReadInteger (" Settings" , " DisablePayAndSpray" , 0 )) == 1 )
11651183 hookCall (0x44AC75 , IsCarSprayableHooked<0x44AC75 >); // CGarage::Update
11661184
@@ -1170,4 +1188,7 @@ void installVehicleHooks()
11701188 hookCall (0x48DA81 , IsLawEnforcementVehicleHooked<0x48DA81 >);
11711189 hookCall (0x469612 , CollectParametersHooked<0x469612 >);
11721190 }
1191+
1192+ if (enableLog == 1 )
1193+ logfile << " OK" << std::endl;
11731194}
0 commit comments