An alternative solution for the kCreateObject workbenches
This commit is contained in:
parent
2870d020ce
commit
8b2ef12e8f
Binary file not shown.
@ -19,16 +19,10 @@ auto EventListener::ProcessEvent(
|
||||
RE::BSTEventSource<SKSE::ModCallbackEvent>* a_eventSource)
|
||||
-> RE::BSEventNotifyControl
|
||||
{
|
||||
if (a_event->eventName == "Enderal_StartCrafting") {
|
||||
const auto refr = a_event->sender->As<RE::TESObjectREFR>();
|
||||
if (refr) {
|
||||
const auto furn = refr->GetBaseObject()->As<RE::TESFurniture>();
|
||||
if (furn) {
|
||||
SKSE::GetTaskInterface()->AddTask([furn]() {
|
||||
FetchSupplies(furn);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (a_event->eventName == "Enderal_StartPortableLab") {
|
||||
SKSE::GetTaskInterface()->AddTask([]() {
|
||||
FetchSupplies(RE::TESForm::LookupByID(0xBAD0C)->As<RE::TESFurniture>()); // CraftingAlchemyWorkbench
|
||||
});
|
||||
} else if (a_event->eventName == "Enderal_StartSpectralizing") {
|
||||
SKSE::GetTaskInterface()->AddTask([]() {
|
||||
FetchSpectralizingSupplies();
|
||||
@ -47,7 +41,41 @@ auto EventListener::ProcessEvent(
|
||||
RE::BSTEventSource<RE::MenuOpenCloseEvent>* 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::CraftingMenu*>(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<RE::BGSKeywordForm>()->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<RE::Script>()) {
|
||||
if (auto script = scriptFactory->Create()) {
|
||||
script->SetCommand("player.additem 1FE82 1 1");
|
||||
script->CompileAndRun(nullptr);
|
||||
}
|
||||
}
|
||||
RE::PlayerCharacter::GetSingleton()->RemoveItem(RE::TESForm::LookupByID(0x1FE82)->As<RE::TESBoundObject>(), 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<RE::TESActivateEvent>* 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<RE::TESFurniture>();
|
||||
|
||||
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<RE::BGSKeywordForm>()->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;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ inline void LoadINI(std::map<std::string, bool>* settings, const char* iniPath)
|
||||
}
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
logger::error(e.what());
|
||||
logger::error("ERROR: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user