diff --git a/SKSE/Plugins/EnderalSEEasyCrafting.dll b/SKSE/Plugins/EnderalSEEasyCrafting.dll index 43f1cff..12b786e 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 8bcfc5f..9630306 100644 --- a/src/src/EventListener.cpp +++ b/src/src/EventListener.cpp @@ -19,16 +19,10 @@ auto EventListener::ProcessEvent( RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { - if (a_event->eventName == "Enderal_StartCrafting") { - const auto refr = a_event->sender->As(); - if (refr) { - const auto furn = refr->GetBaseObject()->As(); - if (furn) { - SKSE::GetTaskInterface()->AddTask([furn]() { - FetchSupplies(furn); - }); - } - } + if (a_event->eventName == "Enderal_StartPortableLab") { + SKSE::GetTaskInterface()->AddTask([]() { + FetchSupplies(RE::TESForm::LookupByID(0xBAD0C)->As()); // CraftingAlchemyWorkbench + }); } else if (a_event->eventName == "Enderal_StartSpectralizing") { SKSE::GetTaskInterface()->AddTask([]() { FetchSpectralizingSupplies(); @@ -47,7 +41,41 @@ auto EventListener::ProcessEvent( RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { - if (!a_event->opening && a_event->menuName == RE::CraftingMenu::MENU_NAME) { + if (a_event->menuName != RE::CraftingMenu::MENU_NAME) { + return RE::BSEventNotifyControl::kContinue; + } + + if (a_event->opening) { + RE::CraftingMenu* menu = static_cast(RE::UI::GetSingleton()->GetMenu(RE::CraftingMenu::MENU_NAME).get()); + + if (!menu || !menu->GetCraftingSubMenu()) { + return RE::BSEventNotifyControl::kContinue; + } + + const auto furn = menu->GetCraftingSubMenu()->furniture; + + if (!furn || furn->workBenchData.benchType != RE::TESFurniture::WorkBenchData::BenchType::kCreateObject || furn->As()->HasKeywordString("CraftingSmelterDismantling")) { + return RE::BSEventNotifyControl::kContinue; + } + + SKSE::GetTaskInterface()->AddTask([furn]() { + + FetchSupplies(furn); + + std::thread([]() { + SKSE::GetTaskInterface()->AddTask([]() { + // Trigger item list update, this trick works only with the kCreateObject workbenches + if (auto scriptFactory = RE::IFormFactory::GetConcreteFormFactoryByType()) { + if (auto script = scriptFactory->Create()) { + script->SetCommand("player.additem 1FE82 1 1"); + script->CompileAndRun(nullptr); + } + } + RE::PlayerCharacter::GetSingleton()->RemoveItem(RE::TESForm::LookupByID(0x1FE82)->As(), 99, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr, 0, 0); + }); + }).detach(); + }); + } else { SKSE::GetTaskInterface()->AddTask([]() { ReturnSupplies(); }); @@ -61,7 +89,7 @@ auto EventListener::ProcessEvent( RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { - if (!a_event->actionRef->IsPlayerRef()) { + if (!a_event->actionRef || !a_event->actionRef->IsPlayerRef() || !a_event->objectActivated) { return RE::BSEventNotifyControl::kContinue; } @@ -73,7 +101,7 @@ auto EventListener::ProcessEvent( auto* furn = refr->GetBaseObject()->As(); - if (furn->workBenchData.benchType == RE::TESFurniture::WorkBenchData::BenchType::kNone) { + if (furn->workBenchData.benchType == RE::TESFurniture::WorkBenchData::BenchType::kNone || furn->workBenchData.benchType == RE::TESFurniture::WorkBenchData::BenchType::kCreateObject) { return RE::BSEventNotifyControl::kContinue; } @@ -82,39 +110,25 @@ auto EventListener::ProcessEvent( return RE::BSEventNotifyControl::kContinue; } - if (furn->As()->HasKeywordString("WICraftingSmithing")) { - // Opens crafting menu without delay + std::thread([furn]() { + std::this_thread::sleep_for(std::chrono::milliseconds(300)); + const auto playerRef = RE::PlayerCharacter::GetSingleton(); + if (playerRef->GetSitSleepState() != RE::SIT_SLEEP_STATE::kWantToSit && playerRef->GetSitSleepState() != RE::SIT_SLEEP_STATE::kWaitingForSitAnim) { + return; + } SKSE::GetTaskInterface()->AddTask([furn]() { FetchSupplies(furn); }); - std::thread([]() { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - if (!RE::UI::GetSingleton()->IsMenuOpen(RE::CraftingMenu::MENU_NAME)) { - SKSE::GetTaskInterface()->AddTask([]() { - ReturnSupplies(); - }); - } - }).detach(); - } else { - std::thread([furn]() { - std::this_thread::sleep_for(std::chrono::milliseconds(300)); - if (RE::PlayerCharacter::GetSingleton()->GetSitSleepState() != RE::SIT_SLEEP_STATE::kWaitingForSitAnim) { - return; - } - SKSE::GetTaskInterface()->AddTask([furn]() { - FetchSupplies(furn); + 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(); }); - 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(); return RE::BSEventNotifyControl::kContinue; } diff --git a/src/src/Util.h b/src/src/Util.h index d647cc5..f77f116 100644 --- a/src/src/Util.h +++ b/src/src/Util.h @@ -49,7 +49,7 @@ inline void LoadINI(std::map* settings, const char* iniPath) } } catch (const std::exception& e) { - logger::error(e.what()); + logger::error("ERROR: {}", e.what()); } }