Skip to content

Commit

Permalink
Alternative collider scale
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Dec 27, 2022
1 parent 027e6c2 commit 25969ab
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 68 additions & 0 deletions ml_amt/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -59,6 +61,13 @@ public override void OnInitializeMelon()
);
}

// 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());
}

Expand Down Expand Up @@ -149,5 +158,64 @@ static bool OnFBTAvailable_Prefix(ref bool __result)

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;
}
}
}
6 changes: 3 additions & 3 deletions ml_amt/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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)]
3 changes: 2 additions & 1 deletion ml_amt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
18 changes: 17 additions & 1 deletion ml_amt/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ enum ModSetting
IKOverrideFly,
IKOverrideJump,
DetectEmotes,
FollowHips
FollowHips,
CollisionScale
};

static bool ms_ikOverrideCrouch = true;
Expand All @@ -31,6 +32,7 @@ enum ModSetting
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<MelonLoader.MelonPreferences_Entry> ms_entries = null;
Expand All @@ -45,6 +47,7 @@ enum ModSetting
static public event Action<bool> IKOverrideJumpChange;
static public event Action<bool> DetectEmotesChange;
static public event Action<bool> FollowHipsChange;
static public event Action<bool> CollisionScaleChange;

public static void Init()
{
Expand All @@ -61,6 +64,7 @@ public static void Init()
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();

Expand Down Expand Up @@ -101,6 +105,7 @@ static void Load()
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)
Expand Down Expand Up @@ -189,6 +194,13 @@ static void OnToggleUpdate(string p_name, string p_value)
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);
Expand Down Expand Up @@ -235,5 +247,9 @@ public static bool FollowHips
{
get => ms_followHips;
}
public static bool CollisionScale
{
get => ms_collisionScale;
}
}
}
5 changes: 5 additions & 0 deletions ml_amt/ml_amt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
<Reference Include="UnityEngine.CoreModule">
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>D:\Games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MotionTweaker.cs" />
Expand Down
7 changes: 7 additions & 0 deletions ml_amt/resources/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
<div id="DetectEmotes" class ="inp_toggle no-scroll" data-current="true"></div>
</div>
</div>
<div class ="row-wrapper">
<div class ="option-caption">Alternative avatar collider scale: </div>
<div class ="option-input">
<div id="CollisionScale" class ="inp_toggle no-scroll" data-current="true"></div>
</div>
</div>
`;
document.getElementById('settings-ik').appendChild(l_block);

Expand Down

0 comments on commit 25969ab

Please sign in to comment.