From 3ee6898cab6abd54f83abb8921d24ce19cf5667e Mon Sep 17 00:00:00 2001 From: colinswrath Date: Tue, 14 Jun 2022 01:38:44 -0400 Subject: [PATCH 1/3] commonlibNG support --- CMakeLists.txt | 6 ++++-- src/Cache.h | 12 ++++++------ src/Conditions.h | 2 +- src/Hooks.h | 16 +++++----------- src/UpdateManager.h | 20 ++++++++++---------- src/main.cpp | 35 +++++------------------------------ vcpkg-configuration.json | 14 ++++++++++++++ vcpkg.json | 3 ++- 8 files changed, 47 insertions(+), 61 deletions(-) create mode 100644 vcpkg-configuration.json diff --git a/CMakeLists.txt b/CMakeLists.txt index a24c57a..0f11682 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,8 +79,9 @@ set(Boost_USE_STATIC_LIBS ON) # ---- Dependencies ---- -add_subdirectory("extern/CommonLibSSE" CommonLibSSE) +#add_subdirectory("extern/CommonLibSSE" CommonLibSSE) +find_package(CommonLibSSE REQUIRED) find_package(spdlog REQUIRED CONFIG) # ---- Add source files ---- @@ -138,9 +139,10 @@ target_include_directories( target_link_libraries( ${PROJECT_NAME} - PRIVATE + PUBLIC CommonLibSSE::CommonLibSSE spdlog::spdlog + fmt::fmt ) if (MSVC) diff --git a/src/Cache.h b/src/Cache.h index b177de1..6c1edd5 100644 --- a/src/Cache.h +++ b/src/Cache.h @@ -12,23 +12,23 @@ namespace Cache { //1.6 = 38590 //1.5.97 = 37637 - IsAttackingAddress = REL::ID(37637).address(); + IsAttackingAddress = REL::RelocationID(37637, 38590).address(); //1.6 = 37952 //1.5.97 = 36927 - IsBlockingAddress = REL::ID(36927).address(); + IsBlockingAddress = REL::RelocationID(36927, 37952).address(); //1.6 = 38782 //1.5.97 = 37828 - HasSpellAddress = REL::ID(37828).address(); + HasSpellAddress = REL::RelocationID(37828, 38782).address(); //1.6 = 403521 //1.5 = 517014 - PlayerSingletonAddress = REL::ID(517014).address(); + PlayerSingletonAddress = REL::RelocationID(517014, 403521).address(); - //1.6 + //1.6 = 375300 //1.5 = 505721 - fPlayerMaxResistanceAddress = { REL::ID(505721).address()}; + fPlayerMaxResistanceAddress = { REL::RelocationID(505721, 375300).address()}; } inline RE::PlayerCharacter* GetPlayerSingleton() diff --git a/src/Conditions.h b/src/Conditions.h index 683e92e..6e26191 100644 --- a/src/Conditions.h +++ b/src/Conditions.h @@ -33,6 +33,6 @@ namespace Conditions static bool IsMoving(RE::PlayerCharacter* player) { - return (!static_cast(player->actorState1.movingForward) && !static_cast(player->actorState1.movingBack) && !static_cast(player->actorState1.movingLeft) && !static_cast(player->actorState1.movingRight)); + return (static_cast(player->actorState1.movingForward) || static_cast(player->actorState1.movingBack) || static_cast(player->actorState1.movingLeft) || static_cast(player->actorState1.movingRight)); } }; diff --git a/src/Hooks.h b/src/Hooks.h index 7416d69..b2eebff 100644 --- a/src/Hooks.h +++ b/src/Hooks.h @@ -2,19 +2,13 @@ namespace Hooks { - //1.6 = REL::Relocation OnFrame_Update_Hook{ REL::ID(36564), 0x6E }; - inline static REL::Relocation OnFrame_Update_Hook{ REL::ID(35565), 0x1E }; + inline static REL::Relocation OnFrame_Update_Hook{ REL::RelocationID(35565,36564), REL::Relocate(0x1E,0x6E) }; + inline static REL::Relocation Scale_Patch_Hook{ REL::RelocationID(37013,38041), REL::Relocate(0x1A,0x1F) }; - //1.6 = REL::Relocation Scale_Patch_Hook{ REL::ID(38041), 0x1F }; - inline static REL::Relocation Scale_Patch_Hook{ REL::ID(37013), 0x1A }; + inline static REL::Relocation Block_GameSetting_Hook{ REL::RelocationID(42842,44014), REL::Relocate(0x452,0x438) }; + inline static REL::Relocation fBlock_GameSetting{ REL::RelocationID(505023,374158), 0x8 }; - //1.6 = REL::Relocation Block_GameSetting_Hook{ REL::ID(44014), 0x438 }; - //1.6 = REL::Relocation fBlock_GameSetting { REL::ID(374158) }; - inline static REL::Relocation Block_GameSetting_Hook{ REL::ID(42842), 0x452 }; - inline static REL::Relocation fBlock_GameSetting{ REL::ID(505023), 0x8 }; - - // 1.6 REL::Relocation SpellCap_Hook{ REL::ID(38741), 0x55 }; - inline static REL::Relocation SpellCap_Hook{ REL::ID(37792), 0x53 }; + inline static REL::Relocation SpellCap_Hook{ REL::RelocationID(37792,38741), REL::Relocate(0x53,0x55) }; bool Install(); } diff --git a/src/UpdateManager.h b/src/UpdateManager.h index a2ffbee..67e0cbb 100644 --- a/src/UpdateManager.h +++ b/src/UpdateManager.h @@ -96,20 +96,20 @@ class UpdateManager { player->RemoveSpell(settings->IsAttackingSpell); } - } - if (IsBlocking(player)) - { - if (!HasSpell(player, settings->IsBlockingSpell)) + if (IsBlocking(player)) { - player->AddSpell(settings->IsBlockingSpell); + if (!HasSpell(player, settings->IsBlockingSpell)) + { + player->AddSpell(settings->IsBlockingSpell); + } } - } - else - { - if (HasSpell(player, settings->IsBlockingSpell)) + else { - player->RemoveSpell(settings->IsBlockingSpell); + if (HasSpell(player, settings->IsBlockingSpell)) + { + player->RemoveSpell(settings->IsBlockingSpell); + } } } diff --git a/src/main.cpp b/src/main.cpp index 65372eb..89f028a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,6 @@ #include "Settings.h" #include "Cache.h" -/* 1.6 void InitLogger() { #ifndef NDEBUG @@ -41,36 +40,11 @@ extern "C" DLLEXPORT constexpr auto SKSEPlugin_Version = v.UsesAddressLibrary(true); return v; }(); -*/ + extern "C" DLLEXPORT bool SKSEAPI SKSEPlugin_Query(const SKSE::QueryInterface * a_skse, SKSE::PluginInfo * a_info) { -#ifndef NDEBUG - auto sink = std::make_shared(); -#else - auto path = logger::log_directory(); - if (!path) { - return false; - } - - *path /= Version::PROJECT; - *path += ".log"sv; - auto sink = std::make_shared(path->string(), true); -#endif - - auto log = std::make_shared("global log"s, std::move(sink)); - -#ifndef NDEBUG - log->set_level(spdlog::level::trace); -#else - log->set_level(spdlog::level::info); - log->flush_on(spdlog::level::info); -#endif - - spdlog::set_default_logger(std::move(log)); - spdlog::set_pattern("%g(%#): [%^%l%$] %v"s); - - logger::info(FMT_STRING("{} v{}"), Version::PROJECT, Version::NAME); + InitLogger(); a_info->infoVersion = SKSE::PluginInfo::kVersion; a_info->name = Version::PROJECT.data(); @@ -82,7 +56,7 @@ extern "C" DLLEXPORT bool SKSEAPI SKSEPlugin_Query(const SKSE::QueryInterface * } const auto ver = a_skse->RuntimeVersion(); - if (ver < SKSE::RUNTIME_1_5_39) { + if (ver < SKSE::RUNTIME_VR_1_4_15) { logger::critical(FMT_STRING("Unsupported runtime version {}"), ver.string()); return false; } @@ -105,7 +79,7 @@ void InitListener(SKSE::MessagingInterface::Message* a_msg) extern "C" DLLEXPORT bool SKSEAPI SKSEPlugin_Load(const SKSE::LoadInterface* a_skse) { - //InitLogger(); //1.6 + InitLogger(); //1.6 SKSE::Init(a_skse); logger::info("Loading Blade and Blunt."); @@ -126,5 +100,6 @@ extern "C" DLLEXPORT bool SKSEAPI SKSEPlugin_Load(const SKSE::LoadInterface* a_s } logger::info("Blade and Blunt loaded."); + spdlog::default_logger()->flush(); return true; } diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json new file mode 100644 index 0000000..f2ed177 --- /dev/null +++ b/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "registries": [ + { + "kind": "git", + "repository": "https://gitlab.com/colorglass/vcpkg-colorglass", + "baseline": "0f58c21b7a7cc96c1ff7bd949c9f4530b514625d", + "packages": [ + "commonlibsse-ng", + "commonlibsse-ng-flatrim", + "commonlibsse-ng-vr" + ] + } + ] +} \ No newline at end of file diff --git a/vcpkg.json b/vcpkg.json index c896251..be1c9e3 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -8,6 +8,7 @@ "boost-stl-interfaces", "rsm-binary-io", "spdlog", - "simpleini" + "simpleini", + "commonlibsse-ng" ] } From d5bc88f542dc7488c252a66b0f562e5d2faad079 Mon Sep 17 00:00:00 2001 From: colinswrath Date: Sat, 24 Sep 2022 13:13:15 -0400 Subject: [PATCH 2/3] Update to most recent version on CLibNG --- CMakeLists.txt | 2 -- extern/CommonLibSSE | 1 - src/Conditions.h | 3 ++- src/UpdateManager.h | 5 +++-- vcpkg-configuration.json | 5 ++--- 5 files changed, 7 insertions(+), 9 deletions(-) delete mode 160000 extern/CommonLibSSE diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f11682..370f044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,8 +141,6 @@ target_link_libraries( ${PROJECT_NAME} PUBLIC CommonLibSSE::CommonLibSSE - spdlog::spdlog - fmt::fmt ) if (MSVC) diff --git a/extern/CommonLibSSE b/extern/CommonLibSSE deleted file mode 160000 index 8473887..0000000 --- a/extern/CommonLibSSE +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 84738878bc33a445edb834b008cc882380455243 diff --git a/src/Conditions.h b/src/Conditions.h index 6e26191..f620464 100644 --- a/src/Conditions.h +++ b/src/Conditions.h @@ -33,6 +33,7 @@ namespace Conditions static bool IsMoving(RE::PlayerCharacter* player) { - return (static_cast(player->actorState1.movingForward) || static_cast(player->actorState1.movingBack) || static_cast(player->actorState1.movingLeft) || static_cast(player->actorState1.movingRight)); + auto playerState = player->AsActorState(); + return (static_cast(playerState->actorState1.movingForward) || static_cast(playerState->actorState1.movingBack) || static_cast(playerState->actorState1.movingLeft) || static_cast(playerState->actorState1.movingRight)); } }; diff --git a/src/UpdateManager.h b/src/UpdateManager.h index 67e0cbb..154883a 100644 --- a/src/UpdateManager.h +++ b/src/UpdateManager.h @@ -136,7 +136,8 @@ class UpdateManager auto scale = _GetScaleFunction(a1); if(skyrim_cast(a1) == RE::PlayerCharacter::GetSingleton()) { - return a1->refScale / 100.0f; + + return a1->GetReferenceRuntimeData().refScale / 100.0f; } else { @@ -148,7 +149,7 @@ class UpdateManager static bool IsBowDrawNoZoomCheck(RE::PlayerCharacter* player, RE::PlayerCamera* playerCamera) { - auto attackState = player->GetAttackState(); + auto attackState = player->AsActorState()->GetAttackState(); if (playerCamera->bowZoomedIn) { diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index f2ed177..154190a 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -3,11 +3,10 @@ { "kind": "git", "repository": "https://gitlab.com/colorglass/vcpkg-colorglass", - "baseline": "0f58c21b7a7cc96c1ff7bd949c9f4530b514625d", + "baseline": "9c522a19f2e9c1127369554c61f47c686a92db98", "packages": [ "commonlibsse-ng", - "commonlibsse-ng-flatrim", - "commonlibsse-ng-vr" + "commonlibsse-ng-flatrim" ] } ] From 2354317ce6811b875c1e1bdac3e251804d1442cd Mon Sep 17 00:00:00 2001 From: colinswrath Date: Sat, 24 Sep 2022 13:23:14 -0400 Subject: [PATCH 3/3] Backwards compatibility hotfix --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 89f028a..403e300 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,6 +38,8 @@ extern "C" DLLEXPORT constexpr auto SKSEPlugin_Version = v.PluginName(Version::PROJECT); v.AuthorName("colinswrath and Kernalsegg"sv); v.UsesAddressLibrary(true); + v.HasNoStructUse(true); + v.UsesStructsPost629(false); return v; }();