Skip to content

Commit

Permalink
added test hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ponzipyramid authored and ThirdEyeSqueegee committed Jan 18, 2024
1 parent 08f6c04 commit 8fa6be0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(
headers
include/Utility.h
include/Maps.h
include/Hooks.h
)

set(
Expand All @@ -38,6 +39,7 @@ set(
src/Parser.cpp
src/Conflicts.cpp
src/Distributor.cpp
src/Hooks.cpp

${CMAKE_CURRENT_BINARY_DIR}/version.rc
)
Expand Down
40 changes: 40 additions & 0 deletions include/Hooks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

namespace Hooks {

struct InitItemImpl
{
static void Thunk(RE::TESObjectREFR* a_ref)
{
if (a_ref->HasContainer()) {
func(a_ref);

logger::info("processing container: {}", a_ref->GetFormID());

auto inv = a_ref->GetInventory();
for (const auto& [form, data] : inv) {
logger::info("contains: {}", form->GetFormEditorID());
}

auto gold = RE::TESDataHandler::GetSingleton()->LookupForm(0xF, "Skyrim.esm");

a_ref->RemoveItem(gold->As<RE::TESBoundObject>(), 1000000, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr);
a_ref->AddObjectToContainer(gold->As<RE::TESBoundObject>(), nullptr, 100, nullptr);

return;
}

func(a_ref);
}
static inline REL::Relocation<decltype(Thunk)> func;
static inline constexpr std::size_t idx{ 0x13 };

static void Install()
{
stl::write_vfunc<RE::TESObjectREFR, InitItemImpl>();
logger::info("Installed Object Reference hook");
}
};

void Install();
}
5 changes: 5 additions & 0 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "Hooks.h"

void Hooks::Install() {
Hooks::InitItemImpl::Install();
}
3 changes: 3 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Distributor.h"
#include "Logging.h"
#include "Settings.h"
#include "Hooks.h"

void Listener(SKSE::MessagingInterface::Message* message) noexcept
{
Expand All @@ -13,6 +14,7 @@ void Listener(SKSE::MessagingInterface::Message* message) noexcept
Settings::LoadSettings();
Conflicts::PrepareDistribution();
Distributor::Distribute();
Hooks::Install();
}
}

Expand All @@ -27,6 +29,7 @@ SKSEPluginLoad(const SKSE::LoadInterface* skse)

Init(skse);


if (const auto messaging{ SKSE::GetMessagingInterface() }; !messaging->RegisterListener(Listener))
return false;

Expand Down

0 comments on commit 8fa6be0

Please sign in to comment.