From 49fd4e3da2a6dce47ed794d5c72783e04ffd3c4b Mon Sep 17 00:00:00 2001 From: powerof3 <32599957+powerof3@users.noreply.github.com> Date: Wed, 6 Mar 2024 01:27:59 +0530 Subject: [PATCH] fix crash --- CMakeLists.txt | 2 +- src/Fixes/ValidateScreenshotFolder.cpp | 88 ++++++++++++-------------- vcpkg.json | 2 +- 3 files changed, 43 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2ffe0f..aba9f2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) set(NAME "po3_Tweaks" CACHE STRING "") -set(VERSION 1.9.1 CACHE STRING "") +set(VERSION 1.9.2 CACHE STRING "") set(AE_VERSION 1) set(VR_VERSION 2) diff --git a/src/Fixes/ValidateScreenshotFolder.cpp b/src/Fixes/ValidateScreenshotFolder.cpp index 84444e8..9dd0c64 100644 --- a/src/Fixes/ValidateScreenshotFolder.cpp +++ b/src/Fixes/ValidateScreenshotFolder.cpp @@ -6,6 +6,13 @@ namespace Fixes::ValidateScreenshotFolder { + RE::Setting* set_ini_string(RE::Setting* a_setting, const char* a_str) + { + using func_t = decltype(&set_ini_string); + REL::Relocation func{ RELOCATION_ID(73882, 75619) }; + return func(a_setting,a_str); + } + bool has_root_directory(const std::filesystem::path& a_path) { auto path = a_path.string(); @@ -21,63 +28,50 @@ namespace Fixes::ValidateScreenshotFolder void Install() { if (auto setting = RE::GetINISetting("sScreenShotBaseName:Display")) { - try { - std::filesystem::path gameDirectory = std::filesystem::current_path(); - gameDirectory.make_preferred(); + std::filesystem::path gameDirectory = std::filesystem::current_path(); + gameDirectory.make_preferred(); - std::filesystem::path screenshotFolder{}; - std::string newBaseName{}; + std::filesystem::path screenshotFolder{}; + std::string newBaseName{}; - auto folder = setting->GetString(); - bool emptyPath = string::is_empty(folder); + auto folder = setting->GetString(); + bool emptyPath = string::is_empty(folder); - if (emptyPath) { - screenshotFolder = gameDirectory; - newBaseName = "Screenshot"; - } else { - screenshotFolder = folder; - screenshotFolder.make_preferred(); + if (emptyPath) { + screenshotFolder = gameDirectory; + newBaseName = "Screenshot"; + } else { + screenshotFolder = folder; + screenshotFolder.make_preferred(); - if (has_root_directory(screenshotFolder)) { - if (!is_subpath(screenshotFolder, gameDirectory) && !std::filesystem::exists(screenshotFolder)) { - newBaseName = "Screenshot"; - } - } else { - // folder will be generated in skyrim root - screenshotFolder = gameDirectory /= screenshotFolder; - screenshotFolder.remove_filename(); + if (has_root_directory(screenshotFolder)) { + if (!is_subpath(screenshotFolder, gameDirectory) && !std::filesystem::exists(screenshotFolder)) { + newBaseName = "Screenshot"; } + } else { + // folder will be generated in skyrim root + screenshotFolder = gameDirectory /= screenshotFolder; + screenshotFolder.remove_filename(); } + } - if (!newBaseName.empty()) { - //to-do: port this to clib - if (setting->data.s) { - RE::free(setting->data.s); - } - - std::size_t strLen = newBaseName.length() + 1; - setting->data.s = RE::malloc(strLen); - std::memcpy(setting->data.s, newBaseName.c_str(), sizeof(char) * strLen); - - if (emptyPath) { - RE::ConsoleLog::GetSingleton()->Print("[po3 Tweaks] sScreenShotBaseName:Display ini setting is empty"); - } else { - RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Screenshot folder ({}) does not exist", screenshotFolder.string()).c_str()); - } - RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Defaulting to {} folder\n", gameDirectory.string()).c_str()); - if (emptyPath) { - logger::info("\t\tValidated screenshot location ({})"sv, screenshotFolder.string()); - } else { - logger::info("\t\tValidated screenshot location ({} -> {})"sv, screenshotFolder.string(), gameDirectory.string()); - } + if (!newBaseName.empty()) { + set_ini_string(setting, newBaseName.c_str()); + + if (emptyPath) { + RE::ConsoleLog::GetSingleton()->Print("[po3 Tweaks] sScreenShotBaseName:Display ini setting is empty"); } else { - RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Screenshot folder ({}) validated successfully\n", screenshotFolder.string()).c_str()); + RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Screenshot folder ({}) does not exist", screenshotFolder.string()).c_str()); + } + RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Defaulting to {} folder\n", gameDirectory.string()).c_str()); + if (emptyPath) { logger::info("\t\tValidated screenshot location ({})"sv, screenshotFolder.string()); + } else { + logger::info("\t\tValidated screenshot location ({} -> {})"sv, screenshotFolder.string(), gameDirectory.string()); } - } catch (std::exception& e) { - logger::info("\t\tUnable to validate screenshot path (error: {})"sv, e.what()); - } catch (...) { - logger::info("\t\tUnable to validate screenshot path (unknown error)"sv); + } else { + RE::ConsoleLog::GetSingleton()->Print(std::format("[po3 Tweaks] Screenshot folder ({}) validated successfully\n", screenshotFolder.string()).c_str()); + logger::info("\t\tValidated screenshot location ({})"sv, screenshotFolder.string()); } } } diff --git a/vcpkg.json b/vcpkg.json index 9a307f4..be2187a 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "po3tweaks", - "version-string": "1.9.1", + "version-string": "1.9.2", "description": "Collection of bug fixes and tweaks for Skyrim SE/AE/VR", "homepage": "https://github.com/powerof3/po3-Tweaks/", "license": "MIT",