using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using RagdollFix_Patch6;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "RagdollFix_Patch6", "1.2.0", "MajedCT", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RagdollFix_Patch6")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0d038c7287205e85231930fa4b284f362cc53b9a")]
[assembly: AssemblyProduct("RagdollFix_Patch6")]
[assembly: AssemblyTitle("RagdollFix_Patch6")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace RagdollFix_Patch6
{
public class Core : MelonMod
{
public static Stopwatch RagdollTimer = new Stopwatch();
private static bool CanRagdoll = true;
private static bool TooFast = false;
public static float SpeedLimit = Preferences.VelocityLimit;
private bool _sceneLoaded;
private bool _previousRagdollState;
private bool _currentRagdollState;
public override void OnInitializeMelon()
{
((MelonBase)this).LoggerInstance.Msg($"RAGDOLL FIX: initialized ragdollfix, mod toggle: {Preferences.ModIsEnabled}");
Hooking.OnLevelLoaded += delegate
{
OnSceneAwake();
};
Preferences.BoneMenuCreator();
Preferences.MelonPreferencesCreator();
}
private void OnSceneAwake()
{
_sceneLoaded = true;
_previousRagdollState = Player.PhysicsRig._legsKinematic;
}
public static void RagdollCheck()
{
if (RagdollTimer.Elapsed.TotalSeconds < 0.5)
{
CanRagdoll = false;
}
if (RagdollTimer.Elapsed.TotalSeconds > 0.5)
{
CanRagdoll = true;
}
}
public static void SpeedCheck()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
Vector3 wholeBodyVelocity = Player.PhysicsRig.wholeBodyVelocity;
if (((Vector3)(ref wholeBodyVelocity)).magnitude > SpeedLimit)
{
TooFast = true;
}
else if (((Vector3)(ref wholeBodyVelocity)).magnitude < SpeedLimit)
{
TooFast = false;
}
}
public static void RagdollFix()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = Player.PhysicsRig.feet.transform.position + new Vector3(0f, 0.25f, 0f);
Player.RigManager.Teleport(val, true);
}
public override void OnUpdate()
{
if (!_sceneLoaded || !Preferences.ModIsEnabled)
{
return;
}
SpeedCheck();
_currentRagdollState = Player.PhysicsRig._legsKinematic;
if (_previousRagdollState && !_currentRagdollState)
{
RagdollCheck();
RagdollTimer.Start();
}
if (!_previousRagdollState && _currentRagdollState)
{
RagdollTimer.Stop();
RagdollCheck();
RagdollTimer.Reset();
if (Preferences.FlyFixIsEnabled && Preferences.VelocityFixIsEnabled && CanRagdoll && !TooFast)
{
RagdollFix();
}
if (Preferences.VelocityFixIsEnabled && !Preferences.FlyFixIsEnabled && !TooFast)
{
RagdollFix();
}
if (Preferences.FlyFixIsEnabled && !Preferences.VelocityFixIsEnabled && CanRagdoll)
{
RagdollFix();
}
if (!Preferences.VelocityFixIsEnabled && !Preferences.FlyFixIsEnabled)
{
RagdollFix();
}
}
_previousRagdollState = _currentRagdollState;
}
}
internal class Preferences
{
private static MelonPreferences_Category MelonPrefCategory { get; set; }
private static MelonPreferences_Entry<bool> ModMelonPref { get; set; }
public static bool ModIsEnabled { get; private set; }
private static MelonPreferences_Entry<bool> FlyFixMelonPref { get; set; }
public static bool FlyFixIsEnabled { get; private set; }
private static MelonPreferences_Entry<bool> VelocityFixMelonPref { get; set; }
public static bool VelocityFixIsEnabled { get; private set; }
private static MelonPreferences_Entry<float> VelocityLimitMelonPref { get; set; }
public static float VelocityLimit { get; private set; } = 5f;
public static void MelonPreferencesCreator()
{
MelonPrefCategory = MelonPreferences.CreateCategory("Ragdoll Fix Patch 6");
ModMelonPref = MelonPrefCategory.CreateEntry<bool>("ModIsEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
ModIsEnabled = ModMelonPref.Value;
FlyFixMelonPref = MelonPrefCategory.CreateEntry<bool>("FlyFixIsEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
FlyFixIsEnabled = FlyFixMelonPref.Value;
VelocityFixMelonPref = MelonPrefCategory.CreateEntry<bool>("VelocityFixIsEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VelocityFixIsEnabled = VelocityFixMelonPref.Value;
VelocityLimitMelonPref = MelonPrefCategory.CreateEntry<float>("VelocityLimit", 5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
VelocityLimit = VelocityLimitMelonPref.Value;
}
public static void BoneMenuCreator()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
Page val = Page.Root.CreatePage("Ragdoll Fix", Color.yellow, 0, true);
val.CreateBool("Mod Toggle", Color.white, true, (Action<bool>)OnModEnabled);
val.CreateBool("Flight Fix (Recommended: ON)", Color.white, true, (Action<bool>)OnFlyFixEnabled);
val.CreateBool("Velocity Fix (Recommended: ON)", Color.white, true, (Action<bool>)OnVelocityFixEnabled);
val.CreateFloat("Velocity Limit", Color.yellow, VelocityLimit, 5f, 0f, 200f, (Action<float>)OnSpeedLimitChanged);
}
private static void OnSpeedLimitChanged(float value)
{
VelocityLimit = value;
Core.SpeedLimit = VelocityLimit;
VelocityLimitMelonPref.Value = value;
MelonPrefCategory.SaveToFile(false);
}
private static void OnModEnabled(bool value)
{
ModIsEnabled = value;
ModMelonPref.Value = value;
MelonPrefCategory.SaveToFile(false);
}
private static void OnFlyFixEnabled(bool value)
{
FlyFixIsEnabled = value;
FlyFixMelonPref.Value = value;
MelonPrefCategory.SaveToFile(false);
}
private static void OnVelocityFixEnabled(bool value)
{
VelocityFixIsEnabled = value;
VelocityFixMelonPref.Value = value;
MelonPrefCategory.SaveToFile(false);
}
}
}