using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GTFO.API;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RagdollMode")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RagdollMode")]
[assembly: AssemblyTitle("RagdollMode")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace RagdollMode
{
[HarmonyPatch]
internal class DamageCheck
{
[HarmonyPatch(typeof(Dam_PlayerDamageBase), "ReceiveMeleeDamage")]
[HarmonyPostfix]
public static void PlayerTakenMeleeDamage(Dam_PlayerDamageBase __instance, pFullDamageData data)
{
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
string empty = string.Empty;
float num = ((UFloat16)(ref data.damage)).Get(((Dam_SyncedDamageBase)__instance).DamageMax);
Agent val = default(Agent);
if (((pAgent)(ref data.source)).TryGet(ref val))
{
empty = ((Object)val).name;
Debug.Log(Object.op_Implicit(empty));
}
if (!(num < ((Dam_SyncedDamageBase)__instance).HealthMax * 0.2f))
{
RagdollLogic component = ((Component)__instance.Owner).GetComponent<RagdollLogic>();
component.ToggleRagdoll(enabled: true);
component.InflictKnockback(((LowResVector3_Normalized)(ref data.direction)).Value, 15000f * (num / ((Dam_SyncedDamageBase)__instance).HealthMax));
}
}
[HarmonyPatch(typeof(Dam_PlayerDamageLocal), "ReceiveFallDamage")]
[HarmonyPostfix]
public static void PlayerTakenFallDamagePatch(Dam_PlayerDamageLocal __instance, pMiniDamageData data)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
float num = ((UFloat16)(ref data.damage)).Get(((Dam_SyncedDamageBase)__instance).HealthMax);
if (!(num < ((Dam_SyncedDamageBase)__instance).HealthMax * 0.12f))
{
CustomThing customThing = default(CustomThing);
customThing.data = data;
CustomThing customThing2 = customThing;
((pPlayerAgent)(ref customThing2.agent)).Set(((Dam_PlayerDamageBase)__instance).Owner);
NetworkAPI.InvokeEvent<CustomThing>("TakeFallDamage", customThing2, (SNet_ChannelType)2);
((Component)((Dam_PlayerDamageBase)__instance).Owner).GetComponent<RagdollLogic>().ToggleRagdoll(enabled: true);
}
}
[HarmonyPatch(typeof(PlayerAgent), "Setup")]
[HarmonyPostfix]
public static void AddRagdollLogic(PlayerAgent __instance)
{
if (!((Object)(object)((Component)__instance).gameObject.GetComponent<RagdollLogic>() != (Object)null))
{
((Component)__instance).gameObject.AddComponent<RagdollLogic>();
}
}
public static void TakeFallDamage(ulong senderID, CustomThing data)
{
PlayerAgent val = default(PlayerAgent);
if (((pPlayerAgent)(ref data.agent)).TryGet(ref val))
{
float num = ((UFloat16)(ref data.data.damage)).Get(((Dam_SyncedDamageBase)val.Damage).HealthMax);
((Component)val).GetComponent<RagdollLogic>().ToggleRagdoll(enabled: true);
}
}
}
[BepInPlugin("com.Brandont.RagdollMode", "RagdollMode", "1.0.0")]
public class Loader : BasePlugin
{
public const string MODNAME = "RagdollMode";
public const string AUTHOR = "Brandont";
public const string GUID = "com.Brandont.RagdollMode";
public const string VERSION = "1.0.0";
public static ManualLogSource Logger;
public override void Load()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
ClassInjector.RegisterTypeInIl2Cpp<RagdollLogic>();
NetworkAPI.RegisterEvent<CustomThing>("TakeFallDamage", (Action<ulong, CustomThing>)DamageCheck.TakeFallDamage);
Logger = ((BasePlugin)this).Log;
((BasePlugin)this).Log.LogMessage((object)"Loading RagdollMode");
Harmony val = new Harmony("RagdollMode");
val.PatchAll();
((BasePlugin)this).Log.LogMessage((object)"Loaded RagdollMode");
}
}
public struct CustomThing
{
public pPlayerAgent agent;
public pMiniDamageData data;
}
public class RagdollLogic : MonoBehaviourExtended
{
public PlayerAgent? player;
public Transform? playerRigClone;
public Transform? playerRig;
public List<GameObject> boneList = new List<GameObject>();
public bool isLocal;
public bool ragdollEnabled = false;
public float timer;
public float landedTimer;
public readonly List<string> excludeBones = new List<string> { "Neck", "LeftShoulder", "RightShoulder", "Spine2", "Spine3" };
public void Awake()
{
boneList = new List<GameObject>();
player = ((Component)this).GetComponent<PlayerAgent>();
isLocal = ((Agent)player).IsLocallyOwned;
player.m_movingCuller.m_animatorCullingEnabled = false;
playerRigClone = ((Component)player.PlayerSyncModel).transform;
playerRig = playerRigClone.Find("PlayerCharacter_rig");
AddRBAndCJ("Hip/LeftUpperLeg/LeftLowerLeg/LeftFoot");
AddRBAndCJ("Hip/RightUpperLeg/RightLowerLeg/RightFoot");
AddRBAndCJ("Hip/Spine1/Spine2/Spine3/LeftShoulder/LeftUpperArm/LeftLowerArm");
AddRBAndCJ("Hip/Spine1/Spine2/Spine3/RightShoulder/RightUpperArm/RightLowerArm");
AddRBAndCJ("Hip/Spine1/Spine2/Spine3/Neck/Head");
}
public void ToggleRagdoll(bool enabled)
{
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_029c: Unknown result type (might be due to invalid IL or missing references)
//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_031d: Unknown result type (might be due to invalid IL or missing references)
timer = 0f;
landedTimer = 0f;
if ((Object)(object)playerRigClone == (Object)null)
{
Debug.Log(Object.op_Implicit("Player Rig is null!"));
return;
}
foreach (GameObject bone in boneList)
{
Rigidbody component = bone.GetComponent<Rigidbody>();
bone.GetComponent<SphereCollider>().radius = 0.15f;
if (enabled)
{
if (((Object)bone).name == "Hip" && isLocal)
{
((Component)player.FPSCamera).transform.parent = bone.transform;
Transform transform = ((Component)player.FPSCamera).transform;
transform.localPosition += new Vector3(0f, 1f, 0f);
}
ragdollEnabled = true;
component.useGravity = true;
component.isKinematic = false;
component.velocity = Vector3.zero;
}
else
{
ragdollEnabled = false;
component.useGravity = false;
component.isKinematic = true;
component.velocity = Vector3.zero;
}
}
if (enabled)
{
((Behaviour)((Component)playerRigClone).GetComponent<Animator>()).enabled = false;
playerRig.parent = null;
((Behaviour)player.Locomotion).enabled = false;
player.SyncIK.SetGrounderEnabled(false);
if (isLocal)
{
player.PlayerSyncModel.SetAllVisible(false);
player.FPItemHolder.ItemHiddenTrigger = true;
}
return;
}
((Behaviour)((Component)playerRigClone).GetComponent<Animator>()).enabled = true;
playerRig.parent = playerRigClone;
playerRig.localRotation = Quaternion.EulerAngles(Vector3.zero);
((Component)playerRig).transform.localPosition = Vector3.zero;
((Behaviour)player.Locomotion).enabled = true;
player.SyncIK.SetGrounderEnabled(true);
if (isLocal)
{
((Component)player.FPSCamera).transform.parent = ((Component)player.FPItemHolder).transform.parent;
Transform transform2 = ((Component)player.FPSCamera).transform;
transform2.localPosition -= new Vector3(0f, 1f, 0f);
player.FPItemHolder.ItemHiddenTrigger = false;
player.PlayerSyncModel.SetAllVisible(true);
player.PlayerSyncModel.SetHeadVisible(false, false);
}
if (((Agent)player).DistanceToGoodNode > 0.5f)
{
player.TeleportTo(((Agent)player).GoodPosition);
}
}
private GameObject GetParent(GameObject go)
{
GameObject gameObject = ((Component)go.transform.parent).gameObject;
while (excludeBones.Contains(((Object)gameObject).name) && ((Object)gameObject).name != "Root")
{
gameObject = ((Component)gameObject.transform.parent).gameObject;
}
return gameObject;
}
public void AddRBAndCJ(string boneName)
{
//IL_023b: Unknown result type (might be due to invalid IL or missing references)
//IL_0265: Unknown result type (might be due to invalid IL or missing references)
//IL_026a: Unknown result type (might be due to invalid IL or missing references)
//IL_0276: Unknown result type (might be due to invalid IL or missing references)
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
//IL_0292: Unknown result type (might be due to invalid IL or missing references)
//IL_0297: Unknown result type (might be due to invalid IL or missing references)
//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
GameObject bone = ((Component)playerRig.Find("Root/" + boneName)).gameObject;
GameObject boneParent = GetParent(bone);
while (((Object)boneParent).name != "Root")
{
if ((Object)(object)boneParent.GetComponent<Rigidbody>() == (Object)null)
{
Rigidbody val = boneParent.AddComponent<Rigidbody>();
val.useGravity = false;
val.isKinematic = true;
val.mass = 15f;
val.interpolation = (RigidbodyInterpolation)1;
val.collisionDetectionMode = (CollisionDetectionMode)3;
if (((Object)boneParent).name != "Hip")
{
boneParent.AddComponent<ConfigurableJoint>();
}
boneParent.AddComponent<SphereCollider>();
boneParent.layer = 18;
}
if ((Object)(object)bone.GetComponent<Rigidbody>() == (Object)null)
{
Rigidbody val2 = bone.AddComponent<Rigidbody>();
val2.useGravity = false;
val2.isKinematic = true;
val2.mass = 15f;
val2.interpolation = (RigidbodyInterpolation)1;
val2.collisionDetectionMode = (CollisionDetectionMode)3;
bone.AddComponent<ConfigurableJoint>();
bone.AddComponent<SphereCollider>();
bone.layer = 18;
}
if (!boneList.Any((GameObject b) => ((Object)b).name == ((Object)bone).name))
{
boneList.Add(bone);
}
if (!boneList.Any((GameObject b) => ((Object)b).name == ((Object)boneParent).name))
{
boneList.Add(boneParent);
}
ConfigurableJoint component = bone.GetComponent<ConfigurableJoint>();
((Joint)component).connectedBody = boneParent.GetComponent<Rigidbody>();
component.xMotion = (ConfigurableJointMotion)0;
component.yMotion = (ConfigurableJointMotion)0;
component.zMotion = (ConfigurableJointMotion)0;
component.angularXMotion = (ConfigurableJointMotion)1;
component.angularYMotion = (ConfigurableJointMotion)1;
component.angularZMotion = (ConfigurableJointMotion)1;
((Joint)component).anchor = Vector3.zero;
((Joint)component).autoConfigureConnectedAnchor = false;
((Joint)component).connectedAnchor = boneParent.transform.InverseTransformPoint(bone.transform.position);
SoftJointLimit lowAngularXLimit = component.lowAngularXLimit;
((SoftJointLimit)(ref lowAngularXLimit)).limit = -20f;
component.lowAngularXLimit = lowAngularXLimit;
SoftJointLimit highAngularXLimit = component.highAngularXLimit;
((SoftJointLimit)(ref highAngularXLimit)).limit = 20f;
component.highAngularXLimit = highAngularXLimit;
SoftJointLimit angularYLimit = component.angularYLimit;
((SoftJointLimit)(ref angularYLimit)).limit = 40f;
component.angularYLimit = angularYLimit;
SoftJointLimit angularZLimit = component.angularZLimit;
((SoftJointLimit)(ref angularZLimit)).limit = 40f;
component.angularZLimit = angularZLimit;
bone = boneParent;
boneParent = GetParent(bone);
}
}
public void InflictKnockback(Vector3 force, float multi)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
foreach (GameObject bone in boneList)
{
bone.GetComponent<Rigidbody>().AddForce(force * multi);
}
player.Locomotion.m_externalPushForce = Vector3.zero;
player.Locomotion.m_hasExternalPushForce = false;
}
public void Update()
{
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
if (!RundownManager.ExpeditionIsStarted || !ragdollEnabled)
{
return;
}
Transform transform = boneList.First((GameObject s) => ((Object)s).name == "Hip").transform;
player.TeleportTo(transform.position);
if (!player.DeadDebugMode && ((Agent)player).CourseNode != null)
{
player.m_movingCuller.UpdatePosition(((Agent)player).DimensionIndex, ((Agent)player).Position);
}
if (((Agent)player).CourseNode != null)
{
player.m_movingCuller.UpdatePosition(((Agent)player).DimensionIndex, ((Agent)player).Position);
}
timer += 1f * Time.deltaTime;
Vector3 velocity = ((Component)transform).GetComponent<Rigidbody>().velocity;
if (((Vector3)(ref velocity)).sqrMagnitude < 0.2f || timer > 5f)
{
landedTimer += Time.deltaTime;
if ((((Dam_SyncedDamageBase)player.Damage).Health > 0f || !(((Agent)player).DistanceToGoodNode < 1f)) && landedTimer > 1.25f)
{
ToggleRagdoll(enabled: false);
}
}
}
}
}