From 65896d5f1438c3f7d9500a7808d39e4137f6ecdc Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Wed, 28 Dec 2022 00:11:14 -0600 Subject: [PATCH] Added PlantFeet & EnforceViewPosition Settings. --- DesktopVRIK/DesktopVRIK.cs | 26 ++++++++++++++++++++++++-- DesktopVRIK/HarmonyPatches.cs | 19 +++++++++++++++++++ DesktopVRIK/Main.cs | 6 +++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/DesktopVRIK/DesktopVRIK.cs b/DesktopVRIK/DesktopVRIK.cs index 7e28795..06f66cc 100644 --- a/DesktopVRIK/DesktopVRIK.cs +++ b/DesktopVRIK/DesktopVRIK.cs @@ -15,20 +15,35 @@ public class DesktopVRIK : MonoBehaviour public bool Setting_Enabled; public bool Setting_EmulateVRChatHipMovement; + public bool Setting_EnforceViewPosition; public bool Setting_EmoteVRIK; public bool Setting_EmoteLookAtIK; + public bool Setting_PlantFeet; + + public Transform viewpoint; + public Vector3 initialCamPos; void Start() { Instance = this; } + public void ChangeViewpointHandling(bool enabled) + { + Setting_EnforceViewPosition = enabled; + if (enabled) + { + PlayerSetup.Instance.desktopCamera.transform.localPosition = Vector3.zero; + return; + } + PlayerSetup.Instance.desktopCamera.transform.localPosition = initialCamPos; + } + public void OnPreSolverUpdate() { //Reset avatar offset (VRIK will literally make you walk away from root otherwise) IKSystem.vrik.transform.localPosition = Vector3.zero; IKSystem.vrik.transform.localRotation = Quaternion.identity; - //VRChat hip movement emulation if (Setting_EmulateVRChatHipMovement) { @@ -38,6 +53,7 @@ public class DesktopVRIK : MonoBehaviour Quaternion rotation = Quaternion.AngleAxis(angle * weight, IKSystem.Instance.avatar.transform.right); IKSystem.vrik.solver.AddRotationOffset(IKSolverVR.RotationOffset.Head, rotation); } + IKSystem.vrik.solver.plantFeet = Setting_PlantFeet; } public void CalibrateDesktopVRIK(CVRAvatar avatar) @@ -63,8 +79,14 @@ public class DesktopVRIK : MonoBehaviour //ChilloutVR specific stuff + //Find eyeoffset + initialCamPos = PlayerSetup.Instance.desktopCamera.transform.localPosition; + Transform headTransform = IKSystem.Instance.animator.GetBoneTransform(HumanBodyBones.Head); + viewpoint = headTransform.Find("LocalHeadPoint"); + ChangeViewpointHandling(Setting_EnforceViewPosition); + //centerEyeAnchor now is head bone - Transform headAnchor = FindIKTarget(IKSystem.Instance.animator.GetBoneTransform(HumanBodyBones.Head)); + Transform headAnchor = FindIKTarget(headTransform); IKSystem.Instance.headAnchorPositionOffset = Vector3.zero; IKSystem.Instance.headAnchorRotationOffset = Vector3.zero; IKSystem.Instance.ApplyAvatarScaleToIk(avatar.viewPosition.y); diff --git a/DesktopVRIK/HarmonyPatches.cs b/DesktopVRIK/HarmonyPatches.cs index e2b05fc..fb2d796 100644 --- a/DesktopVRIK/HarmonyPatches.cs +++ b/DesktopVRIK/HarmonyPatches.cs @@ -3,6 +3,8 @@ using ABI_RC.Core.Player; using ABI_RC.Core.Savior; using ABI_RC.Systems.IK; using ABI_RC.Systems.IK.SubSystems; +using ABI_RC.Systems.MovementSystem; +using ABI_RC.Core.Player.AvatarTracking.Local; using HarmonyLib; using RootMotion.FinalIK; using UnityEngine; @@ -88,4 +90,21 @@ internal class HarmonyPatches } } } + + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerSetup), "HandleDesktopCameraPosition")] + private static void Postfix_PlayerSetup_HandleDesktopCameraPosition(bool ignore, ref PlayerSetup __instance, ref MovementSystem ____movementSystem, ref int ___headBobbingLevel) + { + if (DesktopVRIK.Instance.Setting_EnforceViewPosition) + { + if (!____movementSystem.disableCameraControl || ignore) + { + if (___headBobbingLevel == 2 && DesktopVRIK.Instance.viewpoint != null) + { + __instance.desktopCamera.transform.localPosition = Vector3.zero; + __instance.desktopCameraRig.transform.position = DesktopVRIK.Instance.viewpoint.position; + } + } + } + } } \ No newline at end of file diff --git a/DesktopVRIK/Main.cs b/DesktopVRIK/Main.cs index 539c7b8..ffed9c8 100644 --- a/DesktopVRIK/Main.cs +++ b/DesktopVRIK/Main.cs @@ -7,14 +7,16 @@ public class DesktopVRIKMod : MelonMod { internal const string SettingsCategory = "DesktopVRIK"; private static MelonPreferences_Category m_categoryDesktopVRIK; - private static MelonPreferences_Entry m_entryEnabled, m_entryEmulateHipMovement, m_entryEmoteVRIK, m_entryEmoteLookAtIK; + private static MelonPreferences_Entry m_entryEnabled, m_entryEmulateHipMovement, m_entryEnforceViewPosition, m_entryEmoteVRIK, m_entryEmoteLookAtIK, m_entryPlantFeet; public override void OnInitializeMelon() { m_categoryDesktopVRIK = MelonPreferences.CreateCategory(SettingsCategory); m_entryEnabled = m_categoryDesktopVRIK.CreateEntry("Enabled", true, description: "Attempt to give Desktop VRIK on avatar load."); m_entryEmulateHipMovement = m_categoryDesktopVRIK.CreateEntry("Emulate Hip Movement", true, description: "Emulates VRChat-like hip movement when moving head up/down on desktop."); + m_entryEnforceViewPosition = m_categoryDesktopVRIK.CreateEntry("Enforce View Position", false, description: "Corrects view position to use VRIK offsets."); m_entryEmoteVRIK = m_categoryDesktopVRIK.CreateEntry("Disable Emote VRIK", true, description: "Disable VRIK while emoting. Only disable if you are ok with looking dumb."); m_entryEmoteLookAtIK = m_categoryDesktopVRIK.CreateEntry("Disable Emote LookAtIK", true, description: "Disable LookAtIK while emoting. This setting doesn't really matter, as LookAtIK isn't networked while doing an emote."); + m_entryPlantFeet = m_categoryDesktopVRIK.CreateEntry("Plant Feet", true, description: "Enables Plant Feet for VRIK while in Desktop. Keeps avatar on ground when entering Idle instead of hovering."); foreach (var setting in m_categoryDesktopVRIK.Entries) { @@ -41,6 +43,8 @@ public class DesktopVRIKMod : MelonMod DesktopVRIK.Instance.Setting_EmulateVRChatHipMovement = m_entryEmulateHipMovement.Value; DesktopVRIK.Instance.Setting_EmoteVRIK = m_entryEmoteVRIK.Value; DesktopVRIK.Instance.Setting_EmoteLookAtIK = m_entryEmoteLookAtIK.Value; + DesktopVRIK.Instance.Setting_PlantFeet = m_entryPlantFeet.Value; + DesktopVRIK.Instance.ChangeViewpointHandling(m_entryEnforceViewPosition.Value); } private void OnUpdateSettings(object arg1, object arg2) => UpdateAllSettings();