Decompiled source of BrokenLimbs v0.1.1

plugins/com.shiro.brokenlimbs.dll

Decompiled 6 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BrokenLimbs;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.shiro.BrokenLimbs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+c4194f351f7cf8304aa39649a60e5752b9e1698b")]
[assembly: AssemblyProduct("com.shiro.BrokenLimbs")]
[assembly: AssemblyTitle("BrokenLimbs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.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;
		}
	}
	[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;
		}
	}
}
public class Limb
{
	public string Name;

	public Color Color;

	public Rect sizeRect;

	public bool Draw;

	private Body body = Object.FindFirstObjectByType<Logic>().body;

	public float health;

	public float Health
	{
		get
		{
			return health;
		}
		set
		{
			health = Mathf.Clamp(value, 0f, 100f);
			UpdateColor(health);
			Effects(health);
		}
	}

	public Limb(string name, Color color, Rect rect, float health = 100f, bool draw = true)
	{
		//IL_001e: 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)
		Name = name;
		sizeRect = rect;
		Draw = draw;
		Health = health;
	}

	private void UpdateColor(float h)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		float num = h / 100f;
		if (h <= 0f)
		{
			Color = Color.black;
			health = 0f;
		}
		else if (num < 0.5f)
		{
			Color = Color.Lerp(Color.black, Color.red, num * 2f);
		}
		else
		{
			Color = Color.Lerp(Color.red, Color.white, (num - 0.5f) * 2f);
		}
	}

	private void Effects(float hp)
	{
		string name = Name;
		switch (name)
		{
		default:
			_ = name == "Torso";
			break;
		case "Foot_L":
			body.FootEffect(hp);
			break;
		case "Foot_R":
			body.FootEffect(hp);
			break;
		case "Arm_L":
			break;
		case "Arm_R":
			break;
		}
	}

	public void Damage(float dmg)
	{
		Health -= dmg;
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BrokenLimbs
{
	public class Body
	{
		public Limb head;

		public Limb torso;

		public Limb arm_L;

		public Limb arm_R;

		public Limb foot_L;

		public Limb foot_R;

		public bool hardcoreMode = Plugin.BoundConfig.hardcoreMode.Value;

		public static List<Limb> limbs;

		public bool sprintingEnabled = true;

		public Body()
		{
			limbs = new List<Limb> { head, torso, arm_L, arm_R, foot_L, foot_R };
		}

		public void FootEffect(float hp)
		{
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null || hardcoreMode)
			{
				return;
			}
			if (hp <= 0f)
			{
				if (foot_L.health == 0f && foot_R.health == 0f)
				{
					localCharacter.refs.movement.movementModifier = Plugin.BoundConfig.footBrokenPenalty.Value;
					localCharacter.data.isCrouching = true;
					localCharacter.refs.movement.crouchToggleEnabled = false;
					sprintingEnabled = false;
				}
				else
				{
					localCharacter.refs.movement.movementModifier = Plugin.BoundConfig.footBrokenPenalty.Value;
					localCharacter.refs.movement.crouchToggleEnabled = false;
					sprintingEnabled = false;
				}
			}
			else
			{
				Debug.Log((object)"hi");
				localCharacter.refs.movement.movementModifier = 1f;
				localCharacter.refs.movement.crouchToggleEnabled = true;
				localCharacter.data.isCrouching = false;
				sprintingEnabled = true;
			}
		}

		public void ArmEffect(float hp)
		{
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null || hardcoreMode)
			{
				return;
			}
			if (hp <= 0f)
			{
				if (arm_L.health == 0f && arm_R.health == 0f)
				{
					localCharacter.refs.climbing.climbToggledOn = false;
				}
				else
				{
					localCharacter.refs.climbing.climbSpeedMod = 0.5f;
				}
			}
			else
			{
				localCharacter.refs.climbing.climbToggledOn = true;
				localCharacter.refs.climbing.climbSpeedMod = 1f;
			}
		}

		public void TorsoEffect(float hp)
		{
			Character localCharacter = Character.localCharacter;
			if (!((Object)(object)localCharacter == (Object)null) && !hardcoreMode)
			{
				_ = 0f;
			}
		}

		public void ResetHealth()
		{
			foreach (Limb limb in limbs)
			{
				if (limb != null && limb.Health < 100f)
				{
					limb.Health = 100f;
					Debug.Log((object)("Reset health of " + limb.Name));
				}
			}
		}

		public List<Limb> GetLimbs()
		{
			return new List<Limb> { head, torso, arm_L, arm_R, foot_L, foot_R };
		}

		public Limb GetLimb(string name)
		{
			return name.ToLower() switch
			{
				"head" => head, 
				"torso" => torso, 
				"arm_r" => arm_R, 
				"arm_l" => arm_L, 
				"foot_r" => foot_R, 
				"foot_l" => foot_L, 
				_ => null, 
			};
		}
	}
	public class BrokenLimbsUI : MonoBehaviour
	{
		private static Body body;

		private static Logic logic = new Logic();

		private void Start()
		{
			logic = Object.FindFirstObjectByType<Logic>();
			body = logic.body;
		}

		public void OnGUI()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if ((Object)(object)Character.localCharacter == (Object)null || !name.Contains("Level"))
			{
				return;
			}
			foreach (Limb limb in body.GetLimbs())
			{
				if (limb.Draw)
				{
					DrawLimb(limb);
				}
			}
		}

		private void DrawLimb(Limb limb)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			Color color = limb.Color;
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, color);
			val.Apply();
			GUIStyle val2 = new GUIStyle(GUI.skin.box);
			val2.normal.background = val;
			GUI.backgroundColor = color;
			GUI.Box(limb.sizeRect, "", val2);
		}
	}
	public class Command
	{
		public string Name;

		public string Description;

		public string Usage;

		public Action<string[]> Execute;

		public Command(string name, string description, string usage, Action<string[]> execute)
		{
			Name = name.ToLower();
			Description = description;
			Usage = usage;
			Execute = execute;
		}
	}
	public class CommandManager
	{
		public Dictionary<string, Command> commands = new Dictionary<string, Command>();

		public void RegisterCommand(Command command)
		{
			commands[command.Name.ToLower()] = command;
		}

		public static string[] ParseArguments(string input)
		{
			MatchCollection source = Regex.Matches(input, "[\\\"].+?[\\\"]|'[^']*'|\\S+");
			return (from Match m in source
				select m.Value.Trim().Trim('"', '\'')).ToArray();
		}

		public bool ExecuteCommand(string input)
		{
			if (string.IsNullOrEmpty(input))
			{
				return false;
			}
			string[] array = ParseArguments(input);
			string key = array[0].ToLower();
			string[] obj = array.Skip(1).ToArray();
			if (commands.TryGetValue(key, out Command value))
			{
				value.Execute(obj);
				return true;
			}
			return false;
		}

		public IEnumerable<string> GetCommandList()
		{
			return commands.Values.Select((Command c) => c.Name + " - " + c.Description);
		}

		public IEnumerable<Command> GetCommands()
		{
			return commands.Values;
		}
	}
	public class DebugGui : MonoBehaviour
	{
		private List<string> logMessages = new List<string>();

		private Vector2 scrollPos;

		private string inputText = "";

		private Rect windowRect = new Rect(20f, 20f, 700f, 600f);

		private const int maxLogs = 1000;

		private int logCount;

		private string[] debugLogs = new string[1000];

		private Vector2 debugScrollPos = Vector2.zero;

		private string debugInput = "";

		private int lastLogCount;

		private bool showWindow = true;

		private CommandManager commandManager = new CommandManager();

		public void Start()
		{
			commandManager.RegisterCommand(new Command("Help", "Displays all of the current commands and their descriptions", "help", delegate(string[] args)
			{
				string[] args2 = args;
				GameObject mod5 = Plugin.mod;
				DebugGui component5 = mod5.GetComponent<DebugGui>();
				if (args2.Length == 0)
				{
					foreach (string command2 in component5.commandManager.GetCommandList())
					{
						Debug.Log((object)command2);
					}
					return;
				}
				if (args2.Length == 1)
				{
					Command command = component5.commandManager.GetCommands().FirstOrDefault((Command c) => c.Name.ToLower() == args2[0].ToLower());
					Debug.Log((object)command.Usage);
				}
			}));
			commandManager.RegisterCommand(new Command("Damage", "Damages the limbs health", "Damage <string> <float>", delegate(string[] args)
			{
				GameObject mod4 = Plugin.mod;
				Logic component4 = mod4.GetComponent<Logic>();
				if (args.Length == 2)
				{
					component4.Damage(args[0], float.Parse(args[1]));
				}
			}));
			commandManager.RegisterCommand(new Command("GetHp", "Gets the limbs health", "GetHp <string>", delegate(string[] args)
			{
				GameObject mod3 = Plugin.mod;
				Logic component3 = mod3.GetComponent<Logic>();
				if (args.Length == 1)
				{
					Debug.Log((object)component3.body.GetLimb(args[0]).health);
				}
			}));
			commandManager.RegisterCommand(new Command("SetHealth", "Damages the limbs health", "SetHealth <string> <float>", delegate(string[] args)
			{
				GameObject mod2 = Plugin.mod;
				Logic component2 = mod2.GetComponent<Logic>();
				if (args.Length == 2)
				{
					component2.body.GetLimb(args[0]).Health = float.Parse(args[1]);
				}
			}));
			commandManager.RegisterCommand(new Command("ResetHealth", "Resets the limbs health", "ResetHealth", delegate(string[] args)
			{
				GameObject mod = Plugin.mod;
				Logic component = mod.GetComponent<Logic>();
				if (args.Length == 0)
				{
					component.body.ResetHealth();
				}
			}));
		}

		public void Update()
		{
			if (Input.GetKeyDown((KeyCode)127))
			{
				showWindow = !showWindow;
			}
		}

		private void AddLog(string log)
		{
			if (logCount < 1000)
			{
				debugLogs[logCount] = log;
				logCount++;
				return;
			}
			for (int i = 1; i < 1000; i++)
			{
				debugLogs[i - 1] = debugLogs[i];
			}
			debugLogs[999] = log;
		}

		private void OnEnable()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			Application.logMessageReceived += new LogCallback(HandleLog);
		}

		private void OnDisable()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			Application.logMessageReceived -= new LogCallback(HandleLog);
		}

		private void HandleLog(string logString, string stackTrace, LogType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected I4, but got Unknown
			string log;
			switch ((int)type)
			{
			case 0:
			case 4:
				log = "<color=red>" + logString + " - " + stackTrace + "</color>";
				break;
			case 2:
				log = "<color=yellow>" + logString + "</color>";
				break;
			case 3:
				log = "<color=white>" + logString + "</color>";
				break;
			default:
				log = logString;
				break;
			}
			AddLog(log);
		}

		private void OnGUI()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (showWindow)
			{
				GUI.color = new Color(0f, 0f, 0f, 0.6f);
				GUIStyle val = new GUIStyle(GUI.skin.window);
				val.normal.textColor = Color.white;
				windowRect = GUI.Window(985, windowRect, new WindowFunction(DrawWindow), "Debug Console", val);
			}
		}

		private void DrawWindow(int windowID)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
			debugScrollPos = GUILayout.BeginScrollView(debugScrollPos, false, true, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
			GUI.color = Color.white;
			if (logCount == 0)
			{
				GUILayout.Label("No logs yet.", Array.Empty<GUILayoutOption>());
			}
			else
			{
				for (int i = 0; i < logCount; i++)
				{
					GUILayout.Label(debugLogs[i], Array.Empty<GUILayoutOption>());
				}
			}
			GUILayout.EndScrollView();
			if (logCount > lastLogCount)
			{
				debugScrollPos.y = float.MaxValue;
			}
			lastLogCount = logCount;
			GUI.SetNextControlName("DebugInputField");
			debugInput = GUILayout.TextField(debugInput, Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Enter", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }) && !string.IsNullOrWhiteSpace(debugInput))
			{
				commandManager.ExecuteCommand(debugInput);
				debugInput = "";
			}
			GUILayout.EndVertical();
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref windowRect)).width, 25f));
		}
	}
	public class Logic : MonoBehaviour
	{
		private static Rect windowRect = new Rect((float)(Screen.width / 2), (float)(Screen.height / 2), 200f, 300f);

		private static float margin = 10f;

		private static float padding = 5f;

		private static Character ch;

		private static bool invuln = false;

		private static float invulnTime = 10f;

		private static bool fell = false;

		public Body body = new Body();

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).name.Contains("Level"))
			{
				Debug.Log((object)"scene loaded resetting health.");
				body.ResetHealth();
			}
		}

		public float ConvertImpactVelocityToDamage(float impactVelocity)
		{
			float num = 7.5f;
			float num2 = 30f;
			float num3 = 100f;
			if (impactVelocity < num)
			{
				return 0f;
			}
			float num4 = Mathf.Clamp(impactVelocity, num, num2);
			return (num4 - num) / (num2 - num) * num3;
		}

		private void Start()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			((Rect)(ref windowRect)).x = (float)Screen.width - ((Rect)(ref windowRect)).width / 2f - margin;
			((Rect)(ref windowRect)).y = margin;
			Limb limb = new Limb("Head", Color.white, new Rect(((Rect)(ref windowRect)).x, ((Rect)(ref windowRect)).y, 50f, 50f));
			Limb limb2 = new Limb("Torso", Color.white, new Rect(((Rect)(ref windowRect)).x, ((Rect)(ref limb.sizeRect)).y + ((Rect)(ref limb.sizeRect)).height + padding, ((Rect)(ref limb.sizeRect)).width, ((Rect)(ref limb.sizeRect)).height * 2f));
			Limb limb3 = new Limb("Arm_R", Color.white, new Rect(((Rect)(ref limb2.sizeRect)).x + ((Rect)(ref limb2.sizeRect)).width + padding, ((Rect)(ref limb2.sizeRect)).y, ((Rect)(ref limb.sizeRect)).width / 2f, ((Rect)(ref limb2.sizeRect)).height));
			Limb arm_L = new Limb("Arm_L", Color.white, new Rect(((Rect)(ref limb2.sizeRect)).x - ((Rect)(ref limb3.sizeRect)).width - padding, ((Rect)(ref limb3.sizeRect)).y, ((Rect)(ref limb3.sizeRect)).width, ((Rect)(ref limb3.sizeRect)).height));
			Limb limb4 = new Limb("Foot_L", Color.white, new Rect(((Rect)(ref limb2.sizeRect)).x, ((Rect)(ref limb2.sizeRect)).y + ((Rect)(ref limb2.sizeRect)).height + padding, ((Rect)(ref limb3.sizeRect)).width - padding / 2f, ((Rect)(ref limb3.sizeRect)).height));
			Limb foot_R = new Limb("Foot_R", Color.white, new Rect(((Rect)(ref limb2.sizeRect)).x + ((Rect)(ref limb2.sizeRect)).width - ((Rect)(ref limb4.sizeRect)).width + 1f, ((Rect)(ref limb2.sizeRect)).y + ((Rect)(ref limb2.sizeRect)).height + padding, ((Rect)(ref limb4.sizeRect)).width, ((Rect)(ref limb4.sizeRect)).height));
			body.head = limb;
			body.torso = limb2;
			body.arm_R = limb3;
			body.arm_L = arm_L;
			body.foot_L = limb4;
			body.foot_R = foot_R;
		}

		private void Update()
		{
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			ch = Character.localCharacter;
			if (!((Object)(object)ch != (Object)null))
			{
				return;
			}
			CharacterMovement component = ((Component)ch).GetComponent<CharacterMovement>();
			if (ch.data.sinceGrounded > Plugin.BoundConfig.fallDistance.Value && !ch.data.isClimbingAnything && !ch.data.isJumping && !ch.data.isCarried && !fell)
			{
				ch.Fall(5f);
				Vector3 avarageVelocity = ch.data.avarageVelocity;
				if (((Vector3)(ref avarageVelocity)).magnitude < 0.1f)
				{
					Debug.Log((object)"Movement too small, no force applied.");
				}
				else
				{
					Vector3 val = ((Vector3)(ref avarageVelocity)).normalized * 322f;
					ch.AddForce(val, 1f, 1f);
					Debug.Log((object)$"Force applied: {val}");
				}
				fell = true;
			}
			else if (ch.data.isGrounded)
			{
				fell = false;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (name.Contains("Level") && invulnTime != 0f)
			{
				invulnTime -= Time.deltaTime;
				if (invulnTime <= 0f)
				{
					invulnTime = 0f;
				}
			}
			invuln = invulnTime == 0f;
			if (invuln)
			{
				body.ResetHealth();
			}
		}

		public void Damage(string name, float dmg)
		{
			body.GetLimb(name)?.Damage(dmg);
		}

		public void SetHealth(string name, float healthValue)
		{
			Limb limb = body.GetLimb(name);
			if (limb != null)
			{
				limb.Health = healthValue;
			}
		}
	}
	[BepInPlugin("com.shiro.BrokenLimbs", "BrokenLimbs", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static Harmony har = new Harmony("com.shiro.brokenlimbs");

		public static GameObject mod;

		public const string Id = "com.shiro.BrokenLimbs";

		public static ManualLogSource Log { get; private set; } = null;


		internal static PluginConfig BoundConfig { get; private set; } = null;


		public static string Name => "BrokenLimbs";

		public static string Version => "0.1.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			BoundConfig = new PluginConfig(((BaseUnityPlugin)this).Config);
			try
			{
				har.PatchAll(Assembly.GetExecutingAssembly());
				LoadResources();
			}
			catch (Exception arg)
			{
				Log.LogInfo((object)$"[BrokenLimbs] Harmony patch failed: {arg}");
			}
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private void OnDestroy()
		{
			Harmony obj = har;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			UnloadResources();
		}

		private void LoadResources()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			mod = new GameObject("brokenlimbs");
			mod.AddComponent<DebugGui>();
			mod.AddComponent<BrokenLimbsUI>();
			mod.AddComponent<Logic>();
			Object.DontDestroyOnLoad((Object)(object)mod);
			Log.LogInfo((object)("Mod Object " + ((Object)mod).name + " loaded!"));
		}

		private void UnloadResources()
		{
			Object.Destroy((Object)(object)mod);
			Log.LogInfo((object)("Mod Object " + ((Object)mod).name + " unloaded!"));
		}
	}
	internal class PluginConfig
	{
		public readonly ConfigEntry<float> ragdollDuration;

		public readonly ConfigEntry<float> fallDistance;

		public readonly ConfigEntry<float> footBrokenPenalty;

		public readonly ConfigEntry<bool> hardcoreMode;

		public PluginConfig(ConfigFile cfg)
		{
			cfg.SaveOnConfigSet = false;
			ragdollDuration = cfg.Bind<float>("Settings", "ragdollDuration", 2f, "The maxiumum placement range for the anchor");
			fallDistance = cfg.Bind<float>("Settings", "fallDistance", 1.5f, "The maxiumum ghost range for the anchor");
			hardcoreMode = cfg.Bind<bool>("Settings", "hardcoreMode", false, "Sets wether the mod is in hardcore mode or not");
			footBrokenPenalty = cfg.Bind<float>("Settings", "footBrokenPenalty", 0.6f, "Sets the movement speed penalty for having a broke foot");
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
			dictionary.Clear();
		}
	}
}
namespace BrokenLimbs.Patches
{
	[HarmonyPatch(typeof(Bodypart), "OnCollisionEnter")]
	public class BodyPartPatch
	{
		private static Logic logic = Object.FindFirstObjectByType<Logic>();

