Decompiled source of Extreme ragdoll v1.2.0

plugins/ExtremeRagdoll.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Extreme_Ragdoll;

public static class ConfigElements
{
	public static ConfigEntry<float> ragdollScale;

	public static void Init(ConfigFile config)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		ragdollScale = config.Bind<float>("Ragdoll", "Multiplier", 5f, new ConfigDescription("How many times stronger than vanilla will the ragdoll be. (Vanilla Outward = 1)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 30f), new object[0]));
	}
}
[HarmonyPatch(typeof(Character), "OnReceiveHit")]
public class OnReceiveHitModifier
{
	[HarmonyPrefix]
	public static bool Prefix(Weapon _weapon, float _damage, DamageList _damageList, Vector3 _hitDir, Vector3 _hitPoint, float _angle, float _angleDir, Character _dealerChar, float _knockBack, Character __instance, CharacterSoundManager ___m_characterSoundManager, OnHitEvent ___m_onHitPosResistance, StatusEffectManager ___m_statusEffectManager, ParticleSystem ___m_hurtFX, ParticleSystem[] ___m_elementalFX, HurtType ___m_hurtType)
	{
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_039f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_03af: Invalid comparison between Unknown and I4
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Expected I4, but got Unknown
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		__instance.m_lastHurtTime = Time.time;
		float num = (Object.op_Implicit((Object)(object)__instance.Stats) ? __instance.Stats.GetMitigatedImpact((Tag[])null, _knockBack, false) : _knockBack);
		if (_knockBack > 0f && num == 0f)
		{
			num = 0.001f;
		}
		if ((Object)(object)___m_characterSoundManager != (Object)null && ((Object)(object)_weapon != (Object)null || _damage > 9f))
		{
			Global.AudioManager.PlaySoundAtPosition(___m_characterSoundManager.GetHurtSound(), ((Component)__instance).transform, 0f, 1f, 1f, 1f, 1f);
		}
		((UnityEvent<Weapon, float>)(object)___m_onHitPosResistance)?.Invoke(_weapon, _damage);
		if (Object.op_Implicit((Object)(object)___m_statusEffectManager) && _knockBack >= 10f)
		{
			___m_statusEffectManager.OnReceivedHit();
		}
		if (Object.op_Implicit((Object)(object)_dealerChar))
		{
			__instance.AddLastDealer(_dealerChar.UID);
			((Component)__instance).SendMessage("CharHurt", (object)_dealerChar, (SendMessageOptions)1);
			__instance.OnReceiveHitCombatEngaged(_dealerChar);
		}
		if ((Object)(object)_weapon != (Object)null)
		{
			float num2 = Mathf.Lerp(0.7f, 1f, UnityEngineExtensions.GetLerpValue(Mathf.Clamp(_damage, 10f, 40f), 10f, 40f));
			float num3 = Mathf.Lerp(0f, 0.3f, UnityEngineExtensions.GetLerpValue(Mathf.Clamp(__instance.CharacterController.radius, 0.4f, 0.8f), 0.4f, 0.8f));
			Vector3 position = _hitPoint + (_weapon.WeaponCenter - _hitPoint) * 0.1f;
			Vector3 localScale = Vector3.one * (num2 + num3);
			((Component)___m_hurtFX).transform.position = position;
			((Component)___m_hurtFX).transform.forward = _hitDir;
			((Component)___m_hurtFX).transform.localScale = localScale;
			___m_hurtFX.Play();
			if (_damageList != null)
			{
				for (int i = 0; i < _damageList.Count; i++)
				{
					if (_damageList[i].Damage > 0f)
					{
						int num4 = _damageList[i].Type - 1;
						if (num4 >= 0 && num4 < ___m_elementalFX.Length && (Object)(object)___m_elementalFX[num4] != (Object)null)
						{
							((Component)___m_elementalFX[num4]).transform.position = position;
							((Component)___m_elementalFX[num4]).transform.forward = _hitDir;
							((Component)___m_elementalFX[num4]).transform.localScale = localScale;
							___m_elementalFX[num4].Play();
						}
					}
				}
			}
			if (!(_weapon is ProjectileWeapon))
			{
				if (!Object.op_Implicit((Object)(object)_weapon.ImpactSoundOverride))
				{
					if ((Object)(object)_weapon.ImpactSoundPlayer == (Object)null)
					{
						Debug.LogError((object)$"Null ImpactSoundPlayer! {_weapon}");
					}
					else
					{
						_weapon.ImpactSoundPlayer.Play(__instance.HitSoundMaterial, false);
					}
				}
				else
				{
					_weapon.ImpactSoundOverride.Play(false);
				}
			}
		}
		Vector3 val = _hitDir * ConfigElements.ragdollScale.Value * Mathf.Clamp(CharacterManager.Instance.DeathImpulseCurve.Evaluate(Mathf.Clamp(_damage, 0f, 60f)) + CharacterManager.Instance.DeathImpulseCurve.Evaluate(Mathf.Clamp(num, 0f, 60f)), 0f, 60f);
		__instance.VitalityHit(_dealerChar, _damage, val);
		if ((int)___m_hurtType != 2)
		{
			__instance.StabilityHit(num, Vector3.Angle(((Component)__instance).transform.forward, -_hitDir) * _angleDir, false, _dealerChar);
		}
		return false;
	}
}
[HarmonyPatch(typeof(Character), "Awake")]
public class SetHighDeadPoseRagdollFailsafeSqrDist
{
	[HarmonyPrefix]
	public static void Postfix(Character __instance)
	{
		if (!ExtremeRagdollPlugin.Instance.isPlayerCharacter(__instance))
		{
			__instance.DeadPoseRagdollFailsafeSqrDist = ExtremeRagdollPlugin.LeashLength_i;
		}
	}
}
[HarmonyPatch(typeof(Character), "FixedUpdate")]
public class FixRagdollSpeedResetting
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo methodInfo = AccessTools.Method(typeof(NavMesh), "SamplePosition", new Type[4]
		{
			typeof(Vector3),
			typeof(NavMeshHit).MakeByRefType(),
			typeof(float),
			typeof(int)
		}, (Type[])null);
		if (methodInfo == null)
		{
			ExtremeRagdollPlugin.Log.LogError((object)"Failed to resolve NavMesh.SamplePosition — signature mismatch.");
		}
		MethodInfo methodInfo2 = AccessTools.PropertyGetter(typeof(ExtremeRagdollPlugin), "LeashLength_f");
		if (methodInfo2 == null)
		{
			ExtremeRagdollPlugin.Log.LogError((object)"Failed to resolve ExtremeRagdollPlugin.LeashLength — signature mismatch.");
		}
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		bool flag = false;
		for (int i = 0; i < list.Count; i++)
		{
			if (list[i].opcode == OpCodes.Call && list[i].operand == methodInfo)
			{
				int num = i - 2;
				if (num >= 0 && list[num].opcode == OpCodes.Ldc_R4)
				{
					list[num].opcode = OpCodes.Call;
					list[num].operand = methodInfo2;
					flag = true;
				}
				else
				{
					ExtremeRagdollPlugin.Log.LogWarning((object)$"Expected ldc.r4 two instructions before NavMesh.SamplePosition, found {list[num].opcode} instead.");
				}
			}
		}
		if (!flag)
		{
			ExtremeRagdollPlugin.Log.LogWarning((object)"Cannot find NavMesh.SamplePosition call in Character.FixedUpdate");
		}
		return list;
	}
}
[BepInPlugin("johbenji.extremeragdoll", "Extreme Ragdoll", "1.2.0")]
public class ExtremeRagdollPlugin : BaseUnityPlugin
{
	public const string GUID = "johbenji.extremeragdoll";

	public const string NAME = "Extreme Ragdoll";

	public const string VERSION = "1.2.0";

	public static int leashLength;

	internal static ManualLogSource Log;

	public static ExtremeRagdollPlugin Instance { get; private set; }

	public static int LeashLength_i
	{
		get
		{
			return leashLength;
		}
		private set
		{
			leashLength = value;
		}
	}

	public static float LeashLength_f => leashLength;

	internal void Awake()
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		ConfigElements.Init(((BaseUnityPlugin)this).Config);
		float num = (ConfigElements.ragdollScale.Value - 1f) / 30f;
		LeashLength_i = Mathf.RoundToInt(Mathf.Lerp(25f, 700f, Mathf.Clamp(num, 0f, 1f)));
		new Harmony("johbenji.extremeragdoll").PatchAll();
	}

	public bool isPlayerCharacter(Character _character)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		if ((int)_character.InstantiationType == 1)
		{
			for (int i = 0; i < CharacterManager.Instance.PlayerCharacters.Count; i++)
			{
				Character character = CharacterManager.Instance.GetCharacter(((object)_character.UID/*cast due to .constrained prefix*/).ToString());
				if ((Object)(object)character != (Object)null)
				{
					return true;
				}
			}
		}
		return false;
	}
}