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