127 lines
5.0 KiB
C++
127 lines
5.0 KiB
C++
|
#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 ((std::filesystem::exists("Data\\Dawnguard.esm") && std::filesystem::file_size("Data\\Dawnguard.esm") > 1000000) || (std::filesystem::exists("Data\\Dragonborn.esm") && std::filesystem::file_size("Data\\Dragonborn.esm") > 1000000) || (std::filesystem::exists("Data\\HearthFires.esm") && std::filesystem::file_size("Data\\HearthFires.esm") > 1000000) || (std::filesystem::exists("Data\\Update.esm") && std::filesystem::file_size("Data\\Update.esm") > 1000000)) {
|
||
|
MessageBoxW(NULL, L"Skyrim DLCs are incompatible with Enderal.", L"Error", MB_OK | MB_ICONERROR);
|
||
|
exit(EXIT_FAILURE);
|
||
|
}
|
||
|
if (std::filesystem::exists("Data\\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);
|
||
|
}
|
||
|
if (std::filesystem::exists("Data\\ccBGSSSE001-Fish.esm") || std::filesystem::exists("Data\\ccBGSSSE025-AdvDSGS.esm") || std::filesystem::exists("Data\\ccBGSSSE037-Curios.esl") || std::filesystem::exists("Data\\ccQDRSSE001-SurvivalMode.esl")) {
|
||
|
MessageBoxW(NULL, L"Creation Club mods are incompatible with Enderal.", L"Error", MB_OK | MB_ICONERROR);
|
||
|
exit(EXIT_FAILURE);
|
||
|
}
|
||
|
|
||
|
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) {
|
||
|
//
|
||
|
} 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);
|
||
|
}
|
||
|
}
|
||
|
const auto vm = RE::BSScript::Internal::VirtualMachine::GetSingleton();
|
||
|
if (!vm->TypeIsValid("_00e_questfunctions")) {
|
||
|
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 (skse->RuntimeVersion() != RUNTIME_VR_1_4_15 && skse->RuntimeVersion() != RUNTIME_LATEST_VR && 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;
|
||
|
}
|