Skip to content

Commit 23d9d8e

Browse files
committed
Fixed trucks despawning without despawning trailers
1 parent b66a597 commit 23d9d8e

2 files changed

Lines changed: 27 additions & 58 deletions

File tree

ModelVariations/ModelVariations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#pragma comment (lib, "urlmon.lib")
3030

3131

32-
#define MOD_VERSION "10.2"
32+
#define MOD_VERSION "10.3"
3333
//Using Plugin-SDK: 34ba198
3434

3535
struct jumpInfo {

ModelVariations/Vehicles.cpp

Lines changed: 26 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ int occupantModelIndex = -1;
6363

6464
std::map<CVehicle*, std::vector<CVehicle*>> spawnedTrailers; //<veh, <trailers>>
6565

66-
std::set<CVehicle*> unseenTrucks;
67-
6866
std::uintptr_t x6ABCBE_Destination = 0;
6967

7068
uint32_t asmNextInstr[4] = {};
@@ -205,25 +203,6 @@ bool isAnotherVehicleBehind(CVehicle* veh, const std::vector<CVehicle*> &excepti
205203
return false;
206204
}
207205

208-
bool isVehicleVisible(CVehicle* veh) //TODO: this isn't working 100% correctly
209-
{
210-
if (!IsVehiclePointerValid(veh))
211-
return false;
212-
213-
if (!TheCamera.IsSphereVisible(veh->GetPosition(), CModelInfo::GetModelInfo(veh->m_nModelIndex)->m_pColModel->m_boundSphere.m_fRadius))
214-
return false;
215-
216-
CColPoint outColPoint;
217-
CEntity* outEntity;
218-
219-
bool hit = CWorld::ProcessLineOfSight(TheCamera.GetPosition(), veh->GetPosition(), outColPoint, outEntity, true, true, false, true, true, false, false, false);
220-
221-
if (CVisibilityPlugins::VehicleVisibilityCB(veh->m_pRwClump) && (!hit || (outEntity == veh)))
222-
return true;
223-
224-
return false;
225-
}
226-
227206
int getTuningPartSlot(int model)
228207
{
229208
const auto mInfo = CModelInfo::GetModelInfo(model);
@@ -787,38 +766,6 @@ void VehicleVariations::Process()
787766
variationsUpdateQueued = 0;
788767
}
789768

790-
for (auto it = unseenTrucks.begin(); it != unseenTrucks.end();)
791-
{
792-
auto truck = *it;
793-
auto it2 = spawnedTrailers.find(truck);
794-
795-
if (/*isVehicleVisible(truck) || */it2 == spawnedTrailers.end())
796-
{
797-
it = unseenTrucks.erase(it);
798-
continue;
799-
}
800-
801-
for (auto trailer : it2->second)
802-
if (isVehicleVisible(trailer))
803-
{
804-
it = unseenTrucks.erase(it);
805-
break;
806-
}
807-
808-
auto detachedTrailer = std::find_if(it2->second.begin(), it2->second.end(), [](const CVehicle* trailer) {return trailer->m_pTractor == NULL; });
809-
if (detachedTrailer != it2->second.end() && (CTimer::m_snTimeInMilliseconds - (*detachedTrailer)->m_nCreationTime) > 500)
810-
{
811-
for (auto trailer : it2->second)
812-
{
813-
CWorld::Remove(trailer);
814-
trailer->Remove();
815-
}
816-
it2->second.clear();
817-
}
818-
if (it != unseenTrucks.end())
819-
it++;
820-
}
821-
822769
for (auto it = spawnedTrailers.begin(); it != spawnedTrailers.end(); )
823770
{
824771
CVehicle* veh = it->first;
@@ -1004,7 +951,6 @@ void VehicleVariations::Process()
1004951
CWorld::Add(trailer);
1005952
//CTheScripts::ClearSpaceForMissionEntity(previous->GetPosition(), trailer);
1006953
spawnedTrailers[veh].push_back(trailer);
1007-
unseenTrucks.insert(veh);
1008954
trailer->SetPosn(newPos);
1009955
if (previous == veh)
1010956
if (!trailer->SetTowLink(previous, 1))
@@ -1499,9 +1445,6 @@ void __cdecl PossiblyRemoveVehicleHooked(CVehicle* car)
14991445

15001446
std::vector<CVehicle*> trailersToCheck;
15011447

1502-
if (unseenTrucks.contains(car) && spawnedTrailers.contains(car))
1503-
trailersToCheck = spawnedTrailers[car];
1504-
15051448
for (auto it = spawnedTrailers.begin(); it != spawnedTrailers.end(); )
15061449
{
15071450
if (!it->second.empty())
@@ -1662,6 +1605,27 @@ void __fastcall AddAudioEventHooked(CAEVehicleAudioEntity* audio, void*, int aud
16621605
callMethodOriginal<address>(audio, audioEvent, fVolume);
16631606
}
16641607

1608+
void __cdecl CWorld__Remove(CEntity* entity)
1609+
{
1610+
if (entity)
1611+
{
1612+
auto it = spawnedTrailers.find((CVehicle*)entity);
1613+
if (it != spawnedTrailers.end())
1614+
{
1615+
for (auto trailer : it->second)
1616+
{
1617+
CWorld::Remove(trailer);
1618+
trailer->Remove();
1619+
}
1620+
spawnedTrailers.erase(it);
1621+
}
1622+
1623+
entity->Remove();
1624+
if (entity->m_nType > ENTITY_TYPE_BUILDING && entity->m_nType < ENTITY_TYPE_DUMMY)
1625+
((CPhysical*)entity)->RemoveFromMovingList();
1626+
}
1627+
}
1628+
16651629
template <std::uintptr_t address>
16661630
void __cdecl CWorld__AddHooked(CVehicle* a1)
16671631
{
@@ -2368,6 +2332,11 @@ void VehicleVariations::InstallHooks()
23682332
hookCall(0x6CFFBB, AddAudioEventHooked<0x6CFFBB>, "CAEVehicleAudioEntity::AddAudioEvent"); //CTrailer::SetTowLink
23692333
hookCall(0x6CEFCE, AddAudioEventHooked<0x6CEFCE>, "CAEVehicleAudioEntity::AddAudioEvent"); //CTrailer::BreakTowLink
23702334

2335+
if (memcmp(0x563280, "56 8B 74 24 08"))
2336+
injector::MakeJMP(0x563280, CWorld__Remove);
2337+
else
2338+
Log::LogModifiedAddress(0x563280, "Modified function detected: CWorld::Remove - 0x563280 is %s\n", bytesToString(0x563280, 5).c_str());
2339+
23712340
//Tuning for parked cars
23722341
hookCall(0x6F3C8C, CWorld__AddHooked<0x6F3C8C>, "CWorld::Add"); //CCarGenerator::DoInternalProcessing
23732342

0 commit comments

Comments
 (0)