mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
some oversights fixed + remove redundant code
This commit is contained in:
11 files changed
+194
-297
No files matched your search
@@ -172,6 +172,6 @@ public class ModdedNumberOptionAttribute(
|
||||
/// <inheritdoc />
|
||||
int ITypedOption<int>.GetValueUnboxed()
|
||||
{
|
||||
return (int)Math.Round(GetValueUnboxed());
|
||||
return (int)MathF.Round(GetValueUnboxed());
|
||||
}
|
||||
}
|
||||
@@ -174,6 +174,6 @@ public class ModdedNumberOptionListAttribute(
|
||||
/// <inheritdoc />
|
||||
int ITypedOptionList<int>.GetValueUnboxed(int idx)
|
||||
{
|
||||
return (int)Math.Round(GetValueUnboxed(idx));
|
||||
return (int)MathF.Round(GetValueUnboxed(idx));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Component added onto options generated via MiraAPI. This allows developers to hook patches onto options in general, without using a list.
|
||||
/// </summary>
|
||||
/// <param name="cppPtr">The pointer to the C++ object.</param>
|
||||
[RegisterInIl2Cpp]
|
||||
public class MiraPlayerOptionComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ModdedPlayerOption"/> associated with the object.
|
||||
/// </summary>
|
||||
[HideFromIl2Cpp]
|
||||
public ModdedPlayerOption PlayerOption { get; set; }
|
||||
}
|
||||
@@ -8,7 +8,6 @@ using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities;
|
||||
@@ -41,7 +40,6 @@ public static class ModdedOptionsManager
|
||||
private static readonly Type OptionType = typeof(IModdedOption);
|
||||
private static readonly Type OptionListType = typeof(IModdedOptionList);
|
||||
|
||||
internal static readonly Dictionary<OptionBehaviour, ModdedPlayerOption> CreatedPlayerOptions = [];
|
||||
internal static readonly Dictionary<Type, List<AbstractOptionGroup>> GameModeOptionGroups = [];
|
||||
internal static readonly Dictionary<uint, IModdedOption> ModdedOptions = [];
|
||||
internal static readonly List<AbstractOptionGroup> Groups = [];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using AmongUs.GameOptions;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -72,17 +73,18 @@ public abstract class ModdedBaseStringOption<T>(string groupPrefix, string title
|
||||
stringOption.name = $"{ParentMod!.OptionsTitleText}.{OptionTypeName}.{Title}";
|
||||
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
|
||||
// SetUpFromData method doesn't work correctly so we must set the values manually
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Value = GetIndex(Value);
|
||||
stringOption.Values = StringNameValues;
|
||||
stringOption.stringOptionName = Int32OptionNames.Invalid;
|
||||
stringOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
// Changing the button text to make them more distinct from number options
|
||||
stringOption.MinusBtn.ChangeButtonText("<");
|
||||
stringOption.PlusBtn.ChangeButtonText(">");
|
||||
|
||||
// SetUpFromData method doesn't work correctly so we must set the values manually
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Values = StringNameValues;
|
||||
stringOption.Value = GetIndex(Value);
|
||||
|
||||
OptionBehaviour = stringOption;
|
||||
|
||||
return stringOption;
|
||||
|
||||
@@ -113,7 +113,6 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
data.Increment = Increment;
|
||||
data.ValidRange = new FloatRange(Min, Max);
|
||||
data.FormatString = FormatString;
|
||||
|
||||
data.ZeroIsInfinity = ZeroInfinity;
|
||||
data.SuffixType = (NumberSuffixes)SuffixType;
|
||||
data.OptionName = FloatOptionNames.Invalid;
|
||||
@@ -213,17 +212,10 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
PlayerOption playerOpt,
|
||||
Transform container)
|
||||
{
|
||||
var numberOption = Object.Instantiate(numberOpt, Vector3.zero, Quaternion.identity, container);
|
||||
var numberOption = Object.Instantiate(numberOpt, container);
|
||||
numberOption.name = $"{ParentMod!.OptionsTitleText}.NumberOption.{Title}";
|
||||
var optionComponent = numberOption.gameObject.AddComponent<MiraNumberOptionComponent>();
|
||||
optionComponent.NumberOption = this;
|
||||
optionComponent.DefaultIncrement = Increment;
|
||||
optionComponent.ShiftIncrementToggle = ShiftIncrement;
|
||||
optionComponent.NegativeValue = NegativeWordValue;
|
||||
optionComponent.ZeroValue = ZeroWordValue;
|
||||
|
||||
numberOption.SetUpFromData(Data, 20);
|
||||
numberOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
numberOption.Title = StringName;
|
||||
numberOption.Value = Value;
|
||||
@@ -233,6 +225,14 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
numberOption.ZeroIsInfinity = ZeroInfinity;
|
||||
numberOption.SuffixType = (NumberSuffixes)SuffixType;
|
||||
numberOption.floatOptionName = FloatOptionNames.Invalid;
|
||||
numberOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
var optionComponent = numberOption.gameObject.AddComponent<MiraNumberOptionComponent>();
|
||||
optionComponent.NumberOption = this;
|
||||
optionComponent.DefaultIncrement = Increment;
|
||||
optionComponent.ShiftIncrementToggle = ShiftIncrement;
|
||||
optionComponent.NegativeValue = NegativeWordValue;
|
||||
optionComponent.ZeroValue = ZeroWordValue;
|
||||
|
||||
OptionBehaviour = numberOption;
|
||||
|
||||
@@ -301,6 +301,6 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
/// <returns>Integer value.</returns>
|
||||
public static implicit operator int(ModdedNumberOption option)
|
||||
{
|
||||
return (int)Math.Round(option.Value);
|
||||
return (int)MathF.Round(option.Value);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
@@ -33,7 +34,7 @@ public class ModdedPlayerOption : ModdedOption<int>
|
||||
/// </summary>
|
||||
/// <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="allowNone">Whether the option includes a none option. If None is selected, value will return -1.</param>
|
||||
/// <param name="allowNone">Whether the option includes a none option. If None is selected, value can return -1.</param>
|
||||
public ModdedPlayerOption(string groupPrefix, string title, bool allowNone = true)
|
||||
: base(groupPrefix, title, allowNone ? -1 : 0, false)
|
||||
{
|
||||
@@ -53,7 +54,7 @@ public class ModdedPlayerOption : ModdedOption<int>
|
||||
/// Initializes a new instance of the <see cref="ModdedPlayerOption"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the option.</param>
|
||||
/// <param name="allowNone">Whether the option includes a none option. If None is selected, value will return -1.</param>
|
||||
/// <param name="allowNone">Whether the option includes a none option. If None is selected, value can return -1.</param>
|
||||
public ModdedPlayerOption(string title, bool allowNone = true)
|
||||
: this(string.Empty, title, allowNone)
|
||||
{
|
||||
@@ -67,25 +68,27 @@ public class ModdedPlayerOption : ModdedOption<int>
|
||||
PlayerOption playerOpt,
|
||||
Transform container)
|
||||
{
|
||||
Values = GetFilteredPlayers();
|
||||
|
||||
var playerOption = Object.Instantiate(playerOpt, container);
|
||||
playerOption.name = $"{ParentMod!.OptionsTitleText}.PlayerOption.{Title}";
|
||||
|
||||
Values = GetFilteredPlayers();
|
||||
|
||||
playerOption.SetUpFromData(Data, 20);
|
||||
playerOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
playerOption.Title = StringName;
|
||||
playerOption.Values = Values.ToIl2CppList();
|
||||
playerOption.Value = Value;
|
||||
playerOption.playerIndex = Values.FindIndex(p => p.PlayerId == Value);
|
||||
|
||||
OptionBehaviour = playerOption;
|
||||
ModdedOptionsManager.CreatedPlayerOptions.TryAdd(playerOption, this);
|
||||
playerOption.optionName = Int32OptionNames.Invalid;
|
||||
playerOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
playerOption.SetValueText();
|
||||
playerOption.AdjustButtonsActiveState();
|
||||
|
||||
playerOpt.gameObject.AddComponent<MiraPlayerOptionComponent>().PlayerOption = this;
|
||||
|
||||
OptionBehaviour = playerOption;
|
||||
|
||||
return playerOption;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Translation;
|
||||
using UnityEngine;
|
||||
@@ -82,13 +83,14 @@ public class ModdedToggleOption : ModdedOption<bool>
|
||||
/// <inheritdoc />
|
||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, PlayerOption playerOpt, Transform container)
|
||||
{
|
||||
var toggleOption = Object.Instantiate(toggleOpt, Vector3.zero, Quaternion.identity, container);
|
||||
var toggleOption = Object.Instantiate(toggleOpt, container);
|
||||
toggleOption.name = $"{ParentMod!.OptionsTitleText}.ToggleOption.{Title}";
|
||||
|
||||
toggleOption.SetUpFromData(Data, 20);
|
||||
|
||||
toggleOption.Title = StringName;
|
||||
toggleOption.CheckMark.enabled = Value;
|
||||
toggleOption.boolOptionName = BoolOptionNames.Invalid;
|
||||
toggleOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
OptionBehaviour = toggleOption;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Translation;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -10,125 +9,125 @@ namespace MiraAPI.Patches.Options;
|
||||
[HarmonyPatch]
|
||||
public static class OptionsPatches
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(RoleOptionSetting), nameof(RoleOptionSetting.IncreaseChance))]
|
||||
public static bool RoleIncreaseChancePrefix(RoleOptionSetting __instance)
|
||||
private static bool HandleRoleChance(RoleOptionSetting instance, int direction)
|
||||
{
|
||||
if (!__instance.Role.IsCustomRole())
|
||||
{
|
||||
if (!instance.Role.IsCustomRole())
|
||||
return true;
|
||||
}
|
||||
|
||||
if (__instance.roleChance == 0)
|
||||
{
|
||||
__instance.roleMaxCount = 1;
|
||||
}
|
||||
if (instance.roleChance == 0)
|
||||
instance.roleMaxCount = 1;
|
||||
|
||||
var increment = Input.GetKey(KeyCode.LeftShift) ? 5 : 10;
|
||||
__instance.roleChance += increment;
|
||||
var increment = (Input.GetKey(KeyCode.LeftShift) ? 5 : 10) * direction;
|
||||
instance.roleChance += increment;
|
||||
|
||||
if (__instance.roleChance > 100)
|
||||
{
|
||||
__instance.roleChance = 0;
|
||||
}
|
||||
if (instance.roleChance > 100)
|
||||
instance.roleChance = 0;
|
||||
else if (instance.roleChance < 0)
|
||||
instance.roleChance = 100;
|
||||
|
||||
if (__instance.roleChance == 0)
|
||||
{
|
||||
__instance.roleMaxCount = 0;
|
||||
}
|
||||
if (instance.roleChance == 0)
|
||||
instance.roleMaxCount = 0;
|
||||
|
||||
__instance.OnValueChanged.Invoke(__instance);
|
||||
instance.OnValueChanged.Invoke(instance);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HandleRoleCount(RoleOptionSetting instance, int direction)
|
||||
{
|
||||
if (!instance.Role.IsCustomRole())
|
||||
return true;
|
||||
|
||||
if (instance.roleMaxCount == 0)
|
||||
instance.roleChance = 50;
|
||||
|
||||
instance.roleMaxCount += direction;
|
||||
|
||||
if (instance.roleMaxCount > instance.role.MaxCount)
|
||||
instance.roleMaxCount = 0;
|
||||
else if (instance.roleMaxCount < 0)
|
||||
instance.roleMaxCount = instance.role.MaxCount;
|
||||
|
||||
if (instance.roleMaxCount == 0)
|
||||
instance.roleChance = 0;
|
||||
|
||||
instance.OnValueChanged.Invoke(instance);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HandleNumberOption(NumberOption instance, int direction)
|
||||
{
|
||||
if (!instance.IsCustom())
|
||||
return true;
|
||||
|
||||
var increment = instance.Increment;
|
||||
|
||||
if (Input.GetKey(KeyCode.LeftShift) &&
|
||||
instance.TryGetComponent<MiraNumberOptionComponent>(out var miraNumber) &&
|
||||
miraNumber.ShiftIncrementToggle)
|
||||
{
|
||||
increment /= 2;
|
||||
}
|
||||
|
||||
instance.Value += increment * direction;
|
||||
|
||||
if (instance.Value > instance.ValidRange.max)
|
||||
instance.Value = instance.ValidRange.min;
|
||||
else if (instance.Value < instance.ValidRange.min)
|
||||
instance.Value = instance.ValidRange.max;
|
||||
|
||||
instance.OnValueChanged.Invoke(instance);
|
||||
instance.AdjustButtonsActiveState();
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HandleStringOption(StringOption instance, int direction)
|
||||
{
|
||||
if (!instance.IsCustom())
|
||||
return true;
|
||||
|
||||
instance.Value += direction;
|
||||
|
||||
if (instance.Value >= instance.Values.Length)
|
||||
instance.Value = 0;
|
||||
else if (instance.Value < 0)
|
||||
instance.Value = instance.Values.Length - 1;
|
||||
|
||||
instance.OnValueChanged.Invoke(instance);
|
||||
instance.AdjustButtonsActiveState();
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(RoleOptionSetting), nameof(RoleOptionSetting.IncreaseChance))]
|
||||
public static bool RoleIncreaseChancePrefix(RoleOptionSetting __instance) => HandleRoleChance(__instance, 1);
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(RoleOptionSetting), nameof(RoleOptionSetting.DecreaseChance))]
|
||||
public static bool RoleDecreaseChancePrefix(RoleOptionSetting __instance)
|
||||
{
|
||||
if (!__instance.Role.IsCustomRole())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (__instance.roleChance == 0)
|
||||
{
|
||||
__instance.roleMaxCount = 1;
|
||||
}
|
||||
|
||||
var increment = Input.GetKey(KeyCode.LeftShift) ? 5 : 10;
|
||||
__instance.roleChance -= increment;
|
||||
|
||||
if (__instance.roleChance < 0)
|
||||
{
|
||||
__instance.roleChance = 100;
|
||||
}
|
||||
|
||||
if (__instance.roleChance == 0)
|
||||
{
|
||||
__instance.roleMaxCount = 0;
|
||||
}
|
||||
|
||||
__instance.OnValueChanged.Invoke(__instance);
|
||||
return false;
|
||||
}
|
||||
public static bool RoleDecreaseChancePrefix(RoleOptionSetting __instance) => HandleRoleChance(__instance, -1);
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(RoleOptionSetting), nameof(RoleOptionSetting.IncreaseCount))]
|
||||
public static bool RoleIncreaseCountPrefix(RoleOptionSetting __instance)
|
||||
{
|
||||
if (!__instance.Role.IsCustomRole())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (__instance.roleMaxCount == 0)
|
||||
{
|
||||
__instance.roleChance = 50;
|
||||
}
|
||||
|
||||
__instance.roleMaxCount += 1;
|
||||
if (__instance.roleMaxCount > __instance.role.MaxCount)
|
||||
{
|
||||
__instance.roleMaxCount = 0;
|
||||
}
|
||||
|
||||
if (__instance.roleMaxCount == 0)
|
||||
{
|
||||
__instance.roleChance = 0;
|
||||
}
|
||||
|
||||
__instance.OnValueChanged.Invoke(__instance);
|
||||
return false;
|
||||
}
|
||||
public static bool RoleIncreaseCountPrefix(RoleOptionSetting __instance) => HandleRoleCount(__instance, 1);
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(RoleOptionSetting), nameof(RoleOptionSetting.DecreaseCount))]
|
||||
public static bool RoleDecreaseCountPrefix(RoleOptionSetting __instance)
|
||||
{
|
||||
if (!__instance.Role.IsCustomRole())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static bool RoleDecreaseCountPrefix(RoleOptionSetting __instance) => HandleRoleCount(__instance, -1);
|
||||
|
||||
if (__instance.roleMaxCount == 0)
|
||||
{
|
||||
__instance.roleChance = 50;
|
||||
}
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(NumberOption), nameof(NumberOption.Increase))]
|
||||
public static bool NumberIncrease(NumberOption __instance) => HandleNumberOption(__instance, 1);
|
||||
|
||||
__instance.roleMaxCount -= 1;
|
||||
if (__instance.roleMaxCount < 0)
|
||||
{
|
||||
__instance.roleMaxCount = __instance.role.MaxCount;
|
||||
}
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(NumberOption), nameof(NumberOption.Decrease))]
|
||||
public static bool NumberDecrease(NumberOption __instance) => HandleNumberOption(__instance, -1);
|
||||
|
||||
if (__instance.roleMaxCount == 0)
|
||||
{
|
||||
__instance.roleChance = 0;
|
||||
}
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(StringOption), nameof(StringOption.Increase))]
|
||||
public static bool StringOptionIncrease(StringOption __instance) => HandleStringOption(__instance, 1);
|
||||
|
||||
__instance.OnValueChanged.Invoke(__instance);
|
||||
return false;
|
||||
}
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(StringOption), nameof(StringOption.Decrease))]
|
||||
public static bool StringOptionDecrease(StringOption __instance) => HandleStringOption(__instance, -1);
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(NumberOption), nameof(NumberOption.AdjustButtonsActiveState))]
|
||||
@@ -138,65 +137,43 @@ public static class OptionsPatches
|
||||
[HarmonyPatch(typeof(RoleOptionSetting), nameof(RoleOptionSetting.AdjustCountButtonsActiveState))]
|
||||
public static bool AdjustButtonsPrefix(OptionBehaviour __instance)
|
||||
{
|
||||
if (__instance.IsCustom())
|
||||
if (!__instance.IsCustom())
|
||||
{
|
||||
if (__instance.TryCast<NumberOption>() is { } numberOption)
|
||||
{
|
||||
numberOption.MinusBtn.SetInteractable(true);
|
||||
numberOption.PlusBtn.SetInteractable(true);
|
||||
}
|
||||
if (!__instance.TryCast<RoleOptionSetting>(out var roleOptionSetting) || !roleOptionSetting.Role.IsCustomRole())
|
||||
return true;
|
||||
|
||||
if (__instance.TryCast<StringOption>() is { } stringOption)
|
||||
{
|
||||
stringOption.MinusBtn.SetInteractable(true);
|
||||
stringOption.PlusBtn.SetInteractable(true);
|
||||
}
|
||||
|
||||
if (__instance.TryCast<PlayerOption>() is { } playerOption)
|
||||
{
|
||||
playerOption.MinusBtn.SetInteractable(true);
|
||||
playerOption.PlusBtn.SetInteractable(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (__instance.TryCast<RoleOptionSetting>() is { } roleOptionSetting && roleOptionSetting.Role.IsCustomRole())
|
||||
{
|
||||
roleOptionSetting.CountMinusBtn.SetInteractable(true);
|
||||
roleOptionSetting.CountPlusBtn.SetInteractable(true);
|
||||
roleOptionSetting.ChanceMinusBtn.SetInteractable(true);
|
||||
roleOptionSetting.ChancePlusBtn.SetInteractable(true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ToggleOption), nameof(ToggleOption.Initialize))]
|
||||
public static bool ToggleInit(ToggleOption __instance)
|
||||
{
|
||||
if (!__instance.IsCustom())
|
||||
if (__instance.TryCast<NumberOption>(out var numberOption))
|
||||
{
|
||||
return true;
|
||||
numberOption.MinusBtn.SetInteractable(true);
|
||||
numberOption.PlusBtn.SetInteractable(true);
|
||||
}
|
||||
else if (__instance.TryCast<StringOption>(out var stringOption))
|
||||
{
|
||||
stringOption.MinusBtn.SetInteractable(true);
|
||||
stringOption.PlusBtn.SetInteractable(true);
|
||||
}
|
||||
else if (__instance.TryCast<PlayerOption>(out var playerOption))
|
||||
{
|
||||
playerOption.MinusBtn.SetInteractable(true);
|
||||
playerOption.PlusBtn.SetInteractable(true);
|
||||
}
|
||||
|
||||
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title).Translate();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// UpdateValue was inlined.
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ToggleOption), nameof(ToggleOption.Toggle))]
|
||||
public static bool ToggleUpdate(ToggleOption __instance)
|
||||
{
|
||||
if (!__instance.IsCustom())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
__instance.CheckMark.enabled = !__instance.CheckMark.enabled;
|
||||
__instance.OnValueChanged.Invoke(__instance);
|
||||
@@ -207,134 +184,5 @@ public static class OptionsPatches
|
||||
[HarmonyPatch(typeof(StringOption), nameof(StringOption.UpdateValue))]
|
||||
[HarmonyPatch(typeof(NumberOption), nameof(NumberOption.UpdateValue))]
|
||||
[HarmonyPatch(typeof(PlayerOption), nameof(PlayerOption.UpdateValue))]
|
||||
public static bool UpdateValuePrefix(OptionBehaviour __instance)
|
||||
{
|
||||
return !__instance.IsCustom();
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(NumberOption), nameof(NumberOption.Initialize))]
|
||||
public static bool NumberInit(NumberOption __instance)
|
||||
{
|
||||
if (!__instance.IsCustom())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title).Translate();
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(NumberOption), nameof(NumberOption.Increase))]
|
||||
public static bool NumberIncrease(NumberOption __instance)
|
||||
{
|
||||
if (!__instance.IsCustom())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var increment = __instance.Increment;
|
||||
|
||||
if (Input.GetKey(KeyCode.LeftShift) &&
|
||||
__instance.TryGetComponent<MiraNumberOptionComponent>(out var miraNumber) &&
|
||||
miraNumber.ShiftIncrementToggle)
|
||||
{
|
||||
increment /= 2;
|
||||
}
|
||||
|
||||
__instance.Value += increment;
|
||||
if (__instance.Value > __instance.ValidRange.max)
|
||||
{
|
||||
__instance.Value = __instance.ValidRange.min;
|
||||
}
|
||||
|
||||
__instance.OnValueChanged.Invoke(__instance);
|
||||
__instance.AdjustButtonsActiveState();
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(NumberOption), nameof(NumberOption.Decrease))]
|
||||
public static bool NumberDecrease(NumberOption __instance)
|
||||
{
|
||||
if (!__instance.IsCustom())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var increment = __instance.Increment;
|
||||
|
||||
if (Input.GetKey(KeyCode.LeftShift) &&
|
||||
__instance.TryGetComponent<MiraNumberOptionComponent>(out var miraNumber) &&
|
||||
miraNumber.ShiftIncrementToggle)
|
||||
{
|
||||
increment /= 2;
|
||||
}
|
||||
|
||||
__instance.Value -= increment;
|
||||
if (__instance.Value < __instance.ValidRange.min)
|
||||
{
|
||||
__instance.Value = __instance.ValidRange.max;
|
||||
}
|
||||
|
||||
__instance.OnValueChanged.Invoke(__instance);
|
||||
__instance.AdjustButtonsActiveState();
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(StringOption), nameof(StringOption.Increase))]
|
||||
public static bool StringOptionIncrease(StringOption __instance)
|
||||
{
|
||||
if (!__instance.IsCustom())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
__instance.Value += 1;
|
||||
if (__instance.Value >= __instance.Values.Length)
|
||||
{
|
||||
__instance.Value = 0;
|
||||
}
|
||||
|
||||
__instance.OnValueChanged.Invoke(__instance);
|
||||
__instance.AdjustButtonsActiveState();
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(StringOption), nameof(StringOption.Decrease))]
|
||||
public static bool StringOptionDecrease(StringOption __instance)
|
||||
{
|
||||
if (!__instance.IsCustom())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
__instance.Value -= 1;
|
||||
if (__instance.Value < 0)
|
||||
{
|
||||
__instance.Value = __instance.Values.Length - 1;
|
||||
}
|
||||
|
||||
__instance.OnValueChanged.Invoke(__instance);
|
||||
__instance.AdjustButtonsActiveState();
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(StringOption), nameof(StringOption.Initialize))]
|
||||
public static bool StringInit(StringOption __instance)
|
||||
{
|
||||
if (!__instance.IsCustom())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title).Translate();
|
||||
__instance.ValueText.text = TranslationController.Instance.GetString(__instance.Values[__instance.Value]);
|
||||
|
||||
return false;
|
||||
}
|
||||
public static bool UpdateValuePrefix(OptionBehaviour __instance) => !__instance.IsCustom();
|
||||
}
|
||||
@@ -19,7 +19,9 @@ public static class PlayerOptionPatches
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ModdedOptionsManager.CreatedPlayerOptions.TryGetValue(__instance, out var moddedPlrOpt)) return false;
|
||||
if (!__instance.TryGetComponent<MiraPlayerOptionComponent>(out var component)) return false;
|
||||
|
||||
var moddedPlrOpt = component.PlayerOption;
|
||||
|
||||
var filteredPlayers = moddedPlrOpt.GetFilteredPlayers();
|
||||
if (filteredPlayers.Count != __instance.Values.Count)
|
||||
@@ -42,7 +44,7 @@ public static class PlayerOptionPatches
|
||||
[HarmonyPatch(nameof(PlayerOption.UpdatePlayerIndex))]
|
||||
public static bool UpdatePlayerIndexPatch(PlayerOption __instance, int index)
|
||||
{
|
||||
if (!__instance.IsCustom() || ModdedOptionsManager.CreatedPlayerOptions[__instance].AllowNone)
|
||||
if (!__instance.IsCustom() || !__instance.TryGetComponent<MiraPlayerOptionComponent>(out var component) || component.PlayerOption.AllowNone)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
using MiraAPI.GameModes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Networking;
|
||||
@@ -202,7 +203,7 @@ public static class Extensions
|
||||
/// <returns><see langword="true"/> if the <see langword="float"/> is an integer, <see langword="false"/> otherwise.</returns>
|
||||
public static bool IsInteger(this float number)
|
||||
{
|
||||
return Mathf.Approximately(number, Mathf.Round(number));
|
||||
return Mathf.Approximately(number, MathF.Round(number));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -887,4 +888,24 @@ public static class Extensions
|
||||
attribute = member.GetCustomAttribute<T>();
|
||||
return attribute != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to cast an IL2CPP object to <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the value to cast to.</typeparam>
|
||||
/// <param name="obj">The object to cast.</param>
|
||||
/// <param name="result">When the method returns, the casted object if true; null if false.</param>
|
||||
/// <returns>true if the cast was successful; false otherwise.</returns>
|
||||
public static bool TryCast<T>(this Il2CppObjectBase? obj, [NotNullWhen(true)] out T? result)
|
||||
where T : Il2CppObjectBase
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
result = obj.TryCast<T>();
|
||||
return result != null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user