Skip to content

Commit

Permalink
hopefully VR fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisSoemers committed Apr 9, 2023
1 parent 46e6bb7 commit 36f2d5c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ message("Using toolchain file ${CMAKE_TOOLCHAIN_FILE}.")
########################################################################################################################
project(
PAPER
VERSION 2.2.0
VERSION 2.2.1
DESCRIPTION "The PAper Papyrus ExtendeR. Plugin to expose new functions and events to Skyrim's 'Papyrus' scripting language. "
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
Expand Down
26 changes: 20 additions & 6 deletions include/OnContainerChangedEventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ namespace OnContainerChangedEvents {
#pragma warning(push)
#pragma warning(disable : 4251)

// Retrieve manual offset for edge cases CLIB-NG does not account for yet
// Thanks to Nightfallstorm!
template <class T>
T GetManualRelocateMemberVariable(void* object, REL::VariantOffset offset) {
return *(reinterpret_cast<T*>((uintptr_t)object + offset.offset()));
}

/**
* Data for an event to be processed.
*/
Expand Down Expand Up @@ -95,30 +102,37 @@ namespace OnContainerChangedEvents {
virtual bool matchesFilter(RE::VMHandle handle) override {
auto vm = RE::SkyrimVM::GetSingleton();

vm->InventoryEventFilterMapLock.Lock();
auto inventoryEventFilterMapLock =
GetManualRelocateMemberVariable<RE::BSSpinLock>(vm, REL::VariantOffset(0x8940, 0x8940, 0x8960));

inventoryEventFilterMapLock.Lock();

const auto& inventoryEventFilterMap =
GetManualRelocateMemberVariable<RE::BSTHashMap<RE::VMHandle, RE::SkyrimVM::InventoryEventFilterLists*>>(
vm, REL::VariantOffset(0x8948, 0x8948, 0x8968));

RE::SkyrimVM::InventoryEventFilterLists* filterLists = nullptr;
auto it = vm->InventoryEventFilterMap.find(handle);
if (it != vm->InventoryEventFilterMap.end()) {
auto it = inventoryEventFilterMap.find(handle);
if (it != inventoryEventFilterMap.end()) {
filterLists = it->second;
}

if (filterLists) {
// Have filters, so need at least one of our items to match
for (auto baseObj : baseItems) {
if (OnContainerChangedEventHandler::ItemPassesInventoryFilterLists(baseObj->formID, filterLists)) {
vm->InventoryEventFilterMapLock.Unlock();
inventoryEventFilterMapLock.Unlock();
return true;
}
}
} else {
// No filters, so anything matches
vm->InventoryEventFilterMapLock.Unlock();
inventoryEventFilterMapLock.Unlock();
return true;
}

// Have filters but none matched, so return false
vm->InventoryEventFilterMapLock.Unlock();
inventoryEventFilterMapLock.Unlock();
return false;
}
};
Expand Down
4 changes: 2 additions & 2 deletions include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Instead, edit the template in /cmake/version.h.in

#define PROJECT_VER 2.2.0
#define PROJECT_VER 2.2.1
#define PROJECT_VER_MAJOR 2
#define PROJECT_VER_MINOR 2
#define PROJECT_VER_PATCH 0
#define PROJECT_VER_PATCH 1
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
"name": "paper-plugin",
"version-string": "2.2.0",
"version-string": "2.2.1",
"port-version": 0,
"description": "The PAper Papyrus ExtendeR. Plugin to expose new functions and events to Skyrim's 'Papyrus' scripting language.",
"license": "Apache-2.0",
Expand Down

0 comments on commit 36f2d5c

Please sign in to comment.