1
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

133 lines
4.5 KiB

#include "EventListener.h"
auto EventListener::GetSingleton() -> EventListener*
{
static EventListener singleton{};
return std::addressof(singleton);
}
// Unused
void EventListener::Install()
{
//RE::ScriptEventSourceHolder::GetSingleton()->AddEventSink<RE::TESContainerChangedEvent>(EventListener::GetSingleton());
RE::UI::GetSingleton()->AddEventSink<RE::MenuOpenCloseEvent>(EventListener::GetSingleton());
SKSE::GetModCallbackEventSource()->AddEventSink(EventListener::GetSingleton());
RE::ScriptEventSourceHolder::GetSingleton()->GetEventSource<RE::TESCombatEvent>()->AddEventSink(EventListener::GetSingleton());
RE::ScriptEventSourceHolder::GetSingleton()->GetEventSource<RE::TESHitEvent>()->AddEventSink(EventListener::GetSingleton());
}
auto EventListener::ProcessEvent(
const SKSE::ModCallbackEvent* a_event,
RE::BSTEventSource<SKSE::ModCallbackEvent>* 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<RE::TESContainerChangedEvent>* a_eventSource)
-> RE::BSEventNotifyControl
{
//
return RE::BSEventNotifyControl::kContinue;
}
auto EventListener::ProcessEvent(
const RE::MenuOpenCloseEvent* a_event,
RE::BSTEventSource<RE::MenuOpenCloseEvent>* 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<RE::TESActivateEvent>* a_eventSource)
-> RE::BSEventNotifyControl
{
//
return RE::BSEventNotifyControl::kContinue;
}
auto EventListener::ProcessEvent(
const RE::TESCombatEvent* a_event,
RE::BSTEventSource<RE::TESCombatEvent>* a_eventSource)
-> RE::BSEventNotifyControl
{
if (!a_event) {
return RE::BSEventNotifyControl::kContinue;
}
RE::Actor* sourceActor = a_event->actor ? a_event->actor->As<RE::Actor>() : nullptr;
if (!sourceActor) {
return RE::BSEventNotifyControl::kContinue;
}
RE::Actor* targetActor = a_event->targetActor ? a_event->targetActor->As<RE::Actor>() : 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<RE::TESHitEvent>* 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<RE::TESObjectREFR>() : 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<RE::BGSListForm>(0x44EE4, "Skyrim.esm") : nullptr;
if (formList && formList->HasForm(spellFormID)) {
SKSE::ModCallbackEvent modEvent{ "Enderal_UnlockSpellHit", "", spellFormID, containerRef };
SKSE::GetModCallbackEventSource()->SendEvent(&modEvent);
}
}
return RE::BSEventNotifyControl::kContinue;
}