diff --git a/Dalamud/Game/Config/GameConfig.cs b/Dalamud/Game/Config/GameConfig.cs index a41b60936..dfdb8b5d2 100644 --- a/Dalamud/Game/Config/GameConfig.cs +++ b/Dalamud/Game/Config/GameConfig.cs @@ -67,6 +67,15 @@ public sealed class GameConfig : IServiceType, IGameConfig, IDisposable /// public bool TryGet(SystemConfigOption option, out string value) => this.System.TryGet(option.GetName(), out value); + /// + public bool TryGet(SystemConfigOption option, out UIntConfigProperties? properties) => this.System.TryGetProperties(option.GetName(), out properties); + + /// + public bool TryGet(SystemConfigOption option, out FloatConfigProperties? properties) => this.System.TryGetProperties(option.GetName(), out properties); + + /// + public bool TryGet(SystemConfigOption option, out StringConfigProperties? properties) => this.System.TryGetProperties(option.GetName(), out properties); + /// public bool TryGet(UiConfigOption option, out bool value) => this.UiConfig.TryGet(option.GetName(), out value); @@ -77,7 +86,16 @@ public sealed class GameConfig : IServiceType, IGameConfig, IDisposable public bool TryGet(UiConfigOption option, out float value) => this.UiConfig.TryGet(option.GetName(), out value); /// - public bool TryGet(UiConfigOption option, out string value) => this.UiControl.TryGet(option.GetName(), out value); + public bool TryGet(UiConfigOption option, out string value) => this.UiConfig.TryGet(option.GetName(), out value); + + /// + public bool TryGet(UiConfigOption option, out UIntConfigProperties properties) => this.UiConfig.TryGetProperties(option.GetName(), out properties); + + /// + public bool TryGet(UiConfigOption option, out FloatConfigProperties properties) => this.UiConfig.TryGetProperties(option.GetName(), out properties); + + /// + public bool TryGet(UiConfigOption option, out StringConfigProperties properties) => this.UiConfig.TryGetProperties(option.GetName(), out properties); /// public bool TryGet(UiControlOption option, out bool value) => this.UiControl.TryGet(option.GetName(), out value); @@ -89,8 +107,17 @@ public sealed class GameConfig : IServiceType, IGameConfig, IDisposable public bool TryGet(UiControlOption option, out float value) => this.UiControl.TryGet(option.GetName(), out value); /// - public bool TryGet(UiControlOption option, out string value) => this.System.TryGet(option.GetName(), out value); + public bool TryGet(UiControlOption option, out string value) => this.UiControl.TryGet(option.GetName(), out value); + + /// + public bool TryGet(UiControlOption option, out UIntConfigProperties properties) => this.UiControl.TryGetProperties(option.GetName(), out properties); + /// + public bool TryGet(UiControlOption option, out FloatConfigProperties properties) => this.UiControl.TryGetProperties(option.GetName(), out properties); + + /// + public bool TryGet(UiControlOption option, out StringConfigProperties properties) => this.UiControl.TryGetProperties(option.GetName(), out properties); + /// public void Set(SystemConfigOption option, bool value) => this.System.Set(option.GetName(), value); diff --git a/Dalamud/Game/Config/GameConfigSection.cs b/Dalamud/Game/Config/GameConfigSection.cs index 7b2751901..6c87ad3cf 100644 --- a/Dalamud/Game/Config/GameConfigSection.cs +++ b/Dalamud/Game/Config/GameConfigSection.cs @@ -1,5 +1,5 @@ using System; -using System.Collections.Generic; +using System.Collections.Concurrent; using System.Diagnostics; using Dalamud.Memory; @@ -15,9 +15,8 @@ namespace Dalamud.Game.Config; public class GameConfigSection { private readonly Framework framework; - private readonly Dictionary indexMap = new(); - private readonly Dictionary nameMap = new(); - private readonly Dictionary enumMap = new(); + private readonly ConcurrentDictionary indexMap = new(); + private readonly ConcurrentDictionary enumMap = new(); /// /// Event which is fired when a game config option is changed within the section. @@ -390,6 +389,99 @@ public class GameConfigSection }); } + /// + /// Attempts to get the properties of a UInt option from the config section. + /// + /// Name of the option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public unsafe bool TryGetProperties(string name, out UIntConfigProperties? properties) + { + if (!this.TryGetIndex(name, out var index)) + { + properties = null; + return false; + } + + if (!this.TryGetEntry(index, out var entry)) + { + properties = null; + return false; + } + + if ((ConfigType)entry->Type != ConfigType.UInt) + { + properties = null; + return false; + } + + var prop = &entry->Properties.UInt; + properties = new UIntConfigProperties(prop->DefaultValue, prop->MinValue, prop->MaxValue); + return true; + } + + /// + /// Attempts to get the properties of a Float option from the config section. + /// + /// Name of the option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public unsafe bool TryGetProperties(string name, out FloatConfigProperties? properties) + { + if (!this.TryGetIndex(name, out var index)) + { + properties = null; + return false; + } + + if (!this.TryGetEntry(index, out var entry)) + { + properties = null; + return false; + } + + if ((ConfigType)entry->Type != ConfigType.Float) + { + properties = null; + return false; + } + + var prop = &entry->Properties.Float; + properties = new FloatConfigProperties(prop->DefaultValue, prop->MinValue, prop->MaxValue); + return true; + } + + /// + /// Attempts to get the properties of a String option from the config section. + /// + /// Name of the option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public unsafe bool TryGetProperties(string name, out StringConfigProperties? properties) + { + if (!this.TryGetIndex(name, out var index)) + { + properties = null; + return false; + } + + if (!this.TryGetEntry(index, out var entry)) + { + properties = null; + return false; + } + + if ((ConfigType)entry->Type != ConfigType.String) + { + properties = null; + return false; + } + + var prop = entry->Properties.String; + properties = new StringConfigProperties(prop.DefaultValue == null ? null : MemoryHelper.ReadSeString(prop.DefaultValue)); + return true; + } + /// /// Invokes a change event within the config section. /// @@ -404,12 +496,12 @@ public class GameConfigSection var name = MemoryHelper.ReadStringNullTerminated(new IntPtr(entry->Name)); if (Enum.TryParse(typeof(TEnum), name, out enumObject)) { - this.enumMap.Add(entry->Index, enumObject); + this.enumMap.TryAdd(entry->Index, enumObject); } else { enumObject = null; - this.enumMap.Add(entry->Index, null); + this.enumMap.TryAdd(entry->Index, null); } } @@ -439,7 +531,6 @@ public class GameConfigSection if (eName.Equals(name)) { this.indexMap.TryAdd(name, i); - this.nameMap.TryAdd(i, name); index = i; return true; } diff --git a/Dalamud/Game/Config/Properties.cs b/Dalamud/Game/Config/Properties.cs new file mode 100644 index 000000000..b43a44a47 --- /dev/null +++ b/Dalamud/Game/Config/Properties.cs @@ -0,0 +1,7 @@ +using Dalamud.Game.Text.SeStringHandling; + +namespace Dalamud.Game.Config; + +public record StringConfigProperties(SeString? Default); +public record UIntConfigProperties(uint Default, uint Minimum, uint Maximum); +public record FloatConfigProperties(float Default, float Minimum, float Maximum); diff --git a/Dalamud/Plugin/Services/IGameConfig.cs b/Dalamud/Plugin/Services/IGameConfig.cs index f0607c39e..98f6160cc 100644 --- a/Dalamud/Plugin/Services/IGameConfig.cs +++ b/Dalamud/Plugin/Services/IGameConfig.cs @@ -62,6 +62,30 @@ public interface IGameConfig /// The returned value of the config option. /// A value representing the success. public bool TryGet(SystemConfigOption option, out string value); + + /// + /// Attempts to get the properties of a UInt option from the System section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(SystemConfigOption option, out UIntConfigProperties? properties); + + /// + /// Attempts to get the properties of a Float option from the System section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(SystemConfigOption option, out FloatConfigProperties? properties); + + /// + /// Attempts to get the properties of a String option from the System section. + /// + /// Option to get the properties of. + /// Details of the option: Default Value + /// A value representing the success. + public bool TryGet(SystemConfigOption option, out StringConfigProperties? properties); /// /// Attempts to get a boolean config value from the UiConfig section. @@ -95,6 +119,30 @@ public interface IGameConfig /// A value representing the success. public bool TryGet(UiConfigOption option, out string value); + /// + /// Attempts to get the properties of a UInt option from the UiConfig section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(UiConfigOption option, out UIntConfigProperties? properties); + + /// + /// Attempts to get the properties of a Float option from the UiConfig section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(UiConfigOption option, out FloatConfigProperties? properties); + + /// + /// Attempts to get the properties of a String option from the UiConfig section. + /// + /// Option to get the properties of. + /// Details of the option: Default Value + /// A value representing the success. + public bool TryGet(UiConfigOption option, out StringConfigProperties? properties); + /// /// Attempts to get a boolean config value from the UiControl section. /// @@ -127,6 +175,30 @@ public interface IGameConfig /// A value representing the success. public bool TryGet(UiControlOption option, out string value); + /// + /// Attempts to get the properties of a UInt option from the UiControl section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(UiControlOption option, out UIntConfigProperties? properties); + + /// + /// Attempts to get the properties of a Float option from the UiControl section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(UiControlOption option, out FloatConfigProperties? properties); + + /// + /// Attempts to get the properties of a String option from the UiControl section. + /// + /// Option to get the properties of. + /// Details of the option: Default Value + /// A value representing the success. + public bool TryGet(UiControlOption option, out StringConfigProperties? properties); + /// /// Set a boolean config option in the System config section. /// Note: Not all config options will be be immediately reflected in the game.