		private static string[] limbNames = new string[6] { "Head", "Torso", "Foot_L", "Foot_R", "Arm_L", "Arm_R" };

		private static int vinesLayer = LayerMask.NameToLayer("Vines");

		private static int ropeLayer = LayerMask.NameToLayer("Rope");

		private static int characterLayer = LayerMask.NameToLayer("Character");

		private static int unknownLayer = 0;

		private static bool Prefix(Collision collision, Bodypart __instance)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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_016f: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (!name.Contains("Level"))
			{
				return true;
			}
			if ((Object)(object)__instance.character == (Object)null || __instance.character.data.isGrounded || __instance.character.data.isClimbingAnything)
			{
				return true;
			}
			int layer = collision.gameObject.layer;
			string name2 = ((Object)__instance).name;
			if (limbNames.Contains(name2) && layer != vinesLayer && layer != ropeLayer && layer != characterLayer && layer != unknownLayer && ((Object)collision.gameObject).name != "Elbow_R" && ((Object)collision.gameObject).name != "Elbow_L" && __instance.character.data.sinceGrounded > 0.2f)
			{
				Vector3 relativeVelocity = collision.relativeVelocity;
				float magnitude = ((Vector3)(ref relativeVelocity)).magnitude;
				float num = logic.ConvertImpactVelocityToDamage(magnitude);
				logic.Damage(name2, num);
				Debug.Log((object)$"Name: {name2} taking {num} damage with {magnitude} m/s collided with {((Object)collision.gameObject).name}, layer: {layer}, CPos: {((Component)__instance).transform.position}, ColPos: {collision.transform.position} ");
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(CharacterMovement), "SetMovementState")]
	public class SprintPatch
	{
		private static Logic logic = Object.FindFirstObjectByType<Logic>();

		private static Body body = logic.body;

		private static bool Prefix(SprintPatch __instance)
		{
			if (body != null)
			{
				if (body.sprintingEnabled)
				{
					return true;
				}
				return false;
			}
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}