Decompiled source of Frailty v1.0.0

DiversityLib.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
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: AssemblyTitle("DiversityLib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DiversityLib")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f3aa347e-bdfa-4c6a-b93f-1429e4f206c4")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[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 DiversityLib
{
	public static class DiversityLib
	{
		public static Texture2D RenderToTexture2D(this RenderTexture rTex)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(((Texture)rTex).width, ((Texture)rTex).height, (TextureFormat)4, false);
			RenderTexture.active = rTex;
			val.ReadPixels(new Rect(0f, 0f, (float)((Texture)rTex).width, (float)((Texture)rTex).height), 0, 0);
			val.Apply();
			return val;
		}

		public static Color[] GetPixels(this RenderTexture texture)
		{
			Texture2D val = texture.RenderToTexture2D();
			return val.GetPixels();
		}

		public static float CalculateAverageLuminance(this RenderTexture texture, bool useAlpha = false)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			Texture2D val = texture.RenderToTexture2D();
			float num = ((Texture)val).width * ((Texture)val).height;
			float num2 = 0f;
			Color[] pixels = val.GetPixels();
			foreach (Color color in pixels)
			{
				num2 += color.CalculateLuminance(useAlpha);
			}
			return num2 / num;
		}

		public static float CalculateAverageLuminance(this Texture2D texture, bool useAlpha = false)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Texture)texture).width * ((Texture)texture).height;
			float num2 = 0f;
			Color[] pixels = texture.GetPixels();
			foreach (Color color in pixels)
			{
				num2 += color.CalculateLuminance(useAlpha);
			}
			return num2 / num;
		}

		public static float CalculateAverageLuminance(this Color[] colorArray, bool useAlpha = false)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			float num = colorArray.Length;
			float num2 = 0f;
			foreach (Color color in colorArray)
			{
				num2 += color.CalculateLuminance(useAlpha);
			}
			return num2 / num;
		}

		public static Color AverageDifference(this Texture2D texture, Texture2D secondTexture)
		{
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Texture)texture).width * ((Texture)texture).height;
			float num2 = 0f;
			float num3 = 0f;
			float num4 = 0f;
			float num5 = 0f;
			for (int i = 0; i < ((Texture)texture).width; i++)
			{
				for (int j = 0; j < ((Texture)texture).height; j++)
				{
					Color pixel = texture.GetPixel(i, j);
					Color pixel2 = secondTexture.GetPixel(i, j);
					num2 += Mathf.Abs(pixel.r - pixel2.r);
					num3 += Mathf.Abs(pixel.g - pixel2.g);
					num4 += Mathf.Abs(pixel.b - pixel2.b);
					num5 += Mathf.Abs(pixel.a - pixel2.a);
				}
			}
			num2 /= num;
			num3 /= num;
			num4 /= num;
			num5 /= num;
			return new Color(num2, num3, num4, num5);
		}

		public static float BW(this Color col)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return col.r + col.g + col.b;
		}

		public static float CalculateLuminance(this Color color, bool useAlpha = false)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			return 0.299f * color.r * (useAlpha ? color.a : 1f) + 0.587f * color.g * (useAlpha ? color.a : 1f) + 0.114f * color.b * (useAlpha ? color.a : 1f);
		}

		public static Color GetAverageRGBA(this RenderTexture texture)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			Texture2D texture2 = texture.RenderToTexture2D();
			return texture2.GetAverageRGBA();
		}

		public static Color GetAverageRGBA(this Texture2D texture)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Texture)texture).width * ((Texture)texture).height;
			float num2 = 0f;
			float num3 = 0f;
			float num4 = 0f;
			float num5 = 0f;
			Color[] pixels = texture.GetPixels();
			foreach (Color val in pixels)
			{
				num2 += val.r;
				num3 += val.g;
				num4 += val.b;
				num5 += val.a;
			}
			return new Color(num2 / num, num3 / num, num4 / num, num5 / num);
		}

		public static Color GetAverageRGBA(this Color[] colorArray)
		{
			//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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			float num = colorArray.Length;
			float num2 = 0f;
			float num3 = 0f;
			float num4 = 0f;
			float num5 = 0f;
			foreach (Color val in colorArray)
			{
				num2 += val.r;
				num3 += val.g;
				num4 += val.b;
				num5 += val.a;
			}
			return new Color(num2 / num, num3 / num, num4 / num, num5 / num);
		}

		public static float Remap(this float value, float from1, float to1, float from2, float to2)
		{
			return (value - from1) / (to1 - from1) * (to2 - from2) + from2;
		}

		public static float OneMinus(this float f)
		{
			return 1f - f;
		}

		public static float Negate(this float f)
		{
			return 0f - f;
		}

		public static uint Random(this uint u)
		{
			Random random = new Random();
			uint num = (uint)random.Next(1073741824);
			uint num2 = (uint)random.Next(4);
			return (num << 2) | num2;
		}

		public static float Volume(this Vector3 v3)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return v3.x * v3.y * v3.z;
		}
	}
}

