From fc4f3d1aa064aab77b4d545df309b641634f007f Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:37:41 -0500 Subject: [PATCH] some minor improvements --- MiraAPI/GameOptions/AbstractOptionGroup.cs | 2 -- MiraAPI/GameOptions/ModdedArray.cs | 10 +--------- MiraAPI/GameOptions/ModdedOptionsManager.cs | 12 ++++++++++-- .../OptionTypes/ModdedBaseStringOption.cs | 3 ++- MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs | 4 ++-- .../GameOptions/OptionTypes/ModdedNumberOption.cs | 11 ++++------- MiraAPI/GameOptions/OptionTypes/ModdedOption.cs | 8 +++++--- .../GameOptions/OptionTypes/ModdedPlayerOption.cs | 12 ++++++++---- .../GameOptions/OptionTypes/ModdedStringOption.cs | 7 ++++--- MiraAPI/Modifiers/BaseModifier.cs | 2 -- MiraAPI/Roles/CustomRoleConfiguration.cs | 4 ---- 11 files changed, 36 insertions(+), 39 deletions(-) diff --git a/MiraAPI/GameOptions/AbstractOptionGroup.cs b/MiraAPI/GameOptions/AbstractOptionGroup.cs index a8e74250..072d6f81 100644 --- a/MiraAPI/GameOptions/AbstractOptionGroup.cs +++ b/MiraAPI/GameOptions/AbstractOptionGroup.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using Il2CppInterop.Runtime.Attributes; using MiraAPI.Modifiers; using MiraAPI.Roles; using MiraAPI.Utilities; @@ -46,7 +45,6 @@ public abstract class AbstractOptionGroup /// /// Gets the sprite of the group that is displayed in the match info guide. /// - [HideFromIl2Cpp] public virtual LoadableAsset Sprite => MiraAssets.IconSettings; /// diff --git a/MiraAPI/GameOptions/ModdedArray.cs b/MiraAPI/GameOptions/ModdedArray.cs index 01e4e0fd..4d4c070d 100644 --- a/MiraAPI/GameOptions/ModdedArray.cs +++ b/MiraAPI/GameOptions/ModdedArray.cs @@ -55,15 +55,6 @@ public sealed class ModdedArray : IList, IReadOnlyList, IList, IModdedA items = [.. collection]; } - /// - /// Initializes a new instance of the class with initial values. - /// - /// The initial span of values to initialise with. - public ModdedArray(Span span) - { - items = [.. span]; - } - /// /// Initializes a new instance of the class with initial values. /// @@ -178,6 +169,7 @@ public sealed class ModdedArray : IList, IReadOnlyList, IList, IModdedA { listAttribute = attribute; typedAttribute = attribute as ITypedOptionList; + Refresh(); } /// diff --git a/MiraAPI/GameOptions/ModdedOptionsManager.cs b/MiraAPI/GameOptions/ModdedOptionsManager.cs index bf5921e9..c7f607cc 100644 --- a/MiraAPI/GameOptions/ModdedOptionsManager.cs +++ b/MiraAPI/GameOptions/ModdedOptionsManager.cs @@ -397,8 +397,16 @@ public static class ModdedOptionsManager continue; } - option.ShowNotification = showNotifs; - option.HandleNetData(netData.Data); + try + { + option.ShowNotification = showNotifs; + option.HandleNetData(netData.Data); + } + catch (Exception e) + { + option.ShowNotification = true; + Error(e); + } } foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedBaseStringOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedBaseStringOption.cs index 84d67cd1..447ecaea 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedBaseStringOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedBaseStringOption.cs @@ -60,7 +60,7 @@ public abstract class ModdedBaseStringOption(string groupPrefix, string title var index = Array.IndexOf(UnderlyingValues, value); if (index == -1) - Info($"Cannot find a valid index for {value}. Returning -1 instead. Values: {string.Join(", ", Values)}"); + Warning($"Cannot find a valid index for {value}. Returning -1 instead. Values: {string.Join(", ", Values)}"); return index; } @@ -120,6 +120,7 @@ public abstract class ModdedBaseStringOption(string groupPrefix, string title if ((uint)index < (uint)UnderlyingValues.Length) return UnderlyingValues[index]; + Warning($"Received an index {index} when there wasn't enough values (Length: {UnderlyingValues.Length})"); return UnderlyingValues.Length > 0 ? UnderlyingValues[0] : default!; } } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs index 4149c864..0aa2a45f 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs @@ -111,7 +111,7 @@ public class ModdedEnumOption : ModdedBaseEnumOption } /// - protected internal override ConfigDescription? CreateDescription() + protected override ConfigDescription? CreateDescription() { return new(string.Empty, new AcceptableValueList(UnderlyingValues)); } @@ -197,7 +197,7 @@ public class ModdedEnumOption : ModdedBaseEnumOption } /// - protected internal override ConfigDescription? CreateDescription() + protected override ConfigDescription? CreateDescription() { return new(string.Empty, new AcceptableEnumValues(UnderlyingValues)); } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs index e3d22578..532b256b 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs @@ -93,7 +93,7 @@ public class ModdedNumberOption : ModdedOption string? formatString = null, bool halfIncrements = false, bool includeInPreset = true) - : base(groupPrefix, title, defaultValue, includeInPreset) + : base(groupPrefix, title, Math.Clamp(defaultValue, min, max), includeInPreset) { Min = min; Max = max; @@ -102,15 +102,12 @@ public class ModdedNumberOption : ModdedOption ZeroWordValue = zeroBehavior; ShiftIncrement = halfIncrements; NegativeWordValue = negativeBehavior; - IsInt = defaultValue.IsInteger() && + IsInt = DefaultValue.IsInteger() && Increment.IsInteger() && - Value.IsInteger() && Min.IsInteger() && Max.IsInteger(); FormatString = formatString ?? (IsInt ? "0" : "0.0"); - Value = Mathf.Clamp(defaultValue, min, max); - if (IsInt) { var data = ScriptableObject.CreateInstance(); @@ -297,7 +294,7 @@ public class ModdedNumberOption : ModdedOption /// public override float GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour) { - return Mathf.Clamp(optionBehaviour.GetFloat(), Min, Max); + return Math.Clamp(optionBehaviour.GetFloat(), Min, Max); } /// @@ -316,7 +313,7 @@ public class ModdedNumberOption : ModdedOption } /// - protected internal override ConfigDescription? CreateDescription() + protected override ConfigDescription? CreateDescription() { return new(string.Empty, new AcceptableValueRange(Min, Max)); } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index f8d4c596..fb565378 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -262,9 +262,11 @@ public abstract class ModdedOption(string groupPrefix, string title, T defaul return newValue; } -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member (Justification: Internal code.) - protected internal virtual ConfigDescription? CreateDescription() -#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member + /// + /// Creates a instance for the option's backing config. + /// + /// The option's config description, or null if there is none. + protected virtual ConfigDescription? CreateDescription() { return null; } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs index c6526ec0..f9ec5a00 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs @@ -67,8 +67,12 @@ public class ModdedPlayerOption : ModdedOption PlayerOption playerOpt, Transform container) { + var oldPlayer = GetPlayerValue(); Values = GetFilteredPlayers(); + var newIndex = oldPlayer ? Values.IndexOf(oldPlayer!) : -1; + Value = newIndex >= 0 ? newIndex : (AllowNone ? -1 : 0); + var playerOption = Object.Instantiate(playerOpt, container); playerOption.name = $"{ParentMod!.OptionsTitleText}.PlayerOption.{Title}"; @@ -78,7 +82,7 @@ public class ModdedPlayerOption : ModdedOption playerOption.Title = StringName; playerOption.Values = Values.ToIl2CppList(); playerOption.Value = Value; - playerOption.playerIndex = Values.FindIndex(p => p.PlayerId == Value); + playerOption.playerIndex = Value; playerOption.OnValueChanged = (Action)ValueChanged; playerOption.SetValueText(); @@ -153,8 +157,8 @@ public class ModdedPlayerOption : ModdedOption public override string GetDisplayValue() { var player = GetPlayerValue(); - return !player - ? TranslationController.Instance.GetString(StringNames.None) - : player!.PlayerName; + return player + ? player!.PlayerName + : TranslationController.Instance.GetString(StringNames.None); } } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs index 0095ca9d..868d165b 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs @@ -1,5 +1,4 @@ using System; -using System.Globalization; using System.Linq; using System.Text; using BepInEx.Configuration; @@ -54,6 +53,8 @@ public class ModdedStringOption : ModdedBaseStringOption [Obsolete("Use the Setter feature of modded options to simulate conditional values. This wil be removed in a future version.")] public void RegisterExtraValue(string value, int index = -1) { + Warning("Use the Setter feature of modded options to simulate conditional values."); + if (!Values.Contains(value)) { if (index <= -1) @@ -97,7 +98,7 @@ public class ModdedStringOption : ModdedBaseStringOption /// public override NetData GetNetData() { - return new NetData(Id, Encoding.Unicode.GetBytes(Convert.ToString(Value, NumberFormatInfo.InvariantInfo))); + return new NetData(Id, Encoding.Unicode.GetBytes(Value)); } /// @@ -107,7 +108,7 @@ public class ModdedStringOption : ModdedBaseStringOption } /// - protected internal override ConfigDescription? CreateDescription() + protected override ConfigDescription? CreateDescription() { return new(string.Empty, new AcceptableValueList(UnderlyingValues)); } diff --git a/MiraAPI/Modifiers/BaseModifier.cs b/MiraAPI/Modifiers/BaseModifier.cs index 10931ec9..4a4cac58 100644 --- a/MiraAPI/Modifiers/BaseModifier.cs +++ b/MiraAPI/Modifiers/BaseModifier.cs @@ -171,7 +171,6 @@ public abstract class BaseModifier : IOptionable /// /// Gets the list of abilities or other similar information to display below the text of a modifier's wiki page. /// - [HideFromIl2Cpp] public virtual List WikiAbilities => []; /// @@ -182,7 +181,6 @@ public abstract class BaseModifier : IOptionable /// /// Gets the for the Modifier Icon. /// - [HideFromIl2Cpp] public virtual TMP_SpriteAsset IconTmp => null!; /// diff --git a/MiraAPI/Roles/CustomRoleConfiguration.cs b/MiraAPI/Roles/CustomRoleConfiguration.cs index 46fc3bde..68edebee 100644 --- a/MiraAPI/Roles/CustomRoleConfiguration.cs +++ b/MiraAPI/Roles/CustomRoleConfiguration.cs @@ -81,25 +81,21 @@ public record struct CustomRoleConfiguration /// /// Gets or sets the used for the Role Options menu screenshot. /// - [HideFromIl2Cpp] public LoadableAsset? OptionsScreenshot { get; set; } = null; /// /// Gets or sets the used for the Role Icon. /// - [HideFromIl2Cpp] public LoadableAsset? Icon { get; set; } = null; /// /// Gets or sets the for the Role Icon. /// - [HideFromIl2Cpp] public TMP_SpriteAsset IconTmp { get; set; } /// /// Gets or sets the Intro sound for the Role. /// - [HideFromIl2Cpp] public LoadableAsset? IntroSound { get; set; } = null; ///