mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 18:39:23 +00:00
Drag, angular drag and gravity settings
This commit is contained in:
parent
78ca550e64
commit
f08adb8f53
4 changed files with 113 additions and 24 deletions
|
@ -1,8 +1,8 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using ABI_RC.Core.InteractionSystem;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_prm
|
||||
{
|
||||
|
@ -34,6 +34,11 @@ namespace ml_prm
|
|||
new HarmonyLib.HarmonyMethod(typeof(PlayerRagdollMod).GetMethod(nameof(OnCVRSeatSitDown_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
null
|
||||
);
|
||||
HarmonyInstance.Patch(
|
||||
typeof(BodySystem).GetMethod(nameof(BodySystem.StartCalibration)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(PlayerRagdollMod).GetMethod(nameof(OnStartCalibration_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
null
|
||||
);
|
||||
|
||||
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
|
||||
}
|
||||
|
@ -42,6 +47,8 @@ namespace ml_prm
|
|||
{
|
||||
if(ms_instance == this)
|
||||
ms_instance = null;
|
||||
|
||||
m_localController = null;
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator WaitForLocalPlayer()
|
||||
|
@ -94,5 +101,19 @@ namespace ml_prm
|
|||
}
|
||||
}
|
||||
|
||||
static void OnStartCalibration_Prefix() => ms_instance?.OnStartCalibration();
|
||||
void OnStartCalibration()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(m_localController != null)
|
||||
m_localController.OnStartCalibration();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using RootMotion.Dynamics;
|
||||
using RootMotion.FinalIK;
|
||||
|
@ -43,11 +44,17 @@ namespace ml_prm
|
|||
m_puppetRoot.localRotation = Quaternion.identity;
|
||||
|
||||
Settings.SwitchChange += this.SwitchRagdoll;
|
||||
Settings.MovementDragChange += this.OnMovementDragChange;
|
||||
Settings.AngularDragChange += this.OnAngularDragChange;
|
||||
Settings.GravityChange += this.OnGravityChange;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Settings.SwitchChange -= this.SwitchRagdoll;
|
||||
Settings.MovementDragChange -= this.OnMovementDragChange;
|
||||
Settings.AngularDragChange -= this.OnAngularDragChange;
|
||||
Settings.GravityChange -= this.OnGravityChange;
|
||||
}
|
||||
|
||||
void Update()
|
||||
|
@ -140,8 +147,9 @@ namespace ml_prm
|
|||
{
|
||||
m_rigidBodies.Add(l_body);
|
||||
l_body.isKinematic = true;
|
||||
l_body.angularDrag = 0.5f;
|
||||
l_body.drag = 1.0f;
|
||||
l_body.angularDrag = Settings.AngularDrag;
|
||||
l_body.drag = Settings.MovementDrag;
|
||||
l_body.useGravity = Settings.Gravity;
|
||||
l_body.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
|
||||
}
|
||||
|
||||
|
@ -182,6 +190,12 @@ namespace ml_prm
|
|||
SwitchRagdoll();
|
||||
}
|
||||
|
||||
internal void OnStartCalibration()
|
||||
{
|
||||
if(m_enabled && m_avatarReady)
|
||||
SwitchRagdoll();
|
||||
}
|
||||
|
||||
// IK updates
|
||||
void OnIKPreUpdate()
|
||||
{
|
||||
|
@ -197,10 +211,36 @@ namespace ml_prm
|
|||
m_vrIK.solver.IKPositionWeight = m_vrIkWeight;
|
||||
}
|
||||
|
||||
// Settings
|
||||
void OnMovementDragChange(float p_value)
|
||||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
foreach(Rigidbody l_body in m_rigidBodies)
|
||||
l_body.drag = p_value;
|
||||
}
|
||||
}
|
||||
void OnAngularDragChange(float p_value)
|
||||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
foreach(Rigidbody l_body in m_rigidBodies)
|
||||
l_body.angularDrag = p_value;
|
||||
}
|
||||
}
|
||||
void OnGravityChange(bool p_state)
|
||||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
foreach(Rigidbody l_body in m_rigidBodies)
|
||||
l_body.useGravity = p_state;
|
||||
}
|
||||
}
|
||||
|
||||
// Arbitrary
|
||||
public void SwitchRagdoll()
|
||||
{
|
||||
if(m_avatarReady && (MovementSystem.Instance.lastSeat == null))
|
||||
if(m_avatarReady && (MovementSystem.Instance.lastSeat == null) && !BodySystem.isCalibrating)
|
||||
{
|
||||
m_enabled = !m_enabled;
|
||||
|
||||
|
@ -214,7 +254,7 @@ namespace ml_prm
|
|||
foreach(Rigidbody l_body in m_rigidBodies)
|
||||
l_body.isKinematic = false;
|
||||
|
||||
Vector3 l_velocity = m_velocity * Settings.Multiplier;
|
||||
Vector3 l_velocity = m_velocity * Settings.VelocityMultiplier;
|
||||
foreach(Rigidbody l_body in m_rigidBodies)
|
||||
{
|
||||
l_body.velocity = l_velocity;
|
||||
|
|
|
@ -9,18 +9,27 @@ namespace ml_prm
|
|||
public enum ModSetting
|
||||
{
|
||||
Hotkey = 0,
|
||||
Multiplier,
|
||||
RestorePosition
|
||||
VelocityMultiplier,
|
||||
RestorePosition,
|
||||
MovementDrag,
|
||||
AngularDrag,
|
||||
Gravity
|
||||
}
|
||||
|
||||
public static bool Hotkey { get; private set; } = true;
|
||||
public static float Multiplier { get; private set; } = 2f;
|
||||
public static float VelocityMultiplier { get; private set; } = 2f;
|
||||
public static bool RestorePosition { get; private set; } = false;
|
||||
public static float MovementDrag { get; private set; } = 1f;
|
||||
public static float AngularDrag { get; private set; } = 0.5f;
|
||||
public static bool Gravity { get; private set; } = true;
|
||||
|
||||
static public event Action SwitchChange;
|
||||
static public event Action<bool> HotkeyChange;
|
||||
static public event Action<bool> RestorePositionChange;
|
||||
static public event Action<float> MultiplierChange;
|
||||
static public event Action<float> VelocityMultiplierChange;
|
||||
static public event Action<float> MovementDragChange;
|
||||
static public event Action<float> AngularDragChange;
|
||||
static public event Action<bool> GravityChange;
|
||||
|
||||
static MelonLoader.MelonPreferences_Category ms_category = null;
|
||||
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
|
||||
|
@ -31,13 +40,19 @@ namespace ml_prm
|
|||
ms_entries = new List<MelonLoader.MelonPreferences_Entry>()
|
||||
{
|
||||
ms_category.CreateEntry(ModSetting.Hotkey.ToString(), Hotkey),
|
||||
ms_category.CreateEntry(ModSetting.Multiplier.ToString(), Multiplier),
|
||||
ms_category.CreateEntry(ModSetting.VelocityMultiplier.ToString(), VelocityMultiplier),
|
||||
ms_category.CreateEntry(ModSetting.RestorePosition.ToString(), RestorePosition),
|
||||
ms_category.CreateEntry(ModSetting.MovementDrag.ToString(), MovementDrag),
|
||||
ms_category.CreateEntry(ModSetting.AngularDrag.ToString(), AngularDrag),
|
||||
ms_category.CreateEntry(ModSetting.Gravity.ToString(), Gravity),
|
||||
};
|
||||
|
||||
Hotkey = (bool)ms_entries[(int)ModSetting.Hotkey].BoxedValue;
|
||||
Multiplier = (float)ms_entries[(int)ModSetting.Multiplier].BoxedValue;
|
||||
VelocityMultiplier = UnityEngine.Mathf.Clamp((float)ms_entries[(int)ModSetting.VelocityMultiplier].BoxedValue, 0f, 50f);
|
||||
RestorePosition = (bool)ms_entries[(int)ModSetting.RestorePosition].BoxedValue;
|
||||
MovementDrag = UnityEngine.Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 100f);
|
||||
AngularDrag = UnityEngine.Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0.5f, 50f);
|
||||
Gravity = (bool)ms_entries[(int)ModSetting.Gravity].BoxedValue;
|
||||
|
||||
if(MelonLoader.MelonMod.RegisteredMelons.First(m => m.Info.Name == "BTKUILib") != null)
|
||||
{
|
||||
|
@ -66,13 +81,31 @@ namespace ml_prm
|
|||
{
|
||||
RestorePosition = state;
|
||||
ms_entries[(int)ModSetting.RestorePosition].BoxedValue = state;
|
||||
RestorePositionChange?.Invoke(Hotkey);
|
||||
RestorePositionChange?.Invoke(RestorePosition);
|
||||
};
|
||||
l_page.AddSlider("Velocity multiplier", "Velocity multiplier upon entering ragdoll state", Multiplier, 1f, 50f).OnValueUpdated += (value) =>
|
||||
l_categoryMod.AddToggle("Use gravity", "Apply gravity to ragdoll", Gravity).OnValueUpdated += (state) =>
|
||||
{
|
||||
Multiplier = value;
|
||||
ms_entries[(int)ModSetting.Multiplier].BoxedValue = value;
|
||||
MultiplierChange?.Invoke(value);
|
||||
Gravity = state;
|
||||
ms_entries[(int)ModSetting.Gravity].BoxedValue = state;
|
||||
GravityChange?.Invoke(Gravity);
|
||||
};
|
||||
l_page.AddSlider("Velocity multiplier", "Velocity multiplier upon entering ragdoll state", VelocityMultiplier, 1f, 50f).OnValueUpdated += (value) =>
|
||||
{
|
||||
VelocityMultiplier = value;
|
||||
ms_entries[(int)ModSetting.VelocityMultiplier].BoxedValue = value;
|
||||
VelocityMultiplierChange?.Invoke(VelocityMultiplier);
|
||||
};
|
||||
l_page.AddSlider("Movement drag", "Movement resistance", MovementDrag, 0f, 100f).OnValueUpdated += (value) =>
|
||||
{
|
||||
MovementDrag = value;
|
||||
ms_entries[(int)ModSetting.MovementDrag].BoxedValue = value;
|
||||
MovementDragChange?.Invoke(MovementDrag);
|
||||
};
|
||||
l_page.AddSlider("Angular movement drag", "Rotation movement resistance", AngularDrag, 0.5f, 50f).OnValueUpdated += (value) =>
|
||||
{
|
||||
AngularDrag = value;
|
||||
ms_entries[(int)ModSetting.AngularDrag].BoxedValue = value;
|
||||
AngularDragChange?.Invoke(AngularDrag);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_prm
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue