From 25969abef9d30b655e716a2928dba356976f0030 Mon Sep 17 00:00:00 2001 From: SDraw Date: Tue, 27 Dec 2022 23:18:35 +0300 Subject: [PATCH] Alternative collider scale --- README.md | 2 +- ml_amt/Main.cs | 68 +++++++++++++++++++++++++++++++ ml_amt/Properties/AssemblyInfo.cs | 6 +-- ml_amt/README.md | 3 +- ml_amt/Settings.cs | 18 +++++++- ml_amt/ml_amt.csproj | 5 +++ ml_amt/resources/menu.js | 7 ++++ 7 files changed, 103 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 72a6cb2..d20bc17 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Merged set of MelonLoader mods for ChilloutVR. | Full name | Short name | Latest version | Available in [CVRMA](https://github.com/knah/CVRMelonAssistant) | Current Status | Notes | |-----------|------------|----------------|-----------------------------------------------------------------|----------------|-------| | Avatar Change Info | ml_aci | 1.0.3 | Yes | Working | -| Avatar Motion Tweaker | ml_amt | 1.2.0 | Yes, pending review | Working | +| Avatar Motion Tweaker | ml_amt | 1.2.1 | Yes, pending review | Working | | Desktop Head Tracking | ml_dht | 1.1.1 | Yes | Working | | Desktop Reticle Switch | ml_drs | 1.0.0 | Yes | Working | | Four Point Tracking | ml_fpt | 1.0.9 | Retired | Deprecated | In-game feature since 2022r170 update diff --git a/ml_amt/Main.cs b/ml_amt/Main.cs index a1d5125..cabbf27 100644 --- a/ml_amt/Main.cs +++ b/ml_amt/Main.cs @@ -2,6 +2,8 @@ using ABI_RC.Core.Player; using ABI_RC.Systems.IK.SubSystems; using System.Reflection; +using ABI_RC.Systems.MovementSystem; +using UnityEngine; namespace ml_amt { @@ -59,6 +61,13 @@ namespace ml_amt ); } + // Alternative collider height + HarmonyInstance.Patch( + typeof(MovementSystem).GetMethod("UpdateCollider", BindingFlags.NonPublic | BindingFlags.Instance), + new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnUpdateCollider_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), + null + ); + MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer()); } @@ -149,5 +158,64 @@ namespace ml_amt return true; } + + // Alternative collider size + static bool OnUpdateCollider_Prefix( + ref MovementSystem __instance, + bool __0, // updateRadius + CharacterController ___controller, + float ____avatarHeight, + float ____avatarHeightFactor, + float ____minimumColliderRadius, + Vector3 ____colliderCenter + ) + { + if(!Settings.CollisionScale) + return true; + + try + { + if(___controller != null) + { + float l_scaledHeight = ____avatarHeight * ____avatarHeightFactor; + float l_newRadius = (__0 ? Mathf.Max(____minimumColliderRadius, l_scaledHeight / 6f) : ___controller.radius); + + float l_newHeight = Mathf.Max(l_scaledHeight, l_newRadius * 2f); + float l_currentHeight = ___controller.height; + + Vector3 l_newCenter = ____colliderCenter; + l_newCenter.y = (l_newHeight + 0.075f * ____avatarHeightFactor) * 0.5f; + Vector3 l_currentCenter = ___controller.center; + + if((Mathf.Abs(l_currentHeight - l_newHeight) > (l_currentHeight * 0.05f)) || (Vector3.Distance(l_currentCenter,l_newCenter) > (l_currentHeight * 0.05f))) + { + bool l_active = ___controller.enabled; + + if(__0) + ___controller.radius = l_newRadius; + ___controller.height = l_newHeight; + ___controller.center = l_newCenter; + + __instance.groundDistance = l_newRadius; + + if(__0) + __instance.proxyCollider.radius = l_newRadius; + __instance.proxyCollider.height = l_newHeight; + __instance.proxyCollider.center = new Vector3(0f, l_newCenter.y, 0f); + + __instance.forceObject.transform.localScale = new Vector3(l_newRadius + 0.1f, l_newHeight, l_newRadius + 0.1f); + __instance.groundCheck.localPosition = ____colliderCenter; + + ___controller.enabled = l_active; + } + } + } + catch(System.Exception l_exception) + { + MelonLoader.MelonLogger.Error(l_exception); + } + + return false; + } } } diff --git a/ml_amt/Properties/AssemblyInfo.cs b/ml_amt/Properties/AssemblyInfo.cs index 5577e72..85eefe4 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.0")] -[assembly: AssemblyFileVersion("1.2.0")] +[assembly: AssemblyVersion("1.2.1")] +[assembly: AssemblyFileVersion("1.2.1")] -[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.0", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] +[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.1", "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_amt/README.md b/ml_amt/README.md index b27fb3e..3f339b1 100644 --- a/ml_amt/README.md +++ b/ml_amt/README.md @@ -22,8 +22,9 @@ Available mod's settings in `Settings - IK - Avatar Motion Tweaker`: * **Pose transitions:** allows regular avatars animator to transit in crouch/prone states; default value - `true`. * Note: Avatar is considered as regular if its AAS animator doesn't have `Upright` parameter. * **Adjusted pose movement speed:** scales movement speed upon crouching/proning; default value - `true`. -* **Detect animations emote tag:** disables avatar's IK entirely if current animator state has `Emote` tag; default value - `true`; +* **Detect animations emote tag:** disables avatar's IK entirely if current animator state has `Emote` tag; default value - `true`. * Note: Created as example for [propoused game feature](https://feedback.abinteractive.net/p/disabling-vr-ik-for-emotes-via-animator-state-tag-7b80d963-053a-41c0-86ac-e3d53c61c1e2). +* **Alternative avatar collider scale:** applies slightly different approach to avatar collider size change; default value - `true` Available additional parameters for AAS animator: * **`Upright`:** defines linear coefficient between current viewpoint height and avatar's viewpoint height; float, range - [0.0, 1.0]. diff --git a/ml_amt/Settings.cs b/ml_amt/Settings.cs index 2048398..7eb0ea2 100644 --- a/ml_amt/Settings.cs +++ b/ml_amt/Settings.cs @@ -18,7 +18,8 @@ namespace ml_amt IKOverrideFly, IKOverrideJump, DetectEmotes, - FollowHips + FollowHips, + CollisionScale }; static bool ms_ikOverrideCrouch = true; @@ -31,6 +32,7 @@ namespace ml_amt static bool ms_ikOverrideJump = true; static bool ms_detectEmotes = true; static bool ms_followHips = true; + static bool ms_collisionScale = true; static MelonLoader.MelonPreferences_Category ms_category = null; static List ms_entries = null; @@ -45,6 +47,7 @@ namespace ml_amt static public event Action IKOverrideJumpChange; static public event Action DetectEmotesChange; static public event Action FollowHipsChange; + static public event Action CollisionScaleChange; public static void Init() { @@ -61,6 +64,7 @@ namespace ml_amt ms_entries.Add(ms_category.CreateEntry(ModSetting.IKOverrideJump.ToString(), true)); ms_entries.Add(ms_category.CreateEntry(ModSetting.DetectEmotes.ToString(), true)); ms_entries.Add(ms_category.CreateEntry(ModSetting.FollowHips.ToString(), true)); + ms_entries.Add(ms_category.CreateEntry(ModSetting.CollisionScale.ToString(), true)); Load(); @@ -101,6 +105,7 @@ namespace ml_amt ms_ikOverrideJump = (bool)ms_entries[(int)ModSetting.IKOverrideJump].BoxedValue; ms_detectEmotes = (bool)ms_entries[(int)ModSetting.DetectEmotes].BoxedValue; ms_followHips = (bool)ms_entries[(int)ModSetting.FollowHips].BoxedValue; + ms_collisionScale = (bool)ms_entries[(int)ModSetting.CollisionScale].BoxedValue; } static void OnSliderUpdate(string p_name, string p_value) @@ -189,6 +194,13 @@ namespace ml_amt FollowHipsChange?.Invoke(ms_followHips); } break; + + case ModSetting.CollisionScale: + { + ms_collisionScale = bool.Parse(p_value); + CollisionScaleChange?.Invoke(ms_collisionScale); + } + break; } ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value); @@ -235,5 +247,9 @@ namespace ml_amt { get => ms_followHips; } + public static bool CollisionScale + { + get => ms_collisionScale; + } } } diff --git a/ml_amt/ml_amt.csproj b/ml_amt/ml_amt.csproj index 7d2798e..83cb6a1 100644 --- a/ml_amt/ml_amt.csproj +++ b/ml_amt/ml_amt.csproj @@ -68,6 +68,11 @@ False + + False + D:\Games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll + False + diff --git a/ml_amt/resources/menu.js b/ml_amt/resources/menu.js index e2466f2..1b6ebaa 100644 --- a/ml_amt/resources/menu.js +++ b/ml_amt/resources/menu.js @@ -249,6 +249,13 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
+ +
+
Alternative avatar collider scale:
+
+
+
+
`; document.getElementById('settings-ik').appendChild(l_block);