mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 18:39:23 +00:00
Notification delay
World ragdoll restriction
This commit is contained in:
parent
9c339f3662
commit
0239ab3057
14 changed files with 501 additions and 414 deletions
|
@ -15,6 +15,7 @@ namespace ml_prm
|
|||
Settings.Init();
|
||||
ModUi.Init();
|
||||
GameEvents.Init(HarmonyInstance);
|
||||
WorldHandler.Init();
|
||||
|
||||
// Whitelist the toggle script
|
||||
(typeof(SharedFilter).GetField("_localComponentWhitelist", BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null) as HashSet<Type>)?.Add(typeof(RagdollToggle));
|
||||
|
@ -24,6 +25,8 @@ namespace ml_prm
|
|||
|
||||
public override void OnDeinitializeMelon()
|
||||
{
|
||||
WorldHandler.DeInit();
|
||||
|
||||
if(m_localController != null)
|
||||
UnityEngine.Object.Destroy(m_localController);
|
||||
m_localController = null;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[assembly: MelonLoader.MelonInfo(typeof(ml_prm.PlayerRagdollMod), "PlayerRagdollMod", "1.1.6", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_prm.PlayerRagdollMod), "PlayerRagdollMod", "1.1.7", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
||||
[assembly: MelonLoader.MelonPriority(2)]
|
||||
[assembly: MelonLoader.MelonOptionalDependencies("BTKUILib")]
|
||||
|
|
|
@ -45,6 +45,9 @@ Optional mod's settings in [UIExpansionKit](https://github.com/ddakebono/Chillou
|
|||
Available additional parameters for AAS animator:
|
||||
* **`Ragdolled`:** defines current ragdoll state; boolean.
|
||||
* Note: Can be set as local-only (not synced) if starts with `#` character.
|
||||
|
||||
# World restriction
|
||||
World creators can restrict ragdolling by creating empty game object with name `[RagdollRestriction]` anywhere in scene.
|
||||
|
||||
# Unity Editor Script
|
||||
You can also trigger the ragdoll via animations on your avatar. To do this you need:
|
||||
|
|
|
@ -213,7 +213,7 @@ namespace ml_prm
|
|||
if(m_downTime >= Settings.RecoverDelay)
|
||||
{
|
||||
SwitchRagdoll();
|
||||
m_downTime = float.MinValue; // One attepmt to recover
|
||||
m_downTime = float.MinValue; // One attempt to recover
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,13 +363,13 @@ namespace ml_prm
|
|||
m_rigidBodies.Add(l_body);
|
||||
l_body.isKinematic = true;
|
||||
l_body.angularDrag = Settings.AngularDrag;
|
||||
l_body.drag = (Utils.IsWorldSafe() ? Settings.MovementDrag : 1f);
|
||||
l_body.drag = (WorldHandler.IsSafeWorld() ? Settings.MovementDrag : 1f);
|
||||
l_body.useGravity = false;
|
||||
l_body.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
|
||||
l_body.gameObject.layer = LayerMask.NameToLayer("PlayerLocal");
|
||||
|
||||
GravityInfluencer l_gravInfluencer = l_body.gameObject.AddComponent<GravityInfluencer>();
|
||||
l_gravInfluencer.SetActiveGravity((!Utils.IsWorldSafe() || Settings.Gravity));
|
||||
l_gravInfluencer.SetActiveGravity((!WorldHandler.IsSafeWorld() || Settings.Gravity));
|
||||
m_gravityInfluencers.Add(l_gravInfluencer);
|
||||
}
|
||||
|
||||
|
@ -398,7 +398,7 @@ namespace ml_prm
|
|||
if((l_body != null) && (l_collider != null) && (l_puppetTransforms[i] == m_puppetReferences.hips || l_puppetTransforms[i] == m_puppetReferences.spine || l_puppetTransforms[i] == m_puppetReferences.chest))
|
||||
{
|
||||
PhysicsInfluencer l_physicsInfluencer = l_puppetTransforms[i].gameObject.AddComponent<PhysicsInfluencer>();
|
||||
l_physicsInfluencer.airDrag = (Utils.IsWorldSafe() ? Settings.MovementDrag : 1f);
|
||||
l_physicsInfluencer.airDrag = (WorldHandler.IsSafeWorld() ? Settings.MovementDrag : 1f);
|
||||
l_physicsInfluencer.airAngularDrag = Settings.AngularDrag;
|
||||
l_physicsInfluencer.fluidDrag = 3f;
|
||||
l_physicsInfluencer.fluidAngularDrag = 1f;
|
||||
|
@ -572,7 +572,7 @@ namespace ml_prm
|
|||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
float l_drag = (Utils.IsWorldSafe() ? p_value : 1f);
|
||||
float l_drag = (WorldHandler.IsSafeWorld() ? p_value : 1f);
|
||||
foreach(Rigidbody l_body in m_rigidBodies)
|
||||
{
|
||||
l_body.drag = l_drag;
|
||||
|
@ -601,7 +601,7 @@ namespace ml_prm
|
|||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
bool l_gravity = (!Utils.IsWorldSafe() || p_state);
|
||||
bool l_gravity = (!WorldHandler.IsSafeWorld() || p_state);
|
||||
foreach(PhysicsInfluencer l_influencer in m_physicsInfluencers)
|
||||
l_influencer.enabled = l_gravity;
|
||||
foreach(GravityInfluencer l_influencer in m_gravityInfluencers)
|
||||
|
@ -618,8 +618,8 @@ namespace ml_prm
|
|||
{
|
||||
if(m_physicsMaterial != null)
|
||||
{
|
||||
bool l_slipperiness = (Settings.Slipperiness && Utils.IsWorldSafe());
|
||||
bool l_bounciness = (Settings.Bounciness && Utils.IsWorldSafe());
|
||||
bool l_slipperiness = (Settings.Slipperiness && WorldHandler.IsSafeWorld());
|
||||
bool l_bounciness = (Settings.Bounciness && WorldHandler.IsSafeWorld());
|
||||
m_physicsMaterial.dynamicFriction = (l_slipperiness ? 0f : c_defaultFriction);
|
||||
m_physicsMaterial.staticFriction = (l_slipperiness ? 0f : c_defaultFriction);
|
||||
m_physicsMaterial.frictionCombine = (l_slipperiness ? PhysicMaterialCombine.Minimum : PhysicMaterialCombine.Average);
|
||||
|
@ -631,7 +631,7 @@ namespace ml_prm
|
|||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
bool l_buoyancy = (!Utils.IsWorldSafe() || p_state);
|
||||
bool l_buoyancy = (!WorldHandler.IsSafeWorld() || p_state);
|
||||
foreach(PhysicsInfluencer l_influencer in m_physicsInfluencers)
|
||||
l_influencer.enableInfluence = l_buoyancy;
|
||||
|
||||
|
@ -672,7 +672,7 @@ namespace ml_prm
|
|||
PlayerSetup.Instance.animatorManager.CancelEmote = true;
|
||||
m_ragdolledParameter.SetValue(true);
|
||||
|
||||
if(!Utils.IsWorldSafe())
|
||||
if(!WorldHandler.IsSafeWorld())
|
||||
{
|
||||
m_reachedGround = false; // Force player to unragdoll and reach ground first
|
||||
m_groundedTime = 0f;
|
||||
|
@ -683,8 +683,8 @@ namespace ml_prm
|
|||
foreach(Rigidbody l_body in m_rigidBodies)
|
||||
l_body.isKinematic = false;
|
||||
|
||||
Vector3 l_velocity = Vector3.ClampMagnitude(m_velocity * (Utils.IsWorldSafe() ? Settings.VelocityMultiplier : 1f), Utils.GetWorldMovementLimit());
|
||||
if(Settings.ViewVelocity && Utils.IsWorldSafe())
|
||||
Vector3 l_velocity = Vector3.ClampMagnitude(m_velocity * (WorldHandler.IsSafeWorld() ? Settings.VelocityMultiplier : 1f), WorldHandler.GetMovementLimit());
|
||||
if(Settings.ViewVelocity && WorldHandler.IsSafeWorld())
|
||||
{
|
||||
float l_mag = l_velocity.magnitude;
|
||||
l_velocity = PlayerSetup.Instance.GetActiveCamera().transform.forward * l_mag;
|
||||
|
@ -708,7 +708,7 @@ namespace ml_prm
|
|||
{
|
||||
BetterBetterCharacterController.Instance.TeleportPlayerTo(m_puppetReferences.hips.position, PlayerSetup.Instance.GetPlayerRotation().eulerAngles, false, false);
|
||||
TryRestoreMovement();
|
||||
if(!Utils.IsWorldSafe())
|
||||
if(!WorldHandler.IsSafeWorld())
|
||||
{
|
||||
Vector3 l_vec = BetterBetterCharacterController.Instance.GetVelocity();
|
||||
l_vec.y = Mathf.Clamp(l_vec.y, float.MinValue, 0f);
|
||||
|
@ -775,6 +775,9 @@ namespace ml_prm
|
|||
|
||||
bool CanRagdoll()
|
||||
{
|
||||
if(WorldHandler.IsRestrictedWorld())
|
||||
return false;
|
||||
|
||||
bool l_result = m_reachedGround;
|
||||
l_result &= !BodySystem.isCalibrating;
|
||||
l_result &= !BetterBetterCharacterController.Instance.IsSitting();
|
||||
|
|
|
@ -16,21 +16,6 @@ namespace ml_prm
|
|||
static readonly FieldInfo ms_influencerTouchingVolumes = typeof(PhysicsInfluencer).GetField("_touchingVolumes", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static readonly FieldInfo ms_influencerSubmergedColliders = typeof(PhysicsInfluencer).GetField("_submergedColliders", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
public static bool IsInVR() => ((MetaPort.Instance != null) && MetaPort.Instance.isUsingVr);
|
||||
public static bool IsWorldSafe() => ((CVRWorld.Instance != null) && CVRWorld.Instance.allowFlying);
|
||||
public static float GetWorldMovementLimit()
|
||||
{
|
||||
float l_result = 1f;
|
||||
if(CVRWorld.Instance != null)
|
||||
{
|
||||
l_result = CVRWorld.Instance.baseMovementSpeed;
|
||||
l_result *= CVRWorld.Instance.sprintMultiplier;
|
||||
l_result *= CVRWorld.Instance.inAirMovementMultiplier;
|
||||
l_result *= CVRWorld.Instance.flyMultiplier;
|
||||
}
|
||||
return l_result;
|
||||
}
|
||||
|
||||
public static void ClearFluidVolumes(this BetterBetterCharacterController p_instance) => (ms_touchingVolumes.GetValue(p_instance) as List<FluidVolume>)?.Clear();
|
||||
|
||||
public static void CopyGlobal(this Transform p_source, Transform p_target)
|
||||
|
|
44
ml_prm/WorldHandler.cs
Normal file
44
ml_prm/WorldHandler.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using ABI.CCK.Components;
|
||||
using ABI_RC.Systems.GameEventSystem;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_prm
|
||||
{
|
||||
static class WorldHandler
|
||||
{
|
||||
static bool ms_safeWorld = true;
|
||||
static bool ms_restrictedWorld = false;
|
||||
static float ms_movementLimit = 1f;
|
||||
|
||||
internal static void Init()
|
||||
{
|
||||
CVRGameEventSystem.World.OnLoad.AddListener(OnWorldLoad);
|
||||
}
|
||||
|
||||
internal static void DeInit()
|
||||
{
|
||||
CVRGameEventSystem.World.OnLoad.RemoveListener(OnWorldLoad);
|
||||
}
|
||||
|
||||
static void OnWorldLoad(string p_id)
|
||||
{
|
||||
ms_safeWorld = ((CVRWorld.Instance != null) && CVRWorld.Instance.allowFlying);
|
||||
ms_movementLimit = 1f;
|
||||
|
||||
GameObject l_restrictObj = GameObject.Find("[RagdollRestriction]");
|
||||
ms_restrictedWorld = ((l_restrictObj == null) ? false : (l_restrictObj.scene.name != "DontDestroyOnLoad"));
|
||||
|
||||
if(CVRWorld.Instance != null)
|
||||
{
|
||||
ms_movementLimit = CVRWorld.Instance.baseMovementSpeed;
|
||||
ms_movementLimit *= CVRWorld.Instance.sprintMultiplier;
|
||||
ms_movementLimit *= CVRWorld.Instance.inAirMovementMultiplier;
|
||||
ms_movementLimit *= CVRWorld.Instance.flyMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsSafeWorld() => ms_safeWorld;
|
||||
public static bool IsRestrictedWorld() => ms_restrictedWorld;
|
||||
public static float GetMovementLimit() => ms_movementLimit;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<PackageId>PlayerRagdollMod</PackageId>
|
||||
<Version>1.1.6</Version>
|
||||
<Version>1.1.7</Version>
|
||||
<Authors>SDraw</Authors>
|
||||
<Company>None</Company>
|
||||
<Product>PlayerRagdollMod</Product>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue