Compare commits

...

2 Commits

Author SHA1 Message Date
2870d020ce Minor tweaks 2022-08-21 18:20:02 +02:00
eedd2dff54 Verify that the crafting menu actually opens 2022-08-21 18:19:50 +02:00
3 changed files with 23 additions and 18 deletions

View File

@ -98,9 +98,19 @@ auto EventListener::ProcessEvent(
} else { } else {
std::thread([furn]() { std::thread([furn]() {
std::this_thread::sleep_for(std::chrono::milliseconds(300)); std::this_thread::sleep_for(std::chrono::milliseconds(300));
if (RE::PlayerCharacter::GetSingleton()->GetSitSleepState() == RE::SIT_SLEEP_STATE::kWaitingForSitAnim) { if (RE::PlayerCharacter::GetSingleton()->GetSitSleepState() != RE::SIT_SLEEP_STATE::kWaitingForSitAnim) {
SKSE::GetTaskInterface()->AddTask([furn]() { return;
FetchSupplies(furn); }
SKSE::GetTaskInterface()->AddTask([furn]() {
FetchSupplies(furn);
});
while (RE::PlayerCharacter::GetSingleton()->GetSitSleepState() == RE::SIT_SLEEP_STATE::kWaitingForSitAnim) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
std::this_thread::sleep_for(std::chrono::milliseconds(300));
if (!RE::UI::GetSingleton()->IsMenuOpen(RE::CraftingMenu::MENU_NAME)) {
SKSE::GetTaskInterface()->AddTask([]() {
ReturnSupplies();
}); });
} }
}).detach(); }).detach();

View File

@ -4,6 +4,7 @@
static std::unordered_map<RE::TESForm*, std::uint32_t> supplyCount = {}; static std::unordered_map<RE::TESForm*, std::uint32_t> supplyCount = {};
static bool bSuppliesFetched = false; static bool bSuppliesFetched = false;
static constexpr RE::ITEM_REMOVE_REASON iRemoveReason = RE::ITEM_REMOVE_REASON::kStoreInContainer;
inline void LoadINI(std::map<std::string, bool>* settings, const char* iniPath) inline void LoadINI(std::map<std::string, bool>* settings, const char* iniPath)
{ {
@ -48,7 +49,7 @@ inline void LoadINI(std::map<std::string, bool>* settings, const char* iniPath)
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
//logger::error(e.what()); logger::error(e.what());
} }
} }
@ -73,7 +74,7 @@ inline RE::TESObjectREFR* GetChest()
inline void NotifyFetching(const char* a_notification) inline void NotifyFetching(const char* a_notification)
{ {
if (GetSettings().at("ShowFetchingNotification")) { if (GetSettings().at("ShowFetchingNotification")) {
RE::DebugNotification(a_notification); RE::DebugNotification(a_notification, nullptr, false);
} }
} }
@ -94,13 +95,11 @@ inline void FetchSuppliesByType(RE::FormType formType)
return true; return true;
}); });
RE::ITEM_REMOVE_REASON iReason = RE::ITEM_REMOVE_REASON::kStoreInContainer;
for (const auto& [item, data] : inv) { for (const auto& [item, data] : inv) {
const auto& [count, entry] = data; const auto& [count, entry] = data;
if (count > 0) { if (count > 0) {
supplyCount.insert({ item, count }); supplyCount.insert({ item, count });
chest->RemoveItem(item, count, iReason, nullptr, targetRef, 0, 0); chest->RemoveItem(item, count, iRemoveReason, nullptr, targetRef, 0, 0);
} }
} }
} }
@ -118,7 +117,6 @@ inline void FetchByWorkbench(RE::TESFurniture* workbench)
const auto playerRef = RE::PlayerCharacter::GetSingleton(); const auto playerRef = RE::PlayerCharacter::GetSingleton();
const auto inv = chest->GetInventory(); const auto inv = chest->GetInventory();
const auto keywords = workbench->As<RE::BGSKeywordForm>(); const auto keywords = workbench->As<RE::BGSKeywordForm>();
RE::ITEM_REMOVE_REASON iReason = RE::ITEM_REMOVE_REASON::kStoreInContainer;
for (const auto& recipe : RE::TESDataHandler::GetSingleton()->GetFormArray<RE::BGSConstructibleObject>()) { for (const auto& recipe : RE::TESDataHandler::GetSingleton()->GetFormArray<RE::BGSConstructibleObject>()) {
if (recipe->benchKeyword && keywords->HasKeyword(recipe->benchKeyword) && recipe->requiredItems.numContainerObjects > 0) { if (recipe->benchKeyword && keywords->HasKeyword(recipe->benchKeyword) && recipe->requiredItems.numContainerObjects > 0) {
@ -130,7 +128,7 @@ inline void FetchByWorkbench(RE::TESFurniture* workbench)
const auto it = inv.find(component->obj); const auto it = inv.find(component->obj);
if (it != inv.end()) { if (it != inv.end()) {
supplyCount.insert({ it->first, it->second.first }); supplyCount.insert({ it->first, it->second.first });
chest->RemoveItem(it->first, it->second.first, iReason, nullptr, playerRef, 0, 0); chest->RemoveItem(it->first, it->second.first, iRemoveReason, nullptr, playerRef, 0, 0);
} }
} }
} }
@ -151,13 +149,11 @@ inline void FetchSuppliesByForm(RE::TESForm* a_form)
return a_form == &a_xform; return a_form == &a_xform;
}); });
RE::ITEM_REMOVE_REASON iReason = RE::ITEM_REMOVE_REASON::kStoreInContainer;
for (const auto& [item, data] : inv) { for (const auto& [item, data] : inv) {
const auto& [count, entry] = data; const auto& [count, entry] = data;
if (count > 0) { if (count > 0) {
supplyCount.insert({ item, count }); supplyCount.insert({ item, count });
chest->RemoveItem(item, count, iReason, nullptr, targetRef, 0, 0); chest->RemoveItem(item, count, iRemoveReason, nullptr, targetRef, 0, 0);
} }
} }
} }
@ -176,10 +172,9 @@ inline void ReturnSupplies()
const auto chest = GetChest(); const auto chest = GetChest();
const auto playerRef = RE::PlayerCharacter::GetSingleton(); const auto playerRef = RE::PlayerCharacter::GetSingleton();
RE::ITEM_REMOVE_REASON iReason = RE::ITEM_REMOVE_REASON::kStoreInContainer;
for (auto& item : supplyCount) { for (auto& item : supplyCount) {
playerRef->RemoveItem(item.first->As<RE::TESBoundObject>(), item.second, iReason, nullptr, chest, 0, 0); playerRef->RemoveItem(item.first->As<RE::TESBoundObject>(), item.second, iRemoveReason, nullptr, chest, 0, 0);
} }
supplyCount.clear(); supplyCount.clear();
@ -218,12 +213,12 @@ inline void ReturnSupplies()
for (const auto& [item, data] : inv) { for (const auto& [item, data] : inv) {
const auto& [count, entry] = data; const auto& [count, entry] = data;
if (count > 0 && !entry->IsFavorited() && !entry->IsQuestObject()) { if (count > 0 && !entry->IsFavorited() && !entry->IsQuestObject()) {
playerRef->RemoveItem(item, count, iReason, nullptr, chest, 0, 0); playerRef->RemoveItem(item, count, iRemoveReason, nullptr, chest, 0, 0);
} }
} }
std::thread([]() { std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(3));
SKSE::GetTaskInterface()->AddTask([]() { SKSE::GetTaskInterface()->AddTask([]() {
const auto spell = RE::TESForm::LookupByID(0x824AF); const auto spell = RE::TESForm::LookupByID(0x824AF);
if (spell) { if (spell) {
@ -273,7 +268,7 @@ inline void FetchSupplies(RE::TESFurniture* a_furn)
} }
std::thread([a_furn]() { std::thread([a_furn]() {
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(3));
SKSE::GetTaskInterface()->AddTask([a_furn]() { SKSE::GetTaskInterface()->AddTask([a_furn]() {
switch (a_furn->workBenchData.benchType.underlying()) { switch (a_furn->workBenchData.benchType.underlying()) {