Frailty.dll

Decompiled 2 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Frailty.Manager;
using Frailty.Patches;
using Frailty.Properties;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Frailty")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Frailty")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fe19d81f-566d-4e7e-aa89-f207acbc7d11")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Frailty
{
	public class Configuration
	{
		public static ConfigEntry<bool> fracturedLeg;

		public static ConfigEntry<float> fracturedLegTime;

		public static ConfigEntry<float> fracturedLegChance;

		public static ConfigEntry<bool> fracturedArm;

		public static ConfigEntry<float> fracturedArmTime;

		public static ConfigEntry<float> fracturedArmChance;

		public static ConfigEntry<bool> brokenLeg;

		public static ConfigEntry<float> brokenLegTime;

		public static ConfigEntry<float> brokenLegChance;

		public static ConfigEntry<bool> brokenArm;

		public static ConfigEntry<float> brokenArmTime;

		public static ConfigEntry<float> brokenArmChance;

		public static ConfigEntry<bool> bleeding;

		public static ConfigEntry<float> bleedingTime;

		public static ConfigEntry<float> bleedingChance;

		public static ConfigEntry<bool> blindness;

		public static ConfigEntry<float> blindnessTime;

		public static ConfigEntry<float> blindnessChance;

		public static ConfigEntry<bool> concussed;

		public static ConfigEntry<float> concussedTime;

		public static ConfigEntry<float> concussedChance;

		public static void Load()
		{
			fracturedLeg = Plugin.config.Bind<bool>("Conditions", "Fractured Leg", true, "Can players fracture their legs? (Will also disable broken legs.)");
			fracturedLegTime = Plugin.config.Bind<float>("Condition Times", "Fractured Leg Time", 120f, "How long should fractured legs last?");
			fracturedLegChance = Plugin.config.Bind<float>("Condition Chances", "Fractured Leg Chance", 0.25f, "Chance of fractured legs to occur. (From 0 to 1.)");
			fracturedArm = Plugin.config.Bind<bool>("Conditions", "Fractured Arm", true, "Can players fracture their arms? (Will also disable broken arms.");
			fracturedArmTime = Plugin.config.Bind<float>("Condition Times", "Fractured Arm Time", 120f, "How long should fractured arms last?");
			fracturedArmChance = Plugin.config.Bind<float>("Condition Chances", "Fractured Arm Chance", 0.2f, "Chance of fractured arms to occur. (From 0 to 1.)");
			brokenLeg = Plugin.config.Bind<bool>("Conditions", "Broken Leg", true, "Can players break their legs?");
			brokenLegTime = Plugin.config.Bind<float>("Condition Times", "Broken Leg Time", 180f, "How long should broken legs last?");
			brokenLegChance = Plugin.config.Bind<float>("Condition Chances", "Broken Leg Chance", 0.25f, "Chance of broken legs to occur. (From 0 to 1.)");
			brokenArm = Plugin.config.Bind<bool>("Conditions", "Broken Arm", true, "Can players break their arms?");
			brokenArmTime = Plugin.config.Bind<float>("Condition Times", "Broken Arm Time", 180f, "How long should broken arms last?");
			brokenArmChance = Plugin.config.Bind<float>("Condition Chances", "Broken Arm Chance", 0.2f, "Chance of broken arms to occur. (From 0 to 1.)");
			bleeding = Plugin.config.Bind<bool>("Conditions", "Bleeding", true, "Can players bleed?");
			bleedingTime = Plugin.config.Bind<float>("Condition Times", "Bleeding Time", 45f, "How long should bleeding last?");
			bleedingChance = Plugin.config.Bind<float>("Condition Chances", "Bleeding Chance", 0.25f, "Chance of bleeding to occur. (From 0 to 1.)");
			blindness = Plugin.config.Bind<bool>("Conditions", "Blindness", true, "Can players be blinded?");
			blindnessTime = Plugin.config.Bind<float>("Condition Times", "Blindness Time", 15f, "How long should blindness last? (in seconds)");
			blindnessChance = Plugin.config.Bind<float>("Condition Chances", "Blindness Chance", 0.1f, "Chance of blindness to occur. (From 0 to 1.)");
			concussed = Plugin.config.Bind<bool>("Conditions", "Concussed", true, "Can players concussed?");
			concussedTime = Plugin.config.Bind<float>("Condition Times", "Concussed Time", 30f, "How long should concussed last? (in seconds)");
			concussedChance = Plugin.config.Bind<float>("Condition Chances", "Concussed Chance", 0.1f, "Chance of concussed to occur. (From 0 to 1.)");
		}
	}
	public class Content
	{
		public static AssetBundle MainContent;

		public static void Load()
		{
			Plugin.mls.LogDebug((object)"Loading internal assets...");
			MainContent = AssetBundle.LoadFromMemory(Plugin.assetFile);
			Plugin.mls.LogDebug((object)"Internal assets loaded!");
		}
	}
	[BepInPlugin("Chaos.Frailty", "Frailty", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Chaos.Frailty";

		private const string modName = "Frailty";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Chaos.Frailty");

		public static Plugin Instance;

		public static ManualLogSource mls;

		public static ConfigFile config;

		public static byte[] assetFile;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			assetFile = Resources.frailty;
			mls = ((BaseUnityPlugin)this).Logger;
			config = ((BaseUnityPlugin)this).Config;
			Configuration.Load();
			Content.Load();
			mls.LogDebug((object)"Patching Frailty...");
			harmony.PatchAll(typeof(HUDPatch));
			harmony.PatchAll(typeof(PlayerPatch));
			harmony.PatchAll(typeof(SteamValveHazardPatch));
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
			mls.LogInfo((object)"Frailty loaded.");
		}
	}
}
namespace Frailty.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("Frailty.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] frailty
		{
			get
			{
				object @object = ResourceManager.GetObject("frailty", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Resources()
		{
		}
	}
}
namespace Frailty.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDPatch
	{
		public static GameObject conditionHud;

		public static Transform bleedingHud;

		public static Transform blindnessHud;

		public static Transform brokenArmHud;

		public static Transform brokenLegHud;

		public static Transform concussedHud;

		public static Transform fracturedArmHud;

		public static Transform fracturedLegHud;

		public static Volume concussed;

		public static Volume blindness;

		[HarmonyPatch(typeof(HUDManager), "Awake")]
		[HarmonyPrefix]
		private static void Awake(HUDManager __instance)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			conditionHud = Object.Instantiate<GameObject>(Content.MainContent.LoadAsset<GameObject>("Assets/custom/Frailty/hud/Conditions.prefab"), new Vector3(15.85f, 23.4f, -5.55f), Quaternion.Euler(0f, -14.141f, 0f), __instance.HUDContainer.transform);
			RectTransform component = conditionHud.GetComponent<RectTransform>();
			component.anchoredPosition3D = new Vector3(15.85f, 23.4f, -5.55f);
			((Transform)component).rotation = Quaternion.Euler(0f, -14.141f, 0f);
			((Transform)component).localScale = Vector3.one;
			bleedingHud = conditionHud.transform.Find("Bleeding");
			blindnessHud = conditionHud.transform.Find("Blindness");
			brokenArmHud = conditionHud.transform.Find("BrokenArm");
			brokenLegHud = conditionHud.transform.Find("BrokenLeg");
			concussedHud = conditionHud.transform.Find("Concussed");
			fracturedArmHud = conditionHud.transform.Find("FracturedArm");
			fracturedLegHud = conditionHud.transform.Find("FracturedLeg");
			Plugin.mls.LogDebug((object)"The condition hud has been added.");
			concussed = ((Component)__instance).gameObject.AddComponent<Volume>();
			concussed.profile = Content.MainContent.LoadAsset<VolumeProfile>("Assets/custom/Frailty/volumes/concussed.asset");
			concussed.isGlobal = true;
			concussed.weight = 0f;
			concussed.sharedProfile = Content.MainContent.LoadAsset<VolumeProfile>("Assets/custom/Frailty/volumes/concussed.asset");
			blindness = ((Component)__instance).gameObject.AddComponent<Volume>();
			blindness.profile = Content.MainContent.LoadAsset<VolumeProfile>("Assets/custom/Frailty/volumes/blind.asset");
			blindness.isGlobal = true;
			blindness.weight = 0f;
			blindness.sharedProfile = Content.MainContent.LoadAsset<VolumeProfile>("Assets/custom/Frailty/volumes/blind.asset");
			Plugin.mls.LogDebug((object)"Frailty volumes added!");
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerPatch
	{
		[HarmonyPatch(typeof(PlayerControllerB), "Awake")]
		[HarmonyPrefix]
		private static void Awake(PlayerControllerB __instance)
		{
			if (!Object.op_Implicit((Object)(object)((Component)__instance).gameObject.GetComponent<ConditionManager>()))
			{
				((Component)__instance).gameObject.AddComponent<ConditionManager>();
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
		[HarmonyPrefix]
		private static void DamagePlayer(PlayerControllerB __instance, int damageNumber, bool hasDamageSFX = true, bool callRPC = true, CauseOfDeath causeOfDeath = 0, int deathAnimation = 0, bool fallDamage = false, Vector3 force = default(Vector3))
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			ConditionManager conditionManager = default(ConditionManager);
			if (((Component)__instance).gameObject.TryGetComponent<ConditionManager>(ref conditionManager))
			{
				Plugin.mls.LogDebug((object)(__instance.playerUsername + " got damaged! Triggering OnDamage!"));
				conditionManager.OnDamage(causeOfDeath, damageNumber);
			}
		}
	}
	[HarmonyPatch(typeof(SteamValveHazard))]
	internal class SteamValveHazardPatch
	{
		[HarmonyPatch(typeof(SteamValveHazard), "Update")]
		[HarmonyPrefix]
		private static void Update(SteamValveHazard __instance)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			ConditionManager conditionManager = default(ConditionManager);
			if (__instance.valveHasBurst && Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)__instance.valveAudio).transform.position) < 9f && ((Component)GameNetworkManager.Instance.localPlayerController).gameObject.TryGetComponent<ConditionManager>(ref conditionManager))
			{
				conditionManager.OnDamage(OtherDamageType.Gaz);
			}
		}
	}
}
namespace Frailty.Manager
{
	public class ConditionManager : NetworkBehaviour
	{
		public List<Condition> conditions = new List<Condition>();

