mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
Add DetectedLevelAbove and KickLevelBelow parent options, and clean up option implementation
This commit is contained in:
1 parent
fadcfce33c
commit
c3bc45e2aa
17 files changed
+192
-202
No files matched your search
@@ -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)))
|
||||
{
|
||||
|
||||
@@ -63,13 +63,13 @@ internal sealed class OptionDividerItem : OptionItem
|
||||
Tab.Children.Add(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string representation of the divider value (not applicable).
|
||||
/// </summary>
|
||||
/// <returns>NotImplementedException as dividers don't have values.</returns>
|
||||
/// <exception cref="NotImplementedException">Always thrown since dividers have no values.</exception>
|
||||
public sealed override string ValueAsString()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override object GetBoxedValue()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -85,13 +85,13 @@ internal sealed class OptionHeaderItem : OptionItem
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string representation of the header value (not applicable).
|
||||
/// </summary>
|
||||
/// <returns>NotImplementedException as headers don't have values.</returns>
|
||||
/// <exception cref="NotImplementedException">Always thrown since headers have no values.</exception>
|
||||
public sealed override string ValueAsString()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override object GetBoxedValue()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -94,13 +94,13 @@ internal sealed class OptionTitleItem : OptionItem
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string representation of the title value (not applicable).
|
||||
/// </summary>
|
||||
/// <returns>NotImplementedException as headers don't have values.</returns>
|
||||
/// <exception cref="NotImplementedException">Always thrown since headers have no values.</exception>
|
||||
public sealed override string ValueAsString()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override object GetBoxedValue()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@ public sealed class OptionCheckboxItem : OptionItem<bool>
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier for this option.</param>
|
||||
/// <param name="tab">The tab this option belongs to.</param>
|
||||
/// <param name="tranStr">The translation key for the option name.</param>
|
||||
/// <param name="translationString">The translation key for the option name.</param>
|
||||
/// <param name="defaultValue">The default value for the checkbox.</param>
|
||||
/// <param name="parent">Optional parent option for hierarchical organization.</param>
|
||||
/// <returns>A new or existing OptionCheckboxItem instance.</returns>
|
||||
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<bool>
|
||||
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<bool>
|
||||
/// Gets the boolean value of this checkbox option.
|
||||
/// </summary>
|
||||
/// <returns>The current boolean value.</returns>
|
||||
public sealed override bool GetBool() => GetValue();
|
||||
public bool GetBool() => GetValue();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the checkbox value matches a specific boolean.
|
||||
/// </summary>
|
||||
/// <param name="@bool">The boolean value to compare against.</param>
|
||||
/// <param name="value">The boolean value to compare against.</param>
|
||||
/// <returns>True if the checkbox value matches, false otherwise.</returns>
|
||||
public sealed override bool Is(bool @bool) => @bool == GetBool();
|
||||
public sealed override bool Is(bool value) => value == GetBool();
|
||||
}
|
||||
@@ -40,14 +40,14 @@ public class OptionFloatItem : OptionItem<float>
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier for this option.</param>
|
||||
/// <param name="tab">The tab this option belongs to.</param>
|
||||
/// <param name="tranStr">The translation key for the option name.</param>
|
||||
/// <param name="translationString">The translation key for the option name.</param>
|
||||
/// <param name="Min_Max_Increment">Tuple containing min value, max value, and increment step.</param>
|
||||
/// <param name="defaultValue">The default value for the option.</param>
|
||||
/// <param name="Prefix_Postfix">Tuple containing prefix and postfix strings for display.</param>
|
||||
/// <param name="parent">Optional parent option for hierarchical organization.</param>
|
||||
/// <param name="canBeInfinite">Whether this option can represent infinite values.</param>
|
||||
/// <returns>A new or existing OptionFloatItem instance.</returns>
|
||||
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<float>
|
||||
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<float>
|
||||
/// Gets the float value of this option.
|
||||
/// </summary>
|
||||
/// <returns>The current float value.</returns>
|
||||
public override float GetFloat() => GetValue();
|
||||
public float GetFloat() => GetValue();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option value matches a specific float.
|
||||
/// </summary>
|
||||
/// <param name="@float">The float value to compare against.</param>
|
||||
/// <param name="value">The float value to compare against.</param>
|
||||
/// <returns>True if the option value matches, false otherwise.</returns>
|
||||
public override bool Is(float @float) => @float == GetFloat();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option value matches a specific integer.
|
||||
/// </summary>
|
||||
/// <param name="@int">The integer value to compare against.</param>
|
||||
/// <returns>True if the option value matches (as float), false otherwise.</returns>
|
||||
public override bool Is(int @int) => @int == GetFloat();
|
||||
public override bool Is(float value) => value == GetFloat();
|
||||
}
|
||||
@@ -40,14 +40,14 @@ public sealed class OptionIntItem : OptionItem<int>
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier for this option.</param>
|
||||
/// <param name="tab">The tab this option belongs to.</param>
|
||||
/// <param name="tranStr">The translation key for the option name.</param>
|
||||
/// <param name="translationString">The translation key for the option name.</param>
|
||||
/// <param name="Min_Max_Increment">Tuple containing min value, max value, and increment step.</param>
|
||||
/// <param name="defaultValue">The default value for the option.</param>
|
||||
/// <param name="Prefix_Postfix">Tuple containing prefix and postfix strings for display.</param>
|
||||
/// <param name="parent">Optional parent option for hierarchical organization.</param>
|
||||
/// <param name="canBeInfinite">Whether this option can represent infinite values.</param>
|
||||
/// <returns>A new or existing OptionIntItem instance.</returns>
|
||||
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<int>
|
||||
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<int>
|
||||
/// Gets the integer value of this option.
|
||||
/// </summary>
|
||||
/// <returns>The current integer value.</returns>
|
||||
public sealed override int GetInt() => GetValue();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the float representation of the integer value.
|
||||
/// </summary>
|
||||
/// <returns>The current integer value as a float.</returns>
|
||||
public sealed override float GetFloat() => GetValue();
|
||||
public int GetInt() => GetValue();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option value matches a specific integer.
|
||||
/// </summary>
|
||||
/// <param name="@int">The integer value to compare against.</param>
|
||||
/// <param name="value">The integer value to compare against.</param>
|
||||
/// <returns>True if the option value matches, false otherwise.</returns>
|
||||
public sealed override bool Is(int @int) => @int == GetInt();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option value matches a specific float.
|
||||
/// </summary>
|
||||
/// <param name="@float">The float value to compare against.</param>
|
||||
/// <returns>True if the option value matches (as integer), false otherwise.</returns>
|
||||
public sealed override bool Is(float @float) => @float == GetFloat();
|
||||
public sealed override bool Is(int value) => value == GetInt();
|
||||
}
|
||||
@@ -20,24 +20,63 @@ public abstract class OptionItem
|
||||
internal const string InfiniteIcon = "<b>∞</b>";
|
||||
internal virtual bool CanLoad => true;
|
||||
internal virtual bool IsOption => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localized display name of the option.
|
||||
/// </summary>
|
||||
public string Name => TranslationName != null ? TranslationName.Value.LocalizedString : string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique identifier of the option.
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this option has child options.
|
||||
/// </summary>
|
||||
internal bool IsParent => Children.Count > 0;
|
||||
|
||||
internal List<OptionItem?> Children { get; set; } = [];
|
||||
internal virtual bool Show => ShowCondition.Invoke();
|
||||
internal virtual bool ShowChildren => Show;
|
||||
internal Func<bool>? ShowCondition = () => { return true; };
|
||||
internal bool Hide => !Show || GetParents().Any(opt => !opt.ShowChildren) || BAUModdedSupportFlags.HasFlag(BAUModdedSupportFlags.Disable_GameOption + TranslationName);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an option by its unique identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier of the option.</param>
|
||||
/// <returns>The option with the specified ID, or null if not found.</returns>
|
||||
internal static OptionItem? GetOptionById(int id) => AllOptions.FirstOrDefault(opt => opt._id == id);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the visual appearance of the option.
|
||||
/// </summary>
|
||||
/// <param name="updateTabVisuals">Whether to update the parent tab visuals.</param>
|
||||
internal virtual void UpdateVisuals(bool updateTabVisuals = true) { }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string representation of the current option value.
|
||||
/// </summary>
|
||||
/// <returns>The value as a string.</returns>
|
||||
public abstract string ValueAsString();
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to load the option's value from persistent storage.
|
||||
/// </summary>
|
||||
/// <param name="forceLoad">If true, forces reload even if already loaded.</param>
|
||||
internal virtual void TryLoad(bool forceLoad = false) { }
|
||||
|
||||
/// <summary>
|
||||
/// Resets the option to its default value.
|
||||
/// </summary>
|
||||
internal virtual void SetToDefault() { }
|
||||
|
||||
/// <summary>
|
||||
@@ -63,7 +102,7 @@ public abstract class OptionItem
|
||||
/// <summary>
|
||||
/// Displays a notification with the option's current value or custom text.
|
||||
/// </summary>
|
||||
/// <param name="custom">Custom text to display instead of the value.</param>
|
||||
/// <param name="custom">Optional custom text to display instead of the value.</param>
|
||||
internal void PopNotification(string custom = "")
|
||||
{
|
||||
if (_id == null)
|
||||
@@ -78,7 +117,7 @@ public abstract class OptionItem
|
||||
/// <summary>
|
||||
/// Gets the hierarchical path of parent options leading to this option.
|
||||
/// </summary>
|
||||
/// <returns>A formatted string showing the option hierarchy.</returns>
|
||||
/// <returns>A formatted string showing the option hierarchy path.</returns>
|
||||
internal string GetParentPath()
|
||||
{
|
||||
List<string> names = [Name ?? "???"];
|
||||
@@ -115,7 +154,7 @@ public abstract class OptionItem
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the child index depth of this option in the hierarchy.
|
||||
/// Gets the depth level of this option in the hierarchy.
|
||||
/// </summary>
|
||||
/// <returns>The depth level (0 for root options).</returns>
|
||||
internal int GetChildIndex()
|
||||
@@ -131,9 +170,9 @@ public abstract class OptionItem
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a text tree representation of the option hierarchy.
|
||||
/// Generates a text tree representation of the option hierarchy starting from this option.
|
||||
/// </summary>
|
||||
/// <param name="size">Text size percentage.</param>
|
||||
/// <param name="size">Text size percentage (default 50%).</param>
|
||||
/// <param name="showForPercentOption">Whether to show child options for percent items.</param>
|
||||
/// <returns>A formatted string showing the option tree structure.</returns>
|
||||
internal string FormatOptionsToTextTree(float size = 50f, bool showForPercentOption = true)
|
||||
@@ -205,8 +244,8 @@ public abstract class OptionItem
|
||||
/// <summary>
|
||||
/// Generates text tree representations for multiple option hierarchies.
|
||||
/// </summary>
|
||||
/// <param name="optionItems">Array of root option items.</param>
|
||||
/// <param name="size">Text size percentage.</param>
|
||||
/// <param name="optionItems">Array of root option items to display.</param>
|
||||
/// <param name="size">Text size percentage (default 50%).</param>
|
||||
/// <param name="showForPercentOption">Whether to show child options for percent items.</param>
|
||||
/// <returns>A formatted string showing all option tree structures.</returns>
|
||||
internal static string FormatOptionsToTextTrees(OptionItem?[] optionItems, float size = 50f, bool showForPercentOption = true)
|
||||
@@ -315,88 +354,10 @@ public abstract class OptionItem
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the boolean value of the option (for CheckboxOption).
|
||||
/// Gets the boxed value of this option.
|
||||
/// </summary>
|
||||
/// <returns>The boolean value.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown when the option type doesn't support boolean values.</exception>
|
||||
public virtual bool GetBool()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the float value of the option (for FloatOption).
|
||||
/// </summary>
|
||||
/// <returns>The float value.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown when the option type doesn't support float values.</exception>
|
||||
public virtual float GetFloat()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the integer value of the option (for IntOption).
|
||||
/// </summary>
|
||||
/// <returns>The integer value.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown when the option type doesn't support integer values.</exception>
|
||||
public virtual int GetInt()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string value index of the option (for StringOption and PlayerOption).
|
||||
/// </summary>
|
||||
/// <returns>The string value index.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown when the option type doesn't support string values.</exception>
|
||||
public virtual int GetStringValue()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option's value matches a specific boolean.
|
||||
/// </summary>
|
||||
/// <param name="@bool">The boolean value to check against.</param>
|
||||
/// <returns>True if the option value matches, false otherwise.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown when the option type doesn't support boolean comparison.</exception>
|
||||
public virtual bool Is(bool @bool)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option's value matches a specific float.
|
||||
/// </summary>
|
||||
/// <param name="@float">The float value to check against.</param>
|
||||
/// <returns>True if the option value matches, false otherwise.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown when the option type doesn't support float comparison.</exception>
|
||||
public virtual bool Is(float @float)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option's value matches a specific integer.
|
||||
/// </summary>
|
||||
/// <param name="@int">The integer value to check against.</param>
|
||||
/// <returns>True if the option value matches, false otherwise.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown when the option type doesn't support integer comparison.</exception>
|
||||
public virtual bool Is(int @int)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option's value matches a specific string.
|
||||
/// </summary>
|
||||
/// <param name="@string">The string value to check against.</param>
|
||||
/// <returns>True if the option value matches, false otherwise.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown when the option type doesn't support string comparison.</exception>
|
||||
public virtual bool Is(string @string)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <returns>The option value as an object.</returns>
|
||||
public abstract object GetBoxedValue();
|
||||
|
||||
/// <summary>
|
||||
/// Represents a node in the option hierarchy tree for text formatting.
|
||||
@@ -436,6 +397,20 @@ public abstract class OptionItem<T> : OptionItem
|
||||
private bool HasLoadValue { get; set; }
|
||||
protected T? Value { get; set; } = default;
|
||||
protected T? DefaultValue { get; set; } = default;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the boxed value of this option.
|
||||
/// </summary>
|
||||
/// <returns>The option value as an object.</returns>
|
||||
public override sealed object GetBoxedValue()
|
||||
{
|
||||
return GetValue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value of the option.
|
||||
/// </summary>
|
||||
/// <returns>The current value, or the default value if the option is disabled.</returns>
|
||||
public virtual T? GetValue()
|
||||
{
|
||||
if (BAUModdedSupportFlags.HasFlag(BAUModdedSupportFlags.Disable_GameOption + TranslationName))
|
||||
@@ -445,16 +420,41 @@ public abstract class OptionItem<T> : OptionItem
|
||||
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default value of the option.
|
||||
/// </summary>
|
||||
/// <returns>The default value.</returns>
|
||||
internal virtual T? GetDefaultValue() =>
|
||||
DefaultValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string representation of the current value.
|
||||
/// </summary>
|
||||
/// <returns>The value as a string, or an empty string if null.</returns>
|
||||
public override string ValueAsString() =>
|
||||
Value?.ToString() ?? string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Resets the option to its default value.
|
||||
/// </summary>
|
||||
internal override void SetToDefault()
|
||||
{
|
||||
Value = DefaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the UI behavior for this option.
|
||||
/// </summary>
|
||||
protected abstract void CreateBehavior();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the option value changes.
|
||||
/// </summary>
|
||||
/// <param name="oldValue">The previous value.</param>
|
||||
/// <param name="newValue">The new value.</param>
|
||||
internal virtual void OnValueChange(T oldValue, T newValue) { }
|
||||
|
||||
internal Action<OptionItem>? OnValueChangeAction = (opt) => { };
|
||||
|
||||
/// <summary>
|
||||
@@ -511,6 +511,13 @@ public abstract class OptionItem<T> : OptionItem
|
||||
UpdateVisuals();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option's value matches the specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to compare against.</param>
|
||||
/// <returns>True if the option value matches, false otherwise.</returns>
|
||||
public abstract bool Is(T value);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the option's value and triggers updates and notifications.
|
||||
/// </summary>
|
||||
@@ -529,7 +536,7 @@ public abstract class OptionItem<T> : OptionItem
|
||||
/// <summary>
|
||||
/// Attempts to load the option's value from persistent storage.
|
||||
/// </summary>
|
||||
/// <param name="forceLoad">Whether to force reload even if already loaded.</param>
|
||||
/// <param name="forceLoad">If true, forces reload even if already loaded.</param>
|
||||
internal override void TryLoad(bool forceLoad = false)
|
||||
{
|
||||
if (!CanLoad)
|
||||
|
||||
@@ -12,11 +12,11 @@ public sealed class OptionPercentItem : OptionFloatItem
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier for this option.</param>
|
||||
/// <param name="tab">The tab this option belongs to.</param>
|
||||
/// <param name="tranStr">The translation key for the option name.</param>
|
||||
/// <param name="translationString">The translation key for the option name.</param>
|
||||
/// <param name="defaultValue">The default percentage value (0-100).</param>
|
||||
/// <param name="parent">Optional parent option for hierarchical organization.</param>
|
||||
/// <returns>A new or existing OptionPercentItem instance.</returns>
|
||||
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;
|
||||
|
||||
@@ -42,11 +42,11 @@ public sealed class OptionPlayerItem : OptionItem<int>
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier for this option.</param>
|
||||
/// <param name="tab">The tab this option belongs to.</param>
|
||||
/// <param name="tranStr">The translation key for the option name.</param>
|
||||
/// <param name="translationString">The translation key for the option name.</param>
|
||||
/// <param name="parent">Optional parent option for hierarchical organization.</param>
|
||||
/// <param name="canBeRandom">Whether this option allows random player selection.</param>
|
||||
/// <returns>A new or existing OptionPlayerItem instance.</returns>
|
||||
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<int>
|
||||
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<int>
|
||||
/// Gets the integer value (player index) of this option.
|
||||
/// </summary>
|
||||
/// <returns>The current player index.</returns>
|
||||
public sealed override int GetInt() =>
|
||||
GetValue();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the float representation of the player index.
|
||||
/// </summary>
|
||||
/// <returns>The current player index as a float.</returns>
|
||||
public sealed override float GetFloat() =>
|
||||
GetValue();
|
||||
public int GetInt() => GetValue();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option value matches a specific integer.
|
||||
/// </summary>
|
||||
/// <param name="@int">The integer value to compare against.</param>
|
||||
/// <param name="value">The integer value to compare against.</param>
|
||||
/// <returns>True if the option value matches, false otherwise.</returns>
|
||||
public sealed override bool Is(int @int) => @int == GetInt();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option value matches a specific float.
|
||||
/// </summary>
|
||||
/// <param name="@float">The float value to compare against.</param>
|
||||
/// <returns>True if the option value matches (as integer), false otherwise.</returns>
|
||||
public sealed override bool Is(float @float) => @float == GetFloat();
|
||||
public sealed override bool Is(int value) => value == GetInt();
|
||||
}
|
||||
@@ -24,15 +24,15 @@ public class OptionStringItem : OptionItem<int>
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier for this option.</param>
|
||||
/// <param name="tab">The tab this option belongs to.</param>
|
||||
/// <param name="tranStr">The translation key for the option name.</param>
|
||||
/// <param name="tranStrings">Array of translation keys for the selectable string values.</param>
|
||||
/// <param name="translationStringName">The translation key for the option name.</param>
|
||||
/// <param name="translationStrings">Array of translation keys for the selectable string values.</param>
|
||||
/// <param name="defaultValue">The default index value.</param>
|
||||
/// <param name="parent">Optional parent option for hierarchical organization.</param>
|
||||
/// <returns>A new or existing OptionStringItem instance.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when tranStrings has less than 2 elements.</exception>
|
||||
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<int>
|
||||
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<int>
|
||||
/// Gets the translated string representation of the current selection.
|
||||
/// </summary>
|
||||
/// <returns>The translated string for the current index.</returns>
|
||||
public override string ValueAsString() =>
|
||||
Translator.GetString(TranslatorStrings[Value], showInvalid: false);
|
||||
public string GetString() => Translator.GetString(TranslatorStrings[Value], showInvalid: false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the effective string value index, accounting for random selection.
|
||||
/// Gets the current index value of the selected string option.
|
||||
/// </summary>
|
||||
/// <returns>The actual string index (random if selected).</returns>
|
||||
public sealed override int GetStringValue()
|
||||
{
|
||||
return GetValue();
|
||||
}
|
||||
/// <returns>The current integer index value.</returns>
|
||||
public int GetStringIndex() => GetValue();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the translated string representation of the current selection.
|
||||
/// </summary>
|
||||
/// <returns>The translated string for the current index.</returns>
|
||||
public override string ValueAsString() => GetString();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option's string value matches a specific string.
|
||||
/// </summary>
|
||||
/// <param name="@string">The string value to compare against.</param>
|
||||
/// <param name="str">The string value to compare against.</param>
|
||||
/// <returns>True if the option value matches, false otherwise.</returns>
|
||||
public sealed override bool Is(string @string) => TranslatorStrings[Value].Key == @string || ValueAsString() == @string;
|
||||
public bool Is(string str) => TranslatorStrings[Value].Key == str || ValueAsString() == str;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the option's index value matches a specific integer.
|
||||
/// </summary>
|
||||
/// <param name="@int">The integer value to compare against.</param>
|
||||
/// <param name="value">The integer value to compare against.</param>
|
||||
/// <returns>True if the option value matches, false otherwise.</returns>
|
||||
public sealed override bool Is(int @int) => Value == @int;
|
||||
public sealed override bool Is(int value) => Value == value;
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 != "")
|
||||
|
||||
@@ -444,12 +444,22 @@ public static class TranslationStrings
|
||||
public static readonly TranslationString BetterSetting_Setting_CensorDetectionReason = new("BetterSetting.Setting.CensorDetectionReason");
|
||||
|
||||
/// <summary>
|
||||
/// Base Translation: Detected player levels >
|
||||
/// Base Translation: Detected player levels
|
||||
/// </summary>
|
||||
public static readonly TranslationString BetterSetting_Setting_DetectedLevel = new("BetterSetting.Setting.DetectedLevel");
|
||||
|
||||
/// <summary>
|
||||
/// Base Translation: Detected player level above
|
||||
/// </summary>
|
||||
public static readonly TranslationString BetterSetting_Setting_DetectedLevelAbove = new("BetterSetting.Setting.DetectedLevelAbove");
|
||||
|
||||
/// <summary>
|
||||
/// Base Translation: Kick player levels <
|
||||
/// Base Translation: Kick player levels
|
||||
/// </summary>
|
||||
public static readonly TranslationString BetterSetting_Setting_KickLevel = new("BetterSetting.Setting.KickLevel");
|
||||
|
||||
/// <summary>
|
||||
/// Base Translation: Kick player level below
|
||||
/// </summary>
|
||||
public static readonly TranslationString BetterSetting_Setting_KickLevelBelow = new("BetterSetting.Setting.KickLevelBelow");
|
||||
|
||||
|
||||
Reference in new issue
Block a user