diff --git a/Dalamud/Game/Config/GameConfig.cs b/Dalamud/Game/Config/GameConfig.cs index 81112cd79..5587787c9 100644 --- a/Dalamud/Game/Config/GameConfig.cs +++ b/Dalamud/Game/Config/GameConfig.cs @@ -1,7 +1,6 @@ -using System.Diagnostics; - -using Dalamud.IoC; +using Dalamud.IoC; using Dalamud.IoC.Internal; +using Dalamud.Plugin.Services; using Serilog; namespace Dalamud.Game.Config; @@ -12,14 +11,17 @@ namespace Dalamud.Game.Config; [InterfaceVersion("1.0")] [PluginInterface] [ServiceManager.EarlyLoadedService] -public sealed class GameConfig : IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +public sealed class GameConfig : IServiceType, IGameConfig { [ServiceManager.ServiceConstructor] private unsafe GameConfig(Framework framework) { framework.RunOnTick(() => { - Log.Verbose("[GameConfig] Initalizing"); + Log.Verbose("[GameConfig] Initializing"); var csFramework = FFXIVClientStructs.FFXIV.Client.System.Framework.Framework.Instance(); var commonConfig = &csFramework->SystemConfig.CommonSystemConfig; this.System = new GameConfigSection("System", framework, &commonConfig->ConfigBase); @@ -28,234 +30,84 @@ public sealed class GameConfig : IServiceType }); } - /// - /// Gets the collection of config options that persist between characters. - /// + /// public GameConfigSection System { get; private set; } - /// - /// Gets the collection of config options that are character specific. - /// + /// public GameConfigSection UiConfig { get; private set; } - /// - /// Gets the collection of config options that are control mode specific. (Mouse and Keyboard / Gamepad). - /// + /// public GameConfigSection UiControl { get; private set; } - /// - /// Attempts to get a boolean config value from the System section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(SystemConfigOption option, out bool value) => this.System.TryGet(option.GetName(), out value); - /// - /// Attempts to get a uint config value from the System section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(SystemConfigOption option, out uint value) => this.System.TryGet(option.GetName(), out value); - /// - /// Attempts to get a float config value from the System section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(SystemConfigOption option, out float value) => this.System.TryGet(option.GetName(), out value); - /// - /// Attempts to get a string config value from the System section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(SystemConfigOption option, out string value) => this.System.TryGet(option.GetName(), out value); - /// - /// Attempts to get a boolean config value from the UiConfig section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(UiConfigOption option, out bool value) => this.UiConfig.TryGet(option.GetName(), out value); - /// - /// Attempts to get a uint config value from the UiConfig section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(UiConfigOption option, out uint value) => this.UiConfig.TryGet(option.GetName(), out value); - /// - /// Attempts to get a float config value from the UiConfig section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(UiConfigOption option, out float value) => this.UiConfig.TryGet(option.GetName(), out value); - /// - /// Attempts to get a string config value from the UiConfig section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(UiConfigOption option, out string value) => this.UiControl.TryGet(option.GetName(), out value); - /// - /// Attempts to get a boolean config value from the UiControl section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(UiControlOption option, out bool value) => this.UiControl.TryGet(option.GetName(), out value); - /// - /// Attempts to get a uint config value from the UiControl section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(UiControlOption option, out uint value) => this.UiControl.TryGet(option.GetName(), out value); - /// - /// Attempts to get a float config value from the UiControl section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(UiControlOption option, out float value) => this.UiControl.TryGet(option.GetName(), out value); - /// - /// Attempts to get a string config value from the UiControl section. - /// - /// Option to get the value of. - /// The returned value of the config option. - /// A value representing the success. + /// public bool TryGet(UiControlOption option, out string value) => this.System.TryGet(option.GetName(), out value); - - /// - /// Set a boolean config option in the System config section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + + /// public void Set(SystemConfigOption option, bool value) => this.System.Set(option.GetName(), value); - /// - /// Set a unsigned integer config option in the System config section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + /// public void Set(SystemConfigOption option, uint value) => this.System.Set(option.GetName(), value); - /// - /// Set a float config option in the System config section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + /// public void Set(SystemConfigOption option, float value) => this.System.Set(option.GetName(), value); - /// - /// Set a string config option in the System config section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + /// public void Set(SystemConfigOption option, string value) => this.System.Set(option.GetName(), value); - /// - /// Set a boolean config option in the UiConfig section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + /// public void Set(UiConfigOption option, bool value) => this.UiConfig.Set(option.GetName(), value); - - /// - /// Set a unsigned integer config option in the UiConfig section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + + /// public void Set(UiConfigOption option, uint value) => this.UiConfig.Set(option.GetName(), value); - /// - /// Set a float config option in the UiConfig section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + /// public void Set(UiConfigOption option, float value) => this.UiConfig.Set(option.GetName(), value); - /// - /// Set a string config option in the UiConfig section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + /// public void Set(UiConfigOption option, string value) => this.UiConfig.Set(option.GetName(), value); - - /// - /// Set a boolean config option in the UiControl config section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + + /// public void Set(UiControlOption option, bool value) => this.UiControl.Set(option.GetName(), value); - - /// - /// Set a uint config option in the UiControl config section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + + /// public void Set(UiControlOption option, uint value) => this.UiControl.Set(option.GetName(), value); - - /// - /// Set a float config option in the UiControl config section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + + /// public void Set(UiControlOption option, float value) => this.UiControl.Set(option.GetName(), value); - - /// - /// Set a string config option in the UiControl config section. - /// Note: Not all config options will be be immediately reflected in the game. - /// - /// Name of the config option. - /// New value of the config option. - /// Throw if the config option is not found. - /// Thrown if the name of the config option is found, but the struct was not. + + /// public void Set(UiControlOption option, string value) => this.UiControl.Set(option.GetName(), value); } diff --git a/Dalamud/Plugin/Services/IGameConfig.cs b/Dalamud/Plugin/Services/IGameConfig.cs new file mode 100644 index 000000000..bbff123c0 --- /dev/null +++ b/Dalamud/Plugin/Services/IGameConfig.cs @@ -0,0 +1,242 @@ +using System.Diagnostics; + +using Dalamud.Game.Config; + +namespace Dalamud.Plugin.Services; + +/// +/// This class represents the game's configuration. +/// +public interface IGameConfig +{ + /// + /// Gets the collection of config options that persist between characters. + /// + public GameConfigSection System { get; } + + /// + /// Gets the collection of config options that are character specific. + /// + public GameConfigSection UiConfig { get; } + + /// + /// Gets the collection of config options that are control mode specific. (Mouse and Keyboard / Gamepad). + /// + public GameConfigSection UiControl { get; } + + /// + /// Attempts to get a boolean config value from the System section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(SystemConfigOption option, out bool value); + + /// + /// Attempts to get a uint config value from the System section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(SystemConfigOption option, out uint value); + + /// + /// Attempts to get a float config value from the System section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(SystemConfigOption option, out float value); + + /// + /// Attempts to get a string config value from the System section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(SystemConfigOption option, out string value); + + /// + /// Attempts to get a boolean config value from the UiConfig section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(UiConfigOption option, out bool value); + + /// + /// Attempts to get a uint config value from the UiConfig section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(UiConfigOption option, out uint value); + + /// + /// Attempts to get a float config value from the UiConfig section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(UiConfigOption option, out float value); + + /// + /// Attempts to get a string config value from the UiConfig section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(UiConfigOption option, out string value); + + /// + /// Attempts to get a boolean config value from the UiControl section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(UiControlOption option, out bool value); + + /// + /// Attempts to get a uint config value from the UiControl section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(UiControlOption option, out uint value); + + /// + /// Attempts to get a float config value from the UiControl section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(UiControlOption option, out float value); + + /// + /// Attempts to get a string config value from the UiControl section. + /// + /// Option to get the value of. + /// The returned value of the config option. + /// A value representing the success. + public bool TryGet(UiControlOption option, out string value); + + /// + /// Set a boolean config option in the System config section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(SystemConfigOption option, bool value); + + /// + /// Set a unsigned integer config option in the System config section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(SystemConfigOption option, uint value); + + /// + /// Set a float config option in the System config section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(SystemConfigOption option, float value); + + /// + /// Set a string config option in the System config section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(SystemConfigOption option, string value); + + /// + /// Set a boolean config option in the UiConfig section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(UiConfigOption option, bool value); + + /// + /// Set a unsigned integer config option in the UiConfig section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(UiConfigOption option, uint value); + + /// + /// Set a float config option in the UiConfig section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(UiConfigOption option, float value); + + /// + /// Set a string config option in the UiConfig section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(UiConfigOption option, string value); + + /// + /// Set a boolean config option in the UiControl config section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(UiControlOption option, bool value); + + /// + /// Set a uint config option in the UiControl config section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(UiControlOption option, uint value); + + /// + /// Set a float config option in the UiControl config section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(UiControlOption option, float value); + + /// + /// Set a string config option in the UiControl config section. + /// Note: Not all config options will be be immediately reflected in the game. + /// + /// Name of the config option. + /// New value of the config option. + /// Throw if the config option is not found. + /// Thrown if the name of the config option is found, but the struct was not. + public void Set(UiControlOption option, string value); +}