		private PlayerControllerB player;

		private float concussedIntensity = 0f;

		private float blindnessIntensity = 0f;

		private void Start()
		{
			player = ((Component)this).GetComponent<PlayerControllerB>();
		}

		private void Update()
		{
			if (((NetworkBehaviour)this).IsOwner && (Object)(object)player == (Object)(object)StartOfRound.Instance.localPlayerController)
			{
				HUDPatch.concussed.weight = Mathf.Lerp(HUDPatch.concussed.weight, concussedIntensity, 2f * Time.deltaTime);
				HUDPatch.blindness.weight = Mathf.Lerp(HUDPatch.blindness.weight, blindnessIntensity, 2f * Time.deltaTime);
			}
			if (((NetworkBehaviour)this).IsOwner && player.isPlayerControlled)
			{
				if ((Object)(object)HUDPatch.concussed == (Object)null || (Object)(object)HUDPatch.blindness == (Object)null)
				{
					return;
				}
				foreach (Condition item in conditions.ToList())
				{
					float num = item.startTime + item.duration - Time.realtimeSinceStartup;
					if (num <= 0f)
					{
						RemoveConditionServerRpc(item.type);
						continue;
					}
					float num2 = 1f;
					if (player.drunkness > 0.02f)
					{
						num2 *= Mathf.Abs(StartOfRound.Instance.drunknessSpeedEffect.Evaluate(player.drunkness) - 1.25f);
					}
					switch (item.type)
					{
					case ConditionType.BrokenLeg:
						if (player.isSprinting)
						{
							player.sprintMeter = Mathf.Clamp(player.sprintMeter - Time.deltaTime / (player.sprintTime / 1.5f) * player.carryWeight * num2, 0f, 1f);
						}
						else if (player.isMovementHindered > 0)
						{
							if (player.isWalking)
							{
								player.sprintMeter = Mathf.Clamp(player.sprintMeter - Time.deltaTime / (player.sprintTime / 1.5f) * num2 * 0.5f, 0f, 1f);
							}
						}
						else if (!player.isWalking)
						{
							player.sprintMeter = Mathf.Clamp(player.sprintMeter + Time.deltaTime / (player.sprintTime / 1.5f + 4f) * num2, 0f, 1f);
						}
						else
						{
							player.sprintMeter = Mathf.Clamp(player.sprintMeter + Time.deltaTime / (player.sprintTime / 1.5f + 9f) * num2, 0f, 1f);
						}
						break;
					case ConditionType.BrokenArm:
						if ((Object)(object)player.currentlyHeldObject != (Object)null)
						{
							GrabbableObject currentlyHeldObject2 = player.currentlyHeldObject;
							Item itemProperties3 = currentlyHeldObject2.itemProperties;
							float num5 = Mathf.Clamp(itemProperties3.weight - 1f, 0f, 100f) * 105f;
							if (num5 > 15f && ((NetworkBehaviour)player).IsOwner)
							{
								if (player.timeSinceSwitchingSlots < 0.2f || player.isGrabbingObjectAnimation || player.timeSinceSwitchingSlots < 0.2f || player.isTypingChat || player.inSpecialInteractAnimation || player.activatingItem)
								{
									return;
								}
								((MonoBehaviour)player).StartCoroutine(player.waitToEndOfFrameToDiscard());
							}
						}
						else
						{
							if (!((Object)(object)player.currentlyHeldObjectServer != (Object)null))
							{
								break;
							}
							GrabbableObject currentlyHeldObjectServer2 = player.currentlyHeldObjectServer;
							Item itemProperties4 = currentlyHeldObjectServer2.itemProperties;
							float num6 = Mathf.Clamp(itemProperties4.weight - 1f, 0f, 100f) * 105f;
							if (num6 > 15f && ((NetworkBehaviour)player).IsOwner)
							{
								if (player.timeSinceSwitchingSlots < 0.2f || player.isGrabbingObjectAnimation || player.timeSinceSwitchingSlots < 0.2f || player.isTypingChat || player.inSpecialInteractAnimation || player.activatingItem)
								{
									return;
								}
								((MonoBehaviour)player).StartCoroutine(player.waitToEndOfFrameToDiscard());
							}
						}
						break;
					case ConditionType.FracturedLeg:
						if (player.isSprinting)
						{
							player.sprintMeter = Mathf.Clamp(player.sprintMeter - Time.deltaTime / (player.sprintTime / 1.2f) * player.carryWeight * num2, 0f, 1f);
						}
						else if (player.isMovementHindered > 0)
						{
							if (player.isWalking)
							{
								player.sprintMeter = Mathf.Clamp(player.sprintMeter - Time.deltaTime / (player.sprintTime / 1.2f) * num2 * 0.5f, 0f, 1f);
							}
						}
						else if (!player.isWalking)
						{
							player.sprintMeter = Mathf.Clamp(player.sprintMeter + Time.deltaTime / (player.sprintTime / 1.2f + 4f) * num2, 0f, 1f);
						}
						else
						{
							player.sprintMeter = Mathf.Clamp(player.sprintMeter + Time.deltaTime / (player.sprintTime / 1.2f + 9f) * num2, 0f, 1f);
						}
						break;
					case ConditionType.FracturedArm:
						if ((Object)(object)player.currentlyHeldObject != (Object)null)
						{
							GrabbableObject currentlyHeldObject = player.currentlyHeldObject;
							Item itemProperties = currentlyHeldObject.itemProperties;
							float num3 = Mathf.Clamp(itemProperties.weight - 1f, 0f, 100f) * 105f;
							if (num3 > 25f && ((NetworkBehaviour)player).IsOwner)
							{
								if (player.timeSinceSwitchingSlots < 0.2f || player.isGrabbingObjectAnimation || player.timeSinceSwitchingSlots < 0.2f || player.isTypingChat || player.inSpecialInteractAnimation || player.activatingItem)
								{
									return;
								}
								((MonoBehaviour)player).StartCoroutine(player.waitToEndOfFrameToDiscard());
							}
						}
						else
						{
							if (!((Object)(object)player.currentlyHeldObjectServer != (Object)null))
							{
								break;
							}
							GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer;
							Item itemProperties2 = currentlyHeldObjectServer.itemProperties;
							float num4 = Mathf.Clamp(itemProperties2.weight - 1f, 0f, 100f) * 105f;
							if (num4 > 25f && ((NetworkBehaviour)player).IsOwner)
							{
								if (player.timeSinceSwitchingSlots < 0.2f || player.isGrabbingObjectAnimation || player.timeSinceSwitchingSlots < 0.2f || player.isTypingChat || player.inSpecialInteractAnimation || player.activatingItem)
								{
									return;
								}
								((MonoBehaviour)player).StartCoroutine(player.waitToEndOfFrameToDiscard());
							}
						}
						break;
					case ConditionType.Bleeding:
						player.healthRegenerateTimer = 1f;
						break;
					case ConditionType.Blindness:
						blindnessIntensity = 1f;
						break;
					case ConditionType.Concussed:
						concussedIntensity = 1f;
						break;
					}
				}
			}
			foreach (Condition item2 in conditions.ToList())
			{
				switch (item2.type)
				{
				case ConditionType.BrokenLeg:
					player.limpMultiplier = 1f;
					break;
				case ConditionType.Bleeding:
					player.bleedingHeavily = true;
					break;
				}
			}
			if (!HasCondition(ConditionType.Bleeding))
			{
				player.bleedingHeavily = false;
			}
			if (conditions.Count > 0 && player.isPlayerDead)
			{
				Plugin.mls.LogDebug((object)"PLAYER IS DEAD! REMOVING CONDITIONS!");
				if (((NetworkBehaviour)this).IsOwner)
				{
					ClearAllConditions();
				}
			}
		}

