diff --git a/MiraAPI.Example/Buttons/ThinkButton.cs b/MiraAPI.Example/Buttons/ThinkButton.cs index 1141a9a..6497784 100644 --- a/MiraAPI.Example/Buttons/ThinkButton.cs +++ b/MiraAPI.Example/Buttons/ThinkButton.cs @@ -35,4 +35,4 @@ public class ThinkButton : CustomActionButton { return role != null && role.IsImpostor; } -} \ No newline at end of file +} diff --git a/MiraAPI.Example/ExampleEventHandlers.cs b/MiraAPI.Example/ExampleEventHandlers.cs index 3647899..20c0def 100644 --- a/MiraAPI.Example/ExampleEventHandlers.cs +++ b/MiraAPI.Example/ExampleEventHandlers.cs @@ -1,5 +1,4 @@ -using System.Diagnostics.CodeAnalysis; -using System.Globalization; +using System.Globalization; using System.Linq; using MiraAPI.Events; using MiraAPI.Events.Mira; diff --git a/MiraAPI.Example/ExampleKeybinds.cs b/MiraAPI.Example/ExampleKeybinds.cs index 601fc28..4c8f04f 100644 --- a/MiraAPI.Example/ExampleKeybinds.cs +++ b/MiraAPI.Example/ExampleKeybinds.cs @@ -7,4 +7,4 @@ namespace MiraAPI.Example; public static class ExampleKeybinds { public static MiraKeybind NeutralWinKeybind { get; } = new("Neutral Win", KeyboardKeyCode.C, ControllerButton.RightStick, [ModifierKey.Shift]); -} \ No newline at end of file +} diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index bd56260..ce91ad5 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -217,7 +217,7 @@ public abstract class CustomActionButton { ActiveInputManager.InputType.Keyboard when Keybind.CurrentKey != KeyboardKeyCode.None => Keybind.CurrentKey.ToString(), ActiveInputManager.InputType.Joystick => Keybind.CurrentControllerButton, - _ => string.Empty + _ => string.Empty, }; KeybindText.text = text; @@ -516,7 +516,8 @@ public abstract class CustomActionButton /// Custom action button that has a target . /// /// The type of the target object. -public abstract class CustomActionButton : CustomActionButton where T : MonoBehaviour +public abstract class CustomActionButton : CustomActionButton + where T : MonoBehaviour { /// /// Gets or sets the target of the button. @@ -576,4 +577,4 @@ public abstract class CustomActionButton : CustomActionButton where T : MonoB SetOutline(false); Target = null; } -} \ No newline at end of file +} diff --git a/MiraAPI/Keybinds/BaseKeybind.cs b/MiraAPI/Keybinds/BaseKeybind.cs index c853c1d..9944964 100644 --- a/MiraAPI/Keybinds/BaseKeybind.cs +++ b/MiraAPI/Keybinds/BaseKeybind.cs @@ -79,4 +79,4 @@ public class BaseKeybind Handler -= action; #pragma warning restore CS8601 // Possible null reference assignment } -} \ No newline at end of file +} diff --git a/MiraAPI/Keybinds/KeybindManager.cs b/MiraAPI/Keybinds/KeybindManager.cs index 7d7e3c8..143863e 100644 --- a/MiraAPI/Keybinds/KeybindManager.cs +++ b/MiraAPI/Keybinds/KeybindManager.cs @@ -17,7 +17,8 @@ public static class KeybindManager /// public static List Keybinds { get; } = []; - [HideFromIl2Cpp] internal static Dictionary VanillaKeybinds { get; set; } = []; + [HideFromIl2Cpp] + internal static Dictionary VanillaKeybinds { get; set; } = []; internal static void RewiredInit() { @@ -63,7 +64,7 @@ public static class KeybindManager _elementIdentifierId = elementId, _elementType = elementType, _axisRange = AxisRange.Positive, - _axisContribution = Pole.Positive + _axisContribution = Pole.Positive, }); } } @@ -154,9 +155,11 @@ public static class KeybindManager { var all = new List(); foreach (var keybind in Keybinds) + { if (keybind.CurrentKey == keyCode && (keybind.Exclusive || !exclusiveCheck)) all.Add(keybind); + } return [.. all]; } -} \ No newline at end of file +} diff --git a/MiraAPI/Keybinds/KeybindUtils.cs b/MiraAPI/Keybinds/KeybindUtils.cs index 27bb421..5131839 100644 --- a/MiraAPI/Keybinds/KeybindUtils.cs +++ b/MiraAPI/Keybinds/KeybindUtils.cs @@ -40,7 +40,7 @@ public static class KeybindUtils "square" => "□", "circle" => "○", "triangle" => "△", - _ => name + _ => name, }; } @@ -112,4 +112,4 @@ public static class KeybindUtils return KeyboardKeyCode.None; } -} \ No newline at end of file +} diff --git a/MiraAPI/Keybinds/MiraGlobalKeybinds.cs b/MiraAPI/Keybinds/MiraGlobalKeybinds.cs index be1dc84..57381ea 100644 --- a/MiraAPI/Keybinds/MiraGlobalKeybinds.cs +++ b/MiraAPI/Keybinds/MiraGlobalKeybinds.cs @@ -38,4 +38,4 @@ public static class MiraGlobalKeybinds /// Gets the keybind for Tertiary modifier abilities. /// public static MiraKeybind ModifierTertiaryAbility { get; } = new("Modifier Tertiary Ability", KeyboardKeyCode.P); -} \ No newline at end of file +} diff --git a/MiraAPI/Keybinds/MiraKeybind.cs b/MiraAPI/Keybinds/MiraKeybind.cs index ac6147b..ef466b5 100644 --- a/MiraAPI/Keybinds/MiraKeybind.cs +++ b/MiraAPI/Keybinds/MiraKeybind.cs @@ -49,7 +49,8 @@ public class MiraKeybind(string name, KeyboardKeyCode? defaultKeycode, ModifierK /// The default controller button. /// Up to 3 optional s for the keyboard binding. /// Is exclusive. - public MiraKeybind(string name, KeyboardKeyCode? defaultKeycode, ControllerButton defaultControllerButton, ModifierKey[]? modifierKeys = null, bool exclusive = true) : this(name, defaultKeycode, modifierKeys, exclusive) + public MiraKeybind(string name, KeyboardKeyCode? defaultKeycode, ControllerButton defaultControllerButton, ModifierKey[]? modifierKeys = null, bool exclusive = true) + : this(name, defaultKeycode, modifierKeys, exclusive) { DefaultControllerButton = defaultControllerButton; } @@ -59,4 +60,4 @@ public class MiraKeybind(string name, KeyboardKeyCode? defaultKeycode, ModifierK { return $"{Name} ({Id})"; } -} \ No newline at end of file +} diff --git a/MiraAPI/Keybinds/RegisterCustomKeybindsAttribute.cs b/MiraAPI/Keybinds/RegisterCustomKeybindsAttribute.cs index 77e0735..50f8039 100644 --- a/MiraAPI/Keybinds/RegisterCustomKeybindsAttribute.cs +++ b/MiraAPI/Keybinds/RegisterCustomKeybindsAttribute.cs @@ -6,4 +6,4 @@ namespace MiraAPI.Keybinds; /// Used to mark a class for s registration. /// [AttributeUsage(AttributeTargets.Class)] -public class RegisterCustomKeybindsAttribute : Attribute; \ No newline at end of file +public class RegisterCustomKeybindsAttribute : Attribute; diff --git a/MiraAPI/Keybinds/VanillaKeybind.cs b/MiraAPI/Keybinds/VanillaKeybind.cs index 9c23b3a..01d37b3 100644 --- a/MiraAPI/Keybinds/VanillaKeybind.cs +++ b/MiraAPI/Keybinds/VanillaKeybind.cs @@ -21,4 +21,4 @@ public class VanillaKeybind : BaseKeybind RewiredInputAction = KeybindUtils.GetInputActionById(id); Id = RewiredInputAction != null ? RewiredInputAction.name : id.ToString(CultureInfo.InvariantCulture); } -} \ No newline at end of file +} diff --git a/MiraAPI/Keybinds/VanillaKeybindSingleton.cs b/MiraAPI/Keybinds/VanillaKeybindSingleton.cs index ff30d9d..d4e3fd1 100644 --- a/MiraAPI/Keybinds/VanillaKeybindSingleton.cs +++ b/MiraAPI/Keybinds/VanillaKeybindSingleton.cs @@ -6,7 +6,8 @@ namespace MiraAPI.Keybinds; /// Singleton for getting a by . /// /// type. -public static class VanillaKeybinding where T : ActionButton +public static class VanillaKeybinding + where T : ActionButton { [SuppressMessage("Major Code Smell", "S2743:Static fields should not be used in generic types", Justification = "The instance holds a reference to the button that defines the class's type parameter.")] private static VanillaKeybind? _instance; @@ -16,4 +17,4 @@ public static class VanillaKeybinding where T : ActionButton /// [SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "This is a utility class to get the instance of a vanilla keybind.")] public static VanillaKeybind Instance => _instance ??= KeybindManager.VanillaKeybinds[typeof(T)]; -} \ No newline at end of file +} diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 3ccb81b..ad12c68 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -1,6 +1,5 @@ using System.Collections; using System.Collections.Generic; -using System.Linq; using HarmonyLib; using MiraAPI.Hud; using MiraAPI.Keybinds; @@ -43,6 +42,7 @@ public static class HudManagerPatches if (!_storedButtonsParent) _storedButtonsParent = HudManager.Instance.transform.FindChild("Buttons"); if (_storedButtonsParent) + { foreach (var aspect in _storedButtonsParent.GetComponentsInChildren(true)) { if (!aspect.gameObject) continue; @@ -55,6 +55,7 @@ public static class HudManagerPatches aspect.DistanceFromEdge *= new Vector2(scaleFactor, scaleFactor); aspect.gameObject.SetActive(!aspect.isActiveAndEnabled); } + } foreach (var button in HudManager.Instance.GetComponentsInChildren(true)) { @@ -181,7 +182,7 @@ public static class HudManagerPatches { ButtonLocation.BottomLeft => BottomLeft.transform, ButtonLocation.BottomRight => BottomRight, - _ => null + _ => null, }; if (location is null) continue; @@ -212,7 +213,7 @@ public static class HudManagerPatches { __instance.ReportButton.gameObject, 7 }, { __instance.ImpostorVentButton.gameObject, 50 }, { __instance.SabotageButton.gameObject, 4 }, - { __instance.AbilityButton.gameObject, 49 } + { __instance.AbilityButton.gameObject, 49 }, }; foreach (var kvp in vanillaButtons) @@ -253,6 +254,7 @@ public static class HudManagerPatches if (localPlayer.Data == null) return; foreach (var button in CustomButtonManager.CustomButtons) + { try { button.SetActive(isActive, role); @@ -261,6 +263,7 @@ public static class HudManagerPatches { Error($"Failed to set custom button {button.GetType().Name} active: {e}"); } + } } [HarmonyPatch(nameof(HudManager.Update))] @@ -279,11 +282,15 @@ public static class HudManagerPatches var player = ReInput.players.GetPlayer(0); foreach (var entry in KeybindManager.Keybinds) + { if (entry.RewiredInputAction != null && player.GetButtonDown(entry.RewiredInputAction.id)) entry.Invoke(); + } foreach (var entry in KeybindManager.VanillaKeybinds.Values) + { if (player.GetButtonDown(entry.Id)) entry.Invoke(); + } } -} \ No newline at end of file +} diff --git a/MiraAPI/Patches/Keybinds/ControlMapperPatches.cs b/MiraAPI/Patches/Keybinds/ControlMapperPatches.cs index dc112d4..df2179a 100644 --- a/MiraAPI/Patches/Keybinds/ControlMapperPatches.cs +++ b/MiraAPI/Patches/Keybinds/ControlMapperPatches.cs @@ -66,7 +66,7 @@ public static class ControlMapperPatches { ControllerType.Keyboard => conflicts.ContainsKey(map.keyboardKeyCode), ControllerType.Joystick => controllerConflicts.Any(x => x.controllerMap.id == map.controllerMap.id && x.id == map.id), - _ => false + _ => false, }; if (hasConflict) { @@ -79,4 +79,4 @@ public static class ControlMapperPatches } } } -} \ No newline at end of file +} diff --git a/MiraAPI/Patches/Keybinds/KeybindsPatch.cs b/MiraAPI/Patches/Keybinds/KeybindsPatch.cs index a3fd98b..e7acf89 100644 --- a/MiraAPI/Patches/Keybinds/KeybindsPatch.cs +++ b/MiraAPI/Patches/Keybinds/KeybindsPatch.cs @@ -30,7 +30,7 @@ public static class KeybindMenuPatch { typeof(ReportButton), new VanillaKeybind(7) }, { typeof(VentButton), new VanillaKeybind(50) }, { typeof(SabotageButton), new VanillaKeybind(4) }, - { typeof(AbilityButton), new VanillaKeybind(49) } + { typeof(AbilityButton), new VanillaKeybind(49) }, }; } -} \ No newline at end of file +} diff --git a/MiraAPI/Patches/Keybinds/OptionsMenuBehaviourPatch.cs b/MiraAPI/Patches/Keybinds/OptionsMenuBehaviourPatch.cs index e2a1be1..604ae35 100644 --- a/MiraAPI/Patches/Keybinds/OptionsMenuBehaviourPatch.cs +++ b/MiraAPI/Patches/Keybinds/OptionsMenuBehaviourPatch.cs @@ -42,4 +42,4 @@ public static class OptionsMenuBehaviourPatch _remapRollover.OverColor = conflicts ? new Color32(255, 55, 55, 255) : Palette.AcceptedGreen; if (!conflicts && _remapBackground.color == Color.red) _remapBackground.color = Color.white; } -} \ No newline at end of file +} diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 7df947d..f2d6d0c 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -316,8 +316,10 @@ public static class Extensions try { foreach (var mat in renderer.materials) + { if (mat != null) UnityEngine.Object.Destroy(mat); + } } catch { @@ -437,6 +439,7 @@ public static class Extensions tie = true; var result = new KeyValuePair(byte.MaxValue, int.MinValue); foreach (var keyValuePair in self) + { if (keyValuePair.Value > result.Value) { result = keyValuePair; @@ -446,6 +449,7 @@ public static class Extensions { tie = true; } + } return result; } @@ -461,6 +465,7 @@ public static class Extensions tie = true; var result = new KeyValuePair(byte.MaxValue, int.MinValue); foreach (var keyValuePair in self) + { if (keyValuePair.Value > result.Value) { result = keyValuePair; @@ -470,6 +475,7 @@ public static class Extensions { tie = true; } + } return result; } @@ -687,7 +693,8 @@ public static class Extensions /// Optional predicate to test if the is valid. /// The type of the object. /// The if it was found, or if there is none within the radius. - public static T? GetNearestObjectOfType(this PlayerControl playerControl, float radius, ContactFilter2D filter, string? colliderTag = null, Predicate? predicate = null) where T : Component + public static T? GetNearestObjectOfType(this PlayerControl playerControl, float radius, ContactFilter2D filter, string? colliderTag = null, Predicate? predicate = null) + where T : Component { return Helpers.GetNearestObjectsOfType(playerControl.GetTruePosition(), radius, filter, colliderTag).Find(predicate ?? (component => component)); } @@ -709,7 +716,7 @@ public static class Extensions } /// - /// Fixed version of . + /// Fixed version of . /// /// The you want to update the outline for. /// The outline . @@ -752,7 +759,7 @@ public static class Extensions _actionId = action.id, _elementType = ControllerElementType.Button, _axisContribution = Pole.Positive, - _keyboardKeyCode = key + _keyboardKeyCode = key, }; if (modifiers != null) @@ -765,4 +772,4 @@ public static class Extensions userData.keyboardMaps[0].actionElementMaps.Add(map); return action; } -} \ No newline at end of file +}