diff --git a/src/Modules/AntiCheat/RPCHandlers/SetLevelHandler.cs b/src/Modules/AntiCheat/RPCHandlers/SetLevelHandler.cs index 85e8c01..cb77f2c 100644 --- a/src/Modules/AntiCheat/RPCHandlers/SetLevelHandler.cs +++ b/src/Modules/AntiCheat/RPCHandlers/SetLevelHandler.cs @@ -34,7 +34,7 @@ internal sealed class SetLevelHandler : RPCHandler { uint level = reader.ReadPackedUInt32() + 1; - if (level > BetterGameSettings.DetectedLevelAbove.GetInt()) + if (BetterGameSettings.DetectedLevel.GetBool() && level > BetterGameSettings.DetectedLevelAbove.GetInt()) { if (BetterNotificationManager.NotifyCheat(sender, TranslationStrings.AntiCheat_InvalidLevelRPC.Format(level))) { diff --git a/src/Modules/OptionItems/NoneOption/OptionDividerItem.cs b/src/Modules/OptionItems/NoneOption/OptionDividerItem.cs index e54b963..bfce6b3 100644 --- a/src/Modules/OptionItems/NoneOption/OptionDividerItem.cs +++ b/src/Modules/OptionItems/NoneOption/OptionDividerItem.cs @@ -63,13 +63,13 @@ internal sealed class OptionDividerItem : OptionItem Tab.Children.Add(this); } - /// - /// Gets the string representation of the divider value (not applicable). - /// - /// NotImplementedException as dividers don't have values. - /// Always thrown since dividers have no values. public sealed override string ValueAsString() { throw new NotImplementedException(); } + + public override object GetBoxedValue() + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Modules/OptionItems/NoneOption/OptionHeaderItem.cs b/src/Modules/OptionItems/NoneOption/OptionHeaderItem.cs index 481a8e4..3344655 100644 --- a/src/Modules/OptionItems/NoneOption/OptionHeaderItem.cs +++ b/src/Modules/OptionItems/NoneOption/OptionHeaderItem.cs @@ -85,13 +85,13 @@ internal sealed class OptionHeaderItem : OptionItem } } - /// - /// Gets the string representation of the header value (not applicable). - /// - /// NotImplementedException as headers don't have values. - /// Always thrown since headers have no values. public sealed override string ValueAsString() { throw new NotImplementedException(); } + + public override object GetBoxedValue() + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Modules/OptionItems/NoneOption/OptionTitleItem.cs b/src/Modules/OptionItems/NoneOption/OptionTitleItem.cs index 382e64f..239c64e 100644 --- a/src/Modules/OptionItems/NoneOption/OptionTitleItem.cs +++ b/src/Modules/OptionItems/NoneOption/OptionTitleItem.cs @@ -94,13 +94,13 @@ internal sealed class OptionTitleItem : OptionItem } } - /// - /// Gets the string representation of the title value (not applicable). - /// - /// NotImplementedException as headers don't have values. - /// Always thrown since headers have no values. public sealed override string ValueAsString() { throw new NotImplementedException(); } + + public override object GetBoxedValue() + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/Modules/OptionItems/OptionCheckboxItem.cs b/src/Modules/OptionItems/OptionCheckboxItem.cs index 4a34bd3..a3a8d4a 100644 --- a/src/Modules/OptionItems/OptionCheckboxItem.cs +++ b/src/Modules/OptionItems/OptionCheckboxItem.cs @@ -20,11 +20,11 @@ public sealed class OptionCheckboxItem : OptionItem /// /// The unique identifier for this option. /// The tab this option belongs to. - /// The translation key for the option name. + /// The translation key for the option name. /// The default value for the checkbox. /// Optional parent option for hierarchical organization. /// A new or existing OptionCheckboxItem instance. - internal static OptionCheckboxItem Create(int id, OptionTab tab, TranslationStrings.TranslationString tranStr, bool defaultValue, OptionItem? parent = null) + internal static OptionCheckboxItem Create(int id, OptionTab tab, TranslationStrings.TranslationString translationString, bool defaultValue, OptionItem? parent = null) { if (GetOptionById(id) is OptionCheckboxItem checkboxItem) { @@ -36,7 +36,7 @@ public sealed class OptionCheckboxItem : OptionItem AllOptions.Add(Item); Item._id = id; Item.Tab = tab; - Item.TranslationName = tranStr; + Item.TranslationName = translationString; Item.DefaultValue = defaultValue; if (parent != null) @@ -118,12 +118,12 @@ public sealed class OptionCheckboxItem : OptionItem /// Gets the boolean value of this checkbox option. /// /// The current boolean value. - public sealed override bool GetBool() => GetValue(); + public bool GetBool() => GetValue(); /// /// Checks if the checkbox value matches a specific boolean. /// - /// The boolean value to compare against. + /// The boolean value to compare against. /// True if the checkbox value matches, false otherwise. - public sealed override bool Is(bool @bool) => @bool == GetBool(); + public sealed override bool Is(bool value) => value == GetBool(); } \ No newline at end of file diff --git a/src/Modules/OptionItems/OptionFloatItem.cs b/src/Modules/OptionItems/OptionFloatItem.cs index 8297f53..f6fc589 100644 --- a/src/Modules/OptionItems/OptionFloatItem.cs +++ b/src/Modules/OptionItems/OptionFloatItem.cs @@ -40,14 +40,14 @@ public class OptionFloatItem : OptionItem /// /// The unique identifier for this option. /// The tab this option belongs to. - /// The translation key for the option name. + /// The translation key for the option name. /// Tuple containing min value, max value, and increment step. /// The default value for the option. /// Tuple containing prefix and postfix strings for display. /// Optional parent option for hierarchical organization. /// Whether this option can represent infinite values. /// A new or existing OptionFloatItem instance. - internal static OptionFloatItem Create(int id, OptionTab tab, TranslationStrings.TranslationString tranStr, (float minValue, float maxValue, float incrementValue) Min_Max_Increment, float defaultValue, (string prefix, string postfix) Prefix_Postfix = new(), OptionItem? parent = null, bool canBeInfinite = false) + internal static OptionFloatItem Create(int id, OptionTab tab, TranslationStrings.TranslationString translationString, (float minValue, float maxValue, float incrementValue) Min_Max_Increment, float defaultValue, (string prefix, string postfix) Prefix_Postfix = new(), OptionItem? parent = null, bool canBeInfinite = false) { if (GetOptionById(id) is OptionFloatItem floatItem) { @@ -59,7 +59,7 @@ public class OptionFloatItem : OptionItem AllOptions.Add(Item); Item._id = id; Item.Tab = tab; - Item.TranslationName = tranStr; + Item.TranslationName = translationString; Item.Increment = Min_Max_Increment.incrementValue; Item.CanBeInfinite = canBeInfinite; Item.Range = new FloatRange(Min_Max_Increment.minValue, Min_Max_Increment.maxValue); @@ -209,19 +209,12 @@ public class OptionFloatItem : OptionItem /// Gets the float value of this option. /// /// The current float value. - public override float GetFloat() => GetValue(); + public float GetFloat() => GetValue(); /// /// Checks if the option value matches a specific float. /// - /// The float value to compare against. + /// The float value to compare against. /// True if the option value matches, false otherwise. - public override bool Is(float @float) => @float == GetFloat(); - - /// - /// Checks if the option value matches a specific integer. - /// - /// The integer value to compare against. - /// True if the option value matches (as float), false otherwise. - public override bool Is(int @int) => @int == GetFloat(); + public override bool Is(float value) => value == GetFloat(); } \ No newline at end of file diff --git a/src/Modules/OptionItems/OptionIntItem.cs b/src/Modules/OptionItems/OptionIntItem.cs index ca4e24f..3a7e350 100644 --- a/src/Modules/OptionItems/OptionIntItem.cs +++ b/src/Modules/OptionItems/OptionIntItem.cs @@ -40,14 +40,14 @@ public sealed class OptionIntItem : OptionItem /// /// The unique identifier for this option. /// The tab this option belongs to. - /// The translation key for the option name. + /// The translation key for the option name. /// Tuple containing min value, max value, and increment step. /// The default value for the option. /// Tuple containing prefix and postfix strings for display. /// Optional parent option for hierarchical organization. /// Whether this option can represent infinite values. /// A new or existing OptionIntItem instance. - internal static OptionIntItem Create(int id, OptionTab tab, TranslationStrings.TranslationString tranStr, (int minValue, int maxValue, int incrementValue) Min_Max_Increment, int defaultValue, (string prefix, string postfix) Prefix_Postfix = new(), OptionItem? parent = null, bool canBeInfinite = false) + internal static OptionIntItem Create(int id, OptionTab tab, TranslationStrings.TranslationString translationString, (int minValue, int maxValue, int incrementValue) Min_Max_Increment, int defaultValue, (string prefix, string postfix) Prefix_Postfix = new(), OptionItem? parent = null, bool canBeInfinite = false) { if (GetOptionById(id) is OptionIntItem intItem) { @@ -59,7 +59,7 @@ public sealed class OptionIntItem : OptionItem AllOptions.Add(Item); Item._id = id; Item.Tab = tab; - Item.TranslationName = tranStr; + Item.TranslationName = translationString; Item.Increment = Min_Max_Increment.incrementValue; Item.CanBeInfinite = canBeInfinite; Item.Range = new IntRange(Min_Max_Increment.minValue, Min_Max_Increment.maxValue); @@ -209,25 +209,12 @@ public sealed class OptionIntItem : OptionItem /// Gets the integer value of this option. /// /// The current integer value. - public sealed override int GetInt() => GetValue(); - - /// - /// Gets the float representation of the integer value. - /// - /// The current integer value as a float. - public sealed override float GetFloat() => GetValue(); + public int GetInt() => GetValue(); /// /// Checks if the option value matches a specific integer. /// - /// The integer value to compare against. + /// The integer value to compare against. /// True if the option value matches, false otherwise. - public sealed override bool Is(int @int) => @int == GetInt(); - - /// - /// Checks if the option value matches a specific float. - /// - /// The float value to compare against. - /// True if the option value matches (as integer), false otherwise. - public sealed override bool Is(float @float) => @float == GetFloat(); + public sealed override bool Is(int value) => value == GetInt(); } \ No newline at end of file diff --git a/src/Modules/OptionItems/OptionItem.cs b/src/Modules/OptionItems/OptionItem.cs index feb48c6..9ed6eab 100644 --- a/src/Modules/OptionItems/OptionItem.cs +++ b/src/Modules/OptionItems/OptionItem.cs @@ -20,24 +20,63 @@ public abstract class OptionItem internal const string InfiniteIcon = "∞"; internal virtual bool CanLoad => true; internal virtual bool IsOption => true; + + /// + /// Gets the localized display name of the option. + /// public string Name => TranslationName != null ? TranslationName.Value.LocalizedString : string.Empty; + + /// + /// Gets the unique identifier of the option. + /// public int Id => _id ?? -1; + protected int? _id { get; set; } = null; protected TranslationStrings.TranslationString? TranslationName { get; set; } = null; internal OptionTab? Tab { get; set; } internal OptionBehaviour? Option { get; set; } internal GameObject? Obj { get; set; } internal OptionItem? Parent { get; set; } + + /// + /// Gets a value indicating whether this option has child options. + /// internal bool IsParent => Children.Count > 0; + internal List Children { get; set; } = []; internal virtual bool Show => ShowCondition.Invoke(); internal virtual bool ShowChildren => Show; internal Func? ShowCondition = () => { return true; }; internal bool Hide => !Show || GetParents().Any(opt => !opt.ShowChildren) || BAUModdedSupportFlags.HasFlag(BAUModdedSupportFlags.Disable_GameOption + TranslationName); + + /// + /// Retrieves an option by its unique identifier. + /// + /// The unique identifier of the option. + /// The option with the specified ID, or null if not found. internal static OptionItem? GetOptionById(int id) => AllOptions.FirstOrDefault(opt => opt._id == id); + + /// + /// Updates the visual appearance of the option. + /// + /// Whether to update the parent tab visuals. internal virtual void UpdateVisuals(bool updateTabVisuals = true) { } + + /// + /// Gets the string representation of the current option value. + /// + /// The value as a string. public abstract string ValueAsString(); + + /// + /// Attempts to load the option's value from persistent storage. + /// + /// If true, forces reload even if already loaded. internal virtual void TryLoad(bool forceLoad = false) { } + + /// + /// Resets the option to its default value. + /// internal virtual void SetToDefault() { } /// @@ -63,7 +102,7 @@ public abstract class OptionItem /// /// Displays a notification with the option's current value or custom text. /// - /// Custom text to display instead of the value. + /// Optional custom text to display instead of the value. internal void PopNotification(string custom = "") { if (_id == null) @@ -78,7 +117,7 @@ public abstract class OptionItem /// /// Gets the hierarchical path of parent options leading to this option. /// - /// A formatted string showing the option hierarchy. + /// A formatted string showing the option hierarchy path. internal string GetParentPath() { List names = [Name ?? "???"]; @@ -115,7 +154,7 @@ public abstract class OptionItem } /// - /// Gets the child index depth of this option in the hierarchy. + /// Gets the depth level of this option in the hierarchy. /// /// The depth level (0 for root options). internal int GetChildIndex() @@ -131,9 +170,9 @@ public abstract class OptionItem } /// - /// Generates a text tree representation of the option hierarchy. + /// Generates a text tree representation of the option hierarchy starting from this option. /// - /// Text size percentage. + /// Text size percentage (default 50%). /// Whether to show child options for percent items. /// A formatted string showing the option tree structure. internal string FormatOptionsToTextTree(float size = 50f, bool showForPercentOption = true) @@ -205,8 +244,8 @@ public abstract class OptionItem /// /// Generates text tree representations for multiple option hierarchies. /// - /// Array of root option items. - /// Text size percentage. + /// Array of root option items to display. + /// Text size percentage (default 50%). /// Whether to show child options for percent items. /// A formatted string showing all option tree structures. internal static string FormatOptionsToTextTrees(OptionItem?[] optionItems, float size = 50f, bool showForPercentOption = true) @@ -315,88 +354,10 @@ public abstract class OptionItem } /// - /// Gets the boolean value of the option (for CheckboxOption). + /// Gets the boxed value of this option. /// - /// The boolean value. - /// Thrown when the option type doesn't support boolean values. - public virtual bool GetBool() - { - throw new NotImplementedException(); - } - - /// - /// Gets the float value of the option (for FloatOption). - /// - /// The float value. - /// Thrown when the option type doesn't support float values. - public virtual float GetFloat() - { - throw new NotImplementedException(); - } - - /// - /// Gets the integer value of the option (for IntOption). - /// - /// The integer value. - /// Thrown when the option type doesn't support integer values. - public virtual int GetInt() - { - throw new NotImplementedException(); - } - - /// - /// Gets the string value index of the option (for StringOption and PlayerOption). - /// - /// The string value index. - /// Thrown when the option type doesn't support string values. - public virtual int GetStringValue() - { - throw new NotImplementedException(); - } - - /// - /// Checks if the option's value matches a specific boolean. - /// - /// The boolean value to check against. - /// True if the option value matches, false otherwise. - /// Thrown when the option type doesn't support boolean comparison. - public virtual bool Is(bool @bool) - { - throw new NotImplementedException(); - } - - /// - /// Checks if the option's value matches a specific float. - /// - /// The float value to check against. - /// True if the option value matches, false otherwise. - /// Thrown when the option type doesn't support float comparison. - public virtual bool Is(float @float) - { - throw new NotImplementedException(); - } - - /// - /// Checks if the option's value matches a specific integer. - /// - /// The integer value to check against. - /// True if the option value matches, false otherwise. - /// Thrown when the option type doesn't support integer comparison. - public virtual bool Is(int @int) - { - throw new NotImplementedException(); - } - - /// - /// Checks if the option's value matches a specific string. - /// - /// The string value to check against. - /// True if the option value matches, false otherwise. - /// Thrown when the option type doesn't support string comparison. - public virtual bool Is(string @string) - { - throw new NotImplementedException(); - } + /// The option value as an object. + public abstract object GetBoxedValue(); /// /// Represents a node in the option hierarchy tree for text formatting. @@ -436,6 +397,20 @@ public abstract class OptionItem : OptionItem private bool HasLoadValue { get; set; } protected T? Value { get; set; } = default; protected T? DefaultValue { get; set; } = default; + + /// + /// Gets the boxed value of this option. + /// + /// The option value as an object. + public override sealed object GetBoxedValue() + { + return GetValue(); + } + + /// + /// Gets the current value of the option. + /// + /// The current value, or the default value if the option is disabled. public virtual T? GetValue() { if (BAUModdedSupportFlags.HasFlag(BAUModdedSupportFlags.Disable_GameOption + TranslationName)) @@ -445,16 +420,41 @@ public abstract class OptionItem : OptionItem return Value; } + + /// + /// Gets the default value of the option. + /// + /// The default value. internal virtual T? GetDefaultValue() => DefaultValue; + + /// + /// Gets the string representation of the current value. + /// + /// The value as a string, or an empty string if null. public override string ValueAsString() => Value?.ToString() ?? string.Empty; + + /// + /// Resets the option to its default value. + /// internal override void SetToDefault() { Value = DefaultValue; } + + /// + /// Creates the UI behavior for this option. + /// protected abstract void CreateBehavior(); + + /// + /// Called when the option value changes. + /// + /// The previous value. + /// The new value. internal virtual void OnValueChange(T oldValue, T newValue) { } + internal Action? OnValueChangeAction = (opt) => { }; /// @@ -511,6 +511,13 @@ public abstract class OptionItem : OptionItem UpdateVisuals(); } + /// + /// Checks if the option's value matches the specified value. + /// + /// The value to compare against. + /// True if the option value matches, false otherwise. + public abstract bool Is(T value); + /// /// Sets the option's value and triggers updates and notifications. /// @@ -529,7 +536,7 @@ public abstract class OptionItem : OptionItem /// /// Attempts to load the option's value from persistent storage. /// - /// Whether to force reload even if already loaded. + /// If true, forces reload even if already loaded. internal override void TryLoad(bool forceLoad = false) { if (!CanLoad) diff --git a/src/Modules/OptionItems/OptionPercentItem.cs b/src/Modules/OptionItems/OptionPercentItem.cs index 8bf0496..13d0b42 100644 --- a/src/Modules/OptionItems/OptionPercentItem.cs +++ b/src/Modules/OptionItems/OptionPercentItem.cs @@ -12,11 +12,11 @@ public sealed class OptionPercentItem : OptionFloatItem /// /// The unique identifier for this option. /// The tab this option belongs to. - /// The translation key for the option name. + /// The translation key for the option name. /// The default percentage value (0-100). /// Optional parent option for hierarchical organization. /// A new or existing OptionPercentItem instance. - internal static OptionPercentItem Create(int id, OptionTab tab, TranslationStrings.TranslationString tranStr, float defaultValue, OptionItem? parent = null) + internal static OptionPercentItem Create(int id, OptionTab tab, TranslationStrings.TranslationString translationString, float defaultValue, OptionItem? parent = null) { if (GetOptionById(id) is OptionPercentItem floatItem) { @@ -28,7 +28,7 @@ public sealed class OptionPercentItem : OptionFloatItem AllOptions.Add(Item); Item._id = id; Item.Tab = tab; - Item.TranslationName = tranStr; + Item.TranslationName = translationString; Item.Increment = 5; Item.Range = new FloatRange(0f, 100f); Item.DefaultValue = defaultValue; diff --git a/src/Modules/OptionItems/OptionPlayerItem.cs b/src/Modules/OptionItems/OptionPlayerItem.cs index 52f59b6..c8391c3 100644 --- a/src/Modules/OptionItems/OptionPlayerItem.cs +++ b/src/Modules/OptionItems/OptionPlayerItem.cs @@ -42,11 +42,11 @@ public sealed class OptionPlayerItem : OptionItem /// /// The unique identifier for this option. /// The tab this option belongs to. - /// The translation key for the option name. + /// The translation key for the option name. /// Optional parent option for hierarchical organization. /// Whether this option allows random player selection. /// A new or existing OptionPlayerItem instance. - internal static OptionPlayerItem Create(int id, OptionTab tab, TranslationStrings.TranslationString tranStr, OptionItem? parent = null, bool canBeRandom = true) + internal static OptionPlayerItem Create(int id, OptionTab tab, TranslationStrings.TranslationString translationString, OptionItem? parent = null, bool canBeRandom = true) { if (optionPlayerItems.FirstOrDefault(opt => opt.Id == id) is OptionPlayerItem playerItem) { @@ -59,7 +59,7 @@ public sealed class OptionPlayerItem : OptionItem Item.Value = canBeRandom ? -1 : 0; ; Item._id = id; Item.Tab = tab; - Item.TranslationName = tranStr; + Item.TranslationName = translationString; Item.CanBeRandom = canBeRandom; if (parent != null) @@ -256,27 +256,12 @@ public sealed class OptionPlayerItem : OptionItem /// Gets the integer value (player index) of this option. /// /// The current player index. - public sealed override int GetInt() => - GetValue(); - - /// - /// Gets the float representation of the player index. - /// - /// The current player index as a float. - public sealed override float GetFloat() => - GetValue(); + public int GetInt() => GetValue(); /// /// Checks if the option value matches a specific integer. /// - /// The integer value to compare against. + /// The integer value to compare against. /// True if the option value matches, false otherwise. - public sealed override bool Is(int @int) => @int == GetInt(); - - /// - /// Checks if the option value matches a specific float. - /// - /// The float value to compare against. - /// True if the option value matches (as integer), false otherwise. - public sealed override bool Is(float @float) => @float == GetFloat(); + public sealed override bool Is(int value) => value == GetInt(); } \ No newline at end of file diff --git a/src/Modules/OptionItems/OptionStringItem.cs b/src/Modules/OptionItems/OptionStringItem.cs index 3a747d1..eb99247 100644 --- a/src/Modules/OptionItems/OptionStringItem.cs +++ b/src/Modules/OptionItems/OptionStringItem.cs @@ -24,15 +24,15 @@ public class OptionStringItem : OptionItem /// /// The unique identifier for this option. /// The tab this option belongs to. - /// The translation key for the option name. - /// Array of translation keys for the selectable string values. + /// The translation key for the option name. + /// Array of translation keys for the selectable string values. /// The default index value. /// Optional parent option for hierarchical organization. /// A new or existing OptionStringItem instance. /// Thrown when tranStrings has less than 2 elements. - internal static OptionStringItem Create(int id, OptionTab tab, TranslationStrings.TranslationString tranStr, TranslationStrings.TranslationString[] tranStrings, int defaultValue, OptionItem? parent = null) + internal static OptionStringItem Create(int id, OptionTab tab, TranslationStrings.TranslationString translationStringName, TranslationStrings.TranslationString[] translationStrings, int defaultValue, OptionItem? parent = null) { - if (tranStrings.Length < 2) + if (translationStrings.Length < 2) { throw new ArgumentException("tranStrings must have more then 1 string!"); } @@ -47,9 +47,9 @@ public class OptionStringItem : OptionItem AllOptions.Add(Item); Item._id = id; Item.Tab = tab; - Item.TranslationName = tranStr; - Item.TranslatorStrings = tranStrings; - Item.Range = new IntRange(0, tranStrings.Length - 1); + Item.TranslationName = translationStringName; + Item.TranslatorStrings = translationStrings; + Item.Range = new IntRange(0, translationStrings.Length - 1); Item.DefaultValue = defaultValue; if (parent != null) @@ -160,29 +160,31 @@ public class OptionStringItem : OptionItem /// Gets the translated string representation of the current selection. /// /// The translated string for the current index. - public override string ValueAsString() => - Translator.GetString(TranslatorStrings[Value], showInvalid: false); + public string GetString() => Translator.GetString(TranslatorStrings[Value], showInvalid: false); /// - /// Gets the effective string value index, accounting for random selection. + /// Gets the current index value of the selected string option. /// - /// The actual string index (random if selected). - public sealed override int GetStringValue() - { - return GetValue(); - } + /// The current integer index value. + public int GetStringIndex() => GetValue(); + + /// + /// Gets the translated string representation of the current selection. + /// + /// The translated string for the current index. + public override string ValueAsString() => GetString(); /// /// Checks if the option's string value matches a specific string. /// - /// The string value to compare against. + /// The string value to compare against. /// True if the option value matches, false otherwise. - public sealed override bool Is(string @string) => TranslatorStrings[Value].Key == @string || ValueAsString() == @string; + public bool Is(string str) => TranslatorStrings[Value].Key == str || ValueAsString() == str; /// /// Checks if the option's index value matches a specific integer. /// - /// The integer value to compare against. + /// The integer value to compare against. /// True if the option value matches, false otherwise. - public sealed override bool Is(int @int) => Value == @int; + public sealed override bool Is(int value) => Value == value; } \ No newline at end of file diff --git a/src/Patches/Gameplay/Anticheat/CheckPlayerLevelPatch.cs b/src/Patches/Gameplay/Anticheat/CheckPlayerLevelPatch.cs index ee3147f..9f8abc9 100644 --- a/src/Patches/Gameplay/Anticheat/CheckPlayerLevelPatch.cs +++ b/src/Patches/Gameplay/Anticheat/CheckPlayerLevelPatch.cs @@ -1,6 +1,6 @@ -using BetterAmongUs.Utilities; -using BetterAmongUs.Modules; +using BetterAmongUs.Modules; using BetterAmongUs.Patches.Gameplay.UI.Settings; +using BetterAmongUs.Utilities; using HarmonyLib; namespace BetterAmongUs.Patches.Gameplay.Anticheat; @@ -18,7 +18,7 @@ internal class CheckPlayerLevelPatch if (GameState.IsHost && GameState.IsLobby) { // Kick players below minimum level - if (!__instance.IsLocalPlayer() && __instance.Data.PlayerLevel < BetterGameSettings.KickLevelBelow.GetInt()) + if (!__instance.IsLocalPlayer() && BetterGameSettings.KickLevel.GetBool() && __instance.Data.PlayerLevel < BetterGameSettings.KickLevelBelow.GetInt()) { __instance.Kick(setReasonInfo: $" is level {__instance.Data.PlayerLevel}, level must be equal or above {BetterGameSettings.KickLevelBelow.GetInt()} to join"); } diff --git a/src/Patches/Gameplay/Managers/RoleManagerPatch.cs b/src/Patches/Gameplay/Managers/RoleManagerPatch.cs index d6e98d9..40f6c52 100644 --- a/src/Patches/Gameplay/Managers/RoleManagerPatch.cs +++ b/src/Patches/Gameplay/Managers/RoleManagerPatch.cs @@ -1,11 +1,11 @@ using AmongUs.GameOptions; -using BetterAmongUs.Utilities; using BetterAmongUs.Modules; using BetterAmongUs.Modules.Support; using BetterAmongUs.Mono.Extended; using BetterAmongUs.Patches.Gameplay.UI.Settings; -using HarmonyLib; +using BetterAmongUs.Utilities; using BetterAmongUs.Utilities.Extension; +using HarmonyLib; namespace BetterAmongUs.Patches.Gameplay.Managers; @@ -319,7 +319,7 @@ internal static class RoleManagerPatch internal static int RNG() { // Choose random number generator based on settings - switch (BetterGameSettings.RoleRandomizer.GetStringValue()) + switch (BetterGameSettings.RoleRandomizer.GetStringIndex()) { case 1: return UnityEngine.Random.Range(0, 100); // Unity RNG diff --git a/src/Patches/Gameplay/UI/Settings/GameSettingsPatch.cs b/src/Patches/Gameplay/UI/Settings/GameSettingsPatch.cs index 795c64e..88efe1e 100644 --- a/src/Patches/Gameplay/UI/Settings/GameSettingsPatch.cs +++ b/src/Patches/Gameplay/UI/Settings/GameSettingsPatch.cs @@ -17,7 +17,9 @@ internal sealed class BetterGameSettings internal static OptionCheckboxItem? UseBanNameList; internal static OptionCheckboxItem? UseBanWordList; internal static OptionCheckboxItem? UseBanWordListOnlyLobby; + internal static OptionCheckboxItem? DetectedLevel; internal static OptionIntItem? DetectedLevelAbove; + internal static OptionCheckboxItem? KickLevel; internal static OptionIntItem? KickLevelBelow; internal static OptionCheckboxItem? DetectCheatClients; internal static OptionCheckboxItem? DetectInvalidRPCs; @@ -47,7 +49,7 @@ internal static class GameSettingsPatch // Creates all custom game settings and organizes them in tabs internal static void SetupSettings(bool IsPreload = false) { - // Note: Use 1800 next ID + // Note: Use 2000 next ID // Create main settings tab BetterSettingsTab = OptionTab.Create(3, TranslationStrings.BetterSetting, TranslationStrings.BetterSetting_Description, Color.green); @@ -73,11 +75,13 @@ internal static class GameSettingsPatch BetterGameSettings.UseBanWordListOnlyLobby = OptionCheckboxItem.Create(1400, BetterSettingsTab, TranslationStrings.BetterSetting_Setting_UseBanWordListOnlyLobby, true, BetterGameSettings.UseBanWordList); } - // General detection settings (visible to all) + // General detection settings OptionTitleItem.Create(BetterSettingsTab, TranslationStrings.BetterSetting_TextHeader_Detections); BetterGameSettings.CensorDetectionReason = OptionCheckboxItem.Create(1300, BetterSettingsTab, TranslationStrings.BetterSetting_Setting_CensorDetectionReason, false); - BetterGameSettings.DetectedLevelAbove = OptionIntItem.Create(600, BetterSettingsTab, TranslationStrings.BetterSetting_Setting_DetectedLevelAbove, (100, 10000, 5), 500, ("Lv ", "")); - BetterGameSettings.KickLevelBelow = OptionIntItem.Create(1700, BetterSettingsTab, TranslationStrings.BetterSetting_Setting_KickLevelBelow, (0, 10000, 1), 0, ("Lv ", "")); + BetterGameSettings.DetectedLevel = OptionCheckboxItem.Create(1800, BetterSettingsTab, TranslationStrings.BetterSetting_Setting_DetectedLevel, false); + BetterGameSettings.DetectedLevelAbove = OptionIntItem.Create(600, BetterSettingsTab, TranslationStrings.BetterSetting_Setting_DetectedLevelAbove, (100, 10000, 5), 500, ("Lv ", ""), BetterGameSettings.DetectedLevel); + BetterGameSettings.KickLevel = OptionCheckboxItem.Create(1900, BetterSettingsTab, TranslationStrings.BetterSetting_Setting_KickLevel, false); + BetterGameSettings.KickLevelBelow = OptionIntItem.Create(1700, BetterSettingsTab, TranslationStrings.BetterSetting_Setting_KickLevelBelow, (0, 10000, 1), 0, ("Lv ", ""), BetterGameSettings.KickLevel); BetterGameSettings.DetectCheatClients = OptionCheckboxItem.Create(700, BetterSettingsTab, TranslationStrings.BetterSetting_Setting_DetectCheatClients, true); BetterGameSettings.DetectInvalidRPCs = OptionCheckboxItem.Create(800, BetterSettingsTab, TranslationStrings.BetterSetting_Setting_DetectInvalidRPCs, true); } diff --git a/src/Resources/Lang/en_US.json b/src/Resources/Lang/en_US.json index 440e972..3060cff 100644 --- a/src/Resources/Lang/en_US.json +++ b/src/Resources/Lang/en_US.json @@ -90,8 +90,10 @@ "BetterSetting.Setting.UseBanWordListOnlyLobby": "Only in lobby", "BetterSetting.Setting.ShowRoleForClients": "Show role in name for clients", "BetterSetting.Setting.CensorDetectionReason": "Censor detection reason", - "BetterSetting.Setting.DetectedLevelAbove": "Detected player levels >", - "BetterSetting.Setting.KickLevelBelow": "Kick player levels <", + "BetterSetting.Setting.DetectedLevel": "Detected player levels", + "BetterSetting.Setting.DetectedLevelAbove": "Detected player level above", + "BetterSetting.Setting.KickLevel": "Kick player levels", + "BetterSetting.Setting.KickLevelBelow": "Kick player level below", "BetterSetting.Setting.DetectCheatClients": "Detect cheat clients", "BetterSetting.Setting.DetectInvalidRPCs": "Detect invalid RPCs", "BetterSetting.Setting.RoleRandomizer": "Randomizer", diff --git a/src/Utilities/PlayerControlUtils.cs b/src/Utilities/PlayerControlUtils.cs index 2de0cf1..e1c182e 100644 --- a/src/Utilities/PlayerControlUtils.cs +++ b/src/Utilities/PlayerControlUtils.cs @@ -147,12 +147,12 @@ internal static class PlayerControlUtils if (AntiCheatBan) { - if (BetterGameSettings.WhenCheating.GetStringValue() == 0 && !forceBan) + if (BetterGameSettings.WhenCheating.GetStringIndex() == 0 && !forceBan) { return; } - Ban = (Ban && BetterGameSettings.WhenCheating.GetStringValue() == 2) || forceBan; + Ban = (Ban && BetterGameSettings.WhenCheating.GetStringIndex() == 2) || forceBan; } if (setReasonInfo != "") diff --git a/src/build/Generated/TranslationStrings.cs b/src/build/Generated/TranslationStrings.cs index b9aeb75..b3c4219 100644 --- a/src/build/Generated/TranslationStrings.cs +++ b/src/build/Generated/TranslationStrings.cs @@ -444,12 +444,22 @@ public static class TranslationStrings public static readonly TranslationString BetterSetting_Setting_CensorDetectionReason = new("BetterSetting.Setting.CensorDetectionReason"); /// - /// Base Translation: Detected player levels > + /// Base Translation: Detected player levels + /// + public static readonly TranslationString BetterSetting_Setting_DetectedLevel = new("BetterSetting.Setting.DetectedLevel"); + + /// + /// Base Translation: Detected player level above /// public static readonly TranslationString BetterSetting_Setting_DetectedLevelAbove = new("BetterSetting.Setting.DetectedLevelAbove"); /// - /// Base Translation: Kick player levels < + /// Base Translation: Kick player levels + /// + public static readonly TranslationString BetterSetting_Setting_KickLevel = new("BetterSetting.Setting.KickLevel"); + + /// + /// Base Translation: Kick player level below /// public static readonly TranslationString BetterSetting_Setting_KickLevelBelow = new("BetterSetting.Setting.KickLevelBelow");