		public void OnDamage(CauseOfDeath damageType, int damage)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Invalid comparison between Unknown and I4
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Invalid comparison between Unknown and I4
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Invalid comparison between Unknown and I4
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Invalid comparison between Unknown and I4
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Invalid comparison between Unknown and I4
			if (!((NetworkBehaviour)this).IsOwner)
			{
				return;
			}
			if ((int)damageType == 6 || (int)damageType == 7 || (int)damageType == 15 || (int)damageType == 17 || (int)damageType == 14)
			{
				if (ShouldApplyCondition(((int)damageType == 7) ? 1f : Configuration.bleedingChance.Value, damage) && Configuration.bleeding.Value)
				{
					AddConditionServerRpc(ConditionType.Bleeding, Configuration.bleedingTime.Value);
				}
			}
			else if ((int)damageType == 1 || (int)damageType == 3 || (int)damageType == 12 || (int)damageType == 16)
			{
				if (ShouldApplyCondition(Configuration.concussedChance.Value, damage) && Configuration.concussed.Value)
				{
					AddConditionServerRpc(ConditionType.Concussed, Configuration.concussedTime.Value);
				}
				if (!ShouldApplyCondition(HasCondition(ConditionType.FracturedArm) ? Configuration.brokenArmChance.Value : Configuration.fracturedArmChance.Value, damage))
				{
					return;
				}
				if (!HasCondition(ConditionType.FracturedArm) && !HasCondition(ConditionType.BrokenArm))
				{
					if (Configuration.fracturedArm.Value)
					{
						AddConditionServerRpc(ConditionType.FracturedArm, Configuration.fracturedArmTime.Value);
					}
					return;
				}
				if (HasCondition(ConditionType.FracturedArm))
				{
					RemoveConditionServerRpc(ConditionType.FracturedArm);
				}
				if (Configuration.brokenArm.Value)
				{
					AddConditionServerRpc(ConditionType.BrokenArm, Configuration.brokenArmTime.Value);
				}
			}
			else if ((int)damageType == 2)
			{
				if (!ShouldApplyCondition(HasCondition(ConditionType.FracturedLeg) ? Configuration.brokenLegChance.Value : Configuration.fracturedLegChance.Value, damage))
				{
					return;
				}
				if (!HasCondition(ConditionType.FracturedLeg) && !HasCondition(ConditionType.BrokenLeg))
				{
					if (Configuration.fracturedLeg.Value)
					{
						AddConditionServerRpc(ConditionType.FracturedLeg, Configuration.fracturedLegTime.Value);
					}
					return;
				}
				RemoveConditionServerRpc(ConditionType.FracturedLeg);
				if (Configuration.brokenLeg.Value)
				{
					AddConditionServerRpc(ConditionType.BrokenLeg, Configuration.brokenLegTime.Value);
				}
			}
			else
			{
				Plugin.mls.LogWarning((object)("Damage type isn't supported yet: " + ((object)(CauseOfDeath)(ref damageType)).ToString()));
			}
		}

