Decompiled source of DumbWaysToDie v1.0.0

plugins/DumbWaysToDie.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("DumbWaysToDie")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+413bf0adbbc9baabecac242a8cca304a81e367aa")]
[assembly: AssemblyProduct("DumbWaysToDie")]
[assembly: AssemblyTitle("DumbWaysToDie")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DumbWaysToDie
{
	public enum CauseOfDeath
	{
		Other,
		Age,
		Arrowed,
		BlackHole,
		Clouds,
		Drilled,
		Drilling,
		Drowned,
		Electrocuted,
		Exploded,
		Froze,
		Invisible,
		Leashed,
		Macho,
		Meditating,
		Meteored,
		MeteoringSpace,
		MeteoringWater,
		Rocked,
		Rocking,
		Rolled,
		Space,
		Sworded
	}
	[BepInPlugin("lofen.dumbWaysToDie", "Dumb Ways to Die", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static ConfigEntry<bool> Debug;

		internal static ConfigEntry<float> ScaleFactor;

		public static Dictionary<CauseOfDeath, DeathSpriteCreator> Assets = new Dictionary<CauseOfDeath, DeathSpriteCreator>();

		public static string AssetsPath;

		private void Awake()
		{
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Debug = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Debug mode", false, "Always reload textures from files.");
			ScaleFactor = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Sprite Scale Factor", 1.1f, "Custom sprites appear slightly smaller in game and need to be scaled a bit");
			CharacterSelectHandler_online.clientSideMods_you_can_increment_this_to_enable_matchmaking_for_your_mods__please_dont_use_it_to_cheat_thats_really_cringe_especially_if_its_desyncing_others___you_didnt_even_win_on_your_opponents_screen___I_cannot_imagine_a_sadder_existence++;
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "Assets");
			if (!Directory.Exists(text))
			{
				Logger.LogError((object)"Assets folder not found!");
			}
			AssetsPath = text;
			Stopwatch stopwatch = Stopwatch.StartNew();
			AddDeathSpriteCreator(CauseOfDeath.Age);
			AddDeathSpriteCreator(CauseOfDeath.Arrowed, BlendMode.Killer);
			AddDeathSpriteCreator(CauseOfDeath.BlackHole);
			AddDeathSpriteCreator(CauseOfDeath.Clouds);
			AddDeathSpriteCreator(CauseOfDeath.Drilled);
			AddDeathSpriteCreator(CauseOfDeath.Drilling);
			AddDeathSpriteCreator(CauseOfDeath.Drowned);
			AddDeathSpriteCreator(CauseOfDeath.Electrocuted);
			AddDeathSpriteCreator(CauseOfDeath.Exploded);
			AddDeathSpriteCreator(CauseOfDeath.Froze);
			AddDeathSpriteCreator(CauseOfDeath.Invisible);
			AddDeathSpriteCreator(CauseOfDeath.Leashed);
			AddDeathSpriteCreator(CauseOfDeath.Macho);
			AddDeathSpriteCreator(CauseOfDeath.Meditating);
			AddDeathSpriteCreator(CauseOfDeath.Meteored, BlendMode.Killer);
			AddDeathSpriteCreator(CauseOfDeath.MeteoringSpace);
			AddDeathSpriteCreator(CauseOfDeath.MeteoringWater);
			AddDeathSpriteCreator(CauseOfDeath.Rocked, BlendMode.Victim);
			AddDeathSpriteCreator(CauseOfDeath.Rocking);
			AddDeathSpriteCreator(CauseOfDeath.Rolled);
			AddDeathSpriteCreator(CauseOfDeath.Sworded);
			AddDeathSpriteCreator(CauseOfDeath.Space);
			stopwatch.Stop();
			Logger.LogInfo((object)$"Plugin Dumb Ways to Die with {Assets.Count} alternate sprites was loaded in {stopwatch.ElapsedMilliseconds} ms!");
			Harmony val = new Harmony("lofen.dumbWaysToDie");
			val.PatchAll(typeof(Patch));
		}

		private static void AddDeathSpriteCreator(CauseOfDeath causeOfDeath, BlendMode blendMode = BlendMode.Blend)
		{
			Assets.Add(causeOfDeath, new DeathSpriteCreator(causeOfDeath.ToString(), blendMode));
		}
	}
	public enum BlendMode
	{
		Killer,
		Victim,
		Blend
	}
	public class DeathSpriteCreator
	{
		private string name;

		private BlendMode blendMode;

		private Color[] vpxs;

		private Color[] kpxs;

		private int width;

		private int height;

		private static float MAX_BRIGHTNESS;

		public DeathSpriteCreator(string name, BlendMode blendMode)
		{
			this.name = name;
			this.blendMode = blendMode;
			LoadAllTextures();
		}

		private void LoadAllTextures()
		{
			Stopwatch stopwatch = Stopwatch.StartNew();
			vpxs = LoadPixels(name ?? "");
			kpxs = LoadPixels(name + "-Killer");
			stopwatch.Stop();
			Plugin.Logger.LogDebug((object)$"Loaded textures for {name} in {stopwatch.ElapsedMilliseconds} ms");
		}

		private Color[] LoadPixels(string name)
		{
			Texture2D val = LoadTexture(name);
			return (Color[])(((object)((val != null) ? val.GetPixels() : null)) ?? ((object)new Color[width * height]));
		}

		private Texture2D LoadTexture(string name)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			string text = Path.Combine(Plugin.AssetsPath, name + ".png");
			if (!File.Exists(text))
			{
				return null;
			}
			byte[] array = File.ReadAllBytes(text);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array);
			if (width == 0 || height == 0)
			{
				width = ((Texture)val).width;
				height = ((Texture)val).height;
			}
			else if (((Texture)val).width != width || ((Texture)val).height != height)
			{
				Plugin.Logger.LogWarning((object)$"Texture {text} has wrong dimensions {((Texture)val).width}x{((Texture)val).height}, expected {width}x{height}");
			}
			Texture2D val2 = new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, true);
			((Object)val2).name = name;
			((Texture)val2).filterMode = (FilterMode)1;
			val2.SetPixels(val.GetPixels());
			return val2;
		}

		private static bool IsGreen(Color c)
		{
			//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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			return c.g > c.r && c.g > c.b;
		}

		public Sprite Create(Color victimColor, Color? maybeKillerColor)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_002f: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			Stopwatch stopwatch = Stopwatch.StartNew();
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, true);
			((Object)val).name = name;
			((Texture)val).filterMode = (FilterMode)1;
			if (Plugin.Debug.Value)
			{
				LoadAllTextures();
			}
			Color killerColor = (Color)(((??)maybeKillerColor) ?? Color.green);
			Color[] pixels = (Color[])(object)new Color[width * height];
			Parallel.For(0, pixels.Length, delegate(int i)
			{
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: 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)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Unknown result type (might be due to invalid IL or missing references)
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_013a: 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_016d: Unknown result type (might be due to invalid IL or missing references)
				//IL_016e: 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_017a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_0187: Unknown result type (might be due to invalid IL or missing references)
				//IL_015b: 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)
				if (vpxs[i].a != 0f || kpxs[i].a != 0f)
				{
					Color val2 = (IsGreen(vpxs[i]) ? Color.Lerp(Color.clear, victimColor, ((Color)(ref vpxs[i])).grayscale / MAX_BRIGHTNESS) : vpxs[i]);
					Color val3 = (IsGreen(kpxs[i]) ? Color.Lerp(Color.clear, killerColor, ((Color)(ref kpxs[i])).grayscale / MAX_BRIGHTNESS) : kpxs[i]);
					if (blendMode == BlendMode.Victim && val2.a != 0f)
					{
						pixels[i] = val2;
					}
					else if (blendMode == BlendMode.Killer && val3.a != 0f)
					{
						pixels[i] = val3;
					}
					else
					{
						pixels[i] = Color.Lerp(val2, val3, val3.a / (val2.a + val3.a));
					}
				}
			});
			val.SetPixels(pixels);
			val.Apply();
			Sprite result = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 60f, 0u, (SpriteMeshType)0);
			Plugin.Logger.LogDebug((object)$"Created sprite {name} in {stopwatch.ElapsedMilliseconds} ms");
			return result;
		}

		static DeathSpriteCreator()
		{
			//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)
			Color green = Color.green;
			MAX_BRIGHTNESS = ((Color)(ref green)).grayscale;
		}
	}
	[HarmonyPatch]
	public class Patch
	{
		public static Dictionary<int, CauseOfDeath> CausesOfDeath = new Dictionary<int, CauseOfDeath>();

		public static Dictionary<int, AbilitySelectCircle> AbilitySelectCircles = new Dictionary<int, AbilitySelectCircle>();

		public static Dictionary<int, int> Killers = new Dictionary<int, int>();

		public static Dictionary<int, bool> IsRocking = new Dictionary<int, bool>();

		public static Dictionary<int, bool> IsDrilling = new Dictionary<int, bool>();

		public static Dictionary<int, bool> IsMeditating = new Dictionary<int, bool>();

		public static Dictionary<int, bool> IsMeteoring = new Dictionary<int, bool>();

		private static void TrySetAlternateSprite(int id)
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_01a0: 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_01cd: Expected O, but got Unknown
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			if (!CausesOfDeath.ContainsKey(id))
			{
				Plugin.Logger.LogDebug((object)$"Not setting alternate sprite, no cause of death for player {id} yet");
				return;
			}
			if (!AbilitySelectCircles.ContainsKey(id))
			{
				Plugin.Logger.LogDebug((object)$"Not setting alternate sprite, no ability select for player {id} yet");
				return;
			}
			CauseOfDeath causeOfDeath = CausesOfDeath[id];
			if (!Plugin.Assets.ContainsKey(causeOfDeath))
			{
				Plugin.Logger.LogError((object)$"Not setting alternate sprite, no death sprite creator for cause of death {causeOfDeath}");
				return;
			}
			Plugin.Logger.LogInfo((object)$"Setting alternate sprite {causeOfDeath} for player {id}");
			Color color = PlayerHandler.Get().GetPlayer(id).Color.GetColor("_ShadowColor");
			Killers.TryGetValue(id, out var value);
			Player player = PlayerHandler.Get().GetPlayer(value);
			Color? maybeKillerColor = ((player != null) ? new Color?(player.Color.GetColor("_ShadowColor")) : null);
			Sprite characterSprite = Plugin.Assets[causeOfDeath].Create(color, maybeKillerColor);
			AbilitySelectCircle val = AbilitySelectCircles[id];
			val.SetCharacterSprite(characterSprite);
			Image[] array = (Image[])Traverse.Create((object)val.loser).Field("characterImages").GetValue();
			((Graphic)array[2]).material = null;
			((Transform)((Graphic)array[2]).rectTransform).localScale = new Vector3(Plugin.ScaleFactor.Value, Plugin.ScaleFactor.Value, 1f);
			Image val2 = (Image)Traverse.Create((object)val.winner).Field("character").GetValue();
			((Graphic)val2).material = null;
			((Transform)((Graphic)val2).rectTransform).localScale = new Vector3(Plugin.ScaleFactor.Value, Plugin.ScaleFactor.Value, 1f);
			CausesOfDeath.Remove(id);
			AbilitySelectCircles.Remove(id);
			Killers.Remove(id);
		}

		private static void SetCauseOfDeath(int id, CauseOfDeath causeOfDeath, bool overrideOriginal = false)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (causeOfDeath == CauseOfDeath.MeteoringWater || causeOfDeath == CauseOfDeath.MeteoringSpace)
			{
				IsMeteoring[id] = false;
			}
			if (GameSessionHandler.HasGameEnded())
			{
				Plugin.Logger.LogDebug((object)$"Not setting cause of death {causeOfDeath} for player {id}, game is over");
				return;
			}
			Player player = PlayerHandler.Get().GetPlayer(id);
			if ((int)player.CauseOfDeath != 0 && !overrideOriginal)
			{
				Plugin.Logger.LogDebug((object)$"Not setting cause of death {causeOfDeath} for player {id}, already has standard cause of death {player.CauseOfDeath}");
				return;
			}
			if (player.IsAlive)
			{
				Plugin.Logger.LogDebug((object)$"Not setting cause of death {causeOfDeath} for player {id}, not actually dead yet");
				return;
			}
			if (causeOfDeath == CauseOfDeath.Other)
			{
				Plugin.Logger.LogDebug((object)$"Not setting cause of death {causeOfDeath} for player {id}, no specific cause of death set");
				return;
			}
			Plugin.Logger.LogDebug((object)$"Setting cause of death {causeOfDeath} for player {id}");
			CausesOfDeath[id] = causeOfDeath;
			TrySetAlternateSprite(id);
		}

		private static CauseOfDeath DetermineStateBeforeDeath(int id, bool isLeashed)
		{
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Invalid comparison between Unknown and I4
			CauseOfDeath result = CauseOfDeath.Other;
			Player player = PlayerHandler.Get().GetPlayer(id);
			IsRocking.TryGetValue(player.Id, out var value);
			IsMeditating.TryGetValue(player.Id, out var value2);
			IsDrilling.TryGetValue(player.Id, out var value3);
			IsMeteoring.TryGetValue(player.Id, out var value4);
			if (GameTime.IsTimeStopped() && player.isProtectedFromTimeStop)
			{
				result = CauseOfDeath.Age;
			}
			else if (player.isInvisible)
			{
				result = CauseOfDeath.Invisible;
			}
			else if (isLeashed)
			{
				result = CauseOfDeath.Leashed;
			}
			else if (player.InMachoThrow)
			{
				result = CauseOfDeath.Macho;
			}
			else if (value)
			{
				result = CauseOfDeath.Rocking;
			}
			else if (value2)
			{
				result = CauseOfDeath.Meditating;
			}
			else if (value3)
			{
				result = CauseOfDeath.Drilling;
			}
			else if (value4 && player.Position.y < SceneBounds.WaterHeight)
			{
				result = (((int)Constants.leveltype != 2) ? CauseOfDeath.MeteoringWater : CauseOfDeath.MeteoringSpace);
			}
			return result;
		}

		[HarmonyPatch(typeof(GameSessionHandler), "StartSpawnPlayersRoutine")]
		[HarmonyPrefix]
		public static void GameSessionHandlerStartSpawnPlayersRoutinePre()
		{
			Plugin.Logger.LogDebug((object)"Resetting...");
			CausesOfDeath.Clear();
			AbilitySelectCircles.Clear();
			Killers.Clear();
			IsRocking.Clear();
			IsDrilling.Clear();
			IsMeditating.Clear();
			IsMeteoring.Clear();
		}

		[HarmonyPatch(typeof(AbilitySelectCircle), "SetPlayer")]
		[HarmonyPostfix]
		public static void AbilitySelectCircleSetPlayerPost(AbilitySelectCircle __instance, int id, bool isWinner)
		{
			Plugin.Logger.LogDebug((object)$"Setting ability select circle for player {id} (Winner: {isWinner})");
			AbilitySelectCircles[id] = __instance;
			TrySetAlternateSprite(id);
		}

		[HarmonyPatch(typeof(PlayerCollision), "KillPlayerOnCollision")]
		[HarmonyPrefix]
		public static void KillPlayerPre(ref CauseOfDeath __state, PlayerBody ___body, IPlayerIdHolder ___playerIdHolder)
		{
			bool isLeashed = ___body.ropeBody != null;
			__state = DetermineStateBeforeDeath(___playerIdHolder.GetPlayerId(), isLeashed);
		}

		[HarmonyPatch(typeof(PlayerCollision), "KillPlayerOnCollision")]
		[HarmonyPostfix]
		public static void KillPlayerPost(bool __result, CauseOfDeath __state, IPlayerIdHolder ___playerIdHolder, ref CollisionInformation collision)
		{
			if (!__result)
			{
				return;
			}
			int playerId = ___playerIdHolder.GetPlayerId();
			FixTransform fixTrans = collision.colliderPP.fixTrans;
			GameObject gameObject = ((Component)fixTrans).gameObject;
			CauseOfDeath causeOfDeath = CauseOfDeath.Other;
			bool overrideOriginal = false;
			if (__state != 0)
			{
				causeOfDeath = __state;
				overrideOriginal = true;
			}
			else if (gameObject.layer == LayerMask.NameToLayer("Explosion"))
			{
				if (((Component)fixTrans).CompareTag("ChainLightning"))
				{
					causeOfDeath = CauseOfDeath.Electrocuted;
				}
				else if (((Component)fixTrans).CompareTag("explosion"))
				{
					if (((object)gameObject).ToString().Contains("invisibleHitbox"))
					{
						causeOfDeath = CauseOfDeath.Drilled;
					}
					else
					{
						causeOfDeath = CauseOfDeath.Meteored;
						Killers[playerId] = gameObject.GetComponent<Explosion>().PlayerOwnerId;
					}
				}
				else
				{
					causeOfDeath = CauseOfDeath.Exploded;
				}
			}
			else if (gameObject.layer == LayerMask.NameToLayer("Projectile") && ((Component)fixTrans).CompareTag("projectile"))
			{
				causeOfDeath = CauseOfDeath.Arrowed;
				overrideOriginal = true;
				Killers[playerId] = ((Component)gameObject.GetComponent<Projectile>()).GetComponent<IPlayerIdHolder>().GetPlayerId();
			}
			else if (gameObject.layer == LayerMask.NameToLayer("LethalTerrain"))
			{
				if (((Component)fixTrans).CompareTag("explosion"))
				{
					causeOfDeath = CauseOfDeath.Sworded;
				}
				else if (((Component)fixTrans).CompareTag("ChainLightning"))
				{
					causeOfDeath = CauseOfDeath.Electrocuted;
				}
			}
			else if (gameObject.layer == LayerMask.NameToLayer("Player") && ((Component)fixTrans).CompareTag("Ability"))
			{
				Ability component = gameObject.GetComponent<Ability>();
				if (((object)component).ToString().Contains("Rock"))
				{
					causeOfDeath = CauseOfDeath.Rocked;
				}
				else if (((object)component).ToString().Contains("Roll"))
				{
					causeOfDeath = CauseOfDeath.Rolled;
				}
				else if (((object)component).ToString().Contains("Meteor"))
				{
					causeOfDeath = CauseOfDeath.Meteored;
				}
				Killers[playerId] = ((Component)component).GetComponent<IPlayerIdHolder>().GetPlayerId();
			}
			SetCauseOfDeath(playerId, causeOfDeath, overrideOriginal);
		}

		[HarmonyPatch(typeof(DestroyIfOutsideSceneBounds), "selfDestruct")]
		[HarmonyPrefix]
		public static void SelfDestructPre(DestroyIfOutsideSceneBounds __instance, ref CauseOfDeath __state)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			__state = CauseOfDeath.Other;
			bool isLeashed = false;
			if (((Component)__instance).gameObject.layer == LayerMask.NameToLayer("Player"))
			{
				PlayerCollision component = ((Component)__instance).GetComponent<PlayerCollision>();
				if ((Object)(object)component != (Object)null)
				{
					PlayerBody val = (PlayerBody)Traverse.Create((object)component).Field("body").GetValue();
					isLeashed = val.ropeBody != null;
				}
				BounceBall component2 = ((Component)__instance).GetComponent<BounceBall>();
				if ((Object)(object)component2 != (Object)null)
				{
					isLeashed = component2.ropeBody != null;
				}
				IPlayerIdHolder component3 = ((Component)__instance).GetComponent<IPlayerIdHolder>();
				if (component3 != null)
				{
					int playerId = component3.GetPlayerId();
					__state = DetermineStateBeforeDeath(playerId, isLeashed);
				}
			}
		}

		[HarmonyPatch(typeof(DestroyIfOutsideSceneBounds), "selfDestruct")]
		[HarmonyPostfix]
		public static void selfDestructPost(DestroyIfOutsideSceneBounds __instance, CauseOfDeath __state, FixTransform ___fixTrans)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_009d: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Invalid comparison between Unknown and I4
			if (((Component)__instance).gameObject.layer == LayerMask.NameToLayer("Player"))
			{
				IPlayerIdHolder component = ((Component)__instance).GetComponent<IPlayerIdHolder>();
				if (component != null)
				{
					int playerId = component.GetPlayerId();
					CauseOfDeath causeOfDeath = CauseOfDeath.Other;
					causeOfDeath = ((__state != 0) ? __state : (((int)Constants.leveltype != 2 && ___fixTrans.position.y < SceneBounds.WaterHeight) ? (((int)Constants.leveltype != 1) ? CauseOfDeath.Drowned : CauseOfDeath.Froze) : (((int)Constants.leveltype != 0) ? CauseOfDeath.Space : CauseOfDeath.Clouds)));
					SetCauseOfDeath(playerId, causeOfDeath, overrideOriginal: true);
				}
			}
		}

		[HarmonyPatch(typeof(BlackHole), "OnCollide")]
		[HarmonyPostfix]
		public static void onCollidePost(BlackHole __instance, ref CollisionInformation collision)
		{
			if (collision.layer == LayerMask.NameToLayer("Player"))
			{
				int playerId = ((Component)collision.colliderPP.fixTrans).gameObject.GetComponent<IPlayerIdHolder>().GetPlayerId();
				SetCauseOfDeath(playerId, CauseOfDeath.BlackHole);
			}
		}

		[HarmonyPatch(typeof(BounceBall), "OnEnterAbility")]
		[HarmonyPostfix]
		public static void BounceBallOnEnterPost(ref PlayerInfo ___playerInfo)
		{
			IsRocking[___playerInfo.playerId] = true;
		}

		[HarmonyPatch(typeof(BounceBall), "ExitAbility", new Type[] { typeof(AbilityExitInfo) })]
		[HarmonyPostfix]
		public static void BounceBallExitPost(ref PlayerInfo ___playerInfo)
		{
			IsRocking[___playerInfo.playerId] = false;
		}

		[HarmonyPatch(typeof(CastSpell), "OnEnterAbility")]
		[HarmonyPostfix]
		public static void CastOnEnterPost(ref PlayerInfo ___playerInfo)
		{
			IsMeditating[___playerInfo.playerId] = true;
		}

		[HarmonyPatch(typeof(CastSpell), "ExitAbility", new Type[] { typeof(AbilityExitInfo) })]
		[HarmonyPostfix]
		public static void CastExitPost(ref PlayerInfo ___playerInfo)
		{
			IsMeditating[___playerInfo.playerId] = false;
		}

		[HarmonyPatch(typeof(Drill), "OnEnterAbility")]
		[HarmonyPostfix]
		public static void DrillOnEnterPost(ref PlayerInfo ___playerInfo)
		{
			IsDrilling[___playerInfo.playerId] = true;
		}

		[HarmonyPatch(typeof(Drill), "ExitAbility", new Type[] { typeof(AbilityExitInfo) })]
		[HarmonyPostfix]
		public static void DrillExitPost(ref PlayerInfo ___playerInfo)
		{
			IsDrilling[___playerInfo.playerId] = false;
		}

		[HarmonyPatch(typeof(MeteorSmash), "OnEnterAbility")]
		[HarmonyPostfix]
		public static void MeteorOnEnterPost(ref PlayerInfo ___playerInfo)
		{
			IsMeteoring[___playerInfo.playerId] = true;
		}

		[HarmonyPatch(typeof(MeteorSmash), "ExitAbilityGrounded")]
		[HarmonyPostfix]
		public static void MeteorOnExitGroundedPost(ref PlayerInfo ___playerInfo)
		{
			IsMeteoring[___playerInfo.playerId] = false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DumbWaysToDie";

		public const string PLUGIN_NAME = "DumbWaysToDie";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}