[SA] Add randomized tunes when spawning vehicles

This commit is contained in:
Grinch_ 2022-11-27 00:48:04 +06:00
parent da17ffebca
commit c0aecc19ae
3 changed files with 57 additions and 37 deletions

View File

@ -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) void VehCustmzrMgr::ApplyCustomizations(std::string& cat, std::string& key, std::string& val)
{ {
CVehicle *pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle()); CVehicle *pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle());
@ -292,6 +312,11 @@ VehCustmzrMgr::VehCustmzrMgr()
#endif #endif
} }
bool VehCustmzrMgr::IsValidComponent(CVehicle *pVeh, unsigned int compID)
{
return CallAndReturn<bool, 0x49B010, int, CVehicle*>(compID, pVeh);
}
void VehCustmzrMgr::Draw() void VehCustmzrMgr::Draw()
{ {
CVehicle* pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle()); CVehicle* pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle());
@ -505,7 +530,7 @@ void VehCustmzrMgr::Draw()
}, },
[](std::string& str) [](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(); ImGui::EndTabItem();

View File

@ -49,6 +49,14 @@ public:
// Draw color, neon & texture tabs // Draw color, neon & texture tabs
void Draw(); 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; extern VehCustmzrMgr& VehCustmzr;

View File

@ -357,42 +357,6 @@ void VehiclePage::SpawnVehicle(std::string& smodel)
pVeh = CPools::GetVehicle(hveh); pVeh = CPools::GetVehicle(hveh);
pVeh->SetHeading(player->GetHeading()); pVeh->SetHeading(player->GetHeading());
Command<Commands::WARP_CHAR_INTO_CAR>(hplayer, hveh); Command<Commands::WARP_CHAR_INTO_CAR>(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<bool, 0x49B010, int, CVehicle*>(compID, pVeh))
{
CStreaming::RequestModel(compID, eStreamingFlags::PRIORITY_REQUEST);
CStreaming::LoadAllRequestedModels(true);
Log::Print<eLogLevel::Debug>("Adding component {}", compID);
pVeh->AddVehicleUpgrade(compID);
Log::Print<eLogLevel::Debug>("Added component {}", compID);
CStreaming::SetModelIsDeletable(compID);
}
}
}
Util::SetCarForwardSpeed(pVeh, speed); Util::SetCarForwardSpeed(pVeh, speed);
} }
else else
@ -402,6 +366,29 @@ void VehiclePage::SpawnVehicle(std::string& smodel)
pVeh = CPools::GetVehicle(hveh); pVeh = CPools::GetVehicle(hveh);
pVeh->SetHeading(player->GetHeading() + 55.0f); 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_eDoorLock = DOORLOCK_UNLOCKED;
pVeh->m_nAreaCode = player->m_nAreaCode; pVeh->m_nAreaCode = player->m_nAreaCode;
Command<Commands::MARK_CAR_AS_NO_LONGER_NEEDED>(CPools::GetVehicleRef(pVeh)); Command<Commands::MARK_CAR_AS_NO_LONGER_NEEDED>(CPools::GetVehicleRef(pVeh));