diff --git a/SKSE/Plugins/EnderalSEEasyCrafting.dll b/SKSE/Plugins/EnderalSEEasyCrafting.dll index 7477d3f..822a0fb 100644 Binary files a/SKSE/Plugins/EnderalSEEasyCrafting.dll and b/SKSE/Plugins/EnderalSEEasyCrafting.dll differ diff --git a/src/src/EventListener.cpp b/src/src/EventListener.cpp index 9630306..d1eef29 100644 --- a/src/src/EventListener.cpp +++ b/src/src/EventListener.cpp @@ -59,10 +59,11 @@ auto EventListener::ProcessEvent( } SKSE::GetTaskInterface()->AddTask([furn]() { - - FetchSupplies(furn); - + if (!FetchSupplies(furn)) { + return; + } std::thread([]() { + std::this_thread::sleep_for(std::chrono::milliseconds(50)); SKSE::GetTaskInterface()->AddTask([]() { // Trigger item list update, this trick works only with the kCreateObject workbenches if (auto scriptFactory = RE::IFormFactory::GetConcreteFormFactoryByType()) { @@ -117,17 +118,22 @@ auto EventListener::ProcessEvent( return; } SKSE::GetTaskInterface()->AddTask([furn]() { - FetchSupplies(furn); + if (!FetchSupplies(furn)) { + return; + } + std::thread([]() { + const auto playerRef = RE::PlayerCharacter::GetSingleton(); + while (playerRef->GetSitSleepState() == RE::SIT_SLEEP_STATE::kWantToSit || playerRef->GetSitSleepState() == RE::SIT_SLEEP_STATE::kWaitingForSitAnim) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + if (!RE::UI::GetSingleton()->IsMenuOpen(RE::CraftingMenu::MENU_NAME)) { + SKSE::GetTaskInterface()->AddTask([]() { + ReturnSupplies(); + }); + } + }).detach(); }); - while (playerRef->GetSitSleepState() == RE::SIT_SLEEP_STATE::kWantToSit || playerRef->GetSitSleepState() == RE::SIT_SLEEP_STATE::kWaitingForSitAnim) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - if (!RE::UI::GetSingleton()->IsMenuOpen(RE::CraftingMenu::MENU_NAME)) { - SKSE::GetTaskInterface()->AddTask([]() { - ReturnSupplies(); - }); - } }).detach(); return RE::BSEventNotifyControl::kContinue; diff --git a/src/src/Util.h b/src/src/Util.h index 95caa5c..6d5948a 100644 --- a/src/src/Util.h +++ b/src/src/Util.h @@ -239,10 +239,10 @@ inline void ReturnSupplies() }).detach(); } -inline void FetchSupplies(RE::TESFurniture* a_furn) +inline bool FetchSupplies(RE::TESFurniture* a_furn) { if (!a_furn) { - return; + return false; } supplyCount.clear(); @@ -264,7 +264,7 @@ inline void FetchSupplies(RE::TESFurniture* a_furn) } if (!bAllowFetch) { - return; + return false; } bSuppliesFetched = true; @@ -299,6 +299,8 @@ inline void FetchSupplies(RE::TESFurniture* a_furn) } }); }).detach(); + + return true; } inline bool GetSuppliesFetched()