From 192396abdcce395ce7814336f422190557033fa1 Mon Sep 17 00:00:00 2001 From: goaaats Date: Sun, 19 Jun 2022 12:24:18 +0200 Subject: [PATCH] feat: set boot defaults via json --- Dalamud.Boot/dllmain.cpp | 4 -- Dalamud.Injector/EntryPoint.cs | 54 ++++++---------- Dalamud/DalamudStartInfo.cs | 110 ++++++++++++++++++++++++++++----- 3 files changed, 112 insertions(+), 56 deletions(-) diff --git a/Dalamud.Boot/dllmain.cpp b/Dalamud.Boot/dllmain.cpp index 01e09cd0b..33646cb99 100644 --- a/Dalamud.Boot/dllmain.cpp +++ b/Dalamud.Boot/dllmain.cpp @@ -1,7 +1,5 @@ #include "pch.h" -#include - #include "DalamudStartInfo.h" #include "logging.h" #include "utils.h" @@ -12,8 +10,6 @@ HMODULE g_hModule; HINSTANCE g_hGameInstance = GetModuleHandleW(nullptr); DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) { - MessageBoxW(nullptr, L"", L"", MB_OK); - g_startInfo.from_envvars(); std::string jsonParseError; diff --git a/Dalamud.Injector/EntryPoint.cs b/Dalamud.Injector/EntryPoint.cs index e1b0befe0..24da8b17b 100644 --- a/Dalamud.Injector/EntryPoint.cs +++ b/Dalamud.Injector/EntryPoint.cs @@ -56,11 +56,6 @@ namespace Dalamud.Injector return; } - // Set boot defaults - SetEnvDefaultIfNotExist("DALAMUD_GAMEFIX_LIST", "prevent_devicechange_crashes,disable_game_openprocess_access_check,redirect_openprocess"); - SetEnvDefaultIfNotExist("DALAMUD_DOTNET_OPENPROCESS_HOOKMODE", "0"); - //SetEnvDefaultIfNotExist("DALAMUD_UNHOOK_DLLS", "kernel32.dll,ntdll.dll,user32.dll"); - DalamudStartInfo startInfo = null; if (args.Count == 1) { @@ -108,15 +103,6 @@ namespace Dalamud.Injector } } - private static void SetEnvDefaultIfNotExist(string name, string value) - { - var prevValue = Environment.GetEnvironmentVariable(name); - if (string.IsNullOrWhiteSpace(prevValue)) - { - Environment.SetEnvironmentVariable(name, value); - } - } - private static string GetLogPath(string filename) { var baseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); @@ -263,8 +249,7 @@ namespace Dalamud.Injector int len; string key; - if (startInfo == null) - startInfo = new(); + startInfo ??= new DalamudStartInfo(); var workingDirectory = startInfo.WorkingDirectory; var configurationPath = startInfo.ConfigurationPath; @@ -315,7 +300,7 @@ namespace Dalamud.Injector clientLanguage = ClientLanguage.Japanese; else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "german").Length))] == key[0..len]) clientLanguage = ClientLanguage.German; - else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "deutsche").Length))] == key[0..len]) + else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "deutsch").Length))] == key[0..len]) clientLanguage = ClientLanguage.German; else if (languageStr[0..(len = Math.Min(languageStr.Length, (key = "french").Length))] == key[0..len]) clientLanguage = ClientLanguage.French; @@ -326,17 +311,21 @@ namespace Dalamud.Injector else throw new CommandLineException($"\"{languageStr}\" is not a valid supported language."); - return new() - { - WorkingDirectory = workingDirectory, - ConfigurationPath = configurationPath, - PluginDirectory = pluginDirectory, - DefaultPluginDirectory = defaultPluginDirectory, - AssetDirectory = assetDirectory, - Language = clientLanguage, - GameVersion = null, - DelayInitializeMs = delayInitializeMs, - }; + startInfo.WorkingDirectory = workingDirectory; + startInfo.ConfigurationPath = configurationPath; + startInfo.PluginDirectory = pluginDirectory; + startInfo.DefaultPluginDirectory = defaultPluginDirectory; + startInfo.AssetDirectory = assetDirectory; + startInfo.Language = clientLanguage; + startInfo.DelayInitializeMs = delayInitializeMs; + startInfo.GameVersion = null; + + // Set boot defaults + startInfo.BootEnabledGameFixes = new List { "prevent_devicechange_crashes", "disable_game_openprocess_access_check", "redirect_openprocess" }; + startInfo.BootDotnetOpenProcessHookMode = 0; + //startInfo.BootUnhookDlls = new List() { "kernel32.dll", "ntdll.dll", "user32.dll" }; + + return startInfo; } private static int ProcessHelpCommand(List args, string? particularCommand = default) @@ -689,16 +678,9 @@ namespace Dalamud.Injector var gameVerStr = File.ReadAllText(Path.Combine(ffxivDir, "ffxivgame.ver")); var gameVer = GameVersion.Parse(gameVerStr); - return new() + return new DalamudStartInfo(startInfo) { - WorkingDirectory = startInfo.WorkingDirectory, - ConfigurationPath = startInfo.ConfigurationPath, - PluginDirectory = startInfo.PluginDirectory, - DefaultPluginDirectory = startInfo.DefaultPluginDirectory, - AssetDirectory = startInfo.AssetDirectory, - Language = startInfo.Language, GameVersion = gameVer, - DelayInitializeMs = startInfo.DelayInitializeMs, }; } diff --git a/Dalamud/DalamudStartInfo.cs b/Dalamud/DalamudStartInfo.cs index 1652bb817..40c397e49 100644 --- a/Dalamud/DalamudStartInfo.cs +++ b/Dalamud/DalamudStartInfo.cs @@ -1,5 +1,5 @@ using System; - +using System.Collections.Generic; using Dalamud.Game; using Newtonsoft.Json; @@ -11,45 +11,123 @@ namespace Dalamud [Serializable] public record DalamudStartInfo { + /// + /// Initializes a new instance of the class. + /// + public DalamudStartInfo() + { + // ignored + } + + /// + /// Initializes a new instance of the class. + /// + /// Object to copy values from. + public DalamudStartInfo(DalamudStartInfo other) + { + this.WorkingDirectory = other.WorkingDirectory; + this.ConfigurationPath = other.ConfigurationPath; + this.PluginDirectory = other.PluginDirectory; + this.DefaultPluginDirectory = other.DefaultPluginDirectory; + this.AssetDirectory = other.AssetDirectory; + this.Language = other.Language; + this.GameVersion = other.GameVersion; + this.DelayInitializeMs = other.DelayInitializeMs; + this.BootShowConsole = other.BootShowConsole; + this.BootDisableFallbackConsole = other.BootDisableFallbackConsole; + this.BootWaitMessageBox = other.BootWaitMessageBox; + this.BootWaitDebugger = other.BootWaitDebugger; + this.BootVehEnabled = other.BootVehEnabled; + this.BootVehFull = other.BootVehFull; + this.BootDotnetOpenProcessHookMode = other.BootDotnetOpenProcessHookMode; + this.BootEnabledGameFixes = other.BootEnabledGameFixes; + this.BootUnhookDlls = other.BootUnhookDlls; + } + /// /// Gets or sets the working directory of the XIVLauncher installations. /// - public string WorkingDirectory { get; set; } + public string? WorkingDirectory { get; set; } /// - /// Gets the path to the configuration file. + /// Gets or sets the path to the configuration file. /// - public string ConfigurationPath { get; init; } + public string? ConfigurationPath { get; set; } /// - /// Gets the path to the directory for installed plugins. + /// Gets or sets the path to the directory for installed plugins. /// - public string PluginDirectory { get; init; } + public string? PluginDirectory { get; set; } /// - /// Gets the path to the directory for developer plugins. + /// Gets or sets the path to the directory for developer plugins. /// - public string DefaultPluginDirectory { get; init; } + public string? DefaultPluginDirectory { get; set; } /// - /// Gets the path to core Dalamud assets. + /// Gets or sets the path to core Dalamud assets. /// - public string AssetDirectory { get; init; } + public string? AssetDirectory { get; set; } /// - /// Gets the language of the game client. + /// Gets or sets the language of the game client. /// - public ClientLanguage Language { get; init; } = ClientLanguage.English; + public ClientLanguage Language { get; set; } = ClientLanguage.English; /// - /// Gets the current game version code. + /// Gets or sets the current game version code. /// [JsonConverter(typeof(GameVersionConverter))] - public GameVersion GameVersion { get; init; } + public GameVersion? GameVersion { get; set; } /// - /// Gets a value that specifies how much to wait before a new Dalamud session. + /// Gets or sets a value that specifies how much to wait before a new Dalamud session. /// - public int DelayInitializeMs { get; init; } = 0; + public int DelayInitializeMs { get; set; } = 0; + + /// + /// Gets or sets a value indicating whether a Boot console should be shown. + /// + public bool BootShowConsole { get; set; } + + /// + /// Gets or sets a value indicating whether the fallback console should be shown, if needed. + /// + public bool BootDisableFallbackConsole { get; set; } + + /// + /// Gets or sets a flag indicating where Dalamud should wait with a message box. + /// + public int BootWaitMessageBox { get; set; } + + /// + /// Gets or sets a value indicating whether Dalamud should wait for a debugger to be attached before initializing. + /// + public bool BootWaitDebugger { get; set; } + + /// + /// Gets or sets a value indicating whether the VEH should be enabled. + /// + public bool BootVehEnabled { get; set; } + + /// + /// Gets or sets a value indicating whether the VEH should be doing full crash dumps. + /// + public bool BootVehFull { get; set; } + + /// + /// Gets or sets a value choosing the OpenProcess hookmode. + /// + public int BootDotnetOpenProcessHookMode { get; set; } + + /// + /// Gets or sets a list of enabled game fixes. + /// + public List? BootEnabledGameFixes { get; set; } + + /// + /// Gets or sets a list of DLLs that should be unhooked. + /// + public List? BootUnhookDlls { get; set; } } }