From 0dae6999323ee491de1cd2b356530834d7f94db4 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Tue, 25 Apr 2023 19:11:26 -0500 Subject: [PATCH] added scale modifier ThirdPerson distance now uses avatar height as modifier, so you keep the same distance across avatars & while scaling. --- ThirdPerson/CameraLogic.cs | 12 +++++++----- ThirdPerson/Patches.cs | 12 +++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ThirdPerson/CameraLogic.cs b/ThirdPerson/CameraLogic.cs index 9cc3d3e..9643a79 100644 --- a/ThirdPerson/CameraLogic.cs +++ b/ThirdPerson/CameraLogic.cs @@ -14,6 +14,7 @@ namespace NAK.ThirdPerson; internal static class CameraLogic { private static float _dist; + private static float _scale = 1f; private static Camera _ourCam; private static Camera _desktopCam; private static CameraFovClone _cameraFovClone; @@ -64,7 +65,7 @@ internal static class CameraLogic ThirdPerson.Logger.Msg("Finished setting up third person camera."); } - internal static void CopyFromPlayerCam() + internal static void CopyPlayerCamValues() { Camera ourCamComponent = _ourCam.GetComponent(); Camera playerCamComponent = PlayerSetup.Instance.GetActiveCamera().GetComponent(); @@ -153,23 +154,23 @@ internal static class CameraLogic switch (location) { case CameraLocation.FrontView: - _ourCam.transform.localPosition = new Vector3(0, 0.015f, 0.55f - _dist); + _ourCam.transform.localPosition = new Vector3(0, 0.015f, 0.55f - _dist) * _scale; _ourCam.transform.localRotation = new Quaternion(0, 180, 0, 0); CurrentLocation = CameraLocation.FrontView; break; case CameraLocation.RightSide: - _ourCam.transform.localPosition = new Vector3(0.3f, 0.015f, -0.55f + _dist); + _ourCam.transform.localPosition = new Vector3(0.3f, 0.015f, -0.55f + _dist) * _scale; _ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0); CurrentLocation = CameraLocation.RightSide; break; case CameraLocation.LeftSide: - _ourCam.transform.localPosition = new Vector3(-0.3f, 0.015f, -0.55f + _dist); + _ourCam.transform.localPosition = new Vector3(-0.3f, 0.015f, -0.55f + _dist) * _scale; _ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0); CurrentLocation = CameraLocation.LeftSide; break; case CameraLocation.Default: default: - _ourCam.transform.localPosition = new Vector3(0, 0.015f, -0.55f + _dist); + _ourCam.transform.localPosition = new Vector3(0, 0.015f, -0.88f + _dist) * _scale; _ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0); CurrentLocation = CameraLocation.Default; break; @@ -179,4 +180,5 @@ internal static class CameraLogic private static void ResetDist() => _dist = 0; internal static void IncrementDist() { _dist += 0.25f; RelocateCam(CurrentLocation); } internal static void DecrementDist() { _dist -= 0.25f; RelocateCam(CurrentLocation); } + internal static void AdjustScale(float height) { _scale = height; RelocateCam(CurrentLocation); } } \ No newline at end of file diff --git a/ThirdPerson/Patches.cs b/ThirdPerson/Patches.cs index 1a66882..3a72a2d 100644 --- a/ThirdPerson/Patches.cs +++ b/ThirdPerson/Patches.cs @@ -1,4 +1,5 @@ using ABI.CCK.Components; +using ABI_RC.Core.Player; using MelonLoader; using System.Reflection; using static NAK.ThirdPerson.CameraLogic; @@ -10,15 +11,20 @@ internal static class Patches internal static void Apply(HarmonyLib.Harmony harmony) { harmony.Patch( - typeof(CVRWorld).GetMethod("SetDefaultCamValues", BindingFlags.NonPublic | BindingFlags.Instance), + typeof(CVRWorld).GetMethod(nameof(CVRWorld.SetDefaultCamValues), BindingFlags.NonPublic | BindingFlags.Instance), postfix: typeof(Patches).GetMethod(nameof(OnWorldStart), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod() ); harmony.Patch( - typeof(CVRWorld).GetMethod("CopyRefCamValues", BindingFlags.NonPublic | BindingFlags.Instance), + typeof(CVRWorld).GetMethod(nameof(CVRWorld.CopyRefCamValues), BindingFlags.NonPublic | BindingFlags.Instance), postfix: typeof(Patches).GetMethod(nameof(OnWorldStart), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod() ); + harmony.Patch( + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupIKScaling), BindingFlags.NonPublic | BindingFlags.Instance), + postfix: typeof(Patches).GetMethod(nameof(OnScaleAdjusted), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod() + ); } //Copy camera settings & postprocessing components - private static void OnWorldStart() => CopyFromPlayerCam(); + private static void OnWorldStart() => CopyPlayerCamValues(); + private static void OnScaleAdjusted(float height) => AdjustScale(height); } \ No newline at end of file