		public void OnDamage(OtherDamageType damageType)
		{
			if (((NetworkBehaviour)this).IsOwner && damageType == OtherDamageType.Gaz && ShouldApplyCondition(Configuration.blindnessChance.Value, 0) && Configuration.blindness.Value)
			{
				AddConditionServerRpc(ConditionType.Blindness, Configuration.blindnessTime.Value);
			}
		}

		public void OnDeath()
		{
			if (((NetworkBehaviour)this).IsOwner)
			{
				ClearAllConditions();
			}
		}

		private void ClearAllConditions()
		{
			Plugin.mls.LogDebug((object)("Removing all conditions of " + player.playerUsername + "."));
			foreach (Condition item in conditions.ToList())
			{
				RemoveConditionServerRpc(item.type);
			}
		}

		private float CalculateConditionProbability(int damage)
		{
			return (player.health == 0) ? 1f : Mathf.Clamp01((float)((1 + (1 - player.health / 100)) / 2 + damage / player.health / 2));
		}

		private bool ShouldApplyCondition(float chance, int damage)
		{
			return Random.value * CalculateConditionProbability(damage) <= chance;
		}

		[ServerRpc]
		public void AddConditionServerRpc(ConditionType type, float duration)
		{
			AddConditionClientRpc(type, duration);
		}

