diff --git a/source/Launcher/Enderal Launcher.au3 b/source/Launcher/Enderal Launcher.au3 new file mode 100644 index 000000000..821028b7e --- /dev/null +++ b/source/Launcher/Enderal Launcher.au3 @@ -0,0 +1,1517 @@ +#NoTrayIcon +#Region ;**** Directives created by AutoIt3Wrapper_GUI **** +#AutoIt3Wrapper_Icon=enderal.ico +#AutoIt3Wrapper_Res_File_Add=background.jpg, RT_RCDATA, BACKGROUND +#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +; ============================================ +; Constants and Global Variables +; ============================================ +Global Const $LAUNCHER_WIDTH = 945 +Global Const $LAUNCHER_HEIGHT = 578 +Global Const $SETTINGS_MARGIN = 50 +Global Const $SETTINGS_WIDTH = $LAUNCHER_WIDTH - ($SETTINGS_MARGIN * 2) +Global Const $SETTINGS_HEIGHT = $LAUNCHER_HEIGHT - ($SETTINGS_MARGIN * 2) +Global Const $TAB_LEFT_MARGIN = 42 +Global Const $TAB_TOP_MARGIN = 74 +Global Const $TAB_ROW_HEIGHT = 42 +Global Const $LOCALAPPDATA = EnvGet("LOCALAPPDATA") +Global Const $REG_KEY = "HKEY_CURRENT_USER\Software\SureAI\EnderalSE" +Global Const $REG_INSTALL_PATH = "Install_Path" +Global Const $REG_EXE_PATH = "Exe_Path" +Global Const $REG_START_STEAM = "Start_Steam" +Global Const $AA_TAA = "TAA (Best quality)" +Global Const $AA_FXAA = "FXAA (Low)" +Global Const $AA_OFF = "Off (Best performance)" +Global $PLUGINS_DIR = "" +Global $PLUGINS_FILE = "" +Global $DOCUMENTS_DIR = "" +Global $ENDERAL_INI = "" +Global $ENDERAL_PREFS_INI = "" +Global $LAUNCHER_DIR = @ScriptDir + +; GUI handles +Global $hMainGUI, $hSettingsGUI +Global $btnPlay, $btnSettings, $btnExit +Global $btnClose, $btnMinimize +Global $lblCredits, $lblWiki, $lblSupport, $lblChangelog +Global $lblMinimizeShadow, $lblCloseShadow +Global $lblCreditsShadow, $lblWikiShadow, $lblSupportShadow, $lblChangelogShadow +Global $hBackgroundPic = 0 + +; Settings controls +Global $tabSettings +Global $btnSave, $btnCancel + +; Display tab controls +Global $lblResolution, $cmbResolution +Global $lblAntialiasing, $cmbAntialiasing +Global $chkWindowed +Global $btnLow, $btnMedium, $btnHigh, $btnUltra + +; Rendering tab controls +Global $chk64bitRT, $chkSSAO, $chkVolumetricLighting, $chkSSR + +; SSE Display Tweaks controls +Global $grpSSEDisplayTweaks, $chkSSEDisplayTweaks +Global $lblFramerateLimit, $sldFramerateLimit, $lblFramerateLimitValue + +; Controls tab controls +Global $chkController, $chkVibration +Global $chkStartSteam +Global $grpIniFiles, $btnOpenEnderalIni, $btnOpenEnderalPrefsIni, $btnOpenCustomIni, $btnOpenModIni, $btnOpenSavegames + +; Steam version detection +Global $bIsSteamVersion = False + +; ============================================ +; Helper Functions +; ============================================ +Func DirExists($path) + Return FileExists($path) And StringInStr(FileGetAttrib($path), "D") +EndFunc + +Func SetCheckboxState($ctrl, $value, $checkedValue = "1") + If $value = $checkedValue Then + GUICtrlSetState($ctrl, $GUI_CHECKED) + Else + GUICtrlSetState($ctrl, $GUI_UNCHECKED) + EndIf +EndFunc + +Func GetIniFileName($filePath) + Return StringRegExpReplace($filePath, ".*\\", "") +EndFunc + +Func GetCustomIniPath() + ; Returns the path to EnderalCustom.ini or SkyrimCustom.ini based on current INI mode + Local $iniFileName = GetIniFileName($ENDERAL_INI) + If StringInStr($iniFileName, "Enderal") Then + Return $DOCUMENTS_DIR & "\EnderalCustom.ini" + Else + Return $DOCUMENTS_DIR & "\SkyrimCustom.ini" + EndIf +EndFunc + +Func GetCustomIniFileName() + ; Returns just the filename (EnderalCustom.ini or SkyrimCustom.ini) + Local $iniFileName = GetIniFileName($ENDERAL_INI) + If StringInStr($iniFileName, "Enderal") Then + Return "EnderalCustom.ini" + Else + Return "SkyrimCustom.ini" + EndIf +EndFunc + +Func GetModIniFileName() + ; Returns just the filename for the Mod INI + Return "Enderal - Forgotten Stories.ini" +EndFunc + +Func GetDataIniPath() + ; Returns the path to Data\Enderal - Forgotten Stories.ini + Return $LAUNCHER_DIR & "\Data\" & GetModIniFileName() +EndFunc + +Func IniReadWithCustom($section, $key, $default) + ; Read with precedence: Data INI > Custom INI > Base INI + ; 1. Check Data\Enderal - Forgotten Stories.ini first (highest priority) + Local $dataIniPath = GetDataIniPath() + If FileExists($dataIniPath) Then + Local $dataValue = IniRead($dataIniPath, $section, $key, "") + If $dataValue <> "" Then + Return $dataValue + EndIf + EndIf + + ; 2. Check custom INI (EnderalCustom.ini or SkyrimCustom.ini) + Local $customIniPath = GetCustomIniPath() + If FileExists($customIniPath) Then + Local $customValue = IniRead($customIniPath, $section, $key, "") + If $customValue <> "" Then + Return $customValue + EndIf + EndIf + + ; 3. Fall back to base INI + Return IniRead($ENDERAL_INI, $section, $key, $default) +EndFunc + +Func IniWriteWithCustom($section, $key, $value) + ; Write with precedence: Data INI > Custom INI > Base INI + ; 1. Check Data\Enderal - Forgotten Stories.ini first (highest priority) + Local $dataIniPath = GetDataIniPath() + If FileExists($dataIniPath) Then + Local $dataValue = IniRead($dataIniPath, $section, $key, "") + If $dataValue <> "" Then + Return IniWrite($dataIniPath, $section, $key, $value) + EndIf + EndIf + + ; 2. Check custom INI (EnderalCustom.ini or SkyrimCustom.ini) + Local $customIniPath = GetCustomIniPath() + If FileExists($customIniPath) Then + Local $customValue = IniRead($customIniPath, $section, $key, "") + If $customValue <> "" Then + Return IniWrite($customIniPath, $section, $key, $value) + EndIf + EndIf + + ; 3. Fall back to base INI + Return IniWrite($ENDERAL_INI, $section, $key, $value) +EndFunc + +Func UpdateCustomIniButtonState() + ; Enable or disable the custom INI button based on file existence + Local $customIniPath = GetCustomIniPath() + Local $customIniName = GetCustomIniFileName() + If FileExists($customIniPath) Then + GUICtrlSetData($btnOpenCustomIni, $customIniName) + GUICtrlSetState($btnOpenCustomIni, $GUI_ENABLE) + Else + GUICtrlSetData($btnOpenCustomIni, $customIniName & " (N/A)") + GUICtrlSetState($btnOpenCustomIni, $GUI_DISABLE) + EndIf +EndFunc + +Func UpdateModIniButtonState() + ; Enable or disable the Mod INI button based on file existence + Local $modIniPath = GetDataIniPath() + Local $modIniName = GetModIniFileName() + If FileExists($modIniPath) Then + GUICtrlSetData($btnOpenModIni, $modIniName) + GUICtrlSetState($btnOpenModIni, $GUI_ENABLE) + Else + GUICtrlSetData($btnOpenModIni, $modIniName & " (N/A)") + GUICtrlSetState($btnOpenModIni, $GUI_DISABLE) + EndIf +EndFunc + +Func RunWithAssociation($filePath) + ; Get file extension + Local $ext = StringRegExpReplace($filePath, ".*(\.[^.]+)$", "$1") + If $ext = $filePath Then Return False + + ; Get file type from registry + Local $fileType = RegRead("HKEY_CLASSES_ROOT\" & $ext, "") + If @error Or $fileType = "" Then + ; Fallback to notepad if no association found + Run('notepad.exe "' & $filePath & '"') + Return True + EndIf + + ; Get command for opening this file type + Local $command = RegRead("HKEY_CLASSES_ROOT\" & $fileType & "\shell\open\command", "") + If @error Or $command = "" Then + ; Fallback to notepad if no command found + Run('notepad.exe "' & $filePath & '"') + Return True + EndIf + + ; Replace %1 or %L with the file path, handle quoted and unquoted variants + If StringInStr($command, "%1") Or StringInStr($command, "%L") Then + $command = StringReplace($command, '"%1"', '"' & $filePath & '"') + $command = StringReplace($command, "%1", '"' & $filePath & '"') + $command = StringReplace($command, '"%L"', '"' & $filePath & '"') + $command = StringReplace($command, "%L", '"' & $filePath & '"') + Else + ; Append file path if no placeholder + $command = $command & ' "' & $filePath & '"' + EndIf + + Run($command) + Return True +EndFunc + +Func WriteCheckboxToIni($ctrl, $file, $section, $key, $checkedVal = "1", $uncheckedVal = "0") + If BitAND(GUICtrlRead($ctrl), $GUI_CHECKED) Then + IniWrite($file, $section, $key, $checkedVal) + Else + IniWrite($file, $section, $key, $uncheckedVal) + EndIf +EndFunc + +Func WriteCheckboxWithCustom($ctrl, $section, $key, $checkedVal = "1", $uncheckedVal = "0") + ; Write to custom INI if key exists there, otherwise to base INI ($ENDERAL_INI) + If BitAND(GUICtrlRead($ctrl), $GUI_CHECKED) Then + IniWriteWithCustom($section, $key, $checkedVal) + Else + IniWriteWithCustom($section, $key, $uncheckedVal) + EndIf +EndFunc + +; ============================================ +; Version Detection Functions +; ============================================ +Func GetSkyrimVersion() + Local $exePath = $LAUNCHER_DIR & "\SkyrimSE.exe" + If Not FileExists($exePath) Then Return "" + + ; Try FileVersion and ProductVersion first (older versions use these) + Local $version = FileGetVersion($exePath, "FileVersion") + If @error Or $version = "" Or $version = "1.0.0.0" Then + $version = FileGetVersion($exePath, "ProductVersion") + EndIf + ; Fall back to standard version + If @error Or $version = "" Or $version = "1.0.0.0" Then + $version = FileGetVersion($exePath) + EndIf + If @error Or $version = "" Or $version = "1.0.0.0" Then Return "" + + ; Return only major.minor.build (strip revision) + Local $parts = StringSplit($version, ".") + If $parts[0] >= 3 Then + Return $parts[1] & "." & $parts[2] & "." & $parts[3] + EndIf + Return $version +EndFunc + +Func GetBaseDirectoryName() + ; Returns "Skyrim Special Edition GOG" if Galaxy64.dll exists, otherwise "Skyrim Special Edition" + If FileExists($LAUNCHER_DIR & "\Galaxy64.dll") Then + Return "Skyrim Special Edition GOG" + Else + Return "Skyrim Special Edition" + EndIf +EndFunc + +Func GetEnderalBaseDirectoryName() + ; Returns "Enderal Special Edition GOG" if Galaxy64.dll exists, otherwise "Enderal Special Edition" + If FileExists($LAUNCHER_DIR & "\Galaxy64.dll") Then + Return "Enderal Special Edition GOG" + Else + Return "Enderal Special Edition" + EndIf +EndFunc + +Func GetEnderalVersion() + ; First try to read from EnderalVersion.ini (no section header, just key=value) + Local $versionIni = $LAUNCHER_DIR & "\Data\SKSE\Plugins\EnderalVersion.ini" + If FileExists($versionIni) Then + Local $content = FileRead($versionIni) + ; Match line starting with "version" followed by "=" and capture until end of line + Local $match = StringRegExp($content, "(?im)^version\s*=\s*(.+)$", 1) + If Not @error And UBound($match) > 0 Then + Return StringStripWS($match[0], 3) + EndIf + EndIf + + ; Check if Enderal ESM exists (outdated installation) + Local $esmPath = $LAUNCHER_DIR & "\Data\Enderal - Forgotten Stories.esm" + If FileExists($esmPath) Then Return "outdated" + + ; Neither file exists + Return "" +EndFunc + +; ============================================ +; Main Entry Point +; ============================================ +Main() + +Func Main() + ; Check if SkyrimRedirector is installed + Local $redirectorDll = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SkyrimRedirector.dll" + Local $redirectorIni = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SkyrimRedirector.ini" + + If FileExists($redirectorDll) Then + If FileExists($redirectorIni) Then + ; Read paths from SkyrimRedirector.ini + $ENDERAL_INI = IniRead($redirectorIni, "Redirection", "Ini", "") + $ENDERAL_PREFS_INI = IniRead($redirectorIni, "Redirection", "PrefsIni", "") + $PLUGINS_FILE = IniRead($redirectorIni, "Redirection", "Plugins", "") + + ; Derive directories from file paths + $DOCUMENTS_DIR = StringRegExpReplace($ENDERAL_INI, "\\[^\\]+$", "") + $PLUGINS_DIR = StringRegExpReplace($PLUGINS_FILE, "\\[^\\]+$", "") + Else + ; SkyrimRedirector.dll exists without INI - create INI with Enderal defaults + Local $baseDir = GetEnderalBaseDirectoryName() + + ; Set plugins directory path + $PLUGINS_DIR = $LOCALAPPDATA & "\" & $baseDir + $PLUGINS_FILE = $PLUGINS_DIR & "\plugins.txt" + + ; Get Documents folder path with Enderal INI names + $DOCUMENTS_DIR = GetDocumentsPath() & "\My Games\" & $baseDir + $ENDERAL_INI = $DOCUMENTS_DIR & "\Enderal.ini" + $ENDERAL_PREFS_INI = $DOCUMENTS_DIR & "\EnderalPrefs.ini" + + ; Create SkyrimRedirector.ini with default paths + IniWrite($redirectorIni, "Redirection", "Ini", $ENDERAL_INI) + IniWrite($redirectorIni, "Redirection", "PrefsIni", $ENDERAL_PREFS_INI) + IniWrite($redirectorIni, "Redirection", "Plugins", $PLUGINS_FILE) + EndIf + Else + ; No SkyrimRedirector - use Skyrim default paths + Local $baseDir = GetBaseDirectoryName() + + ; Set plugins directory path + $PLUGINS_DIR = $LOCALAPPDATA & "\" & $baseDir + $PLUGINS_FILE = $PLUGINS_DIR & "\plugins.txt" + + ; Get Documents folder path + $DOCUMENTS_DIR = GetDocumentsPath() & "\My Games\" & $baseDir + $ENDERAL_INI = $DOCUMENTS_DIR & "\Skyrim.ini" + $ENDERAL_PREFS_INI = $DOCUMENTS_DIR & "\SkyrimPrefs.ini" + EndIf + + ; Perform startup checks + StartupChecks() + + ; Auto-start Steam if enabled (Steam version only) + If $bIsSteamVersion Then + Local $startSteam = RegRead($REG_KEY, $REG_START_STEAM) + If Not @error And $startSteam = 1 Then + ; Check if Steam is already running + If Not ProcessExists("steam.exe") Then + ShellExecute("steam://open/main") + EndIf + EndIf + EndIf + + ; Initialize GDI+ + _GDIPlus_Startup() + + ; Create and show main window + CreateMainWindow() + + ; Create settings window (hidden) + CreateSettingsWindow() + + ; Register message handler for dragging + GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN") + + ; Register message handler for slider updates + GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") + + ; Main loop + MainLoop() + + ; Cleanup + _GDIPlus_Shutdown() +EndFunc + +; ============================================ +; Window Drag Handler +; ============================================ +Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) + If $hWnd = $hMainGUI Then + _SendMessage($hMainGUI, $WM_SYSCOMMAND, 0xF012, 0) + EndIf + Return $GUI_RUNDEFMSG +EndFunc + +Func WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam) + If $lParam = GUICtrlGetHandle($sldFramerateLimit) Then + GUICtrlSetData($lblFramerateLimitValue, GUICtrlRead($sldFramerateLimit)) + EndIf + Return $GUI_RUNDEFMSG +EndFunc + +; ============================================ +; Startup Checks +; ============================================ +Func StartupChecks() + ; Check if Enderal is installed + If Not FileExists($LAUNCHER_DIR & "\Data\Enderal - Forgotten Stories.esm") Then + MsgBox(16, "Error", "Unable to find Enderal - Forgotten Stories.esm (Enderal SE is not installed?)") + Exit + EndIf + + If @OSVersion = 'WIN_10' Or @OSVersion = 'WIN_11' Then DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext" , "HWND", "DPI_AWARENESS_CONTEXT" -2) + If @OSVersion = 'WIN_81' Then DllCall("User32.dll", "bool", "SetProcessDPIAware") + + ; Detect Steam version by checking for steam_api64.dll + $bIsSteamVersion = FileExists($LAUNCHER_DIR & "\steam_api64.dll") + + CheckRegistryPaths() + CheckPluginsFile() + CheckINIFiles() + CheckSaveDirectory() +EndFunc + +Func CheckRegistryPaths() + Local $installPathExpected = $LAUNCHER_DIR & "\" + Local $exePathExpected = @ScriptFullPath + + ; Check and update Install_Path + Local $installPath = RegRead($REG_KEY, $REG_INSTALL_PATH) + If @error Or $installPath <> $installPathExpected Then + RegWrite($REG_KEY, $REG_INSTALL_PATH, "REG_SZ", $installPathExpected) + EndIf + + ; Check and update Exe_Path + Local $exePath = RegRead($REG_KEY, $REG_EXE_PATH) + If @error Or $exePath <> $exePathExpected Then + RegWrite($REG_KEY, $REG_EXE_PATH, "REG_SZ", $exePathExpected) + EndIf + + ; For Steam version: initialize Start_Steam if it doesn't exist + If $bIsSteamVersion Then + Local $startSteam = RegRead($REG_KEY, $REG_START_STEAM) + If @error Then + RegWrite($REG_KEY, $REG_START_STEAM, "REG_DWORD", 1) + EndIf + EndIf +EndFunc + +Func CheckPluginsFile() + Local $requiredLines[2] = ["*Enderal - Forgotten Stories.esm", "*SkyUI_SE.esp"] + + If Not DirExists($PLUGINS_DIR) Then + DirCreate($PLUGINS_DIR) + EndIf + + Local $fileContent = "" + If FileExists($PLUGINS_FILE) Then + $fileContent = FileRead($PLUGINS_FILE) + EndIf + + Local $modified = False + Local $lines = StringSplit($fileContent, @CRLF, 1) + + For $i = 0 To UBound($requiredLines) - 1 + Local $lineWithAsterisk = $requiredLines[$i] + Local $lineWithoutAsterisk = StringTrimLeft($lineWithAsterisk, 1) + + Local $foundWithAsterisk = False + Local $foundWithoutAsterisk = False + Local $lineIndex = -1 + + For $j = 1 To $lines[0] + Local $trimmedLine = StringStripWS($lines[$j], 3) + If $trimmedLine = $lineWithAsterisk Then + $foundWithAsterisk = True + ExitLoop + ElseIf $trimmedLine = $lineWithoutAsterisk Then + $foundWithoutAsterisk = True + $lineIndex = $j + ExitLoop + EndIf + Next + + If $foundWithAsterisk Then + ContinueLoop + ElseIf $foundWithoutAsterisk Then + $lines[$lineIndex] = $lineWithAsterisk + $modified = True + Else + If $fileContent <> "" And StringRight($fileContent, 2) <> @CRLF Then + $fileContent &= @CRLF + EndIf + $fileContent &= $lineWithAsterisk & @CRLF + $modified = True + ContinueLoop + EndIf + Next + + If $modified Then + Local $newContent = "" + For $j = 1 To $lines[0] + $newContent &= $lines[$j] + If $j < $lines[0] Then $newContent &= @CRLF + Next + + If StringInStr($fileContent, "*Enderal - Forgotten Stories.esm") Or StringInStr($fileContent, "*SkyUI_SE.esp") Then + $newContent = $fileContent + EndIf + + Local $hFile = FileOpen($PLUGINS_FILE, 2) + FileWrite($hFile, $newContent) + FileClose($hFile) + EndIf +EndFunc + +Func GetPhysicalResolution() + ; Get physical screen resolution using EnumDisplaySettingsW + ; This bypasses DPI scaling which affects @DesktopWidth/@DesktopHeight + Local Const $DEVMODE_SIZE = 220 + Local Const $OFFSET_dmPelsWidth = 172 + Local Const $OFFSET_dmPelsHeight = 176 + Local Const $ENUM_CURRENT_SETTINGS = -1 + + Local $tDevMode = DllStructCreate("byte[" & $DEVMODE_SIZE & "]") + DllStructSetData($tDevMode, 1, $DEVMODE_SIZE, 68) ; dmSize at offset 68 + + Local $aResult = DllCall("user32.dll", "bool", "EnumDisplaySettingsW", _ + "ptr", 0, _ + "dword", $ENUM_CURRENT_SETTINGS, _ + "struct*", $tDevMode) + + If @error Or Not $aResult[0] Then + ; Fallback to AutoIt macros if DllCall fails + Local $aRes[2] = [@DesktopWidth, @DesktopHeight] + Return $aRes + EndIf + + Local $width = DllStructGetData(DllStructCreate("dword", DllStructGetPtr($tDevMode) + $OFFSET_dmPelsWidth), 1) + Local $height = DllStructGetData(DllStructCreate("dword", DllStructGetPtr($tDevMode) + $OFFSET_dmPelsHeight), 1) + + Local $aRes[2] = [$width, $height] + Return $aRes +EndFunc + +Func CheckINIFiles() + If Not DirExists($DOCUMENTS_DIR) Then + DirCreate($DOCUMENTS_DIR) + EndIf + + Local $iniExists = FileExists($ENDERAL_INI) + Local $prefsExists = FileExists($ENDERAL_PREFS_INI) + + If Not $iniExists Or Not $prefsExists Then + Local $aPhysicalRes = GetPhysicalResolution() + Local $screenWidth = $aPhysicalRes[0] + Local $screenHeight = $aPhysicalRes[1] + + If Not $iniExists Then + Local $defaultIni = $LAUNCHER_DIR & "\Enderal_default.ini" + If Not FileExists($defaultIni) Then $defaultIni = $LAUNCHER_DIR & "\Skyrim_default.ini" + If FileExists($defaultIni) Then FileCopy($defaultIni, $ENDERAL_INI) + EndIf + + If Not $prefsExists Then + Local $defaultPrefsIni = $LAUNCHER_DIR & "\EnderalPrefs_default.ini" + If Not FileExists($defaultPrefsIni) Then $defaultPrefsIni = $LAUNCHER_DIR & "\SkyrimPrefs_default.ini" + If FileExists($defaultPrefsIni) Then + FileCopy($defaultPrefsIni, $ENDERAL_PREFS_INI) + IniWrite($ENDERAL_PREFS_INI, "Display", "iSize W", $screenWidth) + IniWrite($ENDERAL_PREFS_INI, "Display", "iSize H", $screenHeight) + EndIf + EndIf + Else + Local $shadowValue = IniRead($ENDERAL_PREFS_INI, "Display", "iShadowMaskQuarter", "") + If $shadowValue <> "4" Then + IniWrite($ENDERAL_PREFS_INI, "Display", "iShadowMaskQuarter", "4") + EndIf + EndIf +EndFunc + +Func CheckSaveDirectory() + ; Read sLocalSavePath from Enderal.ini (or custom INI) and ensure the directory exists + Local $savePath = IniReadWithCustom("General", "sLocalSavePath", "") + + ; Save path is relative to Skyrim's documents directory + Local $skyrimDocsDir = GetDocumentsPath() & "\My Games\" & GetBaseDirectoryName() + + ; Fix empty or legacy relative paths that start with ".." + If $savePath = "" Or StringLeft($savePath, 2) = ".." Then + Local $newSavePath = "EnderalSaves\" + Local $newFullPath = $skyrimDocsDir & "\" & $newSavePath + + ; Ensure new directory exists and update INI + If Not DirExists($newFullPath) Then + DirCreate($newFullPath) + EndIf + IniWriteWithCustom("General", "sLocalSavePath", $newSavePath) + EndIf +EndFunc + +Func GetDocumentsPath() + Local $oShell = ObjCreate("Shell.Application") + If IsObj($oShell) Then + Local $oFolder = $oShell.Namespace(0x05) + If IsObj($oFolder) Then + Return $oFolder.Self.Path + EndIf + EndIf + Return @MyDocumentsDir +EndFunc + +; ============================================ +; Main Window +; ============================================ +Func CreateMainWindow() + $hMainGUI = GUICreate("Enderal Launcher", $LAUNCHER_WIDTH, $LAUNCHER_HEIGHT, -1, -1, $WS_POPUP + $WS_CLIPCHILDREN) + GUISetIcon($LAUNCHER_DIR & "\enderal.ico") + ;GUISetBkColor(0x1A1A1A, $hMainGUI) + + ; Set background image + SetBackgroundImage() + + ; Create top link bar on the left + Local $linkBarY = 10 + Local $linkSpacing = 80 + Local $startX = 20 + + ; Credits - shadow first, then main label + $lblCreditsShadow = GUICtrlCreateLabel("Credits", $startX + 1, $linkBarY + 1, 70, 25, $SS_CENTER) + GUICtrlSetFont(-1, 10, 400, 4) + GUICtrlSetColor(-1, 0x000000) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + $lblCredits = GUICtrlCreateLabel("Credits", $startX, $linkBarY, 70, 25, $SS_CENTER) + GUICtrlSetFont(-1, 10, 400, 4) + GUICtrlSetColor(-1, 0xFFFFFF) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + ; Wiki - shadow first, then main label + $lblWikiShadow = GUICtrlCreateLabel("Wiki", $startX + $linkSpacing + 1, $linkBarY + 1, 70, 25, $SS_CENTER) + GUICtrlSetFont(-1, 10, 400, 4) + GUICtrlSetColor(-1, 0x000000) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + $lblWiki = GUICtrlCreateLabel("Wiki", $startX + $linkSpacing, $linkBarY, 70, 25, $SS_CENTER) + GUICtrlSetFont(-1, 10, 400, 4) + GUICtrlSetColor(-1, 0xFFFFFF) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + ; Support - shadow first, then main label + $lblSupportShadow = GUICtrlCreateLabel("Support", $startX + $linkSpacing * 2 + 1, $linkBarY + 1, 70, 25, $SS_CENTER) + GUICtrlSetFont(-1, 10, 400, 4) + GUICtrlSetColor(-1, 0x000000) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + $lblSupport = GUICtrlCreateLabel("Support", $startX + $linkSpacing * 2, $linkBarY, 70, 25, $SS_CENTER) + GUICtrlSetFont(-1, 10, 400, 4) + GUICtrlSetColor(-1, 0xFFFFFF) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + ; Changelog - shadow first, then main label + $lblChangelogShadow = GUICtrlCreateLabel("Changelog", $startX + $linkSpacing * 3 + 15 + 1, $linkBarY + 1, 100, 25, $SS_CENTER) + GUICtrlSetFont(-1, 10, 400, 4) + GUICtrlSetColor(-1, 0x000000) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + $lblChangelog = GUICtrlCreateLabel("Changelog", $startX + $linkSpacing * 3 + 15, $linkBarY, 100, 25, $SS_CENTER) + GUICtrlSetFont(-1, 10, 400, 4) + GUICtrlSetColor(-1, 0xFFFFFF) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + ; Create close and minimize buttons at top right + ; Minimize - shadow first, then main label + $lblMinimizeShadow = GUICtrlCreateLabel("_", $LAUNCHER_WIDTH - 60 + 1, 5 + 1, 25, 25, $SS_CENTER) + GUICtrlSetFont(-1, 14, 700) + GUICtrlSetColor(-1, 0x000000) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + $btnMinimize = GUICtrlCreateLabel("_", $LAUNCHER_WIDTH - 60, 5, 25, 25, $SS_CENTER) + GUICtrlSetFont(-1, 14, 700) + GUICtrlSetColor(-1, 0xFFFFFF) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + ; Close - shadow first, then main label + $lblCloseShadow = GUICtrlCreateLabel("X", $LAUNCHER_WIDTH - 30 + 1, 5 + 1, 25, 25, $SS_CENTER) + GUICtrlSetFont(-1, 12, 700) + GUICtrlSetColor(-1, 0x000000) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + $btnClose = GUICtrlCreateLabel("X", $LAUNCHER_WIDTH - 30, 5, 25, 25, $SS_CENTER) + GUICtrlSetFont(-1, 12, 700) + GUICtrlSetColor(-1, 0xFFFFFF) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUICtrlSetCursor(-1, 0) + + ; Create main buttons + Local $sTempDir = @TempDir & "\EnderalLauncher\" ; Create a unique temp folder + DirCreate($sTempDir) + + Local $btnWidth = 200 + Local $btnHeight = 82 + Local $btnX = $LAUNCHER_WIDTH - $btnWidth - 60 + Local $btnStartY = $LAUNCHER_HEIGHT - 420 + + Local $sDestinationFile = $sTempDir & "play.bmp" + FileInstall("play.bmp", $sDestinationFile, 1) + $btnPlay = GUICtrlCreateButton("PLAY", $btnX, $btnStartY, $btnWidth, $btnHeight, $BS_BITMAP) + GUICtrlSetFont(-1, 12, 400, $GUI_FONTNORMAL, "Tahoma", $CLEARTYPE_QUALITY) + GUICtrlSetImage($btnPlay, $sDestinationFile) + GUICtrlSetCursor($btnPlay, 0) + + $sDestinationFile = $sTempDir & "settings.bmp" + FileInstall("settings.bmp", $sDestinationFile, 1) + $btnSettings = GUICtrlCreateButton("Settings", $btnX, $btnStartY + 110, $btnWidth, $btnHeight, $BS_BITMAP) + GUICtrlSetFont(-1, 12, 400, $GUI_FONTNORMAL, "Tahoma", $CLEARTYPE_QUALITY) + GUICtrlSetImage($btnSettings, $sDestinationFile) + GUICtrlSetCursor($btnSettings, 0) + + $sDestinationFile = $sTempDir & "exit.bmp" + FileInstall("exit.bmp", $sDestinationFile, 1) + $btnExit = GUICtrlCreateButton("Exit", $btnX, $btnStartY + 220, $btnWidth, $btnHeight, $BS_BITMAP) + GUICtrlSetFont(-1, 12, 400, $GUI_FONTNORMAL, "Tahoma", $CLEARTYPE_QUALITY) + GUICtrlSetImage($btnExit, $sDestinationFile) + GUICtrlSetCursor($btnExit, 0) + + ; Create bottom version bar + CreateVersionBar() + + GUISetState(@SW_SHOW, $hMainGUI) +EndFunc + +Func CreateVersionBar() + Local $bottomY = $LAUNCHER_HEIGHT - 30 + Local $fontSize = 9 + + ; Get versions + Local $skyrimVer = GetSkyrimVersion() + Local $enderalVer = GetEnderalVersion() + + ; Determine display text for each version (include "v" only when version is found) + Local $skyrimText = "N/A" + If $skyrimVer <> "" Then $skyrimText = "v" & $skyrimVer + + Local $enderalText = "N/A" + If $enderalVer <> "" Then $enderalText = "v" & $enderalVer + + ; Build full version string + Local $fullText = "Skyrim SE " & $skyrimText & " | Enderal SE " & $enderalText + + ; Center the text using a wide label with center alignment + Local $labelWidth = 500 + Local $startX = ($LAUNCHER_WIDTH - $labelWidth) / 2 + + ; Shadow label + GUICtrlCreateLabel($fullText, $startX + 1, $bottomY + 1, $labelWidth, 20, $SS_CENTER) + GUICtrlSetFont(-1, $fontSize, 400) + GUICtrlSetColor(-1, 0x000000) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + + ; Main label + GUICtrlCreateLabel($fullText, $startX, $bottomY, $labelWidth, 20, $SS_CENTER) + GUICtrlSetFont(-1, $fontSize, 400) + GUICtrlSetColor(-1, 0xFFFFFF) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) +EndFunc + +Func SetBackgroundImage() + ; Extract background from embedded resource to temp + Local $sTempDir = @TempDir & "\EnderalLauncher\" + DirCreate($sTempDir) + Local $bgFile = $sTempDir & "background.jpg" + FileInstall("background.jpg", $bgFile, 1) + + If FileExists($bgFile) Then + Local $hImage = _GDIPlus_ImageLoadFromFile($bgFile) + If $hImage Then + Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hMainGUI) + Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($LAUNCHER_WIDTH, $LAUNCHER_HEIGHT, $hGraphic) + Local $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) + + ; Get original image dimensions + Local $imgWidth = _GDIPlus_ImageGetWidth($hImage) + Local $imgHeight = _GDIPlus_ImageGetHeight($hImage) + + ; Calculate scale factor to cover the entire window (crop to fit) + Local $scaleX = $LAUNCHER_WIDTH / $imgWidth + Local $scaleY = $LAUNCHER_HEIGHT / $imgHeight + Local $scale = ($scaleX > $scaleY) ? $scaleX : $scaleY + + ; Calculate scaled dimensions + Local $scaledWidth = $imgWidth * $scale + Local $scaledHeight = $imgHeight * $scale + + ; Calculate offset to center the image (crop from center) + Local $offsetX = ($LAUNCHER_WIDTH - $scaledWidth) / 2 + Local $offsetY = ($LAUNCHER_HEIGHT - $scaledHeight) / 2 + + ; Draw image with aspect ratio preserved, centered and cropped + _GDIPlus_GraphicsDrawImageRect($hBuffer, $hImage, $offsetX, $offsetY, $scaledWidth, $scaledHeight) + + Local $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) + $hBackgroundPic = GUICtrlCreatePic("", 0, 0, $LAUNCHER_WIDTH, $LAUNCHER_HEIGHT) + _SetBitmapToCtrl($hBackgroundPic, $hGDIBitmap) + GUICtrlSetState($hBackgroundPic, $GUI_DISABLE) + + _WinAPI_DeleteObject($hGDIBitmap) + _GDIPlus_GraphicsDispose($hBuffer) + _GDIPlus_BitmapDispose($hBitmap) + _GDIPlus_GraphicsDispose($hGraphic) + _GDIPlus_ImageDispose($hImage) + EndIf + EndIf +EndFunc + +Func _SetBitmapToCtrl($idPic, $hBitmap) + Local $hWnd = GUICtrlGetHandle($idPic) + _SendMessage($hWnd, 0x0172, 0, $hBitmap) +EndFunc + +; ============================================ +; Settings Window (child window) +; ============================================ +Func CreateSettingsWindow() + ; Create settings as a child window of main window + $hSettingsGUI = GUICreate("Settings", $SETTINGS_WIDTH, $SETTINGS_HEIGHT, _ + $SETTINGS_MARGIN, $SETTINGS_MARGIN, $WS_POPUP, $WS_EX_MDICHILD, $hMainGUI) + ;GUISetBkColor(0xF0F0F0, $hSettingsGUI) + + ; Tab control + $tabSettings = GUICtrlCreateTab(15, 20, $SETTINGS_WIDTH - 30, $SETTINGS_HEIGHT - 80) + + ; Display tab (includes rendering controls on right side) + GUICtrlCreateTabItem("Display") + CreateDisplayControls() + CreateRenderingControls() + + ; General tab + GUICtrlCreateTabItem("General") + CreateControlsControls() + + ; End tab items + GUICtrlCreateTabItem("") + + ; Save and Cancel buttons (outside tabs) + $btnSave = GUICtrlCreateButton("Save", $SETTINGS_WIDTH - 205, $SETTINGS_HEIGHT - 50, 90, 35) + $btnCancel = GUICtrlCreateButton("Cancel", $SETTINGS_WIDTH - 105, $SETTINGS_HEIGHT - 50, 90, 35) + + ; Hide initially + GUISetState(@SW_HIDE, $hSettingsGUI) + + ; Switch back to main GUI + GUISwitch($hMainGUI) +EndFunc + +Func CreateDisplayControls() + Local $leftMargin = $TAB_LEFT_MARGIN + Local $topMargin = $TAB_TOP_MARGIN + Local $rowHeight = $TAB_ROW_HEIGHT + + ; Resolution + $lblResolution = GUICtrlCreateLabel("Resolution:", $leftMargin, $topMargin, 100, 20) + $cmbResolution = GUICtrlCreateCombo("", $leftMargin + 110, $topMargin - 3, 200, 200, $CBS_DROPDOWNLIST) + PopulateResolutions() + + ; Antialiasing + $lblAntialiasing = GUICtrlCreateLabel("Antialiasing:", $leftMargin, $topMargin + $rowHeight, 100, 20) + $cmbAntialiasing = GUICtrlCreateCombo("", $leftMargin + 110, $topMargin + $rowHeight - 3, 200, 200, $CBS_DROPDOWNLIST) + GUICtrlSetData($cmbAntialiasing, $AA_TAA & "|" & $AA_FXAA & "|" & $AA_OFF) + + ; Windowed Mode + $chkWindowed = GUICtrlCreateCheckbox("Windowed Mode", $leftMargin, $topMargin + $rowHeight * 2, 150, 20) + + ; Detail group + Local $columnWidth = 370 + GUICtrlCreateGroup("Detail Presets", $leftMargin, $topMargin + $rowHeight * 3, $columnWidth, 80) + Local $detailBtnY = $topMargin + $rowHeight * 3 + 30 + Local $detailBtnWidth = 85 + Local $detailBtnHeight = 32 + $btnLow = GUICtrlCreateButton("Low", $leftMargin + 8, $detailBtnY, $detailBtnWidth, $detailBtnHeight) + $btnMedium = GUICtrlCreateButton("Medium", $leftMargin + 95, $detailBtnY, $detailBtnWidth, $detailBtnHeight) + $btnHigh = GUICtrlCreateButton("High", $leftMargin + 182, $detailBtnY, $detailBtnWidth, $detailBtnHeight) + $btnUltra = GUICtrlCreateButton("Ultra", $leftMargin + 269, $detailBtnY, $detailBtnWidth, $detailBtnHeight) + GUICtrlCreateGroup("", -99, -99, 1, 1) + + ; SSE Display Tweaks group + Local $sseGroupY = $topMargin + $rowHeight * 3 + 100 + $grpSSEDisplayTweaks = GUICtrlCreateGroup("SSE Display Tweaks", $leftMargin, $sseGroupY, $columnWidth, 90) + $chkSSEDisplayTweaks = GUICtrlCreateCheckbox("Enable", $leftMargin + 10, $sseGroupY + 25, 200, 20) + GUICtrlSetTip(-1, "Enables support for refresh rates higher than 60 Hz.") + $lblFramerateLimit = GUICtrlCreateLabel("Framerate limit:", $leftMargin + 10, $sseGroupY + 55, 110, 20) + $sldFramerateLimit = GUICtrlCreateSlider($leftMargin + 130, $sseGroupY + 50, 185, 25) + GUICtrlSetLimit($sldFramerateLimit, @DesktopRefresh, 30) + $lblFramerateLimitValue = GUICtrlCreateLabel("60", $leftMargin + 320, $sseGroupY + 55, 35, 20) + GUICtrlCreateGroup("", -99, -99, 1, 1) +EndFunc + +Func CreateRenderingControls() + ; Position on right side of Display tab + Local $leftMargin = $TAB_LEFT_MARGIN + 370 + 40 + Local $topMargin = $TAB_TOP_MARGIN + Local $rowHeight = $TAB_ROW_HEIGHT + Local $columnWidth = 370 + + $chk64bitRT = GUICtrlCreateCheckbox("64-bit RenderTarget", $leftMargin, $topMargin, $columnWidth - 20, 20) + GUICtrlSetTip(-1, "Uses 64-bit precision for HDR rendering instead of 32-bit." & @CRLF & "Reduces color banding in skies and gradients. Uses more VRAM.") + + $chkSSAO = GUICtrlCreateCheckbox("Screen Space Ambient Occlusion", $leftMargin, $topMargin + $rowHeight, $columnWidth - 20, 20) + GUICtrlSetTip(-1, "Adds soft shadows in corners and where objects meet surfaces." & @CRLF & "Makes scenes look more realistic. Has a performance cost.") + + $chkVolumetricLighting = GUICtrlCreateCheckbox("Volumetric Lighting", $leftMargin, $topMargin + $rowHeight * 2, $columnWidth - 20, 20) + GUICtrlSetTip(-1, "Adds visible light rays (god rays) through fog and atmosphere." & @CRLF & "Creates atmospheric sunbeams. Has a performance cost.") + + $chkSSR = GUICtrlCreateCheckbox("Screen Space Reflections", $leftMargin, $topMargin + $rowHeight * 3, $columnWidth - 20, 20) + GUICtrlSetTip(-1, "Skyrim SE is affected by the green water bug with this option enabled." & @CRLF & "Recommended to enable only with ENB or Community Shaders.") +EndFunc + +Func CreateControlsControls() + Local $leftMargin = $TAB_LEFT_MARGIN + Local $topMargin = $TAB_TOP_MARGIN + Local $rowHeight = $TAB_ROW_HEIGHT + Local $columnWidth = 370 + Local $rightMargin = $leftMargin + $columnWidth + 20 + + ; Controls group + GUICtrlCreateGroup("Controls", $leftMargin, $topMargin, $columnWidth, 80) + $chkController = GUICtrlCreateCheckbox("Enable Controller", $leftMargin + 10, $topMargin + 25, $columnWidth - 20, 20) + $chkVibration = GUICtrlCreateCheckbox("Controller Vibration", $leftMargin + 10, $topMargin + 50, $columnWidth - 20, 20) + GUICtrlCreateGroup("", -99, -99, 1, 1) + + ; Steam-only: Start Steam checkbox + $chkStartSteam = GUICtrlCreateCheckbox("Start Steam on launcher start", $leftMargin, $topMargin + 95, $columnWidth, 20) + If Not $bIsSteamVersion Then + GUICtrlSetState($chkStartSteam, $GUI_HIDE) + EndIf + + ; INI Files group (right side) + $grpIniFiles = GUICtrlCreateGroup("INI Files", $rightMargin, $topMargin, $columnWidth, 313) + Local $iniButtonWidth = $columnWidth - 30 + Local $iniButtonHeight = 44 + Local $iniButtonSpacing = 54 + $btnOpenEnderalIni = GUICtrlCreateButton(GetIniFileName($ENDERAL_INI), $rightMargin + 15, $topMargin + 28, $iniButtonWidth, $iniButtonHeight) + $btnOpenEnderalPrefsIni = GUICtrlCreateButton(GetIniFileName($ENDERAL_PREFS_INI), $rightMargin + 15, $topMargin + 28 + $iniButtonSpacing, $iniButtonWidth, $iniButtonHeight) + $btnOpenCustomIni = GUICtrlCreateButton(GetCustomIniFileName(), $rightMargin + 15, $topMargin + 28 + $iniButtonSpacing * 2, $iniButtonWidth, $iniButtonHeight) + UpdateCustomIniButtonState() + $btnOpenModIni = GUICtrlCreateButton(GetModIniFileName(), $rightMargin + 15, $topMargin + 28 + $iniButtonSpacing * 3, $iniButtonWidth, $iniButtonHeight) + UpdateModIniButtonState() + $btnOpenSavegames = GUICtrlCreateButton("Saved games directory", $rightMargin + 15, $topMargin + 28 + $iniButtonSpacing * 4, $iniButtonWidth, $iniButtonHeight) + GUICtrlCreateGroup("", -99, -99, 1, 1) +EndFunc + +Func PopulateResolutions() + Local $aResolutions = GetSupportedResolutions() + Local $resolutions = "" + + For $i = 0 To UBound($aResolutions) - 1 + If $i > 0 Then $resolutions &= "|" + $resolutions &= $aResolutions[$i] + Next + + GUICtrlSetData($cmbResolution, $resolutions) +EndFunc + +Func GetSupportedResolutions() + ; DEVMODEW structure size and offsets + Local Const $DEVMODE_SIZE = 220 + Local Const $OFFSET_dmPelsWidth = 172 + Local Const $OFFSET_dmPelsHeight = 176 + + Local $tDevMode = DllStructCreate("byte[" & $DEVMODE_SIZE & "]") + DllStructSetData($tDevMode, 1, $DEVMODE_SIZE, 68) ; dmSize at offset 68 + + Local $aTemp[100][2] ; Temporary array for width, height pairs + Local $count = 0 + Local $iModeNum = 0 + + ; Enumerate all display modes + While 1 + Local $aResult = DllCall("user32.dll", "bool", "EnumDisplaySettingsW", _ + "ptr", 0, _ + "dword", $iModeNum, _ + "struct*", $tDevMode) + + If @error Or Not $aResult[0] Then ExitLoop + + Local $width = DllStructGetData(DllStructCreate("dword", DllStructGetPtr($tDevMode) + $OFFSET_dmPelsWidth), 1) + Local $height = DllStructGetData(DllStructCreate("dword", DllStructGetPtr($tDevMode) + $OFFSET_dmPelsHeight), 1) + + ; Check for duplicate resolutions + Local $isDuplicate = False + For $i = 0 To $count - 1 + If $aTemp[$i][0] = $width And $aTemp[$i][1] = $height Then + $isDuplicate = True + ExitLoop + EndIf + Next + + If Not $isDuplicate And $width >= 800 And $height >= 600 Then + If $count >= UBound($aTemp) Then + ReDim $aTemp[$count + 50][2] + EndIf + $aTemp[$count][0] = $width + $aTemp[$count][1] = $height + $count += 1 + EndIf + + $iModeNum += 1 + WEnd + + ; Sort by total pixels (width * height) descending + For $i = 0 To $count - 2 + For $j = $i + 1 To $count - 1 + Local $pixelsI = $aTemp[$i][0] * $aTemp[$i][1] + Local $pixelsJ = $aTemp[$j][0] * $aTemp[$j][1] + If $pixelsJ > $pixelsI Then + Local $tmpW = $aTemp[$i][0] + Local $tmpH = $aTemp[$i][1] + $aTemp[$i][0] = $aTemp[$j][0] + $aTemp[$i][1] = $aTemp[$j][1] + $aTemp[$j][0] = $tmpW + $aTemp[$j][1] = $tmpH + EndIf + Next + Next + + ; Build result array + Local $aResult[$count] + For $i = 0 To $count - 1 + $aResult[$i] = $aTemp[$i][0] & "x" & $aTemp[$i][1] + Next + + Return $aResult +EndFunc + +; ============================================ +; Main Loop +; ============================================ +Func MainLoop() + While 1 + Local $msg = GUIGetMsg(1) + Local $msgID = $msg[0] + Local $msgHwnd = $msg[1] + + Switch $msgID + Case $GUI_EVENT_CLOSE + If $msgHwnd = $hMainGUI Then + Exit + ElseIf $msgHwnd = $hSettingsGUI Then + HideSettings() + EndIf + + Case $btnClose, $lblCloseShadow + Exit + + Case $btnMinimize, $lblMinimizeShadow + GUISetState(@SW_MINIMIZE, $hMainGUI) + + Case $btnExit + Exit + + Case $btnPlay + LaunchGame() + + Case $btnSettings + ShowSettings() + + Case $lblCredits, $lblCreditsShadow + ShellExecute("https://mod.pub/enderal-se/38/docs/5-credits") + + Case $lblWiki, $lblWikiShadow + ShellExecute("https://wiki.en.sureai.net/Enderal") + + Case $lblSupport, $lblSupportShadow + ShellExecute("https://mod.pub/enderal-se/38/comments") + + Case $lblChangelog, $lblChangelogShadow + ShellExecute("https://mod.pub/enderal-se/38/changelogs") + + Case $btnSave + SaveSettings() + HideSettings() + + Case $btnCancel + HideSettings() + + Case $btnLow + ApplyDetailPreset("Low") + + Case $btnMedium + ApplyDetailPreset("Medium") + + Case $btnHigh + ApplyDetailPreset("High") + + Case $btnUltra + ApplyDetailPreset("Ultra") + + Case $chkSSEDisplayTweaks + RefreshResolution() + + Case $sldFramerateLimit + GUICtrlSetData($lblFramerateLimitValue, GUICtrlRead($sldFramerateLimit)) + + Case $btnOpenEnderalIni + RunWithAssociation($ENDERAL_INI) + + Case $btnOpenEnderalPrefsIni + RunWithAssociation($ENDERAL_PREFS_INI) + + Case $btnOpenCustomIni + OpenCustomIni() + + Case $btnOpenModIni + OpenModIni() + + Case $btnOpenSavegames + OpenSavegamesDirectory() + + EndSwitch + WEnd +EndFunc + +; ============================================ +; Settings Show/Hide +; ============================================ +Func ShowSettings() + ; Load settings values + LoadSettings() + + ; Select first tab + GUICtrlSetData($tabSettings, 0) + + ; Show settings window + GUISetState(@SW_SHOW, $hSettingsGUI) +EndFunc + +Func HideSettings() + GUISetState(@SW_HIDE, $hSettingsGUI) +EndFunc + +; ============================================ +; Settings Load/Save +; ============================================ +Func RefreshResolution() + ; Read base resolution from Skyrim prefs + Local $width = IniRead($ENDERAL_PREFS_INI, "Display", "iSize W", @DesktopWidth) + Local $height = IniRead($ENDERAL_PREFS_INI, "Display", "iSize H", @DesktopHeight) + Local $resolution = $width & "x" & $height + + ; If SSE Display Tweaks checkbox is checked, read from its INI + Local $sseDisplayTweaksIni = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SSEDisplayTweaks.ini" + If BitAND(GUICtrlRead($chkSSEDisplayTweaks), $GUI_CHECKED) And FileExists($sseDisplayTweaksIni) Then + Local $sseRes = IniRead($sseDisplayTweaksIni, "Render", "Resolution", "") + If $sseRes <> "" Then + $resolution = $sseRes + EndIf + ; Load and enable framerate limit + Local $fpsLimit = IniRead($sseDisplayTweaksIni, "Render", "FramerateLimit", "60") + If Number($fpsLimit) < 30 Then $fpsLimit = 30 + If Number($fpsLimit) > @DesktopRefresh Then $fpsLimit = @DesktopRefresh + GUICtrlSetData($sldFramerateLimit, $fpsLimit) + GUICtrlSetData($lblFramerateLimitValue, $fpsLimit) + GUICtrlSetState($sldFramerateLimit, $GUI_ENABLE) + GUICtrlSetState($lblFramerateLimit, $GUI_ENABLE) + GUICtrlSetState($lblFramerateLimitValue, $GUI_ENABLE) + Else + ; Disable framerate limit slider + GUICtrlSetData($sldFramerateLimit, 60) + GUICtrlSetData($lblFramerateLimitValue, "60") + GUICtrlSetState($sldFramerateLimit, $GUI_DISABLE) + GUICtrlSetState($lblFramerateLimit, $GUI_DISABLE) + GUICtrlSetState($lblFramerateLimitValue, $GUI_DISABLE) + EndIf + + GUICtrlSetData($cmbResolution, $resolution) +EndFunc + +Func LoadSettings() + ; SSE Display Tweaks paths (used in multiple places) + Local $dllPath = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SSEDisplayTweaks.dll" + Local $bakPath = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SSEDisplayTweaks.dll.bak" + Local $sseDisplayTweaksIni = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SSEDisplayTweaks.ini" + + ; Load Display settings + Local $width = IniRead($ENDERAL_PREFS_INI, "Display", "iSize W", @DesktopWidth) + Local $height = IniRead($ENDERAL_PREFS_INI, "Display", "iSize H", @DesktopHeight) + Local $resolution = $width & "x" & $height + + ; If SSE Display Tweaks is enabled, read resolution from its INI + If FileExists($dllPath) And FileExists($sseDisplayTweaksIni) Then + Local $sseRes = IniRead($sseDisplayTweaksIni, "Render", "Resolution", "") + If $sseRes <> "" Then + $resolution = $sseRes + EndIf + EndIf + + GUICtrlSetData($cmbResolution, $resolution) + + ; Load Antialiasing + Local $taa = IniRead($ENDERAL_PREFS_INI, "Display", "bUseTAA", "0") + Local $fxaa = IniRead($ENDERAL_PREFS_INI, "Display", "bFXAAEnabled", "0") + If $taa = "1" Then + GUICtrlSetData($cmbAntialiasing, $AA_TAA) + ElseIf $fxaa = "1" Then + GUICtrlSetData($cmbAntialiasing, $AA_FXAA) + Else + GUICtrlSetData($cmbAntialiasing, $AA_OFF) + EndIf + + ; Load Windowed Mode + Local $fullscreen = IniRead($ENDERAL_PREFS_INI, "Display", "bFull Screen", "1") + SetCheckboxState($chkWindowed, $fullscreen, "0") + + ; Load Rendering settings + If FileExists($dllPath) Then + GUICtrlSetData($grpSSEDisplayTweaks, "SSE Display Tweaks") + GUICtrlSetState($chkSSEDisplayTweaks, $GUI_CHECKED + $GUI_ENABLE) + ; Load framerate limit from INI + Local $fpsLimit = IniRead($sseDisplayTweaksIni, "Render", "FramerateLimit", "60") + If Number($fpsLimit) < 30 Then $fpsLimit = 30 + If Number($fpsLimit) > @DesktopRefresh Then $fpsLimit = @DesktopRefresh + GUICtrlSetData($sldFramerateLimit, $fpsLimit) + GUICtrlSetData($lblFramerateLimitValue, $fpsLimit) + GUICtrlSetState($sldFramerateLimit, $GUI_ENABLE) + GUICtrlSetState($lblFramerateLimit, $GUI_ENABLE) + GUICtrlSetState($lblFramerateLimitValue, $GUI_ENABLE) + ElseIf FileExists($bakPath) Then + GUICtrlSetData($grpSSEDisplayTweaks, "SSE Display Tweaks") + GUICtrlSetState($chkSSEDisplayTweaks, $GUI_UNCHECKED + $GUI_ENABLE) + GUICtrlSetData($sldFramerateLimit, 60) + GUICtrlSetData($lblFramerateLimitValue, "60") + GUICtrlSetState($sldFramerateLimit, $GUI_DISABLE) + GUICtrlSetState($lblFramerateLimit, $GUI_DISABLE) + GUICtrlSetState($lblFramerateLimitValue, $GUI_DISABLE) + Else + GUICtrlSetData($grpSSEDisplayTweaks, "SSE Display Tweaks (not installed)") + GUICtrlSetState($chkSSEDisplayTweaks, $GUI_UNCHECKED + $GUI_DISABLE) + GUICtrlSetData($sldFramerateLimit, 60) + GUICtrlSetData($lblFramerateLimitValue, "60") + GUICtrlSetState($sldFramerateLimit, $GUI_DISABLE) + GUICtrlSetState($lblFramerateLimit, $GUI_DISABLE) + GUICtrlSetState($lblFramerateLimitValue, $GUI_DISABLE) + EndIf + + SetCheckboxState($chk64bitRT, IniRead($ENDERAL_PREFS_INI, "Display", "bUse64bitsHDRRenderTarget", "0")) + SetCheckboxState($chkSSAO, IniRead($ENDERAL_PREFS_INI, "Display", "bSAOEnable", "0")) + SetCheckboxState($chkVolumetricLighting, IniRead($ENDERAL_PREFS_INI, "Display", "bVolumetricLightingEnable", "0")) + + Local $ssr = IniReadWithCustom("Display", "fWaterSSRIntensity", "0.0001") + SetCheckboxState($chkSSR, Number($ssr) > 1 ? "1" : "0") + + ; Load Controls settings + SetCheckboxState($chkController, IniRead($ENDERAL_PREFS_INI, "MAIN", "bGamepadEnable", "0")) + SetCheckboxState($chkVibration, IniRead($ENDERAL_PREFS_INI, "Controls", "bGamePadRumble", "0")) + + ; Update INI Files group label based on SkyrimRedirector status + Local $redirectorDll = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SkyrimRedirector.dll" + If FileExists($redirectorDll) Then + GUICtrlSetData($grpIniFiles, "INI Files (SkyrimRedirector is active)") + Else + GUICtrlSetData($grpIniFiles, "INI Files (SkyrimRedirector is not installed)") + EndIf + + ; Load Start Steam checkbox (Steam version only) + If $bIsSteamVersion Then + Local $startSteam = RegRead($REG_KEY, $REG_START_STEAM) + If @error Then $startSteam = 1 + SetCheckboxState($chkStartSteam, $startSteam) + EndIf +EndFunc + +Func SaveSettings() + ; Save Resolution + Local $resolution = GUICtrlRead($cmbResolution) + Local $resParts = StringSplit($resolution, "x") + If $resParts[0] = 2 Then + IniWrite($ENDERAL_PREFS_INI, "Display", "iSize W", $resParts[1]) + IniWrite($ENDERAL_PREFS_INI, "Display", "iSize H", $resParts[2]) + + ; Sync resolution to SSEDisplayTweaks.ini if present + Local $sseDisplayTweaksIni = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SSEDisplayTweaks.ini" + If FileExists($sseDisplayTweaksIni) Then + Local $currentRes = IniRead($sseDisplayTweaksIni, "Render", "Resolution", "") + If $currentRes <> "" Then + IniWrite($sseDisplayTweaksIni, "Render", "Resolution", $resolution) + EndIf + EndIf + EndIf + + ; Save Antialiasing + Local $aa = GUICtrlRead($cmbAntialiasing) + Switch $aa + Case $AA_TAA + IniWrite($ENDERAL_PREFS_INI, "Display", "bUseTAA", "1") + IniWrite($ENDERAL_PREFS_INI, "Display", "bFXAAEnabled", "0") + Case $AA_FXAA + IniWrite($ENDERAL_PREFS_INI, "Display", "bUseTAA", "0") + IniWrite($ENDERAL_PREFS_INI, "Display", "bFXAAEnabled", "1") + Case $AA_OFF + IniWrite($ENDERAL_PREFS_INI, "Display", "bUseTAA", "0") + IniWrite($ENDERAL_PREFS_INI, "Display", "bFXAAEnabled", "0") + EndSwitch + + ; Save Windowed Mode (inverted: checked = "0" for fullscreen) + WriteCheckboxToIni($chkWindowed, $ENDERAL_PREFS_INI, "Display", "bFull Screen", "0", "1") + + ; Save SSE Display Tweaks (file-based toggle) + Local $dllPath = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SSEDisplayTweaks.dll" + Local $bakPath = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SSEDisplayTweaks.dll.bak" + Local $sseDisplayTweaksIni = $LAUNCHER_DIR & "\Data\SKSE\Plugins\SSEDisplayTweaks.ini" + If BitAND(GUICtrlRead($chkSSEDisplayTweaks), $GUI_CHECKED) Then + If FileExists($bakPath) And Not FileExists($dllPath) Then FileMove($bakPath, $dllPath) + ; Save framerate limit + If FileExists($sseDisplayTweaksIni) Then + IniWrite($sseDisplayTweaksIni, "Render", "FramerateLimit", GUICtrlRead($sldFramerateLimit)) + EndIf + Else + If FileExists($dllPath) Then FileMove($dllPath, $bakPath, 1) + EndIf + + ; Save Rendering settings + WriteCheckboxToIni($chk64bitRT, $ENDERAL_PREFS_INI, "Display", "bUse64bitsHDRRenderTarget") + WriteCheckboxToIni($chkSSAO, $ENDERAL_PREFS_INI, "Display", "bSAOEnable") + WriteCheckboxToIni($chkVolumetricLighting, $ENDERAL_PREFS_INI, "Display", "bVolumetricLightingEnable") + WriteCheckboxWithCustom($chkSSR, "Display", "fWaterSSRIntensity", "1.3", "0.0001") + + ; Save Controls settings + WriteCheckboxToIni($chkController, $ENDERAL_PREFS_INI, "MAIN", "bGamepadEnable") + WriteCheckboxToIni($chkVibration, $ENDERAL_PREFS_INI, "Controls", "bGamePadRumble") + + ; Save Start Steam checkbox (Steam version only) + If $bIsSteamVersion Then + Local $startSteam = (GUICtrlRead($chkStartSteam) = $GUI_CHECKED) ? 1 : 0 + RegWrite($REG_KEY, $REG_START_STEAM, "REG_DWORD", $startSteam) + EndIf +EndFunc + +Func ApplyDetailPreset($presetName) + Local $presetFile = $LAUNCHER_DIR & "\" & $presetName & ".ini" + If Not FileExists($presetFile) Then + MsgBox(16, "Error", "Preset file not found: " & $presetFile) + Return + EndIf + + Local $sections = IniReadSectionNames($presetFile) + If @error Then + MsgBox(16, "Error", "Could not read preset file " & $presetFile) + Return + EndIf + + For $i = 1 To $sections[0] + Local $sectionData = IniReadSection($presetFile, $sections[$i]) + If Not @error Then + For $j = 1 To $sectionData[0][0] + IniWrite($ENDERAL_PREFS_INI, $sections[$i], $sectionData[$j][0], $sectionData[$j][1]) + Next + EndIf + Next + + MsgBox(64, "Settings Updated", "Video settings have been updated.") + LoadSettings() +EndFunc + +; ============================================ +; Game Launch +; ============================================ +Func LaunchGame() + If Not FileExists($LAUNCHER_DIR & "\skse64_loader.exe") Then + MsgBox(16, "Error", "Unable to find skse64_loader.exe! SKSE is not installed.") + Return + EndIf + + ; Hide main buttons + GUICtrlSetState($btnPlay, $GUI_HIDE) + GUICtrlSetState($btnSettings, $GUI_HIDE) + GUICtrlSetState($btnExit, $GUI_HIDE) + + ; Create launching modal (aligned with main buttons) + Local $modalWidth = 200 + Local $modalHeight = 70 + Local $modalX = $LAUNCHER_WIDTH - $modalWidth - 60 + Local $modalY = ($LAUNCHER_HEIGHT - $modalHeight) / 2 + Local $hLaunchingGUI = GUICreate("", $modalWidth, $modalHeight, $modalX, $modalY, $WS_POPUP, $WS_EX_MDICHILD, $hMainGUI) + GUISetBkColor(0x1A1A1A, $hLaunchingGUI) + GUICtrlCreateLabel("Launching...", 0, 20, $modalWidth, 35, $SS_CENTER) + GUICtrlSetFont(-1, 14, 400, 0, "Tahoma") + GUICtrlSetColor(-1, 0xFFFFFF) + GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) + GUISetState(@SW_SHOW, $hLaunchingGUI) + + ; Launch SKSE + Run($LAUNCHER_DIR & "\skse64_loader.exe", $LAUNCHER_DIR) + + ; Wait for SkyrimSE.exe to gain focus + Local $hSkyrimWnd = 0 + While 1 + ; Check if SkyrimSE.exe window exists and has focus + $hSkyrimWnd = WinGetHandle("[CLASS:Skyrim Special Edition]") + If $hSkyrimWnd Then + ; SkyrimSE window exists, check if it has focus + If WinActive($hSkyrimWnd) Then + ExitLoop + EndIf + EndIf + + ; Also check if the process is no longer running (user closed it quickly) + If Not ProcessExists("SkyrimSE.exe") And Not ProcessExists("skse64_loader.exe") Then + ; Process ended before gaining focus, close modal and restore buttons + GUIDelete($hLaunchingGUI) + GUICtrlSetState($btnPlay, $GUI_SHOW) + GUICtrlSetState($btnSettings, $GUI_SHOW) + GUICtrlSetState($btnExit, $GUI_SHOW) + Return + EndIf + + Sleep(100) + WEnd + + ; SkyrimSE.exe has focus, exit launcher + Exit +EndFunc + +; ============================================ +; Get Mod Organizer 2 Directory +; ============================================ +Func GetMO2Directory() + Local $parentPID = _WinAPI_GetParentProcess() + If @error Or $parentPID = 0 Then Return "" + + Local $parentPath = _WinAPI_GetProcessFileName($parentPID) + If @error Or $parentPath = "" Then Return "" + + ; Check if parent is ModOrganizer.exe + If StringInStr($parentPath, "ModOrganizer.exe") Then + Return StringRegExpReplace($parentPath, "\\[^\\]+$", "") + EndIf + + Return "" +EndFunc + +; ============================================ +; Open Savegames Directory +; ============================================ +Func OpenSavegamesDirectory() + Local $savePath = IniReadWithCustom("General", "sLocalSavePath", "Saves\") + Local $skyrimDocsDir = GetDocumentsPath() & "\My Games\" & GetBaseDirectoryName() + Local $fullSavePath = $skyrimDocsDir & "\" & $savePath + If Not DirExists($fullSavePath) Then + MsgBox(16, "Error", "Savegames directory not found: " & $fullSavePath) + Return + EndIf + + ; Check if running under Mod Organizer (parent process is ModOrganizer.exe) + Local $mo2Dir = GetMO2Directory() + If $mo2Dir <> "" Then + Local $explorerPPPath = $mo2Dir & "\explorer++\Explorer++.exe" + If FileExists($explorerPPPath) Then + Run('"' & $explorerPPPath & '" "' & $fullSavePath & '"') + Return + EndIf + ; Explorer++ not found, show path in message box + MsgBox(64, "Saved Games Location", "Your saved games are located at:" & @CRLF & @CRLF & $fullSavePath) + Else + ; Not running under MO2, open normally + ShellExecute($fullSavePath) + EndIf +EndFunc + +; ============================================ +; Open Custom INI File +; ============================================ +Func OpenCustomIni() + Local $customIniPath = GetCustomIniPath() + If FileExists($customIniPath) Then + RunWithAssociation($customIniPath) + EndIf +EndFunc + +; ============================================ +; Open Mod INI File +; ============================================ +Func OpenModIni() + Local $modIniPath = GetDataIniPath() + If FileExists($modIniPath) Then + RunWithAssociation($modIniPath) + EndIf +EndFunc diff --git a/source/Launcher/LICENSE b/source/Launcher/LICENSE new file mode 100644 index 000000000..f288702d2 --- /dev/null +++ b/source/Launcher/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +.