using System;
using System.Collections;
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 HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Interaction;
using ImpactRagdoll;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
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), "ImpactRagdoll", "1.0.0", "notnotnotswipez", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ImpactRagdoll")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ImpactRagdoll")]
[assembly: AssemblyTitle("ImpactRagdoll")]
[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 ImpactRagdoll
{
public class Core : MelonMod
{
[HarmonyPatch(typeof(PhysicsRig), "UnRagdollRig")]
public class UnRagdollPatch
{
public static bool Prefix(PhysicsRig __instance)
{
if (((Object)((Rig)__instance).manager).GetInstanceID() == ((Object)Player.RigManager).GetInstanceID() && lockUnragdoll)
{
return false;
}
return true;
}
}
public static bool enabled = true;
public static bool lockUnragdoll = false;
public static bool seatEjection = true;
public static float ejectionPower = 20f;
private Rigidbody trackingBody;
private Vector3 lastVelocity = Vector3.zero;
public static float downTime = 2f;
public static float cooldown = 6f;
public static float threshHold = 5.5f;
public override void OnInitializeMelon()
{
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
Hooking.OnUIRigCreated += delegate
{
trackingBody = Player.PhysicsRig.physG._rb;
cooldown = 5f;
};
MelonPreferences_Category mainCategory = MelonPreferences.CreateCategory("ImpactRagdoll");
MelonPreferences_Entry<bool> modEnabledEntry = mainCategory.CreateEntry<bool>("ModEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
MelonPreferences_Entry<float> impactThreshEntry = mainCategory.CreateEntry<float>("ImpactThreshold", 6f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
MelonPreferences_Entry<bool> seatEjectionEntry = mainCategory.CreateEntry<bool>("SeatEjection", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
MelonPreferences_Entry<float> seatEjectionPowerEntry = mainCategory.CreateEntry<float>("EjectionPower", 20f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
MelonPreferences_Entry<float> downTimeEntry = mainCategory.CreateEntry<float>("DownTime", 2f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
enabled = modEnabledEntry.Value;
threshHold = impactThreshEntry.Value;
seatEjection = seatEjectionEntry.Value;
ejectionPower = seatEjectionPowerEntry.Value;
downTime = downTimeEntry.Value;
Page val = Page.Root.CreatePage("ImpactRagdoll", Color.yellow, 0, true);
val.CreateBool("Enabled", Color.green, enabled, (Action<bool>)delegate(bool b)
{
enabled = b;
modEnabledEntry.Value = b;
mainCategory.SaveToFile(false);
});
val.CreateFloat("Impact Threshold", Color.blue, threshHold, 0.5f, 1f, 10f, (Action<float>)delegate(float f)
{
threshHold = f;
impactThreshEntry.Value = f;
mainCategory.SaveToFile(false);
});
val.CreateFloat("Down Time", Color.blue, downTime, 0.5f, 1f, 10f, (Action<float>)delegate(float f)
{
downTime = f;
downTimeEntry.Value = f;
mainCategory.SaveToFile(false);
});
val.CreateBool("Seat Ejection", Color.blue, seatEjection, (Action<bool>)delegate(bool b)
{
seatEjection = b;
seatEjectionEntry.Value = b;
mainCategory.SaveToFile(false);
});
val.CreateFloat("Ejection Power", Color.yellow, ejectionPower, 1f, 1f, 1000f, (Action<float>)delegate(float f)
{
ejectionPower = f;
seatEjectionPowerEntry.Value = f;
mainCategory.SaveToFile(false);
});
}
public override void OnUpdate()
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
if (!enabled)
{
return;
}
if (cooldown > 0f)
{
cooldown -= Time.deltaTime;
}
if (!Object.op_Implicit((Object)(object)trackingBody))
{
return;
}
Vector3 velocity = trackingBody.velocity;
float magnitude = ((Vector3)(ref velocity)).magnitude;
float magnitude2 = ((Vector3)(ref lastVelocity)).magnitude;
float targetFloat = magnitude - magnitude2;
PhysicsRig physicsRig = Player.PhysicsRig;
if (FastAbs(targetFloat) > threshHold && !physicsRig.shutdown && cooldown <= 0f)
{
bool flag = false;
MarrowEntity val = null;
Seat activeSeat = Player.RigManager.activeSeat;
if (Object.op_Implicit((Object)(object)activeSeat))
{
if (!seatEjection)
{
return;
}
activeSeat.EgressRig(true);
val = ((Component)activeSeat).GetComponentInParent<MarrowEntity>();
TryDrop(Player.LeftHand);
TryDrop(Player.RightHand);
flag = true;
}
physicsRig.ShutdownRig();
physicsRig.RagdollRig();
lockUnragdoll = true;
MelonCoroutines.Start(WaitAndRestoreUnragdoll(downTime));
if (flag)
{
Vector3 normalized = ((Vector3)(ref lastVelocity)).normalized;
normalized.y += 1f;
normalized *= ejectionPower;
if (Object.op_Implicit((Object)(object)val))
{
IgnoreCollisionWithEntity(val, ignore: true);
}
MelonCoroutines.Start(MinorWaitAndReCollideRig(val, 0.5f));
((Component)((Rig)physicsRig).m_chest).GetComponent<Rigidbody>().AddForce(normalized * ejectionPower, (ForceMode)1);
}
}
lastVelocity = velocity;
}
private void IgnoreCollisionWithEntity(MarrowEntity target, bool ignore)
{
foreach (Collider componentsInChild in ((Component)target).GetComponentsInChildren<Collider>())
{
foreach (Collider componentsInChild2 in ((Component)Player.PhysicsRig).GetComponentsInChildren<Collider>())
{
Physics.IgnoreCollision(componentsInChild, componentsInChild2, ignore);
}
}
}
private bool TryDrop(Hand hand)
{
if (hand.HasAttachedObject())
{
Grip val = ((Il2CppObjectBase)hand.AttachedReceiver).TryCast<Grip>();
if ((Object)(object)val != (Object)null)
{
val.ForceDetach(true);
return true;
}
}
return false;
}
private IEnumerator MinorWaitAndReCollideRig(MarrowEntity entity, float time)
{
yield return (object)new WaitForSeconds(time);
IgnoreCollisionWithEntity(entity, ignore: false);
}
private IEnumerator WaitAndRestoreUnragdoll(float time)
{
yield return (object)new WaitForSeconds(time);
lockUnragdoll = false;
PhysicsRig physicsRig = Player.PhysicsRig;
Transform feet = physicsRig.feet.transform;
Transform knee = physicsRig.knee.transform;
Transform pelvis = ((Component)((Rig)physicsRig).m_pelvis).transform;
physicsRig.TurnOnRig();
physicsRig.UnRagdollRig();
Vector3 position = pelvis.position;
Quaternion rotation = pelvis.rotation;
knee.SetPositionAndRotation(position, rotation);
feet.SetPositionAndRotation(position, rotation);
cooldown = 3f;
}
private float FastAbs(float targetFloat)
{
if (targetFloat < 0f)
{
return targetFloat * -1f;
}
return targetFloat;
}
}
}