Decompiled source of SlowMoKO v1.0.0

Mods/SlowMoKO.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using Microsoft.CodeAnalysis;
using SlowMoKO;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Mod), "SlowMoKO", "1.0.0", "Zooks", null)]
[assembly: MelonGame("Boneloaf", "Gang Beasts")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SlowMoKO")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SlowMoKO")]
[assembly: AssemblyTitle("SlowMoKO")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 SlowMoKO
{
	public class Mod : MelonMod
	{
		[CompilerGenerated]
		private sealed class <CinematicSlowMoRoutine>d__13 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			private float <startTime>5__2;

			private float <targetBarHeight>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <CinematicSlowMoRoutine>d__13(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0175: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0203: Unknown result type (might be due to invalid IL or missing references)
				//IL_0229: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -1;
				}
				else
				{
					<>1__state = -1;
					_inSlowMo = true;
					CreateCinematicUI();
					<startTime>5__2 = Time.unscaledTime;
					<targetBarHeight>5__3 = (float)Screen.height * 0.12f;
				}
				float num2 = Time.unscaledTime - <startTime>5__2;
				float num3 = 0f;
				if (num2 < 0.05f)
				{
					num3 = num2 / 0.05f;
					Time.timeScale = Mathf.Lerp(1f, SlowMoTimeScale, num3);
				}
				else if (num2 < 0.3f)
				{
					num3 = 1f;
					Time.timeScale = SlowMoTimeScale;
				}
				else if (num2 < 0.5f)
				{
					num3 = 1f - (num2 - 0.3f) / 0.2f;
					Time.timeScale = Mathf.Lerp(1f, SlowMoTimeScale, num3);
				}
				else
				{
					Time.timeScale = 1f;
					num3 = 0f;
				}
				SetAllAudioPitch(Mathf.Lerp(1f, 0.6f, num3));
				if ((Object)(object)_dimImage != (Object)null)
				{
					((Graphic)_dimImage).color = new Color(0f, 0f, 0f, Mathf.Lerp(0f, 0.4f, num3));
				}
				if ((Object)(object)_topBarRT != (Object)null && (Object)(object)_bottomBarRT != (Object)null)
				{
					float num4 = Mathf.Lerp(0f, <targetBarHeight>5__3, num3);
					_topBarRT.sizeDelta = new Vector2(0f, num4);
					_bottomBarRT.sizeDelta = new Vector2(0f, num4);
				}
				if (!(num2 >= 0.5f))
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				Time.timeScale = 1f;
				SetAllAudioPitch(1f);
				if ((Object)(object)_dimImage != (Object)null)
				{
					((Graphic)_dimImage).color = new Color(0f, 0f, 0f, 0f);
				}
				if ((Object)(object)_topBarRT != (Object)null)
				{
					_topBarRT.sizeDelta = new Vector2(0f, 0f);
				}
				if ((Object)(object)_bottomBarRT != (Object)null)
				{
					_bottomBarRT.sizeDelta = new Vector2(0f, 0f);
				}
				_inSlowMo = false;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static bool _inSlowMo = false;

		private static readonly float SlowMoTimeScale = 0.15f;

		private static readonly float SlowMoRealDuration = 0.25f;

		private static GameObject _uiRoot;

		private static Image _dimImage;

		private static RectTransform _topBarRT;

		private static RectTransform _bottomBarRT;

		public static Vector3 LocalPlayerPos = Vector3.zero;

		public static bool IsLocalPlayerAlive = false;

		public override void OnInitializeMelon()
		{
			((MelonBase)this).HarmonyInstance.PatchAll();
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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)
			ActorUpdatePatch.ClearCache();
			ParticleManager.ClearAll();
			Time.timeScale = 1f;
			if ((Object)(object)_dimImage != (Object)null)
			{
				((Graphic)_dimImage).color = new Color(0f, 0f, 0f, 0f);
			}
			if ((Object)(object)_topBarRT != (Object)null)
			{
				_topBarRT.sizeDelta = new Vector2(0f, 0f);
			}
			if ((Object)(object)_bottomBarRT != (Object)null)
			{
				_bottomBarRT.sizeDelta = new Vector2(0f, 0f);
			}
			_inSlowMo = false;
			IsLocalPlayerAlive = false;
			SetAllAudioPitch(1f);
		}

		public override void OnUpdate()
		{
			//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_006d: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Keyboard.current != null)
				{
					if (((ButtonControl)Keyboard.current[(Key)99]).wasPressedThisFrame)
					{
						TriggerSlowMo();
					}
					if (((ButtonControl)Keyboard.current[(Key)100]).wasPressedThisFrame)
					{
						Camera val = Camera.main ?? ((IEnumerable<Camera>)Camera.allCameras).FirstOrDefault();
						if ((Object)(object)val != (Object)null)
						{
							ParticleManager.SpawnEffect(((Component)val).transform.position + ((Component)val).transform.forward * 2f, ((Component)val).transform.forward + Vector3.up * 0.5f, 15f);
						}
					}
				}
			}
			catch
			{
			}
			ParticleManager.UpdateParticles();
		}

		public static void TriggerSlowMo()
		{
			if (!_inSlowMo)
			{
				MelonCoroutines.Start(CinematicSlowMoRoutine());
			}
		}

		[IteratorStateMachine(typeof(<CinematicSlowMoRoutine>d__13))]
		private static IEnumerator CinematicSlowMoRoutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CinematicSlowMoRoutine>d__13(0);
		}

		private static void CreateCinematicUI()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0048: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_uiRoot != (Object)null)
			{
				return;
			}
			try
			{
				_uiRoot = new GameObject("SlowMoKOCinematicUI");
				Object.DontDestroyOnLoad((Object)(object)_uiRoot);
				Canvas obj = _uiRoot.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 32000;
				GameObject val = new GameObject("Dimmer");
				val.transform.SetParent(_uiRoot.transform, false);
				_dimImage = val.AddComponent<Image>();
				((Graphic)_dimImage).color = new Color(0f, 0f, 0f, 0f);
				RectTransform rectTransform = ((Graphic)_dimImage).rectTransform;
				rectTransform.anchorMin = Vector2.zero;
				rectTransform.anchorMax = Vector2.one;
				rectTransform.offsetMin = Vector2.zero;
				rectTransform.offsetMax = Vector2.zero;
				GameObject val2 = new GameObject("TopBar");
				val2.transform.SetParent(_uiRoot.transform, false);
				Image obj2 = val2.AddComponent<Image>();
				((Graphic)obj2).color = Color.black;
				_topBarRT = ((Graphic)obj2).rectTransform;
				_topBarRT.anchorMin = new Vector2(0f, 1f);
				_topBarRT.anchorMax = new Vector2(1f, 1f);
				_topBarRT.pivot = new Vector2(0.5f, 1f);
				_topBarRT.sizeDelta = new Vector2(0f, 0f);
				GameObject val3 = new GameObject("BottomBar");
				val3.transform.SetParent(_uiRoot.transform, false);
				Image obj3 = val3.AddComponent<Image>();
				((Graphic)obj3).color = Color.black;
				_bottomBarRT = ((Graphic)obj3).rectTransform;
				_bottomBarRT.anchorMin = new Vector2(0f, 0f);
				_bottomBarRT.anchorMax = new Vector2(1f, 0f);
				_bottomBarRT.pivot = new Vector2(0.5f, 0f);
				_bottomBarRT.sizeDelta = new Vector2(0f, 0f);
			}
			catch
			{
			}
		}

		private static void SetAllAudioPitch(float pitch)
		{
			try
			{
				Il2CppArrayBase<AudioSource> val = Object.FindObjectsOfType<AudioSource>();
				if (val == null)
				{
					return;
				}
				foreach (AudioSource item in val)
				{
					if ((Object)(object)item != (Object)null && (Object)(object)((Component)item).gameObject != (Object)null && ((Component)item).gameObject.activeInHierarchy)
					{
						item.pitch = pitch;
					}
				}
			}
			catch
			{
			}
		}
	}
	public static class ParticleManager
	{
		public class Particle
		{
			public Vector3 Pos3D;

			public Vector3 Vel3D;

			public Image Img;

			public float BaseSize;

			public float Life;

			public Color Col;
		}

		private static GameObject _particleCanvasObj;

		private static Texture2D _tex;

		private static List<Particle> _particles = new List<Particle>();

		public static void ClearAll()
		{
			if ((Object)(object)_particleCanvasObj != (Object)null)
			{
				Object.Destroy((Object)(object)_particleCanvasObj);
				_particleCanvasObj = null;
			}
			if ((Object)(object)_tex != (Object)null)
			{
				Object.Destroy((Object)(object)_tex);
				_tex = null;
			}
			_particles.Clear();
		}

		public static void SpawnEffect(Vector3 position, Vector3 impactDirection, float impactForce)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_particleCanvasObj == (Object)null)
			{
				_particleCanvasObj = new GameObject("SlowMoKOParticles");
				Object.DontDestroyOnLoad((Object)(object)_particleCanvasObj);
				Canvas obj = _particleCanvasObj.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 32767;
				_tex = new Texture2D(32, 32, (TextureFormat)4, false);
				for (int i = 0; i < 32; i++)
				{
					for (int j = 0; j < 32; j++)
					{
						float num = Vector2.Distance(new Vector2((float)i, (float)j), new Vector2(15.5f, 15.5f));
						float num2 = 1f - Mathf.Clamp01((num - 14f) / 1.5f);
						_tex.SetPixel(i, j, new Color(1f, 1f, 1f, num2));
					}
				}
				_tex.Apply();
			}
			Color val = ((Random.value > 0.5f) ? new Color(0.7f, 0f, 0f, 1f) : new Color(0.9f, 0.9f, 0.9f, 1f));
			int num3 = Random.Range(15, 25);
			float num4 = Mathf.Clamp(impactForce * 1.25f, 10f, 35f);
			for (int k = 0; k < num3; k++)
			{
				GameObject val2 = null;
				try
				{
					val2 = new GameObject("Drop");
					val2.transform.SetParent(_particleCanvasObj.transform, false);
					Image val3 = val2.AddComponent<Image>();
					val3.sprite = Sprite.Create(_tex, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f));
					((Graphic)val3).color = val;
					((Behaviour)val3).enabled = false;
					Vector3 val4 = impactDirection + Random.insideUnitSphere * 0.6f;
					Vector3 normalized = ((Vector3)(ref val4)).normalized;
					_particles.Add(new Particle
					{
						Pos3D = position + Random.insideUnitSphere * 0.4f,
						Vel3D = normalized * Random.Range(num4 * 0.41f, num4),
						Img = val3,
						BaseSize = Random.Range(7.9f, 20f),
						Life = 0.9f,
						Col = val
					});
				}
				catch
				{
					if ((Object)(object)val2 != (Object)null)
					{
						Object.Destroy((Object)(object)val2);
					}
				}
			}
		}

		public static void UpdateParticles()
		{
			//IL_00a5: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			if (_particles.Count == 0)
			{
				return;
			}
			Camera val = Camera.main ?? ((IEnumerable<Camera>)Camera.allCameras).FirstOrDefault();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			float num = Mathf.Min(Time.unscaledDeltaTime, 0.1f);
			for (int num2 = _particles.Count - 1; num2 >= 0; num2--)
			{
				try
				{
					Particle particle = _particles[num2];
					particle.Life -= num;
					if (particle.Life <= 0f)
					{
						if ((Object)(object)particle.Img != (Object)null)
						{
							Object.Destroy((Object)(object)((Component)particle.Img).gameObject);
						}
						_particles.RemoveAt(num2);
					}
					else
					{
						particle.Vel3D -= particle.Vel3D * 4f * num;
						particle.Vel3D += Physics.gravity * num * 1.5f;
						particle.Pos3D += particle.Vel3D * num;
						Vector3 val2 = val.WorldToScreenPoint(particle.Pos3D);
						Vector3 val3 = val.WorldToScreenPoint(particle.Pos3D + particle.Vel3D * 0.1f);
						if (val2.z > 0f)
						{
							((Behaviour)particle.Img).enabled = true;
							((Transform)((Graphic)particle.Img).rectTransform).position = new Vector3(val2.x, val2.y, 0f);
							Vector3 val4 = val3 - val2;
							Vector2 val5 = Vector2.op_Implicit(((Vector3)(ref val4)).normalized);
							if (((Vector2)(ref val5)).sqrMagnitude > 0f)
							{
								float num3 = Mathf.Atan2(val5.y, val5.x) * 57.29578f;
								((Transform)((Graphic)particle.Img).rectTransform).rotation = Quaternion.Euler(0f, 0f, num3);
							}
							float num4 = particle.BaseSize / Mathf.Max(1f, val2.z * 0.1f);
							float magnitude = ((Vector3)(ref particle.Vel3D)).magnitude;
							float num5 = Mathf.Clamp(1f + magnitude * 0.15f, 1f, 4f);
							((Graphic)particle.Img).rectTransform.sizeDelta = new Vector2(num4 * num5, num4 * 0.6f);
							if (particle.Life < 0.3f)
							{
								particle.Col.a = Mathf.Lerp(0f, 1f, particle.Life / 0.3f);
								((Graphic)particle.Img).color = particle.Col;
							}
						}
						else
						{
							((Behaviour)particle.Img).enabled = false;
						}
					}
				}
				catch
				{
					if ((Object)(object)_particles[num2].Img != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)_particles[num2].Img).gameObject);
					}
					_particles.RemoveAt(num2);
				}
			}
		}
	}
	[HarmonyPatch]
	public static class ActorUpdatePatch
	{
		private static PropertyInfo _stateProp = null;

		private static FieldInfo _stateField = null;

		private static PropertyInfo _isLocalProp = null;

		private static readonly Dictionary<int, string> _lastStates = new Dictionary<int, string>();

		private static bool _membersCached = false;

		public static void ClearCache()
		{
			_lastStates.Clear();
		}

		public static IEnumerable<MethodBase> TargetMethods()
		{
			List<MethodBase> list = new List<MethodBase>();
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					Type[] types = assembly.GetTypes();
					foreach (Type type in types)
					{
						if (type.Name == "Actor")
						{
							MethodInfo method = type.GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
							if (method != null)
							{
								list.Add(method);
							}
						}
					}
				}
				catch
				{
				}
			}
			return list;
		}

		public static void Postfix(object __instance)
		{
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Type type = __instance.GetType();
				if (!_membersCached)
				{
					_membersCached = true;
					BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
					_stateProp = type.GetProperty("actorState", bindingAttr) ?? type.GetProperty("_actorState", bindingAttr);
					_stateField = type.GetField("actorState", bindingAttr) ?? type.GetField("_actorState", bindingAttr);
					_isLocalProp = type.GetProperty("IsLocal", bindingAttr) ?? type.GetProperty("isLocalPlayer", bindingAttr);
				}
				string text = "";
				if (_stateProp != null)
				{
					text = (_stateProp.GetValue(__instance)?.ToString() ?? "").ToLower();
				}
				else if (_stateField != null)
				{
					text = (_stateField.GetValue(__instance)?.ToString() ?? "").ToLower();
				}
				int hashCode = __instance.GetHashCode();
				if (_lastStates.TryGetValue(hashCode, out var value) && value != text)
				{
					bool num = text.Contains("unconscious") && !value.Contains("unconscious");
					bool flag = text.Contains("dead") && !value.Contains("dead");
					if (num || flag)
					{
						Component val = (Component)((__instance is Component) ? __instance : null);
						if ((Object)(object)val == (Object)null)
						{
							return;
						}
						Vector3 val2 = val.transform.position;
						Rigidbody[] array = Il2CppArrayBase<Rigidbody>.op_Implicit(val.GetComponentsInChildren<Rigidbody>());
						if (array != null && array.Length != 0)
						{
							Rigidbody val3 = ((IEnumerable<Rigidbody>)array).FirstOrDefault((Func<Rigidbody, bool>)((Rigidbody r) => ((Object)r).name.ToLower().Contains("head")));
							val2 = ((!((Object)(object)val3 != (Object)null)) ? array[0].position : val3.position);
						}
						bool flag2 = false;
						if (_isLocalProp != null)
						{
							object value2 = _isLocalProp.GetValue(__instance);
							bool flag3 = default(bool);
							int num2;
							if (value2 is bool)
							{
								flag3 = (bool)value2;
								num2 = 1;
							}
							else
							{
								num2 = 0;
							}
							if (((uint)num2 & (flag3 ? 1u : 0u)) != 0)
							{
								flag2 = true;
							}
						}
						if (flag2)
						{
							Mod.LocalPlayerPos = val2;
							Mod.IsLocalPlayerAlive = !flag;
						}
						bool flag4 = false;
						Vector3 val4 = Vector3.up;
						float num3 = 15f;
						Vector3 val6;
						try
						{
							Rigidbody val5 = array?.FirstOrDefault((Func<Rigidbody, bool>)delegate(Rigidbody r)
							{
								//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)
								Vector3 velocity = r.velocity;
								return ((Vector3)(ref velocity)).magnitude > 2f;
							});
							if ((Object)(object)val5 != (Object)null)
							{
								val6 = val5.velocity;
								val4 = ((Vector3)(ref val6)).normalized;
								val6 = val5.velocity;
								num3 = ((Vector3)(ref val6)).magnitude;
							}
						}
						catch
						{
						}
						if (flag2)
						{
							if (flag)
							{
								flag4 = true;
							}
						}
						else if (Mod.IsLocalPlayerAlive && Vector3.Distance(val2, Mod.LocalPlayerPos) < 8f)
						{
							flag4 = true;
							if (num3 < 5f)
							{
								val6 = val2 - Mod.LocalPlayerPos;
								val4 = ((Vector3)(ref val6)).normalized;
								val4.y = Mathf.Abs(val4.y) + 0.3f;
								num3 = 18f;
							}
						}
						if (flag4)
						{
							Mod.TriggerSlowMo();
							ParticleManager.SpawnEffect(val2, val4, num3);
						}
					}
				}
				_lastStates[hashCode] = text;
				if (!(_isLocalProp != null))
				{
					return;
				}
				object value3 = _isLocalProp.GetValue(__instance);
				bool flag5 = default(bool);
				int num4;
				if (value3 is bool)
				{
					flag5 = (bool)value3;
					num4 = 1;
				}
				else
				{
					num4 = 0;
				}
				if (((uint)num4 & (flag5 ? 1u : 0u)) == 0)
				{
					return;
				}
				Component val7 = (Component)((__instance is Component) ? __instance : null);
				if ((Object)(object)val7 != (Object)null)
				{
					Rigidbody val8 = ((IEnumerable<Rigidbody>)val7.GetComponentsInChildren<Rigidbody>()).FirstOrDefault((Func<Rigidbody, bool>)((Rigidbody r) => ((Object)r).name.ToLower().Contains("head")));
					Mod.LocalPlayerPos = (((Object)(object)val8 != (Object)null) ? val8.position : val7.transform.position);
					Mod.IsLocalPlayerAlive = !text.Contains("dead");
				}
			}
			catch
			{
			}
		}
	}
}