-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathEnum_GetValues_Patch.cs
More file actions
37 lines (32 loc) · 1.42 KB
/
Enum_GetValues_Patch.cs
File metadata and controls
37 lines (32 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Linq;
using System.Reflection;
using NitroxClient.MonoBehaviours.Gui.Input;
namespace NitroxPatcher.Patches.Persistent;
/// <summary>
/// Extends Enum.GetValues() to include Nitrox buttons, which is required for the rebinding UI to recognize them as valid.
/// Duplicate checking ensures compatibility when Nautilus or other mods also extend the enum.
/// GameInputSystem_Initialize_Patch also extends GameInput.AllActions (with its own duplicate check) for action creation.
/// </summary>
public partial class Enum_GetValues_Patch : NitroxPatch, IPersistentPatch
{
private static readonly MethodInfo TARGET_METHOD = Reflect.Method(() => Enum.GetValues(default));
public static void Postfix(Type enumType, ref Array __result)
{
if (enumType != typeof(GameInput.Button))
{
return;
}
// Check if Nitrox buttons are already in the result (e.g. added by Nautilus or a previous call)
int firstNitroxButton = KeyBindingManager.NITROX_BASE_ID;
if (__result.Cast<GameInput.Button>().Any(b => (int)b >= firstNitroxButton && (int)b < firstNitroxButton + KeyBindingManager.KeyBindings.Count))
{
return;
}
__result = (GameInput.Button[])
[
.. __result.Cast<GameInput.Button>(),
.. Enumerable.Range(firstNitroxButton, KeyBindingManager.KeyBindings.Count).Cast<GameInput.Button>()
];
}
}