mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 23:17:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13c6db4d64 | ||
|
|
b9f1f2fcf2 | ||
|
|
c98d133648 | ||
|
|
5c2216dfc9 | ||
|
|
33fdd86b56 | ||
|
|
133cec9c38 | ||
|
|
f677acb6c8 | ||
|
|
c57901ef6d | ||
|
|
38ee19e996 | ||
|
|
8ba03db883 | ||
|
|
5885d211f5 | ||
|
|
80357f0f3e | ||
|
|
f43ede10f5 | ||
|
|
0a4f2f84b1 | ||
|
|
5a09d3c996 | ||
|
|
c013599127 | ||
|
|
fc4f3d1aa0 | ||
|
|
c51ad7e0de | ||
|
|
13dce32ae3 | ||
|
|
314e108d0e | ||
|
|
16c6b53a8c | ||
|
|
2b904d8e8c | ||
|
|
dd0499b5fa | ||
|
|
bab8243f0b | ||
|
|
3fe399c04d | ||
|
|
49529b09ee | ||
|
|
16999684eb |
No files matched your search
@@ -122,3 +122,9 @@ dotnet_diagnostic.SA1143.severity = none
|
|||||||
|
|
||||||
# SA1504: All accessors should be single-line or multi-line
|
# SA1504: All accessors should be single-line or multi-line
|
||||||
dotnet_diagnostic.SA1504.severity = none
|
dotnet_diagnostic.SA1504.severity = none
|
||||||
|
|
||||||
|
# S2386: Mutable fields should not be "public static"
|
||||||
|
dotnet_diagnostic.S2386.severity = none
|
||||||
|
|
||||||
|
# S3887: Mutable, non-private fields should not be "readonly"
|
||||||
|
dotnet_diagnostic.S3887.severity = none
|
||||||
@@ -34,10 +34,10 @@ public class ExampleOptions : AbstractOptionGroup
|
|||||||
[ModdedOptionGetter(nameof(GetApi))] // Can also automatically resolve to {Option Name}Getter
|
[ModdedOptionGetter(nameof(GetApi))] // Can also automatically resolve to {Option Name}Getter
|
||||||
[ModdedOptionSetter(nameof(SetApi))] // Can also automatically resolve to {Option Name}Setter
|
[ModdedOptionSetter(nameof(SetApi))] // Can also automatically resolve to {Option Name}Setter
|
||||||
[ModdedOptionChanged(nameof(ApiChanged))] // Can also automatically resolve to {Option Name}Changed
|
[ModdedOptionChanged(nameof(ApiChanged))] // Can also automatically resolve to {Option Name}Changed
|
||||||
[ModdedEnumOption<Api>("options.exampleOptions1.bestApi", ["Mira API", "Mitochondria", "Reactor"])]
|
[ModdedEnumOption<Api>("options.exampleOptions1.bestApi")] // Not specifying strings will automatically build translation ids based on the defined enum values
|
||||||
public Api BestApi { get; set; } = Api.MiraAPI;
|
public Api BestApi { get; set; } = Api.MiraAPI;
|
||||||
|
|
||||||
[ModdedEnumOptionList<ValueState>("Value State {0}", ["None", "Primary", "Secondary"])]
|
[ModdedEnumOptionList<ValueState>("Value State {0}", [ValueState.None, ValueState.Primary, ValueState.Secondary])] // You can even filter out specific values!
|
||||||
public ModdedArray<ValueState> ValueStates { get; set; } = [ValueState.Primary, ValueState.Secondary, ValueState.None, ValueState.None, ValueState.None];
|
public ModdedArray<ValueState> ValueStates { get; set; } = [ValueState.Primary, ValueState.Secondary, ValueState.None, ValueState.None, ValueState.None];
|
||||||
|
|
||||||
[ModdedPlayerOption("options.exampleOptions1.players")]
|
[ModdedPlayerOption("options.exampleOptions1.players")]
|
||||||
@@ -81,4 +81,5 @@ public enum ValueState
|
|||||||
None,
|
None,
|
||||||
Primary,
|
Primary,
|
||||||
Secondary,
|
Secondary,
|
||||||
|
Tertiary,
|
||||||
}
|
}
|
||||||
@@ -17,12 +17,7 @@ public static class GameOverManager
|
|||||||
|
|
||||||
internal static bool RegisterGameOver(Type type, in MiraPluginManager.RegistrationContext _)
|
internal static bool RegisterGameOver(Type type, in MiraPluginManager.RegistrationContext _)
|
||||||
{
|
{
|
||||||
if (!typeof(CustomGameOver).IsAssignableFrom(type))
|
if (type.IsAbstract || !typeof(CustomGameOver).IsAssignableFrom(type))
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.IsAbstract)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using AmongUs.GameOptions;
|
using AmongUs.GameOptions;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
@@ -300,8 +301,8 @@ public abstract class AbstractGameMode : IOptionable
|
|||||||
instance.closedPosition = new Vector3(xPos, yPos, instance.closedPosition.z);
|
instance.closedPosition = new Vector3(xPos, yPos, instance.closedPosition.z);
|
||||||
instance.openPosition = new Vector3(instance.openPosition.x, yPos, instance.openPosition.z);
|
instance.openPosition = new Vector3(instance.openPosition.x, yPos, instance.openPosition.z);
|
||||||
instance.timer = instance.open
|
instance.timer = instance.open
|
||||||
? Mathf.Min(1f, instance.timer + (Time.deltaTime / instance.animationTimeSeconds))
|
? Math.Min(1f, instance.timer + (Time.deltaTime / instance.animationTimeSeconds))
|
||||||
: Mathf.Max(0f, instance.timer - (Time.deltaTime / instance.animationTimeSeconds));
|
: Math.Max(0f, instance.timer - (Time.deltaTime / instance.animationTimeSeconds));
|
||||||
|
|
||||||
Vector3 relativePos = new(
|
Vector3 relativePos = new(
|
||||||
Mathf.SmoothStep(instance.closedPosition.x, instance.openPosition.x, instance.timer),
|
Mathf.SmoothStep(instance.closedPosition.x, instance.openPosition.x, instance.timer),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public static class CustomGameModeManager
|
|||||||
|
|
||||||
internal static bool RegisterGameMode(Type type, in MiraPluginManager.RegistrationContext context)
|
internal static bool RegisterGameMode(Type type, in MiraPluginManager.RegistrationContext context)
|
||||||
{
|
{
|
||||||
if (!typeof(AbstractGameMode).IsAssignableFrom(type))
|
if (type.IsAbstract || !typeof(AbstractGameMode).IsAssignableFrom(type))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class HideAndSeekMode : AbstractGameMode
|
|||||||
|
|
||||||
private static int ImpostorPlayerID()
|
private static int ImpostorPlayerID()
|
||||||
{
|
{
|
||||||
return OptionGroupSingleton<HnsImpostorOptions>.Instance.SelectedSeeker.Value;
|
return OptionGroupSingleton<HnsImpostorOptions>.Instance.SelectedSeeker;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool HasImpostorPlayerID()
|
private static bool HasImpostorPlayerID()
|
||||||
@@ -516,8 +516,8 @@ public class HideAndSeekMode : AbstractGameMode
|
|||||||
instance.closedPosition = new Vector3(xPos, yPos, instance.closedPosition.z);
|
instance.closedPosition = new Vector3(xPos, yPos, instance.closedPosition.z);
|
||||||
instance.openPosition = new Vector3(instance.openPosition.x, yPos, instance.openPosition.z);
|
instance.openPosition = new Vector3(instance.openPosition.x, yPos, instance.openPosition.z);
|
||||||
instance.timer = instance.open
|
instance.timer = instance.open
|
||||||
? Mathf.Min(1f, instance.timer + (Time.deltaTime / instance.animationTimeSeconds))
|
? Math.Min(1f, instance.timer + (Time.deltaTime / instance.animationTimeSeconds))
|
||||||
: Mathf.Max(0f, instance.timer - (Time.deltaTime / instance.animationTimeSeconds));
|
: Math.Max(0f, instance.timer - (Time.deltaTime / instance.animationTimeSeconds));
|
||||||
|
|
||||||
Vector3 relativePos = new(
|
Vector3 relativePos = new(
|
||||||
Mathf.SmoothStep(instance.closedPosition.x, instance.openPosition.x, instance.timer),
|
Mathf.SmoothStep(instance.closedPosition.x, instance.openPosition.x, instance.timer),
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Il2CppInterop.Runtime.Attributes;
|
|
||||||
using MiraAPI.Modifiers;
|
using MiraAPI.Modifiers;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
@@ -46,7 +45,6 @@ public abstract class AbstractOptionGroup
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the sprite of the group that is displayed in the match info guide.
|
/// Gets the sprite of the group that is displayed in the match info guide.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HideFromIl2Cpp]
|
|
||||||
public virtual LoadableAsset<Sprite> Sprite => MiraAssets.IconSettings;
|
public virtual LoadableAsset<Sprite> Sprite => MiraAssets.IconSettings;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -58,15 +58,14 @@ public class ModdedEnumOptionAttribute(string? title, Type enumType, string idPr
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void SetValue(object value)
|
public override void SetValue(object value)
|
||||||
{
|
{
|
||||||
var opt = HolderOption as ModdedEnumOption;
|
(HolderOption as ModdedEnumOption)?.SetValue((int)value);
|
||||||
opt?.SetValue((int)value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override object GetValue()
|
public override object GetValue()
|
||||||
{
|
{
|
||||||
return HolderOption is ModdedEnumOption opt
|
return HolderOption is ModdedEnumOption opt
|
||||||
? Enum.ToObject(enumType, opt.Value)
|
? Enum.ToObject(enumType, opt.UnderlyingValues[opt.Value])
|
||||||
: throw new InvalidOperationException($"HolderOption for option \"{Title}\" is not a ModdedEnumOption with enum type {enumType.FullName}");
|
: throw new InvalidOperationException($"HolderOption for option \"{Title}\" is not a ModdedEnumOption with enum type {enumType.FullName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,34 +76,59 @@ public class ModdedEnumOptionAttribute(string? title, Type enumType, string idPr
|
|||||||
/// <typeparam name="T">The enum type.</typeparam>
|
/// <typeparam name="T">The enum type.</typeparam>
|
||||||
/// <param name="title">The title of the option.</param>
|
/// <param name="title">The title of the option.</param>
|
||||||
/// <param name="idPrefix">The common translation ID prefix of all enum values.</param>
|
/// <param name="idPrefix">The common translation ID prefix of all enum values.</param>
|
||||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
/// <param name="allowedValues">An option array of enum values to filter down what values can actually be used.</param>
|
||||||
|
/// <param name="values">An optional array of string values to use in place of the <see langword="enum"/> name.</param>
|
||||||
[AttributeUsage(AttributeTargets.Property)]
|
[AttributeUsage(AttributeTargets.Property)]
|
||||||
public class ModdedEnumOptionAttribute<T>(string? title, string idPrefix, string[]? values = null)
|
public class ModdedEnumOptionAttribute<T>(string? title, string idPrefix, T[]? allowedValues = null, string[]? values = null)
|
||||||
: ModdedOptionAttribute(title), ITypedOption<T>
|
: ModdedOptionAttribute(title), ITypedOption<T>
|
||||||
where T : struct, Enum
|
where T : struct, Enum
|
||||||
{
|
{
|
||||||
/// <summary>
|
private const string ObsoleteMsg = "This constructor is deprecated. Please use the equivalent constructor that includes the 'T[]? allowedValues' parameter. This will be removed in a future version.";
|
||||||
/// Initializes a new instance of the <see cref="ModdedEnumOptionAttribute{T}"/> class.
|
|
||||||
/// </summary>
|
/// <inheritdoc cref="ModdedEnumOptionAttribute{T}(string, string, T[], string[])"/>
|
||||||
/// <param name="title">The title of the option.</param>
|
public ModdedEnumOptionAttribute(string? title, T[]? allowedValues = null, string[]? values = null)
|
||||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
: this(title, string.Empty, allowedValues, values)
|
||||||
public ModdedEnumOptionAttribute(string? title, string[]? values = null)
|
|
||||||
: this(title, string.Empty, values)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ModdedEnumOptionAttribute{T}(string, string, T[], string[])"/>
|
||||||
/// Initializes a new instance of the <see cref="ModdedEnumOptionAttribute{T}"/> class.
|
public ModdedEnumOptionAttribute(T[]? allowedValues = null, string[]? values = null, string idPrefix = "")
|
||||||
/// </summary>
|
: this(null, idPrefix, allowedValues, values)
|
||||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
|
||||||
public ModdedEnumOptionAttribute(string[]? values = null)
|
|
||||||
: this(null, string.Empty, values)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOptionAttribute{T}(string, string, T[], string[])"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOptionAttribute(string? title, string idPrefix, string[] values)
|
||||||
|
: this(title, idPrefix, null, values)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOptionAttribute{T}(string, string, T[], string[])"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOptionAttribute(string? title, string[] values)
|
||||||
|
: this(title, string.Empty, null, values)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOptionAttribute{T}(string, string, T[], string[])"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOptionAttribute(string[] values, string idPrefix)
|
||||||
|
: this(null, idPrefix, null, values)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOptionAttribute{T}(string, string, T[], string[])"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOptionAttribute(string[] values)
|
||||||
|
: this(null, string.Empty, null, values)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
internal override IModdedOption CreateOption(object? value, PropertyInfo property, AbstractOptionGroup group)
|
internal override IModdedOption CreateOption(object? value, PropertyInfo property, AbstractOptionGroup group)
|
||||||
{
|
{
|
||||||
var opt = new ModdedEnumOption<T>(group.GroupPrefix, Title ?? property.Name, (T)(value ?? 0), idPrefix, values);
|
var opt = new ModdedEnumOption<T>(group.GroupPrefix, Title ?? property.Name, (T)(value ?? 0), idPrefix, allowedValues, values);
|
||||||
Title = opt.Title;
|
Title = opt.Title;
|
||||||
return opt;
|
return opt;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class ModdedEnumOptionListAttribute(string? title, Type enumType, string
|
|||||||
public override object GetValue(int idx)
|
public override object GetValue(int idx)
|
||||||
{
|
{
|
||||||
return HolderOptionList?.ElementAt(idx) is ModdedEnumOption opt
|
return HolderOptionList?.ElementAt(idx) is ModdedEnumOption opt
|
||||||
? Enum.ToObject(enumType, opt.Value)
|
? Enum.ToObject(enumType, opt.UnderlyingValues[opt.Value])
|
||||||
: throw new InvalidOperationException($"HolderOption for option \"{Titles[idx]}\" is not a ModdedEnumOption with enum type {enumType.FullName}");
|
: throw new InvalidOperationException($"HolderOption for option \"{Titles[idx]}\" is not a ModdedEnumOption with enum type {enumType.FullName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,36 +78,60 @@ public class ModdedEnumOptionListAttribute(string? title, Type enumType, string
|
|||||||
/// <typeparam name="T">The enum type.</typeparam>
|
/// <typeparam name="T">The enum type.</typeparam>
|
||||||
/// <param name="title">The option's title.</param>
|
/// <param name="title">The option's title.</param>
|
||||||
/// <param name="idPrefix">The common translation ID prefix of all enum values.</param>
|
/// <param name="idPrefix">The common translation ID prefix of all enum values.</param>
|
||||||
/// <param name="values">The option's possible values.</param>
|
/// <param name="allowedValues">An option array of enum values to filter down what values can actually be used.</param>
|
||||||
|
/// <param name="values">An optional array of string values to use in place of the <see langword="enum"/> name.</param>
|
||||||
[AttributeUsage(AttributeTargets.Property)]
|
[AttributeUsage(AttributeTargets.Property)]
|
||||||
public class ModdedEnumOptionListAttribute<T>(string? title, string idPrefix, string[]? values = null)
|
public class ModdedEnumOptionListAttribute<T>(string? title, string idPrefix, T[]? allowedValues = null, string[]? values = null)
|
||||||
: ModdedOptionListAttribute(title), ITypedOptionList<T>
|
: ModdedOptionListAttribute(title), ITypedOptionList<T>
|
||||||
where T : struct, Enum
|
where T : struct, Enum
|
||||||
{
|
{
|
||||||
/// <summary>
|
private const string ObsoleteMsg = "This constructor is deprecated. Please use the equivalent constructor that includes the 'T[]? allowedValues' parameter. This will be removed in a future version.";
|
||||||
/// Initializes a new instance of the <see cref="ModdedEnumOptionListAttribute{T}"/> class.
|
|
||||||
/// </summary>
|
/// <inheritdoc cref="ModdedEnumOptionListAttribute{T}(string, string, T[], string[])"/>
|
||||||
/// <param name="title">The option's title.</param>
|
public ModdedEnumOptionListAttribute(string? title, T[]? allowedValues = null, string[]? values = null)
|
||||||
/// <param name="values">The option's possible values.</param>
|
: this(title, string.Empty, allowedValues, values)
|
||||||
public ModdedEnumOptionListAttribute(string? title, string[]? values = null)
|
|
||||||
: this(title, string.Empty, values)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ModdedEnumOptionListAttribute{T}(string, string, T[], string[])"/>
|
||||||
/// Initializes a new instance of the <see cref="ModdedEnumOptionListAttribute{T}"/> class.
|
public ModdedEnumOptionListAttribute(T[]? allowedValues = null, string[]? values = null, string idPrefix = "")
|
||||||
/// </summary>
|
: this(null, idPrefix, allowedValues, values)
|
||||||
/// <param name="values">The option's possible values.</param>
|
|
||||||
/// <param name="idPrefix">The common translation ID prefix of all enum values.</param>
|
|
||||||
public ModdedEnumOptionListAttribute(string[]? values = null, string idPrefix = "")
|
|
||||||
: this(null, idPrefix, values)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOptionListAttribute{T}(string, string, T[], string[])"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOptionListAttribute(string? title, string idPrefix, string[] values)
|
||||||
|
: this(title, idPrefix, null, values)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOptionListAttribute{T}(string, string, T[], string[])"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOptionListAttribute(string? title, string[] values)
|
||||||
|
: this(title, string.Empty, null, values)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOptionListAttribute{T}(string, string, T[], string[])"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOptionListAttribute(string[] values, string idPrefix)
|
||||||
|
: this(null, idPrefix, null, values)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOptionListAttribute{T}(string, string, T[], string[])"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOptionListAttribute(string[] values)
|
||||||
|
: this(null, string.Empty, null, values)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
internal override IBaseModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
internal override IBaseModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||||
{
|
{
|
||||||
var optList = new ModdedOptionList<ModdedEnumOption<T>>(
|
var optList = new ModdedOptionList<ModdedEnumOption<T>>(
|
||||||
list.Count, idx => new(group.GroupPrefix, GetFormattedTitle(idx, property), (T)(list[idx] ?? 0), idPrefix, values));
|
list.Count, idx => new(group.GroupPrefix, GetFormattedTitle(idx, property), (T)(list[idx] ?? 0), idPrefix, allowedValues, values));
|
||||||
return optList;
|
return optList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,15 +55,6 @@ public sealed class ModdedArray<T> : IList<T>, IReadOnlyList<T>, IList, IModdedA
|
|||||||
items = [.. collection];
|
items = [.. collection];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ModdedArray{T}"/> class with initial values.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="span">The initial span of values to initialise with.</param>
|
|
||||||
public ModdedArray(Span<T> span)
|
|
||||||
{
|
|
||||||
items = [.. span];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ModdedArray{T}"/> class with initial values.
|
/// Initializes a new instance of the <see cref="ModdedArray{T}"/> class with initial values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -178,6 +169,7 @@ public sealed class ModdedArray<T> : IList<T>, IReadOnlyList<T>, IList, IModdedA
|
|||||||
{
|
{
|
||||||
listAttribute = attribute;
|
listAttribute = attribute;
|
||||||
typedAttribute = attribute as ITypedOptionList<T>;
|
typedAttribute = attribute as ITypedOptionList<T>;
|
||||||
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace MiraAPI.GameOptions;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ModdedOptionsManager
|
public static class ModdedOptionsManager
|
||||||
{
|
{
|
||||||
|
private static readonly Dictionary<(Type Holder, string Property), IModdedOption> PropertyToOptionMap = [];
|
||||||
private static readonly Dictionary<RuntimeMethodHandle, PropertyOptionAttribute> GetterLookup = [];
|
private static readonly Dictionary<RuntimeMethodHandle, PropertyOptionAttribute> GetterLookup = [];
|
||||||
private static readonly Dictionary<RuntimeMethodHandle, PropertyOptionAttribute> SetterLookup = [];
|
private static readonly Dictionary<RuntimeMethodHandle, PropertyOptionAttribute> SetterLookup = [];
|
||||||
private static readonly HashSet<PropertyInfo> OptionAttributes = [];
|
private static readonly HashSet<PropertyInfo> OptionAttributes = [];
|
||||||
@@ -73,7 +74,7 @@ public static class ModdedOptionsManager
|
|||||||
|
|
||||||
internal static bool RegisterGroup(Type type, in MiraPluginManager.RegistrationContext context)
|
internal static bool RegisterGroup(Type type, in MiraPluginManager.RegistrationContext context)
|
||||||
{
|
{
|
||||||
if (!type.IsAssignableTo(typeof(AbstractOptionGroup)))
|
if (type.IsAbstract || !type.IsAssignableTo(typeof(AbstractOptionGroup)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -147,8 +148,7 @@ public static class ModdedOptionsManager
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
foreach (var field in type.GetFields(MiraPluginManager.DeclaredInstanceMembers)
|
foreach (var field in type.GetFields(MiraPluginManager.DeclaredInstanceMembers)
|
||||||
.Where(f => !f.IsAutoPropertyBackingField()
|
.Where(f => !f.IsAutoPropertyBackingField() && (f.FieldType.IsAssignableTo(OptionType) || f.FieldType.IsAssignableTo(OptionListType))))
|
||||||
&& (f.FieldType.IsAssignableTo(typeof(IModdedOption)) || f.FieldType.IsAssignableTo(typeof(IBaseModdedOptionList)))))
|
|
||||||
{
|
{
|
||||||
Error($"{field.Name} is a field, not a property. Use properties for options.");
|
Error($"{field.Name} is a field, not a property. Use properties for options.");
|
||||||
}
|
}
|
||||||
@@ -218,8 +218,8 @@ public static class ModdedOptionsManager
|
|||||||
|
|
||||||
PatchProperty(property, propType, attribute);
|
PatchProperty(property, propType, attribute);
|
||||||
|
|
||||||
attribute.HolderOption = option;
|
|
||||||
attribute.ValueType = propType;
|
attribute.ValueType = propType;
|
||||||
|
attribute.HolderOption = option;
|
||||||
|
|
||||||
foreach (var attr in attributes)
|
foreach (var attr in attributes)
|
||||||
{
|
{
|
||||||
@@ -305,9 +305,9 @@ public static class ModdedOptionsManager
|
|||||||
|
|
||||||
var valueType = propType.GetGenericArguments()[0];
|
var valueType = propType.GetGenericArguments()[0];
|
||||||
|
|
||||||
attribute.HolderOptionList = optionList;
|
|
||||||
attribute.Value = list;
|
attribute.Value = list;
|
||||||
attribute.ValueType = valueType;
|
attribute.ValueType = valueType;
|
||||||
|
attribute.HolderOptionList = optionList;
|
||||||
|
|
||||||
((IModdedArrayBinding)propertyVal).Bind(attribute);
|
((IModdedArrayBinding)propertyVal).Bind(attribute);
|
||||||
|
|
||||||
@@ -364,8 +364,10 @@ public static class ModdedOptionsManager
|
|||||||
option.ParentMod = pluginInfo.MiraPlugin;
|
option.ParentMod = pluginInfo.MiraPlugin;
|
||||||
|
|
||||||
pluginInfo.InternalOptions.Add(option);
|
pluginInfo.InternalOptions.Add(option);
|
||||||
ModdedOptions.Add(option.Id, option);
|
|
||||||
group.Options.Add(option);
|
group.Options.Add(option);
|
||||||
|
|
||||||
|
ModdedOptions.Add(option.Id, option);
|
||||||
|
PropertyToOptionMap.Add((type, propertyName), option);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SyncAllOptions(int targetId = -1)
|
internal static void SyncAllOptions(int targetId = -1)
|
||||||
@@ -397,8 +399,16 @@ public static class ModdedOptionsManager
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
option.ShowNotification = showNotifs;
|
try
|
||||||
option.HandleNetData(netData.Data);
|
{
|
||||||
|
option.ShowNotification = showNotifs;
|
||||||
|
option.HandleNetData(netData.Data);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
option.ShowNotification = true;
|
||||||
|
Error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins)
|
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins)
|
||||||
@@ -413,6 +423,24 @@ public static class ModdedOptionsManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a <see cref="StringNames"/> value associated to the option of the provided property name that is found in <typeparamref name="T"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The container option type.</typeparam>
|
||||||
|
/// <param name="propertyName">The name of the property that defines the option.</param>
|
||||||
|
/// <returns>The option's string name, or StringNames.None if not found.</returns>
|
||||||
|
public static StringNames GetStringName<T>(string propertyName)
|
||||||
|
where T : AbstractOptionGroup
|
||||||
|
{
|
||||||
|
var type = typeof(T);
|
||||||
|
|
||||||
|
if (PropertyToOptionMap.TryGetValue((type, propertyName), out var option))
|
||||||
|
return option.StringName;
|
||||||
|
|
||||||
|
Error($"Could not find an option with the property name {propertyName} in {type.Name}");
|
||||||
|
return StringNames.None;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Patches the setter of a property to update the value of the option.
|
/// Patches the setter of a property to update the value of the option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -420,7 +448,7 @@ public static class ModdedOptionsManager
|
|||||||
/// <param name="value">The new object value.</param>
|
/// <param name="value">The new object value.</param>
|
||||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention.")]
|
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention.")]
|
||||||
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Read above.")]
|
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Read above.")]
|
||||||
[Obsolete("Use PropertySetterPatch<T> instead. This will be removed in a future version.")]
|
[Obsolete("Use PropertySetterPatch<T> instead. This will be removed in a future version.", true)]
|
||||||
public static void PropertySetterPatch(MethodBase __originalMethod, object value)
|
public static void PropertySetterPatch(MethodBase __originalMethod, object value)
|
||||||
{
|
{
|
||||||
if (!SetterLookup.TryGetValue(__originalMethod.MethodHandle, out var attribute))
|
if (!SetterLookup.TryGetValue(__originalMethod.MethodHandle, out var attribute))
|
||||||
@@ -460,9 +488,9 @@ public static class ModdedOptionsManager
|
|||||||
/// <param name="__originalMethod">The original getter method.</param>
|
/// <param name="__originalMethod">The original getter method.</param>
|
||||||
/// <param name="__result">The result of the property getter.</param>
|
/// <param name="__result">The result of the property getter.</param>
|
||||||
/// <returns><see langword="false"/> so the original getter gets skipped.</returns>
|
/// <returns><see langword="false"/> so the original getter gets skipped.</returns>
|
||||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention")]
|
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention.")]
|
||||||
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Read above.")]
|
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Read above.")]
|
||||||
[Obsolete("Use PropertyGetterPatch<T> instead. This will be removed in a future version.")]
|
[Obsolete("Use PropertyGetterPatch<T> instead. This will be removed in a future version.", true)]
|
||||||
public static bool PropertyGetterPatch(MethodBase __originalMethod, ref object __result)
|
public static bool PropertyGetterPatch(MethodBase __originalMethod, ref object __result)
|
||||||
{
|
{
|
||||||
if (!GetterLookup.TryGetValue(__originalMethod.MethodHandle, out var attribute))
|
if (!GetterLookup.TryGetValue(__originalMethod.MethodHandle, out var attribute))
|
||||||
@@ -479,7 +507,7 @@ public static class ModdedOptionsManager
|
|||||||
/// <param name="__originalMethod">The original getter method.</param>
|
/// <param name="__originalMethod">The original getter method.</param>
|
||||||
/// <param name="__result">The result of the property getter.</param>
|
/// <param name="__result">The result of the property getter.</param>
|
||||||
/// <returns><see langword="false"/> so the original getter gets skipped.</returns>
|
/// <returns><see langword="false"/> so the original getter gets skipped.</returns>
|
||||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention")]
|
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention.")]
|
||||||
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Read above.")]
|
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Read above.")]
|
||||||
public static bool PropertyGetterPatch<T>(MethodBase __originalMethod, ref T __result)
|
public static bool PropertyGetterPatch<T>(MethodBase __originalMethod, ref T __result)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public abstract class ModdedBaseStringOption<T>(string groupPrefix, string title
|
|||||||
var index = Array.IndexOf(UnderlyingValues, value);
|
var index = Array.IndexOf(UnderlyingValues, value);
|
||||||
|
|
||||||
if (index == -1)
|
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;
|
return index;
|
||||||
}
|
}
|
||||||
@@ -120,6 +120,7 @@ public abstract class ModdedBaseStringOption<T>(string groupPrefix, string title
|
|||||||
if ((uint)index < (uint)UnderlyingValues.Length)
|
if ((uint)index < (uint)UnderlyingValues.Length)
|
||||||
return UnderlyingValues[index];
|
return UnderlyingValues[index];
|
||||||
|
|
||||||
|
Warning($"Received an index {index} when there wasn't enough values (Length: {UnderlyingValues.Length})");
|
||||||
return UnderlyingValues.Length > 0 ? UnderlyingValues[0] : default!;
|
return UnderlyingValues.Length > 0 ? UnderlyingValues[0] : default!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,6 +43,9 @@ public class ModdedEnumOption : ModdedBaseEnumOption<int>
|
|||||||
public ModdedEnumOption(string groupPrefix, string title, int defaultValue, Type enumType, string idPrefix, string[]? values = null, bool includeInPreset = true)
|
public ModdedEnumOption(string groupPrefix, string title, int defaultValue, Type enumType, string idPrefix, string[]? values = null, bool includeInPreset = true)
|
||||||
: base(groupPrefix, title, defaultValue, includeInPreset)
|
: base(groupPrefix, title, defaultValue, includeInPreset)
|
||||||
{
|
{
|
||||||
|
if (!enumType.IsEnum)
|
||||||
|
throw new ArgumentException($"The type {enumType.Name} is not an Enum.", nameof(enumType));
|
||||||
|
|
||||||
idPrefix = idPrefix.Replace("%type%", enumType.Name);
|
idPrefix = idPrefix.Replace("%type%", enumType.Name);
|
||||||
|
|
||||||
var rawValues = Enum.GetValues(enumType);
|
var rawValues = Enum.GetValues(enumType);
|
||||||
@@ -51,6 +54,11 @@ public class ModdedEnumOption : ModdedBaseEnumOption<int>
|
|||||||
for (var i = 0; i < rawValues.Length; i++)
|
for (var i = 0; i < rawValues.Length; i++)
|
||||||
UnderlyingValues[i] = Convert.ToInt32(rawValues.GetValue(i), NumberFormatInfo.InvariantInfo);
|
UnderlyingValues[i] = Convert.ToInt32(rawValues.GetValue(i), NumberFormatInfo.InvariantInfo);
|
||||||
|
|
||||||
|
if (values != null && values.Length != UnderlyingValues.Length)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"The number of custom values ({values.Length}) must exactly match the number of enum values ({UnderlyingValues.Length}) in {enumType.Name}.", nameof(values));
|
||||||
|
}
|
||||||
|
|
||||||
Values = values ?? Enum.GetNames(enumType);
|
Values = values ?? Enum.GetNames(enumType);
|
||||||
StringNameValues = [.. Values.Select(x => MiraLocaleManager.GetOrCreateLocaleString($"{idPrefix}{x}"))];
|
StringNameValues = [.. Values.Select(x => MiraLocaleManager.GetOrCreateLocaleString($"{idPrefix}{x}"))];
|
||||||
|
|
||||||
@@ -101,7 +109,7 @@ public class ModdedEnumOption : ModdedBaseEnumOption<int>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override NetData GetNetData()
|
public override NetData GetNetData()
|
||||||
{
|
{
|
||||||
return new(Id, BitConverter.GetBytes(Value));
|
return new(Id, BitConverter.GetBytes(_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -111,7 +119,7 @@ public class ModdedEnumOption : ModdedBaseEnumOption<int>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected internal override ConfigDescription? CreateDescription()
|
protected override ConfigDescription? CreateDescription()
|
||||||
{
|
{
|
||||||
return new(string.Empty, new AcceptableValueList<int>(UnderlyingValues));
|
return new(string.Empty, new AcceptableValueList<int>(UnderlyingValues));
|
||||||
}
|
}
|
||||||
@@ -124,6 +132,8 @@ public class ModdedEnumOption : ModdedBaseEnumOption<int>
|
|||||||
public class ModdedEnumOption<T> : ModdedBaseEnumOption<T>
|
public class ModdedEnumOption<T> : ModdedBaseEnumOption<T>
|
||||||
where T : struct, Enum
|
where T : struct, Enum
|
||||||
{
|
{
|
||||||
|
private const string ObsoleteMsg = "This constructor is deprecated. Please use the equivalent constructor that includes the 'T[]? allowedValues' parameter. This will be removed in a future version.";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ModdedEnumOption{T}"/> class.
|
/// Initializes a new instance of the <see cref="ModdedEnumOption{T}"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -131,54 +141,103 @@ public class ModdedEnumOption<T> : ModdedBaseEnumOption<T>
|
|||||||
/// <param name="title">The title of the option.</param>
|
/// <param name="title">The title of the option.</param>
|
||||||
/// <param name="defaultValue">The default value as an <see langword="int"/>.</param>
|
/// <param name="defaultValue">The default value as an <see langword="int"/>.</param>
|
||||||
/// <param name="idPrefix">The common translation ID prefix of all enum values.</param>
|
/// <param name="idPrefix">The common translation ID prefix of all enum values.</param>
|
||||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
/// <param name="allowedValues">An option array of enum values to filter down what values can actually be used.</param>
|
||||||
|
/// <param name="values">An optional array of string values to use in place of the <see langword="enum"/> name.</param>
|
||||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||||
public ModdedEnumOption(string groupPrefix, string title, T defaultValue, string idPrefix, string[]? values = null, bool includeInPreset = true)
|
public ModdedEnumOption(string groupPrefix, string title, T defaultValue, string idPrefix, T[]? allowedValues = null, string[]? values = null, bool includeInPreset = true)
|
||||||
: base(groupPrefix, title, defaultValue, includeInPreset)
|
: base(groupPrefix, title, defaultValue, includeInPreset)
|
||||||
{
|
{
|
||||||
idPrefix = idPrefix.Replace("%type%", typeof(T).Name);
|
idPrefix = idPrefix.Replace("%type%", typeof(T).Name);
|
||||||
UnderlyingValues = Enum.GetValues<T>();
|
|
||||||
Values = values ?? Enum.GetNames<T>();
|
UnderlyingValues = allowedValues ?? Enum.GetValues<T>();
|
||||||
|
|
||||||
|
if (Array.IndexOf(UnderlyingValues, defaultValue) == -1)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"The defaultValue '{defaultValue}' is not present in the allowed enum values.", nameof(defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (values != null && values.Length != UnderlyingValues.Length)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"The number of custom values ({values.Length}) must exactly match the number of allowed enum values ({UnderlyingValues.Length}).", nameof(values));
|
||||||
|
}
|
||||||
|
|
||||||
|
Values = values ?? [.. UnderlyingValues.Select(v => v.ToString())];
|
||||||
StringNameValues = [.. Values.Select(x => MiraLocaleManager.GetOrCreateLocaleString($"{idPrefix}{x}"))];
|
StringNameValues = [.. Values.Select(x => MiraLocaleManager.GetOrCreateLocaleString($"{idPrefix}{x}"))];
|
||||||
|
|
||||||
InitializeData(GetIndex(defaultValue));
|
InitializeData(GetIndex(defaultValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
/// Initializes a new instance of the <see cref="ModdedEnumOption{T}"/> class.
|
public ModdedEnumOption(string groupPrefix, string title, T defaultValue, T[]? allowedValues = null, string[]? values = null, bool includeInPreset = true)
|
||||||
/// </summary>
|
: this(groupPrefix, title, defaultValue, string.Empty, allowedValues, values, includeInPreset)
|
||||||
/// <param name="groupPrefix">The translation ID prefix of the group containing this option.</param>
|
|
||||||
/// <param name="title">The title of the option.</param>
|
|
||||||
/// <param name="defaultValue">The default value as an <see langword="int"/>.</param>
|
|
||||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
|
||||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
|
||||||
public ModdedEnumOption(string groupPrefix, string title, T defaultValue, string[]? values = null, bool includeInPreset = true)
|
|
||||||
: this(groupPrefix, title, defaultValue, string.Empty, values, includeInPreset)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
/// Initializes a new instance of the <see cref="ModdedEnumOption{T}"/> class.
|
public ModdedEnumOption(string title, T defaultValue, T[]? allowedValues = null, string[]? values = null, bool includeInPreset = true)
|
||||||
/// </summary>
|
: this(string.Empty, title, defaultValue, string.Empty, allowedValues, values, includeInPreset)
|
||||||
/// <param name="title">The title of the option.</param>
|
|
||||||
/// <param name="defaultValue">The default value as an <see langword="int"/>.</param>
|
|
||||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
|
||||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
|
||||||
public ModdedEnumOption(string title, T defaultValue, string[]? values = null, bool includeInPreset = true)
|
|
||||||
: this(string.Empty, title, defaultValue, values, includeInPreset)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
/// Initializes a new instance of the <see cref="ModdedEnumOption{T}"/> class.
|
public ModdedEnumOption(string title, T defaultValue, string idPrefix, T[]? allowedValues = null, string[]? values = null, bool includeInPreset = true)
|
||||||
/// </summary>
|
: this(string.Empty, title, defaultValue, idPrefix, allowedValues, values, includeInPreset)
|
||||||
/// <param name="title">The title of the option.</param>
|
{
|
||||||
/// <param name="defaultValue">The default value as an <see langword="int"/>.</param>
|
}
|
||||||
/// <param name="idPrefix">The common translation ID prefix of all enum values.</param>
|
|
||||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
[Obsolete(ObsoleteMsg)]
|
||||||
public ModdedEnumOption(string title, T defaultValue, string idPrefix, string[]? values = null, bool includeInPreset = true)
|
public ModdedEnumOption(string groupPrefix, string title, T defaultValue, string idPrefix, string[] values, bool includeInPreset)
|
||||||
: this(string.Empty, title, defaultValue, idPrefix, values, includeInPreset)
|
: this(groupPrefix, title, defaultValue, idPrefix, null, values, includeInPreset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOption(string groupPrefix, string title, T defaultValue, string idPrefix, string[] values)
|
||||||
|
: this(groupPrefix, title, defaultValue, idPrefix, null, values, true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOption(string groupPrefix, string title, T defaultValue, string[] values, bool includeInPreset)
|
||||||
|
: this(groupPrefix, title, defaultValue, string.Empty, null, values, includeInPreset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOption(string groupPrefix, string title, T defaultValue, string[] values)
|
||||||
|
: this(groupPrefix, title, defaultValue, string.Empty, null, values, true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOption(string title, T defaultValue, string[] values, bool includeInPreset)
|
||||||
|
: this(string.Empty, title, defaultValue, string.Empty, null, values, includeInPreset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOption(string title, T defaultValue, string[] values)
|
||||||
|
: this(string.Empty, title, defaultValue, string.Empty, null, values, true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOption(string title, T defaultValue, string idPrefix, string[] values, bool includeInPreset)
|
||||||
|
: this(string.Empty, title, defaultValue, idPrefix, null, values, includeInPreset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ModdedEnumOption{T}(string, string, T, string, T[], string[], bool)"/>
|
||||||
|
[Obsolete(ObsoleteMsg)]
|
||||||
|
public ModdedEnumOption(string title, T defaultValue, string idPrefix, string[] values)
|
||||||
|
: this(string.Empty, title, defaultValue, idPrefix, null, values, true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +245,7 @@ public class ModdedEnumOption<T> : ModdedBaseEnumOption<T>
|
|||||||
public override NetData GetNetData()
|
public override NetData GetNetData()
|
||||||
{
|
{
|
||||||
var buffer = new byte[Unsafe.SizeOf<T>()];
|
var buffer = new byte[Unsafe.SizeOf<T>()];
|
||||||
Unsafe.WriteUnaligned(ref buffer[0], Value);
|
Unsafe.WriteUnaligned(ref buffer[0], _value);
|
||||||
return new(Id, buffer);
|
return new(Id, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +256,7 @@ public class ModdedEnumOption<T> : ModdedBaseEnumOption<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected internal override ConfigDescription? CreateDescription()
|
protected override ConfigDescription? CreateDescription()
|
||||||
{
|
{
|
||||||
return new(string.Empty, new AcceptableEnumValues<T>(UnderlyingValues));
|
return new(string.Empty, new AcceptableEnumValues<T>(UnderlyingValues));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
|||||||
string? formatString = null,
|
string? formatString = null,
|
||||||
bool halfIncrements = false,
|
bool halfIncrements = false,
|
||||||
bool includeInPreset = true)
|
bool includeInPreset = true)
|
||||||
: base(groupPrefix, title, defaultValue, includeInPreset)
|
: base(groupPrefix, title, Math.Clamp(defaultValue, min, max), includeInPreset)
|
||||||
{
|
{
|
||||||
Min = min;
|
Min = min;
|
||||||
Max = max;
|
Max = max;
|
||||||
@@ -102,15 +102,12 @@ public class ModdedNumberOption : ModdedOption<float>
|
|||||||
ZeroWordValue = zeroBehavior;
|
ZeroWordValue = zeroBehavior;
|
||||||
ShiftIncrement = halfIncrements;
|
ShiftIncrement = halfIncrements;
|
||||||
NegativeWordValue = negativeBehavior;
|
NegativeWordValue = negativeBehavior;
|
||||||
IsInt = defaultValue.IsInteger() &&
|
IsInt = DefaultValue.IsInteger() &&
|
||||||
Increment.IsInteger() &&
|
Increment.IsInteger() &&
|
||||||
Value.IsInteger() &&
|
|
||||||
Min.IsInteger() &&
|
Min.IsInteger() &&
|
||||||
Max.IsInteger();
|
Max.IsInteger();
|
||||||
FormatString = formatString ?? (IsInt ? "0" : "0.0");
|
FormatString = formatString ?? (IsInt ? "0" : "0.0");
|
||||||
|
|
||||||
Value = Mathf.Clamp(defaultValue, min, max);
|
|
||||||
|
|
||||||
if (IsInt)
|
if (IsInt)
|
||||||
{
|
{
|
||||||
var data = ScriptableObject.CreateInstance<IntGameSetting>();
|
var data = ScriptableObject.CreateInstance<IntGameSetting>();
|
||||||
@@ -285,7 +282,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override NetData GetNetData()
|
public override NetData GetNetData()
|
||||||
{
|
{
|
||||||
return new NetData(Id, BitConverter.GetBytes(Value));
|
return new NetData(Id, BitConverter.GetBytes(_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -297,7 +294,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override float GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
|
public override float GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
|
||||||
{
|
{
|
||||||
return Mathf.Clamp(optionBehaviour.GetFloat(), Min, Max);
|
return Math.Clamp(optionBehaviour.GetFloat(), Min, Max);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -316,9 +313,9 @@ public class ModdedNumberOption : ModdedOption<float>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected internal override ConfigDescription? CreateDescription()
|
protected override ConfigDescription? CreateDescription()
|
||||||
{
|
{
|
||||||
return new(string.Empty, new AcceptableValueRange<float>(Min, Max));
|
return new(string.Empty, new SafeAcceptableValueRange<float>(Min, Max));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using MiraAPI.Networking;
|
using MiraAPI.Networking;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
@@ -14,20 +15,16 @@ namespace MiraAPI.GameOptions.OptionTypes;
|
|||||||
/// Represents a modded option.
|
/// Represents a modded option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The value type.</typeparam>
|
/// <typeparam name="T">The value type.</typeparam>
|
||||||
/// <param name="groupPrefix">The translation ID prefix of the group containing this option.</param>
|
public abstract class ModdedOption<T> : IModdedOption
|
||||||
/// <param name="title">The option title.</param>
|
|
||||||
/// <param name="defaultValue">The default value.</param>
|
|
||||||
/// <param name="includeInPreset">Whether to include the option in the preset.</param>
|
|
||||||
public abstract class ModdedOption<T>(string groupPrefix, string title, T defaultValue, bool includeInPreset = true) : IModdedOption
|
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public uint Id { get; } = ModdedOptionsManager.NextId;
|
public uint Id { get; } = ModdedOptionsManager.NextId;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Title { get; set; } = groupPrefix + title;
|
public string Title { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public StringNames StringName { get; } = MiraLocaleManager.GetOrCreateLocaleString(groupPrefix + title);
|
public StringNames StringName { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the value of the option.
|
/// Gets or sets the value of the option.
|
||||||
@@ -46,18 +43,23 @@ public abstract class ModdedOption<T>(string groupPrefix, string title, T defaul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private T _value = defaultValue;
|
/// <summary>
|
||||||
|
/// The backing value field. Use only for raw and quick comparisons, otherwise use <see cref="Value"/>.
|
||||||
|
/// </summary>
|
||||||
|
[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Useful for raw checks that do not need modifications upon read or write.")]
|
||||||
|
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")]
|
||||||
|
protected T _value;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the default value of the option.
|
/// Gets the default value of the option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public T DefaultValue { get; } = defaultValue;
|
public T DefaultValue { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Func<bool> Visible { get; set; } = DelegateUtilities.AlwaysTrue;
|
public Func<bool> Visible { get; set; } = DelegateUtilities.AlwaysTrue;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IncludeInPreset { get; set; } = includeInPreset;
|
public bool IncludeInPreset { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool ShowNotification { get; set; } = true;
|
public bool ShowNotification { get; set; } = true;
|
||||||
@@ -121,6 +123,23 @@ public abstract class ModdedOption<T>(string groupPrefix, string title, T defaul
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual OptionNotifConfiguration Configuration => new(ParentGroup);
|
public virtual OptionNotifConfiguration Configuration => new(ParentGroup);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ModdedOption{T}"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupPrefix">The translation ID prefix of the group containing this option.</param>
|
||||||
|
/// <param name="title">The option title.</param>
|
||||||
|
/// <param name="defaultValue">The default value.</param>
|
||||||
|
/// <param name="includeInPreset">Whether to include the option in the preset.</param>
|
||||||
|
protected ModdedOption(string groupPrefix, string title, T defaultValue, bool includeInPreset = true)
|
||||||
|
{
|
||||||
|
var translationId = groupPrefix + title;
|
||||||
|
|
||||||
|
Title = translationId;
|
||||||
|
StringName = MiraLocaleManager.GetOrCreateLocaleString(translationId);
|
||||||
|
DefaultValue = _value = defaultValue;
|
||||||
|
IncludeInPreset = includeInPreset;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ModdedOption{T}"/> class.
|
/// Initializes a new instance of the <see cref="ModdedOption{T}"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -162,16 +181,8 @@ public abstract class ModdedOption<T>(string groupPrefix, string title, T defaul
|
|||||||
Rpc<SyncGameOptionsRpc>.Instance.Send(PlayerControl.LocalPlayer, new MiraOptionNetData(true, [GetNetData()]), true);
|
Rpc<SyncGameOptionsRpc>.Instance.Send(PlayerControl.LocalPlayer, new MiraOptionNetData(true, [GetNetData()]), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShowNotification)
|
if (ShowNotification && HudManager.InstanceExists)
|
||||||
{
|
ShowNotif();
|
||||||
ModdedOptionsManager.AddSettingsChangeMessage(
|
|
||||||
HudManager.Instance.Notifier,
|
|
||||||
StringName,
|
|
||||||
GetDisplayValue(),
|
|
||||||
Configuration.PopUpTextColor,
|
|
||||||
Configuration.PopUpIconTmp,
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
|
|
||||||
OnValueChanged(_value);
|
OnValueChanged(_value);
|
||||||
ShowNotification = true;
|
ShowNotification = true;
|
||||||
@@ -262,13 +273,29 @@ public abstract class ModdedOption<T>(string groupPrefix, string title, T defaul
|
|||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member (Justification: Internal code.)
|
/// <summary>
|
||||||
protected internal virtual ConfigDescription? CreateDescription()
|
/// Creates a <see cref="ConfigDescription"/> instance for the option's backing config.
|
||||||
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
/// </summary>
|
||||||
|
/// <returns>The option's config description, or null if there is none.</returns>
|
||||||
|
protected virtual ConfigDescription? CreateDescription()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pops the notification modifier.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void ShowNotif()
|
||||||
|
{
|
||||||
|
ModdedOptionsManager.AddSettingsChangeMessage(
|
||||||
|
HudManager.Instance.Notifier,
|
||||||
|
StringName,
|
||||||
|
GetDisplayValue(),
|
||||||
|
Configuration.PopUpTextColor,
|
||||||
|
Configuration.PopUpIconTmp,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implicitly converts the option to type of <typeparamref name="T"/>.
|
/// Implicitly converts the option to type of <typeparamref name="T"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -67,8 +67,12 @@ public class ModdedPlayerOption : ModdedOption<int>
|
|||||||
PlayerOption playerOpt,
|
PlayerOption playerOpt,
|
||||||
Transform container)
|
Transform container)
|
||||||
{
|
{
|
||||||
|
var oldPlayer = GetPlayerValue();
|
||||||
Values = GetFilteredPlayers();
|
Values = GetFilteredPlayers();
|
||||||
|
|
||||||
|
var newIndex = oldPlayer ? Values.IndexOf(oldPlayer!) : -1;
|
||||||
|
Value = newIndex >= 0 ? newIndex : (AllowNone ? -1 : 0);
|
||||||
|
|
||||||
var playerOption = Object.Instantiate(playerOpt, container);
|
var playerOption = Object.Instantiate(playerOpt, container);
|
||||||
playerOption.name = $"{ParentMod!.OptionsTitleText}.PlayerOption.{Title}";
|
playerOption.name = $"{ParentMod!.OptionsTitleText}.PlayerOption.{Title}";
|
||||||
|
|
||||||
@@ -78,7 +82,7 @@ public class ModdedPlayerOption : ModdedOption<int>
|
|||||||
playerOption.Title = StringName;
|
playerOption.Title = StringName;
|
||||||
playerOption.Values = Values.ToIl2CppList();
|
playerOption.Values = Values.ToIl2CppList();
|
||||||
playerOption.Value = Value;
|
playerOption.Value = Value;
|
||||||
playerOption.playerIndex = Values.FindIndex(p => p.PlayerId == Value);
|
playerOption.playerIndex = Value;
|
||||||
playerOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
playerOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||||
|
|
||||||
playerOption.SetValueText();
|
playerOption.SetValueText();
|
||||||
@@ -125,7 +129,7 @@ public class ModdedPlayerOption : ModdedOption<int>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override NetData GetNetData()
|
public override NetData GetNetData()
|
||||||
{
|
{
|
||||||
return new NetData(Id, BitConverter.GetBytes(Value));
|
return new NetData(Id, BitConverter.GetBytes(_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -153,8 +157,8 @@ public class ModdedPlayerOption : ModdedOption<int>
|
|||||||
public override string GetDisplayValue()
|
public override string GetDisplayValue()
|
||||||
{
|
{
|
||||||
var player = GetPlayerValue();
|
var player = GetPlayerValue();
|
||||||
return !player
|
return player
|
||||||
? TranslationController.Instance.GetString(StringNames.None)
|
? player!.PlayerName
|
||||||
: player!.PlayerName;
|
: TranslationController.Instance.GetString(StringNames.None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using MiraAPI.Networking;
|
using MiraAPI.Networking;
|
||||||
using MiraAPI.Translation;
|
using MiraAPI.Translation;
|
||||||
@@ -54,6 +52,8 @@ public class ModdedStringOption : ModdedBaseStringOption<string>
|
|||||||
[Obsolete("Use the Setter feature of modded options to simulate conditional values. This wil be removed in a future version.")]
|
[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)
|
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 (!Values.Contains(value))
|
||||||
{
|
{
|
||||||
if (index <= -1)
|
if (index <= -1)
|
||||||
@@ -97,17 +97,17 @@ public class ModdedStringOption : ModdedBaseStringOption<string>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override NetData GetNetData()
|
public override NetData GetNetData()
|
||||||
{
|
{
|
||||||
return new NetData(Id, Encoding.Unicode.GetBytes(Convert.ToString(Value, NumberFormatInfo.InvariantInfo)));
|
return new NetData(Id, BitConverter.GetBytes(GetIndex(_value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void HandleNetData(byte[] data)
|
public override void HandleNetData(byte[] data)
|
||||||
{
|
{
|
||||||
SetValue(Encoding.Unicode.GetString(data));
|
SetValue(UnderlyingValues[BitConverter.ToInt32(data)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected internal override ConfigDescription? CreateDescription()
|
protected override ConfigDescription? CreateDescription()
|
||||||
{
|
{
|
||||||
return new(string.Empty, new AcceptableValueList<string>(UnderlyingValues));
|
return new(string.Empty, new AcceptableValueList<string>(UnderlyingValues));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public class ModdedToggleOption : ModdedOption<bool>
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override NetData GetNetData()
|
public override NetData GetNetData()
|
||||||
{
|
{
|
||||||
return new NetData(Id, BitConverter.GetBytes(Value));
|
return new NetData(Id, BitConverter.GetBytes(_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||||
@@ -69,7 +70,7 @@ public sealed class HideAndSeekHudHelper(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
var item = Helpers.GetAlivePlayers().Count(x => !x.Data.Role.IsImpostor);
|
var item = Helpers.GetAlivePlayers().Count(x => !x.Data.Role.IsImpostor);
|
||||||
return !player.inVent && player.Data != null && player.Data.Role != null &&
|
return !player.inVent && player.Data != null && player.Data.Role != null &&
|
||||||
((!player.inVent && player.Data.Role.IsImpostor && IsFinalCountdown &&
|
((!player.inVent && player.Data.Role.IsImpostor && IsFinalCountdown &&
|
||||||
OptionGroupSingleton<HnsFinalHideOptions>.Instance.FinalHideSeekMap.Value) ||
|
OptionGroupSingleton<HnsFinalHideOptions>.Instance.FinalHideSeekMap) ||
|
||||||
(player.Data.Role.IsImpostor &&
|
(player.Data.Role.IsImpostor &&
|
||||||
item <=
|
item <=
|
||||||
(GameData.Instance.PlayerCount - 1) / 3));
|
(GameData.Instance.PlayerCount - 1) / 3));
|
||||||
@@ -95,8 +96,8 @@ public sealed class HideAndSeekHudHelper(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
/// <returns>The match duration in seconds.</returns>
|
/// <returns>The match duration in seconds.</returns>
|
||||||
public static float GetTotalRoundTime()
|
public static float GetTotalRoundTime()
|
||||||
{
|
{
|
||||||
var escapeTime = OptionGroupSingleton<HnsCrewmateOptions>.Instance.HidingTime.Value;
|
var escapeTime = OptionGroupSingleton<HnsCrewmateOptions>.Instance.HidingTime;
|
||||||
var finalCountdownTime = OptionGroupSingleton<HnsFinalHideOptions>.Instance.FinalHideTime.Value;
|
var finalCountdownTime = OptionGroupSingleton<HnsFinalHideOptions>.Instance.FinalHideTime;
|
||||||
return escapeTime + finalCountdownTime;
|
return escapeTime + finalCountdownTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,9 +121,9 @@ public sealed class HideAndSeekHudHelper(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
totalHideTime = OptionGroupSingleton<HnsCrewmateOptions>.Instance.HidingTime.Value;
|
totalHideTime = OptionGroupSingleton<HnsCrewmateOptions>.Instance.HidingTime;
|
||||||
currentHideTime = totalHideTime;
|
currentHideTime = totalHideTime;
|
||||||
totalFinalHideTime = OptionGroupSingleton<HnsFinalHideOptions>.Instance.FinalHideTime.Value;
|
totalFinalHideTime = OptionGroupSingleton<HnsFinalHideOptions>.Instance.FinalHideTime;
|
||||||
currentFinalHideTime = totalFinalHideTime;
|
currentFinalHideTime = totalFinalHideTime;
|
||||||
if (timerBar != null)
|
if (timerBar != null)
|
||||||
{
|
{
|
||||||
@@ -244,7 +245,7 @@ public sealed class HideAndSeekHudHelper(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
{
|
{
|
||||||
playerControl.ClearTasks();
|
playerControl.ClearTasks();
|
||||||
PlayerTask.GetOrCreateTask<ImportantTextTask>(playerControl).Text =
|
PlayerTask.GetOrCreateTask<ImportantTextTask>(playerControl).Text =
|
||||||
DestroyableSingleton<TranslationController>.Instance.GetString(StringNames.HideActionButton);
|
TranslationController.Instance.GetString(StringNames.HideActionButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,14 +260,14 @@ public sealed class HideAndSeekHudHelper(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
|
|
||||||
timerBar.StartFinalHide();
|
timerBar.StartFinalHide();
|
||||||
SoundManager.Instance.PlaySound(finalHideAlertSfx, false);
|
SoundManager.Instance.PlaySound(finalHideAlertSfx, false);
|
||||||
DestroyableSingleton<HudManager>.Instance.SetAlertOverlay(true);
|
HudManager.Instance.SetAlertOverlay(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AdjustEscapeTimer(float timeDeduction, bool forceDirty)
|
private void AdjustEscapeTimer(float timeDeduction, bool forceDirty)
|
||||||
{
|
{
|
||||||
var num = currentHideTime;
|
var num = currentHideTime;
|
||||||
currentHideTime -= timeDeduction;
|
currentHideTime -= timeDeduction;
|
||||||
currentHideTime = Mathf.Max(currentHideTime, 0f);
|
currentHideTime = Math.Max(currentHideTime, 0f);
|
||||||
if (currentHideTime <= 10f && beepCoroutine == null)
|
if (currentHideTime <= 10f && beepCoroutine == null)
|
||||||
{
|
{
|
||||||
beepCoroutine = StartCoroutine(BeepAlmostEverySecond().WrapToIl2Cpp());
|
beepCoroutine = StartCoroutine(BeepAlmostEverySecond().WrapToIl2Cpp());
|
||||||
@@ -308,7 +309,7 @@ public sealed class HideAndSeekHudHelper(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
private void AdjustFinalEscapeTimer(float timeDeduction)
|
private void AdjustFinalEscapeTimer(float timeDeduction)
|
||||||
{
|
{
|
||||||
currentFinalHideTime -= timeDeduction;
|
currentFinalHideTime -= timeDeduction;
|
||||||
currentFinalHideTime = Mathf.Max(currentFinalHideTime, 0f);
|
currentFinalHideTime = Math.Max(currentFinalHideTime, 0f);
|
||||||
timerBar.UpdateTimer(currentFinalHideTime, totalFinalHideTime);
|
timerBar.UpdateTimer(currentFinalHideTime, totalFinalHideTime);
|
||||||
if (secondsSinceLastSetDirty > 1f)
|
if (secondsSinceLastSetDirty > 1f)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -91,9 +91,9 @@ public sealed class HnsDangerMeter(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dangerLevel1 = Mathf.Clamp01(
|
dangerLevel1 = MathUtilities.Clamp01(
|
||||||
(scaryMusicDistance - num) / (scaryMusicDistance - veryScaryMusicDistance));
|
(scaryMusicDistance - num) / (scaryMusicDistance - veryScaryMusicDistance));
|
||||||
dangerLevel2 = Mathf.Clamp01((veryScaryMusicDistance - num) / veryScaryMusicDistance);
|
dangerLevel2 = MathUtilities.Clamp01((veryScaryMusicDistance - num) / veryScaryMusicDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateDangerMeter();
|
UpdateDangerMeter();
|
||||||
@@ -137,7 +137,7 @@ public sealed class HnsDangerMeter(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
|
|
||||||
impostors = [.. Helpers.GetAlivePlayers().Where(x => x.Data.Role.IsImpostor)];
|
impostors = [.. Helpers.GetAlivePlayers().Where(x => x.Data.Role.IsImpostor)];
|
||||||
|
|
||||||
var baseSpeed = OptionGroupSingleton<HnsCrewmateOptions>.Instance.PlayerSpeed.Value;
|
var baseSpeed = OptionGroupSingleton<HnsCrewmateOptions>.Instance.PlayerSpeed;
|
||||||
scaryMusicDistance = 55f * baseSpeed;
|
scaryMusicDistance = 55f * baseSpeed;
|
||||||
veryScaryMusicDistance = 15f * baseSpeed;
|
veryScaryMusicDistance = 15f * baseSpeed;
|
||||||
if (scaryMusicDistance >= veryScaryMusicDistance) return;
|
if (scaryMusicDistance >= veryScaryMusicDistance) return;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using Amongus.GameModes.HideAndSeek;
|
using Amongus.GameModes.HideAndSeek;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using MiraAPI.HnsReimplemented.Options;
|
using MiraAPI.HnsReimplemented.Options;
|
||||||
|
using MiraAPI.Utilities;
|
||||||
using Reactor.Utilities.Attributes;
|
using Reactor.Utilities.Attributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -145,7 +146,7 @@ public sealed class HnsMusicHandler(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
public void StartMusicWithIntro()
|
public void StartMusicWithIntro()
|
||||||
{
|
{
|
||||||
if (!PlayerControl.LocalPlayer.Data.Role.IsImpostor) return;
|
if (!PlayerControl.LocalPlayer.Data.Role.IsImpostor) return;
|
||||||
var clip = OptionGroupSingleton<HnsCrewmateOptions>.Instance.HidingTime.Value <= 180f
|
var clip = OptionGroupSingleton<HnsCrewmateOptions>.Instance.HidingTime <= 180f
|
||||||
? musicCollection.ImpostorShortMusic
|
? musicCollection.ImpostorShortMusic
|
||||||
: musicCollection.ImpostorLongMusic;
|
: musicCollection.ImpostorLongMusic;
|
||||||
if (AprilFoolsMode.ShouldHorseAround())
|
if (AprilFoolsMode.ShouldHorseAround())
|
||||||
@@ -178,19 +179,19 @@ public sealed class HnsMusicHandler(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
SyncMusic();
|
SyncMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
normalSource.volume = Mathf.Lerp(
|
normalSource.volume = MathUtilities.Lerp(
|
||||||
normalSource.volume,
|
normalSource.volume,
|
||||||
normalVolume,
|
normalVolume,
|
||||||
Time.fixedDeltaTime * musicLerpSpeed);
|
Time.fixedDeltaTime * musicLerpSpeed);
|
||||||
taskSource.volume = Mathf.Lerp(
|
taskSource.volume = MathUtilities.Lerp(
|
||||||
taskSource.volume,
|
taskSource.volume,
|
||||||
taskVolume,
|
taskVolume,
|
||||||
Time.fixedDeltaTime * musicLerpSpeed);
|
Time.fixedDeltaTime * musicLerpSpeed);
|
||||||
dangerLevel1Source.volume = Mathf.Lerp(
|
dangerLevel1Source.volume = MathUtilities.Lerp(
|
||||||
dangerLevel1Source.volume,
|
dangerLevel1Source.volume,
|
||||||
dangerLevel1Volume,
|
dangerLevel1Volume,
|
||||||
Time.fixedDeltaTime * musicLerpSpeed);
|
Time.fixedDeltaTime * musicLerpSpeed);
|
||||||
dangerLevel2Source.volume = Mathf.Lerp(
|
dangerLevel2Source.volume = MathUtilities.Lerp(
|
||||||
dangerLevel2Source.volume,
|
dangerLevel2Source.volume,
|
||||||
dangerLevel2Volume,
|
dangerLevel2Volume,
|
||||||
Time.fixedDeltaTime * musicLerpSpeed);
|
Time.fixedDeltaTime * musicLerpSpeed);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using MiraAPI.GameModes;
|
using MiraAPI.GameModes;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
|
using MiraAPI.GameOptions.Attributes;
|
||||||
using MiraAPI.GameOptions.OptionTypes;
|
using MiraAPI.GameOptions.OptionTypes;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
|
|
||||||
@@ -9,108 +10,67 @@ namespace MiraAPI.HnsReimplemented.Options;
|
|||||||
/// Crewmate options for Hide and Seek.
|
/// Crewmate options for Hide and Seek.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// ReSharper disable once ClassNeverInstantiated.Global (Justification: Instantiated via Activator.CreateInstance.)
|
// ReSharper disable once ClassNeverInstantiated.Global (Justification: Instantiated via Activator.CreateInstance.)
|
||||||
|
[SearchPrivate]
|
||||||
public class HnsCrewmateOptions : AbstractOptionGroup<HideAndSeekMode>
|
public class HnsCrewmateOptions : AbstractOptionGroup<HideAndSeekMode>
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string GroupName => "Crewmates";
|
public override string GroupName => "MiraApi.Option.Group.HnsCrewmate";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string GroupPrefix => "MiraApi.HnsCrewmate.Option.";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the player speed.
|
/// Gets the player speed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption PlayerSpeed { get; } = new(
|
[ModdedNumberOption(0.5f, 3f, 0.25f, "#", "#", MiraNumberSuffixes.Multiplier, "0.00")]
|
||||||
"Player Speed",
|
public float PlayerSpeed { get; } = 1f;
|
||||||
1f,
|
|
||||||
0.5f,
|
|
||||||
3f,
|
|
||||||
0.25f,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.Multiplier,
|
|
||||||
"0.00");
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the hiding time.
|
/// Gets the hiding time.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption HidingTime { get; } = new(
|
[ModdedNumberOption(160, 300, 20, "#", "#", MiraNumberSuffixes.Seconds)]
|
||||||
"Hiding Time",
|
public float HidingTime { get; } = 200f;
|
||||||
200,
|
|
||||||
160,
|
|
||||||
300,
|
|
||||||
20,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.Seconds);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the limits of a crewmate's vision.
|
/// Gets the limits of a crewmate's vision.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption CrewmateVision { get; } = new(
|
[ModdedNumberOption(0.25f, 1, 0.05f, "#", "#", MiraNumberSuffixes.Multiplier, "0.00")]
|
||||||
"Crewmate Vision",
|
public float CrewmateVision { get; } = 0.6f;
|
||||||
0.6f,
|
|
||||||
0.25f,
|
|
||||||
1,
|
|
||||||
0.05f,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.Multiplier,
|
|
||||||
"0.00");
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a flag that toggles flashlight vision.
|
/// Gets a value indicating whether flashlight vision is turned on or not.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedToggleOption FlashlightMode { get; } = new(
|
[ModdedToggleOption]
|
||||||
"Flashlight Mode",
|
public bool FlashlightMode { get; } = true;
|
||||||
true);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the range of a crewmate's flashlight.
|
/// Gets the range of a crewmate's flashlight.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption CrewmateFlashlightSize { get; } = new(
|
[ModdedNumberOption(0.1f, 0.5f, 0.05f, "#", "#", MiraNumberSuffixes.Multiplier)]
|
||||||
"Crewmate Flashlight Size",
|
[ModdedOptionVisibility(nameof(FlashlightMode))]
|
||||||
0.35f,
|
public float CrewmateFlashlightSize { get; } = 0.35f;
|
||||||
0.1f,
|
|
||||||
0.5f,
|
|
||||||
0.05f,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.Multiplier)
|
|
||||||
{
|
|
||||||
Visible = () => OptionGroupSingleton<HnsCrewmateOptions>.Instance.FlashlightMode.Value,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the maximum number of times a crewmate can vent.
|
/// Gets the maximum number of times a crewmate can vent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption MaxVentUses { get; } = new(
|
[ModdedNumberOption(0, 5, 1, "#", "#", MiraNumberSuffixes.None)]
|
||||||
"Max Vent Uses",
|
public int MaxVentUses { get; } = 1;
|
||||||
1,
|
|
||||||
0,
|
|
||||||
5,
|
|
||||||
1,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.None);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the maximum amount of time a crewmate can spend inside a vent.
|
/// Gets the maximum amount of time a crewmate can spend inside a vent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption MaxTimeInVent { get; } = new(
|
[ModdedNumberOption(1, 10, 1, "#", "#", MiraNumberSuffixes.Seconds)]
|
||||||
"Max Time in Vent",
|
[ModdedOptionVisibility(nameof(LimitedVentUses))]
|
||||||
3,
|
public float MaxTimeInVent { get; } = 3f;
|
||||||
1,
|
|
||||||
10,
|
|
||||||
1,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.Seconds)
|
|
||||||
{
|
|
||||||
Visible = () => (int)OptionGroupSingleton<HnsCrewmateOptions>.Instance.MaxVentUses.Value > 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the visibility of player names.
|
/// Gets a value indicating whether player names are visible.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedToggleOption ShowNames { get; } = new(
|
[ModdedToggleOption]
|
||||||
"Show Names",
|
public bool ShowNames { get; } = false;
|
||||||
false);
|
|
||||||
|
private bool LimitedVentUses()
|
||||||
|
{
|
||||||
|
return MaxVentUses > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using MiraAPI.GameModes;
|
using MiraAPI.GameModes;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
|
using MiraAPI.GameOptions.Attributes;
|
||||||
using MiraAPI.GameOptions.OptionTypes;
|
using MiraAPI.GameOptions.OptionTypes;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
|
|
||||||
@@ -9,62 +10,43 @@ namespace MiraAPI.HnsReimplemented.Options;
|
|||||||
/// Final Hide options for Hide and Seek.
|
/// Final Hide options for Hide and Seek.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// ReSharper disable once ClassNeverInstantiated.Global (Justification: Instantiated via Activator.CreateInstance.)
|
// ReSharper disable once ClassNeverInstantiated.Global (Justification: Instantiated via Activator.CreateInstance.)
|
||||||
|
[SearchPrivate]
|
||||||
public class HnsFinalHideOptions : AbstractOptionGroup<HideAndSeekMode>
|
public class HnsFinalHideOptions : AbstractOptionGroup<HideAndSeekMode>
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string GroupName => "Final Hide";
|
public override string GroupName => "MiraApi.Option.Group.HnsFinalHide";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string GroupPrefix => "MiraApi.HnsFinalHide.Option.";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the duration of the Final Hide phase.
|
/// Gets the duration of the Final Hide phase.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption FinalHideTime { get; } = new(
|
[ModdedNumberOption(30f, 120f, 5f, "#", "#", MiraNumberSuffixes.Seconds)]
|
||||||
"Hiding Time",
|
public float FinalHideTime { get; } = 50f;
|
||||||
50,
|
|
||||||
30,
|
|
||||||
120,
|
|
||||||
5,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.Seconds);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the Seeker's speed when the Final Hide phase begins.
|
/// Gets the Seeker's speed when the Final Hide phase begins.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption FinalHideImpostorSpeed { get; } = new(
|
[ModdedNumberOption(1f, 3f, 0.05f, "#", "#", MiraNumberSuffixes.Multiplier, "0.00")]
|
||||||
"Final Hide Impostor Speed",
|
public float FinalHideImpostorSpeed { get; } = 1.2f;
|
||||||
1.2f,
|
|
||||||
1f,
|
|
||||||
3,
|
|
||||||
0.05f,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.Multiplier,
|
|
||||||
"0.00");
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets whether the Seeker sees the Final hide player pings.
|
/// Gets a value indicating whether the Seeker sees the Final hide player pings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedToggleOption FinalHidePings { get; } = new(
|
[ModdedToggleOption]
|
||||||
"Final Hide Pings",
|
public bool FinalHidePings { get; } = true;
|
||||||
true);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the interval between each ping.
|
/// Gets the interval between each ping.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption PingInterval { get; } = new(
|
[ModdedNumberOption(3f, 10f, 1f, "#", "#", MiraNumberSuffixes.Seconds)]
|
||||||
"Ping Interval",
|
[ModdedOptionVisibility(nameof(FinalHidePings))]
|
||||||
6,
|
public float PingInterval { get; } = 6f;
|
||||||
3,
|
|
||||||
10,
|
|
||||||
5,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.Seconds);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets whether the Seeker can see players on an admin map.
|
/// Gets a value indicating whether the Seeker can see players on an admin map.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedToggleOption FinalHideSeekMap { get; } = new(
|
[ModdedToggleOption]
|
||||||
"Final Hide Seek Map",
|
public bool FinalHideSeekMap { get; } = true;
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using MiraAPI.GameModes;
|
using MiraAPI.GameModes;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
|
using MiraAPI.GameOptions.Attributes;
|
||||||
using MiraAPI.GameOptions.OptionTypes;
|
using MiraAPI.GameOptions.OptionTypes;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
|
|
||||||
@@ -9,44 +10,36 @@ namespace MiraAPI.HnsReimplemented.Options;
|
|||||||
/// Seeker settings on Hide and Seek.
|
/// Seeker settings on Hide and Seek.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// ReSharper disable once ClassNeverInstantiated.Global (Justification: Instantiated via Activator.CreateInstance.)
|
// ReSharper disable once ClassNeverInstantiated.Global (Justification: Instantiated via Activator.CreateInstance.)
|
||||||
|
[SearchPrivate]
|
||||||
public class HnsImpostorOptions : AbstractOptionGroup<HideAndSeekMode>
|
public class HnsImpostorOptions : AbstractOptionGroup<HideAndSeekMode>
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string GroupName => "Impostors";
|
public override string GroupName => "MiraApi.Option.Group.HnsImpostor";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string GroupPrefix => "MiraApi.HnsImpostor.Option.";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the player who will be the seeker.
|
/// Gets the player who will be the seeker.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedPlayerOption SelectedSeeker { get; } = new(
|
[ModdedPlayerOption]
|
||||||
"Forced Impostor");
|
public int SelectedSeeker { get; } = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the range of a seeker's vision.
|
/// Gets the range of a seeker's vision.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption ImpostorVision { get; } = new(
|
[ModdedNumberOption(0.25f, 1f, 0.05f, "#", "#", MiraNumberSuffixes.Multiplier, "0.00")]
|
||||||
"Impostor Vision",
|
public float ImpostorVision { get; } = 0.6f;
|
||||||
0.6f,
|
|
||||||
0.25f,
|
|
||||||
1,
|
|
||||||
0.05f,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.Multiplier,
|
|
||||||
"0.00");
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the range of a seeker's flashlight.
|
/// Gets the range of a seeker's flashlight.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption ImpostorFlashlightSize { get; } = new(
|
[ModdedNumberOption(0.1f, 0.5f, 0.05f, "#", "#", MiraNumberSuffixes.Multiplier)]
|
||||||
"Impostor Flashlight Size",
|
[ModdedOptionVisibility(nameof(IsFlashlightModeEnabled))]
|
||||||
0.35f,
|
public float ImpostorFlashlightSize { get; } = 0.35f;
|
||||||
0.1f,
|
|
||||||
0.5f,
|
private static bool IsFlashlightModeEnabled()
|
||||||
0.05f,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.Multiplier)
|
|
||||||
{
|
{
|
||||||
Visible = () => OptionGroupSingleton<HnsCrewmateOptions>.Instance.FlashlightMode.Value,
|
return OptionGroupSingleton<HnsCrewmateOptions>.Instance.FlashlightMode;
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using MiraAPI.GameModes;
|
using MiraAPI.GameModes;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
|
using MiraAPI.GameOptions.Attributes;
|
||||||
using MiraAPI.GameOptions.OptionTypes;
|
using MiraAPI.GameOptions.OptionTypes;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
|
|
||||||
@@ -9,47 +10,30 @@ namespace MiraAPI.HnsReimplemented.Options;
|
|||||||
/// Task options for Hide and Seek.
|
/// Task options for Hide and Seek.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// ReSharper disable once ClassNeverInstantiated.Global (Justification: Instantiated via Activator.CreateInstance.)
|
// ReSharper disable once ClassNeverInstantiated.Global (Justification: Instantiated via Activator.CreateInstance.)
|
||||||
|
[SearchPrivate]
|
||||||
public class HnsTaskOptions : AbstractOptionGroup<HideAndSeekMode>
|
public class HnsTaskOptions : AbstractOptionGroup<HideAndSeekMode>
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string GroupName => "Tasks";
|
public override string GroupName => "MiraApi.Option.Group.HnsTask";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string GroupPrefix => "MiraApi.HnsTask.Option.";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the umber of common tasks.
|
/// Gets the number of common tasks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption CommonTasks { get; } = new(
|
[ModdedNumberOption(0, 4, 1, "#", "#", MiraNumberSuffixes.None)]
|
||||||
"# Common Tasks",
|
public int CommonTasks { get; } = 1;
|
||||||
1,
|
|
||||||
0,
|
|
||||||
4,
|
|
||||||
1,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.None);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the number of long tasks.
|
/// Gets the number of long tasks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption LongTasks { get; } = new(
|
[ModdedNumberOption(0, 4, 1, "#", "#", MiraNumberSuffixes.None)]
|
||||||
"# Long Tasks",
|
public int LongTasks { get; } = 1;
|
||||||
1,
|
|
||||||
0,
|
|
||||||
4,
|
|
||||||
1,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.None);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the number of short tasks.
|
/// Gets the number of short tasks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModdedNumberOption ShortTasks { get; } = new(
|
[ModdedNumberOption(0, 8, 1, "#", "#", MiraNumberSuffixes.None)]
|
||||||
"# Short Tasks",
|
public int ShortTasks { get; } = 2;
|
||||||
2,
|
|
||||||
0,
|
|
||||||
8,
|
|
||||||
1,
|
|
||||||
"#",
|
|
||||||
"#",
|
|
||||||
MiraNumberSuffixes.None);
|
|
||||||
}
|
}
|
||||||
@@ -297,7 +297,7 @@ public abstract class CustomActionButton
|
|||||||
/// <param name="time">The time you want to set to.</param>
|
/// <param name="time">The time you want to set to.</param>
|
||||||
public virtual void SetTimer(float time)
|
public virtual void SetTimer(float time)
|
||||||
{
|
{
|
||||||
Timer = Mathf.Clamp(time, -1, float.MaxValue);
|
Timer = Math.Clamp(time, -1, float.MaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -333,7 +333,7 @@ public abstract class CustomActionButton
|
|||||||
/// <param name="amount">The amount you want to set to.</param>
|
/// <param name="amount">The amount you want to set to.</param>
|
||||||
public virtual void SetUses(int amount)
|
public virtual void SetUses(int amount)
|
||||||
{
|
{
|
||||||
UsesLeft = Mathf.Clamp(amount, 0, int.MaxValue);
|
UsesLeft = Math.Clamp(amount, 0, int.MaxValue);
|
||||||
Button?.SetUsesRemaining(UsesLeft);
|
Button?.SetUsesRemaining(UsesLeft);
|
||||||
|
|
||||||
if (Button != null) Button.usesRemainingSprite.color = UsesLeft == 0 ? Color.red : Color.white;
|
if (Button != null) Button.usesRemainingSprite.color = UsesLeft == 0 ? Color.red : Color.white;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public static class CustomButtonManager
|
|||||||
|
|
||||||
internal static bool RegisterButton(Type type, in MiraPluginManager.RegistrationContext context)
|
internal static bool RegisterButton(Type type, in MiraPluginManager.RegistrationContext context)
|
||||||
{
|
{
|
||||||
if (!type.IsAssignableTo(typeof(CustomActionButton)) || Activator.CreateInstance(type) is not CustomActionButton button)
|
if (type.IsAbstract || !type.IsAssignableTo(typeof(CustomActionButton)) || Activator.CreateInstance(type) is not CustomActionButton button)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu<CustomPaginableMenu.
|
|||||||
|
|
||||||
private static int GetTotalPages(int itemCount)
|
private static int GetTotalPages(int itemCount)
|
||||||
{
|
{
|
||||||
return Mathf.Max(1, Mathf.CeilToInt(itemCount / (float)ItemsPerPage));
|
return Math.Max(1, Mathf.CeilToInt(itemCount / (float)ItemsPerPage));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshControllerOverlay(CppCollections.List<UiElement> list)
|
private void RefreshControllerOverlay(CppCollections.List<UiElement> list)
|
||||||
@@ -170,7 +170,7 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu<CustomPaginableMenu.
|
|||||||
var filtered = GetFilteredEntries();
|
var filtered = GetFilteredEntries();
|
||||||
noResultsText?.gameObject.SetActive(filtered.Count == 0 && !string.IsNullOrWhiteSpace(searchText));
|
noResultsText?.gameObject.SetActive(filtered.Count == 0 && !string.IsNullOrWhiteSpace(searchText));
|
||||||
var totalPages = GetTotalPages(filtered.Count);
|
var totalPages = GetTotalPages(filtered.Count);
|
||||||
currentPage = Mathf.Clamp(currentPage, 0, totalPages - 1);
|
currentPage = Math.Clamp(currentPage, 0, totalPages - 1);
|
||||||
|
|
||||||
var list = filtered.Skip(currentPage * ItemsPerPage).Take(ItemsPerPage).ToList();
|
var list = filtered.Skip(currentPage * ItemsPerPage).Take(ItemsPerPage).ToList();
|
||||||
var list2 = new CppCollections.List<UiElement>();
|
var list2 = new CppCollections.List<UiElement>();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public static class LocalSettingsManager
|
|||||||
|
|
||||||
internal static bool RegisterLocalTabs(Type type, in MiraPluginManager.RegistrationContext context)
|
internal static bool RegisterLocalTabs(Type type, in MiraPluginManager.RegistrationContext context)
|
||||||
{
|
{
|
||||||
if (!type.IsAssignableTo(typeof(LocalSettingsTab)))
|
if (type.IsAbstract || !type.IsAssignableTo(typeof(LocalSettingsTab)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
|||||||
TabButton.Content = tab.gameObject;
|
TabButton.Content = tab.gameObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<string, List<ILocalSetting>> entriesByGroup = [];
|
Dictionary<string, List<ILocalSetting>> entriesByGroup = new(StringComparer.Ordinal);
|
||||||
|
|
||||||
foreach (var entry in Settings)
|
foreach (var entry in Settings)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ public class LocalSliderSetting(
|
|||||||
newSlider.OnValueChange.AddListener((UnityAction)(() =>
|
newSlider.OnValueChange.AddListener((UnityAction)(() =>
|
||||||
{
|
{
|
||||||
SetValue(RoundValue
|
SetValue(RoundValue
|
||||||
? Mathf.Round(Mathf.Lerp(SliderRange.min, SliderRange.max, newSlider.Value))
|
? MathF.Round(MathUtilities.Lerp(SliderRange.min, SliderRange.max, newSlider.Value))
|
||||||
: Mathf.Lerp(SliderRange.min, SliderRange.max, newSlider.Value));
|
: MathUtilities.Lerp(SliderRange.min, SliderRange.max, newSlider.Value));
|
||||||
|
|
||||||
newSlider.Title.text = GetValueText();
|
newSlider.Title.text = GetValueText();
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Il2CppInterop.Runtime.Attributes;
|
using Il2CppInterop.Runtime.Attributes;
|
||||||
@@ -125,7 +126,7 @@ public class MeetingAbilityBehaviour : MonoBehaviour
|
|||||||
/// <param name="maxTimer">The maximum timer.</param>
|
/// <param name="maxTimer">The maximum timer.</param>
|
||||||
public void SetFillUp(float timer, float maxTimer)
|
public void SetFillUp(float timer, float maxTimer)
|
||||||
{
|
{
|
||||||
var percentCool = Mathf.Clamp(timer / maxTimer, 0.001f, 1f);
|
var percentCool = Math.Clamp(timer / maxTimer, 0.001f, 1f);
|
||||||
if (percentCool <= 0) percentCool = 1f;
|
if (percentCool <= 0) percentCool = 1f;
|
||||||
Renderer.material.SetFloat(ShaderID.Percent, percentCool);
|
Renderer.material.SetFloat(ShaderID.Percent, percentCool);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -179,7 +180,7 @@ public abstract class MeetingActionButton
|
|||||||
/// <param name="time">The time you want to set to.</param>
|
/// <param name="time">The time you want to set to.</param>
|
||||||
public virtual void SetTimer(float time)
|
public virtual void SetTimer(float time)
|
||||||
{
|
{
|
||||||
Timer = Mathf.Clamp(time, -1, float.MaxValue);
|
Timer = Math.Clamp(time, -1, float.MaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -215,7 +216,7 @@ public abstract class MeetingActionButton
|
|||||||
/// <param name="amount">The amount you want to set to.</param>
|
/// <param name="amount">The amount you want to set to.</param>
|
||||||
public virtual void SetUses(int amount)
|
public virtual void SetUses(int amount)
|
||||||
{
|
{
|
||||||
UsesLeft = Mathf.Clamp(amount, 0, int.MaxValue);
|
UsesLeft = Math.Clamp(amount, 0, int.MaxValue);
|
||||||
Button?.SetUsesRemaining(UsesLeft);
|
Button?.SetUsesRemaining(UsesLeft);
|
||||||
|
|
||||||
if (Button != null)
|
if (Button != null)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public static class MeetingButtonManager
|
|||||||
|
|
||||||
internal static bool RegisterTargetedMeetingButton(Type type, in MiraPluginManager.RegistrationContext context)
|
internal static bool RegisterTargetedMeetingButton(Type type, in MiraPluginManager.RegistrationContext context)
|
||||||
{
|
{
|
||||||
if (!typeof(TargetedMeetingButton).IsAssignableFrom(type))
|
if (type.IsAbstract || !typeof(TargetedMeetingButton).IsAssignableFrom(type))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ public static class MeetingButtonManager
|
|||||||
|
|
||||||
internal static bool RegisterMeetingButton(Type type, in MiraPluginManager.RegistrationContext context)
|
internal static bool RegisterMeetingButton(Type type, in MiraPluginManager.RegistrationContext context)
|
||||||
{
|
{
|
||||||
if (!typeof(MeetingActionButton).IsAssignableFrom(type))
|
if (type.IsAbstract || !typeof(MeetingActionButton).IsAssignableFrom(type))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public abstract class TargetedMeetingButton
|
|||||||
public virtual void UpdateHandler()
|
public virtual void UpdateHandler()
|
||||||
{
|
{
|
||||||
Timer -= Time.deltaTime;
|
Timer -= Time.deltaTime;
|
||||||
Timer = Mathf.Clamp(Timer, 0, int.MaxValue);
|
Timer = System.Math.Clamp(Timer, 0, int.MaxValue);
|
||||||
FixedUpdate();
|
FixedUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ public partial class MiraApiPlugin : BasePlugin, IMiraPlugin
|
|||||||
internal static ConfigEntry<SortingGroups> WikiSortingGroup { get; private set; }
|
internal static ConfigEntry<SortingGroups> WikiSortingGroup { get; private set; }
|
||||||
internal static ConfigEntry<SortingMethod> WikiSortingMethod { get; private set; }
|
internal static ConfigEntry<SortingMethod> WikiSortingMethod { get; private set; }
|
||||||
internal static ConfigEntry<SortingFilter> WikiSortingFilter { get; private set; }
|
internal static ConfigEntry<SortingFilter> WikiSortingFilter { get; private set; }
|
||||||
internal static ConfigEntry<string> DistanceSuffix { get; private set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Load()
|
public override void Load()
|
||||||
@@ -91,11 +90,6 @@ public partial class MiraApiPlugin : BasePlugin, IMiraPlugin
|
|||||||
"WikiSortingFilter",
|
"WikiSortingFilter",
|
||||||
SortingFilter.AllRoles,
|
SortingFilter.AllRoles,
|
||||||
"Determines what roles / modifiers are displayed at once.");
|
"Determines what roles / modifiers are displayed at once.");
|
||||||
DistanceSuffix = Config.Bind(
|
|
||||||
"Display",
|
|
||||||
"Distance",
|
|
||||||
"unit(s)",
|
|
||||||
"Dictates the unit of distance used in numeric option displays representing a distance.");
|
|
||||||
Harmony.PatchAll();
|
Harmony.PatchAll();
|
||||||
RoleOptionsCollectionPatch.PatchRoleMethods(Harmony);
|
RoleOptionsCollectionPatch.PatchRoleMethods(Harmony);
|
||||||
|
|
||||||
|
|||||||
@@ -195,19 +195,22 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
|||||||
/// Gets the scale of the ability buttons.
|
/// Gets the scale of the ability buttons.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LocalSliderSetting(min: 0.5f, max: 1.5f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
[LocalSliderSetting(min: 0.5f, max: 1.5f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
||||||
public ConfigEntry<float> ButtonUIFactorSlider { get; } = config.Bind("MiraApi.VisualsUi", "MiraApi.ButtonScaleFactor", 0.75f);
|
public ConfigEntry<float> ButtonUIFactorSlider { get; } =
|
||||||
|
config.Bind("MiraApi.VisualsUi", "MiraApi.ButtonScaleFactor", 0.75f, new ConfigDescription(string.Empty, new SafeAcceptableValueRange<float>(0.5f, 1.5f)));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the scale of the UI buttons.
|
/// Gets the scale of the UI buttons.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LocalSliderSetting(min: 0.3f, max: 2f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
[LocalSliderSetting(min: 0.3f, max: 2f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
||||||
public ConfigEntry<float> TopRightButtonsFactorSlider { get; } = config.Bind("MiraApi.VisualsUi", "MiraApi.TopRightButtonScaleFactor", 1f);
|
public ConfigEntry<float> TopRightButtonsFactorSlider { get; } =
|
||||||
|
config.Bind("MiraApi.VisualsUi", "MiraApi.TopRightButtonScaleFactor", 1f, new ConfigDescription(string.Empty, new SafeAcceptableValueRange<float>(0.3f, 2f)));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the fps specified by the player.
|
/// Gets the fps specified by the player.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LocalSliderSetting(min: 60f, max: 240f, suffixType: MiraNumberSuffixes.None, formatString: "0", displayValue: true, roundValue: true)]
|
[LocalSliderSetting(min: 60f, max: 240f, suffixType: MiraNumberSuffixes.None, formatString: "0", displayValue: true, roundValue: true)]
|
||||||
public ConfigEntry<float> SetFpsSlider { get; } = config.Bind("MiraApi.VisualsUi", "Max FPS", 120f);
|
public ConfigEntry<float> SetFpsSlider { get; } =
|
||||||
|
config.Bind("MiraApi.VisualsUi", "MiraApi.MaxFps", 120f, new ConfigDescription(string.Empty, new SafeAcceptableValueRange<float>(60f, 240f)));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets whether the modifiers hud should be on the left side of the screen (under roles/task tab). Recommended for streamers.
|
/// Gets whether the modifiers hud should be on the left side of the screen (under roles/task tab). Recommended for streamers.
|
||||||
@@ -225,7 +228,8 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
|||||||
/// Gets the scale of the match info guide.
|
/// Gets the scale of the match info guide.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[LocalSliderSetting(min: 0.5f, max: 1f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
[LocalSliderSetting(min: 0.5f, max: 1f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
||||||
public ConfigEntry<float> MatchInfoGuideScaleFactor { get; } = config.Bind("MiraApi.MatchInfoGuide", "MiraApi.MatchInfoGuideScaleFactor", 1f);
|
public ConfigEntry<float> MatchInfoGuideScaleFactor { get; } =
|
||||||
|
config.Bind("MiraApi.MatchInfoGuide", "MiraApi.MatchInfoGuideScaleFactor", 1f, new ConfigDescription(string.Empty, new SafeAcceptableValueRange<float>(0.5f, 1f)));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the flag indicating whether the wiki is on the bottom row.
|
/// Gets the flag indicating whether the wiki is on the bottom row.
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Il2CppInterop.Runtime.Attributes;
|
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
@@ -171,7 +170,6 @@ public abstract class BaseModifier : IOptionable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of abilities or other similar information to display below the text of a modifier's wiki page.
|
/// Gets the list of abilities or other similar information to display below the text of a modifier's wiki page.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HideFromIl2Cpp]
|
|
||||||
public virtual List<AdvancedWikiAbilityDescription> WikiAbilities => [];
|
public virtual List<AdvancedWikiAbilityDescription> WikiAbilities => [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -182,7 +180,6 @@ public abstract class BaseModifier : IOptionable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="TMP_SpriteAsset"/> for the Modifier Icon.
|
/// Gets the <see cref="TMP_SpriteAsset"/> for the Modifier Icon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HideFromIl2Cpp]
|
|
||||||
public virtual TMP_SpriteAsset IconTmp => null!;
|
public virtual TMP_SpriteAsset IconTmp => null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -165,7 +166,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
private void UpdatePage()
|
private void UpdatePage()
|
||||||
{
|
{
|
||||||
var totalPages = Mathf.CeilToInt((float)_modifiers.Count / ItemsPerPage);
|
var totalPages = Mathf.CeilToInt((float)_modifiers.Count / ItemsPerPage);
|
||||||
_currentPage = Mathf.Clamp(_currentPage, 0, Mathf.Max(0, totalPages - 1));
|
_currentPage = Math.Clamp(_currentPage, 0, Math.Max(0, totalPages - 1));
|
||||||
|
|
||||||
if (_modifiers.Count <= ItemsPerPage)
|
if (_modifiers.Count <= ItemsPerPage)
|
||||||
{
|
{
|
||||||
@@ -177,7 +178,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
_pagination.gameObject.SetActive(true);
|
_pagination.gameObject.SetActive(true);
|
||||||
if (_pageText != null)
|
if (_pageText != null)
|
||||||
{
|
{
|
||||||
_pageText.text = $"{MiraLocaleManager.Get("MiraApi.ModifierDisplay.Page", "Page")} {_currentPage + 1}/{Mathf.Max(totalPages, 1)}";
|
_pageText.text = $"{MiraLocaleManager.Get("MiraApi.ModifierDisplay.Page", "Page")} {_currentPage + 1}/{Math.Max(totalPages, 1)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
_nextButton.gameObject.SetActive(true);
|
_nextButton.gameObject.SetActive(true);
|
||||||
@@ -185,7 +186,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
|
|
||||||
_modifiers.Do(x => x.Value.gameObject.SetActive(false));
|
_modifiers.Do(x => x.Value.gameObject.SetActive(false));
|
||||||
var start = _currentPage * ItemsPerPage;
|
var start = _currentPage * ItemsPerPage;
|
||||||
var end = Mathf.Min(start + ItemsPerPage, _modifiers.Count);
|
var end = Math.Min(start + ItemsPerPage, _modifiers.Count);
|
||||||
var modifiers = _modifiers.ToArray();
|
var modifiers = _modifiers.ToArray();
|
||||||
|
|
||||||
for (var i = start; i < end; i++)
|
for (var i = start; i < end; i++)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public static class ModifierManager
|
|||||||
|
|
||||||
internal static bool RegisterModifier(Type type, in MiraPluginManager.RegistrationContext context)
|
internal static bool RegisterModifier(Type type, in MiraPluginManager.RegistrationContext context)
|
||||||
{
|
{
|
||||||
if (!typeof(BaseModifier).IsAssignableFrom(type))
|
if (type.IsAbstract || !typeof(BaseModifier).IsAssignableFrom(type))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using AmongUs.GameOptions;
|
||||||
using AmongUs.GameOptions;
|
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.Events;
|
using MiraAPI.Events;
|
||||||
using MiraAPI.Events.Vanilla.Gameplay;
|
using MiraAPI.Events.Vanilla.Gameplay;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
@@ -24,7 +25,7 @@ namespace MiraAPI.Patches.Freeplay;
|
|||||||
[HarmonyPatch(typeof(TaskAdderGame))]
|
[HarmonyPatch(typeof(TaskAdderGame))]
|
||||||
public static class TaskAdderPatches
|
public static class TaskAdderPatches
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<string, TaskFolder> Folders = [];
|
private static readonly Dictionary<string, TaskFolder> Folders = new(StringComparer.Ordinal);
|
||||||
private static Scroller _scroller = null!;
|
private static Scroller _scroller = null!;
|
||||||
|
|
||||||
public static string CrewmateName => TranslationController.Instance.GetString(StringNames.Crewmate);
|
public static string CrewmateName => TranslationController.Instance.GetString(StringNames.Crewmate);
|
||||||
@@ -237,7 +238,7 @@ public static class TaskAdderPatches
|
|||||||
item.transform.SetParent(instance.TaskParent);
|
item.transform.SetParent(instance.TaskParent);
|
||||||
item.transform.localPosition = new Vector3(xCursor, yCursor, 0f);
|
item.transform.localPosition = new Vector3(xCursor, yCursor, 0f);
|
||||||
item.transform.localScale = Vector3.one;
|
item.transform.localScale = Vector3.one;
|
||||||
maxHeight = Mathf.Max(maxHeight, item.Text.bounds.size.y + 1.3f);
|
maxHeight = Math.Max(maxHeight, item.Text.bounds.size.y + 1.3f);
|
||||||
xCursor += instance.fileWidth;
|
xCursor += instance.fileWidth;
|
||||||
if (xCursor > instance.lineWidth)
|
if (xCursor > instance.lineWidth)
|
||||||
{
|
{
|
||||||
@@ -288,7 +289,7 @@ public static class TaskAdderPatches
|
|||||||
taskFolder2.Parent = __instance;
|
taskFolder2.Parent = __instance;
|
||||||
taskFolder2.transform.localPosition = new Vector3(num, num2, 0f);
|
taskFolder2.transform.localPosition = new Vector3(num, num2, 0f);
|
||||||
taskFolder2.transform.localScale = Vector3.one;
|
taskFolder2.transform.localScale = Vector3.one;
|
||||||
num3 = Mathf.Max(num3, taskFolder2.Text.bounds.size.y + 1.1f);
|
num3 = Math.Max(num3, taskFolder2.Text.bounds.size.y + 1.1f);
|
||||||
num += __instance.folderWidth;
|
num += __instance.folderWidth;
|
||||||
if (num > __instance.lineWidth)
|
if (num > __instance.lineWidth)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ internal static class GameOptionsMenuPatch
|
|||||||
_gamemodeDescription.transform.localPosition = new Vector3(0.3f, 0, -0.01f);
|
_gamemodeDescription.transform.localPosition = new Vector3(0.3f, 0, -0.01f);
|
||||||
_gamemodeDescription.horizontalAlignment = HorizontalAlignmentOptions.Left;
|
_gamemodeDescription.horizontalAlignment = HorizontalAlignmentOptions.Left;
|
||||||
var texture = icon.LoadAsset().texture;
|
var texture = icon.LoadAsset().texture;
|
||||||
var scale = Mathf.Min(128f / texture.width, 128f / texture.height);
|
var scale = Math.Min(128f / texture.width, 128f / texture.height);
|
||||||
|
|
||||||
var newSprite = Sprite.Create(
|
var newSprite = Sprite.Create(
|
||||||
texture,
|
texture,
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ public static class OptionsPatches
|
|||||||
}
|
}
|
||||||
|
|
||||||
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title).Translate();
|
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title).Translate();
|
||||||
|
__instance.ValueText.text = Helpers.FormatValue(__instance.Value, (MiraNumberSuffixes)__instance.SuffixType, __instance.FormatString);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Options;
|
namespace MiraAPI.Patches.Options;
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ public static class PlayerOptionPatches
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newIndex = Mathf.Clamp(index, 0, __instance.Values.Count - 1);
|
var newIndex = Math.Clamp(index, 0, __instance.Values.Count - 1);
|
||||||
__instance.playerIndex = newIndex;
|
__instance.playerIndex = newIndex;
|
||||||
__instance.Value = __instance.Values[newIndex].PlayerId;
|
__instance.Value = __instance.Values[newIndex].PlayerId;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -688,8 +688,6 @@ public static class RoleSettingMenuPatches
|
|||||||
|
|
||||||
var roleOptionSetting = Object.Instantiate(
|
var roleOptionSetting = Object.Instantiate(
|
||||||
__instance.roleOptionSettingOrigin,
|
__instance.roleOptionSettingOrigin,
|
||||||
Vector3.zero,
|
|
||||||
Quaternion.identity,
|
|
||||||
__instance.RoleChancesSettings.transform);
|
__instance.RoleChancesSettings.transform);
|
||||||
roleOptionSetting.transform.localPosition = new Vector3(-0.1f, scrollerNum, -2f);
|
roleOptionSetting.transform.localPosition = new Vector3(-0.1f, scrollerNum, -2f);
|
||||||
|
|
||||||
@@ -743,7 +741,7 @@ public static class RoleSettingMenuPatches
|
|||||||
passiveButton.interactableColor = btnRend.color = customRole.OptionsMenuColor.FindAlternateColor();
|
passiveButton.interactableColor = btnRend.color = customRole.OptionsMenuColor.FindAlternateColor();
|
||||||
passiveButton.interactableHoveredColor = Color.white;
|
passiveButton.interactableHoveredColor = Color.white;
|
||||||
|
|
||||||
passiveButton.OnClick.AddListener((UnityAction)(() => { ChangeTab(role, __instance); }));
|
passiveButton.OnClick.AddListener((UnityAction)(() => ChangeTab(role, __instance)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customRole.Configuration is { MaxRoleCount: 0 })
|
if (customRole.Configuration is { MaxRoleCount: 0 })
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
using System.Globalization;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using MiraAPI.GameOptions.OptionTypes;
|
using MiraAPI.GameOptions.OptionTypes;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Options;
|
namespace MiraAPI.Patches.Options;
|
||||||
|
|
||||||
@@ -28,53 +27,54 @@ public static class SettingPatches
|
|||||||
ref string __result,
|
ref string __result,
|
||||||
[HarmonyArgument(0)] float value)
|
[HarmonyArgument(0)] float value)
|
||||||
{
|
{
|
||||||
string result;
|
return SetResult(ref __result, value, (MiraNumberSuffixes)__instance.SuffixType, __instance.FormatString, __instance.ZeroIsInfinity, __instance);
|
||||||
var suffix = (MiraNumberSuffixes)__instance.SuffixType;
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prefix for the <see cref="IntGameSetting.GetValueString"/> method. Adds support for custom number suffixes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="__instance">The <see cref="IntGameSetting"/> instance.</param>
|
||||||
|
/// <param name="__result">The result of the <see cref="IntGameSetting.GetValueString"/> method.</param>
|
||||||
|
/// <param name="value">The <see langword="float"/> value.</param>
|
||||||
|
/// <returns><see langword="false"/> to skip original method.</returns>
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(IntGameSetting), nameof(IntGameSetting.GetValueString))]
|
||||||
|
public static bool ValueStringPatch(
|
||||||
|
IntGameSetting __instance,
|
||||||
|
ref string __result,
|
||||||
|
[HarmonyArgument(0)] float value)
|
||||||
|
{
|
||||||
|
return SetResult(ref __result, value, (MiraNumberSuffixes)__instance.SuffixType, __instance.FormatString, __instance.ZeroIsInfinity, __instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool SetResult(ref string __result, float value, MiraNumberSuffixes suffix, string formatString, bool zeroIsInfinity, BaseGameSetting setting)
|
||||||
|
{
|
||||||
|
var custom = ModdedOptionsManager.ModdedOptions.Values.FirstOrDefault(opt => opt.Data == setting);
|
||||||
|
|
||||||
var custom =
|
|
||||||
ModdedOptionsManager.ModdedOptions.Values.FirstOrDefault(opt =>
|
|
||||||
opt.OptionBehaviour != null && opt.OptionBehaviour.Data == __instance);
|
|
||||||
if (custom is ModdedNumberOption moddedNumberOption)
|
if (custom is ModdedNumberOption moddedNumberOption)
|
||||||
{
|
{
|
||||||
if (moddedNumberOption.NegativeWordValue != "#" && (int)value == -1)
|
if (moddedNumberOption.NegativeWordValue != "#" && (int)value == -1)
|
||||||
{
|
{
|
||||||
result = $"<b>{moddedNumberOption.NegativeWordValue}</b>";
|
__result = $"<b>{moddedNumberOption.NegativeWordValue}</b>";
|
||||||
}
|
}
|
||||||
else if (moddedNumberOption.ZeroWordValue != "#" && Mathf.Abs(value) < 0.0001f)
|
else if (moddedNumberOption.ZeroWordValue != "#" && Math.Abs(value) < 0.0001f)
|
||||||
{
|
{
|
||||||
result = $"<b>{moddedNumberOption.ZeroWordValue}</b>";
|
__result = $"<b>{moddedNumberOption.ZeroWordValue}</b>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var part = value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo);
|
__result = Helpers.FormatValue(value, suffix, formatString);
|
||||||
result = suffix switch
|
|
||||||
{
|
|
||||||
MiraNumberSuffixes.None => part,
|
|
||||||
MiraNumberSuffixes.Multiplier => part + "x",
|
|
||||||
MiraNumberSuffixes.Percent => part + "%",
|
|
||||||
MiraNumberSuffixes.Distance => part + MiraApiPlugin.DistanceSuffix.Value,
|
|
||||||
_ => TranslationController.Instance.GetString(StringNames.GameSecondsAbbrev, part),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (__instance.ZeroIsInfinity && Mathf.Abs(value) < 0.0001f)
|
else if (zeroIsInfinity && Math.Abs(value) < 0.0001f)
|
||||||
{
|
{
|
||||||
result = "<b>∞</b>";
|
__result = "<b>∞</b>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var part = value.ToString(__instance.FormatString, NumberFormatInfo.InvariantInfo);
|
__result = Helpers.FormatValue(value, suffix, formatString);
|
||||||
result = suffix switch
|
|
||||||
{
|
|
||||||
MiraNumberSuffixes.None => part,
|
|
||||||
MiraNumberSuffixes.Multiplier => part + "x",
|
|
||||||
MiraNumberSuffixes.Percent => part + "%",
|
|
||||||
MiraNumberSuffixes.Distance => part + MiraApiPlugin.DistanceSuffix.Value,
|
|
||||||
_ => TranslationController.Instance.GetString(StringNames.GameSecondsAbbrev, part),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__result = result;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ public static class RoleGuidePatches
|
|||||||
}
|
}
|
||||||
|
|
||||||
var targetSize = Helpers.MatchInfoGuideBaseScale *
|
var targetSize = Helpers.MatchInfoGuideBaseScale *
|
||||||
Mathf.Clamp(scaleFactor, MinGuideScaleFactor, MaxGuideScaleFactor);
|
Math.Clamp(scaleFactor, MinGuideScaleFactor, MaxGuideScaleFactor);
|
||||||
instance.transitionOpen.targetSize = targetSize;
|
instance.transitionOpen.targetSize = targetSize;
|
||||||
if (instance.MatchInfoParent.activeSelf)
|
if (instance.MatchInfoParent.activeSelf)
|
||||||
{
|
{
|
||||||
@@ -228,12 +228,19 @@ public static class RoleGuidePatches
|
|||||||
|
|
||||||
private static IEnumerator CoPreload(MatchInfoGuide instance)
|
private static IEnumerator CoPreload(MatchInfoGuide instance)
|
||||||
{
|
{
|
||||||
while (instance && (!HudManager.InstanceExists || !GameManager.Instance))
|
var counter = 0;
|
||||||
|
while (!instance || !HudManager.InstanceExists || !GameManager.Instance)
|
||||||
{
|
{
|
||||||
yield return null;
|
counter++;
|
||||||
|
if (counter > 10)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance || GameManager.Instance.TryCast<NormalGameManager>() == null)
|
if (GameManager.Instance.TryCast<NormalGameManager>() == null)
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
@@ -1011,7 +1018,7 @@ public static class RoleGuidePatches
|
|||||||
|
|
||||||
private static float GetGridScrollBounds(int count)
|
private static float GetGridScrollBounds(int count)
|
||||||
{
|
{
|
||||||
return Mathf.Clamp(Mathf.Ceil(count / 2f) * 1.3f - 1.5f, 0f, 999f);
|
return Math.Clamp(MathF.Ceiling(count / 2f) * 1.3f - 1.5f, 0f, 999f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void StartPopulate(float delay = 0f)
|
private static void StartPopulate(float delay = 0f)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using HarmonyLib;
|
using System;
|
||||||
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Roles;
|
namespace MiraAPI.Patches.Roles;
|
||||||
@@ -52,8 +53,8 @@ internal static class TaskPanelPatch
|
|||||||
__instance.closedPosition = closePosition;
|
__instance.closedPosition = closePosition;
|
||||||
|
|
||||||
__instance.timer = __instance.open
|
__instance.timer = __instance.open
|
||||||
? Mathf.Min(1f, __instance.timer + Time.deltaTime / __instance.animationTimeSeconds)
|
? Math.Min(1f, __instance.timer + Time.deltaTime / __instance.animationTimeSeconds)
|
||||||
: Mathf.Max(0f, __instance.timer - Time.deltaTime / __instance.animationTimeSeconds);
|
: Math.Max(0f, __instance.timer - Time.deltaTime / __instance.animationTimeSeconds);
|
||||||
|
|
||||||
var relativePos = new Vector3(
|
var relativePos = new Vector3(
|
||||||
Mathf.SmoothStep(__instance.closedPosition.x, __instance.openPosition.x, __instance.timer),
|
Mathf.SmoothStep(__instance.closedPosition.x, __instance.openPosition.x, __instance.timer),
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
using BepInEx.Configuration;
|
|
||||||
using BepInEx.Unity.IL2CPP;
|
using BepInEx.Unity.IL2CPP;
|
||||||
|
using HarmonyLib;
|
||||||
using MiraAPI.Colors;
|
using MiraAPI.Colors;
|
||||||
using MiraAPI.Events;
|
using MiraAPI.Events;
|
||||||
using MiraAPI.GameEnd;
|
using MiraAPI.GameEnd;
|
||||||
@@ -40,16 +40,14 @@ public sealed class MiraPluginManager
|
|||||||
internal const BindingFlags DeclaredInstanceMembers = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
|
internal const BindingFlags DeclaredInstanceMembers = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
|
||||||
internal const BindingFlags DeclaredStaticMembers = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
|
internal const BindingFlags DeclaredStaticMembers = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
|
||||||
|
|
||||||
private readonly Dictionary<string, MiraPluginInfo> _registeredPlugins = [];
|
private readonly Dictionary<string, MiraPluginInfo> _registeredPlugins = new(StringComparer.Ordinal);
|
||||||
|
|
||||||
internal MiraPluginInfo[] RegisteredPlugins { get; private set; } = [];
|
internal MiraPluginInfo[] RegisteredPlugins { get; private set; } = [];
|
||||||
internal MiraPluginInfo[] RegisteredPluginsWithOptions { get; private set; } = [];
|
internal MiraPluginInfo[] RegisteredPluginsWithOptions { get; private set; } = [];
|
||||||
internal MiraPluginInfo[] PluginsWithOptionsOrGameModes { get; private set; } = [];
|
internal MiraPluginInfo[] PluginsWithOptionsOrGameModes { get; private set; } = [];
|
||||||
|
|
||||||
internal Dictionary<MiraPluginInfo, List<Type>> QueuedRoleRegistrations { get; } = [];
|
internal Dictionary<MiraPluginInfo, List<Type>> QueuedRoleRegistrations { get; } = [];
|
||||||
|
|
||||||
internal static MiraPluginManager Instance { get; } = new();
|
internal static MiraPluginManager Instance { get; } = new();
|
||||||
internal static ConfigFile MiraApiConfig { get; private set; } = null!;
|
|
||||||
internal static MiraPluginInfo MiraApiPluginInfo { get; private set; } = null!;
|
|
||||||
|
|
||||||
private static readonly (string LogContext, TypeRegistrationHandler Handler)[] RegistrationHandlers =
|
private static readonly (string LogContext, TypeRegistrationHandler Handler)[] RegistrationHandlers =
|
||||||
[
|
[
|
||||||
@@ -94,27 +92,15 @@ public sealed class MiraPluginManager
|
|||||||
|
|
||||||
if (IL2CPPChainloader.Instance.Plugins.TryGetValue(MiraApiPlugin.Id, out var newPlugin))
|
if (IL2CPPChainloader.Instance.Plugins.TryGetValue(MiraApiPlugin.Id, out var newPlugin))
|
||||||
{
|
{
|
||||||
var registrationTimer = Stopwatch.StartNew();
|
RegisterPlugin(typeof(MiraPluginManager).Assembly, apiPlugin, newPlugin, miraApiPlugin);
|
||||||
var info = RegisterPlugin(typeof(MiraPluginManager).Assembly, apiPlugin, newPlugin, miraApiPlugin);
|
|
||||||
|
|
||||||
MiraApiConfig = info.PluginConfig;
|
|
||||||
MiraApiPluginInfo = info;
|
|
||||||
|
|
||||||
registrationTimer.Stop();
|
|
||||||
Info($"Registered Mira API as mod in {registrationTimer.ElapsedMilliseconds}ms.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IL2CPPChainloader.Instance.PluginLoad += (pluginInfo, assembly, plugin) =>
|
IL2CPPChainloader.Instance.PluginLoad += (pluginInfo, assembly, plugin) =>
|
||||||
{
|
{
|
||||||
if (plugin is not IMiraPlugin miraPlugin || pluginInfo.Metadata.GUID == MiraApiPlugin.Id)
|
if (plugin is IMiraPlugin miraPlugin && pluginInfo.Metadata.GUID != MiraApiPlugin.Id)
|
||||||
{
|
{
|
||||||
return;
|
RegisterPlugin(assembly, miraPlugin, pluginInfo, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
var registrationTimer = Stopwatch.StartNew();
|
|
||||||
RegisterPlugin(assembly, miraPlugin, pluginInfo, plugin);
|
|
||||||
registrationTimer.Stop();
|
|
||||||
Info($"Registered mod {pluginInfo.Metadata.Name} with Mira API in {registrationTimer.ElapsedMilliseconds}ms.");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
IL2CPPChainloader.Instance.Finished += () =>
|
IL2CPPChainloader.Instance.Finished += () =>
|
||||||
@@ -141,8 +127,9 @@ public sealed class MiraPluginManager
|
|||||||
PluginsWithOptionsOrGameModes = [.. RegisteredPlugins.Where(m => m.MiraPlugin.DisplayOnOptionsMenu || m.GameModes.Count > 0)];
|
PluginsWithOptionsOrGameModes = [.. RegisteredPlugins.Where(m => m.MiraPlugin.DisplayOnOptionsMenu || m.GameModes.Count > 0)];
|
||||||
}
|
}
|
||||||
|
|
||||||
private MiraPluginInfo RegisterPlugin(Assembly assembly, IMiraPlugin plugin, PluginInfo pluginInfo, BasePlugin basePlugin)
|
private void RegisterPlugin(Assembly assembly, IMiraPlugin plugin, PluginInfo pluginInfo, BasePlugin basePlugin)
|
||||||
{
|
{
|
||||||
|
var registrationTimer = Stopwatch.StartNew();
|
||||||
var info = new MiraPluginInfo(plugin, pluginInfo, assembly);
|
var info = new MiraPluginInfo(plugin, pluginInfo, assembly);
|
||||||
var roles = new List<Type>();
|
var roles = new List<Type>();
|
||||||
|
|
||||||
@@ -164,7 +151,9 @@ public sealed class MiraPluginManager
|
|||||||
PresetManager.CreateDefaultPreset(info);
|
PresetManager.CreateDefaultPreset(info);
|
||||||
PresetManager.LoadPresets(info);
|
PresetManager.LoadPresets(info);
|
||||||
|
|
||||||
return info;
|
registrationTimer.Stop();
|
||||||
|
|
||||||
|
Info($"Registered mod {pluginInfo.Metadata.Name} in {registrationTimer.ElapsedMilliseconds}ms.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ProcessAssemblyTypes(Assembly assembly, MiraPluginInfo info, BasePlugin basePlugin, IMiraPlugin plugin, List<Type> roles)
|
private static void ProcessAssemblyTypes(Assembly assembly, MiraPluginInfo info, BasePlugin basePlugin, IMiraPlugin plugin, List<Type> roles)
|
||||||
@@ -176,9 +165,9 @@ public sealed class MiraPluginManager
|
|||||||
|
|
||||||
var context = new RegistrationContext(info, plugin, basePlugin, roles);
|
var context = new RegistrationContext(info, plugin, basePlugin, roles);
|
||||||
|
|
||||||
foreach (var type in assembly.GetTypes())
|
foreach (var type in AccessTools.GetTypesFromAssembly(assembly))
|
||||||
{
|
{
|
||||||
if (type.IsDefined<MiraIgnoreAttribute>())
|
if (type.IsDefined<MiraIgnoreAttribute>() || type.IsDefined<HarmonyAttribute>())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (var (logContext, handler) in RegistrationHandlers)
|
foreach (var (logContext, handler) in RegistrationHandlers)
|
||||||
|
|||||||
@@ -26,11 +26,9 @@
|
|||||||
<string name="MiraApi.CustomOptionMenuDescription">Apply game settings for this mod!</string>
|
<string name="MiraApi.CustomOptionMenuDescription">Apply game settings for this mod!</string>
|
||||||
<string name="MiraApi.Gamemode">Gamemode</string>
|
<string name="MiraApi.Gamemode">Gamemode</string>
|
||||||
<string name="MiraApi.Gamemode.Classic">Classic</string>
|
<string name="MiraApi.Gamemode.Classic">Classic</string>
|
||||||
<string name="MiraApi.Gamemode.Classic.Description">The classic Among Us experience!
|
<string name="MiraApi.Gamemode.Classic.Description">The classic Among Us experience![nl]Find the Impostors or deceive the Crew.</string>
|
||||||
Find the Impostors or deceive the Crew.</string>
|
|
||||||
<string name="MiraApi.Gamemode.HideAndSeek">Hide n Seek</string>
|
<string name="MiraApi.Gamemode.HideAndSeek">Hide n Seek</string>
|
||||||
<string name="MiraApi.Gamemode.HideAndSeek.Description">You can run, but you can't hide!
|
<string name="MiraApi.Gamemode.HideAndSeek.Description">You can run, but you can't hide![nl]Outlive the timer or eliminate the crew.</string>
|
||||||
Outlive the timer or eliminate the crew.</string>
|
|
||||||
<string name="MiraApi.GameSetting.Global.ClickToClose">Click to close</string>
|
<string name="MiraApi.GameSetting.Global.ClickToClose">Click to close</string>
|
||||||
<string name="MiraApi.GameSetting.Global.ClickToOpen">Click to open</string>
|
<string name="MiraApi.GameSetting.Global.ClickToOpen">Click to open</string>
|
||||||
<string name="MiraApi.GameSetting.Preset.Hint">Select or create a options preset for this game</string>
|
<string name="MiraApi.GameSetting.Preset.Hint">Select or create a options preset for this game</string>
|
||||||
@@ -77,4 +75,32 @@ Outlive the timer or eliminate the crew.</string>
|
|||||||
<string name="Inactive">Inactive</string>
|
<string name="Inactive">Inactive</string>
|
||||||
<string name="Activated">Activated</string>
|
<string name="Activated">Activated</string>
|
||||||
<string name="Deactivated">Deactivated</string>
|
<string name="Deactivated">Deactivated</string>
|
||||||
|
<string name="MiraApi.AbbreviatedDistance">unit(s)</string>
|
||||||
|
|
||||||
|
<string name="MiraApi.Option.Group.HnsCrewmate">Crewmates</string>
|
||||||
|
<string name="MiraApi.HnsCrewmate.Option.PlayerSpeed">Player Speed</string>
|
||||||
|
<string name="MiraApi.HnsCrewmate.Option.HidingTime">Hiding Time</string>
|
||||||
|
<string name="MiraApi.HnsCrewmate.Option.CrewmateVision">Crewmate Vision</string>
|
||||||
|
<string name="MiraApi.HnsCrewmate.Option.FlashlightMode">Flashlight Mode</string>
|
||||||
|
<string name="MiraApi.HnsCrewmate.Option.CrewmateFlashlightSize">Crewmate Flashlight Size</string>
|
||||||
|
<string name="MiraApi.HnsCrewmate.Option.MaxVentUses">Max Vent Uses</string>
|
||||||
|
<string name="MiraApi.HnsCrewmate.Option.MaxTimeInVent">Max Time In Vent</string>
|
||||||
|
<string name="MiraApi.HnsCrewmate.Option.ShowNames">Show Names</string>
|
||||||
|
|
||||||
|
<string name="MiraApi.Option.Group.HnsFinalHide">Final Hide</string>
|
||||||
|
<string name="MiraApi.HnsFinalHide.Option.FinalHideTime">Hiding Time</string>
|
||||||
|
<string name="MiraApi.HnsFinalHide.Option.FinalHideImpostorSpeed">Final Hide Impostor Speed</string>
|
||||||
|
<string name="MiraApi.HnsFinalHide.Option.FinalHidePings">Final Hide Pings</string>
|
||||||
|
<string name="MiraApi.HnsFinalHide.Option.PingInterval">Ping Interval</string>
|
||||||
|
<string name="MiraApi.HnsFinalHide.Option.FinalHideSeekMap">Final Hide Seek Map</string>
|
||||||
|
|
||||||
|
<string name="MiraApi.Option.Group.HnsImpostor">Impostors</string>
|
||||||
|
<string name="MiraApi.HnsImpostor.Option.SelectedSeeker">Forced Impostor</string>
|
||||||
|
<string name="MiraApi.HnsImpostor.Option.ImpostorVision">Impostor Vision</string>
|
||||||
|
<string name="MiraApi.HnsImpostor.Option.ImpostorFlashlightSize">Impostor Flashlight Size</string>
|
||||||
|
|
||||||
|
<string name="MiraApi.Option.Group.HnsTask">Tasks</string>
|
||||||
|
<string name="MiraApi.HnsTask.Option.CommonTasks"># Common Tasks</string>
|
||||||
|
<string name="MiraApi.HnsTask.Option.LongTasks"># Long Tasks</string>
|
||||||
|
<string name="MiraApi.HnsTask.Option.ShortTasks"># Short Tasks</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using AmongUs.GameOptions;
|
using AmongUs.GameOptions;
|
||||||
using Il2CppInterop.Runtime.Attributes;
|
|
||||||
using MiraAPI.GameModes;
|
using MiraAPI.GameModes;
|
||||||
using MiraAPI.Patches.Freeplay;
|
using MiraAPI.Patches.Freeplay;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
@@ -81,25 +80,21 @@ public record struct CustomRoleConfiguration
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="Sprite"/> used for the Role Options menu screenshot.
|
/// Gets or sets the <see cref="Sprite"/> used for the Role Options menu screenshot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HideFromIl2Cpp]
|
|
||||||
public LoadableAsset<Sprite>? OptionsScreenshot { get; set; } = null;
|
public LoadableAsset<Sprite>? OptionsScreenshot { get; set; } = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="Sprite"/> used for the Role Icon.
|
/// Gets or sets the <see cref="Sprite"/> used for the Role Icon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HideFromIl2Cpp]
|
|
||||||
public LoadableAsset<Sprite>? Icon { get; set; } = null;
|
public LoadableAsset<Sprite>? Icon { get; set; } = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="TMP_SpriteAsset"/> for the Role Icon.
|
/// Gets or sets the <see cref="TMP_SpriteAsset"/> for the Role Icon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HideFromIl2Cpp]
|
|
||||||
public TMP_SpriteAsset IconTmp { get; set; }
|
public TMP_SpriteAsset IconTmp { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Intro sound for the Role.
|
/// Gets or sets the Intro sound for the Role.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HideFromIl2Cpp]
|
|
||||||
public LoadableAsset<AudioClip>? IntroSound { get; set; } = null;
|
public LoadableAsset<AudioClip>? IntroSound { get; set; } = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public static class CustomRoleManager
|
|||||||
|
|
||||||
internal static bool RegisterRole(Type type, in MiraPluginManager.RegistrationContext context)
|
internal static bool RegisterRole(Type type, in MiraPluginManager.RegistrationContext context)
|
||||||
{
|
{
|
||||||
if (!(typeof(RoleBehaviour).IsAssignableFrom(type) && typeof(ICustomRole).IsAssignableFrom(type)))
|
if (type.IsAbstract || !(typeof(RoleBehaviour).IsAssignableFrom(type) && typeof(ICustomRole).IsAssignableFrom(type)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ public static class CustomRoleManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
var useTaskHint = customRole.Configuration.RoleHintType is RoleHintType.TaskHint;
|
var useTaskHint = customRole.Configuration.RoleHintType is RoleHintType.TaskHint;
|
||||||
var overridesTaskText = customRole.GetType().GetMethod("SpawnTaskHeader")?.DeclaringType == customRole.GetType();
|
var overridesTaskText = roleType.GetMethod("SpawnTaskHeader")?.DeclaringType == roleType;
|
||||||
|
|
||||||
if (useTaskHint && !overridesTaskText)
|
if (useTaskHint && !overridesTaskText)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -186,11 +186,11 @@ public interface ICustomRole : IOptionable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Binds the configuration options for this role to the provided ConfigFile.
|
/// Binds the configuration options for this role to the provided ConfigFile.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="config">The ConfigFile to bind the options to.</param>
|
/// <param name="config">The <see cref="ConfigFile"/> to bind the options to.</param>
|
||||||
void BindConfig(ConfigFile config)
|
void BindConfig(ConfigFile config)
|
||||||
{
|
{
|
||||||
config.Bind(NumConfigDefinition, Configuration.DefaultRoleCount, new ConfigDescription(string.Empty, new AcceptableValueRange<int>(0, Configuration.MaxRoleCount)));
|
config.Bind(NumConfigDefinition, Configuration.DefaultRoleCount, new ConfigDescription(string.Empty, new SafeAcceptableValueRange<int>(0, Configuration.MaxRoleCount)));
|
||||||
config.Bind(ChanceConfigDefinition, Configuration.DefaultChance, new ConfigDescription(string.Empty, new AcceptableValueRange<int>(0, 100)));
|
config.Bind(ChanceConfigDefinition, Configuration.DefaultChance, new ConfigDescription(string.Empty, new SafeAcceptableValueRange<int>(0, 100)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -231,7 +231,7 @@ public interface ICustomRole : IOptionable
|
|||||||
return !Configuration.CanModifyChance
|
return !Configuration.CanModifyChance
|
||||||
? Configuration.DefaultChance
|
? Configuration.DefaultChance
|
||||||
: ParentMod.PluginConfig.TryGetEntry(ChanceConfigDefinition, out ConfigEntry<int> entry)
|
: ParentMod.PluginConfig.TryGetEntry(ChanceConfigDefinition, out ConfigEntry<int> entry)
|
||||||
? Mathf.Clamp(entry.Value, 0, 100)
|
? Math.Clamp(entry.Value, 0, 100)
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ public interface ICustomRole : IOptionable
|
|||||||
int? GetCount()
|
int? GetCount()
|
||||||
{
|
{
|
||||||
return ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out ConfigEntry<int> entry)
|
return ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out ConfigEntry<int> entry)
|
||||||
? Mathf.Clamp(entry.Value, 0, Configuration.MaxRoleCount)
|
? Math.Clamp(entry.Value, 0, Configuration.MaxRoleCount)
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,7 +260,7 @@ public interface ICustomRole : IOptionable
|
|||||||
|
|
||||||
if (ParentMod.PluginConfig.TryGetEntry(ChanceConfigDefinition, out ConfigEntry<int> entry))
|
if (ParentMod.PluginConfig.TryGetEntry(ChanceConfigDefinition, out ConfigEntry<int> entry))
|
||||||
{
|
{
|
||||||
entry.Value = Mathf.Clamp(chance, 0, 100);
|
entry.Value = Math.Clamp(chance, 0, 100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ public interface ICustomRole : IOptionable
|
|||||||
{
|
{
|
||||||
if (ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out ConfigEntry<int> entry))
|
if (ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out ConfigEntry<int> entry))
|
||||||
{
|
{
|
||||||
entry.Value = Mathf.Clamp(count, 0, Configuration.MaxRoleCount);
|
entry.Value = Math.Clamp(count, 0, Configuration.MaxRoleCount);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using AmongUs.Data;
|
using AmongUs.Data;
|
||||||
|
using BepInEx;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using Reactor.Localization.Utilities;
|
using Reactor.Localization.Utilities;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -16,7 +18,9 @@ namespace MiraAPI.Translation;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class MiraLocaleManager
|
public static class MiraLocaleManager
|
||||||
{
|
{
|
||||||
|
private const string StringNamesPrefix = "StringNames";
|
||||||
private const string LangDirectory = "mira_languages";
|
private const string LangDirectory = "mira_languages";
|
||||||
|
private const string VanillaPrefix = "@vanilla:";
|
||||||
private const string RefPrefix = "@ref:";
|
private const string RefPrefix = "@ref:";
|
||||||
private const int MaxDepth = 10;
|
private const int MaxDepth = 10;
|
||||||
|
|
||||||
@@ -35,9 +39,11 @@ public static class MiraLocaleManager
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a dictionary mapping registered string keys to their corresponding <see cref="StringNames"/> enum values.
|
/// Gets a dictionary mapping registered string keys to their corresponding <see cref="StringNames"/> enum values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly Dictionary<string, StringNames> RegisteredStringNames = [];
|
public static readonly Dictionary<string, StringNames> RegisteredStringNames = new(StringComparer.Ordinal);
|
||||||
internal static readonly Dictionary<StringNames, string> StringNamesLookup = [];
|
internal static readonly Dictionary<StringNames, string> StringNamesLookup = [];
|
||||||
|
|
||||||
|
private static readonly Dictionary<string, StringNames> VanillaKeyMap = new(StringComparer.Ordinal);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a dictionary mapping <see cref="MiraLanguage"/> values to their standard language codes.
|
/// Gets a dictionary mapping <see cref="MiraLanguage"/> values to their standard language codes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -73,7 +79,7 @@ public static class MiraLocaleManager
|
|||||||
{ MiraLanguage.Hebrew, "heb" },
|
{ MiraLanguage.Hebrew, "heb" },
|
||||||
};
|
};
|
||||||
private static readonly Dictionary<string, MiraLanguage> ReverseLangLookup =
|
private static readonly Dictionary<string, MiraLanguage> ReverseLangLookup =
|
||||||
LangList.ToDictionary(x => x.Value, x => x.Key);
|
LangList.ToDictionary(x => x.Value, x => x.Key, StringComparer.Ordinal);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a dictionary mapping <see cref="MiraLanguage"/> values to their standard language codes.
|
/// Gets a dictionary mapping <see cref="MiraLanguage"/> values to their standard language codes.
|
||||||
@@ -147,6 +153,9 @@ public static class MiraLocaleManager
|
|||||||
/// <returns>A <see cref="string"/> based on the key provided.</returns>
|
/// <returns>A <see cref="string"/> based on the key provided.</returns>
|
||||||
public static string Get(MiraLanguage language, string key, string fallback = "")
|
public static string Get(MiraLanguage language, string key, string fallback = "")
|
||||||
{
|
{
|
||||||
|
if (VanillaKeyMap.TryGetValue(key, out var stringName) && TranslationController.InstanceExists)
|
||||||
|
return TranslationController.Instance.GetString(stringName);
|
||||||
|
|
||||||
var text = Locale.GetValueOrDefault(language)?.GetValueOrDefault(key);
|
var text = Locale.GetValueOrDefault(language)?.GetValueOrDefault(key);
|
||||||
|
|
||||||
if (language != MiraLanguage.English)
|
if (language != MiraLanguage.English)
|
||||||
@@ -173,14 +182,7 @@ public static class MiraLocaleManager
|
|||||||
return GetParsed(CurrentLanguage, key, parseList, string.IsNullOrEmpty(fallback) ? key : fallback);
|
return GetParsed(CurrentLanguage, key, parseList, string.IsNullOrEmpty(fallback) ? key : fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="GetParsed(MiraLanguage, string, ValueTuple{string, string}[], string)"/>
|
||||||
/// Translates a key into the current language.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="language">The specific language to prioritize.</param>
|
|
||||||
/// <param name="key">The string id to find.</param>
|
|
||||||
/// <param name="parseList">List of keys to change into other text.</param>
|
|
||||||
/// <param name="fallback">Fallback string to use if no translation is found.</param>
|
|
||||||
/// <returns>A <see cref="string"/> based on the key provided.</returns>
|
|
||||||
public static string GetParsed(
|
public static string GetParsed(
|
||||||
MiraLanguage language,
|
MiraLanguage language,
|
||||||
string key,
|
string key,
|
||||||
@@ -221,6 +223,32 @@ public static class MiraLocaleManager
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="GetParsed(MiraLanguage, string, ValueTuple{string, string}[], string)"/>
|
||||||
|
public static string GetParsed(
|
||||||
|
MiraLanguage language,
|
||||||
|
string key,
|
||||||
|
string fallback,
|
||||||
|
params object[] parseList)
|
||||||
|
{
|
||||||
|
var text = Get(language, key, fallback);
|
||||||
|
|
||||||
|
if (parseList == null || parseList.Length == 0)
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(CultureInfo.InvariantCulture, text, parseList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="GetParsed(MiraLanguage, string, ValueTuple{string, string}[], string)"/>
|
||||||
|
public static string GetParsed(
|
||||||
|
MiraLanguage language,
|
||||||
|
string key,
|
||||||
|
params object[] parseList)
|
||||||
|
{
|
||||||
|
return GetParsed(language, key, string.Empty, parseList);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Builds a formatted translation ID string using a mod ID, a specific ID part, and a suffix.
|
/// Builds a formatted translation ID string using a mod ID, a specific ID part, and a suffix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -256,6 +284,11 @@ public static class MiraLocaleManager
|
|||||||
return stringName;
|
return stringName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (VanillaKeyMap.TryGetValue(name, out stringName))
|
||||||
|
{
|
||||||
|
return stringName;
|
||||||
|
}
|
||||||
|
|
||||||
var newString = CustomStringName.CreateAndRegister(name);
|
var newString = CustomStringName.CreateAndRegister(name);
|
||||||
RegisteredStringNames.Add(name, newString);
|
RegisteredStringNames.Add(name, newString);
|
||||||
StringNamesLookup.Add(newString, name);
|
StringNamesLookup.Add(newString, name);
|
||||||
@@ -267,9 +300,9 @@ public static class MiraLocaleManager
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void LoadExternalLocale()
|
public static void LoadExternalLocale()
|
||||||
{
|
{
|
||||||
CheckExternalDirectory("mira.api", BepInEx.Paths.PluginPath);
|
CheckExternalDirectory("mira.api", Paths.PluginPath);
|
||||||
CheckExternalDirectory("mira.api", BepInEx.Paths.BepInExRootPath);
|
CheckExternalDirectory("mira.api", Paths.BepInExRootPath);
|
||||||
CheckExternalDirectory("mira.api", BepInEx.Paths.GameRootPath);
|
CheckExternalDirectory("mira.api", Paths.GameRootPath);
|
||||||
foreach (var mod in RegisteredModIds)
|
foreach (var mod in RegisteredModIds)
|
||||||
{
|
{
|
||||||
CheckExternalDirectory(mod, GetModLangDir(mod));
|
CheckExternalDirectory(mod, GetModLangDir(mod));
|
||||||
@@ -296,7 +329,7 @@ public static class MiraLocaleManager
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Locale.TryAdd(lang, []);
|
Locale.TryAdd(lang, new(StringComparer.Ordinal));
|
||||||
using var fileStream = File.OpenRead(filePath);
|
using var fileStream = File.OpenRead(filePath);
|
||||||
ParseXmlFile(fileStream, lang, false);
|
ParseXmlFile(fileStream, lang, false);
|
||||||
}
|
}
|
||||||
@@ -332,7 +365,7 @@ public static class MiraLocaleManager
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Locale.TryAdd(lang, []);
|
Locale.TryAdd(lang, new(StringComparer.Ordinal));
|
||||||
ParseXmlFile(resourceStream, lang, true);
|
ParseXmlFile(resourceStream, lang, true);
|
||||||
atLeastOneLoaded = true;
|
atLeastOneLoaded = true;
|
||||||
}
|
}
|
||||||
@@ -378,7 +411,7 @@ public static class MiraLocaleManager
|
|||||||
var dict = Locale[language];
|
var dict = Locale[language];
|
||||||
var total = 0;
|
var total = 0;
|
||||||
|
|
||||||
var pendingRefs = new Dictionary<string, string>();
|
var pendingRefs = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -400,6 +433,23 @@ public static class MiraLocaleManager
|
|||||||
{
|
{
|
||||||
pendingRefs[name] = value[RefPrefix.Length..];
|
pendingRefs[name] = value[RefPrefix.Length..];
|
||||||
}
|
}
|
||||||
|
else if (value.StartsWith(VanillaPrefix, StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
var enumString = value[VanillaPrefix.Length..];
|
||||||
|
|
||||||
|
if (enumString.StartsWith(StringNamesPrefix, StringComparison.Ordinal))
|
||||||
|
enumString = enumString[StringNamesPrefix.Length..];
|
||||||
|
|
||||||
|
if (Enum.TryParse<StringNames>(enumString, true, out var stringName))
|
||||||
|
{
|
||||||
|
VanillaKeyMap[name] = stringName;
|
||||||
|
total++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Error($"Failed to parse vanilla StringNames enum: {enumString}");
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
value = value.Replace('[', '<')
|
value = value.Replace('[', '<')
|
||||||
|
|||||||
@@ -69,9 +69,9 @@ public class MiraLocalizationProvider : LocalizationProvider
|
|||||||
Warning($"<resources>");
|
Warning($"<resources>");
|
||||||
foreach (var stringName in TranslationController.Instance.currentLanguage.AllStrings)
|
foreach (var stringName in TranslationController.Instance.currentLanguage.AllStrings)
|
||||||
{
|
{
|
||||||
var value = stringName.Value.Replace("\n", "\\%nl\\%");
|
var value = stringName.Value.Replace("\n", "[nl]");
|
||||||
value = value.Replace("{", "[");
|
value = value.Replace("<", "[");
|
||||||
value = value.Replace("}", "]");
|
value = value.Replace(">", "]");
|
||||||
Warning($"<string name=\"{stringName.Key}\">{value}</string>");
|
Warning($"<string name=\"{stringName.Key}\">{value}</string>");
|
||||||
}
|
}
|
||||||
Warning($"</resources>");*/
|
Warning($"</resources>");*/
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Reactor.Utilities.Extensions;
|
using Reactor.Utilities.Extensions;
|
||||||
@@ -11,7 +12,7 @@ namespace MiraAPI.Utilities.Assets;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class TmpSpriteUtils
|
public static class TmpSpriteUtils
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<string, TMP_SpriteAsset> LoadedSprites = [];
|
private static readonly Dictionary<string, TMP_SpriteAsset> LoadedSprites = new(StringComparer.Ordinal);
|
||||||
private static Shader _spriteShader;
|
private static Shader _spriteShader;
|
||||||
|
|
||||||
[SuppressMessage("Critical Code Smell", "S2223:Non-constant static fields should not be visible", Justification = "Internal behaviour that does not need property-level validation.")]
|
[SuppressMessage("Critical Code Smell", "S2223:Non-constant static fields should not be visible", Justification = "Internal behaviour that does not need property-level validation.")]
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class CenteredGridArrange(IntPtr iPtr) : MonoBehaviour(iPtr)
|
|||||||
{
|
{
|
||||||
var row = index / MaxColumns;
|
var row = index / MaxColumns;
|
||||||
var rowStartIndex = row * MaxColumns;
|
var rowStartIndex = row * MaxColumns;
|
||||||
var itemsInRow = Mathf.Min(MaxColumns, cells.Count - rowStartIndex);
|
var itemsInRow = Math.Min(MaxColumns, cells.Count - rowStartIndex);
|
||||||
var col = index - rowStartIndex;
|
var col = index - rowStartIndex;
|
||||||
|
|
||||||
var rowWidth = (itemsInRow - 1) * CellSize.x;
|
var rowWidth = (itemsInRow - 1) * CellSize.x;
|
||||||
|
|||||||
@@ -72,10 +72,10 @@ public class LoadingRing(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
|||||||
{
|
{
|
||||||
var dx = x + 0.5f - (size / 2f);
|
var dx = x + 0.5f - (size / 2f);
|
||||||
var dy = y + 0.5f - (size / 2f);
|
var dy = y + 0.5f - (size / 2f);
|
||||||
var radius = Mathf.Sqrt((dx * dx) + (dy * dy));
|
var radius = MathF.Sqrt((dx * dx) + (dy * dy));
|
||||||
var ring = Mathf.Clamp01(radius - innerRadius) * Mathf.Clamp01(outerRadius - radius);
|
var ring = MathUtilities.Clamp01(radius - innerRadius) * MathUtilities.Clamp01(outerRadius - radius);
|
||||||
var angle = (Mathf.Atan2(dy, dx) + Mathf.PI) / (2f * Mathf.PI);
|
var angle = (MathF.Atan2(dy, dx) + MathF.PI) / (2f * MathF.PI);
|
||||||
pixels[(y * size) + x] = new Color(1f, 1f, 1f, ring * Mathf.Lerp(1f, 0.1f, angle));
|
pixels[(y * size) + x] = new Color(1f, 1f, 1f, ring * MathUtilities.Lerp(1f, 0.1f, angle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public static class Extensions
|
|||||||
/// <param name="format">The format string to use for the timer text.</param>
|
/// <param name="format">The format string to use for the timer text.</param>
|
||||||
public static void SetCooldownFormat(this ActionButton? button, float timer, float maxTimer, string format = "0")
|
public static void SetCooldownFormat(this ActionButton? button, float timer, float maxTimer, string format = "0")
|
||||||
{
|
{
|
||||||
var num = Mathf.Clamp(timer / maxTimer, 0f, 1f);
|
var num = Math.Clamp(timer / maxTimer, 0f, 1f);
|
||||||
button!.isCoolingDown = num > 0f;
|
button!.isCoolingDown = num > 0f;
|
||||||
button.SetCooldownFill(num);
|
button.SetCooldownFill(num);
|
||||||
if (button.isCoolingDown)
|
if (button.isCoolingDown)
|
||||||
@@ -111,7 +111,7 @@ public static class Extensions
|
|||||||
/// <param name="format">The format string to use for the timer text.</param>
|
/// <param name="format">The format string to use for the timer text.</param>
|
||||||
public static void SetFillUpFormat(this ActionButton button, float timer, float maxTimer, string format = "0")
|
public static void SetFillUpFormat(this ActionButton button, float timer, float maxTimer, string format = "0")
|
||||||
{
|
{
|
||||||
var num = Mathf.Clamp(timer / maxTimer, 0f, 1f);
|
var num = Math.Clamp(timer / maxTimer, 0f, 1f);
|
||||||
button.isCoolingDown = num > 0f;
|
button.isCoolingDown = num > 0f;
|
||||||
if (button.isCoolingDown && timer < 3f)
|
if (button.isCoolingDown && timer < 3f)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ internal static class GuideOptionPages
|
|||||||
item.Group.MatchInfoGuidePageOrder,
|
item.Group.MatchInfoGuidePageOrder,
|
||||||
GetMenuOrder(item.Group.ParentMenu),
|
GetMenuOrder(item.Group.ParentMenu),
|
||||||
item.Group.GroupPriority,
|
item.Group.GroupPriority,
|
||||||
Mathf.Clamp(item.Group.MatchInfoGuidePageColumns, 1, 6),
|
Math.Clamp(item.Group.MatchInfoGuidePageColumns, 1, 6),
|
||||||
item.ModAbbreviation,
|
item.ModAbbreviation,
|
||||||
modSearchTerms,
|
modSearchTerms,
|
||||||
entries);
|
entries);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public static class Helpers
|
|||||||
"Major Code Smell",
|
"Major Code Smell",
|
||||||
"S3011:Reflection should not be used to increase accessibility of classes, methods, or fields",
|
"S3011:Reflection should not be used to increase accessibility of classes, methods, or fields",
|
||||||
Justification = "Dynamic singleton initialization requires reflection to bypass the private field access modifier because the type is only known at runtime.")]
|
Justification = "Dynamic singleton initialization requires reflection to bypass the private field access modifier because the type is only known at runtime.")]
|
||||||
private const BindingFlags StaticInstanceFlags = BindingFlags.Static | BindingFlags.NonPublic;
|
private const BindingFlags StaticInstanceFlags = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
|
||||||
|
|
||||||
internal const float MatchInfoGuideBaseScale = 1.3f;
|
internal const float MatchInfoGuideBaseScale = 1.3f;
|
||||||
private static NumberOption? _advancedSettingsRowPrefab;
|
private static NumberOption? _advancedSettingsRowPrefab;
|
||||||
@@ -284,7 +284,7 @@ public static class Helpers
|
|||||||
where T : MonoBehaviour
|
where T : MonoBehaviour
|
||||||
{
|
{
|
||||||
T? closest = null;
|
T? closest = null;
|
||||||
var closestDistanceSqr = Mathf.Infinity;
|
var closestDistanceSqr = float.PositiveInfinity;
|
||||||
|
|
||||||
foreach (var obj in objectList)
|
foreach (var obj in objectList)
|
||||||
{
|
{
|
||||||
@@ -574,11 +574,10 @@ public static class Helpers
|
|||||||
{
|
{
|
||||||
return suffix switch
|
return suffix switch
|
||||||
{
|
{
|
||||||
MiraNumberSuffixes.None => string.Empty,
|
|
||||||
MiraNumberSuffixes.Multiplier => "x",
|
|
||||||
MiraNumberSuffixes.Seconds => "s",
|
|
||||||
MiraNumberSuffixes.Percent => "%",
|
MiraNumberSuffixes.Percent => "%",
|
||||||
MiraNumberSuffixes.Distance => MiraApiPlugin.DistanceSuffix.Value,
|
MiraNumberSuffixes.Multiplier => "x",
|
||||||
|
MiraNumberSuffixes.Distance => MiraLocaleManager.Get("MiraApi.AbbreviatedDistance"),
|
||||||
|
MiraNumberSuffixes.Seconds => TranslationController.Instance.GetString(StringNames.AbbreviatedSecond, string.Empty),
|
||||||
_ => string.Empty,
|
_ => string.Empty,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -614,14 +613,7 @@ public static class Helpers
|
|||||||
public static string FormatValue(float value, MiraNumberSuffixes suffix = MiraNumberSuffixes.None, string formatString = "0.0")
|
public static string FormatValue(float value, MiraNumberSuffixes suffix = MiraNumberSuffixes.None, string formatString = "0.0")
|
||||||
{
|
{
|
||||||
var part = value.ToString(formatString, NumberFormatInfo.InvariantInfo);
|
var part = value.ToString(formatString, NumberFormatInfo.InvariantInfo);
|
||||||
return suffix switch
|
return part + GetSuffix(suffix);
|
||||||
{
|
|
||||||
MiraNumberSuffixes.None => part,
|
|
||||||
MiraNumberSuffixes.Percent => part + "%",
|
|
||||||
MiraNumberSuffixes.Multiplier => part + "x",
|
|
||||||
MiraNumberSuffixes.Distance => part + MiraApiPlugin.DistanceSuffix.Value,
|
|
||||||
_ => TranslationController.Instance.GetString(StringNames.GameSecondsAbbrev, part),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -813,8 +805,8 @@ public static class Helpers
|
|||||||
obj.transform.localPosition = new Vector3(0f, 0.5f, 0f);
|
obj.transform.localPosition = new Vector3(0f, 0.5f, 0f);
|
||||||
var scrollHeight = variableTextSizing
|
var scrollHeight = variableTextSizing
|
||||||
? desc.textBounds.size.y - 2.5f + maxTextSize + 0.475f
|
? desc.textBounds.size.y - 2.5f + maxTextSize + 0.475f
|
||||||
: desc.textBounds.size.y - 2.5f + Mathf.Ceil(num / 2f) * 1.45f;
|
: desc.textBounds.size.y - 2.5f + MathF.Ceiling(num / 2f) * 1.45f;
|
||||||
parent.SetYBoundsMax(Mathf.Clamp(scrollHeight, 0f, 999f));
|
parent.SetYBoundsMax(Math.Clamp(scrollHeight, 0f, 999f));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -896,7 +888,7 @@ public static class Helpers
|
|||||||
const float groupHeaderContentGap = 0.05f;
|
const float groupHeaderContentGap = 0.05f;
|
||||||
const int contentSortingOrder = 151;
|
const int contentSortingOrder = 151;
|
||||||
|
|
||||||
columns = Mathf.Clamp(columns, 1, 6);
|
columns = Math.Clamp(columns, 1, 6);
|
||||||
var inner = parent.Inner;
|
var inner = parent.Inner;
|
||||||
var layout = inner.GetComponent<GridLayoutGroup>();
|
var layout = inner.GetComponent<GridLayoutGroup>();
|
||||||
if (layout)
|
if (layout)
|
||||||
@@ -904,11 +896,11 @@ public static class Helpers
|
|||||||
layout.enabled = false;
|
layout.enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var columnGap = layout ? Mathf.Clamp(layout.spacing.x, 0.1f, 0.6f) : 0.3f;
|
var columnGap = layout ? Math.Clamp(layout.spacing.x, 0.1f, 0.6f) : 0.3f;
|
||||||
const int baseColumnCount = 2;
|
const int baseColumnCount = 2;
|
||||||
var baseColumnWidth = layout ? Mathf.Clamp(layout.cellSize.x, 2f, 3.2f) : 2.7f;
|
var baseColumnWidth = layout ? Math.Clamp(layout.cellSize.x, 2f, 3.2f) : 2.7f;
|
||||||
var availableWidth = baseColumnWidth * baseColumnCount + columnGap * (baseColumnCount - 1);
|
var availableWidth = baseColumnWidth * baseColumnCount + columnGap * (baseColumnCount - 1);
|
||||||
var columnWidth = Mathf.Clamp(
|
var columnWidth = Math.Clamp(
|
||||||
(availableWidth - (columns - 1) * columnGap) / columns,
|
(availableWidth - (columns - 1) * columnGap) / columns,
|
||||||
1f,
|
1f,
|
||||||
3.2f);
|
3.2f);
|
||||||
@@ -979,7 +971,7 @@ public static class Helpers
|
|||||||
var group = groupedSettings[i].Key;
|
var group = groupedSettings[i].Key;
|
||||||
var band = i / columns;
|
var band = i / columns;
|
||||||
groupColumns[group] = i % columns;
|
groupColumns[group] = i % columns;
|
||||||
bandHeights[band] = Mathf.Max(
|
bandHeights[band] = Math.Max(
|
||||||
bandHeights[band],
|
bandHeights[band],
|
||||||
rowPitch * (groupedSettings[i].Count() + 1) + groupHeaderContentGap + 0.25f);
|
rowPitch * (groupedSettings[i].Count() + 1) + groupHeaderContentGap + 0.25f);
|
||||||
}
|
}
|
||||||
@@ -987,7 +979,7 @@ public static class Helpers
|
|||||||
var bandOffset = 0f;
|
var bandOffset = 0f;
|
||||||
for (var band = 0; band < bandCount; band++)
|
for (var band = 0; band < bandCount; band++)
|
||||||
{
|
{
|
||||||
for (var i = band * columns; i < Mathf.Min((band + 1) * columns, groupedSettings.Count); i++)
|
for (var i = band * columns; i < Math.Min((band + 1) * columns, groupedSettings.Count); i++)
|
||||||
{
|
{
|
||||||
groupTopOffsets[groupedSettings[i].Key] = bandOffset;
|
groupTopOffsets[groupedSettings[i].Key] = bandOffset;
|
||||||
groupRows[groupedSettings[i].Key] = 0;
|
groupRows[groupedSettings[i].Key] = 0;
|
||||||
@@ -1217,7 +1209,7 @@ public static class Helpers
|
|||||||
{
|
{
|
||||||
if (renderer.enabled && renderer.gameObject.activeInHierarchy)
|
if (renderer.enabled && renderer.gameObject.activeInHierarchy)
|
||||||
{
|
{
|
||||||
contentBottom = Mathf.Min(
|
contentBottom = Math.Min(
|
||||||
contentBottom,
|
contentBottom,
|
||||||
inner.InverseTransformPoint(renderer.bounds.min).y);
|
inner.InverseTransformPoint(renderer.bounds.min).y);
|
||||||
}
|
}
|
||||||
@@ -1233,7 +1225,7 @@ public static class Helpers
|
|||||||
var scrollRange = contentOverflow > 0.05f
|
var scrollRange = contentOverflow > 0.05f
|
||||||
? contentOverflow + 0.05f
|
? contentOverflow + 0.05f
|
||||||
: 0f;
|
: 0f;
|
||||||
parent.SetYBoundsMax(Mathf.Clamp(scrollRange, 0f, 999f));
|
parent.SetYBoundsMax(Math.Clamp(scrollRange, 0f, 999f));
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
|
||||||
|
namespace MiraAPI.Utilities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specify the range of acceptable values for a setting.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the value.</typeparam>
|
||||||
|
public sealed class SafeAcceptableValueRange<T> : AcceptableValueBase
|
||||||
|
where T : IComparable<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the lowest acceptable value.
|
||||||
|
/// </summary>
|
||||||
|
public T Min { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the highest acceptable value.
|
||||||
|
/// </summary>
|
||||||
|
public T Max { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SafeAcceptableValueRange{T}"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="min">Lowest acceptable value.</param>
|
||||||
|
/// <param name="max">Highest acceptable value.</param>
|
||||||
|
public SafeAcceptableValueRange(T min, T max)
|
||||||
|
: base(typeof(T))
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(min);
|
||||||
|
ArgumentNullException.ThrowIfNull(max);
|
||||||
|
|
||||||
|
if (min.CompareTo(max) > 0)
|
||||||
|
{
|
||||||
|
Min = max;
|
||||||
|
Max = min;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Min = min;
|
||||||
|
Max = max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override object Clamp(object value)
|
||||||
|
{
|
||||||
|
if (value is not T val)
|
||||||
|
return Min;
|
||||||
|
|
||||||
|
if (val.CompareTo(Min) <= 0)
|
||||||
|
return Min;
|
||||||
|
|
||||||
|
if (val.CompareTo(Max) > 0)
|
||||||
|
return Max;
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool IsValid(object value)
|
||||||
|
{
|
||||||
|
if (value is not T val)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return val.CompareTo(Min) >= 0 && val.CompareTo(Max) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override string ToDescriptionString()
|
||||||
|
{
|
||||||
|
return $"# Acceptable value range: From {Min} to {Max}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Utilities;
|
namespace MiraAPI.Utilities;
|
||||||
@@ -8,7 +9,7 @@ namespace MiraAPI.Utilities;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ShaderID
|
public static class ShaderID
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<string, int> Cache = [];
|
private static readonly Dictionary<string, int> Cache = new(StringComparer.Ordinal);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the cached shader property ID for the specified name. If it is not cached, it registers and caches the ID before returning it.
|
/// Retrieves the cached shader property ID for the specified name. If it is not cached, it registers and caches the ID before returning it.
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class StateMachineWrapper<T>
|
|||||||
throw new MissingMemberException($"Could not find required properties in type '{_type}'.");
|
throw new MissingMemberException($"Could not find required properties in type '{_type}'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
_propertyCache = [];
|
_propertyCache = new(StringComparer.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in new issue
Block a user