using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using Dalamud.Game.Text; using Dalamud.Interface.Style; using Newtonsoft.Json; using Serilog; using Serilog.Events; namespace Dalamud.Configuration.Internal { /// /// Class containing Dalamud settings. /// [Serializable] internal sealed class DalamudConfiguration : IServiceType { /// /// Currently used beta key for Dalamud staging builds. /// public const string DalamudCurrentBetaKey = "proof of context"; private static readonly JsonSerializerSettings SerializerSettings = new() { TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple, Formatting = Formatting.Indented, }; [JsonIgnore] private string configPath; /// /// Delegate for the event that occurs when the dalamud configuration is saved. /// /// The current dalamud configuration. public delegate void DalamudConfigurationSavedDelegate(DalamudConfiguration dalamudConfiguration); /// /// Event that occurs when dalamud configuration is saved. /// public event DalamudConfigurationSavedDelegate DalamudConfigurationSaved; /// /// Gets a value indicating whether or not Dalamud staging is enabled. /// [JsonIgnore] public bool IsConventionalStaging => this.DalamudBetaKey == DalamudCurrentBetaKey; /// /// Gets or sets a list of muted works. /// public List BadWords { get; set; } /// /// Gets or sets a value indicating whether or not the taskbar should flash once a duty is found. /// public bool DutyFinderTaskbarFlash { get; set; } = true; /// /// Gets or sets a value indicating whether or not a message should be sent in chat once a duty is found. /// public bool DutyFinderChatMessage { get; set; } = true; /// /// Gets or sets the language code to load Dalamud localization with. /// public string LanguageOverride { get; set; } = null; /// /// Gets or sets the last loaded Dalamud version. /// public string LastVersion { get; set; } = null; /// /// Gets or sets the last loaded Dalamud version. /// public string LastChangelogMajorMinor { get; set; } = null; /// /// Gets or sets the chat type used by default for plugin messages. /// public XivChatType GeneralChatType { get; set; } = XivChatType.Debug; /// /// Gets or sets a value indicating whether or not plugin testing builds should be shown. /// public bool DoPluginTest { get; set; } = false; /// /// Gets or sets a key to opt into Dalamud staging builds. /// public string? DalamudBetaKey { get; set; } = null; /// /// Gets or sets a list of custom repos. /// public List ThirdRepoList { get; set; } = new(); /// /// Gets or sets a list of hidden plugins. /// public List HiddenPluginInternalName { get; set; } = new(); /// /// Gets or sets a list of seen plugins. /// public List SeenPluginInternalName { get; set; } = new(); /// /// Gets or sets a list of additional settings for devPlugins. The key is the absolute path /// to the plugin DLL. This is automatically generated for any plugins in the devPlugins folder. /// However by specifiying this value manually, you can add arbitrary files outside the normal /// file paths. /// public Dictionary DevPluginSettings { get; set; } = new(); /// /// Gets or sets a list of additional locations that dev plugins should be loaded from. This can /// be either a DLL or folder, but should be the absolute path, or a path relative to the currently /// injected Dalamud instance. /// public List DevPluginLoadLocations { get; set; } = new(); /// /// Gets or sets the global UI scale. /// public float GlobalUiScale { get; set; } = 1.0f; /// /// Gets or sets a value indicating whether to use AXIS fonts from the game. /// public bool UseAxisFontsFromGame { get; set; } = false; /// /// Gets or sets the gamma value to apply for Dalamud fonts. Effects text thickness. /// /// Before gamma is applied... /// * ...TTF fonts loaded with stb or FreeType are in linear space. /// * ...the game's prebaked AXIS fonts are in gamma space with gamma value of 1.4. /// public float FontGammaLevel { get; set; } = 1.4f; /// /// Gets or sets a value indicating the level of font resolution between 1 to 5. /// 0(1024x1024), 1(2048x2048), 2(4096x4096), 3(8192x8192), 4(16384x16384). /// public int FontResolutionLevel { get; set; } = 2; /// /// Gets or sets a value indicating whether to disable font fallback notice. /// public bool DisableFontFallbackNotice { get; set; } = false; /// /// Gets or sets a value indicating whether or not plugin UI should be hidden. /// public bool ToggleUiHide { get; set; } = true; /// /// Gets or sets a value indicating whether or not plugin UI should be hidden during cutscenes. /// public bool ToggleUiHideDuringCutscenes { get; set; } = true; /// /// Gets or sets a value indicating whether or not plugin UI should be hidden during GPose. /// public bool ToggleUiHideDuringGpose { get; set; } = true; /// /// Gets or sets a value indicating whether or not a message containing detailed plugin information should be sent at login. /// public bool PrintPluginsWelcomeMsg { get; set; } = true; /// /// Gets or sets a value indicating whether or not plugins should be auto-updated. /// public bool AutoUpdatePlugins { get; set; } /// /// Gets or sets a value indicating whether or not Dalamud should add buttons to the system menu. /// public bool DoButtonsSystemMenu { get; set; } = true; /// /// Gets or sets the default Dalamud debug log level on startup. /// public LogEventLevel LogLevel { get; set; } = LogEventLevel.Information; /// /// Gets or sets a value indicating whether or not the debug log should scroll automatically. /// public bool LogAutoScroll { get; set; } = true; /// /// Gets or sets a value indicating whether or not the debug log should open at startup. /// public bool LogOpenAtStartup { get; set; } /// /// Gets or sets a value indicating whether or not the dev bar should open at startup. /// public bool DevBarOpenAtStartup { get; set; } /// /// Gets or sets a value indicating whether or not ImGui asserts should be enabled at startup. /// public bool AssertsEnabledAtStartup { get; set; } /// /// Gets or sets a value indicating whether or not docking should be globally enabled in ImGui. /// public bool IsDocking { get; set; } /// /// Gets or sets a value indicating whether viewports should always be disabled. /// public bool IsDisableViewport { get; set; } = true; /// /// Gets or sets a value indicating whether or not navigation via a gamepad should be globally enabled in ImGui. /// public bool IsGamepadNavigationEnabled { get; set; } = true; /// /// Gets or sets a value indicating whether or not focus management is enabled. /// public bool IsFocusManagementEnabled { get; set; } = true; /// /// Gets or sets a value indicating whether or not the anti-anti-debug check is enabled on startup. /// public bool IsAntiAntiDebugEnabled { get; set; } = false; /// /// Gets or sets a value indicating whether to resume game main thread after plugins load. /// public bool IsResumeGameAfterPluginLoad { get; set; } = false; /// /// Gets or sets the kind of beta to download when matches the server value. /// public string DalamudBetaKind { get; set; } /// /// Gets or sets a value indicating whether or not all plugins, regardless of API level, should be loaded. /// public bool LoadAllApiLevels { get; set; } /// /// Gets or sets a value indicating whether or not banned plugins should be loaded. /// public bool LoadBannedPlugins { get; set; } /// /// Gets or sets a value indicating whether or not any plugin should be loaded when the game is started. /// It is reset immediately when read. /// public bool PluginSafeMode { get; set; } /// /// Gets or sets a list of saved styles. /// [JsonProperty("SavedStyles")] public List? SavedStylesOld { get; set; } /// /// Gets or sets a list of saved styles. /// [JsonProperty("SavedStylesVersioned")] public List? SavedStyles { get; set; } /// /// Gets or sets the name of the currently chosen style. /// public string ChosenStyle { get; set; } = "Dalamud Standard"; /// /// Gets or sets a value indicating whether or not Dalamud RMT filtering should be disabled. /// public bool DisableRmtFiltering { get; set; } /// /// Gets or sets the order of DTR elements, by title. /// public List? DtrOrder { get; set; } /// /// Gets or sets the list of ignored DTR elements, by title. /// public List? DtrIgnore { get; set; } /// /// Gets or sets the spacing used for DTR entries. /// public int DtrSpacing { get; set; } = 10; /// /// Gets or sets a value indicating whether to swap the /// direction in which elements are drawn in the DTR. /// False indicates that elements will be drawn from the end of /// the left side of the Server Info bar, and continue leftwards. /// True indicates the opposite. /// public bool DtrSwapDirection { get; set; } = false; /// /// Gets or sets a value indicating whether the title screen menu is shown. /// public bool ShowTsm { get; set; } = true; /// /// Gets or sets a value indicating whether or not market board data should be uploaded. /// public bool IsMbCollect { get; set; } = true; /// /// Gets the ISO 639-1 two-letter code for the language of the effective Dalamud display language. /// public string EffectiveLanguage { get { var languages = Localization.ApplicableLangCodes.Prepend("en").ToArray(); try { if (string.IsNullOrEmpty(this.LanguageOverride)) { var currentUiLang = CultureInfo.CurrentUICulture; if (Localization.ApplicableLangCodes.Any(x => currentUiLang.TwoLetterISOLanguageName == x)) return currentUiLang.TwoLetterISOLanguageName; else return languages[0]; } else { return this.LanguageOverride; } } catch (Exception) { return languages[0]; } } } /// /// Gets or sets a value indicating whether or not to show info on dev bar. /// public bool ShowDevBarInfo { get; set; } = true; /// /// Load a configuration from the provided path. /// /// The path to load the configuration file from. /// The deserialized configuration file. public static DalamudConfiguration Load(string path) { DalamudConfiguration deserialized = null; try { deserialized = JsonConvert.DeserializeObject(File.ReadAllText(path), SerializerSettings); } catch (Exception ex) { Log.Warning(ex, "Failed to load DalamudConfiguration at {0}", path); } deserialized ??= new DalamudConfiguration(); deserialized.configPath = path; return deserialized; } /// /// Save the configuration at the path it was loaded from. /// public void Save() { File.WriteAllText(this.configPath, JsonConvert.SerializeObject(this, SerializerSettings)); this.DalamudConfigurationSaved?.Invoke(this); } } }