mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
Remove collision scaling.
This commit is contained in:
parent
33d0714429
commit
2ada1263cc
3 changed files with 4 additions and 86 deletions
|
@ -1,96 +1,18 @@
|
|||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.Savior;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using cohtml;
|
||||
using HarmonyLib;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace MenuScalePatch;
|
||||
|
||||
public class MenuScalePatch : MelonMod
|
||||
{
|
||||
|
||||
private static MelonPreferences_Category m_categoryMenuScalePatch;
|
||||
private static MelonPreferences_Entry<bool> m_entryScaleCollision;
|
||||
private static MelonPreferences_Entry<bool> m_entrySkinWidthLimit;
|
||||
|
||||
private static float defaultSkinWidth = 0f;
|
||||
|
||||
public override void OnApplicationStart()
|
||||
{
|
||||
m_categoryMenuScalePatch = MelonPreferences.CreateCategory(nameof(MenuScalePatch));
|
||||
m_entryScaleCollision = m_categoryMenuScalePatch.CreateEntry<bool>("Scale Collision", false, description: "Should we scale player collision alongside avatar?");
|
||||
//m_entrySmallHeightLimit = m_categoryMenuScalePatch.CreateEntry<bool>("Small Height Limit", true, description: "Prevents avatar collision height from going below 0.3f. Disabling this can lead to errors if avatar is too small.");
|
||||
m_entrySkinWidthLimit = m_categoryMenuScalePatch.CreateEntry<bool>("No Skin Width", false, description: "Enabling this allows your feet to touch the ground properly, but may also make it easier for you to get stuck on collision.");
|
||||
|
||||
m_categoryMenuScalePatch.SaveToFile(false);
|
||||
m_entryScaleCollision.OnValueChangedUntyped += UpdateSettings;
|
||||
m_entrySkinWidthLimit.OnValueChangedUntyped += UpdateSettings;
|
||||
|
||||
UpdateSettings();
|
||||
}
|
||||
|
||||
private static void UpdateSettings()
|
||||
{
|
||||
HarmonyPatches._controllerScaleCollision = m_entryScaleCollision.Value;
|
||||
|
||||
if (!MovementSystem.Instance) return;
|
||||
|
||||
CharacterController controller = Traverse.Create(MovementSystem.Instance).Field("controller").GetValue() as CharacterController;
|
||||
|
||||
if (!m_entryScaleCollision.Value)
|
||||
{
|
||||
controller.skinWidth = defaultSkinWidth;
|
||||
MovementSystem.Instance.UpdateAvatarHeightFactor(1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
float _avatarHeight = Traverse.Create(PlayerSetup.Instance).Field("_avatarHeight").GetValue<float>();
|
||||
MovementSystem.Instance.UpdateAvatarHeightFactor(_avatarHeight);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
private class HarmonyPatches
|
||||
{
|
||||
|
||||
static public bool _controllerScaleCollision = false;
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(MovementSystem), "UpdateCollider")]
|
||||
private static void SetScale(ref float ____minimumColliderRadius, ref float ____avatarHeightFactor, ref CharacterController ___controller, ref float ___groundDistance, ref CapsuleCollider ___proxyCollider, ref GameObject ___forceObject, ref Transform ___groundCheck, ref Vector3 ____colliderCenter)
|
||||
{
|
||||
if (!_controllerScaleCollision) return;
|
||||
//avatar height = viewpoint height
|
||||
//heightfactor = viewpoint height * scale difference
|
||||
|
||||
//unity docs say to not put skinwidth too low, or you chance getting stuck often
|
||||
//but removing skinWidth allows your character to completely touch the floor
|
||||
|
||||
//grab the original skinWidth if it wasn't already logged
|
||||
if (defaultSkinWidth == 0f) defaultSkinWidth = ___controller.skinWidth;
|
||||
|
||||
float skinWidth = (m_entrySkinWidthLimit.Value ? 0.001f : defaultSkinWidth);
|
||||
//to prevent falling anims when smol- take skinWidth into maths
|
||||
___controller.skinWidth = skinWidth;
|
||||
___groundDistance = ___controller.radius + skinWidth;
|
||||
___groundCheck.localPosition = ____colliderCenter + Vector3.up * skinWidth;
|
||||
|
||||
//scale charactercontroller collision (take allow small player collider setting into account)
|
||||
___controller.height = Mathf.Max(____avatarHeightFactor, ____minimumColliderRadius);
|
||||
___controller.radius = Mathf.Max(____avatarHeightFactor / 6f, ____minimumColliderRadius);
|
||||
___controller.center = ____colliderCenter + Vector3.up * (___controller.height * 0.5f);
|
||||
|
||||
//match the proxy and force colliders to the scaled charactercontroller
|
||||
___proxyCollider.height = ___controller.height;
|
||||
___proxyCollider.radius = ___controller.radius;
|
||||
___proxyCollider.center = ___controller.center;
|
||||
___forceObject.transform.localScale = new Vector3(___controller.radius + 0.1f, ___controller.height, ___controller.radius + 0.1f);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(CVR_MenuManager), "SetScale")]
|
||||
private static void SetQMScale(ref CohtmlView ___quickMenu, ref float ____scaleFactor, float avatarHeight)
|
||||
|
@ -102,10 +24,6 @@ public class MenuScalePatch : MelonMod
|
|||
___quickMenu.transform.eulerAngles = new Vector3(rotationPivot.eulerAngles.x, rotationPivot.eulerAngles.y, rotationPivot.eulerAngles.z);
|
||||
___quickMenu.transform.position = rotationPivot.position + rotationPivot.forward * 1f * ____scaleFactor;
|
||||
}
|
||||
|
||||
//update avatar height while we are here
|
||||
if (!_controllerScaleCollision) return;
|
||||
MovementSystem.Instance.UpdateAvatarHeightFactor(avatarHeight);
|
||||
}
|
||||
|
||||
//ViewManager.SetScale runs once a second when it should only run when aspect ratio changes- CVR bug
|
||||
|
@ -136,4 +54,4 @@ public class MenuScalePatch : MelonMod
|
|||
___needsMenuPositionUpdate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,6 @@ using System.Reflection;
|
|||
namespace MenuScalePatch.Properties;
|
||||
internal static class AssemblyInfoParams
|
||||
{
|
||||
public const string Version = "1.1.1";
|
||||
public const string Version = "2.0.0";
|
||||
public const string Author = "NotAKidoS";
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
wa {
|
||||
"_id": 95,
|
||||
"name": "MenuScalePatch",
|
||||
"modversion": "1.1.1",
|
||||
|
@ -16,7 +16,7 @@
|
|||
"requirements": [
|
||||
"None"
|
||||
],
|
||||
"downloadlink": "https://github.com/NotAKidOnSteam/MenuScalePatch/releases/download/r3/MenuScalePatch.dll",
|
||||
"downloadlink": "https://github.com/NotAKidOnSteam/MenuScalePatch/releases/download/r4/MenuScalePatch.dll",
|
||||
"sourcelink": "https://github.com/NotAKidOnSteam/MenuScalePatch/",
|
||||
"changelog": "Fixed collision center. Collision no longer disconnects from avatar when moving roomscale.",
|
||||
"embedcolor": "804221"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue