Decompiled source of Paranoia v1.0.2

plugins/ParanoiaMod.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ParanoiaMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("ParanoiaMod")]
[assembly: AssemblyTitle("ParanoiaMod")]
[assembly: AssemblyVersion("1.0.2.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ParanoiaMod
{
	internal static class AvengerMusic
	{
		private const int Rate = 12000;

		private const int LoopSeconds = 12;

		private const double TwoPi = Math.PI * 2.0;

		private const float TwoPiF = MathF.PI * 2f;

		private static AudioClip _loop;

		private static AudioClip _hit;

		public static AudioClip Loop
		{
			get
			{
				if ((Object)(object)_loop == (Object)null)
				{
					_loop = MakeLoop();
				}
				return _loop;
			}
		}

		public static AudioClip Hit
		{
			get
			{
				if ((Object)(object)_hit == (Object)null)
				{
					_hit = MakeHit();
				}
				return _hit;
			}
		}

		public static void Prewarm()
		{
			AudioClip loop = Loop;
			AudioClip hit = Hit;
			if ((Object)(object)loop == (Object)null || (Object)(object)hit == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Avenger music: clips were not created.");
			}
		}

		private static float Tone(long cycles, long i, int n)
		{
			return (float)Math.Sin(Math.PI * 2.0 * (double)(cycles * i % n) / (double)n);
		}

		private static float Boom(float m, float start, float gain)
		{
			float num = m - start;
			if (num < 0f || num > 1.6f)
			{
				return 0f;
			}
			float num2 = Mathf.Exp((0f - num) * 6.5f) * (1f - Mathf.Exp((0f - num) * 250f));
			float num3 = MathF.PI * 2f * (38f * num + 26f * (1f - Mathf.Exp((0f - num) * 9f)) / 9f);
			return (Mathf.Sin(num3) + 0.55f * Mathf.Sin(num3 * 2f)) * num2 * gain;
		}

		private static AudioClip MakeLoop()
		{
			int num = 144000;
			float[] array = new float[num];
			long[] array2 = new long[6] { 989L, 1048L, 1398L, 1482L, 2963L, 3139L };
			float[] array3 = new float[6] { 0.3f, 0.26f, 0.22f, 0.18f, 0.09f, 0.08f };
			int[] array4 = new int[6] { 0, 1, 2, 0, 1, 2 };
			long[] array5 = new long[3] { 15822L, 23712L, 31644L };
			int num2 = 6000;
			Random random = new Random(7771);
			float[] array6 = new float[num + num2];
			float num3 = 0f;
			float num4 = 0f;
			for (int i = 0; i < array6.Length; i++)
			{
				float num5 = (float)(random.NextDouble() * 2.0 - 1.0);
				num3 += (num5 - num3) * 0.12f;
				num4 = (array6[i] = num4 + (num3 - num4) * 0.12f);
			}
			for (int j = 0; j < num2; j++)
			{
				float num6 = (float)j / (float)num2;
				array6[j] = array6[j] * num6 + array6[num + j] * (1f - num6);
			}
			float[] array7 = new float[3];
			for (int k = 0; k < num; k++)
			{
				float num7 = 0f;
				float num8 = 0.75f + 0.25f * Tone(1L, k, num);
				num7 += (Tone(494L, k, num) * 0.26f + Tone(524L, k, num) * 0.2f) * num8;
				array7[0] = 0.55f + 0.45f * Tone(1L, k, num);
				array7[1] = 0.55f + 0.45f * Tone(2L, k, num);
				array7[2] = 0.55f + 0.45f * Tone(3L, k, num);
				for (int l = 0; l < array2.Length; l++)
				{
					long num9 = array2[l];
					float num10 = Tone(num9, k, num);
					if (l < 4)
					{
						num10 += 0.5f * Tone(num9 * 2, k, num) + 0.28f * Tone(num9 * 3, k, num);
					}
					float num11 = array7[array4[l]];
					num7 += num10 * array3[l] * num11;
				}
				float num12 = Tone(3L, (long)k + 40000L, num);
				num12 = Mathf.Max(0f, num12);
				num12 *= num12;
				float num13 = 0f;
				for (int m = 0; m < array5.Length; m++)
				{
					num13 += Tone(array5[m], k, num) / (1f + (float)m * 0.6f);
				}
				num7 += num13 * 0.035f * num12;
				num7 += array6[k] * 0.55f * array7[1];
				float m2 = (float)(k % 24000) / 12000f;
				num7 += Boom(m2, 0f, 0.95f) + Boom(m2, 0.36f, 0.6f);
				array[k] = num7;
			}
			Normalize(array, 0.85f);
			AudioClip obj = AudioClip.Create("ParanoiaAvengerDread", num, 1, 12000, false);
			obj.SetData(array, 0);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static AudioClip MakeHit()
		{
			int num = 48000;
			float[] array = new float[num];
			Random random = new Random(4242);
			float num2 = 0f;
			for (int i = 0; i < num; i++)
			{
				float num3 = (float)i / 12000f;
				float num4 = 1f - Mathf.Exp((0f - num3) * 400f);
				float num5 = MathF.PI * 2f * (30f * num3 + 48f * (1f - Mathf.Exp((0f - num3) * 5f)) / 5f);
				float num6 = (Mathf.Sin(num5) + 0.5f * Mathf.Sin(num5 * 2f)) * Mathf.Exp((0f - num3) * 1.7f) * num4;
				float num7 = (1f - Mathf.Exp((0f - num3) * 2.5f)) * Mathf.Exp((0f - num3) * 0.95f);
				float num8 = (Mathf.Sin(517.7345f * num3) + Mathf.Sin(548.5221f * num3) + 0.8f * Mathf.Sin(MathF.PI * 233f * num3) + 0.5f * Mathf.Sin(1551.3185f * num3) + 0.5f * Mathf.Sin(1643.6814f * num3)) * 0.12f * num7;
				float num9 = (Mathf.Sin(MathF.PI * 2636f * num3) + 0.7f * Mathf.Sin(MathF.PI * 3952f * num3) + 0.5f * Mathf.Sin(MathF.PI * 5626f * num3)) * 0.05f * Mathf.Exp((0f - num3) * 3.2f) * num4;
				float num10 = (float)(random.NextDouble() * 2.0 - 1.0);
				num2 += (num10 - num2) * 0.25f;
				float num11 = num2 * 0.9f * Mathf.Exp((0f - num3) * 14f);
				array[i] = num6 * 0.9f + num8 + num9 + num11;
			}
			int num12 = 3000;
			for (int j = num - num12; j < num; j++)
			{
				array[j] *= (float)(num - j) / (float)num12;
			}
			Normalize(array, 0.9f);
			AudioClip obj = AudioClip.Create("ParanoiaAvengerHit", num, 1, 12000, false);
			obj.SetData(array, 0);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static void Normalize(float[] data, float peakTarget)
		{
			float num = 0.001f;
			for (int i = 0; i < data.Length; i++)
			{
				num = Mathf.Max(num, Mathf.Abs(data[i]));
			}
			float num2 = peakTarget / num;
			for (int j = 0; j < data.Length; j++)
			{
				data[j] *= num2;
			}
		}
	}
	internal static class AvengerVoiceClips
	{
		private const string ResourceName = "ParanoiaMod.avenger_voice.wav";

		private const float ShriekStart = 0.64f;

		private static bool _tried;

		private static AudioClip _synthFull;

		private static AudioClip _synthGrowl;

		private static AudioClip _synthShriekA;

		private static AudioClip _synthShriekB;

		private static AudioClip _recFull;

		private static AudioClip _recShriek;

		private static bool _useRecording;

		public static AudioClip Full
		{
			get
			{
				Load();
				if (!_useRecording || !((Object)(object)_recFull != (Object)null))
				{
					return _synthFull;
				}
				return _recFull;
			}
		}

		public static AudioClip Shriek
		{
			get
			{
				Load();
				if (_useRecording && (Object)(object)_recShriek != (Object)null)
				{
					return _recShriek;
				}
				if ((Object)(object)_synthShriekB != (Object)null && Random.value < 0.5f)
				{
					return _synthShriekB;
				}
				if (!((Object)(object)_synthShriekA != (Object)null))
				{
					return _synthShriekB;
				}
				return _synthShriekA;
			}
		}

		public static AudioClip Growl
		{
			get
			{
				Load();
				if (_useRecording && (Object)(object)_recShriek != (Object)null)
				{
					return _recShriek;
				}
				if (!((Object)(object)_synthGrowl != (Object)null))
				{
					return Shriek;
				}
				return _synthGrowl;
			}
		}

		public static void Prewarm()
		{
			Load();
		}

		private static void Load()
		{
			if (_tried)
			{
				return;
			}
			_tried = true;
			try
			{
				Stopwatch stopwatch = Stopwatch.StartNew();
				_synthFull = MakeClip("ParanoiaAvengerFull", AvengerVoiceSynth.Normalize(AvengerVoiceSynth.Full()));
				_synthGrowl = MakeClip("ParanoiaAvengerGrowl", AvengerVoiceSynth.Normalize(AvengerVoiceSynth.Growl()));
				_synthShriekA = MakeClip("ParanoiaAvengerShriekA", AvengerVoiceSynth.Normalize(AvengerVoiceSynth.Shriek()));
				_synthShriekB = MakeClip("ParanoiaAvengerShriekB", AvengerVoiceSynth.Normalize(AvengerVoiceSynth.Shriek(0.95f, 77u, 0.88f)));
				stopwatch.Stop();
				Plugin.Log.LogInfo((object)("Avenger voice: synthesized in " + stopwatch.ElapsedMilliseconds + " ms (full " + Seconds(_synthFull) + " s, growl " + Seconds(_synthGrowl) + " s, shriek " + Seconds(_synthShriekA) + " / " + Seconds(_synthShriekB) + " s)."));
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Avenger voice: synthesis failed (" + ex.Message + "), the game's growl is used instead."));
			}
			try
			{
				if (Plugin.AvengerUseRecording != null && Plugin.AvengerUseRecording.Value)
				{
					LoadRecording();
					_useRecording = (Object)(object)_recFull != (Object)null;
				}
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)("Avenger voice: the recording failed to load: " + ex2.Message));
			}
		}

		private static string Seconds(AudioClip clip)
		{
			if (!((Object)(object)clip == (Object)null))
			{
				return clip.length.ToString("F2");
			}
			return "-";
		}

		private static AudioClip MakeClip(string name, float[] data)
		{
			int num = data.Length;
			int num2 = Mathf.Min(num, 96);
			for (int i = 0; i < num2; i++)
			{
				data[i] *= (float)i / (float)num2;
			}
			AudioClip obj = AudioClip.Create(name, num, 1, 24000, false);
			obj.SetData(data, 0);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static void LoadRecording()
		{
			byte[] b;
			using (Stream stream = typeof(AvengerVoiceClips).Assembly.GetManifestResourceStream("ParanoiaMod.avenger_voice.wav"))
			{
				if (stream == null)
				{
					Plugin.Log.LogInfo((object)"Avenger voice: UseRecording is on, but no recording is embedded in this build; the synthesized voice stays.");
					return;
				}
				MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				b = memoryStream.ToArray();
			}
			if (!ParseWav(b, out var data, out var rate, out var why))
			{
				Plugin.Log.LogWarning((object)("Avenger voice: cannot read the recording (" + why + "), the synthesized voice stays."));
				return;
			}
			_recFull = Make("ParanoiaAvengerVoice", data, 0, rate);
			int start = Mathf.Clamp((int)(0.64f * (float)rate), 0, data.Length - 1);
			_recShriek = Make("ParanoiaAvengerShriek", data, start, rate);
			Plugin.Log.LogInfo((object)("Avenger voice: the embedded recording is used (" + ((float)data.Length / (float)rate).ToString("F2") + " s, " + rate + " Hz)."));
		}

		private static AudioClip Make(string name, float[] data, int start, int rate)
		{
			int num = data.Length - start;
			float[] array = new float[num];
			Array.Copy(data, start, array, 0, num);
			int num2 = Mathf.Min(num, (int)(0.006f * (float)rate));
			for (int i = 0; i < num2; i++)
			{
				array[i] *= (float)i / (float)num2;
			}
			AudioClip obj = AudioClip.Create(name, num, 1, rate, false);
			obj.SetData(array, 0);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static bool ParseWav(byte[] b, out float[] data, out int rate, out string why)
		{
			data = null;
			rate = 0;
			why = null;
			if (b == null || b.Length < 44 || b[0] != 82 || b[1] != 73 || b[2] != 70 || b[3] != 70)
			{
				why = "not a RIFF file";
				return false;
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 12;
			while (num4 + 8 <= b.Length)
			{
				char c = (char)b[num4];
				string text = c.ToString();
				c = (char)b[num4 + 1];
				string text2 = c.ToString();
				c = (char)b[num4 + 2];
				string text3 = c.ToString();
				c = (char)b[num4 + 3];
				string text4 = text + text2 + text3 + c;
				int num5 = BitConverter.ToInt32(b, num4 + 4);
				int num6 = num4 + 8;
				if (text4 == "fmt ")
				{
					num3 = BitConverter.ToInt16(b, num6);
					num = BitConverter.ToInt16(b, num6 + 2);
					rate = BitConverter.ToInt32(b, num6 + 4);
					num2 = BitConverter.ToInt16(b, num6 + 14);
				}
				else if (text4 == "data")
				{
					if (num3 != 1 || num2 != 16 || num < 1 || rate <= 0)
					{
						why = "unsupported format " + num3 + "/" + num2 + " bit/" + num + " ch";
						return false;
					}
					int num7 = Mathf.Min(num5, b.Length - num6) / (2 * num);
					data = new float[num7];
					for (int i = 0; i < num7; i++)
					{
						float num8 = 0f;
						for (int j = 0; j < num; j++)
						{
							num8 += (float)BitConverter.ToInt16(b, num6 + (i * num + j) * 2) / 32768f;
						}
						data[i] = num8 / (float)num;
					}
					return num7 > 0;
				}
				num4 = num6 + num5 + (num5 & 1);
			}
			why = "no data chunk";
			return false;
		}
	}
	internal static class AvengerVoiceSynth
	{
		internal sealed class Rng
		{
			private uint _s;

			public Rng(uint seed)
			{
				_s = ((seed == 0) ? 1u : seed);
			}

			private uint Next()
			{
				uint s = _s;
				s ^= s << 13;
				s ^= s >> 17;
				return _s = s ^ (s << 5);
			}

			public double Noise()
			{
				return (double)(Next() >> 8) / 8388608.0 - 1.0;
			}
		}

		internal sealed class Resonator
		{
			private double _y1;

			private double _y2;

			public double Run(double x, double f, double bw)
			{
				double num = Math.Exp(-Math.PI * bw / 24000.0);
				double num2 = Math.PI * 2.0 * f / 24000.0;
				double num3 = 2.0 * num * Math.Cos(num2);
				double num4 = (0.0 - num) * num;
				double num5 = (1.0 - num) * Math.Sqrt(Math.Max(1E-06, 1.0 - 2.0 * num * Math.Cos(2.0 * num2) + num * num)) * x + num3 * _y1 + num4 * _y2;
				_y2 = _y1;
				_y1 = num5;
				return num5;
			}
		}

		public const int Rate = 24000;

		private const double TwoPi = Math.PI * 2.0;

		public static float[] Growl(float seconds = 1.9f, uint seed = 11u)
		{
			int num = (int)(seconds * 24000f);
			Rng rng = new Rng(seed);
			float[] obj = new float[10] { 0f, 46f, 0.5f, 60f, 1f, 76f, 1.4f, 104f, 0f, 66f };
			obj[8] = seconds;
			float[] array = obj;
			float[][] array2 = new float[4][];
			float[] obj2 = new float[8] { 0f, 430f, 1f, 520f, 1.3f, 760f, 0f, 560f };
			obj2[6] = seconds;
			array2[0] = obj2;
			float[] obj3 = new float[8] { 0f, 760f, 1f, 900f, 1.3f, 1250f, 0f, 900f };
			obj3[6] = seconds;
			array2[1] = obj3;
			array2[2] = new float[4] { 0f, 2400f, seconds, 2600f };
			array2[3] = new float[4] { 0f, 3300f, seconds, 3400f };
			float[][] formk = array2;
			float[] obj4 = new float[8] { 0f, 0.1f, 1f, 0.18f, 1.35f, 0.4f, 0f, 0.25f };
			obj4[6] = seconds;
			float[] noisek = obj4;
			float[] subk = new float[4] { 0f, 0.5f, seconds, 0.9f };
			float[] obj5 = new float[6] { 0f, 0.55f, 1.2f, 0.45f, 0f, 0.25f };
			obj5[4] = seconds;
			float[] amk = obj5;
			float[] obj6 = new float[6] { 0f, 1.4f, 1.3f, 2.6f, 0f, 1.8f };
			obj6[4] = seconds;
			float[] drivek = obj6;
			float[] oqk = new float[4] { 0f, 0.55f, seconds, 0.5f };
			float[] vibk = new float[4] { 0f, 0.02f, seconds, 0.03f };
			float[] array3 = Voice(num, rng, array, formk, noisek, subk, amk, 31.0, drivek, oqk, 0.025, 0.25, vibk, 0.3, 0.25);
			float[] array4 = (float[])array.Clone();
			for (int i = 1; i < array4.Length; i += 2)
			{
				array4[i] *= 0.5f;
			}
			float[] array5 = Voice(num, rng, array4, formk, noisek, subk, amk, 27.0, drivek, oqk, 0.04, 0.3, vibk, 0.25, 0.2);
			float[] array6 = new float[num];
			for (int j = 0; j < num; j++)
			{
				array6[j] = array3[j] + 0.55f * array5[j];
			}
			array6 = DcBlock(Level(array6, 0.22, 0.9));
			for (int k = 0; k < num; k++)
			{
				array6[k] = (float)Math.Tanh((double)array6[k] * Envelope(k, 0.3, 1.35, 0.3));
			}
			return array6;
		}

		public static float[] Shriek(float seconds = 1.15f, uint seed = 23u, float pitch = 1f)
		{
			int num = (int)(seconds * 24000f);
			Rng rng = new Rng(seed);
			float[] obj = new float[10] { 0f, 0f, 0.08f, 0f, 0.35f, 0f, 0.7f, 0f, 0f, 0f };
			obj[1] = 250f * pitch;
			obj[3] = 430f * pitch;
			obj[5] = 650f * pitch;
			obj[7] = 560f * pitch;
			obj[8] = seconds;
			obj[9] = 330f * pitch;
			float[] array = obj;
			float[][] array2 = new float[4][];
			float[] obj2 = new float[8] { 0f, 800f, 0.4f, 420f, 0.8f, 760f, 0f, 650f };
			obj2[6] = seconds;
			array2[0] = obj2;
			float[] obj3 = new float[8] { 0f, 1250f, 0.4f, 2200f, 0.8f, 1300f, 0f, 1100f };
			obj3[6] = seconds;
			array2[1] = obj3;
			float[] obj4 = new float[6] { 0f, 2700f, 0.4f, 3000f, 0f, 2700f };
			obj4[4] = seconds;
			array2[2] = obj4;
			float[] obj5 = new float[6] { 0f, 3500f, 0.4f, 3700f, 0f, 3500f };
			obj5[4] = seconds;
			array2[3] = obj5;
			float[][] formk = array2;
			float[] obj6 = new float[6] { 0f, 0.22f, 0.5f, 0.3f, 0f, 0.5f };
			obj6[4] = seconds;
			float[] noisek = obj6;
			float[] obj7 = new float[8] { 0f, 0f, 0.3f, 0f, 0.6f, 0.9f, 0f, 0.7f };
			obj7[6] = seconds;
			float[] subk = obj7;
			float[] amk = new float[4] { 0f, 0f, seconds, 0f };
			float[] drivek = new float[4] { 0f, 2f, seconds, 2.6f };
			float[] oqk = new float[4] { 0f, 0.7f, seconds, 0.55f };
			float[] obj8 = new float[8] { 0f, 0f, 0.2f, 0.012f, 0.8f, 0.03f, 0f, 0.03f };
			obj8[6] = seconds;
			float[] vibk = obj8;
			float[] array3 = Voice(num, rng, array, formk, noisek, subk, amk, 0.0, drivek, oqk, 0.015, 0.2, vibk, 0.8, 0.9);
			float[] array4 = (float[])array.Clone();
			for (int i = 1; i < array4.Length; i += 2)
			{
				array4[i] *= 0.5035f;
			}
			float[] array5 = Voice(num, rng, array4, formk, noisek, subk, amk, 0.0, drivek, oqk, 0.03, 0.25, vibk, 0.6, 0.6);
			float[] array6 = new float[num];
			for (int j = 0; j < num; j++)
			{
				array6[j] = array3[j] + 0.5f * array5[j];
			}
			array6 = DcBlock(Level(array6, 0.22, 0.9));
			double hold = (double)seconds * 0.54;
			for (int k = 0; k < num; k++)
			{
				array6[k] = (float)Math.Tanh((double)array6[k] * Envelope(k, 0.03, hold, 0.3));
			}
			return array6;
		}

		public static float[] Full()
		{
			float[] array = Growl(1.45f);
			float[] array2 = Shriek();
			int num = 22080;
			int num2 = num + array2.Length;
			float[] array3 = new float[num2];
			for (int i = 0; i < array.Length; i++)
			{
				double num3 = ((i < num) ? 1.0 : Math.Max(0.0, 1.0 - (double)(i - num) / (double)(array.Length - num)));
				array3[i] += array[i] * 0.75f * (float)num3;
			}
			for (int j = 0; j < array2.Length; j++)
			{
				array3[num + j] += array2[j] * 0.9f;
			}
			for (int k = 0; k < num2; k++)
			{
				array3[k] = (float)Math.Tanh((double)array3[k] * 1.1);
			}
			return array3;
		}

		public static float[] Normalize(float[] x, float peak = 0.9f)
		{
			float num = 0f;
			for (int i = 0; i < x.Length; i++)
			{
				float num2 = Math.Abs(x[i]);
				if (num2 > num)
				{
					num = num2;
				}
			}
			if (num < 1E-06f)
			{
				return x;
			}
			float num3 = peak / num;
			for (int j = 0; j < x.Length; j++)
			{
				x[j] *= num3;
			}
			return x;
		}

		internal static double Track(float[] k, double t)
		{
			if (t <= (double)k[0])
			{
				return k[1];
			}
			for (int i = 2; i < k.Length; i += 2)
			{
				if (t <= (double)k[i])
				{
					double num = k[i - 2];
					double num2 = k[i - 1];
					double num3 = k[i];
					double num4 = k[i + 1];
					double num5 = (t - num) / (num3 - num);
					num5 = num5 * num5 * (3.0 - 2.0 * num5);
					return num2 + (num4 - num2) * num5;
				}
			}
			return k[^1];
		}

		internal static double Glottal(double p, double oq)
		{
			double num = oq * 0.62;
			double num2 = oq * 0.38;
			if (p < num)
			{
				return 0.5 * Math.Sin(Math.PI * p / num) * (num2 / num);
			}
			if (p < num + num2)
			{
				return 0.0 - Math.Sin(Math.PI / 2.0 * (p - num) / num2);
			}
			return 0.0;
		}

		internal static float[] Voice(int n, Rng rng, float[] f0k, float[][] formk, float[] noisek, float[] subk, float[] amk, double amRate, float[] drivek, float[] oqk, double jitter, double shimmer, float[] vibk, double lp, double bright)
		{
			float[] array = new float[n];
			Resonator[] array2 = new Resonator[4];
			for (int i = 0; i < 4; i++)
			{
				array2[i] = new Resonator();
			}
			double[] array3 = new double[4] { 70.0, 90.0, 140.0, 200.0 };
			double[] array4 = new double[4];
			double num = 0.0;
			double num2 = 1.0;
			double num3 = 0.0;
			double num4 = 1.0;
			double num5 = 0.0;
			double num6 = 0.0;
			double num7 = 0.0;
			double num8 = 1.0 / 600.0;
			for (int j = 0; j < n; j++)
			{
				double num9 = (double)j / 24000.0;
				double num10 = Track(f0k, num9);
				double num11 = Track(vibk, num9);
				num10 *= 1.0 + num11 * Math.Sin(36.4424747816416 * num9) + num3;
				double num12 = Track(subk, num9);
				num10 *= 1.0 + 0.06 * num12 * num2;
				num += num10 / 24000.0;
				if (num >= 1.0)
				{
					num -= 1.0;
					num2 = 0.0 - num2;
					num3 = rng.Noise() * jitter;
					num4 = 1.0 + rng.Noise() * shimmer;
				}
				double num13 = Track(oqk, num9);
				double num14 = Glottal(num, num13) * num4 * (1.0 - 0.45 * num12 * (num2 + 1.0) * 0.5);
				double num15 = Track(noisek, num9);
				num14 = num14 * (1.0 - num15) + rng.Noise() * num15 * (0.35 + 0.65 * ((num < num13) ? 1.0 : 0.4));
				for (int k = 0; k < 4; k++)
				{
					array4[k] = Track(formk[k], num9);
				}
				double num16 = num14;
				for (int l = 0; l < 4; l++)
				{
					num16 = array2[l].Run(num16, array4[l], array3[l] + 0.04 * array4[l]);
				}
				double num17 = Track(amk, num9);
				if (num17 > 0.0)
				{
					num16 *= 1.0 - num17 * (0.5 + 0.5 * Math.Sin(Math.PI * 2.0 * amRate * num9));
				}
				num7 += (num16 * num16 - num7) * num8;
				num16 *= Math.Min(4000.0, 0.3 / (Math.Sqrt(num7) + 1E-06));
				num16 = Math.Tanh(Track(drivek, num9) * num16);
				num5 += (num16 - num5) * lp;
				array[j] = (float)(num5 + bright * (num5 - num6));
				num6 = num5;
			}
			return array;
		}

		internal static float[] Level(float[] x, double target, double power)
		{
			double num = 1.0 / 480.0;
			double num2 = 0.0;
			float[] array = new float[x.Length];
			for (int i = 0; i < x.Length; i++)
			{
				double num3 = x[i];
				num2 += (num3 * num3 - num2) * num;
				double val = Math.Pow(target / (Math.Sqrt(num2) + 0.004), power);
				array[i] = (float)(num3 * Math.Min(400.0, val));
			}
			return array;
		}

		internal static float[] DcBlock(float[] x)
		{
			float[] array = new float[x.Length];
			double num = 0.0;
			double num2 = 0.0;
			for (int i = 0; i < x.Length; i++)
			{
				double num3 = x[i];
				num2 = num3 - num + 0.995 * num2;
				num = num3;
				array[i] = (float)num2;
			}
			return array;
		}

		internal static double Envelope(int i, double attack, double hold, double decay)
		{
			double num = (double)i / 24000.0;
			double num2 = Math.Min(1.0, num / attack);
			num2 = 0.5 - 0.5 * Math.Cos(Math.PI * num2);
			double num3 = 1.0;
			if (num > hold)
			{
				num3 = Math.Exp((0.0 - (num - hold)) / decay * 3.0);
			}
			return num2 * num3;
		}
	}
	internal class BloodAvenger
	{
		private enum Phase
		{
			Chase,
			Climax,
			Away,
			Gone
		}

		private class Rag
		{
			public Transform T;

			public float Yaw;

			public float BaseX;

			public float Phase;

			public float Drag = 1f;
		}

		private class Puff
		{
			public Transform T;

			public SpriteRenderer R;

			public Vector3 Velocity;

			public float Age;

			public float Life = 1f;

			public float Size0 = 0.3f;

			public float Size1 = 1f;

			public float MaxAlpha = 0.5f;

			public float Roll;

			public float Spin;

			public bool Alive;
		}

		private struct Ring
		{
			public float Y;

			public float X;

			public float Z;

			public float Rx;

			public float Rz;

			public Ring(float y, float x, float z, float rx, float rz)
			{
				Y = y;
				X = x;
				Z = z;
				Rx = rx;
				Rz = rz;
			}
		}

		private const float FaceWorldSize = 0.46f;

		private const float IdleSeconds = 2.6f;

		private const float ForcedLead = 6.4f;

		private const float DarkStart = 0.12f;

		private const float DarkEnd = 0.6f;

		private const float StrikeGap = 0.62f;

		private const float FlashLen = 0.45f;

		private const float StrikeWind = 0.14f;

		private const float StrikeSwing = 0.16f;

		private const float StrikeStand = 1.3f;

		private const float CreepSpeed = 3.2f;

		private const float FinalDistance = 2.3f;

		private const int PuffCount = 40;

		private const float BeamRange = 24f;

		private static Sprite _faceSprite;

		private static Sprite _smokeSprite;

		private static AudioClip _humClip;

		private static Material _bodyMaterial;

		private static Mesh _capsuleMesh;

		private static Mesh _sphereMesh;

		private static int _sightMask;

		private Transform _root;

		private Transform _torso;

		private Transform _head;

		private Transform _legL;

		private Transform _legR;

		private Transform _armL;

		private Transform _armR;

		private Transform _kneeL;

		private Transform _kneeR;

		private Transform _elbowL;

		private Transform _elbowR;

		private SpriteRenderer _face;

		private GameObject _smokeRoot;

		private AudioSource _hum;

		private AudioSource _music;

		private readonly List<MeshRenderer> _bodyRenderers = new List<MeshRenderer>();

		private readonly List<Puff> _puffs = new List<Puff>();

		private readonly List<Rag> _rags = new List<Rag>();

		private readonly List<Mesh> _ownMeshes = new List<Mesh>();

		private Phase _phase;

		private float _scale = 1f;

		private float _clock;

		private float _age;

		private float _light = 1f;

		private float _climaxT;

		private Vector3 _climaxTo;

		private bool _flashDone;

		private int _strikeNo;

		private int _windows = 1;

		private float _vanishAt;

		private float _finishAt;

		private bool _bodyOn;

		private Vector3 _pos;

		private Vector3 _moveDir = Vector3.forward;

		private Vector3 _climaxFrom;

		private Vector3 _climaxDir = Vector3.forward;

		private float _yaw;

		private float _speedNow;

		private float _moved;

		private float _walk;

		private float _stepAcc;

		private readonly NavMeshPath _path = new NavMeshPath();

		private Vector3[] _corners;

		private float _nextRepath;

		private float _pathLength = 30f;

		private float _pathFail;

		private string _spawnInfo = string.Empty;

		private bool _seen;

		private bool _hasLos;

		private bool _inBeam;

		private bool _lit;

		private float _beam = 1f;

		private float _threat;

		private float _nextSight;

		private float _freezeUntil;

		private float _nextFreeze;

		private Vector3 _prevPlayer;

		private bool _hasPrevPlayer;

		private float _playerSpeed;

		private PlayerControllerB _local;

		private Transform _cam;

		private float _duration;

		private int _strikesPlanned;

		private int _strikesDone;

		private float _awayUntil;

		private float _nextDiag;

		private bool _flkActive;

		private bool _flkTeleported;

		private float _flkStart;

		private float _flkLength;

		private float _flkGap;

		private float _flkSeed;

		private float _nextFlk;

		private float _nextVoice;

		private float _strikeT = -1f;

		private bool _strikeHit;

		private bool _strikeReach;

		private Vector3 _strikeFrom;

		private Vector3 _strikeTo;

		private bool _aggro;

		private float _unseenFor;

		private float _nextAggro;

		private float _nextTeleport;

		private float _faceHideUntil;

		private float _beamGlitch = 1f;

		private float _musicLevel;

		private float _nextGlitch;

		private float _glitchUntil;

		private Vector3 _glitchTilt;

		private float _emit;

		private float _nextBeat;

		private static readonly Dictionary<string, Mesh> LoftCache = new Dictionary<string, Mesh>();

		private static readonly Ring[] TorsoRings = new Ring[12]
		{
			new Ring(-0.12f, 0f, 0f, 0.02f, 0.02f),
			new Ring(-0.06f, 0f, 0f, 0.13f, 0.09f),
			new Ring(0.05f, 0f, 0f, 0.15f, 0.1f),
			new Ring(0.22f, 0f, 0f, 0.1f, 0.075f),
			new Ring(0.4f, 0f, 0f, 0.11f, 0.08f),
			new Ring(0.58f, 0f, 0.01f, 0.16f, 0.1f),
			new Ring(0.74f, 0f, 0f, 0.2f, 0.115f),
			new Ring(0.86f, 0f, -0.03f, 0.27f, 0.12f),
			new Ring(0.92f, 0f, -0.05f, 0.28f, 0.14f),
			new Ring(0.99f, 0f, -0.03f, 0.17f, 0.12f),
			new Ring(1.04f, 0f, 0f, 0.07f, 0.07f),
			new Ring(1.09f, 0f, 0.03f, 0.04f, 0.04f)
		};

		private static readonly Ring[] HeadRings = new Ring[8]
		{
			new Ring(-0.14f, 0f, 0.07f, 0.015f, 0.015f),
			new Ring(-0.08f, 0f, 0.05f, 0.05f, 0.05f),
			new Ring(0f, 0f, 0.03f, 0.09f, 0.09f),
			new Ring(0.1f, 0f, 0f, 0.12f, 0.12f),
			new Ring(0.22f, 0f, -0.01f, 0.13f, 0.13f),
			new Ring(0.32f, 0f, -0.02f, 0.115f, 0.12f),
			new Ring(0.4f, 0f, -0.03f, 0.07f, 0.08f),
			new Ring(0.44f, 0f, -0.03f, 0.02f, 0.02f)
		};

		private static readonly Ring[] UpperArmRings = new Ring[5]
		{
			new Ring(0.05f, 0f, 0f, 0.03f, 0.03f),
			new Ring(0f, 0f, 0f, 0.06f, 0.055f),
			new Ring(-0.1f, 0f, 0f, 0.055f, 0.05f),
			new Ring(-0.35f, 0f, 0f, 0.042f, 0.04f),
			new Ring(-0.62f, 0f, 0f, 0.034f, 0.032f)
		};

		private static readonly Ring[] ForearmRings = new Ring[4]
		{
			new Ring(0f, 0f, 0f, 0.034f, 0.032f),
			new Ring(-0.12f, 0f, 0f, 0.04f, 0.036f),
			new Ring(-0.4f, 0f, 0f, 0.03f, 0.028f),
			new Ring(-0.66f, 0f, 0f, 0.024f, 0.022f)
		};

		private static readonly Ring[] PalmRings = new Ring[5]
		{
			new Ring(0.01f, 0f, 0f, 0.025f, 0.014f),
			new Ring(-0.04f, 0f, 0f, 0.048f, 0.017f),
			new Ring(-0.1f, 0f, 0f, 0.05f, 0.015f),
			new Ring(-0.15f, 0f, 0f, 0.035f, 0.012f),
			new Ring(-0.17f, 0f, 0f, 0.02f, 0.01f)
		};

		private static readonly Ring[] ThighRings = new Ring[4]
		{
			new Ring(0.05f, 0f, 0f, 0.03f, 0.03f),
			new Ring(0f, 0f, 0f, 0.09f, 0.085f),
			new Ring(-0.2f, 0f, 0f, 0.085f, 0.08f),
			new Ring(-0.56f, 0f, 0f, 0.052f, 0.05f)
		};

		private static readonly Ring[] ShinRings = new Ring[3]
		{
			new Ring(0f, 0f, 0f, 0.052f, 0.05f),
			new Ring(-0.15f, 0f, 0f, 0.05f, 0.046f),
			new Ring(-0.52f, 0f, 0f, 0.02f, 0.02f)
		};

		private static readonly Ring[] FootRings = new Ring[3]
		{
			new Ring(0f, 0f, 0f, 0.04f, 0.03f),
			new Ring(-0.16f, 0f, 0f, 0.034f, 0.022f),
			new Ring(-0.34f, 0f, 0f, 0f, 0f)
		};

		private const float AggroRange = 42f;

		private const float AggroHalfAngle = 80f;

		public bool Finished { get; private set; }

		public float LightFactor => _light * _beamGlitch;

		public static void Prewarm()
		{
			if ((Object)(object)_faceSprite == (Object)null)
			{
				_faceSprite = MakeFaceSprite();
			}
			if ((Object)(object)_smokeSprite == (Object)null)
			{
				_smokeSprite = MakeSmokeSprite();
			}
			if ((Object)(object)_humClip == (Object)null)
			{
				_humClip = MakeHum();
			}
			AvengerMusic.Prewarm();
			AvengerVoiceClips.Prewarm();
		}

		private static float MusicV(float x)
		{
			return Mathf.Clamp01(x * Plugin.AvengerMusicVolume.Value * Plugin.Volume.Value);
		}

		private static float V2(float x)
		{
			return Mathf.Clamp01(x * Plugin.AvengerVolume.Value * Plugin.Volume.Value);
		}

		private static float V3(float x)
		{
			return Mathf.Clamp01(x * Plugin.AvengerVolume.Value);
		}

		private static int SightMask()
		{
			if (_sightMask == 0)
			{
				int mask = LayerMask.GetMask(new string[6] { "Default", "Room", "Colliders", "MiscLevelGeometry", "Terrain", "Railing" });
				_sightMask = ((mask != 0) ? mask : (-1));
			}
			return _sightMask;
		}

		public bool TrySpawn(PlayerControllerB local, Transform cam, out string error)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			error = null;
			if ((Object)(object)local == (Object)null || (Object)(object)cam == (Object)null)
			{
				error = "no active player";
				return false;
			}
			if (!FindSpawn(local, cam, out var result, out error))
			{
				return false;
			}
			try
			{
				Prewarm();
				Build(result, ((Component)local).transform.position);
			}
			catch (Exception ex)
			{
				Dispose();
				error = "could not build the figure: " + ex.Message;
				return false;
			}
			_phase = Phase.Chase;
			_light = 1f;
			_nextFreeze = Time.time + 3.5f;
			_nextGlitch = Time.time + 1.2f;
			_beamGlitch = 1f;
			_nextFlk = Time.time + 2.6f + Random.Range(2f, 4.5f);
			_nextVoice = Time.time + 2.6f + Random.Range(5f, 9f);
			_nextTeleport = Time.time + 6f;
			Plugin.Log.LogInfo((object)("Blood avenger spawned: " + _spawnInfo));
			PlayAppear();
			return true;
		}

		private bool FindSpawn(PlayerControllerB local, Transform cam, out Vector3 result, out string error, float minMul = 1f, float maxMul = 1f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0055: 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_0076: 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_007f: Expected O, but got Unknown
			//IL_00c4: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//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_0100: 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_0107: 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_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: 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_0126: 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_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			result = Vector3.zero;
			error = null;
			Vector3 position = ((Component)local).transform.position;
			float num = Mathf.Min(Plugin.AvengerSpawnMin.Value, Plugin.AvengerSpawnMax.Value) * minMul;
			float num2 = Mathf.Max(Plugin.AvengerSpawnMin.Value, Plugin.AvengerSpawnMax.Value) * maxMul;
			NavMeshHit val = default(NavMeshHit);
			if (!NavMesh.SamplePosition(position, ref val, 3f, -1))
			{
				error = "no NavMesh under the player (ship or unsupported place)";
				return false;
			}
			Vector3 position2 = ((NavMeshHit)(ref val)).position;
			NavMeshPath val2 = new NavMeshPath();
			int num3 = SightMask();
			bool flag = false;
			float num4 = float.MinValue;
			float num5 = 0f;
			float num6 = (num + num2) * 0.5f;
			NavMeshHit val3 = default(NavMeshHit);
			for (int i = 0; i < 40; i++)
			{
				float num7 = Random.Range(0f, 360f);
				float num8 = Random.Range(num, num2);
				if (!NavMesh.SamplePosition(position + Quaternion.Euler(0f, num7, 0f) * Vector3.forward * num8, ref val3, 5f, -1))
				{
					continue;
				}
				Vector3 position3 = ((NavMeshHit)(ref val3)).position;
				if (Mathf.Abs(position3.y - position.y) > 3.5f)
				{
					continue;
				}
				float num9 = Vector3.Distance(position3, position);
				if (num9 < num * 0.7f || !NavMesh.CalculatePath(position3, position2, -1, val2) || (int)val2.status != 0)
				{
					continue;
				}
				float num10 = PathLength(val2.corners);
				if (num10 > num2 * 2.5f + 10f)
				{
					continue;
				}
				bool flag2 = !Physics.Linecast(cam.position, position3 + Vector3.up * 1.6f, num3, (QueryTriggerInteraction)1);
				float num11 = Vector3.Angle(cam.forward, position3 - cam.position);
				float num12 = Random.value * 0.6f;
				if (Plugin.AvengerSpawnHidden.Value)
				{
					num12 += (flag2 ? (-2.5f) : 1.2f);
					num12 += Mathf.Clamp(num10 / Mathf.Max(1f, num9) - 1f, 0f, 1.5f);
				}
				else
				{
					if (flag2)
					{
						num12 += 1.5f;
					}
					if (flag2 && num11 < 70f)
					{
						num12 += 1f;
					}
				}
				num12 -= Mathf.Abs(num9 - num6) * 0.02f;
				if (num12 > num4)
				{
					num4 = num12;
					num5 = num10;
					result = position3;
					flag = true;
				}
			}
			if (!flag)
			{
				error = "no reachable spot on NavMesh " + num.ToString("F0") + "-" + num2.ToString("F0") + " m away";
				return false;
			}
			_spawnInfo = Vector3.Distance(result, position).ToString("F0") + " m away, path " + num5.ToString("F0") + " m";
			return true;
		}

		private static float PathLength(Vector3[] corners)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			if (corners == null)
			{
				return num;
			}
			for (int i = 1; i < corners.Length; i++)
			{
				num += Vector3.Distance(corners[i - 1], corners[i]);
			}
			return num;
		}

		private static Material BodyMaterial()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0049: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_0068: Expected O, but got Unknown
			if ((Object)(object)_bodyMaterial != (Object)null)
			{
				return _bodyMaterial;
			}
			GameObject val = new GameObject("ParanoiaAvengerTemp");
			Material sharedMaterial = ((Renderer)val.AddComponent<SpriteRenderer>()).sharedMaterial;
			Object.DestroyImmediate((Object)val);
			Material val2 = (((Object)(object)sharedMaterial != (Object)null) ? new Material(sharedMaterial) : new Material(Shader.Find("Sprites/Default")));
			val2.color = Color.black;
			((Object)val2).hideFlags = (HideFlags)61;
			_bodyMaterial = val2;
			return val2;
		}

		private static Mesh GetMesh(PrimitiveType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = (((int)type == 0) ? _sphereMesh : _capsuleMesh);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			GameObject obj = GameObject.CreatePrimitive(type);
			Mesh sharedMesh = obj.GetComponent<MeshFilter>().sharedMesh;
			Object.DestroyImmediate((Object)(object)obj);
			Mesh val2 = Object.Instantiate<Mesh>(sharedMesh);
			try
			{
				Color[] array = (Color[])(object)new Color[val2.vertexCount];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = Color.white;
				}
				val2.colors = array;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Blood avenger: could not set vertex colors: " + ex.Message));
			}
			((Object)val2).hideFlags = (HideFlags)61;
			if ((int)type == 0)
			{
				_sphereMesh = val2;
			}
			else
			{
				_capsuleMesh = val2;
			}
			return val2;
		}

		private Transform Pivot(string name, Transform parent, Vector3 localPosition)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			return val.transform;
		}

		private void AttachMesh(GameObject go, PrimitiveType type)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			AttachMeshRaw(go, GetMesh(type));
		}

		private void AttachMeshRaw(GameObject go, Mesh mesh)
		{
			go.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer val = go.AddComponent<MeshRenderer>();
			((Renderer)val).sharedMaterial = BodyMaterial();
			((Renderer)val).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val).receiveShadows = false;
			((Renderer)val).sortingOrder = 0;
			((Renderer)val).enabled = false;
			_bodyRenderers.Add(val);
		}

		private void Blob(string name, Transform parent, Vector3 localPosition, Vector3 size, Vector3 euler)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			val.transform.localRotation = Quaternion.Euler(euler);
			val.transform.localScale = size;
			AttachMesh(val, (PrimitiveType)0);
		}

		private void MeshPart(string name, Transform parent, Mesh mesh, Vector3 localPosition, Vector3 localEuler)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			val.transform.localRotation = Quaternion.Euler(localEuler);
			AttachMeshRaw(val, mesh);
		}

		private static Ring[] FingerRings(float reach)
		{
			return new Ring[4]
			{
				new Ring(0f, 0f, 0f, 0.014f, 0.012f),
				new Ring((0f - reach) * 0.4f, 0f, 0f, 0.01f, 0.009f),
				new Ring((0f - reach) * 0.8f, 0f, 0f, 0.006f, 0.006f),
				new Ring(0f - reach, 0f, 0f, 0f, 0f)
			};
		}

		private static Mesh GetLoft(string key, Ring[] rings, int sides)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			if (LoftCache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			int num = rings.Length;
			Vector3[] array = (Vector3[])(object)new Vector3[num * sides];
			for (int i = 0; i < num; i++)
			{
				Ring ring = rings[i];
				for (int j = 0; j < sides; j++)
				{
					float num2 = (float)j * (MathF.PI * 2f) / (float)sides;
					array[i * sides + j] = new Vector3(ring.X + Mathf.Cos(num2) * ring.Rx, ring.Y, ring.Z + Mathf.Sin(num2) * ring.Rz);
				}
			}
			int[] array2 = new int[(num - 1) * sides * 6];
			int num3 = 0;
			for (int k = 0; k < num - 1; k++)
			{
				for (int l = 0; l < sides; l++)
				{
					int num4 = (l + 1) % sides;
					int num5 = k * sides + l;
					int num6 = k * sides + num4;
					int num7 = (k + 1) * sides + l;
					int num8 = (k + 1) * sides + num4;
					array2[num3++] = num5;
					array2[num3++] = num7;
					array2[num3++] = num6;
					array2[num3++] = num6;
					array2[num3++] = num7;
					array2[num3++] = num8;
				}
			}
			Mesh val = FinishMesh(key, array, array2);
			LoftCache[key] = val;
			return val;
		}

		private static Mesh FinishMesh(string name, Vector3[] vertices, int[] triangles)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh();
			((Object)val).name = "ParanoiaAvenger_" + name;
			val.vertices = vertices;
			val.triangles = triangles;
			Color[] array = (Color[])(object)new Color[vertices.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Color.white;
			}
			val.colors = array;
			val.RecalculateNormals();
			val.RecalculateBounds();
			((Object)val).hideFlags = (HideFlags)61;
			return val;
		}

		private static Mesh MakeRagMesh(float width, float length)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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)
			float num = width * 0.5f;
			float num2 = Random.Range(0.92f, 1f);
			float num3 = Random.Range(0.78f, 0.97f);
			float num4 = Random.Range(0.66f, 0.76f);
			float num5 = Random.Range(-0.45f, -0.2f);
			float num6 = Random.Range(0.15f, 0.42f);
			Vector3[] vertices = (Vector3[])(object)new Vector3[9]
			{
				new Vector3(0f - num, 0f, 0f),
				new Vector3(num, 0f, 0f),
				new Vector3((0f - num) * 0.92f, (0f - length) * 0.42f, 0f),
				new Vector3(num * 0.95f, (0f - length) * 0.48f, 0f),
				new Vector3((0f - num) * 0.78f, (0f - length) * 0.7f, 0f),
				new Vector3(num * 0.72f, (0f - length) * 0.74f, 0f),
				new Vector3(width * num5, (0f - length) * num2, 0f),
				new Vector3(width * 0.02f, (0f - length) * num4, 0f),
				new Vector3(width * num6, (0f - length) * num3, 0f)
			};
			int[] triangles = new int[21]
			{
				0, 1, 3, 0, 3, 2, 2, 3, 5, 2,
				5, 4, 4, 6, 7, 4, 7, 5, 7, 8,
				5
			};
			return FinishMesh("rag", vertices, triangles);
		}

		private Transform BuildArm(Transform shoulder)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00d4: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			MeshPart("UpperArm", shoulder, GetLoft("upperArm", UpperArmRings, 8), Vector3.zero, Vector3.zero);
			Transform val = Pivot("Elbow", shoulder, new Vector3(0f, -0.62f, 0f));
			Blob("ElbowJoint", val, Vector3.zero, new Vector3(0.068f, 0.068f, 0.064f), Vector3.zero);
			MeshPart("Forearm", val, GetLoft("foreArm", ForearmRings, 8), Vector3.zero, Vector3.zero);
			Transform parent = Pivot("Wrist", val, new Vector3(0f, -0.66f, 0f));
			MeshPart("Palm", parent, GetLoft("palm", PalmRings, 8), Vector3.zero, Vector3.zero);
			float[] array = new float[4] { -0.032f, -0.011f, 0.011f, 0.032f };
			float[] array2 = new float[4] { 0.26f, 0.34f, 0.32f, 0.24f };
			for (int i = 0; i < array.Length; i++)
			{
				MeshPart("Finger", parent, GetLoft("finger" + i, FingerRings(array2[i]), 5), new Vector3(array[i], -0.14f, 0f), new Vector3(-10f, 0f, array[i] * 500f));
			}
			return val;
		}

		private Transform BuildLeg(Transform hip)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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)
			MeshPart("Thigh", hip, GetLoft("thigh", ThighRings, 8), Vector3.zero, Vector3.zero);
			Transform val = Pivot("Knee", hip, new Vector3(0f, -0.56f, 0.02f));
			Blob("KneeJoint", val, Vector3.zero, new Vector3(0.104f, 0.104f, 0.1f), Vector3.zero);
			MeshPart("Shin", val, GetLoft("shin", ShinRings, 8), Vector3.zero, Vector3.zero);
			MeshPart("Foot", val, GetLoft("foot", FootRings, 6), new Vector3(0f, -0.52f, 0f), new Vector3(-90f, 0f, 0f));
			return val;
		}

		private void AddRag(Transform parent, Vector3 at, float width, float length, float yaw, float baseX, float drag)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Pivot("Rag", parent, at);
			val.localRotation = Quaternion.Euler(baseX, yaw, 0f);
			Mesh val2 = MakeRagMesh(width, length);
			_ownMeshes.Add(val2);
			MeshPart("Cloth", val, val2, Vector3.zero, Vector3.zero);
			_rags.Add(new Rag
			{
				T = val,
				Yaw = yaw,
				BaseX = baseX,
				Phase = Random.Range(0f, 6.28f),
				Drag = drag
			});
		}

		private void Build(Vector3 spawn, Vector3 player)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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)
			//IL_0118: 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_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Expected O, but got Unknown
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Expected O, but got Unknown
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Expected O, but got Unknown
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			_scale = Mathf.Clamp(Plugin.AvengerScale.Value, 0.6f, 1.6f);
			GameObject val = new GameObject("ParanoiaAvenger");
			_root = val.transform;
			_root.position = spawn;
			_root.localScale = Vector3.one * _scale;
			_pos = spawn;
			Vector3 val2 = player - spawn;
			val2.y = 0f;
			if (((Vector3)(ref val2)).sqrMagnitude > 0.01f)
			{
				_moveDir = ((Vector3)(ref val2)).normalized;
				_yaw = Mathf.Atan2(val2.x, val2.z) * 57.29578f;
			}
			_root.rotation = Quaternion.Euler(0f, _yaw, 0f);
			_torso = Pivot("Torso", _root, new Vector3(0f, 1.15f, 0f));
			MeshPart("Body", _torso, GetLoft("torso", TorsoRings, 14), Vector3.zero, Vector3.zero);
			_head = Pivot("Head", _torso, new Vector3(0f, 1.06f, 0.05f));
			MeshPart("Skull", _head, GetLoft("head", HeadRings, 14), Vector3.zero, Vector3.zero);
			_armL = Pivot("ArmL", _torso, new Vector3(-0.25f, 0.88f, -0.03f));
			_armR = Pivot("ArmR", _torso, new Vector3(0.25f, 0.88f, -0.03f));
			_elbowL = BuildArm(_armL);
			_elbowR = BuildArm(_armR);
			_legL = Pivot("LegL", _root, new Vector3(-0.11f, 1.12f, 0f));
			_legR = Pivot("LegR", _root, new Vector3(0.11f, 1.12f, 0f));
			_kneeL = BuildLeg(_legL);
			_kneeR = BuildLeg(_legR);
			float[] array = new float[7] { 0f, 50f, 100f, 160f, 200f, 260f, 310f };
			float[] array2 = new float[7] { 0.62f, 0.5f, 0.76f, 1f, 0.9f, 0.68f, 0.52f };
			Vector3 at = default(Vector3);
			for (int i = 0; i < array.Length; i++)
			{
				float num = array[i] * (MathF.PI / 180f);
				((Vector3)(ref at))..ctor(Mathf.Sin(num) * 0.15f, 1.1f, Mathf.Cos(num) * 0.11f);
				AddRag(_root, at, 0.13f, array2[i], array[i], -8f, 1f);
			}
			AddRag(_torso, new Vector3(-0.08f, 0.88f, -0.2f), 0.14f, 1.15f, 180f, -7f, 0.7f);
			AddRag(_torso, new Vector3(0.08f, 0.82f, -0.2f), 0.12f, 1f, 180f, -9f, 0.7f);
			AddRag(_elbowL, new Vector3(-0.03f, 0f, 0f), 0.11f, 0.52f, 90f, -4f, 0.2f);
			AddRag(_elbowR, new Vector3(0.03f, 0f, 0f), 0.11f, 0.48f, 270f, -4f, 0.2f);
			GameObject val3 = new GameObject("Face");
			val3.transform.SetParent(_head, false);
			val3.transform.localPosition = new Vector3(0f, 0.19f, 0.135f);
			val3.transform.localScale = Vector3.one * 0.72f;
			val3.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
			_face = val3.AddComponent<SpriteRenderer>();
			_face.sprite = _faceSprite;
			((Renderer)_face).sortingOrder = 20;
			_face.color = new Color(1f, 1f, 1f, 0f);
			_smokeRoot = new GameObject("ParanoiaAvengerSmoke");
			for (int j = 0; j < 40; j++)
			{
				GameObject val4 = new GameObject("Puff");
				val4.transform.SetParent(_smokeRoot.transform, false);
				Puff puff = new Puff();
				puff.T = val4.transform;
				puff.R = val4.AddComponent<SpriteRenderer>();
				puff.R.sprite = _smokeSprite;
				((Renderer)puff.R).sortingOrder = 5;
				puff.R.color = new Color(1f, 1f, 1f, 0f);
				val4.SetActive(false);
				_puffs.Add(puff);
			}
			AudioClip loop = AvengerMusic.Loop;
			if ((Object)(object)loop != (Object)null)
			{
				_music = _smokeRoot.AddComponent<AudioSource>();
				_music.clip = loop;
				_music.loop = true;
				_music.spatialBlend = 0f;
				_music.playOnAwake = false;
				_music.volume = 0f;
				_music.Play();
			}
			_hum = val.AddComponent<AudioSource>();
			_hum.clip = _humClip;
			_hum.loop = true;
			_hum.spatialBlend = 1f;
			_hum.rolloffMode = (AudioRolloffMode)1;
			_hum.minDistance = 2f;
			_hum.maxDistance = 32f;
			_hum.dopplerLevel = 0f;
			_hum.playOnAwake = false;
			_hum.volume = 0f;
			_hum.Play();
		}

		public void Tick(float dt, PlayerControllerB local, Transform cam, float t, float duration, float flicker, bool lightOn)
		{
			//IL_0078: 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_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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_root == (Object)null || (Object)(object)local == (Object)null || (Object)(object)cam == (Object)null)
			{
				return;
			}
			_local = local;
			_cam = cam;
			_duration = duration;
			_clock += dt;
			_age += dt;
			_moved = 0f;
			_beam = Mathf.Clamp01(flicker * LightFactor);
			Vector3 position = ((Component)local).transform.position;
			MeasurePlayerSpeed(position, dt);
			Vector3 toPlayer = position - _pos;
			toPlayer.y = 0f;
			float magnitude = ((Vector3)(ref toPlayer)).magnitude;
			if (_phase == Phase.Chase)
			{
				UpdateSight(cam);
				UpdateAggro(dt, toPlayer, magnitude);
				if (UpdateFlicker(local, cam, magnitude))
				{
					toPlayer = position - _pos;
					toPlayer.y = 0f;
					magnitude = ((Vector3)(ref toPlayer)).magnitude;
					_nextSight = 0f;
					UpdateSight(cam);
				}
				_lit = _inBeam && _beam > 0.45f && lightOn;
				bool flag = Mathf.Abs(_pos.y - position.y) < 3.2f;
				bool flag2 = _age > 2.6f && flag && magnitude < Plugin.AvengerCatchDistance.Value;
				bool flag3 = t >= duration - 6.4f;
				bool flag4 = _pathFail > 4f;
				if (flag2 || flag3 || flag4)
				{
					BeginClimax(position, flag2 ? "caught up" : (flag3 ? "time is up" : "no path to player"), magnitude);
				}
				else
				{
					Chase(dt, position, magnitude, t, duration);
				}
			}
			if (_phase != Phase.Chase)
			{
				_lit = false;
				_beamGlitch = 1f;
				_flkActive = false;
				ClimaxTick(dt, position);
			}
			if (_phase != Phase.Gone && _phase != Phase.Away)
			{
				UpdateBody(dt, toPlayer, cam);
			}
			UpdateSmoke(dt, cam);
			UpdateAudio(dt, magnitude);
		}

		private void UpdateAggro(float dt, Vector3 toPlayer, float flatDist)
		{
			//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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (_age < 1f)
			{
				return;
			}
			Vector3 val = toPlayer;
			val.y = 0f;
			if (_hasLos && flatDist < 42f && ((Vector3)(ref val)).sqrMagnitude > 0.01f && Vector3.Angle(_root.forward, val) < 80f)
			{
				_unseenFor = 0f;
				if (!_aggro && Time.time >= _nextAggro)
				{
					_aggro = true;
					_nextAggro = Time.time + 12f;
					_nextVoice = Time.time + Random.Range(7f, 12f);
					float num = Mathf.Clamp01(1f - flatDist / 30f);
					PlayVoice(AvengerVoiceClips.Full, 0.95f, Random.Range(0.94f, 1f), Mathf.Lerp(3000f, 9000f, num));
					Plugin.Log.LogInfo((object)("Blood avenger noticed the player at " + flatDist.ToString("F0") + " m: voice."));
				}
			}
			else
			{
				_unseenFor += dt;
				if (_aggro && _unseenFor > 5f)
				{
					_aggro = false;
				}
			}
		}

		private void MeasurePlayerSpeed(Vector3 player, float dt)
		{
			//IL_0061: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			if (_hasPrevPlayer && dt > 0.0001f)
			{
				Vector3 val = player - _prevPlayer;
				val.y = 0f;
				float num = ((Vector3)(ref val)).magnitude / dt;
				if (num < 16f)
				{
					_playerSpeed = Mathf.Lerp(_playerSpeed, num, 1f - Mathf.Exp((0f - dt) / 0.35f));
				}
			}
			_prevPlayer = player;
			_hasPrevPlayer = true;
		}

		private void UpdateSight(Transform cam)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_005d: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			if (!(Time.time < _nextSight))
			{
				_nextSight = Time.time + 0.1f;
				Vector3 val = _pos + Vector3.up * (1.6f * _scale);
				Vector3 val2 = _pos + Vector3.up * (2.3f * _scale);
				Vector3 val3 = val - cam.position;
				int num = SightMask();
				bool flag = !Physics.Linecast(cam.position, val, num, (QueryTriggerInteraction)1);
				bool flag2 = !Physics.Linecast(cam.position, val2, num, (QueryTriggerInteraction)1);
				_hasLos = flag || flag2;
				_seen = _hasLos && Vector3.Angle(cam.forward, val3) < 55f && ((Vector3)(ref val3)).magnitude < 60f;
				float num2 = Mathf.Clamp(Plugin.RedLightCone.Value, 20f, 70f);
				float num3 = Mathf.Min(Vector3.Angle(cam.forward, val3), Vector3.Angle(cam.forward, val2 - cam.position));
				_inBeam = _hasLos && num3 < num2 && ((Vector3)(ref val3)).magnitude < 24f;
			}
		}

		private bool UpdateFlicker(PlayerControllerB local, Transform cam, float flatDist)
		{
			if (!Plugin.AvengerFlicker.Value || _age < 2.6f)
			{
				_beamGlitch = 1f;
				return false;
			}
			float time = Time.time;
			if (!_flkActive)
			{
				_beamGlitch = 1f;
				if (time >= _nextFlk)
				{
					_flkActive = true;
					_flkStart = time;
					float num = Mathf.Max(0.2f, Mathf.Min(Plugin.AvengerFlickerDarkMin.Value, Plugin.AvengerFlickerDarkMax.Value));
					float num2 = Mathf.Max(num, Mathf.Max(Plugin.AvengerFlickerDarkMin.Value, Plugin.AvengerFlickerDarkMax.Value));
					_flkGap = Random.Range(num, num2);
					_flkLength = Random.Range(0.45f, 0.8f) + _flkGap;
					_flkSeed = Random.Range(0f, 100f);
					_flkTeleported = false;
					TestSounds.Play2D(RedLightAudio.Crackle, V2(0.3f), Random.Range(1.1f, 1.5f));
				}
				return false;
			}
			float num3 = time - _flkStart;
			if (num3 >= _flkLength)
			{
				_flkActive = false;
				_beamGlitch = 1f;
				float num4 = Mathf.Min(Plugin.AvengerFlickerMin.Value, Plugin.AvengerFlickerMax.Value);
				float num5 = Mathf.Max(Plugin.AvengerFlickerMin.Value, Plugin.AvengerFlickerMax.Value);
				float num6 = Mathf.Clamp01(1f - flatDist / 24f);
				_nextFlk = time + Random.Range(Mathf.Max(1.5f, num4), Mathf.Max(2f, num5)) * Mathf.Lerp(1f, 0.55f, num6);
				return false;
			}
			bool num7 = num3 > _flkLength - _flkGap;
			if (num7)
			{
				_beamGlitch = 0f;
			}
			else
			{
				float num8 = Mathf.PerlinNoise(num3 * 16f, _flkSeed);
				_beamGlitch = ((num8 < 0.4f) ? Random.Range(0f, 0.15f) : Random.Range(0.6f, 1f));
			}
			if (num7 && !_flkTeleported)
			{
				_flkTeleported = true;
				if (time >= _nextTeleport && Random.value < Plugin.AvengerTeleportChance.Value)
				{
					return TryTeleport(local, cam);
				}
			}
			return false;
		}

		private bool TryTeleport(PlayerControllerB local, Transform cam)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0075: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)local).transform.position;
			float num = Mathf.Min(Plugin.AvengerTeleportMin.Value, Plugin.AvengerTeleportMax.Value);
			float num2 = Mathf.Max(Plugin.AvengerTeleportMin.Value, Plugin.AvengerTeleportMax.Value);
			num = Mathf.Max(num, Plugin.AvengerCatchDistance.Value + 1.5f);
			num2 = Mathf.Max(num2, num + 1f);
			NavMeshHit val2 = default(NavMeshHit);
			Vector3 val = (NavMesh.SamplePosition(position, ref val2, 3f, -1) ? ((NavMeshHit)(ref val2)).position : position);
			NavMeshPath val3 = new NavMeshPath();
			int num3 = SightMask();
			bool flag = false;
			float num4 = float.MinValue;
			Vector3 pos = _pos;
			NavMeshHit val4 = default(NavMeshHit);
			for (int i = 0; i < 30; i++)
			{
				float num5 = Random.Range(0f, 360f);
				float num6 = Random.Range(num, num2);
				if (!NavMesh.SamplePosition(position + Quaternion.Euler(0f, num5, 0f) * Vector3.forward * num6, ref val4, 3f, -1))
				{
					continue;
				}
				Vector3 position2 = ((NavMeshHit)(ref val4)).position;
				if (Mathf.Abs(position2.y - position.y) > 3.2f)
				{
					continue;
				}
				float num7 = Mathf.Sqrt(FlatSqr(position2 - position));
				if (num7 < num * 0.8f || num7 > num2 * 1.25f || FlatSqr(position2 - _pos) < 9f || !NavMesh.CalculatePath(position2, val, -1, val3) || (int)val3.status != 0)
				{
					continue;
				}
				float num8 = PathLength(val3.corners);
				if (!(num8 > num7 * 3f + 8f))
				{
					bool flag2 = !Physics.Linecast(cam.position, position2 + Vector3.up * (1.6f * _scale), num3, (QueryTriggerInteraction)1);
					float num9 = Random.value * 0.5f;
					num9 += (flag2 ? (-2.5f) : 1.2f);
					num9 += Mathf.Clamp(num8 / Mathf.Max(1f, num7) - 1f, 0f, 1.5f);
					num9 -= num7 * 0.03f;
					if (num9 > num4)
					{
						num4 = num9;
						pos = position2;
						flag = true;
					}
				}
			}
			if (!flag)
			{
				return false;
			}
			Burst(14, 1f);
			Vector3 pos2 = _pos;
			_pos = pos;
			_corners = null;
			_nextRepath = 0f;
			_speedNow = 0f;
			_moved = 0f;
			_nextTeleport = Time.time + Random.Range(9f, 14f);
			_faceHideUntil = Time.time + 0.4f;
			Vector3 val5 = position - _pos;
			val5.y = 0f;
			if (((Vector3)(ref val5)).sqrMagnitude > 0.01f)
			{
				_moveDir = ((Vector3)(ref val5)).normalized;
				_yaw = Mathf.Atan2(val5.x, val5.z) * 57.29578f;
			}
			_root.position = _pos;
			_root.rotation = Quaternion.Euler(0f, _yaw, 0f);
			Burst(10, 0.8f);
			TestSounds.Play3D(RedLightAudio.Crackle, _pos + Vector3.up * 1.2f, V3(0.5f), 0.75f, 900f, 40f);
			if (_aggro)
			{
				PlayVoice(AvengerVoiceClips.Shriek, 0.6f, Random.Range(0.9f, 1.1f), 6000f);
			}
			Plugin.Log.LogInfo((object)("Blood avenger teleported " + Vector3.Distance(pos2, _pos).ToString("F0") + " m, now " + Mathf.Sqrt(FlatSqr(_pos - position)).ToString("F0") + " m from the player."));
			return true;
		}

		private void Chase(float dt, Vector3 player, float flatDist, float t, float duration)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (_age < 2.6f)
			{
				_speedNow = 0f;
				return;
			}
			if (Time.time >= _nextRepath)
			{
				Repath(player);
			}
			float num = Mathf.Max(1f, duration - 6.4f - t);
			float num2 = _pathLength / num;
			bool value = Plugin.AvengerFreezeInLight.Value;
			float num3;
			if (value && _lit)
			{
				num3 = 0f;
			}
			else if (!value && _seen)
			{
				if (Time.time >= _nextFreeze)
				{
					_freezeUntil = Time.time + Random.Range(0.4f, 1.1f);
					_nextFreeze = _freezeUntil + Random.Range(1.2f, 3f);
				}
				num3 = ((Time.time < _freezeUntil) ? 0f : Mathf.Clamp(Mathf.Max(Plugin.AvengerWatchedSpeed.Value, num2), 0f, 3.8f));
			}
			else
			{
				float num4 = Mathf.Max(Plugin.AvengerHiddenSpeed.Value, Plugin.AvengerChaseMaxSpeed.Value);
				float num5 = Mathf.Min(_playerSpeed + Plugin.AvengerChaseMargin.Value, num4);
				num3 = Mathf.Clamp(Mathf.Max(new float[3]
				{
					Plugin.AvengerHiddenSpeed.Value,
					num2,
					num5
				}), 0f, num4);
				if (_flkActive)
				{
					num3 = Mathf.Min(num3 * 1.3f, num4 + 0.8f);
				}
			}
			float num6 = ((num3 < _speedNow) ? 45f : (_flkActive ? 16f : 9f));
			_speedNow = Mathf.MoveTowards(_speedNow, num3, num6 * dt);
			MoveAlongPath(dt);
			if (Time.time >= _nextDiag)
			{
				_nextDiag = Time.time + 3f;
				Plugin.Log.LogInfo((object)("Blood avenger chase: " + flatDist.ToString("F1") + " m away, path " + _pathLength.ToString("F0") + " m, speed " + _speedNow.ToString("F1") + " (target " + num3.ToString("F1") + "), player " + _playerSpeed.ToString("F1") + " m/s, " + (_lit ? "lit by the beam" : (_seen ? "seen, not lit" : "out of sight")) + (_flkActive ? ", flashlight glitch" : "") + ((_corners == null) ? ", NO PATH" : "") + ", music vol " + (((Object)(object)_music != (Object)null) ? _music.volume.ToString("F2") : "none") + ", breath vol " + (((Object)(object)_hum != (Object)null) ? _hum.volume.ToString("F2") : "none") + "."));
			}
		}

		private void Repath(Vector3 player)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			_nextRepath = Time.time + 0.4f;
			Vector3 val = player;
			NavMeshHit val2 = default(NavMeshHit);
			if (NavMesh.SamplePosition(player, ref val2, 3f, -1))
			{
				val = ((NavMeshHit)(ref val2)).position;
			}
			if (NavMesh.CalculatePath(_pos, val, -1, _path) && (int)_path.status != 2 && _path.corners.Length >= 2)
			{
				_corners = _path.corners;
				_pathLength = Mathf.Max(1f, PathLength(_corners));
				if ((int)_path.status == 1)
				{
					_pathFail += 0.4f;
				}
				else
				{
					_pathFail = 0f;
				}
			}
			else
			{
				_corners = null;
				_pathFail += 0.4f;
			}
		}

		private void MoveAlongPath(float dt)
		{
			//IL_0060: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_00e2: 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_00ff: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			if (_corners == null || _corners.Length < 2 || _speedNow < 0.01f)
			{
				return;
			}
			int i;
			for (i = 1; i < _corners.Length - 1 && FlatSqr(_corners[i] - _pos) < 0.25f; i++)
			{
			}
			Vector3 val = _corners[i] - _pos;
			val.y = 0f;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (!(magnitude < 0.001f))
			{
				Vector3 val2 = val / magnitude;
				float num = Mathf.Min(magnitude, _speedNow * dt);
				Vector3 val3 = _pos + val2 * num;
				NavMeshHit val4 = default(NavMeshHit);
				if (NavMesh.SamplePosition(val3, ref val4, 1.5f, -1))
				{
					val3 = ((NavMeshHit)(ref val4)).position;
				}
				Vector3 val5 = val3 - _pos;
				val5.y = 0f;
				_moved = ((Vector3)(ref val5)).magnitude;
				_moveDir = val2;
				_pos = val3;
			}
		}

		private static float FlatSqr(Vector3 v)
		{
			v.y = 0f;
			return ((Vector3)(ref v)).sqrMagnitude;
		}

		private void BeginClimax(Vector3 player, string why, float flatDist)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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)
			_phase = Phase.Climax;
			_climaxT = 0f;
			_climaxFrom = _pos;
			_speedNow = 0f;
			_flashDone = false;
			_nextBeat = 0f;
			if (_strikesPlanned == 0)
			{
				int num = Mathf.Clamp(Plugin.AvengerStrikeCount.Value, 1, 6);
				int num2 = num;
				if (Plugin.AvengerStrikeByDuration.Value && num > 1)
				{
					float num3 = Mathf.Min(Plugin.AvengerMinSeconds.Value, Plugin.AvengerMaxSeconds.Value);
					float num4 = Mathf.Max(Plugin.AvengerMinSeconds.Value, Plugin.AvengerMaxSeconds.Value);
					float num5 = ((num4 - num3 > 1f) ? Mathf.InverseLerp(num3, num4, _duration) : 1f);
					num2 = Mathf.Clamp(1 + (int)(num5 * (float)num), 1, num);
				}
				_strikesPlanned = ((!Plugin.AvengerStrike.Value) ? 1 : num2);
			}
			_windows = 1;
			_strikeNo = 0;
			_vanishAt = 0.6f + (float)_windows * 0.62f + 0.35f;
			_finishAt = _vanishAt + 0.85f;
			Vector3 val = _pos - player;
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = -_moveDir;
			}
			_climaxDir = ((Vector3)(ref val)).normalized;
			float num6 = Mathf.Min(flatDist, Mathf.Max(2.3f, flatDist - 1.5360001f));
			_climaxTo = player + _climaxDir * num6;
			Plugin.Log.LogInfo((object)("Blood avenger: climax (" + why + "), distance " + flatDist.ToString("F1") + " m, strike " + (_strikesDone + 1) + " of " + _strikesPlanned + " (event length " + _duration.ToString("F0") + " s)."));
			TestSounds.Play2D(RedLightAudio.Crackle, V2(0.9f), 0.6f);
			TestSounds.Play2D(TestSounds.Bang, V2(0.45f), 0.45f);
			Burst(10, 0.8f);
		}

		private void BeginStrike(Vector3 player)
		{
			//IL_000d: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0047: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.AvengerStrike.Value)
			{
				Vector3 val = player - _pos;
				val.y = 0f;
				float magnitude = ((Vector3)(ref val)).magnitude;
				_strikeT = 0f;
				_strikeHit = false;
				_strikeFrom = _pos;
				_strikeReach = magnitude <= 3.1999998f;
				if (_strikeReach && magnitude > 1.3f)
				{
					_strikeTo = player - val / magnitude * 1.3f;
				}
				else
				{
					_strikeTo = _pos;
				}
				_strikeTo.y = _pos.y;
			}
		}

		private string DealStrikeDamage()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Clamp(Plugin.AvengerStrikeDamage.Value, 0, 100);
			bool value = Plugin.AvengerStrikeLethal.Value;
			PlayerControllerB local = _local;
			if (num <= 0)
			{
				return " (no damage: StrikeDamage = 0).";
			}
			if ((Object)(object)local == (Object)null || local.isPlayerDead || !local.isPlayerControlled)
			{
				return " (no damage: the player is not alive).";
			}
			int num2 = (value ? num : Mathf.Min(num, local.health - 1));
			if (num2 <= 0)
			{
				return " (no damage: health is too low, StrikeLethal = false).";
			}
			try
			{
				int health = local.health;
				local.DamagePlayer(num2, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
				return ", damage " + num2 + " (health " + health + " -> " + local.health + (local.isPlayerDead ? ", the player died" : "") + ").";
			}
			catch (Exception ex)
			{
				return ", damage FAILED: " + ex.Message;
			}
		}

		private void TickStrike(float dt)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_005d: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			if (_strikeT < 0f)
			{
				return;
			}
			_strikeT += dt;
			float num = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((_strikeT - 0.056f) / 0.3f));
			Vector3 val = Vector3.Lerp(_strikeFrom, _strikeTo, num);
			Vector3 val2 = val - _pos;
			val2.y = 0f;
			_moved = ((Vector3)(ref val2)).magnitude;
			_pos = val;
			if (!_strikeHit && _strikeT >= 0.3f)
			{
				_strikeHit = true;
				if (_strikeReach)
				{
					TestSounds.Play2D(TestSounds.Thud, V2(0.95f), 0.7f);
					TestSounds.Play2D(TestSounds.Bang, V2(0.7f), 0.55f);
					Plugin.Log.LogInfo((object)("Blood avenger: strike " + (_strikesDone + 1) + "/" + _strikesPlanned + " landed" + DealStrikeDamage()));
				}
				else
				{
					TestSounds.Play3D(TestSounds.Thud, _pos + Vector3.up * 1.2f, V3(0.5f), 0.9f, 900f, 30f);
					Plugin.Log.LogInfo((object)("Blood avenger: strike " + (_strikesDone + 1) + "/" + _strikesPlanned + " missed, the player was too far."));
				}
			}
		}

		private void ApplyStrikePose()
		{
			//IL_011f: 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_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			float strikeT = _strikeT;
			float num = 0.3f;
			float num3;
			float num4;
			float num5;
			if (strikeT < 0.14f)
			{
				float num2 = Mathf.SmoothStep(0f, 1f, strikeT / 0.14f);
				num3 = Mathf.Lerp(-4f, 70f, num2);
				num4 = Mathf.Lerp(7f, 18f, num2);
				num5 = Mathf.Lerp(20f, 65f, num2);
			}
			else if (strikeT < num)
			{
				float num6 = (strikeT - 0.14f) / 0.16f;
				num6 *= num6;
				num3 = Mathf.Lerp(70f, -105f, num6);
				num4 = Mathf.Lerp(18f, -14f, num6);
				num5 = Mathf.Lerp(65f, 6f, num6);
			}
			else
			{
				float num7 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((strikeT - num) / 0.45f));
				num3 = Mathf.Lerp(-105f, -4f, num7);
				num4 = Mathf.Lerp(-14f, 7f, num7);
				num5 = Mathf.Lerp(6f, 20f, num7);
			}
			_armR.localRotation = Quaternion.Euler(num3, 0f, num4);
			_elbowR.localRotation = Quaternion.Euler(0f - num5, 0f, 0f);
			float num8 = ((strikeT < num) ? Mathf.Clamp01(strikeT / num) : (1f - Mathf.Clamp01((strikeT - num) / 0.45f)));
			_armL.localRotation = Quaternion.Euler(Mathf.Lerp(-4f, -60f, num8), 0f, Mathf.Lerp(-7f, -4f, num8));
			_elbowL.localRotation = Quaternion.Euler(0f - Mathf.Lerp(20f, 35f, num8), 0f, 0f);
		}

		private void ClimaxTick(float dt, Vector3 player)
		{
			//IL_00c9: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			_climaxT += dt;
			float climaxT = _climaxT;
			if (_phase == Phase.Climax)
			{
				if (climaxT < 0.12f)
				{
					_light = 1f - climaxT / 0.12f;
				}
				else if (climaxT < 0.6f)
				{
					_light = 0f;
				}
				else
				{
					float num = climaxT - 0.6f;
					int num2 = (int)(num / 0.62f);
					_light = ((num2 < _windows && num - (float)num2 * 0.62f < 0.45f) ? 1f : 0f);
				}
				if (climaxT >= 0.12f && climaxT < 0.6f)
				{
					float num3 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((climaxT - 0.12f) / 0.48000002f));
					Vector3 val = Vector3.Lerp(_climaxFrom, _climaxTo, num3);
					NavMeshHit val2 = default(NavMeshHit);
					if (NavMesh.SamplePosition(val, ref val2, 2f, -1))
					{
						val = ((NavMeshHit)(ref val2)).position;
					}
					Vector3 val3 = val - _pos;
					val3.y = 0f;
					_moved = ((Vector3)(ref val3)).magnitude;
					_pos = val;
					_speedNow = ((dt > 0f) ? (_moved / dt) : 0f);
				}
				else
				{
					_speedNow = 0f;
				}
				while (_strikeNo < _windows && climaxT >= 0.6f + (float)_strikeNo * 0.62f)
				{
					bool flag = _strikeNo == 0;
					bool flag2 = _strikeNo == _windows - 1;
					_strikeNo++;
					_flashDone = true;
					if (Plugin.AvengerStrikeFollows.Value)
					{
						SnapToPlayer(player);
					}
					_glitchUntil = Time.time + 0.25f;
					_glitchTilt = new Vector3(14f, Random.Range(-25f, 25f), 24f);
					if (flag)
					{
						TestSounds.Play2D(TestSounds.Bang, V2(0.8f), 0.42f);
						TestSounds.Play2D(RedLightAudio.Crackle, V2(0.8f), 1.2f);
						TestSounds.Play2D(AvengerMusic.Hit, MusicV(0.95f));
					}
					else
					{
						TestSounds.Play2D(TestSounds.Bang, V2(0.7f), 0.5f);
						TestSounds.Play2D(AvengerMusic.Hit, MusicV(0.7f), 1.15f);
					}
					if (flag || flag2)
					{
						PlayVoice(AvengerVoiceClips.Shriek, flag ? 1f : 0.85f, flag ? 0.8f : 0.92f, 0f);
					}
					Burst(8, 0.6f);
					BeginStrike(player);
				}
				TickStrike(dt);
				if (climaxT >= _vanishAt)
				{
					EndOfStrike();
				}
			}
			else if (_phase == Phase.Away)
			{
				_light = Mathf.Clamp01((climaxT - _vanishAt) / 0.8f);
				_speedNow = 0f;
				if (Time.time >= _awayUntil)
				{
					Reappear();
				}
			}
			else
			{
				_light = Mathf.Clamp01((climaxT - _vanishAt) / 0.8f);
				if (climaxT >= _finishAt)
				{
					Finished = true;
				}
			}
		}

		private void SnapToPlayer(Vector3 player)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: 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)
			Transform cam = _cam;
			if ((Object)(object)cam == (Object)null)
			{
				return;
			}
			Vector3 val = player - _pos;
			val.y = 0f;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude <= 2.9f)
			{
				return;
			}
			Vector3 val2 = cam.forward;
			val2.y = 0f;
			if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
			{
				val2 = -val;
			}
			((Vector3)(ref val2)).Normalize();
			int num = SightMask();
			float[] array = new float[8] { 0f, 30f, -30f, 60f, -60f, 100f,