2022-07-31 18:55:11 +00:00
# include "EventListener.h"
# include "Util.h"
# include "Papyrus.h"
2023-12-21 11:41:08 +00:00
# include "Patches/FlatMapMarkers.h"
# include "Patches/StayAtSystemPage.h"
# include "Patches/MapMarkerPlacement.h"
# include "Patches/AchievementFix.h"
# include "Patches/BinkInterruptPatch.h"
# include "Patches/DialogueMenuPatch.h"
2023-12-15 20:39:41 +00:00
# include "Patches/TweenMenuPatch.h"
2023-12-19 15:58:36 +00:00
# include "Patches/HeroMenuPatch.h"
2023-12-20 15:27:06 +00:00
# include "Patches/HUDMenuPatch.h"
2022-07-31 18:55:11 +00:00
using namespace SKSE ;
static std : : map < std : : string , bool > g_settings {
{ " FlatMapMarkers " , true } ,
2023-12-10 20:10:58 +00:00
{ " StayAtSystemPage " , true } ,
2023-12-11 00:43:01 +00:00
{ " MapMarkerPlacementFixes " , true } ,
2023-12-11 08:53:57 +00:00
{ " AchievementFix " , true } ,
{ " VideoInterruptPatch " , true }
2022-07-31 18:55:11 +00:00
} ;
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 ) {
2022-09-29 19:41:38 +00:00
2022-07-31 18:55:11 +00:00
if ( message - > type = = MessagingInterface : : kPostLoad ) {
if ( g_settings . at ( " StayAtSystemPage " ) ) {
if ( const auto pluginInfo = GetLoadInterface ( ) - > GetPluginInfo ( " StayAtSystemPage " ) ; pluginInfo ) {
2023-12-11 01:44:41 +00:00
MessageBoxW ( NULL , L " Stay At The System Page is already included in Enderal, please, disable it. " , L " Enderal SE Error " , MB_OK | MB_ICONERROR ) ;
2022-07-31 18:55:11 +00:00
exit ( EXIT_FAILURE ) ;
}
}
if ( g_settings . at ( " FlatMapMarkers " ) ) {
if ( const auto pluginInfo = GetLoadInterface ( ) - > GetPluginInfo ( " FlatMapMarkersSSE " ) ; pluginInfo ) {
2023-12-11 01:44:41 +00:00
MessageBoxW ( NULL , L " Flat Map Markers is already included in Enderal, please, disable it (remove file Data \\ SKSE \\ Plugins \\ FlatMapMarkersSSE.dll). " , L " Enderal SE Error " , MB_OK | MB_ICONERROR ) ;
2022-07-31 18:55:11 +00:00
exit ( EXIT_FAILURE ) ;
}
}
2023-12-10 20:10:58 +00:00
if ( g_settings . at ( " MapMarkerPlacementFixes " ) ) {
logger : : info ( " Initializing map market placement fixes... " ) ;
MapMarkerPlacement : : Install ( ) ;
}
2022-07-31 18:55:11 +00:00
} else if ( message - > type = = MessagingInterface : : kDataLoaded ) {
2023-12-15 08:21:50 +00:00
if ( GetLoadInterface ( ) - > RuntimeVersion ( ) . minor ( ) > 5 ) {
RE : : INIPrefSettingCollection : : GetSingleton ( ) - > GetSetting ( " bFreebiesSeen:General " ) - > data . b = true ;
if ( GetLoadInterface ( ) - > RuntimeVersion ( ) . minor ( ) > 6 | | GetLoadInterface ( ) - > RuntimeVersion ( ) . patch ( ) > = 1130 ) {
RE : : INIPrefSettingCollection : : GetSingleton ( ) - > GetSetting ( " bUpsellOwned:General " ) - > data . b = true ;
}
}
2022-07-31 18:55:11 +00:00
const auto dataHandler = RE : : TESDataHandler : : GetSingleton ( ) ;
if ( dataHandler ) {
if ( ! dataHandler - > LookupLoadedModByName ( " Update.esm " ) ) {
2023-12-11 01:44:41 +00:00
MessageBoxW ( NULL , L " Update.esm is not loaded! " , L " Enderal SE Error " , MB_OK | MB_ICONERROR ) ;
2022-07-31 18:55:11 +00:00
exit ( EXIT_FAILURE ) ;
}
if ( ! dataHandler - > LookupLoadedModByName ( " Enderal - Forgotten Stories.esm " ) ) {
2023-12-11 01:44:41 +00:00
MessageBoxW ( NULL , L " Enderal - Forgotten Stories.esm is not loaded! " , L " Enderal SE Error " , MB_OK | MB_ICONERROR ) ;
2022-07-31 18:55:11 +00:00
exit ( EXIT_FAILURE ) ;
}
}
2022-09-01 10:59:36 +00:00
2022-09-29 19:41:38 +00:00
if ( ! RE : : BSScript : : Internal : : VirtualMachine : : GetSingleton ( ) - > TypeIsValid ( " UI " ) ) {
RE : : DebugMessageBox ( " Unable to detect SKSE scripts, make sure SKSE is properly installed. " ) ;
}
2022-09-01 10:59:36 +00:00
bool bScripts = RE : : BSScript : : Internal : : VirtualMachine : : GetSingleton ( ) - > TypeIsValid ( " PRKF__00E_CraftQuestPotionPe_0300146D " ) ;
2022-09-29 19:41:38 +00:00
bool bInterface = RE : : BSResourceNiBinaryStream ( " interface/00e_heromenu.swf " ) . good ( ) ;
if ( ! bScripts | | ! bInterface ) {
RE : : DebugMessageBox ( " E - Misc.bsa is not loaded or is outdated. Make sure Enderal - Forgotten Stories.esm is enabled and revalidate your files. " ) ;
}
2022-09-01 10:59:36 +00:00
bool bSounds = RE : : BSResourceNiBinaryStream ( " sound/fx/enderal/laughingchild.wav " ) . good ( ) ;
2022-09-29 19:41:38 +00:00
if ( ! bSounds ) {
RE : : DebugMessageBox ( " E - Sounds.bsa is not loaded. Make sure Enderal - Forgotten Stories.esm is enabled and revalidate your files. " ) ;
}
2022-09-01 10:59:36 +00:00
bool bVoices = RE : : BSResourceNiBinaryStream ( " sound/voice/enderal - forgotten stories.esm/vt_calia/fs_mq18c__0002a4ed_1.fuz " ) . good ( ) ;
2022-09-29 19:41:38 +00:00
if ( ! bVoices ) {
RE : : DebugMessageBox ( " L - Voices.bsa is not loaded. Make sure Enderal - Forgotten Stories.esm is enabled and revalidate your files. " ) ;
2022-07-31 18:55:11 +00:00
}
2022-09-01 10:59:36 +00:00
2022-09-29 19:41:38 +00:00
bool bMeshes = RE : : BSResourceNiBinaryStream ( " meshes/enderal/loadscreenart/loadscreenundercity.nif " ) . good ( ) ;
if ( ! bMeshes ) {
RE : : DebugMessageBox ( " E - Meshes.bsa is not loaded. Make sure Enderal - Forgotten Stories.esm is enabled and revalidate your files. " ) ;
}
2022-07-31 18:55:11 +00:00
CheckIncompatibleMods ( ) ;
2022-09-29 19:41:38 +00:00
2022-07-31 18:55:11 +00:00
} else if ( ( message - > type = = MessagingInterface : : kPostLoadGame & & message - > data ) | | message - > type = = MessagingInterface : : kNewGame ) {
NewGameCount ( true ) ;
}
} ) ;
}
}
SKSEPluginLoad ( const LoadInterface * skse ) {
2022-09-30 11:46:36 +00:00
std : : string filenames [ 4 ] = {
" fs.dll " ,
" fs_se.dll " ,
" fs_skse_functions.dll " ,
" FlatMapMarkersEnderal.dll "
} ;
for ( int i = 0 ; i < 4 ; i + + ) {
if ( std : : filesystem : : exists ( std : : format ( " Data \\ SKSE \\ Plugins \\ {} " , filenames [ i ] ) ) ) {
2023-12-11 01:44:41 +00:00
MessageBoxA ( NULL , std : : format ( " Found a leftover file from a previous version of Enderal SE. Please, delete Data \\ SKSE \\ Plugins \\ {}. " , filenames [ i ] ) . c_str ( ) , " Enderal SE Error " , MB_OK | MB_ICONERROR ) ;
2022-09-30 11:46:36 +00:00
exit ( EXIT_FAILURE ) ;
}
}
2022-09-29 19:41:38 +00:00
if ( DataFileExists ( " Dawnguard.esm " ) | | DataFileExists ( " Dragonborn.esm " ) | | DataFileExists ( " HearthFires.esm " ) | | DataFileExists ( " Update.esm " ) ) {
2023-12-11 01:44:41 +00:00
MessageBoxW ( NULL , L " Skyrim DLCs are incompatible with Enderal. " , L " Enderal SE Error " , MB_OK | MB_ICONERROR ) ;
2022-09-29 19:41:38 +00:00
exit ( EXIT_FAILURE ) ;
}
if ( DataFileExists ( " Unofficial Skyrim Special Edition Patch.esp " ) ) {
2023-12-11 01:44:41 +00:00
MessageBoxW ( NULL , L " Unofficial Skyrim Special Edition Patch is incompatible with Enderal. " , L " Enderal SE Error " , MB_OK | MB_ICONERROR ) ;
exit ( EXIT_FAILURE ) ;
}
if ( ! DataFileExists ( " Enderal - Forgotten Stories.esm " ) ) {
MessageBoxW ( NULL , L " Enderal - Forgotten Stories.esm is not loaded! " , L " Enderal SE Error " , MB_OK | MB_ICONERROR ) ;
2022-09-29 19:41:38 +00:00
exit ( EXIT_FAILURE ) ;
}
CheckCCMods ( ) ;
2022-07-31 18:55:11 +00:00
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 ( ) ;
2023-12-15 08:21:50 +00:00
RE : : INISettingCollection : : GetSingleton ( ) - > GetSetting ( " sIntroSequence:General " ) - > data . s = nullptr ;
RE : : INISettingCollection : : GetSingleton ( ) - > GetSetting ( " bModManagerMenuEnabled:General " ) - > data . b = false ;
2023-12-11 01:44:41 +00:00
2023-12-15 06:26:39 +00:00
EventListener : : Install ( ) ;
2022-09-29 19:41:38 +00:00
2022-07-31 18:55:11 +00:00
GetPapyrusInterface ( ) - > Register ( Papyrus : : Bind ) ;
2023-12-15 06:26:39 +00:00
DialogueMenuPatch : : Install ( ) ;
2023-12-19 15:58:36 +00:00
HeroMenuPatch : : Install ( ) ;
2023-12-15 20:39:41 +00:00
TweenMenuPatch : : Install ( ) ;
2023-12-20 15:27:06 +00:00
HUDMenuPatch : : Install ( ) ;
2023-12-15 06:26:39 +00:00
2023-12-11 08:53:57 +00:00
if ( g_settings . at ( " VideoInterruptPatch " ) ) {
logger : : info ( " Making videos interruptible... " ) ;
BinkInterruptPatch : : Install ( ) ;
}
2023-12-11 00:43:01 +00:00
if ( g_settings . at ( " AchievementFix " ) ) {
logger : : info ( " Patching achievements... " ) ;
AchievementFix : : Install ( ) ;
}
2023-12-11 01:44:41 +00:00
if ( ! REL : : Module : : IsVR ( ) ) {
2022-09-07 22:58:18 +00:00
if ( g_settings . at ( " FlatMapMarkers " ) ) {
logger : : info ( " Initializing Flat Map Markers... " ) ;
FlatMapMarkers : : Install ( ) ;
}
if ( g_settings . at ( " StayAtSystemPage " ) ) {
logger : : info ( " Initializing Stay At The System Page... " ) ;
JournalMenuEx : : InstallHooks ( ) ;
}
2022-07-31 18:55:11 +00:00
}
logger : : info ( " {} has finished loading. " , plugin - > GetName ( ) ) ;
return true ;
}