From 2d6c4a3fc5d92259d81f34acb4545b63f2186408 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 28 Jul 2023 23:13:14 -0500 Subject: [PATCH] [PathCamDisabler] Fixes for 2023r171 --- PathCamDisabler/HarmonyPatches.cs | 26 ++++++++++++ PathCamDisabler/Main.cs | 47 ++++++++-------------- PathCamDisabler/Properties/AssemblyInfo.cs | 5 ++- PathCamDisabler/format.json | 8 ++-- 4 files changed, 50 insertions(+), 36 deletions(-) create mode 100644 PathCamDisabler/HarmonyPatches.cs diff --git a/PathCamDisabler/HarmonyPatches.cs b/PathCamDisabler/HarmonyPatches.cs new file mode 100644 index 0000000..f783500 --- /dev/null +++ b/PathCamDisabler/HarmonyPatches.cs @@ -0,0 +1,26 @@ +using ABI_RC.Core.IO; +using ABI_RC.Systems.InputManagement.InputModules; +using HarmonyLib; + +namespace NAK.PathCamDisabler.HarmonyPatches; + +internal class CVRPathCamControllerPatches +{ + [HarmonyPrefix] + [HarmonyPatch(typeof(CVRPathCamController), nameof(CVRPathCamController.Update))] + private static void Prefix_CVRPathCamController_Update(ref bool __runOriginal) + { + __runOriginal &= !PathCamDisabler.EntryDisablePathCam.Value; + } +} + +internal 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; + } +} \ No newline at end of file diff --git a/PathCamDisabler/Main.cs b/PathCamDisabler/Main.cs index 8f335d5..83cfe88 100644 --- a/PathCamDisabler/Main.cs +++ b/PathCamDisabler/Main.cs @@ -1,49 +1,34 @@ -using ABI_RC.Core.IO; -using ABI_RC.Core.Player; -using MelonLoader; -using UnityEngine; +using MelonLoader; 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 EntryDisablePathCam = - Category.CreateEntry("Disable Path Camera Controller.", true, description: "Disable Path Camera Controller."); + public static readonly MelonPreferences_Entry EntryDisablePathCam = + Category.CreateEntry("Disable Path Camera Controller", true, description: "Disable Path Camera Controller."); - public static readonly MelonPreferences_Entry 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 EntryDisableFlightBind = + Category.CreateEntry("Disable Flight Binding", false, description: "Disable flight bind if Path Camera Controller is also 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() + private void ApplyPatches(Type type) { - while (CVRPathCamController.Instance == null) - yield return null; - UpdateSettings(); - } - - private void UpdateSettings() - { - 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); } } } \ No newline at end of file diff --git a/PathCamDisabler/Properties/AssemblyInfo.cs b/PathCamDisabler/Properties/AssemblyInfo.cs index eafd29e..a25ee50 100644 --- a/PathCamDisabler/Properties/AssemblyInfo.cs +++ b/PathCamDisabler/Properties/AssemblyInfo.cs @@ -20,10 +20,13 @@ using System.Reflection; [assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] [assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: MelonColor(255, 155, 89, 182)] +[assembly: MelonAuthorColor(255, 158, 21, 32)] +[assembly: HarmonyDontPatchAll] namespace NAK.PathCamDisabler.Properties; internal static class AssemblyInfoParams { - public const string Version = "1.0.1"; + public const string Version = "1.0.2"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/PathCamDisabler/format.json b/PathCamDisabler/format.json index cd30365..dab937a 100644 --- a/PathCamDisabler/format.json +++ b/PathCamDisabler/format.json @@ -1,8 +1,8 @@ { "_id": 110, "name": "PathCamDisabler", - "modversion": "1.0.1", - "gameversion": "2022r170p1", + "modversion": "1.0.2", + "gameversion": "2023r171", "loaderversion": "0.6.1", "modtype": "Mod", "author": "NotAKidoS", @@ -16,8 +16,8 @@ "requirements": [ "None" ], - "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r3/PathCamDisabler.dll", + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r16/PathCamDisabler.dll", "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/PathCamDisabler/", - "changelog": "- Organizational changes.\n- No longer using SaveToFile().", + "changelog": "- Fixes for 2023r171.", "embedcolor": "#9b59b6" } \ No newline at end of file