From e74089ec747f13e384ce19487a53ec7c77dd1f3a Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Sun, 24 Oct 2021 02:57:34 +0600 Subject: [PATCH] [III] Finish vehicle tab --- src/filehandler.cpp | 34 +---- src/filehandler.h | 5 +- src/vehicle.cpp | 348 ++++++++++++++++++++------------------------ src/vehicle.h | 2 - 4 files changed, 162 insertions(+), 227 deletions(-) diff --git a/src/filehandler.cpp b/src/filehandler.cpp index 630f94b..4380f72 100644 --- a/src/filehandler.cpp +++ b/src/filehandler.cpp @@ -61,8 +61,7 @@ void FileHandler::GenerateHandlingFile(int pHandling, std::map fclose(fp); } -void FileHandler::FetchColorData(std::vector>& storeVec, - std::map>& storeMap) +void FileHandler::FetchColorData(std::vector>& storeVec) { std::string m_FilePath = GAME_PATH((char*)"/data/carcols.dat"); @@ -129,37 +128,6 @@ void FileHandler::FetchColorData(std::vector>& storeVec, gLog << "Error parsing carcols.dat, " << line << std::endl; } } - - if (bIsCar) - { - std::string temp; - std::stringstream ss(line); - - // Format: modelname, colorindex1, colorindex2,... - getline(ss, temp, ','); - std::string name = temp; - while (getline(ss, temp, ',')) - { - try - { - std::for_each(name.begin(), name.end(), [](char& c) - { - c = ::toupper(c); - }); - - int val = std::stoi(temp); - if (!(std::find(storeMap[name].begin(), storeMap[name].end(), val) != - storeMap[name].end())) - { - storeMap[name].push_back(val); - } - } - catch (...) - { - gLog << "Error parsing carcols.dat, " << line << std::endl; - } - } - } } file.close(); diff --git a/src/filehandler.h b/src/filehandler.h index 51def1a..55bed4b 100644 --- a/src/filehandler.h +++ b/src/filehandler.h @@ -10,11 +10,10 @@ public: FileHandler(FileHandler&) = delete; /* - Parses data/carcols.dat file and stores color data per vehicle + Parses data/carcols.dat file and stores color data TODO: Implement something that also parses modloader data */ - static void FetchColorData(std::vector>& storeVec, - std::map>& storeMap); + static void FetchColorData(std::vector>& storeVec); /* Parses data/vehicles.ide file and stores handingId in a map TODO: Implement something that also parses modloader data diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 0788645..e6206c5 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -36,7 +36,7 @@ Vehicle::Vehicle() #ifdef GTASA FileHandler::FetchHandlingID(m_VehicleIDE); #endif - FileHandler::FetchColorData(m_CarcolsColorData, m_CarcolsCarData); + FileHandler::FetchColorData(m_CarcolsColorData); Events::processScriptsEvent += [this] { @@ -335,169 +335,164 @@ void Vehicle::SpawnVehicle(std::string& rootkey, std::string& vehName, std::stri int interior = BY_GAME(player->m_nAreaCode, player->m_nInterior, 0); - if (Command(imodel)) + CVector pos = player->GetPosition(); + int speed = 0; + + bool bInVehicle = Command(hplayer); + if (bInVehicle && m_Spawner::m_bSpawnInside) { - CVector pos = player->GetPosition(); - int speed = 0; + CVehicle* pveh = player->m_pVehicle; + int hveh = CPools::GetVehicleRef(pveh); + pos = pveh->GetPosition(); - bool bInVehicle = Command(hplayer); - if (bInVehicle && m_Spawner::m_bSpawnInside) - { - CVehicle* pveh = player->m_pVehicle; - int hveh = CPools::GetVehicleRef(pveh); - pos = pveh->GetPosition(); + Command(hveh, &speed); - Command(hveh, &speed); - - Command(hplayer, pos.x, pos.y, pos.z); + Command(hplayer, pos.x, pos.y, pos.z); #ifdef GTASA - if (pveh->m_nVehicleClass == VEHICLE_TRAIN) - { - Command(hveh); - } - else - { - Command(hveh); - } -#else // GTA3 & GTAVC - Command(hveh); -#endif - } - - if (interior == 0) + if (pveh->m_nVehicleClass == VEHICLE_TRAIN) { - if (m_Spawner::m_bSpawnInAir && (CModelInfo::IsHeliModel(imodel) || CModelInfo::IsPlaneModel(imodel))) - { - pos.z = 400; - } - else - { - pos.z -= 5; - } - } - -#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_bSpawnInside) - { - Command(hplayer, hveh); - Command(hveh, speed); - } - Command(hveh); - Command(hveh); - CStreaming::SetModelIsDeletable(590); - CStreaming::SetModelIsDeletable(538); - CStreaming::SetModelIsDeletable(570); - CStreaming::SetModelIsDeletable(569); - CStreaming::SetModelIsDeletable(537); - CStreaming::SetModelIsDeletable(449); + Command(hveh); } 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_bSpawnInside) - { - Command(imodel, pos.x, pos.y, pos.z + 4.0f, &hveh); - veh = CPools::GetVehicle(hveh); -#ifdef GTASA - veh->SetHeading(player->GetHeading()); -#elif GTAVC - float x,y,z; - player->m_placement.GetOrientation(x, y, z); - veh->m_placement.SetOrientation(x, y, z); -#else // GTA3 - float x,y,z; - player->GetOrientation(x, y, z); - veh->SetOrientation(x, y, z); -#endif - Command(hplayer, hveh); - Command(hveh, speed); - } - else - { -#ifdef GTASA - player->TransformFromObjectSpace(pos, CVector(0, 10, 0)); -#else // GTA3 & GTAVC - 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 - float x,y,z; - player->m_placement.GetOrientation(x, y, z); - veh->m_placement.SetOrientation(x, y, z); -#else // GTA3 - float x,y,z; - player->GetOrientation(x, y, z); - veh->SetOrientation(x, y, z); -#endif - } - BY_GAME(veh->m_nDoorLock, veh->m_nLockStatus, veh->m_nDoorLock) = CARLOCK_UNLOCKED; -#ifndef GTA3 - BY_GAME(veh->m_nAreaCode, veh->m_nInterior) = interior; -#endif - Command(CPools::GetVehicleRef(veh)); - CStreaming::SetModelIsDeletable(imodel); -#ifdef GTASA + Command(hveh); } - veh->m_nVehicleFlags.bHasBeenOwnedByPlayer = true; #else // GTA3 & GTAVC - Command(); + Command(hveh); #endif } + + if (interior == 0) + { + if (m_Spawner::m_bSpawnInAir && (CModelInfo::IsHeliModel(imodel) || CModelInfo::IsPlaneModel(imodel))) + { + pos.z = 400; + } + else + { + pos.z -= 5; + } + } + +#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_bSpawnInside) + { + Command(hplayer, hveh); + Command(hveh, 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_bSpawnInside) + { + Command(imodel, pos.x, pos.y, pos.z + 4.0f, &hveh); + veh = CPools::GetVehicle(hveh); +#ifdef GTASA + veh->SetHeading(player->GetHeading()); +#elif GTAVC + float x,y,z; + player->m_placement.GetOrientation(x, y, z); + veh->m_placement.SetOrientation(x, y, z); +#else // GTA3 + float x,y,z; + player->GetOrientation(x, y, z); + veh->SetOrientation(x, y, z); +#endif + Command(hplayer, hveh); + Command(hveh, speed); + } + else + { +#ifdef GTASA + player->TransformFromObjectSpace(pos, CVector(0, 10, 0)); +#else // GTA3 & GTAVC + 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 + float x,y,z; + player->m_placement.GetOrientation(x, y, z); + veh->m_placement.SetOrientation(x, y, z); +#else // GTA3 + float x,y,z; + player->GetOrientation(x, y, z); + veh->SetOrientation(x, y, z); +#endif + } + BY_GAME(veh->m_nDoorLock, veh->m_nLockStatus, veh->m_nDoorLock) = CARLOCK_UNLOCKED; +#ifndef GTA3 + BY_GAME(veh->m_nAreaCode, veh->m_nInterior) = interior; +#endif + Command(CPools::GetVehicleRef(veh)); + CStreaming::SetModelIsDeletable(imodel); +#ifdef GTASA + } + veh->m_nVehicleFlags.bHasBeenOwnedByPlayer = true; +#else // GTA3 & GTAVC + Command(); +#endif } std::string Vehicle::GetNameFromModel(int model) { - CBaseModelInfo* info; -#ifdef GTASA - info = CModelInfo::GetModelInfo(model); +#ifdef GTA3 + return std::to_string(model); #else - info = CModelInfo::ms_modelInfoPtrs[model]; + return (const char*)CModelInfo::GetModelInfo(model) + 0x32; #endif - return (const char*)info + 0x32; } int Vehicle::GetModelFromName(const char* name) @@ -522,7 +517,7 @@ void Vehicle::Draw() int hplayer = CPools::GetPedRef(pPlayer); CVehicle *pVeh = pPlayer->m_pVehicle; - if (ImGui::Button("Blow up cars", ImVec2(Ui::GetSize(BY_GAME(3,2))))) + if (ImGui::Button("Blow up cars", ImVec2(Ui::GetSize(BY_GAME(3,2,2))))) { for (CVehicle *pVeh : CPools::ms_pVehiclePool) { @@ -532,7 +527,7 @@ void Vehicle::Draw() ImGui::SameLine(); - if (ImGui::Button("Fix vehicle", ImVec2(Ui::GetSize(BY_GAME(3,2))))) + if (ImGui::Button("Fix vehicle", ImVec2(Ui::GetSize(BY_GAME(3,2,2))))) { if (pPlayer && pVeh) { @@ -802,7 +797,10 @@ void Vehicle::Draw() { ImGui::Spacing(); ImGui::BeginChild("MenusChild"); + +#ifdef GTASA Ui::EditAddress("Density multiplier", 0x8A5B20, 0, 1, 10); +#endif if (ImGui::CollapsingHeader("Enter nearest vehicle as")) { int hplayer = CPools::GetPedRef(pPlayer); @@ -829,6 +827,7 @@ void Vehicle::Draw() Command(hplayer, pClosestVeh); } +#ifndef GTA3 for (int i = 0; i < seats; ++i) { if (i % 2 != 1) @@ -846,6 +845,7 @@ void Vehicle::Draw() #endif } } +#endif } else { @@ -865,7 +865,7 @@ void Vehicle::Draw() for (CVehicle* pVeh : CPools::ms_pVehiclePool) { if (DistanceBetweenPoints(pVeh->GetPosition(), player->GetPosition()) < m_nVehRemoveRadius - && !(BY_GAME(player->m_nPedFlags.bInVehicle, true, true) && player->m_pVehicle == pVeh)) + && player->m_pVehicle != pVeh) { Command(CPools::GetVehicleRef(pVeh)); } @@ -875,6 +875,7 @@ void Vehicle::Draw() ImGui::Separator(); } +#ifndef GTA3 if (ImGui::CollapsingHeader("Traffic options")) { @@ -894,6 +895,7 @@ void Vehicle::Draw() ImGui::Spacing(); ImGui::Separator(); } +#endif if (pPlayer && pPlayer->m_pVehicle) { CVehicle* pVeh = pPlayer->m_pVehicle; @@ -1019,7 +1021,7 @@ void Vehicle::Draw() { return GetNameFromModel(std::stoi(str)); }); -#elif GTAVC +#else // GTA3 & GTAVC Ui::DrawJSON(m_Spawner::m_VehData, SpawnVehicle, nullptr); #endif ImGui::EndTabItem(); @@ -1061,14 +1063,12 @@ void Vehicle::Draw() ImGui::RadioButton("Primary", &m_Color::m_nRadioButton, 1); ImGui::RadioButton("Secondary", &m_Color::m_nRadioButton, 2); ImGui::NextColumn(); - ImGui::Checkbox("Show all", &m_Color::bShowAll); + ImGui::NewLine(); ImGui::RadioButton("Tertiary", &m_Color::m_nRadioButton, 3); ImGui::RadioButton("Quaternary", &m_Color::m_nRadioButton, 4); -#elif GTAVC - ImGui::Checkbox("Show all", &m_Color::bShowAll); +#else // GTA3 & GTAVC ImGui::RadioButton("Primary", &m_Color::m_nRadioButton, 1); ImGui::NextColumn(); - ImGui::NewLine(); ImGui::RadioButton("Secondary", &m_Color::m_nRadioButton, 2); #endif ImGui::Spacing(); @@ -1085,46 +1085,16 @@ void Vehicle::Draw() ImGui::BeginChild("Colorss"); - if (m_Color::bShowAll) + for (int colorId = 0; colorId < count; ++colorId) { - for (int colorId = 0; colorId < count; ++colorId) + if (Ui::ColorButton(colorId, m_CarcolsColorData[colorId], ImVec2(btnSize, btnSize))) { - if (Ui::ColorButton(colorId, m_CarcolsColorData[colorId], ImVec2(btnSize, btnSize))) - { - *(uint8_replacement*)(int(veh) + BY_GAME(0x433, 0x19F) + m_Color::m_nRadioButton) = colorId; - } - - if ((colorId + 1) % btnsInRow != 0) - { - ImGui::SameLine(0.0, 4.0); - } + *(uint8_replacement*)(int(veh) + BY_GAME(0x433, 0x19F, 0x19B) + m_Color::m_nRadioButton) = colorId; } - } - else - { - std::string vehName = GetNameFromModel(pPlayer->m_pVehicle->m_nModelIndex); - for (auto entry : m_CarcolsCarData) + + if ((colorId + 1) % btnsInRow != 0) { - if (entry.first == vehName) - { - int count = 1; - for (int colorId : entry.second) - { - if (Ui::ColorButton(colorId, m_CarcolsColorData[colorId], - ImVec2(btnSize, btnSize))) - { - *(uint8_replacement*)(int(veh) + BY_GAME(0x433, 0x19F) + m_Color::m_nRadioButton) = colorId; - } - - if (count % btnsInRow != 0) - { - ImGui::SameLine(0.0, 4.0); - } - ++count; - } - - break; - } + ImGui::SameLine(0.0, 4.0); } } diff --git a/src/vehicle.h b/src/vehicle.h index 50635b3..11993bf 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -24,12 +24,10 @@ private: static inline bool m_bLockSpeed; static inline float m_fLockSpeed; static inline std::vector> m_CarcolsColorData; - static inline std::map> m_CarcolsCarData; struct m_Color { static inline bool m_bMatFilter = true; static inline int m_nRadioButton = 1; - static inline bool bShowAll; static inline float m_fColorPicker[3]{ 0, 0, 0 }; };