#include "EventListener.h" auto EventListener::GetSingleton() -> EventListener* { static EventListener singleton{}; return std::addressof(singleton); } // Unused void EventListener::Install() { //RE::ScriptEventSourceHolder::GetSingleton()->AddEventSink(EventListener::GetSingleton()); RE::UI::GetSingleton()->AddEventSink(EventListener::GetSingleton()); SKSE::GetModCallbackEventSource()->AddEventSink(EventListener::GetSingleton()); RE::ScriptEventSourceHolder::GetSingleton()->GetEventSource()->AddEventSink(EventListener::GetSingleton()); RE::ScriptEventSourceHolder::GetSingleton()->GetEventSource()->AddEventSink(EventListener::GetSingleton()); } auto EventListener::ProcessEvent( const SKSE::ModCallbackEvent* a_event, RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { if (a_event->eventName == "Enderal_OpenHelpURL") { ShowWindow(GetForegroundWindow(), SW_MINIMIZE); ShellExecuteA(NULL, "open", "https://go.eddoursul.win/enderal-se-support", NULL, NULL, SW_SHOWNORMAL); } return RE::BSEventNotifyControl::kContinue; } auto EventListener::ProcessEvent( const RE::TESContainerChangedEvent* a_event, RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { // return RE::BSEventNotifyControl::kContinue; } auto EventListener::ProcessEvent( const RE::MenuOpenCloseEvent* a_event, RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { if (a_event->opening) { if (a_event->menuName == RE::DialogueMenu::MENU_NAME) { // Make sure Tab is not blocked. If it should be, a Papyrus script will block it a few frames later. DialogueMenuPatch::BlockTab(false); } else if (a_event->menuName == "CustomMenu") { auto uiMovie = RE::UI::GetSingleton()->GetMovieView("CustomMenu"); if (uiMovie && std::strstr(uiMovie->GetMovieDef()->GetFileURL(), "_heromenu.swf") != NULL) { if (RE::UI::GetSingleton()->IsMenuOpen(RE::TweenMenu::MENU_NAME)) { CloseTweenMenu(); } HeroMenuPatch::FillMenuValues(); } } } else { if (a_event->menuName == RE::DialogueMenu::MENU_NAME) { DialogueMenuPatch::BlockTab(false); } else if (a_event->menuName == RE::MainMenu::MENU_NAME) { CheckScriptVersions(); } } return RE::BSEventNotifyControl::kContinue; } auto EventListener::ProcessEvent( const RE::TESActivateEvent* a_event, RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { // return RE::BSEventNotifyControl::kContinue; } auto EventListener::ProcessEvent( const RE::TESCombatEvent* a_event, RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { if (!a_event) { return RE::BSEventNotifyControl::kContinue; } RE::Actor* sourceActor = a_event->actor ? a_event->actor->As() : nullptr; if (!sourceActor) { return RE::BSEventNotifyControl::kContinue; } RE::Actor* targetActor = a_event->targetActor ? a_event->targetActor->As() : nullptr; SKSE::ModCallbackEvent modEvent{ "Enderal_CombatStateChanged", targetActor && targetActor->IsPlayerRef() ? "1" : "", a_event->newState.underlying(), sourceActor }; SKSE::GetModCallbackEventSource()->SendEvent(&modEvent); return RE::BSEventNotifyControl::kContinue; } auto EventListener::ProcessEvent( const RE::TESHitEvent* a_event, RE::BSTEventSource* a_eventSource) -> RE::BSEventNotifyControl { if (!a_event || !a_event->cause || a_event->cause->formID != 0x14) { return RE::BSEventNotifyControl::kContinue; } RE::FormID spellFormID = a_event->projectile ? a_event->projectile : a_event->source; RE::TESObjectREFR* containerRef = a_event->target ? a_event->target->As() : nullptr; if (!containerRef || !spellFormID) { return RE::BSEventNotifyControl::kContinue; } RE::TESBoundObject* baseObject = containerRef->GetBaseObject(); if (baseObject && (baseObject->Is(RE::FormType::Container) || baseObject->Is(RE::FormType::Door)) && containerRef->IsLocked()) { auto* dataHandler = RE::TESDataHandler::GetSingleton(); const RE::BGSListForm* formList = dataHandler ? dataHandler->LookupForm(0x44EE4, "Skyrim.esm") : nullptr; if (formList && formList->HasForm(spellFormID)) { SKSE::ModCallbackEvent modEvent{ "Enderal_UnlockSpellHit", "", spellFormID, containerRef }; SKSE::GetModCallbackEventSource()->SendEvent(&modEvent); } } return RE::BSEventNotifyControl::kContinue; }