From c32d8735be5c60eb519f86120024241265e26fa2 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Tue, 13 Jun 2023 14:33:17 -0500 Subject: [PATCH] [DesktopCameraFix] Update viewpoint when disabling mod. --- DesktopCameraFix/HarmonyPatches.cs | 14 +------------- DesktopCameraFix/Main.cs | 13 ++++++++----- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/DesktopCameraFix/HarmonyPatches.cs b/DesktopCameraFix/HarmonyPatches.cs index a56c32d..9d4d0c8 100644 --- a/DesktopCameraFix/HarmonyPatches.cs +++ b/DesktopCameraFix/HarmonyPatches.cs @@ -14,6 +14,7 @@ class PlayerSetupPatches if (!DesktopCameraFix.EntryEnabled.Value) return; + // this would be much simplier if I bothered with transpilers if (____movementSystem.disableCameraControl && !ignore) return; @@ -25,18 +26,5 @@ class PlayerSetupPatches { __instance.desktopCamera.transform.position = viewpointTransform.position; } - - /** - desktopCameraRig -> desktopCamera - desktopCameraRig is parent of desktopCamera. - - desktopCamera rotates, so it pivots in place. - desktopCameraRig is moved to head bone, local position of camera is viewpoint offset when standing - - if rig was moving position & rotation, this would work - but because rig handles position and camera handles rotation, camera pivots in place instead of at correct point - which is gross - - **/ } } diff --git a/DesktopCameraFix/Main.cs b/DesktopCameraFix/Main.cs index 427b901..172ec03 100644 --- a/DesktopCameraFix/Main.cs +++ b/DesktopCameraFix/Main.cs @@ -1,24 +1,27 @@ -using ABI_RC.Core.IO; +using ABI_RC.Core.Player; using MelonLoader; -using UnityEngine; namespace NAK.DesktopCameraFix; public class DesktopCameraFix : MelonMod { - internal const string SettingsCategory = nameof(DesktopCameraFix); - public static readonly MelonPreferences_Category Category = - MelonPreferences.CreateCategory(SettingsCategory); + MelonPreferences.CreateCategory(nameof(DesktopCameraFix)); public static readonly MelonPreferences_Entry EntryEnabled = Category.CreateEntry("Enabled", true, description: "Toggle DesktopCameraFix entirely."); public override void OnInitializeMelon() { + EntryEnabled.OnEntryValueChanged.Subscribe(OnEntryEnabledChanged); ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches)); } + void OnEntryEnabledChanged(bool newValue, bool oldValue) + { + if (newValue) PlayerSetup.Instance.SetViewPointOffset(); + } + void ApplyPatches(Type type) { try