		[ClientRpc]
		public void AddConditionClientRpc(ConditionType type, float duration)
		{
			if (player.isPlayerDead)
			{
				return;
			}
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (HasCondition(type))
			{
				conditions.Where((Condition x) => x.type == type).ToArray()[0].duration = duration;
				conditions.Where((Condition x) => x.type == type).ToArray()[0].startTime = realtimeSinceStartup;
			}
			else
			{
				conditions.Add(new Condition
				{
					startTime = realtimeSinceStartup,
					duration = duration,
					type = type
				});
			}
			if (((NetworkBehaviour)this).IsOwner)
			{
				ShowConditionHUD(type);
			}
			Plugin.mls.LogDebug((object)("Player '" + player.playerUsername + "' received the condition: " + type.ToString() + "."));
		}

		private void ShowConditionHUD(ConditionType type)
		{
			switch (type)
			{
			case ConditionType.BrokenLeg:
				HUDPatch.brokenLegHud.SetAsFirstSibling();
				((Component)HUDPatch.brokenLegHud).gameObject.SetActive(true);
				((Component)HUDPatch.brokenLegHud).GetComponent<Animator>().SetBool("Visible", true);
				break;
			case ConditionType.BrokenArm:
				HUDPatch.brokenArmHud.SetAsFirstSibling();
				((Component)HUDPatch.brokenArmHud).gameObject.SetActive(true);
				((Component)HUDPatch.brokenArmHud).GetComponent<Animator>().SetBool("Visible", true);
				break;
			case ConditionType.FracturedLeg:
				HUDPatch.fracturedLegHud.SetAsFirstSibling();
				((Component)HUDPatch.fracturedLegHud).gameObject.SetActive(true);
				((Component)HUDPatch.fracturedLegHud).GetComponent<Animator>().SetBool("Visible", true);
				break;
			case ConditionType.FracturedArm:
				HUDPatch.fracturedArmHud.SetAsFirstSibling();
				((Component)HUDPatch.fracturedArmHud).gameObject.SetActive(true);
				((Component)HUDPatch.fracturedArmHud).GetComponent<Animator>().SetBool("Visible", true);
				break;
			case ConditionType.Bleeding:
				HUDPatch.bleedingHud.SetAsFirstSibling();
				((Component)HUDPatch.bleedingHud).gameObject.SetActive(true);
				((Component)HUDPatch.bleedingHud).GetComponent<Animator>().SetBool("Visible", true);
				break;
			case ConditionType.Blindness:
				HUDPatch.blindnessHud.SetAsFirstSibling();
				((Component)HUDPatch.blindnessHud).gameObject.SetActive(true);
				((Component)HUDPatch.blindnessHud).GetComponent<Animator>().SetBool("Visible", true);
				break;
			case ConditionType.Concussed:
				HUDPatch.concussedHud.SetAsFirstSibling();
				((Component)HUDPatch.concussedHud).gameObject.SetActive(true);
				((Component)HUDPatch.concussedHud).GetComponent<Animator>().SetBool("Visible", true);
				break;
			}
		}

