diff --git a/MiraAPI/Keybinds/BaseKeybind.cs b/MiraAPI/Keybinds/BaseKeybind.cs
index 21d636e..e4e6ac8 100644
--- a/MiraAPI/Keybinds/BaseKeybind.cs
+++ b/MiraAPI/Keybinds/BaseKeybind.cs
@@ -16,7 +16,7 @@ public class BaseKeybind
///
/// Gets the unique identifier for this keybind. Used in Rewired.
///
- public string Id { get; }
+ public string Id { get; protected set; }
///
/// Gets the currently assigned keycode.
@@ -38,6 +38,11 @@ public class BaseKeybind
Handler = () => { };
}
+ public BaseKeybind()
+ {
+ Handler = () => { };
+ }
+
///
/// Triggers the keybind, invoking its handler.
///
diff --git a/MiraAPI/Keybinds/KeybindManager.cs b/MiraAPI/Keybinds/KeybindManager.cs
index a123647..a47a20a 100644
--- a/MiraAPI/Keybinds/KeybindManager.cs
+++ b/MiraAPI/Keybinds/KeybindManager.cs
@@ -16,7 +16,8 @@ public static class KeybindManager
/// Gets a list of all registered keybinds.
///
public static List Keybinds { get; } = new();
- internal static Dictionary VanillaKeybinds { get; } = new();
+
+ internal static Dictionary VanillaKeybinds { get; set; }
internal static void RewiredInit()
{
@@ -92,10 +93,4 @@ public static class KeybindManager
return all.ToArray();
}
-
- internal static void RegisterVanillaKeybind(ActionButton button, int id)
- {
- var keybind = new VanillaKeybind(button, KeybindUtils.GetInputActionById(id)!);
- VanillaKeybinds.Add(button.GetType(), keybind);
- }
}
diff --git a/MiraAPI/Keybinds/VanillaKeybind.cs b/MiraAPI/Keybinds/VanillaKeybind.cs
index ad1bbb5..c04b83b 100644
--- a/MiraAPI/Keybinds/VanillaKeybind.cs
+++ b/MiraAPI/Keybinds/VanillaKeybind.cs
@@ -10,16 +10,15 @@ public class VanillaKeybind : BaseKeybind
///
/// Gets the this keybind is binded to.
///
- public ActionButton? Button { get; }
+ public ActionButton? Button { get; internal set; }
///
/// Initializes a new instance of the class.
///
- /// The keybind action button.
- /// The rewired input action.
- public VanillaKeybind(ActionButton button, InputAction action) : base(action.name)
+ /// The keybind id.
+ public VanillaKeybind(int id)
{
- Button = button;
- RewiredInputAction = action;
+ RewiredInputAction = KeybindUtils.GetInputActionById(id);
+ Id = RewiredInputAction?.name;
}
}
diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs
index 6183d5c..c1a9bf2 100644
--- a/MiraAPI/Patches/HudManagerPatches.cs
+++ b/MiraAPI/Patches/HudManagerPatches.cs
@@ -45,33 +45,6 @@ public static class HudManagerPatches
[HarmonyPatch(nameof(HudManager.Start))]
public static void StartPostfix(HudManager __instance)
{
- vanillaKeybindIcons = [];
- var keybindIconPos = new Vector3(-0.4f, 0.4f, -9f);
- var vanillaButtons = new Dictionary
- {
- { __instance.KillButton.gameObject, 8 },
- { __instance.UseButton.gameObject, 6 },
- { __instance.ReportButton.gameObject, 7 },
- { __instance.ImpostorVentButton.gameObject, 50 },
- { __instance.SabotageButton.gameObject, 4 },
- };
-
- KeybindManager.VanillaKeybinds.Clear();
- foreach (var kvp in vanillaButtons)
- {
- var buttonObj = kvp.Key;
- var actionId = kvp.Value;
-
- var key = KeybindUtils.GetKeycodeByActionId(actionId);
- if (key == KeyboardKeyCode.None)
- {
- continue;
- }
- var icon = Helpers.CreateKeybindIcon(buttonObj, key, keybindIconPos);
- vanillaKeybindIcons.Add(icon.transform.GetChild(0).GetComponent(), actionId);
- KeybindManager.RegisterVanillaKeybind(buttonObj.GetComponent(), actionId);
- }
-
if (Buttons == null)
{
Buttons = __instance.transform.Find("Buttons");
@@ -125,8 +98,35 @@ public static class HudManagerPatches
gridArrange.Start();
gridArrange.ArrangeChilds();
-
aspectPosition.AdjustPosition();
+
+ vanillaKeybindIcons = [];
+ var keybindIconPos = new Vector3(-0.4f, 0.4f, -9f);
+ var vanillaButtons = new Dictionary
+ {
+ { __instance.KillButton.gameObject, 8 },
+ { __instance.UseButton.gameObject, 6 },
+ { __instance.ReportButton.gameObject, 7 },
+ { __instance.ImpostorVentButton.gameObject, 50 },
+ { __instance.SabotageButton.gameObject, 4 },
+ };
+
+ KeybindManager.VanillaKeybinds.Clear();
+ foreach (var kvp in vanillaButtons)
+ {
+ var buttonObj = kvp.Key;
+ var actionId = kvp.Value;
+
+ var key = KeybindUtils.GetKeycodeByActionId(actionId);
+ if (key == KeyboardKeyCode.None)
+ {
+ continue;
+ }
+ var icon = Helpers.CreateKeybindIcon(buttonObj, key, keybindIconPos);
+ vanillaKeybindIcons.Add(icon.transform.GetChild(0).GetComponent(), actionId);
+ var comp = buttonObj.GetComponent();
+ KeybindManager.VanillaKeybinds[comp.GetType()].Button = comp;
+ }
}
///
diff --git a/MiraAPI/Patches/Keybinds/KeybindsPatch.cs b/MiraAPI/Patches/Keybinds/KeybindsPatch.cs
index 1f60df0..3a6cf24 100644
--- a/MiraAPI/Patches/Keybinds/KeybindsPatch.cs
+++ b/MiraAPI/Patches/Keybinds/KeybindsPatch.cs
@@ -1,5 +1,6 @@
using HarmonyLib;
using MiraAPI.Keybinds;
+using MonoMod.Utils;
using Rewired;
namespace MiraAPI.Patches.Keybinds;
@@ -20,5 +21,15 @@ public static class KeybindMenuPatch
KeybindUtils.RewiredInputManager = __instance;
KeybindManager.RewiredInit();
_registered = true;
+
+ // Set these here right after input manager initializes
+ KeybindManager.VanillaKeybinds = new()
+ {
+ { typeof(KillButton), new VanillaKeybind(8) },
+ { typeof(UseButton), new VanillaKeybind(6) },
+ { typeof(ReportButton), new VanillaKeybind(7) },
+ { typeof(VentButton), new VanillaKeybind(50) },
+ { typeof(SabotageButton), new VanillaKeybind(4) },
+ };
}
}