From 245716875bf1406960bf25101d59c042db14e156 Mon Sep 17 00:00:00 2001 From: shad0wshayd3 Date: Thu, 21 Nov 2024 00:38:34 -0700 Subject: [PATCH] refactor: wip xmake work --- src/Menus/LevelUpMenu.h | 6 ++-- src/Menus/PerkManager.h | 77 +++++++++++++++++++++-------------------- src/PCH.cpp | 37 -------------------- src/PCH.h | 25 +------------ src/Settings.h | 46 ------------------------ 5 files changed, 44 insertions(+), 147 deletions(-) delete mode 100644 src/PCH.cpp delete mode 100644 src/Settings.h diff --git a/src/Menus/LevelUpMenu.h b/src/Menus/LevelUpMenu.h index d681c0a..9aa77db 100644 --- a/src/Menus/LevelUpMenu.h +++ b/src/Menus/LevelUpMenu.h @@ -27,7 +27,7 @@ namespace Menus RE::UI_MENU_FLAGS::kUsesBlurredBackground, RE::UI_MENU_FLAGS::kUsesMovementToDirection); menuHUDMode = "SpecialMode"; - depthPriority.set(RE::UI_DEPTH_PRIORITY::kTerminal); + depthPriority = RE::UI_DEPTH_PRIORITY::kTerminal; const auto ScaleformManager = RE::BSScaleformManager::GetSingleton(); [[maybe_unused]] const auto LoadMovieSuccess = @@ -255,8 +255,8 @@ namespace Menus if (auto PlayerCharacter = RE::PlayerCharacter::GetSingleton()) { auto level = PlayerCharacter->GetLevel(); - HeaderText = IsNewLevel ? fmt::format(fmt::runtime(Translations::Formatting::LevelUpText.data()), level) - : Translations::Formatting::PerkMenu.data(); + HeaderText = IsNewLevel ? std::vformat(Translations::Formatting::LevelUpText, std::make_format_args(level)) + : Translations::Formatting::PerkMenu; IsNewLevel = false; RE::Scaleform::GFx::Value Header[1]; diff --git a/src/Menus/PerkManager.h b/src/Menus/PerkManager.h index 6cedc57..839f00e 100644 --- a/src/Menus/PerkManager.h +++ b/src/Menus/PerkManager.h @@ -28,44 +28,41 @@ namespace Menus break; } + auto avName = actorValue->GetFullName(); auto compareValue = a_condition->GetComparisonValue(); switch (a_condition->data.condition) { case RE::ENUM_COMPARISON_CONDITION::kEqual: - _conditionText = fmt::format( - fmt::runtime(Translations::Formatting::Equal.data()), - actorValue->GetFullName(), - compareValue); + _conditionText = std::vformat( + Translations::Formatting::Equal, + std::make_format_args(avName, compareValue)); break; case RE::ENUM_COMPARISON_CONDITION::kNotEqual: - _conditionText = fmt::format( - fmt::runtime(Translations::Formatting::NotEqual.data()), - actorValue->GetFullName(), - compareValue); + _conditionText = std::vformat( + Translations::Formatting::NotEqual, + std::make_format_args(avName, compareValue)); break; case RE::ENUM_COMPARISON_CONDITION::kGreaterThan: - _conditionText = fmt::format( - fmt::runtime(Translations::Formatting::Greater.data()), - actorValue->GetFullName(), - compareValue + 1.0F); + compareValue += 1.0f; + _conditionText = std::vformat( + Translations::Formatting::Greater, + std::make_format_args(avName, compareValue)); break; case RE::ENUM_COMPARISON_CONDITION::kGreaterThanEqual: - _conditionText = fmt::format( - fmt::runtime(Translations::Formatting::GreaterEqual.data()), - actorValue->GetFullName(), - compareValue); + _conditionText = std::vformat( + Translations::Formatting::GreaterEqual, + std::make_format_args(avName, compareValue)); break; case RE::ENUM_COMPARISON_CONDITION::kLessThan: - _conditionText = fmt::format( - fmt::runtime(Translations::Formatting::Less.data()), - actorValue->GetFullName(), - compareValue); + _conditionText = std::vformat( + Translations::Formatting::Less, + std::make_format_args(avName, compareValue)); break; case RE::ENUM_COMPARISON_CONDITION::kLessThanEqual: - _conditionText = fmt::format( - fmt::runtime(Translations::Formatting::LessEqual.data()), - actorValue->GetFullName(), - compareValue + 1.0F); + compareValue += 1.0f; + _conditionText = std::vformat( + Translations::Formatting::LessEqual, + std::make_format_args(avName, compareValue)); break; default: _isValid = false; @@ -107,11 +104,17 @@ namespace Menus switch (a_condition->data.condition) { case RE::ENUM_COMPARISON_CONDITION::kEqual: - _conditionText = fmt::format(fmt::runtime(Translations::Formatting::HasPerk.data()), perk->GetFullName()); + { + auto perkName = perk->GetFullName(); + _conditionText = std::vformat(Translations::Formatting::HasPerk, std::make_format_args(perkName)); break; + } case RE::ENUM_COMPARISON_CONDITION::kNotEqual: - _conditionText = fmt::format(fmt::runtime(Translations::Formatting::NotPerk.data()), perk->GetFullName()); + { + auto perkName = perk->GetFullName(); + _conditionText = std::vformat(Translations::Formatting::NotPerk, std::make_format_args(perkName)); break; + } default: _isValid = false; break; @@ -270,8 +273,8 @@ namespace Menus auto refrLevel = RE::PlayerCharacter::GetSingleton()->GetLevel(); - std::string levelText = fmt::format(fmt::runtime(Translations::Formatting::Level.data()), _perkLevel); - std::string ranksText = fmt::format(fmt::runtime(Translations::Formatting::Ranks.data()), _perk->data.numRanks); + std::string levelText = std::vformat(Translations::Formatting::Level, std::make_format_args(_perkLevel)); + std::string ranksText = std::vformat(Translations::Formatting::Ranks, std::make_format_args(_perk->data.numRanks)); if (refrLevel < _perkLevel) { levelText = ErrorTag(levelText); @@ -285,18 +288,18 @@ namespace Menus levelText = "--"; } - std::string reqsText = fmt::format(fmt::runtime(Translations::Formatting::Reqs.data()), levelText); - _conditionText = fmt::format( - FMT_STRING("{:s}
{:s}

{:s}"sv), + std::string reqsText = std::vformat(Translations::Formatting::Reqs, std::make_format_args(levelText)); + _conditionText = std::format( + "{:s}
{:s}

{:s}"sv, reqsText, ranksText, GetDescription()); } else { - std::string reqsText = fmt::format(fmt::runtime(Translations::Formatting::Reqs.data()), levelText); - _conditionText = fmt::format( - FMT_STRING("{:s}, {:s}
{:s}

{:s}"sv), + std::string reqsText = std::vformat(Translations::Formatting::Reqs, std::make_format_args(levelText)); + _conditionText = std::format( + "{:s}, {:s}
{:s}

{:s}"sv, reqsText, perkConditions.GetConditionText(), ranksText, @@ -383,7 +386,7 @@ namespace Menus auto IsValidPath = [](const std::string& a_path) { RE::BSTSmartPointer stream{ nullptr }; - auto relativePath = fmt::format(FMT_STRING("Interface\\{:s}"sv), a_path); + auto relativePath = std::format("Interface\\{:s}"sv, a_path); return (RE::BSResource::GetOrCreateStream(relativePath.c_str(), stream) == RE::BSResource::ErrorCode::kNone); }; @@ -395,7 +398,7 @@ namespace Menus continue; } - auto formattedPath = fmt::format(FMT_STRING("Components\\VaultBoys\\Perks\\PerkClip_{:x}.swf"sv), _perkChain[i]->formID); + auto formattedPath = std::format("Components\\VaultBoys\\Perks\\PerkClip_{:x}.swf"sv, _perkChain[i]->formID); if (IsValidPath(formattedPath)) { _perkChain[i].SetPerkIcon(formattedPath); @@ -488,7 +491,7 @@ namespace Menus private: static std::string ErrorTag(std::string_view a_string) { - return fmt::format(FMT_STRING("{:s}"sv), a_string); + return std::format("{:s}"sv, a_string); } RE::BGSPerk* GetFirstPerkInChain(RE::BGSPerk* a_perk) diff --git a/src/PCH.cpp b/src/PCH.cpp deleted file mode 100644 index 8607860..0000000 --- a/src/PCH.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "PCH.h" - -namespace stl -{ - namespace detail - { - struct asm_patch : - Xbyak::CodeGenerator - { - asm_patch(std::uintptr_t a_dst) - { - Xbyak::Label dst; - - jmp(ptr[rip + dst]); - - L(dst); - dq(a_dst); - } - }; - } - - void asm_jump(std::uintptr_t a_from, [[maybe_unused]] std::size_t a_size, std::uintptr_t a_to) - { - detail::asm_patch p{ a_to }; - p.ready(); - assert(p.getSize() <= a_size); - REL::safe_write( - a_from, - std::span{ p.getCode(), p.getSize() }); - } - - void asm_replace(std::uintptr_t a_from, std::size_t a_size, std::uintptr_t a_to) - { - REL::safe_fill(a_from, REL::INT3, a_size); - asm_jump(a_from, a_size, a_to); - } -} diff --git a/src/PCH.h b/src/PCH.h index 6852c0e..3f188df 100644 --- a/src/PCH.h +++ b/src/PCH.h @@ -1,29 +1,6 @@ -#pragma once - -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX +#pragma once #include "F4SE/F4SE.h" #include "RE/Fallout.h" -#include -#include -#include - -#define DLLEXPORT __declspec(dllexport) - using namespace std::literals; - -namespace logger = F4SE::log; - -namespace stl -{ - using namespace F4SE::stl; - - void asm_replace(std::uintptr_t a_from, std::size_t a_size, std::uintptr_t a_to); -} - -// clang-format off -#include "Version.h" -#include "Settings.h" -// clang-format on diff --git a/src/Settings.h b/src/Settings.h deleted file mode 100644 index ce29340..0000000 --- a/src/Settings.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -namespace Settings -{ - namespace - { - using bSetting = AutoTOML::bSetting; - using ISetting = AutoTOML::ISetting; - } - - namespace General - { - inline bSetting EnableDebugLogging{ "General"s, "EnableDebugLogging"s, false }; - } - - inline void Load() - { - try - { - const auto table = toml::parse_file( - fmt::format(FMT_STRING("Data/F4SE/Plugins/{:s}.toml"sv), Version::PROJECT)); - for (const auto& setting : ISetting::get_settings()) - { - setting->load(table); - } - } - catch (const toml::parse_error& e) - { - std::ostringstream ss; - ss - << "Error parsing file \'" << *e.source().path << "\':\n" - << '\t' << e.description() << '\n' - << "\t\t(" << e.source().begin << ')'; - logger::error(FMT_STRING("{:s}"sv), ss.str()); - stl::report_and_fail("Failed to load settings."sv); - } - catch (const std::exception& e) - { - stl::report_and_fail(e.what()); - } - catch (...) - { - stl::report_and_fail("Unknown failure."sv); - } - } -}