		private void HideConditionHUD(ConditionType type)
		{
			switch (type)
			{
			case ConditionType.BrokenLeg:
				((Component)HUDPatch.brokenLegHud).GetComponent<Animator>().SetBool("Visible", false);
				((MonoBehaviour)this).StartCoroutine(WaitFade(((Component)HUDPatch.brokenLegHud).GetComponent<Animator>()));
				break;
			case ConditionType.BrokenArm:
				((Component)HUDPatch.brokenArmHud).GetComponent<Animator>().SetBool("Visible", false);
				((MonoBehaviour)this).StartCoroutine(WaitFade(((Component)HUDPatch.brokenArmHud).GetComponent<Animator>()));
				break;
			case ConditionType.FracturedLeg:
				((Component)HUDPatch.fracturedLegHud).GetComponent<Animator>().SetBool("Visible", false);
				((MonoBehaviour)this).StartCoroutine(WaitFade(((Component)HUDPatch.fracturedLegHud).GetComponent<Animator>()));
				break;
			case ConditionType.FracturedArm:
				((Component)HUDPatch.fracturedArmHud).GetComponent<Animator>().SetBool("Visible", false);
				((MonoBehaviour)this).StartCoroutine(WaitFade(((Component)HUDPatch.fracturedArmHud).GetComponent<Animator>()));
				break;
			case ConditionType.Bleeding:
				((Component)HUDPatch.bleedingHud).GetComponent<Animator>().SetBool("Visible", false);
				((MonoBehaviour)this).StartCoroutine(WaitFade(((Component)HUDPatch.bleedingHud).GetComponent<Animator>()));
				break;
			case ConditionType.Blindness:
				((Component)HUDPatch.blindnessHud).GetComponent<Animator>().SetBool("Visible", false);
				((MonoBehaviour)this).StartCoroutine(WaitFade(((Component)HUDPatch.blindnessHud).GetComponent<Animator>()));
				break;
			case ConditionType.Concussed:
				((Component)HUDPatch.concussedHud).GetComponent<Animator>().SetBool("Visible", false);
				((MonoBehaviour)this).StartCoroutine(WaitFade(((Component)HUDPatch.concussedHud).GetComponent<Animator>()));
				break;
			}
		}

