diff --git a/src/game/backend/SavedVehicles.cpp b/src/game/backend/SavedVehicles.cpp index 047cfff..9953642 100644 --- a/src/game/backend/SavedVehicles.cpp +++ b/src/game/backend/SavedVehicles.cpp @@ -1,6 +1,5 @@ #include "SavedVehicles.hpp" -#include "core/backend/FiberPool.hpp" #include "core/backend/ScriptMgr.hpp" #include "core/frontend/Notifications.hpp" #include "game/gta/VehicleModel.hpp" @@ -18,21 +17,19 @@ namespace YimMenu void SavedVehicles::RefreshList(std::string folderName, std::vector& folders, std::vector& files) { - FiberPool::Push([folderName, &folders, &files] { - folders.clear(); + folders.clear(); - const auto file_path = CheckFolder(); - for (const auto& directory_entry : std::filesystem::directory_iterator(file_path.Path())) - if (directory_entry.is_directory()) - folders.push_back(directory_entry.path().filename().generic_string()); + const auto file_path = CheckFolder(); + for (const auto& directory_entry : std::filesystem::directory_iterator(file_path.Path())) + if (directory_entry.is_directory()) + folders.push_back(directory_entry.path().filename().generic_string()); - files.clear(); + files.clear(); - const auto file_path2 = CheckFolder(folderName); - for (const auto& directory_entry : std::filesystem::directory_iterator(file_path2.Path())) - if (directory_entry.path().extension() == ".json") - files.push_back(directory_entry.path().filename().generic_string()); - }); + const auto file_path2 = CheckFolder(folderName); + for (const auto& directory_entry : std::filesystem::directory_iterator(file_path2.Path())) + if (directory_entry.path().extension() == ".json") + files.push_back(directory_entry.path().filename().generic_string()); } nlohmann::json SavedVehicles::GetJson(Vehicle veh) @@ -132,55 +129,53 @@ namespace YimMenu void SavedVehicles::Save(std::string folderName, std::string fileName) { - FiberPool::Push([folderName, fileName] { - if (auto veh = Self::GetVehicle(); veh && veh.IsValid()) - { - const auto file = SavedVehicles::CheckFolder(folderName).GetFile(fileName); - std::ofstream file_stream(file.Path(), std::ios::out | std::ios::trunc); - file_stream << SavedVehicles::GetJson(veh).dump(4); - file_stream.close(); - } - else - Notifications::Show("Persist Car", "Tried to save a vehicle which does not exist", NotificationType::Warning); - }); + if (auto veh = Self::GetVehicle(); veh && veh.IsValid()) + { + const auto file = SavedVehicles::CheckFolder(folderName).GetFile(fileName); + std::ofstream file_stream(file.Path(), std::ios::out | std::ios::trunc); + file_stream << SavedVehicles::GetJson(veh).dump(4); + file_stream.close(); + } + else + Notifications::Show("Persist Car", "Tried to save a vehicle which does not exist", NotificationType::Warning); } void SavedVehicles::Load(std::string folderName, std::string fileName, bool spawnInside) { if (!fileName.empty()) - FiberPool::Push([folderName, fileName, spawnInside] { - const auto file = CheckFolder(folderName).GetFile(fileName).Path(); + { + const auto file = CheckFolder(folderName).GetFile(fileName).Path(); - if (!std::filesystem::exists(file)) + if (!std::filesystem::exists(file)) + { + Notifications::Show("Persist Car", "File does not exist.", NotificationType::Error); + return; + } + + std::ifstream file_stream(file); + nlohmann::json vehicle_json; + + try + { + file_stream >> vehicle_json; + auto veh = SpawnFromJson(vehicle_json); + + if (veh) { - Notifications::Show("Persist Car", "File does not exist.", NotificationType::Error); - return; + if (spawnInside) + Self::GetPed().SetInVehicle(veh.GetHandle()); + Notifications::Show("Persist Car", std::format("Spawned {}", fileName), NotificationType::Success); } + else + Notifications::Show("Persist Car", std::format("Unable to spawn {}", fileName), NotificationType::Error); + } + catch (std::exception& e) + { + LOG(WARNING) << e.what(); + } - std::ifstream file_stream(file); - nlohmann::json vehicle_json; - - try - { - file_stream >> vehicle_json; - auto veh = SpawnFromJson(vehicle_json); - - if (veh) - { - if (spawnInside) - Self::GetPed().SetInVehicle(veh.GetHandle()); - Notifications::Show("Persist Car", std::format("Spawned {}", fileName), NotificationType::Success); - } - else - Notifications::Show("Persist Car", std::format("Unable to spawn {}", fileName), NotificationType::Error); - } - catch (std::exception& e) - { - LOG(WARNING) << e.what(); - } - - file_stream.close(); - }); + file_stream.close(); + } else Notifications::Show("Persist Car", "Select a file first", NotificationType::Warning); } diff --git a/src/game/features/teleport/TpToWaypoint.cpp b/src/game/features/teleport/TpToWaypoint.cpp index 9271dc3..3600901 100644 --- a/src/game/features/teleport/TpToWaypoint.cpp +++ b/src/game/features/teleport/TpToWaypoint.cpp @@ -14,22 +14,18 @@ namespace YimMenu::Features constexpr int max_attempts = 20; float ground_z = vec.z; int current_attempts = 0; + bool found_ground = false; do { STREAMING::REQUEST_COLLISION_AT_COORD(vec.x, vec.y, vec.z); - float water_height; - if (WATER::GET_WATER_HEIGHT(vec.x, vec.y, vec.z, &water_height)) - { - vec.z = water_height; - return; - } - + // find ground first and if found set z to new value and break if (MISC::GET_GROUND_Z_FOR_3D_COORD(vec.x, vec.y, max_ground_check, &ground_z, false, false)) { vec.z = ground_z + 1.0f; - return; + found_ground = true; + break; } if (current_attempts % 3 == 0) @@ -40,8 +36,18 @@ namespace YimMenu::Features ++current_attempts; ScriptMgr::Yield(); } while (current_attempts < max_attempts); + + // whether ground was found or not check for water height + float water_height; + if (WATER::GET_WATER_HEIGHT(vec.x, vec.y, vec.z, &water_height)) + { + vec.z = water_height; + return; + } - vec.z = PATHFIND::GET_APPROX_HEIGHT_FOR_POINT(vec.x, vec.y); // fallback value + // fallback value + if (!found_ground) + vec.z = PATHFIND::GET_APPROX_HEIGHT_FOR_POINT(vec.x, vec.y); } class TpToWaypoint : public Command diff --git a/src/game/frontend/submenus/Vehicle/SavedVehicles.cpp b/src/game/frontend/submenus/Vehicle/SavedVehicles.cpp index 9d09686..db99ba8 100644 --- a/src/game/frontend/submenus/Vehicle/SavedVehicles.cpp +++ b/src/game/frontend/submenus/Vehicle/SavedVehicles.cpp @@ -30,32 +30,29 @@ namespace YimMenu::Submenus return; if (ImGui::Button("Save")) - { - std::string fileName = vehicle_file_name_input; - strcpy(vehicle_file_name_input, ""); + FiberPool::Push([saveToNewFolder] { + std::string fileName = vehicle_file_name_input; + strcpy(vehicle_file_name_input, ""); - if (!TrimString(fileName).size()) - { - Notifications::Show("Saved Vehicles", "Filename empty!", NotificationType::Warning); - return; - } + if (!TrimString(fileName).size()) + { + Notifications::Show("Saved Vehicles", "Filename empty!", NotificationType::Warning); + return; + } - ReplaceString(fileName, ".", ""); // filename say "bob.." will throw relative path error from Folder::GetFile - fileName += ".json"; + ReplaceString(fileName, ".", ""); // filename say "bob.." will throw relative path error from Folder::GetFile + fileName += ".json"; - SavedVehicles::Save(saveToNewFolder ? newFolder : folder, fileName); + SavedVehicles::Save(saveToNewFolder ? newFolder : folder, fileName); - if (saveToNewFolder) - { - folder = newFolder; // set current folder to newly created folder - strcpy(newFolder, ""); - } + if (saveToNewFolder) + { + folder = newFolder; // set current folder to newly created folder + strcpy(newFolder, ""); + } - FiberPool::Push([] { - ScriptMgr::Yield(1000ms); // wait for files to save and then refresh SavedVehicles::RefreshList(folder, folders, files); }); - } ImGui::SameLine(); if (ImGui::Button("Populate Name")) FiberPool::Push([] { @@ -65,7 +62,9 @@ namespace YimMenu::Submenus }; if (ImGui::Button("Refresh List")) - SavedVehicles::RefreshList(folder, folders, files); + FiberPool::Push([] { + SavedVehicles::RefreshList(folder, folders, files); + }); ImGui::SetNextItemWidth(300.f); auto folder_display = folder.empty() ? "Root" : folder.c_str(); @@ -74,14 +73,18 @@ namespace YimMenu::Submenus if (ImGui::Selectable("Root", folder == "")) { folder.clear(); - SavedVehicles::RefreshList(folder, folders, files); + FiberPool::Push([] { + SavedVehicles::RefreshList(folder, folders, files); + }); } for (std::string folder_name : folders) if (ImGui::Selectable(folder_name.c_str(), folder == folder_name)) { folder = folder_name; - SavedVehicles::RefreshList(folder, folders, files); + FiberPool::Push([] { + SavedVehicles::RefreshList(folder, folders, files); + }); } ImGui::EndCombo(); @@ -144,7 +147,9 @@ namespace YimMenu::Submenus ImGui::Spacing(); if (ImGui::Button("Yes")) { - SavedVehicles::Load(folder, file, spawnInsideSavedVehicle.GetState()); + FiberPool::Push([] { + SavedVehicles::Load(folder, file, spawnInsideSavedVehicle.GetState()); + }); open_modal = false; ImGui::CloseCurrentPopup(); } diff --git a/src/game/frontend/submenus/Vehicle/VehicleEditor.cpp b/src/game/frontend/submenus/Vehicle/VehicleEditor.cpp index 2b4a0ea..6446f8f 100644 --- a/src/game/frontend/submenus/Vehicle/VehicleEditor.cpp +++ b/src/game/frontend/submenus/Vehicle/VehicleEditor.cpp @@ -17,6 +17,7 @@ namespace YimMenu::Submenus static bool preparingVehicle = false; static bool isBennys = false; static int selected_slot = -1; + static char plate[9] = ""; static std::map owned_mods{}; static std::map slot_display_names{}; @@ -38,6 +39,10 @@ namespace YimMenu::Submenus auto model = Self::GetVehicle().GetModel(); front_wheel_stock_mod = -1; rear_wheel_stock_mod = -1; + vehName = Self::GetVehicle().GetFullName(); + owned_mods = Self::GetVehicle().GetOwnedMods(); + isBennys = VehicleModel::IsBennys(currentVeh); + strcpy(plate, Self::GetVehicle().GetPlateText().c_str()); if (!HUD::HAS_THIS_ADDITIONAL_TEXT_LOADED("MOD_MNU", 10)) { @@ -46,10 +51,6 @@ namespace YimMenu::Submenus ScriptMgr::Yield(); } - vehName = Self::GetVehicle().GetFullName(); - owned_mods = Self::GetVehicle().GetOwnedMods(); - isBennys = VehicleModel::IsBennys(currentVeh); - VEHICLE::SET_VEHICLE_MOD_KIT(currentVeh, 0); std::map tmp_slot_display_names; @@ -162,15 +163,15 @@ namespace YimMenu::Submenus return; } + if (preparingVehicle) + return; + if (currentVeh != Self::GetVehicle().GetHandle()) { prepareVehicle(); return; } - if (preparingVehicle) - return; - ImGui::BeginGroup(); { ImGui::Text("%s", vehName.c_str()); @@ -182,7 +183,6 @@ namespace YimMenu::Submenus ImGui::Spacing(); { - static char plate[9]; ImGui::SetNextItemWidth(150); ImGui::InputTextWithHint("##plate", "Plate Number", plate, sizeof(plate), ImGuiInputTextFlags_None); ImGui::SameLine(); diff --git a/src/game/gta/Entity.cpp b/src/game/gta/Entity.cpp index 0e7bae8..d651a8a 100644 --- a/src/game/gta/Entity.cpp +++ b/src/game/gta/Entity.cpp @@ -122,7 +122,7 @@ namespace YimMenu return ENTITY::IS_ENTITY_A_MISSION_ENTITY(GetHandle()); // TODO: detect more mission states } - int Entity::GetModel() + Hash Entity::GetModel() { ENTITY_ASSERT_VALID(); return ENTITY::GET_ENTITY_MODEL(GetHandle()); diff --git a/src/game/gta/Entity.hpp b/src/game/gta/Entity.hpp index bf00c72..ea3c5bf 100644 --- a/src/game/gta/Entity.hpp +++ b/src/game/gta/Entity.hpp @@ -1,5 +1,6 @@ #pragma once #include "types/rage/vector.hpp" +#include "types/script/types.hpp" #define ENTITY_DEBUG @@ -92,7 +93,7 @@ namespace YimMenu bool IsMissionEntity(); // info - int GetModel(); + Hash GetModel(); // position rage::fvector3 GetPosition();