Skip to content

Commit 987ff61

Browse files
committed
Fixed bugs, added features (5 MAR 2022)
Fixed drug dealer save crash Added ability to select models by name
1 parent 7ca5ec1 commit 987ff61

3 files changed

Lines changed: 111 additions & 74 deletions

File tree

ModelVariations/LogUtil.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <string>
77
#include <iostream>
88

9-
#define MOD_VERSION "7.0"
9+
#define MOD_VERSION "7.1"
1010
#ifdef _DEBUG
1111
#define MOD_NAME "ModelVariations_d.asi"
1212
#else

ModelVariations/ModelVariations.cpp

Lines changed: 79 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -184,46 +184,44 @@ bool IdExists(std::vector<unsigned short>& vec, int id)
184184
return false;
185185
}
186186

187-
void drugDealerFix(void)
187+
void drugDealerFix()
188188
{
189189
bool enableFix = false;
190190

191-
for (unsigned int i = 0; i < 6; i++)
191+
for (unsigned int i = 0; i < 16; i++)
192192
if (!pedVariations[28][i].empty() || !pedVariations[29][i].empty() || !pedVariations[30][i].empty() || !pedVariations[254][i].empty())
193193
enableFix = true;
194194

195195
if (!enableFix)
196196
return;
197197

198198
std::vector<unsigned short> totalVariations;
199+
std::set<unsigned short> drugDealers;
199200

200-
for (unsigned int i = 0; i < 6; i++)
201+
for (unsigned int i = 0; i < 16; i++)
201202
totalVariations.insert(totalVariations.end(), pedVariations[28][i].begin(), pedVariations[28][i].end());
202203

203-
for (unsigned int i = 0; i < 6; i++)
204+
for (unsigned int i = 0; i < 16; i++)
204205
totalVariations.insert(totalVariations.end(), pedVariations[29][i].begin(), pedVariations[29][i].end());
205206

206-
for (unsigned int i = 0; i < 6; i++)
207-
totalVariations.insert(totalVariations.end(), pedVariations[30][i].begin(), pedVariations[30][0].end());
207+
for (unsigned int i = 0; i < 16; i++)
208+
totalVariations.insert(totalVariations.end(), pedVariations[30][i].begin(), pedVariations[30][i].end());
208209

209-
for (unsigned int i = 0; i < 6; i++)
210-
totalVariations.insert(totalVariations.end(), pedVariations[254][i].begin(), pedVariations[254][0].end());
210+
for (unsigned int i = 0; i < 16; i++)
211+
totalVariations.insert(totalVariations.end(), pedVariations[254][i].begin(), pedVariations[254][i].end());
211212

212-
std::vector<unsigned short> variationsProcessed;
213+
213214

214-
for (unsigned int i = 0; i < totalVariations.size(); i++)
215-
{
216-
unsigned short variationModel = totalVariations[i];
217-
if (variationModel > 300 && IdExists(variationsProcessed, variationModel) == false)
218-
variationsProcessed.push_back(variationModel);
219-
}
215+
for (auto &i : totalVariations)
216+
if (i > 300)
217+
drugDealers.insert(i);
220218

221-
for (unsigned int i = 0; i < variationsProcessed.size(); i++)
219+
for (auto &i : drugDealers)
222220
{
223221
if (enableLog == 1)
224-
logfile << variationsProcessed[i] << "\n";
225-
Command<COMMAND_ALLOCATE_STREAMED_SCRIPT_TO_RANDOM_PED>(19, variationsProcessed[i], 100);
226-
Command<COMMAND_ATTACH_ANIMS_TO_MODEL>(variationsProcessed[i], "DEALER");
222+
logfile << i << "\n";
223+
Command<COMMAND_ALLOCATE_STREAMED_SCRIPT_TO_RANDOM_PED>(19, i, 100);
224+
//Command<COMMAND_ATTACH_ANIMS_TO_MODEL>(i, "DEALER");
227225
}
228226
}
229227

@@ -260,61 +258,70 @@ void updateVariations(CZone* zInfo)
260258
CWanted* wanted = FindPlayerWanted(-1);
261259

