diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index 43b6e13..93b5b5f 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -122,7 +122,7 @@ public abstract class ModdedOption : IModdedOption entry.Value = Value; } - Rpc.Instance.Send(PlayerControl.LocalPlayer, [GetNetData()]); + Rpc.Instance.Send(PlayerControl.LocalPlayer, [GetNetData()], true); } OnValueChanged(newValue); diff --git a/MiraAPI/Patches/Options/OptionsPatches.cs b/MiraAPI/Patches/Options/OptionsPatches.cs index 8560a77..c61613c 100644 --- a/MiraAPI/Patches/Options/OptionsPatches.cs +++ b/MiraAPI/Patches/Options/OptionsPatches.cs @@ -37,6 +37,22 @@ public static class OptionsPatches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(StringOption), nameof(StringOption.UpdateValue))] + [HarmonyPatch(typeof(NumberOption), nameof(NumberOption.UpdateValue))] + public static bool UpdateValuePrefix(OptionBehaviour __instance) + { + return !__instance.IsCustom(); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(NumberOption), nameof(NumberOption.AdjustButtonsActiveState))] + [HarmonyPatch(typeof(StringOption), nameof(StringOption.AdjustButtonsActiveState))] + public static bool AdjustButtonsPrefix(OptionBehaviour __instance) + { + return !__instance.IsCustom(); + } + [HarmonyPrefix] [HarmonyPatch(typeof(NumberOption), nameof(NumberOption.Initialize))] public static bool NumberInit(NumberOption __instance) @@ -46,17 +62,84 @@ public static class OptionsPatches return true; } - __instance.TitleText.text = - TranslationController.Instance.GetString(__instance.Title, Array.Empty()); - + __instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title, Array.Empty()); return false; } [HarmonyPrefix] - [HarmonyPatch(typeof(NumberOption), nameof(NumberOption.UpdateValue))] - public static bool NumberUpdate(NumberOption __instance) + [HarmonyPatch(typeof(NumberOption), nameof(NumberOption.Increase))] + public static bool NumberIncrease(NumberOption __instance) { - return !__instance.IsCustom(); + if (!__instance.IsCustom()) + { + return true; + } + + __instance.Value += __instance.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; + } + + __instance.Value -= __instance.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] @@ -68,19 +151,9 @@ public static class OptionsPatches return true; } - __instance.TitleText.text = - TranslationController.Instance.GetString(__instance.Title, Array.Empty()); - __instance.ValueText.text = TranslationController.Instance.GetString( - __instance.Values[__instance.Value], - Array.Empty()); + __instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title, Array.Empty()); + __instance.ValueText.text = TranslationController.Instance.GetString(__instance.Values[__instance.Value], Array.Empty()); return false; } - - [HarmonyPrefix] - [HarmonyPatch(typeof(StringOption), nameof(StringOption.UpdateValue))] - public static bool StringUpdate(StringOption __instance) - { - return !__instance.IsCustom(); - } } diff --git a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs index 617fc0d..a15ce2a 100644 --- a/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs +++ b/MiraAPI/Patches/Options/RoleSettingMenuPatches.cs @@ -300,7 +300,7 @@ public static class RoleSettingMenuPatches if (AmongUsClient.Instance.AmHost) { - Rpc.Instance.Send(PlayerControl.LocalPlayer, [role.GetNetData()]); + Rpc.Instance.Send(PlayerControl.LocalPlayer, [role.GetNetData()], true); } GameOptionsManager.Instance.GameHostOptions = GameOptionsManager.Instance.CurrentGameOptions;