		[ServerRpc]
		public void RemoveConditionServerRpc(ConditionType type)
		{
			RemoveConditionClientRpc(type);
		}

		[ClientRpc]
		public void RemoveConditionClientRpc(ConditionType type)
		{
			if (!HasCondition(type))
			{
				return;
			}
			conditions.Remove(conditions.Where((Condition x) => x.type == type).ToArray()[0]);
			if (((NetworkBehaviour)this).IsOwner)
			{
				HideConditionHUD(type);
				switch (type)
				{
				case ConditionType.Blindness:
					blindnessIntensity = 0f;
					break;
				case ConditionType.Concussed:
					concussedIntensity = 0f;
					break;
				}
			}
			Plugin.mls.LogDebug((object)("Player '" + player.playerUsername + "' lost the condition: " + type.ToString() + "."));
		}

		private bool HasCondition(ConditionType type)
		{
			return conditions.Any((Condition x) => x.type == type);
		}

		public IEnumerator WaitFade(Animator anim)
		{
			yield return (object)new WaitUntil((Func<bool>)delegate
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				AnimatorStateInfo currentAnimatorStateInfo = anim.GetCurrentAnimatorStateInfo(1);
				return ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime >= 1f;
			});
			((Component)anim).gameObject.SetActive(false);
		}
	}
	public class Condition
	{
		public float startTime;

		public float duration;

		public ConditionType type;
	}
	public enum ConditionType
	{
		BrokenLeg,
		BrokenArm,
		FracturedLeg,
		FracturedArm,
		Bleeding,
		Blindness,
		Concussed
	}
	public enum OtherDamageType
	{
		Gaz
	}
}