262260
for (auto& i : iniPed.data)
261+
{
262+
int modelid = 0;
263263
if (i.first[0] >= '0' && i.first[0] <= '9')
264-
{
265-
int modelid = std::stoi(i.first);
266-
if (modelid > 0 && modelid < 300)
267-
{
268-
vectorUnion(pedVariations[modelid][4], pedVariations[modelid][currentTown], pedCurrentVariations[modelid]);
264+
modelid = std::stoi(i.first);
265+
else
266+
CModelInfo::GetModelInfo((char*)i.first.c_str(), &modelid);
269267

270-
std::vector<unsigned short> vec = iniLineParser(i.first, ((lastZone[0] == 0) ? zInfo->m_szLabel : lastZone), &iniPed);
271-
if (!vec.empty())
272-
{
273-
if (pedMergeZones.find((unsigned short)modelid) != pedMergeZones.end())
274-
pedCurrentVariations[modelid] = vectorUnion(pedCurrentVariations[modelid], vec);
275-
else
276-
pedCurrentVariations[modelid] = vec;
277-
}
268+
if (modelid > 0 && modelid < 300)
269+
{
270+
vectorUnion(pedVariations[modelid][4], pedVariations[modelid][currentTown], pedCurrentVariations[modelid]);
278271

279-
vec = iniLineParser(i.first, currentInterior, &iniPed);
280-
if (!vec.empty())
272+
std::vector<unsigned short> vec = iniLineParser(i.first, ((lastZone[0] == 0) ? zInfo->m_szLabel : lastZone), &iniPed);
273+
if (!vec.empty())
274+
{
275+
if (pedMergeZones.find((unsigned short)modelid) != pedMergeZones.end())
281276
pedCurrentVariations[modelid] = vectorUnion(pedCurrentVariations[modelid], vec);
277+
else
278+
pedCurrentVariations[modelid] = vec;
279+
}
282280

283-
if (wanted)
284-
{
285-
unsigned int wantedLevel = (wanted->m_nWantedLevel > 0) ? (wanted->m_nWantedLevel - 1) : (wanted->m_nWantedLevel);
286-
if (!pedWantedVariations[modelid][wantedLevel].empty() && !pedCurrentVariations[modelid].empty())
287-
filterWantedVariations(pedCurrentVariations[modelid], pedWantedVariations[modelid][wantedLevel]);
288-
}
281+
vec = iniLineParser(i.first, currentInterior, &iniPed);
282+
if (!vec.empty())
283+
pedCurrentVariations[modelid] = vectorUnion(pedCurrentVariations[modelid], vec);
284+
285+
if (wanted)
286+
{
287+
unsigned int wantedLevel = (wanted->m_nWantedLevel > 0) ? (wanted->m_nWantedLevel - 1) : (wanted->m_nWantedLevel);
288+
if (!pedWantedVariations[modelid][wantedLevel].empty() && !pedCurrentVariations[modelid].empty())
289+
filterWantedVariations(pedCurrentVariations[modelid], pedWantedVariations[modelid][wantedLevel]);
289290
}
290291
}
292+
}
291293

292294

293295
for (auto& i : iniVeh.data)
296+
{
297+
int modelid = 0;
294298
if (i.first[0] >= '0' && i.first[0] <= '9')
299+
modelid = std::stoi(i.first);
300+
else
301+
CModelInfo::GetModelInfo((char*)i.first.c_str(), &modelid);
302+
303+
modelid -= 400;
304+
if (modelid > 0 && modelid < 212)
295305
{
296-
int modelid = std::stoi(i.first) - 400;
297-
if (modelid > 0 && modelid < 212)
298-
{
299-
vectorUnion(vehVariations[modelid][4], vehVariations[modelid][currentTown], vehCurrentVariations[modelid]);
306+
vectorUnion(vehVariations[modelid][4], vehVariations[modelid][currentTown], vehCurrentVariations[modelid]);
300307

301-
std::vector<unsigned short> vec = iniLineParser(i.first, ((lastZone[0] == 0) ? zInfo->m_szLabel : lastZone), &iniVeh);
302-
if (!vec.empty())
303-
{
304-
if (vehMergeZones.find((unsigned short)modelid) != vehMergeZones.end())
305-
vehCurrentVariations[modelid] = vectorUnion(vehCurrentVariations[modelid], vec);
306-
else
307-
vehCurrentVariations[modelid] = vec;
308-
}
308+
std::vector<unsigned short> vec = iniLineParser(i.first, ((lastZone[0] == 0) ? zInfo->m_szLabel : lastZone), &iniVeh);
309+
if (!vec.empty())
310+
{
311+
if (vehMergeZones.find((unsigned short)modelid) != vehMergeZones.end())
312+
vehCurrentVariations[modelid] = vectorUnion(vehCurrentVariations[modelid], vec);
313+
else
314+
vehCurrentVariations[modelid] = vec;
315+
}
309316

310-
if (wanted)
311-
{
312-
unsigned int wantedLevel = (wanted->m_nWantedLevel > 0) ? (wanted->m_nWantedLevel - 1) : (wanted->m_nWantedLevel);
313-
if (!vehWantedVariations[modelid][wantedLevel].empty() && !vehCurrentVariations[modelid].empty())
314-
filterWantedVariations(vehCurrentVariations[modelid], vehWantedVariations[modelid][wantedLevel]);
315-
}
317+
if (wanted)
318+
{
319+
unsigned int wantedLevel = (wanted->m_nWantedLevel > 0) ? (wanted->m_nWantedLevel - 1) : (wanted->m_nWantedLevel);
320+
if (!vehWantedVariations[modelid][wantedLevel].empty() && !vehCurrentVariations[modelid].empty())
321+
filterWantedVariations(vehCurrentVariations[modelid], vehWantedVariations[modelid][wantedLevel]);
316322
}
317-
}
323+
}
324+
}
318325
}
319326

320327
void printCurrentVariations()
@@ -414,12 +421,18 @@ void installHooks()
414421

415422
void loadIniData(bool firstTime)
416423
{
417-
418-
for (unsigned short i = 0; i < 300; i++)
424+
//for (unsigned short i = 0; i < 300; i++)
425+
for (auto &iniData : iniPed.data)
419426
{
420-
std::string section = std::to_string(i);
427+
int i = 0;
428+
std::string section = iniData.first;
429+
430+
if (section[0] >= '0' && section[0] <= '9')
431+
i = std::stoi(iniData.first);
432+
else
433+
CModelInfo::GetModelInfo((char*)section.c_str(), &i);
421434

422-
if (iniPed.data.find(section) != iniPed.data.end())
435+
if (i > 0 && i < 300)
423436
{
424437
pedVariations[i][0] = iniLineParser(section, "Countryside", &iniPed);
425438
pedVariations[i][1] = iniLineParser(section, "LosSantos", &iniPed);
@@ -473,7 +486,7 @@ void loadIniData(bool firstTime)
473486
pedOriginalModels.insert({ pedVariations[i][j][k], i });
474487

475488
if (iniPed.ReadInteger(section, "MergeZonesWithCities", 0) == 1)
476-
pedMergeZones.insert(i);
489+
pedMergeZones.insert((unsigned short)i);
477490
}
478491
}
479492

@@ -682,6 +695,8 @@ class ModelVariations {
682695

683696
Events::initScriptsEvent += []
684697
{
698+
loadIniData(false);
699+
685700
if (loadAllVehicles)
686701
for (int i = 400; i < 612; i++)
687702
CStreaming::RequestModel(i, KEEP_IN_MEMORY);

ModelVariations/Vehicles.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <CDarkel.h>
1212
#include <CGeneral.h>
1313
#include <CHeli.h>
14+
#include <CModelInfo.h>
1415
#include <CPopulation.h>
1516
#include <CStreaming.h>
1617
#include <CTheScripts.h>
@@ -171,26 +172,39 @@ void readVehicleIni(bool firstTime)
171172
}
172173

173174
for (auto& i : result) //for every zone name
174-
for (auto &j : iniVeh.data)
175+
for (auto& j : iniVeh.data)
176+
{
177+
int modelid = 0;
175178
if (j.first[0] >= '0' && j.first[0] <= '9')
176-
{
177-
int modelid = std::stoi(j.first);
179+
modelid = std::stoi(j.first);
180+
else
181+
CModelInfo::GetModelInfo((char*)j.first.c_str(), &modelid);
178182

183+
if (modelid > 0)
184+
{
179185
std::vector<unsigned short> vec = iniLineParser(j.first, i, &iniVeh); //get zone name 'i' of veh id 'j'
180186

181187
if (!vec.empty()) //if veh id 'j' has variations in zone 'i'
182188
for (auto& k : vec) //for every variation 'k' of veh id 'j' in zone 'i'
183189
if (modelid != k && !(IdExists(vehInheritExclude, k)))
184190
vehOriginalModels.insert({ k, modelid });
185-
}
191+
}
192+
}
186193

187194
if (zoneFile.is_open())
188195
zoneFile.close();
189196

190-
for (unsigned short i = 400; i < 612; i++)
197+
for (auto& inidata : iniVeh.data)
191198
{
192-
std::string section = std::to_string(i);
193-
if (iniVeh.data.find(section) != iniVeh.data.end())
199+
std::string section = inidata.first;
200+
int modelid = 0;
201+
if (section[0] >= '0' && section[0] <= '9')
202+
modelid = std::stoi(section);
203+
else
204+
CModelInfo::GetModelInfo((char*)section.c_str(), &modelid);
205+
206+
unsigned short i = (unsigned short)modelid;
207+
if (i >= 400 && i < 612)
194208
{
195209
if (iniVeh.ReadInteger(section, "ChangeOnlyParked", 0) == 1)
196210
parkedCars.insert(i);
@@ -252,10 +266,17 @@ void readVehicleIni(bool firstTime)
252266
enableLights = iniVeh.ReadInteger("Settings", "EnableLights", 0);
253267

254268
for (auto& i : iniVeh.data)
269+
{
270+
int k = 0;
255271
if (i.first[0] >= '0' && i.first[0] <= '9')
256-
{
257-
unsigned short modelid = (unsigned short)std::stoi(i.first);
272+
k = std::stoi(i.first);
273+
else
274+
CModelInfo::GetModelInfo((char*)i.first.c_str(), &k);
258275

276+
unsigned short modelid = (unsigned short)k;
277+
278+
if (modelid >= 400)
279+
{
259280
std::vector<unsigned short> vec = iniLineParser(i.first, "Countryside", &iniVeh, true);
260281
if (!vec.empty()) vehGroups[modelid][0] = vec;
261282

@@ -406,6 +427,7 @@ void readVehicleIni(bool firstTime)
406427
if (!vec.empty())
407428
vehPassengers.insert({ modelid, vec });
408429
}
430+
}
409431

410432
if (firstTime)
411433
{

0 commit comments

Comments
 (0)