# pragma once
# include "CheckInvalidForms.h"
# include <SimpleIni.h>
# include <regex>
inline const SKSE : : LoadInterface * GetLoadInterface ( const SKSE : : LoadInterface * loadInterface = nullptr )
{
const static SKSE : : LoadInterface * singleton ;
if ( loadInterface ) {
singleton = loadInterface ;
}
return singleton ;
}
inline uint8_t NewGameCount ( bool increment = false )
{
static uint8_t g_NewGameStarted = 0 ;
if ( increment ) {
g_NewGameStarted + + ;
}
return g_NewGameStarted ;
}
inline bool IsSE ( )
{
return GetLoadInterface ( ) - > RuntimeVersion ( ) . minor ( ) = = 5 ;
}
inline bool IsVR ( )
{
return GetLoadInterface ( ) - > RuntimeVersion ( ) = = SKSE : : RUNTIME_VR_1_4_15 | | GetLoadInterface ( ) - > RuntimeVersion ( ) = = SKSE : : RUNTIME_LATEST_VR ;
}
inline void SetINISettings ( )
{
auto * setting = RE : : INIPrefSettingCollection : : GetSingleton ( ) - > GetSetting ( " bFreebiesSeen:General " ) ;
if ( setting & & ! setting - > GetBool ( ) ) {
setting - > data . b = true ;
RE : : INIPrefSettingCollection : : GetSingleton ( ) - > WriteSetting ( setting ) ;
}
setting = RE : : INISettingCollection : : GetSingleton ( ) - > GetSetting ( " bInvalidateOlderFiles:Archive " ) ;
if ( setting & & ! setting - > GetBool ( ) ) {
setting - > data . b = true ;
RE : : INISettingCollection : : GetSingleton ( ) - > WriteSetting ( setting ) ;
}
setting = RE : : INISettingCollection : : GetSingleton ( ) - > GetSetting ( " bModManagerMenuEnabled:General " ) ;
if ( setting & & setting - > GetBool ( ) ) {
setting - > data . b = false ;
RE : : INISettingCollection : : GetSingleton ( ) - > WriteSetting ( setting ) ;
}
}
inline void CheckIncompatibleMods ( )
{
bool bPrinted = false ;
if ( std : : filesystem : : exists ( " Data \\ SKSE \\ Plugins \\ EnderalVersion.ini " ) ) {
CSimpleIniA ini ;
ini . SetUnicode ( false ) ;
ini . SetMultiKey ( false ) ;
ini . LoadFile ( " Data/SKSE/Plugins/EnderalVersion.ini " ) ;
const char * version = ini . GetValue ( " " , " version " , " 2.0.x " ) ;
std : : regex version_expr ( " ^[ \\ d \\ .]+$ " ) ;
if ( std : : regex_match ( version , version_expr ) ) {
RE : : ConsoleLog : : GetSingleton ( ) - > Print ( std : : format ( " Loaded SureAI's Enderal: Forgotten Stories | Special Edition v{} by Eddoursul and contributors " , version ) . c_str ( ) ) ;
bPrinted = true ;
}
}
if ( ! bPrinted ) {
RE : : ConsoleLog : : GetSingleton ( ) - > Print ( " Loaded SureAI's Enderal: Forgotten Stories | Special Edition v2.0.x by Eddoursul and contributors " ) ;
}
CheckBlacklist ( ) ;
CheckWorldspaces ( ) ;
CheckUnconvertedMap ( ) ;
CheckSkyrimCells ( ) ;
CheckEnderalCells ( ) ;
CheckEnderalContainers ( ) ;
CheckEnderalNPCs ( ) ;
}
inline void LoadINI ( std : : map < std : : string , bool > * settings , const char * iniPath )
{
for ( auto it = settings - > begin ( ) ; it ! = settings - > end ( ) ; it + + ) {
logger : : info ( " [DEFAULT] {} = {} " , it - > first , it - > second ) ;
}
if ( ! std : : filesystem : : exists ( iniPath ) ) {
logger : : warn ( " {} does not exist, using default values. " , iniPath ) ;
return ;
}
try {
CSimpleIniA ini ;
ini . SetUnicode ( false ) ;
ini . SetMultiKey ( false ) ;
ini . LoadFile ( iniPath ) ;
std : : list < CSimpleIniA : : Entry > keysList ;
ini . GetAllKeys ( " " , keysList ) ;
bool bUpdateINI = false ;
for ( auto it = settings - > begin ( ) ; it ! = settings - > end ( ) ; it + + ) {
bool bExists = false ;
for ( const auto & k : keysList ) {
if ( it - > first = = k . pItem ) {
settings - > insert_or_assign ( k . pItem , ini . GetBoolValue ( " " , k . pItem , settings - > at ( k . pItem ) ) ) ;
logger : : info ( " [INI] {} = {} " , k . pItem , settings - > at ( k . pItem ) ) ;
bExists = true ;
break ;
}
}
if ( ! bExists ) {
ini . SetBoolValue ( " " , it - > first . c_str ( ) , it - > second ) ;
bUpdateINI = true ;
}
}
if ( bUpdateINI ) {
logger : : info ( " New settings detected, adding to ArtifactTracker.ini " ) ;
ini . SaveFile ( iniPath ) ;
}
} catch ( const std : : exception & e ) {
logger : : error ( " {} " , e . what ( ) ) ;
}
}