[PathCamDisabler] New input module changes.

This commit is contained in:
NotAKidoS 2023-05-17 12:51:24 -05:00
parent 9a36450d8f
commit ced3f26e8d
2 changed files with 44 additions and 25 deletions

View file

@ -0,0 +1,26 @@
using ABI_RC.Core.IO;
using ABI_RC.Systems.InputManagement.InputModules;
using HarmonyLib;
namespace NAK.PathCamDisabler.HarmonyPatches;
class CVRPathCamControllerPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(CVRPathCamController), nameof(CVRPathCamController.Start))]
private static void Postfix_CVRPathCamController_Start()
{
PathCamDisabler.OnUpdateSettings();
}
}
class CVRInputModule_KeyboardPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(CVRInputModule_Keyboard), nameof(CVRInputModule_Keyboard.Update_Binds))]
private static void Postfix_CVRInputModule_Keyboard_Update_Binds(ref CVRInputModule_Keyboard __instance)
{
if (PathCamDisabler.EntryDisableFlightBind.Value)
__instance._inputManager.toggleFlight = false;
}
}

View file

@ -1,49 +1,42 @@
using ABI_RC.Core.IO; using ABI_RC.Core.IO;
using ABI_RC.Core.Player;
using MelonLoader; using MelonLoader;
using UnityEngine;
namespace NAK.PathCamDisabler; namespace NAK.PathCamDisabler;
public class PathCamDisabler : MelonMod public class PathCamDisabler : MelonMod
{ {
public static readonly MelonPreferences_Category Category = public static readonly MelonPreferences_Category Category =
MelonPreferences.CreateCategory(nameof(PathCamDisabler)); MelonPreferences.CreateCategory(nameof(PathCamDisabler));
public static readonly MelonPreferences_Entry<bool> EntryDisablePathCam = public static readonly MelonPreferences_Entry<bool> EntryDisablePathCam =
Category.CreateEntry("Disable Path Camera Controller.", true, description: "Disable Path Camera Controller."); Category.CreateEntry("Disable Path Camera Controller", true, description: "Should the Pathing Camera Controller be disabled?");
public static readonly MelonPreferences_Entry<bool> EntryDisableFlightBind = public static readonly MelonPreferences_Entry<bool> EntryDisableFlightBind =
Category.CreateEntry("Disable Flight Binding (if controller off).", false, description: "Disable flight bind if Path Camera Controller is also disabled."); Category.CreateEntry("Disable Keyboard Flight Bind", true, description: "Should the Keyboard flight bind be disabled?");
public override void OnInitializeMelon() public override void OnInitializeMelon()
{ {
EntryDisablePathCam.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings); EntryDisablePathCam.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
ApplyPatches(typeof(HarmonyPatches.CVRPathCamControllerPatches));
MelonLoader.MelonCoroutines.Start(WaitForCVRPathCamController()); ApplyPatches(typeof(HarmonyPatches.CVRInputModule_KeyboardPatches));
} }
private System.Collections.IEnumerator WaitForCVRPathCamController() internal static void OnUpdateSettings(object arg1 = null, object arg2 = null)
{ {
while (CVRPathCamController.Instance == null) if (CVRPathCamController.Instance != null)
yield return null; CVRPathCamController.Instance.enabled = !EntryDisablePathCam.Value;
UpdateSettings();
} }
private void UpdateSettings() void ApplyPatches(Type type)
{ {
CVRPathCamController.Instance.enabled = !EntryDisablePathCam.Value; try
}
private void OnUpdateSettings(object arg1, object arg2) => UpdateSettings();
public override void OnUpdate()
{
if (EntryDisablePathCam.Value && !EntryDisableFlightBind.Value)
{ {
if (Input.GetKeyDown(KeyCode.Keypad5)) HarmonyInstance.PatchAll(type);
{ }
PlayerSetup.Instance._movementSystem.ToggleFlight(); catch (Exception e)
} {
LoggerInstance.Msg($"Failed while patching {type.Name}!");
LoggerInstance.Error(e);
} }
} }
} }