ToggleHold sprint, tactical, headlight, goggles
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Comfort.Common;
|
||||
using EFT.InputSystem;
|
||||
using HarmonyLib;
|
||||
using JsonType;
|
||||
using SPT.Reflection.Patching;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -12,17 +14,18 @@ public static class AimToggleHoldPatches
|
||||
{
|
||||
public static void Enable()
|
||||
{
|
||||
new AddStatesPatch().Enable();
|
||||
new AddTwoKeyStatesPatch().Enable();
|
||||
new AddOneKeyStatesPatch().Enable();
|
||||
new UpdateInputPatch().Enable();
|
||||
|
||||
Settings.ToggleOrHoldAim.SettingChanged += (_, _) =>
|
||||
{
|
||||
// Will "save" control settings, running GClass1911.UpdateInput, which will set (or unset) toggle/hold behavior
|
||||
Singleton<SharedGameSettingsClass>.Instance.Control.Controller.method_3();
|
||||
};
|
||||
Settings.ToggleOrHoldAim.SettingChanged += OnSettingChanged;
|
||||
Settings.ToggleOrHoldSprint.SettingChanged += OnSettingChanged;
|
||||
Settings.ToggleOrHoldTactical.SettingChanged += OnSettingChanged;
|
||||
Settings.ToggleOrHoldHeadlight.SettingChanged += OnSettingChanged;
|
||||
Settings.ToggleOrHoldGoggles.SettingChanged += OnSettingChanged;
|
||||
}
|
||||
|
||||
public class AddStatesPatch : ModulePatch
|
||||
public class AddTwoKeyStatesPatch : ModulePatch
|
||||
{
|
||||
private static FieldInfo StateMachineArray;
|
||||
|
||||
@@ -35,7 +38,14 @@ public static class AimToggleHoldPatches
|
||||
[PatchPostfix]
|
||||
public static void Postfix(ToggleKeyCombination __instance, EGameKey gameKey, ECommand disableCommand, KeyCombination.KeyCombinationState[] ___keyCombinationState_1)
|
||||
{
|
||||
if (!Settings.ToggleOrHoldAim.Value || gameKey != EGameKey.Aim)
|
||||
bool useToggleHold = gameKey switch
|
||||
{
|
||||
EGameKey.Aim => Settings.ToggleOrHoldAim.Value,
|
||||
EGameKey.Sprint => Settings.ToggleOrHoldSprint.Value,
|
||||
_ => false
|
||||
};
|
||||
|
||||
if (!useToggleHold)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -51,6 +61,43 @@ public static class AimToggleHoldPatches
|
||||
}
|
||||
}
|
||||
|
||||
public class AddOneKeyStatesPatch : ModulePatch
|
||||
{
|
||||
private static FieldInfo StateMachineArray;
|
||||
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
StateMachineArray = AccessTools.Field(typeof(KeyCombination), "keyCombinationState_1");
|
||||
return AccessTools.GetDeclaredConstructors(typeof(KeyCombination)).Single();
|
||||
}
|
||||
|
||||
[PatchPostfix]
|
||||
public static void Postfix(ToggleKeyCombination __instance, EGameKey gameKey, ECommand command, KeyCombination.KeyCombinationState[] ___keyCombinationState_1)
|
||||
{
|
||||
bool useToggleHold = gameKey switch
|
||||
{
|
||||
EGameKey.Tactical => Settings.ToggleOrHoldTactical.Value,
|
||||
EGameKey.ToggleGoggles => Settings.ToggleOrHoldGoggles.Value,
|
||||
EGameKey.ToggleHeadLight => Settings.ToggleOrHoldHeadlight.Value,
|
||||
_ => false
|
||||
};
|
||||
|
||||
if (!useToggleHold)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<KeyCombination.KeyCombinationState> states = new(___keyCombinationState_1)
|
||||
{
|
||||
new ToggleHoldIdleState(__instance),
|
||||
new ToggleHoldClickOrHoldState(__instance),
|
||||
new ToggleHoldHoldState(__instance, command)
|
||||
};
|
||||
|
||||
StateMachineArray.SetValue(__instance, states.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateInputPatch : ModulePatch
|
||||
{
|
||||
protected override MethodBase GetTargetMethod()
|
||||
@@ -61,12 +108,26 @@ public static class AimToggleHoldPatches
|
||||
[PatchPostfix]
|
||||
public static void Postfix(KeyCombination __instance)
|
||||
{
|
||||
if (!Settings.ToggleOrHoldAim.Value || __instance.GameKey != EGameKey.Aim)
|
||||
bool useToggleHold = __instance.GameKey switch
|
||||
{
|
||||
return;
|
||||
}
|
||||
EGameKey.Aim => Settings.ToggleOrHoldAim.Value,
|
||||
EGameKey.Tactical => Settings.ToggleOrHoldTactical.Value,
|
||||
EGameKey.ToggleGoggles => Settings.ToggleOrHoldGoggles.Value,
|
||||
EGameKey.ToggleHeadLight => Settings.ToggleOrHoldHeadlight.Value,
|
||||
EGameKey.Sprint => Settings.ToggleOrHoldSprint.Value,
|
||||
_ => false
|
||||
};
|
||||
|
||||
if (useToggleHold)
|
||||
{
|
||||
__instance.method_0((KeyCombination.EKeyState)ToggleHoldState.Idle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnSettingChanged(object sender, EventArgs args)
|
||||
{
|
||||
// Will "save" control settings, running GClass1911.UpdateInput, which will set (or unset) toggle/hold behavior
|
||||
Singleton<SharedGameSettingsClass>.Instance.Control.Controller.method_3();
|
||||
}
|
||||
}
|
||||
|
42
Settings.cs
42
Settings.cs
@@ -67,6 +67,10 @@ internal class Settings
|
||||
|
||||
// Input
|
||||
public static ConfigEntry<bool> ToggleOrHoldAim { get; set; }
|
||||
public static ConfigEntry<bool> ToggleOrHoldSprint { get; set; }
|
||||
public static ConfigEntry<bool> ToggleOrHoldTactical { get; set; }
|
||||
public static ConfigEntry<bool> ToggleOrHoldHeadlight { get; set; }
|
||||
public static ConfigEntry<bool> ToggleOrHoldGoggles { get; set; }
|
||||
public static ConfigEntry<bool> UseHomeEnd { get; set; }
|
||||
public static ConfigEntry<bool> RebindPageUpDown { get; set; }
|
||||
public static ConfigEntry<int> MouseScrollMulti { get; set; }
|
||||
@@ -225,7 +229,43 @@ internal class Settings
|
||||
"Use Toggle/Hold Aiming",
|
||||
false,
|
||||
new ConfigDescription(
|
||||
"Tap the aim key to toggle aiming, or hold the aim key for continuous aiming",
|
||||
"Tap the aim key to toggle aiming, or hold the key for continuous aiming",
|
||||
null,
|
||||
new ConfigurationManagerAttributes { })));
|
||||
|
||||
configEntries.Add(ToggleOrHoldSprint = config.Bind(
|
||||
InputSection,
|
||||
"Use Toggle/Hold Sprint",
|
||||
false,
|
||||
new ConfigDescription(
|
||||
"Tap the sprint key to toggle sprinting, or hold the key for continuous sprinting",
|
||||
null,
|
||||
new ConfigurationManagerAttributes { })));
|
||||
|
||||
configEntries.Add(ToggleOrHoldTactical = config.Bind(
|
||||
InputSection,
|
||||
"Use Toggle/Hold Tactical Device",
|
||||
false,
|
||||
new ConfigDescription(
|
||||
"Tap the tactical device key to toggle your tactical device, or hold the key for continuous",
|
||||
null,
|
||||
new ConfigurationManagerAttributes { })));
|
||||
|
||||
configEntries.Add(ToggleOrHoldHeadlight = config.Bind(
|
||||
InputSection,
|
||||
"Use Toggle/Hold Headlight",
|
||||
false,
|
||||
new ConfigDescription(
|
||||
"Tap the headlight key to toggle your headlight, or hold the key for continuous",
|
||||
null,
|
||||
new ConfigurationManagerAttributes { })));
|
||||
|
||||
configEntries.Add(ToggleOrHoldGoggles = config.Bind(
|
||||
InputSection,
|
||||
"Use Toggle/Hold Goggles",
|
||||
false,
|
||||
new ConfigDescription(
|
||||
"Tap the goggles key to toggle night vision/goggles/faceshield, or hold the key for continuous",
|
||||
null,
|
||||
new ConfigurationManagerAttributes { })));
|
||||
|
||||
|
Reference in New Issue
Block a user