From da17ffebca1e629a11e63ce1ffd8c9d04cf9a393 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Sat, 26 Nov 2022 09:15:03 +0600 Subject: [PATCH] Resolve #82 & #83 --- src/pages/menu.cpp | 3 +- src/pages/vehicle.cpp | 251 +++++++++++++++++++++++++++--------------- 2 files changed, 165 insertions(+), 89 deletions(-) diff --git a/src/pages/menu.cpp b/src/pages/menu.cpp index ad4ba37..7b395ad 100644 --- a/src/pages/menu.cpp +++ b/src/pages/menu.cpp @@ -77,7 +77,8 @@ void MenuPage::Draw() { if (Locale::SetLocale(selected) == Locale::eReturnCodes::SUCCESS) { - gConfig.Set("Menu.Language", vec[selected]); + std::string label = vec[selected]; + gConfig.Set("Menu.Language", label); } else { diff --git a/src/pages/vehicle.cpp b/src/pages/vehicle.cpp index 26757bc..c97ae0f 100644 --- a/src/pages/vehicle.cpp +++ b/src/pages/vehicle.cpp @@ -252,9 +252,167 @@ void VehiclePage::AddNew() #ifdef GTASA void VehiclePage::SpawnVehicle(std::string& smodel) +{ + CPlayerPed* player = FindPlayerPed(); + int hplayer = CPools::GetPedRef(player); + int imodel = std::stoi(smodel); + CVehicle* pVeh = nullptr; + + CVector pos = player->GetPosition(); + float speed = 0; + + bool bInVehicle = Command(hplayer); + if (bInVehicle && m_Spawner.m_bAsDriver) + { + CVehicle* pVeh = player->m_pVehicle; + int hVeh = CPools::GetVehicleRef(pVeh); + pos = pVeh->GetPosition(); + + Command(hVeh, &speed); + Command(hplayer, pos.x, pos.y, pos.z); + + if (pVeh->m_nVehicleClass == VEHICLE_TRAIN) + { + Command(hVeh); + } + else + { + Command(hVeh); + } + } + + if (player->m_nAreaCode == 0) + { + if (m_Spawner.m_bInAir && (CModelInfo::IsHeliModel(imodel) || CModelInfo::IsPlaneModel(imodel))) + { + pos.z = 400; + } + else + { + pos.z -= 5; + } + } + + if (CModelInfo::IsTrainModel(imodel)) + { + int trainID = GetRandomTrainIdForModel(imodel); + + if (trainID == -1) // Unknown train id + { + return; + } + + int hVeh = 0; + + // Loading all train related models + CStreaming::RequestModel(590, PRIORITY_REQUEST); + CStreaming::RequestModel(538, PRIORITY_REQUEST); + CStreaming::RequestModel(570, PRIORITY_REQUEST); + CStreaming::RequestModel(569, PRIORITY_REQUEST); + CStreaming::RequestModel(537, PRIORITY_REQUEST); + CStreaming::RequestModel(449, PRIORITY_REQUEST); + CStreaming::LoadAllRequestedModels(false); + + CTrain* pTrain = nullptr; + CTrain* carraige = nullptr; + int track = Random(0, 1); + int node = CTrain::FindClosestTrackNode(pos, &track); + CTrain::CreateMissionTrain(pos, (Random(0, 1)) == 1 ? true : false, trainID, &pTrain, &carraige, node, track, false); + + pVeh = (CVehicle*)pTrain; + hVeh = CPools::GetVehicleRef(pVeh); + if (pVeh->m_pDriver) + { + Command(CPools::GetPedRef(pVeh->m_pDriver)); + } + + if (m_Spawner.m_bAsDriver) + { + Command(hplayer, hVeh); + Util::SetCarForwardSpeed(pVeh, speed); + } + Command(hVeh); + Command(hVeh); + CStreaming::SetModelIsDeletable(590); + CStreaming::SetModelIsDeletable(538); + CStreaming::SetModelIsDeletable(570); + CStreaming::SetModelIsDeletable(569); + CStreaming::SetModelIsDeletable(537); + CStreaming::SetModelIsDeletable(449); + } + else + { + CStreaming::RequestModel(imodel, PRIORITY_REQUEST); + CStreaming::LoadAllRequestedModels(false); + + if (m_Spawner.m_nLicenseText[0] != '\0') + { + Command(imodel, m_Spawner.m_nLicenseText); + } + + int hveh = 0; + if (m_Spawner.m_bAsDriver) + { + Command(imodel, pos.x, pos.y, pos.z + 4.0f, &hveh); + 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 + { + player->TransformFromObjectSpace(pos, CVector(0, 10, 0)); + Command(imodel, pos.x, pos.y, pos.z + 3.0f, &hveh); + pVeh = CPools::GetVehicle(hveh); + pVeh->SetHeading(player->GetHeading() + 55.0f); + } + pVeh->m_eDoorLock = DOORLOCK_UNLOCKED; + pVeh->m_nAreaCode = player->m_nAreaCode; + Command(CPools::GetVehicleRef(pVeh)); + CStreaming::SetModelIsDeletable(imodel); + } + pVeh->m_nVehicleFlags.bHasBeenOwnedByPlayer = true; +} + #else + void VehiclePage::SpawnVehicle(std::string& rootkey, std::string& vehName, std::string& smodel) -#endif { CPlayerPed* player = FindPlayerPed(); int hplayer = CPools::GetPedRef(player); @@ -274,20 +432,7 @@ void VehiclePage::SpawnVehicle(std::string& rootkey, std::string& vehName, std:: Command(hveh, &speed); Command(hplayer, pos.x, pos.y, pos.z); - -#ifdef GTASA - if (pveh->m_nVehicleClass == VEHICLE_TRAIN) - { - Command(hveh); - } - else - { - - Command(hveh); - } -#else Command(hveh); -#endif } if (interior == 0) @@ -302,73 +447,14 @@ void VehiclePage::SpawnVehicle(std::string& rootkey, std::string& vehName, std:: } } -#ifdef GTASA - if (CModelInfo::IsTrainModel(imodel)) - { - int train_id = GetRandomTrainIdForModel(imodel); - - if (train_id == -1) // Unknown train id - return; - - int hveh = 0; - - // Loading all train related models - CStreaming::RequestModel(590, PRIORITY_REQUEST); - CStreaming::RequestModel(538, PRIORITY_REQUEST); - CStreaming::RequestModel(570, PRIORITY_REQUEST); - CStreaming::RequestModel(569, PRIORITY_REQUEST); - CStreaming::RequestModel(537, PRIORITY_REQUEST); - CStreaming::RequestModel(449, PRIORITY_REQUEST); - - CStreaming::LoadAllRequestedModels(false); - - CTrain* train = nullptr; - CTrain* carraige = nullptr; - int track = Random(0, 1); - int node = CTrain::FindClosestTrackNode(pos, &track); - CTrain::CreateMissionTrain(pos, (Random(0, 1)) == 1 ? true : false, train_id, &train, &carraige, node, - track, false); - - veh = (CVehicle*)train; - hveh = CPools::GetVehicleRef(veh); - if (veh->m_pDriver) - { - Command(CPools::GetPedRef(veh->m_pDriver)); - } - - if (m_Spawner.m_bAsDriver) - { - Command(hplayer, hveh); - Util::SetCarForwardSpeed(veh, speed); - } - Command(hveh); - Command(hveh); - CStreaming::SetModelIsDeletable(590); - CStreaming::SetModelIsDeletable(538); - CStreaming::SetModelIsDeletable(570); - CStreaming::SetModelIsDeletable(569); - CStreaming::SetModelIsDeletable(537); - CStreaming::SetModelIsDeletable(449); - } - else - { -#endif CStreaming::RequestModel(imodel, PRIORITY_REQUEST); CStreaming::LoadAllRequestedModels(false); -#ifdef GTASA - if (m_Spawner.m_nLicenseText[0] != '\0') - { - Command(imodel, m_Spawner.m_nLicenseText); - } -#endif int hveh = 0; if (m_Spawner.m_bAsDriver) { Command(imodel, pos.x, pos.y, pos.z + 4.0f, &hveh); veh = CPools::GetVehicle(hveh); -#ifdef GTASA - veh->SetHeading(player->GetHeading()); -#elif GTAVC +#ifdef GTAVC float x,y,z; player->m_placement.GetOrientation(x, y, z); veh->m_placement.SetOrientation(x, y, z); @@ -378,21 +464,14 @@ void VehiclePage::SpawnVehicle(std::string& rootkey, std::string& vehName, std:: veh->SetOrientation(x, y, z); #endif Command(hplayer, hveh); - Util::SetCarForwardSpeed(veh, speed); } else { -#ifdef GTASA - player->TransformFromObjectSpace(pos, CVector(0, 10, 0)); -#else player->TransformFromObjectSpace(pos); -#endif Command(imodel, pos.x, pos.y, pos.z + 3.0f, &hveh); veh = CPools::GetVehicle(hveh); -#ifdef GTASA - veh->SetHeading(player->GetHeading() + 55.0f); -#elif GTAVC +#ifdef GTAVC float x,y,z; player->m_placement.GetOrientation(x, y, z); veh->m_placement.SetOrientation(x, y, z); @@ -403,18 +482,14 @@ void VehiclePage::SpawnVehicle(std::string& rootkey, std::string& vehName, std:: #endif } veh->m_eDoorLock = DOORLOCK_UNLOCKED; -#ifndef GTA3 +#ifdef GTAVC BY_GAME(veh->m_nAreaCode, veh->m_nAreaCode, NULL) = interior; #endif Command(CPools::GetVehicleRef(veh)); CStreaming::SetModelIsDeletable(imodel); -#ifdef GTASA - } - veh->m_nVehicleFlags.bHasBeenOwnedByPlayer = true; -#else Command(); -#endif } +#endif void VehiclePage::Draw() {