From 699d7bdd5fc8032af37a505f979bfeab8139a0ef Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Mon, 1 May 2023 23:24:13 -0500 Subject: [PATCH] [PRM] Avatar Scaling Support --- ml_prm/Main.cs | 19 +++++++++++++++++++ ml_prm/RagdollController.cs | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/ml_prm/Main.cs b/ml_prm/Main.cs index 0ab7447..24cb968 100644 --- a/ml_prm/Main.cs +++ b/ml_prm/Main.cs @@ -36,6 +36,11 @@ namespace ml_prm null, new HarmonyLib.HarmonyMethod(typeof(PlayerRagdollMod).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); + HarmonyInstance.Patch( + typeof(PlayerSetup).GetMethod("SetupIKScaling", BindingFlags.NonPublic | BindingFlags.Instance), + null, + new HarmonyLib.HarmonyMethod(typeof(PlayerRagdollMod).GetMethod(nameof(OnSetupIKScaling_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) + ); HarmonyInstance.Patch( typeof(CVRSeat).GetMethod(nameof(CVRSeat.SitDown)), new HarmonyLib.HarmonyMethod(typeof(PlayerRagdollMod).GetMethod(nameof(OnCVRSeatSitDown_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), @@ -120,6 +125,20 @@ namespace ml_prm } } + static void OnSetupIKScaling_Postfix(ref UnityEngine.Vector3 ___scaleDifference) => ms_instance?.OnSetupIKScaling(___scaleDifference.y); + void OnSetupIKScaling(float scaleDifference) + { + try + { + if (m_localController != null) + m_localController.OnAvatarScaling(1f + scaleDifference); + } + catch (Exception e) + { + MelonLoader.MelonLogger.Error(e); + } + } + static void OnCVRSeatSitDown_Prefix(ref CVRSeat __instance) => ms_instance?.OnCVRSeatSitDown(__instance); void OnCVRSeatSitDown(CVRSeat p_seat) { diff --git a/ml_prm/RagdollController.cs b/ml_prm/RagdollController.cs index 3dfa59f..7091657 100644 --- a/ml_prm/RagdollController.cs +++ b/ml_prm/RagdollController.cs @@ -28,6 +28,7 @@ namespace ml_prm Transform m_puppet = null; BipedRagdollReferences m_puppetReferences; readonly List> m_boneLinks = null; + readonly List> m_jointAnchors = null; bool m_avatarReady = false; Vector3 m_lastPosition = Vector3.zero; @@ -50,6 +51,7 @@ namespace ml_prm m_rigidBodies = new List(); m_colliders = new List(); m_boneLinks = new List>(); + m_jointAnchors = new List>(); m_physicsMaterial = new PhysicMaterial("Ragdoll"); m_physicsMaterial.dynamicFriction = 0.5f; @@ -172,8 +174,10 @@ namespace ml_prm m_colliders.Clear(); m_puppetReferences = new BipedRagdollReferences(); m_boneLinks.Clear(); + m_jointAnchors.Clear(); m_reachedGround = true; m_downTime = float.MinValue; + m_puppetRoot.localScale = Vector3.one; } internal void OnAvatarSetup() @@ -244,6 +248,7 @@ namespace ml_prm { l_joint.enablePreprocessing = false; l_joint.enableProjection = true; + m_jointAnchors.Add(System.Tuple.Create(l_joint, l_joint.connectedAnchor)); } Collider l_collider = l_puppetTransforms[i].GetComponent(); @@ -282,6 +287,18 @@ namespace ml_prm } } + internal void OnAvatarScaling(float scaleDifference) + { + if(m_avatarReady) + { + m_puppetRoot.localScale = Vector3.one * scaleDifference; + for(int i = 0; i < m_jointAnchors.Count; i++) + { + m_jointAnchors[i].Item1.connectedAnchor = m_jointAnchors[i].Item2 * scaleDifference; + } + } + } + internal void OnSeatSitDown(CVRSeat p_seat) { if(m_avatarReady && m_enabled && !p_seat.occupied)