diff --git a/README.md b/README.md index 546217e..5bdaa68 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,5 @@ Merged set of MelonLoader mods for ChilloutVR. | Extended Game Notifications | ml_egn | 1.0.0 | On review | Working | Four Point Tracking | ml_fpt | 1.0.9 | Retired | Deprecated | In-game feature since 2022r170 update | Leap Motion Extension | ml_lme | 1.2.9 | Yes | Working | +| Pickup Arm Movement | ml_pam | 1.0.0 | On review | Working | Server Connection Info | ml_sci | 1.0.2 | Yes | Working | Will be superseded by `Extended Game Notifications` diff --git a/ml_amt/MotionTweaker.cs b/ml_amt/MotionTweaker.cs index 497694f..1e7e4c2 100644 --- a/ml_amt/MotionTweaker.cs +++ b/ml_amt/MotionTweaker.cs @@ -28,6 +28,7 @@ namespace ml_amt int m_locomotionLayer = 0; float m_ikWeight = 1f; // Original weight float m_locomotionWeight = 1f; // Original weight + bool m_plantFeet = false; // Original plant feet float m_avatarScale = 1f; // Instantiated scale Transform m_avatarHips = null; float m_viewPointHeight = 1f; @@ -258,6 +259,7 @@ namespace ml_amt m_ikWeight = m_vrIk.solver.IKPositionWeight; m_locomotionWeight = m_vrIk.solver.locomotion.weight; + m_plantFeet = m_vrIk.solver.plantFeet; if(m_detectEmotes && m_emoteActive) m_vrIk.solver.IKPositionWeight = 0f; @@ -283,6 +285,7 @@ namespace ml_amt if(l_legsOverride && l_solverActive && m_followHips && (!m_moving || (m_poseState == PoseState.Proning)) && m_isInVR && !BodySystem.isCalibratedAsFullBody) { + m_vrIk.solver.plantFeet = false; ABI_RC.Systems.IK.IKSystem.VrikRootController.enabled = false; PlayerSetup.Instance._avatar.transform.localPosition = m_hipsToPlayer; } @@ -292,6 +295,7 @@ namespace ml_amt { m_vrIk.solver.IKPositionWeight = m_ikWeight; m_vrIk.solver.locomotion.weight = m_locomotionWeight; + m_vrIk.solver.plantFeet = m_plantFeet; } public void SetIKOverrideCrouch(bool p_state) diff --git a/ml_amt/Properties/AssemblyInfo.cs b/ml_amt/Properties/AssemblyInfo.cs index 85eefe4..b79799e 100644 --- a/ml_amt/Properties/AssemblyInfo.cs +++ b/ml_amt/Properties/AssemblyInfo.cs @@ -1,10 +1,10 @@ using System.Reflection; [assembly: AssemblyTitle("AvatarMotionTweaker")] -[assembly: AssemblyVersion("1.2.1")] -[assembly: AssemblyFileVersion("1.2.1")] +[assembly: AssemblyVersion("1.2.2")] +[assembly: AssemblyFileVersion("1.2.2")] -[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.1", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] +[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.2", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)] \ No newline at end of file diff --git a/ml_mods_cvr.sln b/ml_mods_cvr.sln index 2a6635d..d9193c5 100644 --- a/ml_mods_cvr.sln +++ b/ml_mods_cvr.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ml_dht", "ml_dht\ml_dht.csp EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ml_egn", "ml_egn\ml_egn.csproj", "{1B5ACA07-6266-4C9A-BA30-D4BBE6634846}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ml_pam", "ml_pam\ml_pam.csproj", "{3B5028DE-8C79-40DF-A1EF-BDB29D366125}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -39,6 +41,10 @@ Global {1B5ACA07-6266-4C9A-BA30-D4BBE6634846}.Debug|x64.Build.0 = Debug|x64 {1B5ACA07-6266-4C9A-BA30-D4BBE6634846}.Release|x64.ActiveCfg = Release|x64 {1B5ACA07-6266-4C9A-BA30-D4BBE6634846}.Release|x64.Build.0 = Release|x64 + {3B5028DE-8C79-40DF-A1EF-BDB29D366125}.Debug|x64.ActiveCfg = Debug|x64 + {3B5028DE-8C79-40DF-A1EF-BDB29D366125}.Debug|x64.Build.0 = Debug|x64 + {3B5028DE-8C79-40DF-A1EF-BDB29D366125}.Release|x64.ActiveCfg = Release|x64 + {3B5028DE-8C79-40DF-A1EF-BDB29D366125}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ml_pam/ArmMover.cs b/ml_pam/ArmMover.cs new file mode 100644 index 0000000..4ce512f --- /dev/null +++ b/ml_pam/ArmMover.cs @@ -0,0 +1,59 @@ +using ABI.CCK.Components; +using ABI_RC.Core.Player; +using UnityEngine; + +namespace ml_pam +{ + class ArmMover : MonoBehaviour + { + static readonly Vector4 ms_pointVector = new Vector4(0f, 0f, 0f, 1f); + static readonly Quaternion ms_rotationOffset = Quaternion.Euler(0f, 0f, -90f); + + Animator m_animator = null; + CVRPickupObject m_target = null; + Matrix4x4 m_offset = Matrix4x4.identity; + + void Start() + { + m_animator = PlayerSetup.Instance._animator; + } + + void OnAnimatorIK(int p_layerIndex) + { + if((p_layerIndex == 0) && (m_target != null)) // Only main Locomotion/Emotes layer + { + Transform l_camera = PlayerSetup.Instance.GetActiveCamera().transform; + + m_animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1f); + m_animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1f); + + switch(m_target.gripType) + { + case CVRPickupObject.GripType.Origin: + { + if(m_target.gripOrigin != null) + { + m_animator.SetIKPosition(AvatarIKGoal.RightHand, m_target.gripOrigin.position); + m_animator.SetIKRotation(AvatarIKGoal.RightHand, l_camera.rotation * ms_rotationOffset); + } + } + break; + + case CVRPickupObject.GripType.Free: + { + Matrix4x4 l_result = m_target.transform.GetMatrix() * m_offset; + m_animator.SetIKPosition(AvatarIKGoal.RightHand, l_result * ms_pointVector); + m_animator.SetIKRotation(AvatarIKGoal.RightHand, l_camera.rotation * ms_rotationOffset); + } + break; + } + } + } + + public void SetTarget(CVRPickupObject p_target, Vector3 p_hit) + { + m_target = p_target; + m_offset = (m_target != null) ? (p_target.transform.GetMatrix().inverse * Matrix4x4.Translate(p_hit)): Matrix4x4.identity; + } + } +} diff --git a/ml_pam/Main.cs b/ml_pam/Main.cs new file mode 100644 index 0000000..3f808c9 --- /dev/null +++ b/ml_pam/Main.cs @@ -0,0 +1,107 @@ +using ABI.CCK.Components; +using ABI_RC.Core.Player; +using System; +using System.Reflection; +using UnityEngine; + +namespace ml_pam +{ + public class PickupArmMovement : MelonLoader.MelonMod + { + static PickupArmMovement ms_instance = null; + + ArmMover m_localPuller = null; + + public override void OnInitializeMelon() + { + if(ms_instance == null) + ms_instance = this; + + HarmonyInstance.Patch( + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)), + null, + new HarmonyLib.HarmonyMethod(typeof(PickupArmMovement).GetMethod(nameof(OnAvatarClear_Postfix), BindingFlags.NonPublic | BindingFlags.Static)) + ); + HarmonyInstance.Patch( + typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)), + null, + new HarmonyLib.HarmonyMethod(typeof(PickupArmMovement).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) + ); + HarmonyInstance.Patch( + typeof(CVRPickupObject).GetMethod(nameof(CVRPickupObject.Grab)), + null, + new HarmonyLib.HarmonyMethod(typeof(PickupArmMovement).GetMethod(nameof(OnCVRPickupObjectGrab_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) + ); + HarmonyInstance.Patch( + typeof(CVRPickupObject).GetMethod(nameof(CVRPickupObject.Drop)), + null, + new HarmonyLib.HarmonyMethod(typeof(PickupArmMovement).GetMethod(nameof(OnCVRPickupObjectDrop_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) + ); + } + + public override void OnDeinitializeMelon() + { + if(ms_instance == this) + ms_instance = null; + } + + static void OnAvatarClear_Postfix() => ms_instance?.OnAvatarClear(); + void OnAvatarClear() + { + try + { + m_localPuller = null; + } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } + } + + static void OnSetupAvatar_Postfix() => ms_instance?.OnSetupAvatar(); + void OnSetupAvatar() + { + try + { + if(!Utils.IsInVR()) + m_localPuller = PlayerSetup.Instance._avatar.AddComponent(); + } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } + } + + static void OnCVRPickupObjectGrab_Postfix(ref CVRPickupObject __instance, Vector3 __2) => ms_instance?.OnCVRPickupObjectGrab(__instance, __2); + void OnCVRPickupObjectGrab(CVRPickupObject p_pickup, Vector3 p_hit) + { + try + { + if(p_pickup.IsGrabbedByMe() && (m_localPuller != null)) + { + m_localPuller.SetTarget(p_pickup, p_hit); + } + } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } + } + + static void OnCVRPickupObjectDrop_Postfix() => ms_instance?.OnCVRPickupObjectDrop(); + void OnCVRPickupObjectDrop() + { + try + { + if(m_localPuller != null) + { + m_localPuller.SetTarget(null, Vector3.zero); + } + } + catch(Exception e) + { + MelonLoader.MelonLogger.Error(e); + } + } + } +} diff --git a/ml_pam/Properties/AssemblyInfo.cs b/ml_pam/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a0e0b87 --- /dev/null +++ b/ml_pam/Properties/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Reflection; + +[assembly: AssemblyTitle("PickupArmMovement")] +[assembly: AssemblyVersion("1.0.0")] +[assembly: AssemblyFileVersion("1.0.0")] + +[assembly: MelonLoader.MelonInfo(typeof(ml_pam.PickupArmMovement), "PickupArmMovement", "1.0.0", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] +[assembly: MelonLoader.MelonGame(null, "ChilloutVR")] +[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)] \ No newline at end of file diff --git a/ml_pam/README.md b/ml_pam/README.md new file mode 100644 index 0000000..dceb34e --- /dev/null +++ b/ml_pam/README.md @@ -0,0 +1,7 @@ +# Pickup Arm Movement +This mod adds arm tracking upon holding pickup. + +# Installation +* Install [latest MelonLoader](https://github.com/LavaGang/MelonLoader) +* Get [latest release DLL](../../../releases/latest): + * Put `ml_pam.dll` in `Mods` folder of game diff --git a/ml_pam/Utils.cs b/ml_pam/Utils.cs new file mode 100644 index 0000000..b11b808 --- /dev/null +++ b/ml_pam/Utils.cs @@ -0,0 +1,15 @@ +using UnityEngine; + +namespace ml_pam +{ + static class Utils + { + public static bool IsInVR() => ((ABI_RC.Core.Savior.CheckVR.Instance != null) && ABI_RC.Core.Savior.CheckVR.Instance.hasVrDeviceLoaded); + + // Extensions + public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false) + { + return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.localScale : Vector3.one); + } + } +} diff --git a/ml_pam/ml_pam.csproj b/ml_pam/ml_pam.csproj new file mode 100644 index 0000000..23e1b5b --- /dev/null +++ b/ml_pam/ml_pam.csproj @@ -0,0 +1,75 @@ + + + + + Debug + AnyCPU + {3B5028DE-8C79-40DF-A1EF-BDB29D366125} + Library + Properties + ml_pam + ml_pam + v4.7.2 + 512 + true + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + + + + False + D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll + False + + + False + D:\Games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll + False + + + False + D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll + False + + + + + + + + + + False + + + False + False + + + + + + + + + + + copy /y "$(TargetPath)" "D:\Games\Steam\steamapps\common\ChilloutVR\Mods\" + + \ No newline at end of file diff --git a/ml_pam/ml_pam.csproj.user b/ml_pam/ml_pam.csproj.user new file mode 100644 index 0000000..04df561 --- /dev/null +++ b/ml_pam/ml_pam.csproj.user @@ -0,0 +1,6 @@ + + + + D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\;D:\Games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\ + + \ No newline at end of file