1
Fork 0

Always run SyncCellStorage as a task

ae-1.6.629
Eddoursul 2 years ago
parent 1fedd07be1
commit deaac1c723
  1. BIN
      SKSE/Plugins/ArtifactTracker.dll
  2. 125
      Source/ArtifactTrackerDLL/src/ArtifactTracker.cpp
  3. 36
      Source/ArtifactTrackerDLL/src/EventListener.cpp

Binary file not shown.

@ -269,9 +269,7 @@ namespace ArtifactTracker
g_bBookShelf = false; g_bBookShelf = false;
std::thread([]() { std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(1200)); std::this_thread::sleep_for(std::chrono::milliseconds(1200));
SKSE::GetTaskInterface()->AddTask([&]() { ArtifactTracker::SyncCellStorage();
ArtifactTracker::SyncCellStorage();
});
}).detach(); }).detach();
} else { } else {
SyncCellStorage(); SyncCellStorage();
@ -377,8 +375,8 @@ namespace ArtifactTracker
log::info("Adding new storage in {}", cell->GetName()); log::info("Adding new storage in {}", cell->GetName());
#endif #endif
SKSE::GetTaskInterface()->AddTask([&]() { SKSE::GetTaskInterface()->AddTask([]() {
cellStorage = RE::PlayerCharacter::GetSingleton()->PlaceObjectAtMe(g_cellContainer, true).get(); const auto cellStorage = RE::PlayerCharacter::GetSingleton()->PlaceObjectAtMe(g_cellContainer, true).get();
if (cellStorage) { if (cellStorage) {
cellStorage->Disable(); cellStorage->Disable();
@ -406,83 +404,86 @@ namespace ArtifactTracker
log::info("Running SyncCellStorage"); log::info("Running SyncCellStorage");
#endif #endif
std::unordered_set<RE::FormID> cellItems; const RE::FormID ignoreFormID = a_ignoreRef ? a_ignoreRef->formID : NULL;
const auto cell = g_cellStorage->GetParentCell(); SKSE::GetTaskInterface()->AddTask([ignoreFormID]() {
const auto inv = g_cellStorage->GetInventory(); std::unordered_set<RE::FormID> cellItems;
cell->ForEachReference([&](RE::TESObjectREFR& a_ref) { const auto cell = g_cellStorage->GetParentCell();
if (a_ignoreRef && a_ignoreRef->formID == a_ref.formID) { const auto inv = g_cellStorage->GetInventory();
return true;
}
const auto baseObj = a_ref.GetBaseObject(); cell->ForEachReference([&](RE::TESObjectREFR& a_ref) {
if (ignoreFormID && ignoreFormID == a_ref.formID) {
if (IsValidContainer(&a_ref)) {
if (g_cellContainer == baseObj || baseObj->formID == 0xDC9E7 || g_persistentMap.contains(a_ref.formID)) { // skip persistent and PlayerBookShelfContainer
return true; return true;
} }
const auto contInv = a_ref.GetInventory([&](RE::TESBoundObject& a_object) -> bool { const auto baseObj = a_ref.GetBaseObject();
return !cellItems.contains(a_object.formID) && IsArtifact(&a_object);
});
for (const auto& [item, data] : contInv) { if (IsValidContainer(&a_ref)) {
if (data.first > 0) { if (g_cellContainer == baseObj || baseObj->formID == 0xDC9E7 || g_persistentMap.contains(a_ref.formID)) { // skip persistent and PlayerBookShelfContainer
cellItems.insert(item->formID); return true;
if (inv.find(item) == inv.end()) {
g_cellStorage->AddObjectToContainer(item, nullptr, 1, nullptr);
}
if (!g_listStored->HasForm(item)) {
ListRemoveItem(g_listNew, item);
ListRemoveItem(g_listFound, item);
g_listStored->AddForm(item);
}
} }
}
return true; const auto contInv = a_ref.GetInventory([&](RE::TESBoundObject& a_object) -> bool {
} return !cellItems.contains(a_object.formID) && IsArtifact(&a_object);
});
if (a_ref.IsDisabled() || a_ref.IsMarkedForDeletion() || cellItems.contains(baseObj->formID) || !IsArtifact(baseObj)) { for (const auto& [item, data] : contInv) {
return true; if (data.first > 0) {
} cellItems.insert(item->formID);
if (inv.find(item) == inv.end()) {
g_cellStorage->AddObjectToContainer(item, nullptr, 1, nullptr);
}
if (!g_listStored->HasForm(item)) {
ListRemoveItem(g_listNew, item);
ListRemoveItem(g_listFound, item);
g_listStored->AddForm(item);
}
}
}
cellItems.insert(baseObj->formID); return true;
}
if (inv.find(baseObj) == inv.end()) { if (a_ref.IsDisabled() || a_ref.IsMarkedForDeletion() || cellItems.contains(baseObj->formID) || !IsArtifact(baseObj)) {
g_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr); return true;
} }
if (!g_listStored->HasForm(baseObj)) { cellItems.insert(baseObj->formID);
ListRemoveItem(g_listNew, baseObj);
ListRemoveItem(g_listFound, baseObj);
g_listStored->AddForm(baseObj);
}
return true; if (inv.find(baseObj) == inv.end()) {
}); g_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr);
}
for (const auto& [item, data] : inv) { if (!g_listStored->HasForm(baseObj)) {
const auto& [count, entry] = data; ListRemoveItem(g_listNew, baseObj);
if (count > 0 && !cellItems.contains(item->formID)) { ListRemoveItem(g_listFound, baseObj);
g_listStored->AddForm(baseObj);
}
g_cellStorage->RemoveItem(item, count, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr); return true;
});
if (!RefListHasItem(g_persistentStorage, item->formID)) { for (const auto& [item, data] : inv) {
ListRemoveItem(g_listStored, item); const auto& [count, entry] = data;
if (GetItemCount(RE::PlayerCharacter::GetSingleton(), item) || FollowersHaveItem(item)) { if (count > 0 && !cellItems.contains(item->formID)) {
ListRemoveItem(g_listNew, item); g_cellStorage->RemoveItem(item, count, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr);
g_listFound->AddForm(item);
} else { if (!RefListHasItem(g_persistentStorage, item->formID)) {
ListRemoveItem(g_listFound, item); ListRemoveItem(g_listStored, item);
g_listNew->AddForm(item); if (GetItemCount(RE::PlayerCharacter::GetSingleton(), item) || FollowersHaveItem(item)) {
ListRemoveItem(g_listNew, item);
g_listFound->AddForm(item);
} else {
ListRemoveItem(g_listFound, item);
g_listNew->AddForm(item);
}
} }
} }
} }
}
cellItems.clear(); cellItems.clear();
});
} }
void OnContainerChanged(const RE::TESContainerChangedEvent* a_event, RE::TESForm* form) void OnContainerChanged(const RE::TESContainerChangedEvent* a_event, RE::TESForm* form)
@ -759,7 +760,7 @@ namespace ArtifactTracker
g_iFollowerIndex = iCurrentFollowers; g_iFollowerIndex = iCurrentFollowers;
std::thread([]() { std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait for followers to load into the new cell std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait for followers to load into the new cell
SKSE::GetTaskInterface()->AddTask([&]() { SKSE::GetTaskInterface()->AddTask([]() {
RescanFoundArtifacts(); RescanFoundArtifacts();
}); });
}).detach(); }).detach();

@ -84,22 +84,26 @@ auto EventListener::ProcessEvent(
SKSE::log::info("MenuOpenCloseEvent"); SKSE::log::info("MenuOpenCloseEvent");
#endif #endif
if (a_event->opening) { bool bOpening = a_event->opening;
RE::BSInputDeviceManager::GetSingleton()->AddEventSink(EventListener::GetSingleton());
} else { SKSE::GetTaskInterface()->AddTask([bOpening]() {
RE::BSInputDeviceManager::GetSingleton()->RemoveEventSink(EventListener::GetSingleton()); if (bOpening) {
if (ArtifactTracker::g_bTakeAll && ArtifactTracker::g_bNotifyNewArtifact && ArtifactTracker::g_bTakeAllCount > 0) { RE::BSInputDeviceManager::GetSingleton()->AddEventSink(EventListener::GetSingleton());
//RE::DebugNotification(fmt::format("{} new artifact(s) acquired", ArtifactTracker::g_bTakeAllCount).c_str()); } else {
RE::BSTSmartPointer<RE::BSScript::IStackCallbackFunctor> stackCallback; RE::BSInputDeviceManager::GetSingleton()->RemoveEventSink(EventListener::GetSingleton());
RE::BSScript::Internal::VirtualMachine::GetSingleton()->DispatchStaticCall("ETR_NewArtifactsCombinedNotification", "Show", RE::MakeFunctionArguments<std::uint32_t>(std::move(ArtifactTracker::g_bTakeAllCount)), stackCallback); if (ArtifactTracker::g_bTakeAll && ArtifactTracker::g_bNotifyNewArtifact && ArtifactTracker::g_bTakeAllCount > 0) {
//RE::DebugNotification(fmt::format("{} new artifact(s) acquired", ArtifactTracker::g_bTakeAllCount).c_str());
RE::BSTSmartPointer<RE::BSScript::IStackCallbackFunctor> stackCallback;
RE::BSScript::Internal::VirtualMachine::GetSingleton()->DispatchStaticCall("ETR_NewArtifactsCombinedNotification", "Show", RE::MakeFunctionArguments<std::uint32_t>(std::move(ArtifactTracker::g_bTakeAllCount)), stackCallback);
}
ArtifactTracker::g_bTakeAll = false;
ArtifactTracker::g_bTakeAllCount = 0;
} }
ArtifactTracker::g_bTakeAll = false;
ArtifactTracker::g_bTakeAllCount = 0;
}
if (ArtifactTracker::IsHome()) { if (ArtifactTracker::IsHome()) {
ArtifactTracker::SetContainerMode(a_event->opening); ArtifactTracker::SetContainerMode(bOpening);
} }
});
} }
return RE::BSEventNotifyControl::kContinue; return RE::BSEventNotifyControl::kContinue;
@ -116,9 +120,7 @@ auto EventListener::ProcessEvent(
if (ref && ArtifactTracker::IsArtifact(ref->GetBaseObject())) { if (ref && ArtifactTracker::IsArtifact(ref->GetBaseObject())) {
std::thread([]() { std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
SKSE::GetTaskInterface()->AddTask([&]() { ArtifactTracker::SyncCellStorage();
ArtifactTracker::SyncCellStorage();
});
}).detach(); }).detach();
} }
} }

Loading…
Cancel
Save