diff --git a/CHANGELOG.md b/CHANGELOG.md index cd37f4d..4211c3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.8.2 + +- Fix a crash that occurred if the car's ini file had invalid data + ## 0.8.1 - Fix a bug where the seat position was not loaded correctly if a stage was diff --git a/CMakeLists.txt b/CMakeLists.txt index a7d2f6a..2a21195 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ set(HEADERS set(openRBRVR_Major 0) set(openRBRVR_Minor 8) -set(openRBRVR_Patch 1) +set(openRBRVR_Patch 2) set(openRBRVR_Tweak 0) # set(openRBRVR_TweakStr "-rc${openRBRVR_Tweak}") diff --git a/src/Config.hpp b/src/Config.hpp index 04f9b3a..1e3014b 100644 --- a/src/Config.hpp +++ b/src/Config.hpp @@ -341,14 +341,20 @@ struct Config { { auto cars_ini_path = "Cars\\cars.ini"; if (!std::filesystem::exists(cars_ini_path)) { + dbg("Could not resolve car ini path"); return std::nullopt; } - ini::IniFile cars_ini(cars_ini_path); - auto car_key = std::format("Car0{}", car_id); - return std::filesystem::path(cars_ini[car_key]["IniFile"].as() - | std::ranges::views::filter([](char c) { return c != '"'; }) - | std::ranges::to()); + try { + ini::IniFile cars_ini(cars_ini_path); + auto car_key = std::format("Car0{}", car_id); + return std::filesystem::path(cars_ini[car_key]["IniFile"].as() + | std::ranges::views::filter([](char c) { return c != '"'; }) + | std::ranges::to()); + } catch (...) { + dbg("Could not resolve car ini path"); + return std::nullopt; + } } static std::optional resolve_personal_car_ini_path(uint32_t car_id) @@ -374,9 +380,14 @@ struct Config { return false; } - ini::IniFile personal_ini(ini_path.value()); - personal_ini["openRBRVR"]["seatPosition"] = vec3_as_space_separated_string(seat_translation); - personal_ini.save(ini_path.value()); + try { + ini::IniFile personal_ini(ini_path.value()); + personal_ini["openRBRVR"]["seatPosition"] = vec3_as_space_separated_string(seat_translation); + personal_ini.save(ini_path.value()); + } catch (...) { + dbg("Updating seat translation failed"); + return false; + } return true; } @@ -392,30 +403,36 @@ struct Config { bool is_openrbrvr_translation = false; std::optional seat_translation = std::nullopt; - if (std::filesystem::exists(ini_path.value())) { - ini::IniFile personal_ini(ini_path.value()); + try { + if (std::filesystem::exists(ini_path.value())) { + ini::IniFile personal_ini(ini_path.value()); - seat_translation = vec3_from_space_separated_string(personal_ini["openRBRVR"]["seatPosition"].as()); + seat_translation = vec3_from_space_separated_string(personal_ini["openRBRVR"]["seatPosition"].as()); - if (!seat_translation) { - seat_translation = vec3_from_space_separated_string(personal_ini["Cam_internal"]["Pos"].as()); - } else { - is_openrbrvr_translation = true; + if (!seat_translation) { + seat_translation = vec3_from_space_separated_string(personal_ini["Cam_internal"]["Pos"].as()); + } else { + is_openrbrvr_translation = true; + } } - } - if (!seat_translation) { - ini_path = resolve_car_ini_path(car_id).and_then(to_string); - if (!ini_path) { - return default_translation; + if (!seat_translation) { + ini_path = resolve_car_ini_path(car_id).and_then(to_string); + if (!ini_path) { + return default_translation; + } + ini::IniFile ini(ini_path.value()); + seat_translation = vec3_from_space_separated_string(ini["Cam_internal"]["Pos"].as()); } - ini::IniFile ini(ini_path.value()); - seat_translation = vec3_from_space_separated_string(ini["Cam_internal"]["Pos"].as()); - } - return seat_translation - .and_then([&](const glm::vec3& t) { return std::optional(std::make_tuple(t, is_openrbrvr_translation)); }) - .value_or(default_translation); + return seat_translation + .and_then([&](const glm::vec3& t) { return std::optional(std::make_tuple(t, is_openrbrvr_translation)); }) + .value_or(default_translation); + + } catch (...) { + dbg("Loading seat translation failed"); + return default_translation; + } } static Config from_path(const std::filesystem::path& path) diff --git a/src/RBR.cpp b/src/RBR.cpp index 382f2d0..f0046c9 100644 --- a/src/RBR.cpp +++ b/src/RBR.cpp @@ -247,7 +247,7 @@ namespace rbr { g::game_mode = game_mode; } - if(g::previous_game_mode != g::game_mode && g::game_mode == GameMode::PreStage) { + if (g::previous_game_mode != g::game_mode && g::game_mode == GameMode::PreStage) { // Make sure we reload the seat position whenever the stage is restarted g::seat_position_loaded = false; } @@ -329,8 +329,11 @@ namespace rbr { } if (!seat_saved && seat_still_frames > 250) { - g::cfg.insert_or_update_seat_translation(*g::car_id_ptr, g::seat_translation); - g::game->WriteGameMessage("openRBRVR seat position saved.", 2.0, 100.0, 100.0); + if (g::cfg.insert_or_update_seat_translation(*g::car_id_ptr, g::seat_translation)) { + g::game->WriteGameMessage("openRBRVR seat position saved.", 2.0, 100.0, 100.0); + } else { + g::game->WriteGameMessage("Failed to save openRBRVR seat position.", 2.0, 100.0, 100.0); + } seat_saved = true; } } else if (g::seat_movement_request) {