Decompiled source of Death Ragdoll v1.0.0

RagdollDeath.dll

Decompiled a day ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using Voxels.TowerDefense;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RagdollDeath")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RagdollDeath")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8ed8295f-16a6-4965-bf03-8e1cd954b84c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MyRagdollMod;

[BepInPlugin("com.user.betterragdoll", "Better Ragdoll Death", "1.1.4")]
public class RagdollPlugin : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("com.user.betterragdoll").PatchAll();
	}
}
public class DoomedAgent : MonoBehaviour
{
}
[HarmonyPatch(typeof(Agent), "DealDamage")]
public class AgentDeathPatch
{
	private static bool Prefix(Agent __instance, Attack attack, ref bool __result)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: 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_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		float num = __instance.health - ((Attack)(ref attack)).damage;
		if (num <= 0f && (Object)(object)__instance.ragdoller != (Object)null)
		{
			bool flag = false;
			if (!__instance.groundedState.active || !((NavPos)(ref __instance.navPos)).valid)
			{
				flag = true;
			}
			else
			{
				NavPos navPos = __instance.navPos;
				Vector3 normalized = ((Vector3)(ref attack.direction)).normalized;
				Vector3 val = (((Object)(object)((NavPos)(ref __instance.navPos)).transform != (Object)null) ? ((NavPos)(ref __instance.navPos)).transform.InverseTransformVector(normalized) : normalized);
				Edge val2 = default(Edge);
				((NavPos)(ref navPos)).MoveTo(((NavPos)(ref navPos)).pos + val * 1f, ref val2);
				if ((val2 != null && val2.cliff) || !((NavPos)(ref navPos)).valid)
				{
					flag = true;
				}
			}
			if (flag)
			{
				if ((Object)(object)((Component)__instance).GetComponent<DoomedAgent>() == (Object)null)
				{
					((Component)__instance).gameObject.AddComponent<DoomedAgent>();
				}
				float num2 = ((Attack)(ref attack)).knockback / __instance.mass;
				if (((Attack)(ref attack)).launchImpulse > 0f)
				{
					num2 += ((Attack)(ref attack)).launchImpulse / (__instance.scale * __instance.scale);
				}
				Vector3 val3 = __instance.velocity + ((Vector3)(ref attack.direction)).normalized * num2;
				val3 += Vector3.up * 1.5f;
				__instance.ragdoller.Launch(val3);
				__instance.health = 0f;
				__instance.maxHealth = 0f;
				if (Object.op_Implicit((Object)(object)__instance.squad))
				{
					__instance.squad.ReportDead(__instance);
				}
				if (((Attack)(ref attack)).hasSound)
				{
					IslandGameplayManager.RequestCombatAudio(attack.soundPrefix, "Kill", ((Component)__instance).gameObject);
				}
				else
				{
					IslandGameplayManager.RequestCombatAudio(__instance.hurtSound, ((Component)__instance).gameObject);
				}
				Death component = ((Component)__instance).GetComponent<Death>();
				if ((Object)(object)component != (Object)null && !string.IsNullOrEmpty(component.deathSound))
				{
					FabricWrapper.PostEvent(component.deathSound, ((Component)__instance).gameObject);
				}
				ReusableEffect bloodSlash = ScriptableObjectSingleton<PrefabManager>.instance.bloodSlash;
				if ((Object)(object)bloodSlash != (Object)null)
				{
					bloodSlash.PlayAt(attack.pos, -attack.direction);
				}
				((ReusableEffect)ScriptableObjectSingleton<PrefabManager>.instance.bloodStain).PlayAt(((Component)__instance).transform.position, Vector3.up);
				__result = true;
				return false;
			}
		}
		return true;
	}
}
[HarmonyPatch(typeof(Ragdoller), "TryAttach")]
public class RagdollBlockRevive
{
	private static bool Prefix(Ragdoller __instance, ref bool __result)
	{
		if ((Object)(object)((AgentComponent)__instance).agent != (Object)null && (Object)(object)((Component)((AgentComponent)__instance).agent).GetComponent<DoomedAgent>() != (Object)null)
		{
			__result = false;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(Ragdoller), "RagdollUpdate")]
public class RagdollForceCorpse
{
	private static void Postfix(Ragdoller __instance)
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)((AgentComponent)__instance).agent != (Object)null) || !((Object)(object)((Component)((AgentComponent)__instance).agent).GetComponent<DoomedAgent>() != (Object)null))
		{
			return;
		}
		Traverse val = Traverse.Create((object)__instance).Field("ragdoll").Field("rb");
		if (val.GetValue() != null)
		{
			Vector3 value = val.Property("velocity", (object[])null).GetValue<Vector3>();
			if (((Vector3)(ref value)).sqrMagnitude < 0.2f)
			{
				ForceSmash(__instance);
			}
		}
	}

	private static void ForceSmash(Ragdoller ragdoller)
	{
		MethodInfo method = typeof(Ragdoller).GetMethod("Smash", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method != null)
		{
			method.Invoke(ragdoller, new object[1]);
		}
	}
}
[HarmonyPatch(typeof(Ragdoller), "Smash")]
public class RagdollSmashFix
{
	private static void Prefix(Ragdoller __instance)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)((AgentComponent)__instance).agent != (Object)null && !((NavPos)(ref ((AgentComponent)__instance).agent.navPos)).valid)
		{
			NavPos navPos = default(NavPos);
			((NavPos)(ref navPos))..ctor(((IslandComponent)((AgentComponent)__instance).agent.faction).island.navManager.navigationMesh, ((Component)__instance).transform.position, true, 5f);
			if (((NavPos)(ref navPos)).valid)
			{
				((AgentComponent)__instance).agent.SetNavPos(navPos);
				((AgentComponent)__instance).agent.deadState.SetActive(true);
			}
		}
	}
}