From fbcd0ebbaa0d05e2f11e6fcb16cc594ade714f8a Mon Sep 17 00:00:00 2001 From: MetricExpansion <> Date: Sun, 9 Oct 2022 14:07:31 -0700 Subject: [PATCH] Deep logging support --- CMakeLists.txt | 6 ++++++ include/SOS_PCH.h | 2 ++ include/Utility.h | 8 ++++++++ src/OutfitSystem.cpp | 1 + src/Utility.cpp | 19 +++++++++++++++++++ src/main.cpp | 18 +++++++++--------- vcpkg.json | 1 + 7 files changed, 46 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5279f7a..5a4a77c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,11 +171,17 @@ add_custom_command(TARGET SkyrimOutfitSystemSE POST_BUILD find_package(span-lite REQUIRED CONFIG) find_package(spdlog REQUIRED CONFIG) find_package(xbyak REQUIRED CONFIG) +find_library(INIH_LIBRARY inih REQUIRED) +find_path(INIH_INCLUDE_DIRS "ini.h" REQUIRED) target_link_libraries(SkyrimOutfitSystemSE PUBLIC CommonLibSSE::CommonLibSSE nonstd::span-lite spdlog::spdlog + ${INIH_LIBRARY} ProtocolBuffers xbyak::xbyak ) + +target_include_directories(SkyrimOutfitSystemSE PRIVATE + ${INIH_INCLUDE_DIRS}) diff --git a/include/SOS_PCH.h b/include/SOS_PCH.h index 614bebd..d728328 100644 --- a/include/SOS_PCH.h +++ b/include/SOS_PCH.h @@ -13,6 +13,8 @@ #include #include +#include "INIReader.h" + #ifdef NDEBUG #include #else diff --git a/include/Utility.h b/include/Utility.h index a9dc79b..c95c86f 100644 --- a/include/Utility.h +++ b/include/Utility.h @@ -5,3 +5,11 @@ std::string GetRuntimeName(); const std::string& GetRuntimeDirectory(); + +class Settings { +public: + Settings(); + ~Settings(); + INIReader reader; + static Settings* Instance(); +}; diff --git a/src/OutfitSystem.cpp b/src/OutfitSystem.cpp index 105c531..d0873bc 100644 --- a/src/OutfitSystem.cpp +++ b/src/OutfitSystem.cpp @@ -29,6 +29,7 @@ namespace OutfitSystem { std::int32_t GetOutfitNameMaxLength(RE::BSScript::IVirtualMachine* registry, std::uint32_t stackId, RE::StaticFunctionTag*) { + LOG(trace, "GetOutfitNameMaxLength"); return ArmorAddonOverrideService::ce_outfitNameMaxLength; } std::vector GetCarriedArmor(RE::BSScript::IVirtualMachine* registry, diff --git a/src/Utility.cpp b/src/Utility.cpp index 9f26b80..c053f1e 100644 --- a/src/Utility.cpp +++ b/src/Utility.cpp @@ -50,3 +50,22 @@ const std::string& GetRuntimeDirectory() { return s_runtimeDirectory; } + +Settings::Settings() : reader(GetRuntimeDirectory() + "Data\\SKSE\\Plugins\\SkyrimOutfitSystemSE.ini") { + if (reader.ParseError() != 0) { + // Failed to load INI. We proceed without it. + LOG(info, "Could not load INI file from {}. Continuing without it.", GetRuntimeDirectory() + "Data\\SKSE\\Plugins\\SkyrimOutfitSystemSE.ini"); + return; + } else { + LOG(info, "INI file was successfully loaded."); + } +} + +Settings::~Settings() {} + +static Settings* settings; + +Settings* Settings::Instance() { + if (!settings) settings = new Settings(); + return settings; +} diff --git a/src/main.cpp b/src/main.cpp index a44a2c9..1f7512c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,8 @@ #include "OutfitSystem.h" -#include - -#include -#include +#include "ArmorAddonOverrideService.h" +#include "hooking/Hooks.hpp" +#include "Utility.h" void WaitForDebugger(void) { while (!IsDebuggerPresent()) { @@ -28,11 +27,12 @@ namespace { *path /= fmt::format("{}.log"sv, Plugin::NAME); auto sink = std::make_shared(path->string(), true); -#ifndef NDEBUG - const auto level = spdlog::level::trace; -#else - const auto level = spdlog::level::info; -#endif + auto level = spdlog::level::info; + bool deepLogEnabled = Settings::Instance()->reader.GetBoolean("Debug", "ExtraLogging", false); + if (deepLogEnabled) { + LOG(info, "Extra logging enabled."); + level = spdlog::level::trace; + } auto log = std::make_shared("global log"s, std::move(sink)); log->set_level(level); diff --git a/vcpkg.json b/vcpkg.json index 60a9abb..f6d31fc 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -6,6 +6,7 @@ "dependencies": [ "span-lite", "spdlog", + "inih", "protobuf", "boost-stl-interfaces", "rsm-binary-io",