4
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
5.0 KiB

#include "EventListener.h"
#include "Util.h"
#include "Papyrus.h"
#include "FlatMapMarkers.h"
#include "StayAtSystemPage.h"
using namespace SKSE;
static std::map<std::string, bool> g_settings{
{ "FlatMapMarkers", true },
{ "StayAtSystemPage", true }
};
namespace {
void InitializeLogging() {
auto path = logger::log_directory();
if (!path) {
SKSE::stl::report_and_fail("Failed to find standard logging directory"sv);
}
*path /= "EnderalSE.log"sv;
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true);
auto log = std::make_shared<spdlog::logger>("global log"s, std::move(sink));
log->set_level(spdlog::level::info);
log->flush_on(spdlog::level::info);
spdlog::set_default_logger(std::move(log));
spdlog::set_pattern("[%l] %v"s);
}
void InitializeMessaging()
{
GetMessagingInterface()->RegisterListener([](MessagingInterface::Message* message) {
if (message->type == MessagingInterface::kPostLoad) {
if (DataFileExists("Dawnguard.esm") || DataFileExists("Dragonborn.esm") || DataFileExists("HearthFires.esm") || DataFileExists("Update.esm")) {
MessageBoxW(NULL, L"Skyrim DLCs are incompatible with Enderal.", L"Error", MB_OK | MB_ICONERROR);
exit(EXIT_FAILURE);
}
if (DataFileExists("Unofficial Skyrim Special Edition Patch.esp")) {
MessageBoxW(NULL, L"Unofficial Skyrim Special Edition Patch is incompatible with Enderal.", L"Error", MB_OK | MB_ICONERROR);
exit(EXIT_FAILURE);
}
CheckCCMods();
if (g_settings.at("StayAtSystemPage")) {
if (const auto pluginInfo = GetLoadInterface()->GetPluginInfo("StayAtSystemPage"); pluginInfo) {
MessageBoxW(NULL, L"Stay At The System Page is already included in Enderal, please, disable it.", L"Error", MB_OK | MB_ICONERROR);
exit(EXIT_FAILURE);
}
}
if (g_settings.at("FlatMapMarkers")) {
if (const auto pluginInfo = GetLoadInterface()->GetPluginInfo("FlatMapMarkersSSE"); pluginInfo) {
MessageBoxW(NULL, L"Flat Map Markers is already included in Enderal, please, disable it (remove file Data\\SKSE\\Plugins\\FlatMapMarkersSSE.dll).", L"Error", MB_OK | MB_ICONERROR);
exit(EXIT_FAILURE);
}
}
SetINISettings();
EventListener::Install();
} else if (message->type == MessagingInterface::kPostPostLoad) {
SKSE::GetModCallbackEventSource()->AddEventSink(EventListener::GetSingleton());
} else if (message->type == MessagingInterface::kDataLoaded) {
const auto dataHandler = RE::TESDataHandler::GetSingleton();
if (dataHandler) {
if (!dataHandler->LookupLoadedModByName("Update.esm")) {
MessageBoxW(NULL, L"Update.esm is not loaded!", L"Error", MB_OK | MB_ICONERROR);
exit(EXIT_FAILURE);
}
if (!dataHandler->LookupLoadedModByName("Enderal - Forgotten Stories.esm")) {
MessageBoxW(NULL, L"Enderal - Forgotten Stories.esm is not loaded!", L"Error", MB_OK | MB_ICONERROR);
exit(EXIT_FAILURE);
}
}
bool bScripts = RE::BSScript::Internal::VirtualMachine::GetSingleton()->TypeIsValid("PRKF__00E_CraftQuestPotionPe_0300146D");
bool bSounds = RE::BSResourceNiBinaryStream("sound/fx/enderal/laughingchild.wav").good();
bool bVoices = RE::BSResourceNiBinaryStream("sound/voice/enderal - forgotten stories.esm/vt_calia/fs_mq18c__0002a4ed_1.fuz").good();
bool bMeshes = RE::BSResourceNiBinaryStream("meshes/enderal/loadscreenart/loadscreenundercity.nif").good();
bool bTextures = RE::BSResourceNiBinaryStream("textures/enderal/forgottenstories/theriantrophist/theriantrophistrecipe.dds").good();
bool bInterface = RE::BSResourceNiBinaryStream("interface/00e_heromenu.swf").good();
if (!bScripts || !bSounds || !bVoices || !bMeshes || !bTextures || !bInterface) {
MessageBoxW(NULL, L"One or more of Enderal's BSA archives are not loaded. Make sure Enderal - Forgotten Stories.esm is enabled and revalidate your files.", L"Error", MB_OK | MB_ICONERROR);
exit(EXIT_FAILURE);
}
CheckIncompatibleMods();
} else if (message->type == MessagingInterface::kPreLoadGame) {
//
} else if ((message->type == MessagingInterface::kPostLoadGame && message->data) || message->type == MessagingInterface::kNewGame) {
NewGameCount(true);
}
});
}
}
SKSEPluginLoad(const LoadInterface* skse) {
GetLoadInterface(skse);
InitializeLogging();
auto* plugin = PluginDeclaration::GetSingleton();
auto version = plugin->GetVersion();
logger::info("{} {} is loading...", plugin->GetName(), version);
LoadINI(&g_settings, "Data/SKSE/Plugins/EnderalSE.ini");
Init(skse);
InitializeMessaging();
GetPapyrusInterface()->Register(Papyrus::Bind);
if (!IsVR()) {
if (g_settings.at("FlatMapMarkers")) {
logger::info("Initializing Flat Map Markers...");
SKSE::AllocTrampoline(1 << 4);
FlatMapMarkers::Install();
}
if (g_settings.at("StayAtSystemPage")) {
logger::info("Initializing Stay At The System Page...");
JournalMenuEx::InstallHooks();
}
}
logger::info("{} has finished loading.", plugin->GetName());
return true;
}