From 6e0358737fbfe269c29f7f7d9a3f4b5c8a35a5de Mon Sep 17 00:00:00 2001 From: Quentin Date: Sat, 30 Mar 2024 18:42:04 +0100 Subject: [PATCH] fix nlohmann potential throw in ped outfit (#2894) --- src/backend/looped/self/persist_outfit.cpp | 45 +++++++++++++++------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/backend/looped/self/persist_outfit.cpp b/src/backend/looped/self/persist_outfit.cpp index 69689832..5af1966e 100644 --- a/src/backend/looped/self/persist_outfit.cpp +++ b/src/backend/looped/self/persist_outfit.cpp @@ -1,11 +1,11 @@ #include "backend/looped/looped.hpp" +#include "core/scr_globals.hpp" #include "file_manager.hpp" +#include "gta/enums.hpp" #include "logger/logger.hpp" #include "natives.hpp" #include "pointers.hpp" #include "services/outfit/outfit_service.hpp" -#include "gta/enums.hpp" -#include "core/scr_globals.hpp" #include "services/tunables/tunables_service.hpp" namespace big @@ -15,13 +15,13 @@ namespace big int offset = 0; switch (model) { - case "mp_m_freemode_01"_J: break; - case "mp_f_freemode_01"_J: - { - offset = 1; - break; - } - default: return false; //For non-normal models + case "mp_m_freemode_01"_J: break; + case "mp_f_freemode_01"_J: + { + offset = 1; + break; + } + default: return false; //For non-normal models } return PED::GET_PED_DRAWABLE_VARIATION(self::ped, ComponentId::AUXILIARY) == 15 && PED::GET_PED_DRAWABLE_VARIATION(self::ped, ComponentId::TORSO) == 15 && PED::GET_PED_DRAWABLE_VARIATION(self::ped, ComponentId::LEGS) == (14 + offset); @@ -52,11 +52,28 @@ namespace big if (persisting_outfit != g.self.persist_outfit) { - persisting_outfit = g.self.persist_outfit; - folder saved_outfit_path = g_file_manager.get_project_folder("saved_outfits"); - std::ifstream i(saved_outfit_path.get_file(persisting_outfit).get_path()); - outfit.clear(); - i >> outfit; + persisting_outfit = g.self.persist_outfit; + folder saved_outfit_path = g_file_manager.get_project_folder("saved_outfits"); + const auto persist_outfit_file_path = saved_outfit_path.get_file(persisting_outfit).get_path(); + if (std::filesystem::exists(persist_outfit_file_path)) + { + std::ifstream i(persist_outfit_file_path); + if (i.is_open()) + { + outfit.clear(); + try + { + i >> outfit; + } + catch (const std::exception& e) + { + LOG(INFO) << e.what(); + + outfit = {}; + g.self.persist_outfit = ""; + } + } + } } if (outfit.contains("model") && outfit["model"].get() == model)