Skip to content

Commit

Permalink
Merge pull request #2 from colinswrath/feature/CommonlibNGSupport
Browse files Browse the repository at this point in the history
Feature/commonlib ng support
  • Loading branch information
colinswrath authored Sep 24, 2022
2 parents 8569cd5 + 2354317 commit a6245af
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 65 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----
Expand Down Expand Up @@ -138,9 +139,8 @@ target_include_directories(

target_link_libraries(
${PROJECT_NAME}
PRIVATE
PUBLIC
CommonLibSSE::CommonLibSSE
spdlog::spdlog
)

if (MSVC)
Expand Down
1 change: 0 additions & 1 deletion extern/CommonLibSSE
Submodule CommonLibSSE deleted from 847388
12 changes: 6 additions & 6 deletions src/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/Conditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace Conditions

static bool IsMoving(RE::PlayerCharacter* player)
{
return (!static_cast<bool>(player->actorState1.movingForward) && !static_cast<bool>(player->actorState1.movingBack) && !static_cast<bool>(player->actorState1.movingLeft) && !static_cast<bool>(player->actorState1.movingRight));
auto playerState = player->AsActorState();
return (static_cast<bool>(playerState->actorState1.movingForward) || static_cast<bool>(playerState->actorState1.movingBack) || static_cast<bool>(playerState->actorState1.movingLeft) || static_cast<bool>(playerState->actorState1.movingRight));
}
};
16 changes: 5 additions & 11 deletions src/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@

namespace Hooks
{
//1.6 = REL::Relocation<std::uintptr_t> OnFrame_Update_Hook{ REL::ID(36564), 0x6E };
inline static REL::Relocation<std::uintptr_t> OnFrame_Update_Hook{ REL::ID(35565), 0x1E };
inline static REL::Relocation<std::uintptr_t> OnFrame_Update_Hook{ REL::RelocationID(35565,36564), REL::Relocate(0x1E,0x6E) };
inline static REL::Relocation<std::uintptr_t> Scale_Patch_Hook{ REL::RelocationID(37013,38041), REL::Relocate(0x1A,0x1F) };

//1.6 = REL::Relocation<std::uintptr_t> Scale_Patch_Hook{ REL::ID(38041), 0x1F };
inline static REL::Relocation<std::uintptr_t> Scale_Patch_Hook{ REL::ID(37013), 0x1A };
inline static REL::Relocation<std::uintptr_t> Block_GameSetting_Hook{ REL::RelocationID(42842,44014), REL::Relocate(0x452,0x438) };
inline static REL::Relocation<std::uintptr_t> fBlock_GameSetting{ REL::RelocationID(505023,374158), 0x8 };

//1.6 = REL::Relocation<std::uintptr_t> Block_GameSetting_Hook{ REL::ID(44014), 0x438 };
//1.6 = REL::Relocation<std::uintptr_t> fBlock_GameSetting { REL::ID(374158) };
inline static REL::Relocation<std::uintptr_t> Block_GameSetting_Hook{ REL::ID(42842), 0x452 };
inline static REL::Relocation<std::uintptr_t> fBlock_GameSetting{ REL::ID(505023), 0x8 };

// 1.6 REL::Relocation<std::uintptr_t> SpellCap_Hook{ REL::ID(38741), 0x55 };
inline static REL::Relocation<std::uintptr_t> SpellCap_Hook{ REL::ID(37792), 0x53 };
inline static REL::Relocation<std::uintptr_t> SpellCap_Hook{ REL::RelocationID(37792,38741), REL::Relocate(0x53,0x55) };

bool Install();
}
25 changes: 13 additions & 12 deletions src/UpdateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand All @@ -136,7 +136,8 @@ class UpdateManager
auto scale = _GetScaleFunction(a1);
if(skyrim_cast<RE::Actor*>(a1) == RE::PlayerCharacter::GetSingleton())
{
return a1->refScale / 100.0f;

return a1->GetReferenceRuntimeData().refScale / 100.0f;
}
else
{
Expand All @@ -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)
{
Expand Down
37 changes: 7 additions & 30 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "Settings.h"
#include "Cache.h"

/* 1.6
void InitLogger()
{
#ifndef NDEBUG
Expand Down Expand Up @@ -39,38 +38,15 @@ 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;
}();
*/


extern "C" DLLEXPORT bool SKSEAPI SKSEPlugin_Query(const SKSE::QueryInterface * a_skse, SKSE::PluginInfo * a_info)
{
#ifndef NDEBUG
auto sink = std::make_shared<spdlog::sinks::msvc_sink_mt>();
#else
auto path = logger::log_directory();
if (!path) {
return false;
}

*path /= Version::PROJECT;
*path += ".log"sv;
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true);
#endif

auto log = std::make_shared<spdlog::logger>("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();
Expand All @@ -82,7 +58,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;
}
Expand All @@ -105,7 +81,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.");
Expand All @@ -126,5 +102,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;
}
13 changes: 13 additions & 0 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"registries": [
{
"kind": "git",
"repository": "https://gitlab.com/colorglass/vcpkg-colorglass",
"baseline": "9c522a19f2e9c1127369554c61f47c686a92db98",
"packages": [
"commonlibsse-ng",
"commonlibsse-ng-flatrim"
]
}
]
}
3 changes: 2 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"boost-stl-interfaces",
"rsm-binary-io",
"spdlog",
"simpleini"
"simpleini",
"commonlibsse-ng"
]
}

0 comments on commit a6245af

Please sign in to comment.