diff --git a/src/custom/vehcustmzr.cpp b/src/custom/vehcustmzr.cpp index e48a8e9..c298e60 100644 --- a/src/custom/vehcustmzr.cpp +++ b/src/custom/vehcustmzr.cpp @@ -80,6 +80,26 @@ void VehCustmzrMgr::RemoveComponent(const std::string& component, const bool dis } } +bool VehCustmzrMgr::IsSideskirtComponent(unsigned int compID) +{ + static int models[] = + { 1007, 1026, 1027, 1030, 1031, 1036, 1039, 1040, 1041, 1042, 1047, 1048, 1051, 1052, 1056, + 1057, 1062, 1063, 1069, 1070, 1071, 1072, 1090, 1093, 1094, 1095, 1099, 1101, 1102, 1106, 1107, 1108, 1118, 1119, + 1120, 1121, 1122, 1124, 1133, 1134, 1137 + }; + static int maxSize = sizeof(models)/sizeof(models[0]); + + for (int j = 0; j != maxSize; ++j) + { + if (compID == models[j]) + { + return true; + } + } + + return false; +} + void VehCustmzrMgr::ApplyCustomizations(std::string& cat, std::string& key, std::string& val) { CVehicle *pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle()); @@ -292,6 +312,11 @@ VehCustmzrMgr::VehCustmzrMgr() #endif } +bool VehCustmzrMgr::IsValidComponent(CVehicle *pVeh, unsigned int compID) +{ + return CallAndReturn(compID, pVeh); +} + void VehCustmzrMgr::Draw() { CVehicle* pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle()); @@ -505,7 +530,7 @@ void VehCustmzrMgr::Draw() }, [](std::string& str) { - return ((bool(*)(int, CVehicle*))0x49B010)(std::stoi(str), FindPlayerPed()->m_pVehicle); + return VehCustmzr.IsValidComponent(FindPlayerPed()->m_pVehicle, std::stoi(str)); }); ImGui::EndTabItem(); diff --git a/src/custom/vehcustmzr.h b/src/custom/vehcustmzr.h index b167dcd..1420c0d 100644 --- a/src/custom/vehcustmzr.h +++ b/src/custom/vehcustmzr.h @@ -49,6 +49,14 @@ public: // Draw color, neon & texture tabs void Draw(); + +#ifdef GTASA + // Returns true if the component is a sideskirt + bool IsSideskirtComponent(unsigned int compID); + + // Returns true if the componenet is supported by the vehicle + bool IsValidComponent(CVehicle *pVeh, unsigned int compID); +#endif }; extern VehCustmzrMgr& VehCustmzr; \ No newline at end of file diff --git a/src/pages/vehicle.cpp b/src/pages/vehicle.cpp index c97ae0f..6d91ef6 100644 --- a/src/pages/vehicle.cpp +++ b/src/pages/vehicle.cpp @@ -357,42 +357,6 @@ void VehiclePage::SpawnVehicle(std::string& smodel) pVeh = CPools::GetVehicle(hveh); pVeh->SetHeading(player->GetHeading()); Command(hplayer, hveh); - - if (pVeh->m_nVehicleSubClass == VEHICLE_AUTOMOBILE) - { - static int exceptions[] = {1007, 1026, 1031, 1042, 1047, 1048, 1070, 1090}; - static int maxSize = sizeof(exceptions)/sizeof(exceptions[0]); - - for (int i = 0; i < 20; ++i) - { - unsigned int compID = Random(1000, 1093); - bool skip = false; - - for (int j = 0; j != maxSize; ++j) - { - if (compID == exceptions[j]) - { - skip = true; - break; - } - } - - if (skip) - { - continue; - } - - if (CallAndReturn(compID, pVeh)) - { - CStreaming::RequestModel(compID, eStreamingFlags::PRIORITY_REQUEST); - CStreaming::LoadAllRequestedModels(true); - Log::Print("Adding component {}", compID); - pVeh->AddVehicleUpgrade(compID); - Log::Print("Added component {}", compID); - CStreaming::SetModelIsDeletable(compID); - } - } - } Util::SetCarForwardSpeed(pVeh, speed); } else @@ -402,6 +366,29 @@ void VehiclePage::SpawnVehicle(std::string& smodel) pVeh = CPools::GetVehicle(hveh); pVeh->SetHeading(player->GetHeading() + 55.0f); } + + // Add random tunes + if (pVeh->m_nVehicleSubClass <= VEHICLE_QUAD) + { + for (int i = 0; i < 20; ++i) + { + unsigned int compID = Random(1000, 1093); + + if (VehCustmzr.IsSideskirtComponent(compID)) + { + continue; + } + + if (VehCustmzr.IsValidComponent(pVeh, compID)) + { + CStreaming::RequestModel(compID, eStreamingFlags::PRIORITY_REQUEST); + CStreaming::LoadAllRequestedModels(true); + pVeh->AddVehicleUpgrade(compID); + CStreaming::SetModelIsDeletable(compID); + } + } + } + pVeh->m_eDoorLock = DOORLOCK_UNLOCKED; pVeh->m_nAreaCode = player->m_nAreaCode; Command(CPools::GetVehicleRef(pVeh));