Decompiled source of Victor Deadlock v0.2.10

plugins/Wish-Victor/NAudio.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Win32;
using NAudio.CoreAudioApi;
using NAudio.CoreAudioApi.Interfaces;
using NAudio.Dmo;
using NAudio.Dmo.Effect;
using NAudio.Dsp;
using NAudio.FileFormats.Wav;
using NAudio.MediaFoundation;
using NAudio.Mixer;
using NAudio.Utils;
using NAudio.Wave;
using NAudio.Wave.Asio;
using NAudio.Wave.Compression;
using NAudio.Wave.SampleProviders;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("NAudioTests")]
[assembly: AssemblyCompany("Mark Heath & Contributors")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("© Mark Heath 2020")]
[assembly: AssemblyDescription("NAudio, an audio library for .NET")]
[assembly: AssemblyFileVersion("1.10.0.0")]
[assembly: AssemblyInformationalVersion("1.10.0")]
[assembly: AssemblyProduct("NAudio")]
[assembly: AssemblyTitle("NAudio")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.10.0.0")]
[module: UnverifiableCode]
namespace NAudio
{
	public enum Manufacturers
	{
		Microsoft = 1,
		Creative = 2,
		Mediavision = 3,
		Fujitsu = 4,
		Artisoft = 20,
		TurtleBeach = 21,
		Ibm = 22,
		Vocaltec = 23,
		Roland = 24,
		DspSolutions = 25,
		Nec = 26,
		Ati = 27,
		Wanglabs = 28,
		Tandy = 29,
		Voyetra = 30,
		Antex = 31,
		IclPS = 32,
		Intel = 33,
		Gravis = 34,
		Val = 35,
		Interactive = 36,
		Yamaha = 37,
		Everex = 38,
		Echo = 39,
		Sierra = 40,
		Cat = 41,
		Apps = 42,
		DspGroup = 43,
		Melabs = 44,
		ComputerFriends = 45,
		Ess = 46,
		Audiofile = 47,
		Motorola = 48,
		Canopus = 49,
		Epson = 50,
		Truevision = 51,
		Aztech = 52,
		Videologic = 53,
		Scalacs = 54,
		Korg = 55,
		Apt = 56,
		Ics = 57,
		Iteratedsys = 58,
		Metheus = 59,
		Logitech = 60,
		Winnov = 61,
		Ncr = 62,
		Exan = 63,
		Ast = 64,
		Willowpond = 65,
		Sonicfoundry = 66,
		Vitec = 67,
		Moscom = 68,
		Siliconsoft = 69,
		Supermac = 73,
		Audiopt = 74,
		Speechcomp = 76,
		Ahead = 77,
		Dolby = 78,
		Oki = 79,
		Auravision = 80,
		Olivetti = 81,
		Iomagic = 82,
		Matsushita = 83,
		Controlres = 84,
		Xebec = 85,
		Newmedia = 86,
		Nms = 87,
		Lyrrus = 88,
		Compusic = 89,
		Opti = 90,
		Adlacc = 91,
		Compaq = 92,
		Dialogic = 93,
		Insoft = 94,
		Mptus = 95,
		Weitek = 96,
		LernoutAndHauspie = 97,
		Qciar = 98,
		Apple = 99,
		Digital = 100,
		Motu = 101,
		Workbit = 102,
		Ositech = 103,
		Miro = 104,
		Cirruslogic = 105,
		Isolution = 106,
		Horizons = 107,
		Concepts = 108,
		Vtg = 109,
		Radius = 110,
		Rockwell = 111,
		Xyz = 112,
		Opcode = 113,
		Voxware = 114,
		NorthernTelecom = 115,
		Apicom = 116,
		Grande = 117,
		Addx = 118,
		Wildcat = 119,
		Rhetorex = 120,
		Brooktree = 121,
		Ensoniq = 125,
		Fast = 126,
		Nvidia = 127,
		Oksori = 128,
		Diacoustics = 129,
		Gulbransen = 130,
		KayElemetrics = 131,
		Crystal = 132,
		SplashStudios = 133,
		Quarterdeck = 134,
		Tdk = 135,
		DigitalAudioLabs = 136,
		Seersys = 137,
		Picturetel = 138,
		AttMicroelectronics = 139,
		Osprey = 140,
		Mediatrix = 141,
		Soundesigns = 142,
		Aldigital = 143,
		SpectrumSignalProcessing = 144,
		Ecs = 145,
		Amd = 146,
		Coredynamics = 147,
		Canam = 148,
		Softsound = 149,
		Norris = 150,
		Ddd = 151,
		Euphonics = 152,
		Precept = 153,
		CrystalNet = 154,
		Chromatic = 155,
		Voiceinfo = 156,
		Viennasys = 157,
		Connectix = 158,
		Gadgetlabs = 159,
		Frontier = 160,
		Viona = 161,
		Casio = 162,
		Diamondmm = 163,
		S3 = 164,
		FraunhoferIis = 172
	}
	public class MmException : Exception
	{
		private MmResult result;

		private string function;

		public MmResult Result => result;

		public MmException(MmResult result, string function)
			: base(ErrorMessage(result, function))
		{
			this.result = result;
			this.function = function;
		}

		private static string ErrorMessage(MmResult result, string function)
		{
			return $"{result} calling {function}";
		}

		public static void Try(MmResult result, string function)
		{
			if (result != MmResult.NoError)
			{
				throw new MmException(result, function);
			}
		}
	}
	public enum MmResult
	{
		NoError = 0,
		UnspecifiedError = 1,
		BadDeviceId = 2,
		NotEnabled = 3,
		AlreadyAllocated = 4,
		InvalidHandle = 5,
		NoDriver = 6,
		MemoryAllocationError = 7,
		NotSupported = 8,
		BadErrorNumber = 9,
		InvalidFlag = 10,
		InvalidParameter = 11,
		HandleBusy = 12,
		InvalidAlias = 13,
		BadRegistryDatabase = 14,
		RegistryKeyNotFound = 15,
		RegistryReadError = 16,
		RegistryWriteError = 17,
		RegistryDeleteError = 18,
		RegistryValueNotFound = 19,
		NoDriverCallback = 20,
		MoreData = 21,
		WaveBadFormat = 32,
		WaveStillPlaying = 33,
		WaveHeaderUnprepared = 34,
		WaveSync = 35,
		AcmNotPossible = 512,
		AcmBusy = 513,
		AcmHeaderUnprepared = 514,
		AcmCancelled = 515,
		MixerInvalidLine = 1024,
		MixerInvalidControl = 1025,
		MixerInvalidValue = 1026
	}
}
namespace NAudio.Utils
{
	public static class BufferHelpers
	{
		public static byte[] Ensure(byte[] buffer, int bytesRequired)
		{
			if (buffer == null || buffer.Length < bytesRequired)
			{
				buffer = new byte[bytesRequired];
			}
			return buffer;
		}

		public static float[] Ensure(float[] buffer, int samplesRequired)
		{
			if (buffer == null || buffer.Length < samplesRequired)
			{
				buffer = new float[samplesRequired];
			}
			return buffer;
		}
	}
	public static class ByteArrayExtensions
	{
		public static bool IsEntirelyNull(byte[] buffer)
		{
			for (int i = 0; i < buffer.Length; i++)
			{
				if (buffer[i] != 0)
				{
					return false;
				}
			}
			return true;
		}

		public static string DescribeAsHex(byte[] buffer, string separator, int bytesPerLine)
		{
			StringBuilder stringBuilder = new StringBuilder();
			int num = 0;
			foreach (byte b in buffer)
			{
				stringBuilder.AppendFormat("{0:X2}{1}", b, separator);
				if (++num % bytesPerLine == 0)
				{
					stringBuilder.Append("\r\n");
				}
			}
			stringBuilder.Append("\r\n");
			return stringBuilder.ToString();
		}

		public static string DecodeAsString(byte[] buffer, int offset, int length, Encoding encoding)
		{
			for (int i = 0; i < length; i++)
			{
				if (buffer[offset + i] == 0)
				{
					length = i;
				}
			}
			return encoding.GetString(buffer, offset, length);
		}

		public static byte[] Concat(params byte[][] byteArrays)
		{
			int num = 0;
			byte[][] array = byteArrays;
			foreach (byte[] array2 in array)
			{
				num += array2.Length;
			}
			if (num <= 0)
			{
				return new byte[0];
			}
			byte[] array3 = new byte[num];
			int num2 = 0;
			array = byteArrays;
			foreach (byte[] array4 in array)
			{
				Array.Copy(array4, 0, array3, num2, array4.Length);
				num2 += array4.Length;
			}
			return array3;
		}
	}
	public class ByteEncoding : Encoding
	{
		public static readonly ByteEncoding Instance = new ByteEncoding();

		private ByteEncoding()
		{
		}

		public override int GetByteCount(char[] chars, int index, int count)
		{
			return count;
		}

		public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
		{
			for (int i = 0; i < charCount; i++)
			{
				bytes[byteIndex + i] = (byte)chars[charIndex + i];
			}
			return charCount;
		}

		public override int GetCharCount(byte[] bytes, int index, int count)
		{
			for (int i = 0; i < count; i++)
			{
				if (bytes[index + i] == 0)
				{
					return i;
				}
			}
			return count;
		}

		public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
		{
			for (int i = 0; i < byteCount; i++)
			{
				byte b = bytes[byteIndex + i];
				if (b == 0)
				{
					return i;
				}
				chars[charIndex + i] = (char)b;
			}
			return byteCount;
		}

		public override int GetMaxCharCount(int byteCount)
		{
			return byteCount;
		}

		public override int GetMaxByteCount(int charCount)
		{
			return charCount;
		}
	}
	public class ChunkIdentifier
	{
		public static int ChunkIdentifierToInt32(string s)
		{
			if (s.Length != 4)
			{
				throw new ArgumentException("Must be a four character string");
			}
			byte[] bytes = Encoding.UTF8.GetBytes(s);
			if (bytes.Length != 4)
			{
				throw new ArgumentException("Must encode to exactly four bytes");
			}
			return BitConverter.ToInt32(bytes, 0);
		}
	}
	public class CircularBuffer
	{
		private readonly byte[] buffer;

		private readonly object lockObject;

		private int writePosition;

		private int readPosition;

		private int byteCount;

		public int MaxLength => buffer.Length;

		public int Count
		{
			get
			{
				lock (lockObject)
				{
					return byteCount;
				}
			}
		}

		public CircularBuffer(int size)
		{
			buffer = new byte[size];
			lockObject = new object();
		}

		public int Write(byte[] data, int offset, int count)
		{
			lock (lockObject)
			{
				int num = 0;
				if (count > buffer.Length - byteCount)
				{
					count = buffer.Length - byteCount;
				}
				int num2 = Math.Min(buffer.Length - writePosition, count);
				Array.Copy(data, offset, buffer, writePosition, num2);
				writePosition += num2;
				writePosition %= buffer.Length;
				num += num2;
				if (num < count)
				{
					Array.Copy(data, offset + num, buffer, writePosition, count - num);
					writePosition += count - num;
					num = count;
				}
				byteCount += num;
				return num;
			}
		}

		public int Read(byte[] data, int offset, int count)
		{
			lock (lockObject)
			{
				if (count > byteCount)
				{
					count = byteCount;
				}
				int num = 0;
				int num2 = Math.Min(buffer.Length - readPosition, count);
				Array.Copy(buffer, readPosition, data, offset, num2);
				num += num2;
				readPosition += num2;
				readPosition %= buffer.Length;
				if (num < count)
				{
					Array.Copy(buffer, readPosition, data, offset + num, count - num);
					readPosition += count - num;
					num = count;
				}
				byteCount -= num;
				return num;
			}
		}

		public void Reset()
		{
			lock (lockObject)
			{
				ResetInner();
			}
		}

		private void ResetInner()
		{
			byteCount = 0;
			readPosition = 0;
			writePosition = 0;
		}

		public void Advance(int count)
		{
			lock (lockObject)
			{
				if (count >= byteCount)
				{
					ResetInner();
					return;
				}
				byteCount -= count;
				readPosition += count;
				readPosition %= MaxLength;
			}
		}
	}
	public class Decibels
	{
		private const double LOG_2_DB = 8.685889638065037;

		private const double DB_2_LOG = 0.11512925464970228;

		public static double LinearToDecibels(double lin)
		{
			return Math.Log(lin) * 8.685889638065037;
		}

		public static double DecibelsToLinear(double dB)
		{
			return Math.Exp(dB * 0.11512925464970228);
		}
	}
	[AttributeUsage(AttributeTargets.Field)]
	public class FieldDescriptionAttribute : Attribute
	{
		public string Description { get; }

		public FieldDescriptionAttribute(string description)
		{
			Description = description;
		}

		public override string ToString()
		{
			return Description;
		}
	}
	public static class FieldDescriptionHelper
	{
		public static string Describe(Type t, Guid guid)
		{
			FieldInfo[] fields = t.GetFields(BindingFlags.Static | BindingFlags.Public);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (!fieldInfo.IsPublic || !fieldInfo.IsStatic || (object)fieldInfo.FieldType != typeof(Guid) || !((Guid)fieldInfo.GetValue(null) == guid))
				{
					continue;
				}
				object[] customAttributes = fieldInfo.GetCustomAttributes(inherit: false);
				for (int j = 0; j < customAttributes.Length; j++)
				{
					if (customAttributes[j] is FieldDescriptionAttribute fieldDescriptionAttribute)
					{
						return fieldDescriptionAttribute.Description;
					}
				}
				return fieldInfo.Name;
			}
			return guid.ToString();
		}
	}
	public static class HResult
	{
		public const int S_OK = 0;

		public const int S_FALSE = 1;

		public const int E_INVALIDARG = -2147483645;

		private const int FACILITY_AAF = 18;

		private const int FACILITY_ACS = 20;

		private const int FACILITY_BACKGROUNDCOPY = 32;

		private const int FACILITY_CERT = 11;

		private const int FACILITY_COMPLUS = 17;

		private const int FACILITY_CONFIGURATION = 33;

		private const int FACILITY_CONTROL = 10;

		private const int FACILITY_DISPATCH = 2;

		private const int FACILITY_DPLAY = 21;

		private const int FACILITY_HTTP = 25;

		private const int FACILITY_INTERNET = 12;

		private const int FACILITY_ITF = 4;

		private const int FACILITY_MEDIASERVER = 13;

		private const int FACILITY_MSMQ = 14;

		private const int FACILITY_NULL = 0;

		private const int FACILITY_RPC = 1;

		private const int FACILITY_SCARD = 16;

		private const int FACILITY_SECURITY = 9;

		private const int FACILITY_SETUPAPI = 15;

		private const int FACILITY_SSPI = 9;

		private const int FACILITY_STORAGE = 3;

		private const int FACILITY_SXS = 23;

		private const int FACILITY_UMI = 22;

		private const int FACILITY_URT = 19;

		private const int FACILITY_WIN32 = 7;

		private const int FACILITY_WINDOWS = 8;

		private const int FACILITY_WINDOWS_CE = 24;

		public static int MAKE_HRESULT(int sev, int fac, int code)
		{
			return (sev << 31) | (fac << 16) | code;
		}

		public static int GetHResult(this COMException exception)
		{
			return exception.ErrorCode;
		}
	}
	public static class IEEE
	{
		private static double UnsignedToFloat(ulong u)
		{
			return (double)(long)(u - int.MaxValue - 1) + 2147483648.0;
		}

		private static double ldexp(double x, int exp)
		{
			return x * Math.Pow(2.0, exp);
		}

		private static double frexp(double x, out int exp)
		{
			exp = (int)Math.Floor(Math.Log(x) / Math.Log(2.0)) + 1;
			return 1.0 - (Math.Pow(2.0, exp) - x) / Math.Pow(2.0, exp);
		}

		private static ulong FloatToUnsigned(double f)
		{
			return (ulong)((long)(f - 2147483648.0) + int.MaxValue + 1);
		}

		public static byte[] ConvertToIeeeExtended(double num)
		{
			int num2;
			if (num < 0.0)
			{
				num2 = 32768;
				num *= -1.0;
			}
			else
			{
				num2 = 0;
			}
			ulong num4;
			ulong num5;
			int num3;
			if (num == 0.0)
			{
				num3 = 0;
				num4 = 0uL;
				num5 = 0uL;
			}
			else
			{
				double num6 = frexp(num, out num3);
				if (num3 > 16384 || !(num6 < 1.0))
				{
					num3 = num2 | 0x7FFF;
					num4 = 0uL;
					num5 = 0uL;
				}
				else
				{
					num3 += 16382;
					if (num3 < 0)
					{
						num6 = ldexp(num6, num3);
						num3 = 0;
					}
					num3 |= num2;
					num6 = ldexp(num6, 32);
					double num7 = Math.Floor(num6);
					num4 = FloatToUnsigned(num7);
					num6 = ldexp(num6 - num7, 32);
					num7 = Math.Floor(num6);
					num5 = FloatToUnsigned(num7);
				}
			}
			return new byte[10]
			{
				(byte)(num3 >> 8),
				(byte)num3,
				(byte)(num4 >> 24),
				(byte)(num4 >> 16),
				(byte)(num4 >> 8),
				(byte)num4,
				(byte)(num5 >> 24),
				(byte)(num5 >> 16),
				(byte)(num5 >> 8),
				(byte)num5
			};
		}

		public static double ConvertFromIeeeExtended(byte[] bytes)
		{
			if (bytes.Length != 10)
			{
				throw new Exception("Incorrect length for IEEE extended.");
			}
			int num = ((bytes[0] & 0x7F) << 8) | bytes[1];
			uint num2 = (uint)((bytes[2] << 24) | (bytes[3] << 16) | (bytes[4] << 8) | bytes[5]);
			uint num3 = (uint)((bytes[6] << 24) | (bytes[7] << 16) | (bytes[8] << 8) | bytes[9]);
			double num4;
			if (num == 0 && num2 == 0 && num3 == 0)
			{
				num4 = 0.0;
			}
			else if (num == 32767)
			{
				num4 = double.NaN;
			}
			else
			{
				num -= 16383;
				num4 = ldexp(UnsignedToFloat(num2), num -= 31);
				num4 += ldexp(UnsignedToFloat(num3), num -= 32);
			}
			if ((bytes[0] & 0x80) == 128)
			{
				return 0.0 - num4;
			}
			return num4;
		}
	}
	public class IgnoreDisposeStream : Stream
	{
		public Stream SourceStream { get; private set; }

		public bool IgnoreDispose { get; set; }

		public override bool CanRead => SourceStream.CanRead;

		public override bool CanSeek => SourceStream.CanSeek;

		public override bool CanWrite => SourceStream.CanWrite;

		public override long Length => SourceStream.Length;

		public override long Position
		{
			get
			{
				return SourceStream.Position;
			}
			set
			{
				SourceStream.Position = value;
			}
		}

		public IgnoreDisposeStream(Stream sourceStream)
		{
			SourceStream = sourceStream;
			IgnoreDispose = true;
		}

		public override void Flush()
		{
			SourceStream.Flush();
		}

		public override int Read(byte[] buffer, int offset, int count)
		{
			return SourceStream.Read(buffer, offset, count);
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			return SourceStream.Seek(offset, origin);
		}

		public override void SetLength(long value)
		{
			SourceStream.SetLength(value);
		}

		public override void Write(byte[] buffer, int offset, int count)
		{
			SourceStream.Write(buffer, offset, count);
		}

		protected override void Dispose(bool disposing)
		{
			if (!IgnoreDispose)
			{
				SourceStream.Dispose();
				SourceStream = null;
			}
		}
	}
	public static class MarshalHelpers
	{
		public static int SizeOf<T>()
		{
			return Marshal.SizeOf(typeof(T));
		}

		public static IntPtr OffsetOf<T>(string fieldName)
		{
			return Marshal.OffsetOf(typeof(T), fieldName);
		}

		public static T PtrToStructure<T>(IntPtr pointer)
		{
			return (T)Marshal.PtrToStructure(pointer, typeof(T));
		}
	}
	internal class MergeSort
	{
		private static void Sort<T>(IList<T> list, int lowIndex, int highIndex, IComparer<T> comparer)
		{
			if (lowIndex >= highIndex)
			{
				return;
			}
			int num = (lowIndex + highIndex) / 2;
			Sort(list, lowIndex, num, comparer);
			Sort(list, num + 1, highIndex, comparer);
			int num2 = num;
			int num3 = num + 1;
			while (lowIndex <= num2 && num3 <= highIndex)
			{
				if (comparer.Compare(list[lowIndex], list[num3]) <= 0)
				{
					lowIndex++;
					continue;
				}
				T value = list[num3];
				for (int num4 = num3 - 1; num4 >= lowIndex; num4--)
				{
					list[num4 + 1] = list[num4];
				}
				list[lowIndex] = value;
				lowIndex++;
				num2++;
				num3++;
			}
		}

		public static void Sort<T>(IList<T> list) where T : IComparable<T>
		{
			Sort(list, 0, list.Count - 1, Comparer<T>.Default);
		}

		public static void Sort<T>(IList<T> list, IComparer<T> comparer)
		{
			Sort(list, 0, list.Count - 1, comparer);
		}
	}
	internal class NativeMethods
	{
		[DllImport("kernel32.dll")]
		public static extern IntPtr LoadLibrary(string dllToLoad);

		[DllImport("kernel32.dll")]
		public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);

		[DllImport("kernel32.dll")]
		public static extern bool FreeLibrary(IntPtr hModule);
	}
	public class ProgressLog : UserControl
	{
		private delegate void LogMessageDelegate(Color color, string message);

		private delegate void ClearLogDelegate();

		private IContainer components;

		private RichTextBox richTextBoxLog;

		public string Text => ((Control)richTextBoxLog).Text;

		public ProgressLog()
		{
			InitializeComponent();
		}

		public void LogMessage(Color color, string message)
		{
			if (((Control)richTextBoxLog).InvokeRequired)
			{
				((Control)this).Invoke((Delegate)new LogMessageDelegate(LogMessage), new object[2] { color, message });
			}
			else
			{
				((TextBoxBase)richTextBoxLog).SelectionStart = ((TextBoxBase)richTextBoxLog).TextLength;
				richTextBoxLog.SelectionColor = color;
				((TextBoxBase)richTextBoxLog).AppendText(message);
				((TextBoxBase)richTextBoxLog).AppendText(Environment.NewLine);
			}
		}

		public void ClearLog()
		{
			if (((Control)richTextBoxLog).InvokeRequired)
			{
				((Control)this).Invoke((Delegate)new ClearLogDelegate(ClearLog), new object[0]);
			}
			else
			{
				((TextBoxBase)richTextBoxLog).Clear();
			}
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			((ContainerControl)this).Dispose(disposing);
		}

		private void InitializeComponent()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			richTextBoxLog = new RichTextBox();
			((Control)this).SuspendLayout();
			((TextBoxBase)richTextBoxLog).BorderStyle = (BorderStyle)0;
			((Control)richTextBoxLog).Dock = (DockStyle)5;
			((Control)richTextBoxLog).Location = new Point(1, 1);
			((Control)richTextBoxLog).Name = "richTextBoxLog";
			((TextBoxBase)richTextBoxLog).ReadOnly = true;
			((Control)richTextBoxLog).Size = new Size(311, 129);
			((Control)richTextBoxLog).TabIndex = 0;
			((Control)richTextBoxLog).Text = "";
			((ContainerControl)this).AutoScaleDimensions = new SizeF(6f, 13f);
			((ContainerControl)this).AutoScaleMode = (AutoScaleMode)1;
			((Control)this).BackColor = SystemColors.ControlDarkDark;
			((Control)this).Controls.Add((Control)(object)richTextBoxLog);
			((Control)this).Name = "ProgressLog";
			((Control)this).Padding = new Padding(1);
			((Control)this).Size = new Size(313, 131);
			((Control)this).ResumeLayout(false);
		}
	}
	public static class WavePositionExtensions
	{
		public static TimeSpan GetPositionTimeSpan(this IWavePosition @this)
		{
			return TimeSpan.FromMilliseconds((double)(@this.GetPosition() / (@this.OutputWaveFormat.Channels * @this.OutputWaveFormat.BitsPerSample / 8)) * 1000.0 / (double)@this.OutputWaveFormat.SampleRate);
		}
	}
}
namespace NAudio.Mixer
{
	public class BooleanMixerControl : MixerControl
	{
		private MixerInterop.MIXERCONTROLDETAILS_BOOLEAN boolDetails;

		public bool Value
		{
			get
			{
				GetControlDetails();
				return boolDetails.fValue == 1;
			}
			set
			{
				boolDetails.fValue = (value ? 1 : 0);
				mixerControlDetails.paDetails = Marshal.AllocHGlobal(Marshal.SizeOf((object)boolDetails));
				Marshal.StructureToPtr((object)boolDetails, mixerControlDetails.paDetails, fDeleteOld: false);
				MmException.Try(MixerInterop.mixerSetControlDetails(mixerHandle, ref mixerControlDetails, MixerFlags.Mixer | mixerHandleType), "mixerSetControlDetails");
				Marshal.FreeHGlobal(mixerControlDetails.paDetails);
			}
		}

		internal BooleanMixerControl(MixerInterop.MIXERCONTROL mixerControl, IntPtr mixerHandle, MixerFlags mixerHandleType, int nChannels)
		{
			base.mixerControl = mixerControl;
			base.mixerHandle = mixerHandle;
			base.mixerHandleType = mixerHandleType;
			base.nChannels = nChannels;
			mixerControlDetails = default(MixerInterop.MIXERCONTROLDETAILS);
			GetControlDetails();
		}

		protected override void GetDetails(IntPtr pDetails)
		{
			boolDetails = MarshalHelpers.PtrToStructure<MixerInterop.MIXERCONTROLDETAILS_BOOLEAN>(pDetails);
		}
	}
	public class CustomMixerControl : MixerControl
	{
		internal CustomMixerControl(MixerInterop.MIXERCONTROL mixerControl, IntPtr mixerHandle, MixerFlags mixerHandleType, int nChannels)
		{
			base.mixerControl = mixerControl;
			base.mixerHandle = mixerHandle;
			base.mixerHandleType = mixerHandleType;
			base.nChannels = nChannels;
			mixerControlDetails = default(MixerInterop.MIXERCONTROLDETAILS);
			GetControlDetails();
		}

		protected override void GetDetails(IntPtr pDetails)
		{
		}
	}
	public class ListTextMixerControl : MixerControl
	{
		internal ListTextMixerControl(MixerInterop.MIXERCONTROL mixerControl, IntPtr mixerHandle, MixerFlags mixerHandleType, int nChannels)
		{
			base.mixerControl = mixerControl;
			base.mixerHandle = mixerHandle;
			base.mixerHandleType = mixerHandleType;
			base.nChannels = nChannels;
			mixerControlDetails = default(MixerInterop.MIXERCONTROLDETAILS);
			GetControlDetails();
		}

		protected override void GetDetails(IntPtr pDetails)
		{
		}
	}
	public class Mixer
	{
		private MixerInterop.MIXERCAPS caps;

		private IntPtr mixerHandle;

		private MixerFlags mixerHandleType;

		public static int NumberOfDevices => MixerInterop.mixerGetNumDevs();

		public int DestinationCount => (int)caps.cDestinations;

		public string Name => caps.szPname;

		public Manufacturers Manufacturer => (Manufacturers)caps.wMid;

		public int ProductID => caps.wPid;

		public IEnumerable<MixerLine> Destinations
		{
			get
			{
				for (int destination = 0; destination < DestinationCount; destination++)
				{
					yield return GetDestination(destination);
				}
			}
		}

		public static IEnumerable<Mixer> Mixers
		{
			get
			{
				for (int device = 0; device < NumberOfDevices; device++)
				{
					yield return new Mixer(device);
				}
			}
		}

		public Mixer(int mixerIndex)
		{
			if (mixerIndex < 0 || mixerIndex >= NumberOfDevices)
			{
				throw new ArgumentOutOfRangeException("mixerID");
			}
			caps = default(MixerInterop.MIXERCAPS);
			MmException.Try(MixerInterop.mixerGetDevCaps((IntPtr)mixerIndex, ref caps, Marshal.SizeOf((object)caps)), "mixerGetDevCaps");
			mixerHandle = (IntPtr)mixerIndex;
			mixerHandleType = MixerFlags.Mixer;
		}

		public MixerLine GetDestination(int destinationIndex)
		{
			if (destinationIndex < 0 || destinationIndex >= DestinationCount)
			{
				throw new ArgumentOutOfRangeException("destinationIndex");
			}
			return new MixerLine(mixerHandle, destinationIndex, mixerHandleType);
		}
	}
	public abstract class MixerControl
	{
		internal MixerInterop.MIXERCONTROL mixerControl;

		internal MixerInterop.MIXERCONTROLDETAILS mixerControlDetails;

		protected IntPtr mixerHandle;

		protected int nChannels;

		protected MixerFlags mixerHandleType;

		public string Name => mixerControl.szName;

		public MixerControlType ControlType => mixerControl.dwControlType;

		public bool IsBoolean => IsControlBoolean(mixerControl.dwControlType);

		public bool IsListText => IsControlListText(mixerControl.dwControlType);

		public bool IsSigned => IsControlSigned(mixerControl.dwControlType);

		public bool IsUnsigned => IsControlUnsigned(mixerControl.dwControlType);

		public bool IsCustom => IsControlCustom(mixerControl.dwControlType);

		public static IList<MixerControl> GetMixerControls(IntPtr mixerHandle, MixerLine mixerLine, MixerFlags mixerHandleType)
		{
			List<MixerControl> list = new List<MixerControl>();
			if (mixerLine.ControlsCount > 0)
			{
				int num = MarshalHelpers.SizeOf<MixerInterop.MIXERCONTROL>();
				MixerInterop.MIXERLINECONTROLS mixerLineControls = default(MixerInterop.MIXERLINECONTROLS);
				IntPtr intPtr = Marshal.AllocHGlobal(num * mixerLine.ControlsCount);
				mixerLineControls.cbStruct = Marshal.SizeOf((object)mixerLineControls);
				mixerLineControls.dwLineID = mixerLine.LineId;
				mixerLineControls.cControls = mixerLine.ControlsCount;
				mixerLineControls.pamxctrl = intPtr;
				mixerLineControls.cbmxctrl = MarshalHelpers.SizeOf<MixerInterop.MIXERCONTROL>();
				try
				{
					MmResult mmResult = MixerInterop.mixerGetLineControls(mixerHandle, ref mixerLineControls, MixerFlags.Mixer | mixerHandleType);
					if (mmResult != MmResult.NoError)
					{
						throw new MmException(mmResult, "mixerGetLineControls");
					}
					for (int i = 0; i < mixerLineControls.cControls; i++)
					{
						MixerInterop.MIXERCONTROL mIXERCONTROL = MarshalHelpers.PtrToStructure<MixerInterop.MIXERCONTROL>((IntPtr)(intPtr.ToInt64() + num * i));
						MixerControl item = GetMixerControl(mixerHandle, mixerLine.LineId, mIXERCONTROL.dwControlID, mixerLine.Channels, mixerHandleType);
						list.Add(item);
					}
				}
				finally
				{
					Marshal.FreeHGlobal(intPtr);
				}
			}
			return list;
		}

		public static MixerControl GetMixerControl(IntPtr mixerHandle, int nLineId, int controlId, int nChannels, MixerFlags mixerFlags)
		{
			MixerInterop.MIXERLINECONTROLS mixerLineControls = default(MixerInterop.MIXERLINECONTROLS);
			MixerInterop.MIXERCONTROL mIXERCONTROL = default(MixerInterop.MIXERCONTROL);
			IntPtr intPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf((object)mIXERCONTROL));
			mixerLineControls.cbStruct = Marshal.SizeOf((object)mixerLineControls);
			mixerLineControls.cControls = 1;
			mixerLineControls.dwControlID = controlId;
			mixerLineControls.cbmxctrl = Marshal.SizeOf((object)mIXERCONTROL);
			mixerLineControls.pamxctrl = intPtr;
			mixerLineControls.dwLineID = nLineId;
			MmResult mmResult = MixerInterop.mixerGetLineControls(mixerHandle, ref mixerLineControls, MixerFlags.ListText | mixerFlags);
			if (mmResult != MmResult.NoError)
			{
				Marshal.FreeCoTaskMem(intPtr);
				throw new MmException(mmResult, "mixerGetLineControls");
			}
			mIXERCONTROL = MarshalHelpers.PtrToStructure<MixerInterop.MIXERCONTROL>(mixerLineControls.pamxctrl);
			Marshal.FreeCoTaskMem(intPtr);
			if (IsControlBoolean(mIXERCONTROL.dwControlType))
			{
				return new BooleanMixerControl(mIXERCONTROL, mixerHandle, mixerFlags, nChannels);
			}
			if (IsControlSigned(mIXERCONTROL.dwControlType))
			{
				return new SignedMixerControl(mIXERCONTROL, mixerHandle, mixerFlags, nChannels);
			}
			if (IsControlUnsigned(mIXERCONTROL.dwControlType))
			{
				return new UnsignedMixerControl(mIXERCONTROL, mixerHandle, mixerFlags, nChannels);
			}
			if (IsControlListText(mIXERCONTROL.dwControlType))
			{
				return new ListTextMixerControl(mIXERCONTROL, mixerHandle, mixerFlags, nChannels);
			}
			if (IsControlCustom(mIXERCONTROL.dwControlType))
			{
				return new CustomMixerControl(mIXERCONTROL, mixerHandle, mixerFlags, nChannels);
			}
			throw new InvalidOperationException($"Unknown mixer control type {mIXERCONTROL.dwControlType}");
		}

		protected void GetControlDetails()
		{
			mixerControlDetails.cbStruct = Marshal.SizeOf((object)mixerControlDetails);
			mixerControlDetails.dwControlID = mixerControl.dwControlID;
			if (IsCustom)
			{
				mixerControlDetails.cChannels = 0;
			}
			else if ((mixerControl.fdwControl & 1) != 0)
			{
				mixerControlDetails.cChannels = 1;
			}
			else
			{
				mixerControlDetails.cChannels = nChannels;
			}
			if ((mixerControl.fdwControl & 2) != 0)
			{
				mixerControlDetails.hwndOwner = (IntPtr)mixerControl.cMultipleItems;
			}
			else if (IsCustom)
			{
				mixerControlDetails.hwndOwner = IntPtr.Zero;
			}
			else
			{
				mixerControlDetails.hwndOwner = IntPtr.Zero;
			}
			if (IsBoolean)
			{
				mixerControlDetails.cbDetails = MarshalHelpers.SizeOf<MixerInterop.MIXERCONTROLDETAILS_BOOLEAN>();
			}
			else if (IsListText)
			{
				mixerControlDetails.cbDetails = MarshalHelpers.SizeOf<MixerInterop.MIXERCONTROLDETAILS_LISTTEXT>();
			}
			else if (IsSigned)
			{
				mixerControlDetails.cbDetails = MarshalHelpers.SizeOf<MixerInterop.MIXERCONTROLDETAILS_SIGNED>();
			}
			else if (IsUnsigned)
			{
				mixerControlDetails.cbDetails = MarshalHelpers.SizeOf<MixerInterop.MIXERCONTROLDETAILS_UNSIGNED>();
			}
			else
			{
				mixerControlDetails.cbDetails = mixerControl.Metrics.customData;
			}
			int num = mixerControlDetails.cbDetails * mixerControlDetails.cChannels;
			if ((mixerControl.fdwControl & 2) != 0)
			{
				num *= (int)mixerControl.cMultipleItems;
			}
			IntPtr intPtr = Marshal.AllocCoTaskMem(num);
			mixerControlDetails.paDetails = intPtr;
			MmResult mmResult = MixerInterop.mixerGetControlDetails(mixerHandle, ref mixerControlDetails, MixerFlags.Mixer | mixerHandleType);
			if (mmResult == MmResult.NoError)
			{
				GetDetails(mixerControlDetails.paDetails);
			}
			Marshal.FreeCoTaskMem(intPtr);
			if (mmResult != MmResult.NoError)
			{
				throw new MmException(mmResult, "mixerGetControlDetails");
			}
		}

		protected abstract void GetDetails(IntPtr pDetails);

		private static bool IsControlBoolean(MixerControlType controlType)
		{
			switch (controlType)
			{
			case MixerControlType.BooleanMeter:
			case MixerControlType.Boolean:
			case MixerControlType.OnOff:
			case MixerControlType.Mute:
			case MixerControlType.Mono:
			case MixerControlType.Loudness:
			case MixerControlType.StereoEnhance:
			case MixerControlType.Button:
			case MixerControlType.SingleSelect:
			case MixerControlType.Mux:
			case MixerControlType.MultipleSelect:
			case MixerControlType.Mixer:
				return true;
			default:
				return false;
			}
		}

		private static bool IsControlListText(MixerControlType controlType)
		{
			if (controlType == MixerControlType.Equalizer || (uint)(controlType - 1879113728) <= 1u || (uint)(controlType - 1895890944) <= 1u)
			{
				return true;
			}
			return false;
		}

		private static bool IsControlSigned(MixerControlType controlType)
		{
			switch (controlType)
			{
			case MixerControlType.SignedMeter:
			case MixerControlType.PeakMeter:
			case MixerControlType.Signed:
			case MixerControlType.Decibels:
			case MixerControlType.Slider:
			case MixerControlType.Pan:
			case MixerControlType.QSoundPan:
				return true;
			default:
				return false;
			}
		}

		private static bool IsControlUnsigned(MixerControlType controlType)
		{
			switch (controlType)
			{
			case MixerControlType.UnsignedMeter:
			case MixerControlType.Unsigned:
			case MixerControlType.Percent:
			case MixerControlType.Fader:
			case MixerControlType.Volume:
			case MixerControlType.Bass:
			case MixerControlType.Treble:
			case MixerControlType.Equalizer:
			case MixerControlType.MicroTime:
			case MixerControlType.MilliTime:
				return true;
			default:
				return false;
			}
		}

		private static bool IsControlCustom(MixerControlType controlType)
		{
			return controlType == MixerControlType.Custom;
		}

		public override string ToString()
		{
			return $"{Name} {ControlType}";
		}
	}
	[Flags]
	internal enum MixerControlClass
	{
		Custom = 0,
		Meter = 0x10000000,
		Switch = 0x20000000,
		Number = 0x30000000,
		Slider = 0x40000000,
		Fader = 0x50000000,
		Time = 0x60000000,
		List = 0x70000000,
		Mask = 0x70000000
	}
	[Flags]
	internal enum MixerControlSubclass
	{
		SwitchBoolean = 0,
		SwitchButton = 0x1000000,
		MeterPolled = 0,
		TimeMicrosecs = 0,
		TimeMillisecs = 0x1000000,
		ListSingle = 0,
		ListMultiple = 0x1000000,
		Mask = 0xF000000
	}
	[Flags]
	internal enum MixerControlUnits
	{
		Custom = 0,
		Boolean = 0x10000,
		Signed = 0x20000,
		Unsigned = 0x30000,
		Decibels = 0x40000,
		Percent = 0x50000,
		Mask = 0xFF0000
	}
	public enum MixerControlType
	{
		Custom = 0,
		BooleanMeter = 268500992,
		SignedMeter = 268566528,
		PeakMeter = 268566529,
		UnsignedMeter = 268632064,
		Boolean = 536936448,
		OnOff = 536936449,
		Mute = 536936450,
		Mono = 536936451,
		Loudness = 536936452,
		StereoEnhance = 536936453,
		Button = 553713664,
		Decibels = 805568512,
		Signed = 805437440,
		Unsigned = 805502976,
		Percent = 805634048,
		Slider = 1073872896,
		Pan = 1073872897,
		QSoundPan = 1073872898,
		Fader = 1342373888,
		Volume = 1342373889,
		Bass = 1342373890,
		Treble = 1342373891,
		Equalizer = 1342373892,
		SingleSelect = 1879113728,
		Mux = 1879113729,
		MultipleSelect = 1895890944,
		Mixer = 1895890945,
		MicroTime = 1610809344,
		MilliTime = 1627586560
	}
	[Flags]
	public enum MixerFlags
	{
		Handle = int.MinValue,
		Mixer = 0,
		MixerHandle = int.MinValue,
		WaveOut = 0x10000000,
		WaveOutHandle = -1879048192,
		WaveIn = 0x20000000,
		WaveInHandle = -1610612736,
		MidiOut = 0x30000000,
		MidiOutHandle = -1342177280,
		MidiIn = 0x40000000,
		MidiInHandle = -1073741824,
		Aux = 0x50000000,
		Value = 0,
		ListText = 1,
		QueryMask = 0xF,
		All = 0,
		OneById = 1,
		OneByType = 2,
		GetLineInfoOfDestination = 0,
		GetLineInfoOfSource = 1,
		GetLineInfoOfLineId = 2,
		GetLineInfoOfComponentType = 3,
		GetLineInfoOfTargetType = 4,
		GetLineInfoOfQueryMask = 0xF
	}
	internal class MixerInterop
	{
		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
		public struct MIXERCONTROLDETAILS
		{
			public int cbStruct;

			public int dwControlID;

			public int cChannels;

			public IntPtr hwndOwner;

			public int cbDetails;

			public IntPtr paDetails;
		}

		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct MIXERCAPS
		{
			public ushort wMid;

			public ushort wPid;

			public uint vDriverVersion;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
			public string szPname;

			public uint fdwSupport;

			public uint cDestinations;
		}

		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct MIXERLINECONTROLS
		{
			public int cbStruct;

			public int dwLineID;

			public int dwControlID;

			public int cControls;

			public int cbmxctrl;

			public IntPtr pamxctrl;
		}

		[Flags]
		public enum MIXERLINE_LINEF
		{
			MIXERLINE_LINEF_ACTIVE = 1,
			MIXERLINE_LINEF_DISCONNECTED = 0x8000,
			MIXERLINE_LINEF_SOURCE = int.MinValue
		}

		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct MIXERLINE
		{
			public int cbStruct;

			public int dwDestination;

			public int dwSource;

			public int dwLineID;

			public MIXERLINE_LINEF fdwLine;

			public IntPtr dwUser;

			public MixerLineComponentType dwComponentType;

			public int cChannels;

			public int cConnections;

			public int cControls;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
			public string szShortName;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
			public string szName;

			public uint dwType;

			public uint dwDeviceID;

			public ushort wMid;

			public ushort wPid;

			public uint vDriverVersion;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
			public string szPname;
		}

		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct Bounds
		{
			public int minimum;

			public int maximum;

			public int reserved2;

			public int reserved3;

			public int reserved4;

			public int reserved5;
		}

		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct Metrics
		{
			public int step;

			public int customData;

			public int reserved2;

			public int reserved3;

			public int reserved4;

			public int reserved5;
		}

		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct MIXERCONTROL
		{
			public uint cbStruct;

			public int dwControlID;

			public MixerControlType dwControlType;

			public uint fdwControl;

			public uint cMultipleItems;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
			public string szShortName;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
			public string szName;

			public Bounds Bounds;

			public Metrics Metrics;
		}

		public struct MIXERCONTROLDETAILS_BOOLEAN
		{
			public int fValue;
		}

		public struct MIXERCONTROLDETAILS_SIGNED
		{
			public int lValue;
		}

		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct MIXERCONTROLDETAILS_LISTTEXT
		{
			public uint dwParam1;

			public uint dwParam2;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
			public string szName;
		}

		public struct MIXERCONTROLDETAILS_UNSIGNED
		{
			public uint dwValue;
		}

		public const uint MIXERCONTROL_CONTROLF_UNIFORM = 1u;

		public const uint MIXERCONTROL_CONTROLF_MULTIPLE = 2u;

		public const uint MIXERCONTROL_CONTROLF_DISABLED = 2147483648u;

		public const int MAXPNAMELEN = 32;

		public const int MIXER_SHORT_NAME_CHARS = 16;

		public const int MIXER_LONG_NAME_CHARS = 64;

		[DllImport("winmm.dll", CharSet = CharSet.Ansi)]
		public static extern int mixerGetNumDevs();

		[DllImport("winmm.dll", CharSet = CharSet.Ansi)]
		public static extern MmResult mixerOpen(out IntPtr hMixer, int uMxId, IntPtr dwCallback, IntPtr dwInstance, MixerFlags dwOpenFlags);

		[DllImport("winmm.dll", CharSet = CharSet.Ansi)]
		public static extern MmResult mixerClose(IntPtr hMixer);

		[DllImport("winmm.dll", CharSet = CharSet.Ansi)]
		public static extern MmResult mixerGetControlDetails(IntPtr hMixer, ref MIXERCONTROLDETAILS mixerControlDetails, MixerFlags dwDetailsFlags);

		[DllImport("winmm.dll", CharSet = CharSet.Ansi)]
		public static extern MmResult mixerGetDevCaps(IntPtr nMixerID, ref MIXERCAPS mixerCaps, int mixerCapsSize);

		[DllImport("winmm.dll", CharSet = CharSet.Ansi)]
		public static extern MmResult mixerGetID(IntPtr hMixer, out int mixerID, MixerFlags dwMixerIDFlags);

		[DllImport("winmm.dll", CharSet = CharSet.Ansi)]
		public static extern MmResult mixerGetLineControls(IntPtr hMixer, ref MIXERLINECONTROLS mixerLineControls, MixerFlags dwControlFlags);

		[DllImport("winmm.dll", CharSet = CharSet.Ansi)]
		public static extern MmResult mixerGetLineInfo(IntPtr hMixer, ref MIXERLINE mixerLine, MixerFlags dwInfoFlags);

		[DllImport("winmm.dll", CharSet = CharSet.Ansi)]
		public static extern MmResult mixerMessage(IntPtr hMixer, uint nMessage, IntPtr dwParam1, IntPtr dwParam2);

		[DllImport("winmm.dll", CharSet = CharSet.Ansi)]
		public static extern MmResult mixerSetControlDetails(IntPtr hMixer, ref MIXERCONTROLDETAILS mixerControlDetails, MixerFlags dwDetailsFlags);
	}
	public class MixerLine
	{
		private MixerInterop.MIXERLINE mixerLine;

		private IntPtr mixerHandle;

		private MixerFlags mixerHandleType;

		public string Name => mixerLine.szName;

		public string ShortName => mixerLine.szShortName;

		public int LineId => mixerLine.dwLineID;

		public MixerLineComponentType ComponentType => mixerLine.dwComponentType;

		public string TypeDescription => mixerLine.dwComponentType switch
		{
			MixerLineComponentType.DestinationUndefined => "Undefined Destination", 
			MixerLineComponentType.DestinationDigital => "Digital Destination", 
			MixerLineComponentType.DestinationLine => "Line Level Destination", 
			MixerLineComponentType.DestinationMonitor => "Monitor Destination", 
			MixerLineComponentType.DestinationSpeakers => "Speakers Destination", 
			MixerLineComponentType.DestinationHeadphones => "Headphones Destination", 
			MixerLineComponentType.DestinationTelephone => "Telephone Destination", 
			MixerLineComponentType.DestinationWaveIn => "Wave Input Destination", 
			MixerLineComponentType.DestinationVoiceIn => "Voice Recognition Destination", 
			MixerLineComponentType.SourceUndefined => "Undefined Source", 
			MixerLineComponentType.SourceDigital => "Digital Source", 
			MixerLineComponentType.SourceLine => "Line Level Source", 
			MixerLineComponentType.SourceMicrophone => "Microphone Source", 
			MixerLineComponentType.SourceSynthesizer => "Synthesizer Source", 
			MixerLineComponentType.SourceCompactDisc => "Compact Disk Source", 
			MixerLineComponentType.SourceTelephone => "Telephone Source", 
			MixerLineComponentType.SourcePcSpeaker => "PC Speaker Source", 
			MixerLineComponentType.SourceWaveOut => "Wave Out Source", 
			MixerLineComponentType.SourceAuxiliary => "Auxiliary Source", 
			MixerLineComponentType.SourceAnalog => "Analog Source", 
			_ => "Invalid Component Type", 
		};

		public int Channels => mixerLine.cChannels;

		public int SourceCount => mixerLine.cConnections;

		public int ControlsCount => mixerLine.cControls;

		public bool IsActive => (mixerLine.fdwLine & MixerInterop.MIXERLINE_LINEF.MIXERLINE_LINEF_ACTIVE) != 0;

		public bool IsDisconnected => (mixerLine.fdwLine & MixerInterop.MIXERLINE_LINEF.MIXERLINE_LINEF_DISCONNECTED) != 0;

		public bool IsSource => (mixerLine.fdwLine & MixerInterop.MIXERLINE_LINEF.MIXERLINE_LINEF_SOURCE) != 0;

		public IEnumerable<MixerControl> Controls => MixerControl.GetMixerControls(mixerHandle, this, mixerHandleType);

		public IEnumerable<MixerLine> Sources
		{
			get
			{
				for (int source = 0; source < SourceCount; source++)
				{
					yield return GetSource(source);
				}
			}
		}

		public string TargetName => mixerLine.szPname;

		public MixerLine(IntPtr mixerHandle, int destinationIndex, MixerFlags mixerHandleType)
		{
			this.mixerHandle = mixerHandle;
			this.mixerHandleType = mixerHandleType;
			mixerLine = default(MixerInterop.MIXERLINE);
			mixerLine.cbStruct = Marshal.SizeOf((object)mixerLine);
			mixerLine.dwDestination = destinationIndex;
			MmException.Try(MixerInterop.mixerGetLineInfo(mixerHandle, ref mixerLine, mixerHandleType | MixerFlags.Mixer), "mixerGetLineInfo");
		}

		public MixerLine(IntPtr mixerHandle, int destinationIndex, int sourceIndex, MixerFlags mixerHandleType)
		{
			this.mixerHandle = mixerHandle;
			this.mixerHandleType = mixerHandleType;
			mixerLine = default(MixerInterop.MIXERLINE);
			mixerLine.cbStruct = Marshal.SizeOf((object)mixerLine);
			mixerLine.dwDestination = destinationIndex;
			mixerLine.dwSource = sourceIndex;
			MmException.Try(MixerInterop.mixerGetLineInfo(mixerHandle, ref mixerLine, mixerHandleType | MixerFlags.ListText), "mixerGetLineInfo");
		}

		public static int GetMixerIdForWaveIn(int waveInDevice)
		{
			int mixerID = -1;
			MmException.Try(MixerInterop.mixerGetID((IntPtr)waveInDevice, out mixerID, MixerFlags.WaveIn), "mixerGetID");
			return mixerID;
		}

		public MixerLine GetSource(int sourceIndex)
		{
			if (sourceIndex < 0 || sourceIndex >= SourceCount)
			{
				throw new ArgumentOutOfRangeException("sourceIndex");
			}
			return new MixerLine(mixerHandle, mixerLine.dwDestination, sourceIndex, mixerHandleType);
		}

		public override string ToString()
		{
			return $"{Name} {TypeDescription} ({ControlsCount} controls, ID={mixerLine.dwLineID})";
		}
	}
	public enum MixerLineComponentType
	{
		DestinationUndefined = 0,
		DestinationDigital = 1,
		DestinationLine = 2,
		DestinationMonitor = 3,
		DestinationSpeakers = 4,
		DestinationHeadphones = 5,
		DestinationTelephone = 6,
		DestinationWaveIn = 7,
		DestinationVoiceIn = 8,
		SourceUndefined = 4096,
		SourceDigital = 4097,
		SourceLine = 4098,
		SourceMicrophone = 4099,
		SourceSynthesizer = 4100,
		SourceCompactDisc = 4101,
		SourceTelephone = 4102,
		SourcePcSpeaker = 4103,
		SourceWaveOut = 4104,
		SourceAuxiliary = 4105,
		SourceAnalog = 4106
	}
	public class SignedMixerControl : MixerControl
	{
		private MixerInterop.MIXERCONTROLDETAILS_SIGNED signedDetails;

		public int Value
		{
			get
			{
				GetControlDetails();
				return signedDetails.lValue;
			}
			set
			{
				signedDetails.lValue = value;
				mixerControlDetails.paDetails = Marshal.AllocHGlobal(Marshal.SizeOf((object)signedDetails));
				Marshal.StructureToPtr((object)signedDetails, mixerControlDetails.paDetails, fDeleteOld: false);
				MmException.Try(MixerInterop.mixerSetControlDetails(mixerHandle, ref mixerControlDetails, MixerFlags.Mixer | mixerHandleType), "mixerSetControlDetails");
				Marshal.FreeHGlobal(mixerControlDetails.paDetails);
			}
		}

		public int MinValue => mixerControl.Bounds.minimum;

		public int MaxValue => mixerControl.Bounds.maximum;

		public double Percent
		{
			get
			{
				return 100.0 * (double)(Value - MinValue) / (double)(MaxValue - MinValue);
			}
			set
			{
				Value = (int)((double)MinValue + value / 100.0 * (double)(MaxValue - MinValue));
			}
		}

		internal SignedMixerControl(MixerInterop.MIXERCONTROL mixerControl, IntPtr mixerHandle, MixerFlags mixerHandleType, int nChannels)
		{
			base.mixerControl = mixerControl;
			base.mixerHandle = mixerHandle;
			base.mixerHandleType = mixerHandleType;
			base.nChannels = nChannels;
			mixerControlDetails = default(MixerInterop.MIXERCONTROLDETAILS);
			GetControlDetails();
		}

		protected override void GetDetails(IntPtr pDetails)
		{
			signedDetails = MarshalHelpers.PtrToStructure<MixerInterop.MIXERCONTROLDETAILS_SIGNED>(mixerControlDetails.paDetails);
		}

		public override string ToString()
		{
			return $"{base.ToString()} {Percent}%";
		}
	}
	public class UnsignedMixerControl : MixerControl
	{
		private MixerInterop.MIXERCONTROLDETAILS_UNSIGNED[] unsignedDetails;

		public uint Value
		{
			get
			{
				GetControlDetails();
				return unsignedDetails[0].dwValue;
			}
			set
			{
				int num = Marshal.SizeOf((object)unsignedDetails[0]);
				mixerControlDetails.paDetails = Marshal.AllocHGlobal(num * nChannels);
				for (int i = 0; i < nChannels; i++)
				{
					unsignedDetails[i].dwValue = value;
					long num2 = mixerControlDetails.paDetails.ToInt64() + num * i;
					Marshal.StructureToPtr((object)unsignedDetails[i], (IntPtr)num2, fDeleteOld: false);
				}
				MmException.Try(MixerInterop.mixerSetControlDetails(mixerHandle, ref mixerControlDetails, MixerFlags.Mixer | mixerHandleType), "mixerSetControlDetails");
				Marshal.FreeHGlobal(mixerControlDetails.paDetails);
			}
		}

		public uint MinValue => (uint)mixerControl.Bounds.minimum;

		public uint MaxValue => (uint)mixerControl.Bounds.maximum;

		public double Percent
		{
			get
			{
				return 100.0 * (double)(Value - MinValue) / (double)(MaxValue - MinValue);
			}
			set
			{
				Value = (uint)((double)MinValue + value / 100.0 * (double)(MaxValue - MinValue));
			}
		}

		internal UnsignedMixerControl(MixerInterop.MIXERCONTROL mixerControl, IntPtr mixerHandle, MixerFlags mixerHandleType, int nChannels)
		{
			base.mixerControl = mixerControl;
			base.mixerHandle = mixerHandle;
			base.mixerHandleType = mixerHandleType;
			base.nChannels = nChannels;
			mixerControlDetails = default(MixerInterop.MIXERCONTROLDETAILS);
			GetControlDetails();
		}

		protected override void GetDetails(IntPtr pDetails)
		{
			unsignedDetails = new MixerInterop.MIXERCONTROLDETAILS_UNSIGNED[nChannels];
			for (int i = 0; i < nChannels; i++)
			{
				unsignedDetails[i] = MarshalHelpers.PtrToStructure<MixerInterop.MIXERCONTROLDETAILS_UNSIGNED>(mixerControlDetails.paDetails);
			}
		}

		public override string ToString()
		{
			return $"{base.ToString()} {Percent}%";
		}
	}
}
namespace NAudio.Midi
{
	public class ChannelAfterTouchEvent : MidiEvent
	{
		private byte afterTouchPressure;

		public int AfterTouchPressure
		{
			get
			{
				return afterTouchPressure;
			}
			set
			{
				if (value < 0 || value > 127)
				{
					throw new ArgumentOutOfRangeException("value", "After touch pressure must be in the range 0-127");
				}
				afterTouchPressure = (byte)value;
			}
		}

		public ChannelAfterTouchEvent(BinaryReader br)
		{
			afterTouchPressure = br.ReadByte();
			if ((afterTouchPressure & 0x80) != 0)
			{
				throw new FormatException("Invalid afterTouchPressure");
			}
		}

		public ChannelAfterTouchEvent(long absoluteTime, int channel, int afterTouchPressure)
			: base(absoluteTime, channel, MidiCommandCode.ChannelAfterTouch)
		{
			AfterTouchPressure = afterTouchPressure;
		}

		public override void Export(ref long absoluteTime, BinaryWriter writer)
		{
			base.Export(ref absoluteTime, writer);
			writer.Write(afterTouchPressure);
		}
	}
	public class ControlChangeEvent : MidiEvent
	{
		private MidiController controller;

		private byte controllerValue;

		public MidiController Controller
		{
			get
			{
				return controller;
			}
			set
			{
				if ((int)value < 0 || (int)value > 127)
				{
					throw new ArgumentOutOfRangeException("value", "Controller number must be in the range 0-127");
				}
				controller = value;
			}
		}

		public int ControllerValue
		{
			get
			{
				return controllerValue;
			}
			set
			{
				if (value < 0 || value > 127)
				{
					throw new ArgumentOutOfRangeException("value", "Controller Value must be in the range 0-127");
				}
				controllerValue = (byte)value;
			}
		}

		public ControlChangeEvent(BinaryReader br)
		{
			byte b = br.ReadByte();
			controllerValue = br.ReadByte();
			if ((b & 0x80) != 0)
			{
				throw new InvalidDataException("Invalid controller");
			}
			controller = (MidiController)b;
			if ((controllerValue & 0x80) != 0)
			{
				throw new InvalidDataException($"Invalid controllerValue {controllerValue} for controller {controller}, Pos 0x{br.BaseStream.Position:X}");
			}
		}

		public ControlChangeEvent(long absoluteTime, int channel, MidiController controller, int controllerValue)
			: base(absoluteTime, channel, MidiCommandCode.ControlChange)
		{
			Controller = controller;
			ControllerValue = controllerValue;
		}

		public override string ToString()
		{
			return $"{base.ToString()} Controller {controller} Value {controllerValue}";
		}

		public override int GetAsShortMessage()
		{
			byte b = (byte)controller;
			return base.GetAsShortMessage() + (b << 8) + (controllerValue << 16);
		}

		public override void Export(ref long absoluteTime, BinaryWriter writer)
		{
			base.Export(ref absoluteTime, writer);
			writer.Write((byte)controller);
			writer.Write(controllerValue);
		}
	}
	public class KeySignatureEvent : MetaEvent
	{
		private readonly byte sharpsFlats;

		private readonly byte majorMinor;

		public int SharpsFlats => (sbyte)sharpsFlats;

		public int MajorMinor => majorMinor;

		public KeySignatureEvent(BinaryReader br, int length)
		{
			if (length != 2)
			{
				throw new FormatException("Invalid key signature length");
			}
			sharpsFlats = br.ReadByte();
			majorMinor = br.ReadByte();
		}

		public KeySignatureEvent(int sharpsFlats, int majorMinor, long absoluteTime)
			: base(MetaEventType.KeySignature, 2, absoluteTime)
		{
			this.sharpsFlats = (byte)sharpsFlats;
			this.majorMinor = (byte)majorMinor;
		}

		public override MidiEvent Clone()
		{
			return (KeySignatureEvent)MemberwiseClone();
		}

		public override string ToString()
		{
			return $"{base.ToString()} {SharpsFlats} {majorMinor}";
		}

		public override void Export(ref long absoluteTime, BinaryWriter writer)
		{
			base.Export(ref absoluteTime, writer);
			writer.Write(sharpsFlats);
			writer.Write(majorMinor);
		}
	}
	public class MetaEvent : MidiEvent
	{
		private MetaEventType metaEvent;

		internal int metaDataLength;

		public MetaEventType MetaEventType => metaEvent;

		protected MetaEvent()
		{
		}

		public MetaEvent(MetaEventType metaEventType, int metaDataLength, long absoluteTime)
			: base(absoluteTime, 1, MidiCommandCode.MetaEvent)
		{
			metaEvent = metaEventType;
			this.metaDataLength = metaDataLength;
		}

		public override MidiEvent Clone()
		{
			return new MetaEvent(metaEvent, metaDataLength, base.AbsoluteTime);
		}

		public static MetaEvent ReadMetaEvent(BinaryReader br)
		{
			MetaEventType metaEventType = (MetaEventType)br.ReadByte();
			int num = MidiEvent.ReadVarInt(br);
			MetaEvent metaEvent = new MetaEvent();
			if (metaEventType <= MetaEventType.SetTempo)
			{
				if (metaEventType <= MetaEventType.DeviceName)
				{
					if (metaEventType != MetaEventType.TrackSequenceNumber)
					{
						if (metaEventType - 1 > MetaEventType.ProgramName)
						{
							goto IL_00a6;
						}
						metaEvent = new TextEvent(br, num);
					}
					else
					{
						metaEvent = new TrackSequenceNumberEvent(br, num);
					}
				}
				else if (metaEventType != MetaEventType.EndTrack)
				{
					if (metaEventType != MetaEventType.SetTempo)
					{
						goto IL_00a6;
					}
					metaEvent = new TempoEvent(br, num);
				}
				else if (num != 0)
				{
					throw new FormatException("End track length");
				}
			}
			else if (metaEventType <= MetaEventType.TimeSignature)
			{
				if (metaEventType != MetaEventType.SmpteOffset)
				{
					if (metaEventType != MetaEventType.TimeSignature)
					{
						goto IL_00a6;
					}
					metaEvent = new TimeSignatureEvent(br, num);
				}
				else
				{
					metaEvent = new SmpteOffsetEvent(br, num);
				}
			}
			else if (metaEventType != MetaEventType.KeySignature)
			{
				if (metaEventType != MetaEventType.SequencerSpecific)
				{
					goto IL_00a6;
				}
				metaEvent = new SequencerSpecificEvent(br, num);
			}
			else
			{
				metaEvent = new KeySignatureEvent(br, num);
			}
			metaEvent.metaEvent = metaEventType;
			metaEvent.metaDataLength = num;
			return metaEvent;
			IL_00a6:
			byte[] array = br.ReadBytes(num);
			if (array.Length != num)
			{
				throw new FormatException("Failed to read metaevent's data fully");
			}
			return new RawMetaEvent(metaEventType, 0L, array);
		}

		public override string ToString()
		{
			return $"{base.AbsoluteTime} {metaEvent}";
		}

		public override void Export(ref long absoluteTime, BinaryWriter writer)
		{
			base.Export(ref absoluteTime, writer);
			writer.Write((byte)metaEvent);
			MidiEvent.WriteVarInt(writer, metaDataLength);
		}
	}
	public enum MetaEventType : byte
	{
		TrackSequenceNumber = 0,
		TextEvent = 1,
		Copyright = 2,
		SequenceTrackName = 3,
		TrackInstrumentName = 4,
		Lyric = 5,
		Marker = 6,
		CuePoint = 7,
		ProgramName = 8,
		DeviceName = 9,
		MidiChannel = 32,
		MidiPort = 33,
		EndTrack = 47,
		SetTempo = 81,
		SmpteOffset = 84,
		TimeSignature = 88,
		KeySignature = 89,
		SequencerSpecific = 127
	}
	public enum MidiCommandCode : byte
	{
		NoteOff = 128,
		NoteOn = 144,
		KeyAfterTouch = 160,
		ControlChange = 176,
		PatchChange = 192,
		ChannelAfterTouch = 208,
		PitchWheelChange = 224,
		Sysex = 240,
		Eox = 247,
		TimingClock = 248,
		StartSequence = 250,
		ContinueSequence = 251,
		StopSequence = 252,
		AutoSensing = 254,
		MetaEvent = byte.MaxValue
	}
	public enum MidiController : byte
	{
		BankSelect = 0,
		Modulation = 1,
		BreathController = 2,
		FootController = 4,
		MainVolume = 7,
		Pan = 10,
		Expression = 11,
		BankSelectLsb = 32,
		Sustain = 64,
		Portamento = 65,
		Sostenuto = 66,
		SoftPedal = 67,
		LegatoFootswitch = 68,
		ResetAllControllers = 121,
		AllNotesOff = 123
	}
	public class MidiEvent : ICloneable
	{
		private MidiCommandCode commandCode;

		private int channel;

		private int deltaTime;

		private long absoluteTime;

		public virtual int Channel
		{
			get
			{
				return channel;
			}
			set
			{
				if (value < 1 || value > 16)
				{
					throw new ArgumentOutOfRangeException("value", value, $"Channel must be 1-16 (Got {value})");
				}
				channel = value;
			}
		}

		public int DeltaTime => deltaTime;

		public long AbsoluteTime
		{
			get
			{
				return absoluteTime;
			}
			set
			{
				absoluteTime = value;
			}
		}

		public MidiCommandCode CommandCode => commandCode;

		public static MidiEvent FromRawMessage(int rawMessage)
		{
			long num = 0L;
			int num2 = rawMessage & 0xFF;
			int num3 = (rawMessage >> 8) & 0xFF;
			int num4 = (rawMessage >> 16) & 0xFF;
			int num5 = 1;
			MidiCommandCode midiCommandCode;
			if ((num2 & 0xF0) == 240)
			{
				midiCommandCode = (MidiCommandCode)num2;
			}
			else
			{
				midiCommandCode = (MidiCommandCode)(num2 & 0xF0);
				num5 = (num2 & 0xF) + 1;
			}
			switch (midiCommandCode)
			{
			case MidiCommandCode.NoteOff:
			case MidiCommandCode.NoteOn:
			case MidiCommandCode.KeyAfterTouch:
				if (num4 > 0 && midiCommandCode == MidiCommandCode.NoteOn)
				{
					return new NoteOnEvent(num, num5, num3, num4, 0);
				}
				return new NoteEvent(num, num5, midiCommandCode, num3, num4);
			case MidiCommandCode.ControlChange:
				return new ControlChangeEvent(num, num5, (MidiController)num3, num4);
			case MidiCommandCode.PatchChange:
				return new PatchChangeEvent(num, num5, num3);
			case MidiCommandCode.ChannelAfterTouch:
				return new ChannelAfterTouchEvent(num, num5, num3);
			case MidiCommandCode.PitchWheelChange:
				return new PitchWheelChangeEvent(num, num5, num3 + (num4 << 7));
			case MidiCommandCode.TimingClock:
			case MidiCommandCode.StartSequence:
			case MidiCommandCode.ContinueSequence:
			case MidiCommandCode.StopSequence:
			case MidiCommandCode.AutoSensing:
				return new MidiEvent(num, num5, midiCommandCode);
			default:
				throw new FormatException($"Unsupported MIDI Command Code for Raw Message {midiCommandCode}");
			}
		}

		public static MidiEvent ReadNextEvent(BinaryReader br, MidiEvent previous)
		{
			int num = ReadVarInt(br);
			int num2 = 1;
			byte b = br.ReadByte();
			MidiCommandCode midiCommandCode;
			if ((b & 0x80) == 0)
			{
				midiCommandCode = previous.CommandCode;
				num2 = previous.Channel;
				br.BaseStream.Position--;
			}
			else if ((b & 0xF0) == 240)
			{
				midiCommandCode = (MidiCommandCode)b;
			}
			else
			{
				midiCommandCode = (MidiCommandCode)(b & 0xF0);
				num2 = (b & 0xF) + 1;
			}
			MidiEvent midiEvent;
			switch (midiCommandCode)
			{
			case MidiCommandCode.NoteOn:
				midiEvent = new NoteOnEvent(br);
				break;
			case MidiCommandCode.NoteOff:
			case MidiCommandCode.KeyAfterTouch:
				midiEvent = new NoteEvent(br);
				break;
			case MidiCommandCode.ControlChange:
				midiEvent = new ControlChangeEvent(br);
				break;
			case MidiCommandCode.PatchChange:
				midiEvent = new PatchChangeEvent(br);
				break;
			case MidiCommandCode.ChannelAfterTouch:
				midiEvent = new ChannelAfterTouchEvent(br);
				break;
			case MidiCommandCode.PitchWheelChange:
				midiEvent = new PitchWheelChangeEvent(br);
				break;
			case MidiCommandCode.TimingClock:
			case MidiCommandCode.StartSequence:
			case MidiCommandCode.ContinueSequence:
			case MidiCommandCode.StopSequence:
				midiEvent = new MidiEvent();
				break;
			case MidiCommandCode.Sysex:
				midiEvent = SysexEvent.ReadSysexEvent(br);
				break;
			case MidiCommandCode.MetaEvent:
				midiEvent = MetaEvent.ReadMetaEvent(br);
				break;
			default:
				throw new FormatException($"Unsupported MIDI Command Code {(byte)midiCommandCode:X2}");
			}
			midiEvent.channel = num2;
			midiEvent.deltaTime = num;
			midiEvent.commandCode = midiCommandCode;
			return midiEvent;
		}

		public virtual int GetAsShortMessage()
		{
			return channel - 1 + (int)commandCode;
		}

		protected MidiEvent()
		{
		}

		public MidiEvent(long absoluteTime, int channel, MidiCommandCode commandCode)
		{
			this.absoluteTime = absoluteTime;
			Channel = channel;
			this.commandCode = commandCode;
		}

		public virtual MidiEvent Clone()
		{
			return (MidiEvent)MemberwiseClone();
		}

		object ICloneable.Clone()
		{
			return Clone();
		}

		public static bool IsNoteOff(MidiEvent midiEvent)
		{
			if (midiEvent != null)
			{
				if (midiEvent.CommandCode == MidiCommandCode.NoteOn)
				{
					return ((NoteEvent)midiEvent).Velocity == 0;
				}
				return midiEvent.CommandCode == MidiCommandCode.NoteOff;
			}
			return false;
		}

		public static bool IsNoteOn(MidiEvent midiEvent)
		{
			if (midiEvent != null && midiEvent.CommandCode == MidiCommandCode.NoteOn)
			{
				return ((NoteEvent)midiEvent).Velocity > 0;
			}
			return false;
		}

		public static bool IsEndTrack(MidiEvent midiEvent)
		{
			if (midiEvent != null && midiEvent is MetaEvent metaEvent)
			{
				return metaEvent.MetaEventType == MetaEventType.EndTrack;
			}
			return false;
		}

		public override string ToString()
		{
			if ((int)commandCode >= 240)
			{
				return $"{absoluteTime} {commandCode}";
			}
			return $"{absoluteTime} {commandCode} Ch: {channel}";
		}

		public static int ReadVarInt(BinaryReader br)
		{
			int num = 0;
			for (int i = 0; i < 4; i++)
			{
				byte b = br.ReadByte();
				num <<= 7;
				num += b & 0x7F;
				if ((b & 0x80) == 0)
				{
					return num;
				}
			}
			throw new FormatException("Invalid Var Int");
		}

		public static void WriteVarInt(BinaryWriter writer, int value)
		{
			if (value < 0)
			{
				throw new ArgumentOutOfRangeException("value", value, "Cannot write a negative Var Int");
			}
			if (value > 268435455)
			{
				throw new ArgumentOutOfRangeException("value", value, "Maximum allowed Var Int is 0x0FFFFFFF");
			}
			int num = 0;
			byte[] array = new byte[4];
			do
			{
				array[num++] = (byte)(value & 0x7F);
				value >>= 7;
			}
			while (value > 0);
			while (num > 0)
			{
				num--;
				if (num > 0)
				{
					writer.Write((byte)(array[num] | 0x80));
				}
				else
				{
					writer.Write(array[num]);
				}
			}
		}

		public virtual void Export(ref long absoluteTime, BinaryWriter writer)
		{
			if (this.absoluteTime < absoluteTime)
			{
				throw new FormatException("Can't export unsorted MIDI events");
			}
			WriteVarInt(writer, (int)(this.absoluteTime - absoluteTime));
			absoluteTime = this.absoluteTime;
			int num = (int)commandCode;
			if (commandCode != MidiCommandCode.MetaEvent)
			{
				num += channel - 1;
			}
			writer.Write((byte)num);
		}
	}
	public class MidiEventCollection : IEnumerable<IList<MidiEvent>>, IEnumerable
	{
		private int midiFileType;

		private readonly List<IList<MidiEvent>> trackEvents;

		public int Tracks => trackEvents.Count;

		public long StartAbsoluteTime { get; set; }

		public int DeltaTicksPerQuarterNote { get; }

		public IList<MidiEvent> this[int trackNumber] => trackEvents[trackNumber];

		public int MidiFileType
		{
			get
			{
				return midiFileType;
			}
			set
			{
				if (midiFileType != value)
				{
					midiFileType = value;
					if (value == 0)
					{
						FlattenToOneTrack();
					}
					else
					{
						ExplodeToManyTracks();
					}
				}
			}
		}

		public MidiEventCollection(int midiFileType, int deltaTicksPerQuarterNote)
		{
			this.midiFileType = midiFileType;
			DeltaTicksPerQuarterNote = deltaTicksPerQuarterNote;
			StartAbsoluteTime = 0L;
			trackEvents = new List<IList<MidiEvent>>();
		}

		public IList<MidiEvent> GetTrackEvents(int trackNumber)
		{
			return trackEvents[trackNumber];
		}

		public IList<MidiEvent> AddTrack()
		{
			return AddTrack(null);
		}

		public IList<MidiEvent> AddTrack(IList<MidiEvent> initialEvents)
		{
			List<MidiEvent> list = new List<MidiEvent>();
			if (initialEvents != null)
			{
				list.AddRange(initialEvents);
			}
			trackEvents.Add(list);
			return list;
		}

		public void RemoveTrack(int track)
		{
			trackEvents.RemoveAt(track);
		}

		public void Clear()
		{
			trackEvents.Clear();
		}

		public void AddEvent(MidiEvent midiEvent, int originalTrack)
		{
			if (midiFileType == 0)
			{
				EnsureTracks(1);
				trackEvents[0].Add(midiEvent);
			}
			else if (originalTrack == 0)
			{
				switch (midiEvent.CommandCode)
				{
				case MidiCommandCode.NoteOff:
				case MidiCommandCode.NoteOn:
				case MidiCommandCode.KeyAfterTouch:
				case MidiCommandCode.ControlChange:
				case MidiCommandCode.PatchChange:
				case MidiCommandCode.ChannelAfterTouch:
				case MidiCommandCode.PitchWheelChange:
					EnsureTracks(midiEvent.Channel + 1);
					trackEvents[midiEvent.Channel].Add(midiEvent);
					break;
				default:
					EnsureTracks(1);
					trackEvents[0].Add(midiEvent);
					break;
				}
			}
			else
			{
				EnsureTracks(originalTrack + 1);
				trackEvents[originalTrack].Add(midiEvent);
			}
		}

		private void EnsureTracks(int count)
		{
			for (int i = trackEvents.Count; i < count; i++)
			{
				trackEvents.Add(new List<MidiEvent>());
			}
		}

		private void ExplodeToManyTracks()
		{
			IList<MidiEvent> list = trackEvents[0];
			Clear();
			foreach (MidiEvent item in list)
			{
				AddEvent(item, 0);
			}
			PrepareForExport();
		}

		private void FlattenToOneTrack()
		{
			bool flag = false;
			for (int i = 1; i < trackEvents.Count; i++)
			{
				foreach (MidiEvent item in trackEvents[i])
				{
					if (!MidiEvent.IsEndTrack(item))
					{
						trackEvents[0].Add(item);
						flag = true;
					}
				}
			}
			for (int num = trackEvents.Count - 1; num > 0; num--)
			{
				RemoveTrack(num);
			}
			if (flag)
			{
				PrepareForExport();
			}
		}

		public void PrepareForExport()
		{
			MidiEventComparer comparer = new MidiEventComparer();
			foreach (IList<MidiEvent> trackEvent in trackEvents)
			{
				MergeSort.Sort(trackEvent, comparer);
				int num = 0;
				while (num < trackEvent.Count - 1)
				{
					if (MidiEvent.IsEndTrack(trackEvent[num]))
					{
						trackEvent.RemoveAt(num);
					}
					else
					{
						num++;
					}
				}
			}
			int num2 = 0;
			while (num2 < trackEvents.Count)
			{
				IList<MidiEvent> list = trackEvents[num2];
				if (list.Count == 0)
				{
					RemoveTrack(num2);
					continue;
				}
				if (list.Count == 1 && MidiEvent.IsEndTrack(list[0]))
				{
					RemoveTrack(num2);
					continue;
				}
				if (!MidiEvent.IsEndTrack(list[list.Count - 1]))
				{
					list.Add(new MetaEvent(MetaEventType.EndTrack, 0, list[list.Count - 1].AbsoluteTime));
				}
				num2++;
			}
		}

		public IEnumerator<IList<MidiEvent>> GetEnumerator()
		{
			return trackEvents.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return trackEvents.GetEnumerator();
		}
	}
	public class MidiEventComparer : IComparer<MidiEvent>
	{
		public int Compare(MidiEvent x, MidiEvent y)
		{
			long num = x.AbsoluteTime;
			long num2 = y.AbsoluteTime;
			if (num == num2)
			{
				MetaEvent metaEvent = x as MetaEvent;
				MetaEvent metaEvent2 = y as MetaEvent;
				if (metaEvent != null)
				{
					num = ((metaEvent.MetaEventType != MetaEventType.EndTrack) ? long.MinValue : long.MaxValue);
				}
				if (metaEvent2 != null)
				{
					num2 = ((metaEvent2.MetaEventType != MetaEventType.EndTrack) ? long.MinValue : long.MaxValue);
				}
			}
			return num.CompareTo(num2);
		}
	}
	public class MidiFile
	{
		private readonly MidiEventCollection events;

		private readonly ushort fileFormat;

		private readonly ushort deltaTicksPerQuarterNote;

		private readonly bool strictChecking;

		public int FileFormat => fileFormat;

		public MidiEventCollection Events => events;

		public int Tracks => events.Tracks;

		public int DeltaTicksPerQuarterNote => deltaTicksPerQuarterNote;

		public MidiFile(string filename)
			: this(filename, strictChecking: true)
		{
		}

		public MidiFile(string filename, bool strictChecking)
			: this(File.OpenRead(filename), strictChecking, ownInputStream: true)
		{
		}

		public MidiFile(Stream inputStream, bool strictChecking)
			: this(inputStream, strictChecking, ownInputStream: false)
		{
		}

		private MidiFile(Stream inputStream, bool strictChecking, bool ownInputStream)
		{
			this.strictChecking = strictChecking;
			BinaryReader binaryReader = new BinaryReader(inputStream);
			try
			{
				if (Encoding.UTF8.GetString(binaryReader.ReadBytes(4)) != "MThd")
				{
					throw new FormatException("Not a MIDI file - header chunk missing");
				}
				uint num = SwapUInt32(binaryReader.ReadUInt32());
				if (num != 6)
				{
					throw new FormatException("Unexpected header chunk length");
				}
				fileFormat = SwapUInt16(binaryReader.ReadUInt16());
				int num2 = SwapUInt16(binaryReader.ReadUInt16());
				deltaTicksPerQuarterNote = SwapUInt16(binaryReader.ReadUInt16());
				events = new MidiEventCollection((fileFormat != 0) ? 1 : 0, deltaTicksPerQuarterNote);
				for (int i = 0; i < num2; i++)
				{
					events.AddTrack();
				}
				long num3 = 0L;
				for (int j = 0; j < num2; j++)
				{
					if (fileFormat == 1)
					{
						num3 = 0L;
					}
					if (Encoding.UTF8.GetString(binaryReader.ReadBytes(4)) != "MTrk")
					{
						throw new FormatException("Invalid chunk header");
					}
					num = SwapUInt32(binaryReader.ReadUInt32());
					long position = binaryReader.BaseStream.Position;
					MidiEvent midiEvent = null;
					List<NoteOnEvent> list = new List<NoteOnEvent>();
					while (binaryReader.BaseStream.Position < position + num)
					{
						try
						{
							midiEvent = MidiEvent.ReadNextEvent(binaryReader, midiEvent);
						}
						catch (InvalidDataException)
						{
							if (strictChecking)
							{
								throw;
							}
							continue;
						}
						catch (FormatException)
						{
							if (strictChecking)
							{
								throw;
							}
							continue;
						}
						num3 = (midiEvent.AbsoluteTime = num3 + midiEvent.DeltaTime);
						events[j].Add(midiEvent);
						if (midiEvent.CommandCode == MidiCommandCode.NoteOn)
						{
							NoteEvent noteEvent = (NoteEvent)midiEvent;
							if (noteEvent.Velocity > 0)
							{
								list.Add((NoteOnEvent)noteEvent);
							}
							else
							{
								FindNoteOn(noteEvent, list);
							}
						}
						else if (midiEvent.CommandCode == MidiCommandCode.NoteOff)
						{
							FindNoteOn((NoteEvent)midiEvent, list);
						}
						else if (midiEvent.CommandCode == MidiCommandCode.MetaEvent && ((MetaEvent)midiEvent).MetaEventType == MetaEventType.EndTrack && strictChecking && binaryReader.BaseStream.Position < position + num)
						{
							throw new FormatException($"End Track event was not the last MIDI event on track {j}");
						}
					}
					if (list.Count > 0 && strictChecking)
					{
						throw new FormatException($"Note ons without note offs {list.Count} (file format {fileFormat})");
					}
					if (binaryReader.BaseStream.Position != position + num)
					{
						throw new FormatException($"Read too far {num}+{position}!={binaryReader.BaseStream.Position}");
					}
				}
			}
			finally
			{
				if (ownInputStream)
				{
					binaryReader.Close();
				}
			}
		}

		private void FindNoteOn(NoteEvent offEvent, List<NoteOnEvent> outstandingNoteOns)
		{
			bool flag = false;
			foreach (NoteOnEvent outstandingNoteOn in outstandingNoteOns)
			{
				if (outstandingNoteOn.Channel == offEvent.Channel && outstandingNoteOn.NoteNumber == offEvent.NoteNumber)
				{
					outstandingNoteOn.OffEvent = offEvent;
					outstandingNoteOns.Remove(outstandingNoteOn);
					flag = true;
					break;
				}
			}
			if (!flag && strictChecking)
			{
				throw new FormatException($"Got an off without an on {offEvent}");
			}
		}

		private static uint SwapUInt32(uint i)
		{
			return ((i & 0xFF000000u) >> 24) | ((i & 0xFF0000) >> 8) | ((i & 0xFF00) << 8) | ((i & 0xFF) << 24);
		}

		private static ushort SwapUInt16(ushort i)
		{
			return (ushort)(((i & 0xFF00) >> 8) | ((i & 0xFF) << 8));
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendFormat("Format {0}, Tracks {1}, Delta Ticks Per Quarter Note {2}\r\n", fileFormat, Tracks, deltaTicksPerQuarterNote);
			for (int i = 0; i < Tracks; i++)
			{
				foreach (MidiEvent item in events[i])
				{
					stringBuilder.AppendFormat("{0}\r\n", item);
				}
			}
			return stringBuilder.ToString();
		}

		public static void Export(string filename, MidiEventCollection events)
		{
			if (events.MidiFileType == 0 && events.Tracks > 1)
			{
				throw new ArgumentException("Can't export more than one track to a type 0 file");
			}
			using BinaryWriter binaryWriter = new BinaryWriter(File.Create(filename));
			binaryWriter.Write(Encoding.UTF8.GetBytes("MThd"));
			binaryWriter.Write(SwapUInt32(6u));
			binaryWriter.Write(SwapUInt16((ushort)events.MidiFileType));
			binaryWriter.Write(SwapUInt16((ushort)events.Tracks));
			binaryWriter.Write(SwapUInt16((ushort)events.DeltaTicksPerQuarterNote));
			for (int i = 0; i < events.Tracks; i++)
			{
				IList<MidiEvent> list = events[i];
				binaryWriter.Write(Encoding.UTF8.GetBytes("MTrk"));
				long position = binaryWriter.BaseStream.Position;
				binaryWriter.Write(SwapUInt32(0u));
				long absoluteTime = events.StartAbsoluteTime;
				MergeSort.Sort(list, new MidiEventComparer());
				_ = list.Count;
				_ = 0;
				foreach (MidiEvent item in list)
				{
					item.Export(ref absoluteTime, binaryWriter);
				}
				uint num = (uint)((int)(binaryWriter.BaseStream.Position - position) - 4);
				binaryWriter.BaseStream.Position = position;
				binaryWriter.Write(SwapUInt32(num));
				binaryWriter.BaseStream.Position += num;
			}
		}
	}
	public class MidiIn : IDisposable
	{
		private IntPtr hMidiIn = IntPtr.Zero;

		private bool disposed;

		private MidiInterop.MidiInCallback callback;

		public static int NumberOfDevices => MidiInterop.midiInGetNumDevs();

		public event EventHandler<MidiInMessageEventArgs> MessageReceived;

		public event EventHandler<MidiInMessageEventArgs> ErrorReceived;

		public MidiIn(int deviceNo)
		{
			callback = Callback;
			MmException.Try(MidiInterop.midiInOpen(out hMidiIn, (IntPtr)deviceNo, callback, IntPtr.Zero, 196608), "midiInOpen");
		}

		public void Close()
		{
			Dispose();
		}

		public void Dispose()
		{
			GC.KeepAlive(callback);
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		public void Start()
		{
			MmException.Try(MidiInterop.midiInStart(hMidiIn), "midiInStart");
		}

		public void Stop()
		{
			MmException.Try(MidiInterop.midiInStop(hMidiIn), "midiInStop");
		}

		public void Reset()
		{
			MmException.Try(MidiInterop.midiInReset(hMidiIn), "midiInReset");
		}

		private void Callback(IntPtr midiInHandle, MidiInterop.MidiInMessage message, IntPtr userData, IntPtr messageParameter1, IntPtr messageParameter2)
		{
			switch (message)
			{
			case MidiInterop.MidiInMessage.Data:
				if (this.MessageReceived != null)
				{
					this.MessageReceived(this, new MidiInMessageEventArgs(messageParameter1.ToInt32(), messageParameter2.ToInt32()));
				}
				break;
			case MidiInterop.MidiInMessage.Error:
				if (this.ErrorReceived != null)
				{
					this.ErrorReceived(this, new MidiInMessageEventArgs(messageParameter1.ToInt32(), messageParameter2.ToInt32()));
				}
				break;
			case MidiInterop.MidiInMessage.Open:
			case MidiInterop.MidiInMessage.Close:
			case MidiInterop.MidiInMessage.LongData:
			case MidiInterop.MidiInMessage.LongError:
			case (MidiInterop.MidiInMessage)967:
			case (MidiInterop.MidiInMessage)968:
			case (MidiInterop.MidiInMessage)969:
			case (MidiInterop.MidiInMessage)970:
			case (MidiInterop.MidiInMessage)971:
			case MidiInterop.MidiInMessage.MoreData:
				break;
			}
		}

		public static MidiInCapabilities DeviceInfo(int midiInDeviceNumber)
		{
			MidiInCapabilities capabilities = default(MidiInCapabilities);
			int size = Marshal.SizeOf((object)capabilities);
			MmException.Try(MidiInterop.midiInGetDevCaps((IntPtr)midiInDeviceNumber, out capabilities, size), "midiInGetDevCaps");
			return capabilities;
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposed)
			{
				MidiInterop.midiInClose(hMidiIn);
			}
			disposed = true;
		}

		~MidiIn()
		{
			Dispose(disposing: false);
		}
	}
	[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
	public struct MidiInCapabilities
	{
		private ushort manufacturerId;

		private ushort productId;

		private uint driverVersion;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
		private string productName;

		private int support;

		private const int MaxProductNameLength = 32;

		public Manufacturers Manufacturer => (Manufacturers)manufacturerId;

		public int ProductId => productId;

		public string ProductName => productName;
	}
	public class MidiInMessageEventArgs : EventArgs
	{
		public int RawMessage { get; private set; }

		public MidiEvent MidiEvent { get; private set; }

		public int Timestamp { get; private set; }

		public MidiInMessageEventArgs(int message, int timestamp)
		{
			RawMessage = message;
			Timestamp = timestamp;
			try
			{
				MidiEvent = MidiEvent.FromRawMessage(message);
			}
			catch (Exception)
			{
			}
		}
	}
	internal class MidiInterop
	{
		public enum MidiInMessage
		{
			Open = 961,
			Close = 962,
			Data = 963,
			LongData = 964,
			Error = 965,
			LongError = 966,
			MoreData = 972
		}

		public enum MidiOutMessage
		{
			Open = 967,
			Close,
			Done
		}

		public delegate void MidiInCallback(IntPtr midiInHandle, MidiInMessage message, IntPtr userData, IntPtr messageParameter1, IntPtr messageParameter2);

		public delegate void MidiOutCallback(IntPtr midiInHandle, MidiOutMessage message, IntPtr userData, IntPtr messageParameter1, IntPtr messageParameter2);

		public struct MMTIME
		{
			public int wType;

			public int u;
		}

		public struct MIDIEVENT
		{
			public int dwDeltaTime;

			public int dwStreamID;

			public int dwEvent;

			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
			public int dwParms;
		}

		public struct MIDIHDR
		{
			public IntPtr lpData;

			public int dwBufferLength;

			public int dwBytesRecorded;

			public IntPtr dwUser;

			public int dwFlags;

			public IntPtr lpNext;

			public IntPtr reserved;

			public int dwOffset;

			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
			public IntPtr[] dwReserved;
		}

		public struct MIDIPROPTEMPO
		{
			public int cbStruct;

			public int dwTempo;
		}

		public const int CALLBACK_FUNCTION = 196608;

		public const int CALLBACK_NULL = 0;

		[DllImport("winmm.dll")]
		public static extern MmResult midiConnect(IntPtr hMidiIn, IntPtr hMidiOut, IntPtr pReserved);

		[DllImport("winmm.dll")]
		public static extern MmResult midiDisconnect(IntPtr hMidiIn, IntPtr hMidiOut, IntPtr pReserved);

		[DllImport("winmm.dll")]
		public static extern MmResult midiInAddBuffer(IntPtr hMidiIn, ref MIDIHDR lpMidiInHdr, int uSize);

		[DllImport("winmm.dll")]
		public static extern MmResult midiInClose(IntPtr hMidiIn);

		[DllImport("winmm.dll", CharSet = CharSet.Auto)]
		public static extern MmResult midiInGetDevCaps(IntPtr deviceId, out MidiInCapabilities capabilities, int size);

		[DllImport("winmm.dll")]
		public static extern MmResult midiInGetErrorText(int err, string lpText, int uSize);

		[DllImport("winmm.dll")]
		public static extern MmResult midiInGetID(IntPtr hMidiIn, out int lpuDeviceId);

		[DllImport("winmm.dll")]
		public static extern int midiInGetNumDevs();

		[DllImport("winmm.dll")]
		public static extern MmResult midiInMessage(IntPtr hMidiIn, int msg, IntPtr dw1, IntPtr dw2);

		[DllImport("winmm.dll")]
		public static extern MmResult midiInOpen(out IntPtr hMidiIn, IntPtr uDeviceID, MidiInCallback callback, IntPtr dwInstance, int dwFlags);

		[DllImport("winmm.dll", EntryPoint = "midiInOpen")]
		public static extern MmResult midiInOpenWindow(out IntPtr hMidiIn, IntPtr uDeviceID, IntPtr callbackWindowHandle, IntPtr dwInstance, int dwFlags);

		[DllImport("winmm.dll")]
		public static extern MmResult midiInPrepareHeader(IntPtr hMidiIn, ref MIDIHDR lpMidiInHdr, int uSize);

		[DllImport("winmm.dll")]
		public static extern MmResult midiInReset(IntPtr hMidiIn);

		[DllImport("winmm.dll")]
		public static extern MmResult midiInStart(IntPtr hMidiIn);

		[DllImport("winmm.dll")]
		public static extern MmResult midiInStop(IntPtr hMidiIn);

		[DllImport("winmm.dll")]
		public static extern MmResult midiInUnprepareHeader(IntPtr hMidiIn, ref MIDIHDR lpMidiInHdr, int uSize);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutCacheDrumPatches(IntPtr hMidiOut, int uPatch, IntPtr lpKeyArray, int uFlags);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutCachePatches(IntPtr hMidiOut, int uBank, IntPtr lpPatchArray, int uFlags);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutClose(IntPtr hMidiOut);

		[DllImport("winmm.dll", CharSet = CharSet.Auto)]
		public static extern MmResult midiOutGetDevCaps(IntPtr deviceNumber, out MidiOutCapabilities caps, int uSize);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutGetErrorText(IntPtr err, string lpText, int uSize);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutGetID(IntPtr hMidiOut, out int lpuDeviceID);

		[DllImport("winmm.dll")]
		public static extern int midiOutGetNumDevs();

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutGetVolume(IntPtr uDeviceID, ref int lpdwVolume);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutLongMsg(IntPtr hMidiOut, ref MIDIHDR lpMidiOutHdr, int uSize);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutMessage(IntPtr hMidiOut, int msg, IntPtr dw1, IntPtr dw2);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutOpen(out IntPtr lphMidiOut, IntPtr uDeviceID, MidiOutCallback dwCallback, IntPtr dwInstance, int dwFlags);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutPrepareHeader(IntPtr hMidiOut, ref MIDIHDR lpMidiOutHdr, int uSize);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutReset(IntPtr hMidiOut);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutSetVolume(IntPtr hMidiOut, int dwVolume);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutShortMsg(IntPtr hMidiOut, int dwMsg);

		[DllImport("winmm.dll")]
		public static extern MmResult midiOutUnprepareHeader(IntPtr hMidiOut, ref MIDIHDR lpMidiOutHdr, int uSize);

		[DllImport("winmm.dll")]
		public static extern MmResult midiStreamClose(IntPtr hMidiStream);

		[DllImport("winmm.dll")]
		public static extern MmResult midiStreamOpen(out IntPtr hMidiStream, IntPtr puDeviceID, int cMidi, IntPtr dwCallback, IntPtr dwInstance, int fdwOpen);

		[DllImport("winmm.dll")]
		public static extern MmResult midiStreamOut(IntPtr hMidiStream, ref MIDIHDR pmh, int cbmh);

		[DllImport("winmm.dll")]
		public static extern MmResult midiStreamPause(IntPtr hMidiStream);

		[DllImport("winmm.dll")]
		public static extern MmResult midiStreamPosition(IntPtr hMidiStream, ref MMTIME lpmmt, int cbmmt);

		[DllImport("winmm.dll")]
		public static extern MmResult midiStreamProperty(IntPtr hMidiStream, IntPtr lppropdata, int dwProperty);

		[DllImport("winmm.dll")]
		public static extern MmResult midiStreamRestart(IntPtr hMidiStream);

		[DllImport("winmm.dll")]
		public static extern MmResult midiStreamStop(IntPtr hMidiStream);
	}
	public class MidiMessage
	{
		private int rawData;

		public int RawData => rawData;

		public MidiMessage(int status, int data1, int data2)
		{
			rawData = status + (data1 << 8) + (data2 << 16);
		}

		public MidiMessage(int rawData)
		{
			this.rawData = rawData;
		}

		public static MidiMessage StartNote(int note, int volume, int channel)
		{
			ValidateNoteParameters(note, volume, channel);
			return new MidiMessage(144 + channel - 1, note, volume);
		}

		private static void ValidateNoteParameters(int note, int volume, int channel)
		{
			ValidateChannel(channel);
			if (note < 0 || note > 127)
			{
				throw new ArgumentOutOfRangeException("note", "Note number must be in the range 0-127");
			}
			if (volume < 0 || volume > 127)
			{
				throw new ArgumentOutOfRangeException("volume", "Velocity must be in the range 0-127");
			}
		}

		private static void ValidateChannel(int channel)
		{
			if (channel < 1 || channel > 16)
			{
				throw new ArgumentOutOfRangeException("channel", channel, $"Channel must be 1-16 (Got {channel})");
			}
		}

		public static MidiMessage StopNote(int note, int volume, int channel)
		{
			ValidateNoteParameters(note, volume, channel);
			return new MidiMessage(128 + channel - 1, note, volume);
		}

		public static MidiMessage ChangePatch(int patch, int channel)
		{
			ValidateChannel(channel);
			return new MidiMessage(192 + channel - 1, patch, 0);
		}

		public static MidiMessage ChangeControl(int controller, int value, int channel)
		{
			ValidateChannel(channel);
			return new MidiMessage(176 + channel - 1, controller, value);
		}
	}
	public class MidiOut : IDisposable
	{
		private IntPtr hMidiOut = IntPtr.Zero;

		private bool disposed;

		private MidiInterop.MidiOutCallback callback;

		public static int NumberOfDevices => MidiInterop.midiOutGetNumDevs();

		public int Volume
		{
			get
			{
				int lpdwVolume = 0;
				MmException.Try(MidiInterop.midiOutGetVolume(hMidiOut, ref lpdwVolume), "midiOutGetVolume");
				return lpdwVolume;
			}
			set
			{
				MmException.Try(MidiInterop.midiOutSetVolume(hMidiOut, value), "midiOutSetVolume");
			}
		}

		public static MidiOutCapabilities DeviceInfo(int midiOutDeviceNumber)
		{
			MidiOutCapabilities caps = default(MidiOutCapabilities);
			int uSize = Marshal.SizeOf((object)caps);
			MmException.Try(MidiInterop.midiOutGetDevCaps((IntPtr)midiOutDeviceNumber, out caps, uSize), "midiOutGetDevCaps");
			return caps;
		}

		public MidiOut(int deviceNo)
		{
			callback = Callback;
			MmException.Try(MidiInterop.midiOutOpen(out hMidiOut, (IntPtr)deviceNo, callback, IntPtr.Zero, 196608), "midiOutOpen");
		}

		public void Close()
		{
			Dispose();
		}

		public void Dispose()
		{
			GC.KeepAlive(callback);
			Dispose(disposing: true);
			GC.SuppressFinalize(this);
		}

		public void Reset()
		{
			MmException.Try(MidiInterop.midiOutReset(hMidiOut), "midiOutReset");
		}

		public void SendDriverMessage(int message, int param1, int param2)
		{
			MmException.Try(MidiInterop.midiOutMessage(hMidiOut, message, (IntPtr)param1, (IntPtr)param2), "midiOutMessage");
		}

		public void Send(int message)
		{
			MmException.Try(MidiInterop.midiOutShortMsg(hMidiOut, message), "midiOutShortMsg");
		}

		protected virtual void Dispose(bool disposing)
		{
			if (!disposed)
			{
				MidiInterop.midiOutClose(hMidiOut);
			}
			disposed = true;
		}

		private void Callback(IntPtr midiInHandle, MidiInterop.MidiOutMessage message, IntPtr userData, IntPtr messageParameter1, IntPtr messageParameter2)
		{
		}

		public void SendBuffer(byte[] byteBuffer)
		{
			MidiInterop.MIDIHDR lpMidiOutHdr = new MidiInterop.MIDIHDR
			{
				lpData = Marshal.AllocHGlobal(byteBuffer.Length)
			};
			Marshal.Copy(byteBuffer, 0, lpMidiOutHdr.lpData, byteBuffer.Length);
			lpMidiOutHdr.dwBufferLength = byteBuffer.Length;
			lpMidiOutHdr.dwBytesRecorded = byteBuffer.Length;
			int uSize = Marshal.SizeOf((object)lpMidiOutHdr);
			MidiInterop.midiOutPrepareHeader(hMidiOut, ref lpMidiOutHdr, uSize);
			if (MidiInterop.midiOutLongMsg(hMidiOut, ref lpMidiOutHdr, uSize) != MmResult.NoError)
			{
				MidiInterop.midiOutUnprepareHeader(hMidiOut, ref lpMidiOutHdr, uSize);
			}
			Marshal.FreeHGlobal(lpMidiOutHdr.lpData);
		}

		~MidiOut()
		{
			Dispose(disposing: false);
		}
	}
	[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
	public struct MidiOutCapabilities
	{
		[Flags]
		private enum MidiOutCapabilityFlags
		{
			Volume = 1,
			LeftRightVolume = 2,
			PatchCaching = 4,
			Stream = 8
		}

		private short manufacturerId;

		private short productId;

		private int driverVersion;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
		private string productName;

		private short wTechnology;

		private short wVoices;

		private short wNotes;

		private ushort wChannelMask;

		private MidiOutCapabilityFlags dwSupport;

		private const int MaxProductNameLength = 32;

		public Manufacturers Manufacturer => (Manufacturers)manufacturerId;

		public short ProductId => productId;

		public string ProductName => productName;

		public int Voices => wVoices;

		public int Notes => wNotes;

		public bool SupportsAllChannels => wChannelMask == ushort.MaxValue;

		public bool SupportsPatchCaching => (dwSupport & MidiOutCapabilityFlags.PatchCaching) != 0;

		public bool SupportsSeparateLeftAndRightVolume => (dwSupport & MidiOutCapabilityFlags.LeftRightVolume) != 0;

		public bool SupportsMidiStreamOut => (dwSupport & MidiOutCapabilityFlags.Stream) != 0;

		public bool SupportsVolumeControl => (dwSupport & MidiOutCapabilityFlags.Volume) != 0;

		public MidiOutTechnology Technology => (MidiOutTechnology)wTechnology;

		public bool SupportsChannel(int channel)
		{
			return (wChannelMask & (1 << channel - 1)) > 0;
		}
	}
	public enum MidiOutTechnology
	{
		MidiPort = 1,
		Synth,
		SquareWaveSynth,
		FMSynth,
		MidiMapper,
		WaveTableSynth,
		SoftwareSynth
	}
	public class NoteEvent : MidiEvent
	{
		private int noteNumber;

		private int velocity;

		private static readonly string[] NoteNames = new string[12]
		{
			"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A",
			"A#", "B"
		};

		public virtual int NoteNumber
		{
			get
			{
				return noteNumber;
			}
			set
			{
				if (value < 0 || value > 127)
				{
					throw new ArgumentOutOfRangeException("value", "Note number must be in the range 0-127");
				}
				noteNumber = value;
			}
		}

		public int Velocity
		{
			get
			{
				return velocity;
			}
			set
			{
				if (value < 0 || value > 127)
				{
					throw new ArgumentOutOfRangeException("value", "Velocity must be in the range 0-127");
				}
				velocity = value;
			}
		}

		public string NoteName
		{
			get
			{
				if (Channel == 16 || Channel == 10)
				{
					return noteNumber switch
					{
						35 => "Acoustic Bass Drum", 
						36 => "Bass Drum 1", 
						37 => "Side Stick", 
						38 => "Acoustic Snare", 
						39 => "Hand Clap", 
						40 => "Electric Snare", 
						41 => "Low Floor Tom", 
						42 => "Closed Hi-Hat", 
						43 => "High Floor Tom", 
						44 => "Pedal Hi-Hat", 
						45 => "Low Tom", 
						46 => "Open Hi-Hat", 
						47 => "Low-Mid Tom", 
						48 => "Hi-Mid Tom", 
						49 => "Crash Cymbal 1", 
						50 => "High Tom", 
						51 => "Ride Cymbal 1", 
						52 => "Chinese Cymbal", 
						53 => "Ride Bell", 
						54 => "Tambourine", 
						55 => "Splash Cymbal", 
						56 => "Cowbell", 
						57 => "Crash Cymbal 2", 
						58 => "Vibraslap", 
						59 => "Ride Cymbal 2", 
						60 => "Hi Bongo", 
						61 => "Low Bongo", 
						62 => "Mute Hi Conga", 
						63 => "Open Hi Conga", 
						64 => "Low Conga", 
						65 => "High Timbale", 
						66 => "Low Timbale", 
						67 => "High Agogo", 
						68 => "Low Agogo", 
						69 => "Cabasa", 
						70 => "Maracas", 
						71 => "Short Whistle", 
						72 => "Long Whistle", 
						73 => "Short Guiro", 
						74 => "Long Guiro", 
						75 => "Claves", 
						76 => "Hi Wood Block", 
						77 => "Low Wood Block", 
						78 => "Mute Cuica", 
						79 => "Open Cuica", 
						80 => "Mute Triangle", 
						81 => "Open Triangle", 
						_ => $"Drum {noteNumber}", 
					};
				}
				int num = noteNumber / 12;
				return $"{NoteNames[noteNumber % 12]}{num}";
			}
		}

		public NoteEvent(BinaryReader br)
		{
			NoteNumber = br.ReadByte();
			velocity = br.ReadByte();
			if (velocity > 127)
			{
				velocity = 127;
			}
		}

		public NoteEvent(long absoluteTime, int channel, MidiCommandCode commandCode, int noteNumber, int velocity)
			: base(absoluteTime, channel, commandCode)
		{
			NoteNumber = noteNumber;
			Velocity = velocity;
		}

		public override int GetAsShortMessage()
		{
			return base.GetAsShortMessage() + (noteNumber << 8) + (velocity << 16);
		}

		public override string ToString()
		{
			return $"{base.ToString()} {NoteName} Vel:{Velocity}";
		}

		public override void Export(ref long absoluteTime, BinaryWriter writer)
		{
			base.Export(ref absoluteTime, writer);
			writer.Write((byte)noteNumber);
			writer.Write((byte)velocity);
		}
	}
	public class NoteOnEvent : NoteEvent
	{
		private NoteEvent offEvent;

		public NoteEvent OffEvent
		{
			get
			{
				return offEvent;
			}
			set
			{
				if (!MidiEvent.IsNoteOff(value))
				{
					throw new ArgumentException("OffEvent must be a valid MIDI note off event");
				}
				if (value.NoteNumber != NoteNumber)
				{
					throw new ArgumentException("Note Off Event must be for the same note number");
				}
				if (value.Channel != Channel)
				{
					throw new ArgumentException("Note Off Event must be for the same channel");
				}
				offEvent = value;
			}
		}

		public override int NoteNumber
		{
			get
			{
				return base.NoteNumber;
			}
			set
			{
				base.NoteNumber = value;
				if (OffEvent != null)
				{
					OffEvent.NoteNumber = NoteNumber;
				}
			}
		}

		public override int Channel
		{
			get
			{
				return base.Channel;
			}
			set
			{
				base.Channel = value;
				if (OffEvent != null)
				{
					OffEvent.Channel = Channel;
				}
			}
		}

		public int NoteLength
		{
			get
			{
				return (int)(offEvent.AbsoluteTime - base.AbsoluteTime);
			}
			set
			{
				if (value < 0)
				{
					throw new ArgumentException("NoteLength must be 0 or greater");
				}
				offEvent.AbsoluteTime = base.AbsoluteTime + value;
			}
		}

		public NoteOnEvent(BinaryReader br)
			: base(br)
		{
		}

		public NoteOnEvent(long absoluteTime, int channel, int noteNumber, int velocity, int duration)
			: base(absoluteTime, channel, MidiCommandCode.NoteOn, noteNumber, velocity)
		{
			OffEvent = new NoteEvent(absoluteTime, channel, MidiCommandCode.NoteOff, noteNumber, 0);
			NoteLength = duration;
		}

		public override MidiEvent Clone()
		{
			return new NoteOnEvent(base.AbsoluteTime, Channel, NoteNumber, base.Velocity, NoteLength);
		}

		public override string ToString()
		{
			if (base.Velocity == 0 && OffEvent == null)
			{
				return $"{base.ToString()} (Note Off)";
			}
			return string.Format("{0} Len: {1}", base.ToString(), (OffEvent == null) ? "?" : NoteLength.ToString());
		}
	}
	public class PatchChangeEvent : MidiEvent
	{
		private byte patch;

		private static readonly string[] patchNames = new string[128]
		{
			"Acoustic Grand", "Bright Acoustic", "Electric Grand", "Honky-Tonk", "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clav", "Celesta", "Glockenspiel",
			"Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ", "Percussive Organ", "Rock Organ", "Church Organ",
			"Reed Organ", "Accoridan", "Harmonica", "Tango Accordian", "Acoustic Guitar(nylon)", "Acoustic Guitar(steel)", "Electric Guitar(jazz)", "Electric Guitar(clean)", "Electric Guitar(muted)", "Overdriven Guitar",
			"Distortion Guitar", "Guitar Harmonics", "Acoustic Bass", "Electric Bass(finger)", "Electric Bass(pick)", "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2",
			"Violin", "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Strings", "Timpani", "String Ensemble 1", "String Ensemble 2",
			"SynthStrings 1", "SynthStrings 2", "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba", "Muted Trumpet",
			"French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax", "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn",
			"Bassoon", "Clarinet", "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Skakuhachi", "Whistle", "Ocarina",
			"Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)", "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)", "Pad 2 (warm)",
			"Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)", "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)", "FX 4 (atmosphere)",
			"FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)", "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bagpipe",
			"Fiddle", "Shanai", "Tinkle Bell", "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
			"Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter", "Applause", "Gunshot"
		};

		public int Patch
		{
			get
			{
				return patch;
			}
			set
			{
				if (value < 0 || value > 127)
				{
					throw new ArgumentOutOfRangeException("value", "Patch number must be in the range 0-127");
				}
				patch = (byte)value;
			}
		}

		public static string GetPatchName(int patchNumber)
		{
			return patchNames[patchNumber];
		}

		public PatchChangeEvent(BinaryReader br)
		{
			patch = br.ReadByte();
			if ((patch & 0x80) != 0)
			{
				throw new FormatException("Invalid patch");
			}
		}

		public PatchChangeEvent(long absoluteTime, int channel, int patchNumber)
			: base(absoluteTime, channel, MidiCommandCode.PatchChange)
		{
			Patch = patchNumber;
		}

		public override string ToString()
		{
			return $"{base.ToString()} {GetPatchName(patch)}";
		}

		public override int GetAsShortMessage()
		{
			return base.GetAsShortMessage() + (patch << 8);
		}

		public override void Export(ref long absoluteTime, BinaryWriter writer)
		{
			base.Export(ref absoluteTime, writer);
			writer.Write(patch);
		}
	}
	public class PitchWheelChangeEvent : MidiEvent
	{
		private int pitch;

		public int Pitch
		{
			get
			{
				return pitch;
			}
			set
			{
				if (value < 0 || value >= 16384)
				{
					throw new ArgumentOutOfRangeException("value", "Pitch value must be in the range 0 - 0x3FFF");
				}
				pitch = value;
			}
		}

		public PitchWheelChangeEvent(BinaryReader br)
		{
			byte b = br.ReadByte();
			byte b2 = br.ReadByte();
			if ((b & 0x80) != 0)
			{
				throw new FormatException("Invalid pitchwheelchange byte 1");
			}
			if ((b2 & 0x80) != 0)
			{
				throw new FormatException("Invalid pitchwheelchange byte 2");
			}
			pitch = b + (b2 << 7);
		}

		public PitchWheelChangeEvent(long absoluteTime, int channel, int pitchWheel)
			: base(absoluteTime, channel, MidiCommandCode.PitchWheelChange)
		{
			Pitch = pitchWheel;
		}

		public override string ToString()
		{
			return $"{base.ToString()} Pitch {pitch} ({pitch - 8192})";
		}

		public override int GetAsShortMessage()
		{
			return base.GetAsShortMessage() + ((pitch & 0x7F) << 8) + (((pitch >> 7) & 0x7F) << 16);
		}

		public override void Export(ref long absoluteTime, BinaryWriter writer)
		{
			base.Export(ref absoluteTime, writer);
			writer.Write((byte)(pitch & 0x7F));
			writer.Write((byte)((pitch >> 7) & 0x7F));
		}
	}
	public class RawMetaEvent : MetaEvent
	{
		public byte[] Data { get; set; }

		public RawMetaEvent(MetaEventType metaEventType, long absoluteTime, byte[] data)
			: base(metaEventType, (data != null) ? data.Length : 0, absoluteTime)
		{
			Data = data;
		}

		public override MidiEvent Clone()
		{
			return new RawMetaEvent(base.MetaEventType, base.AbsoluteTime, (byte[])Data?.Clone());
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder().Append(base.ToString());
			byte[] data = Data;
			foreach (byte b in data)
			{
				stringBuilder.AppendFormat(" {0:X2}", b);
			}
			return stringBuilder.ToString();
		}

		public override void Export(ref long absoluteTime, BinaryWriter writer)
		{
			base.Export(ref absoluteTime, writer);
			if (Data != null)
			{
				writer.Write(Data, 0, Data.Length);
			}
		}
	}
	public class SequencerSpecificEvent : MetaEvent
	{
		private byte[] data;

		public byte[] Data
		{
			get
			{
				return data;
			}
			set
			{
				data = value;
				metaDataLength = data.Length;
			}
		}

		public SequencerSpecificEvent(BinaryReader br, int length)
		{
			data = br.ReadBytes(length);
		}

		public SequencerSpecificEvent(byte[] data, long absoluteTime)
			: base(MetaEventType.SequencerSpecific, data.Length, absoluteTime)
		{
			this.data = data;
		}

		public override MidiEvent Clone()
		{
			return new SequencerSpecificEvent((byte[])data.Clone(), base.AbsoluteTime);
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(base.ToString());
			stringBuilder.Append(" ");
			byte[] array = data;
			foreach (byte b in array)
			{
				stringBuilder.AppendFormat("{0:X2} ", b);
			}
			stringBuilder.Length--;
			return stringBuilder.ToString();
		}

		public override void Export(ref long absoluteTime, BinaryWriter writer)
		{
			base.Export(ref absoluteTime, writer);
			writer.Write(data);
		}
	}
	public class SmpteOffsetEvent : MetaEvent
	{
		private readonly byte hours;

		private readonly byte minutes;

		private readonly byte seconds;

		private readonly byte frames;

		private readonly byte subFrames;

		public int Hours => hours;

		public int Minutes => minutes;

		public i

plugins/Wish-Victor/Wish.Victor.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using EntityStates;
using Microsoft.CodeAnalysis;
using NAudio.Wave;
using NAudio.Wave.SampleProviders;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.ConVar;
using RoR2.ContentManagement;
using RoR2.Skills;
using RoR2.UI;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Wish.Victor.Native;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyVersion("0.0.0.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;
		}
	}
}
public sealed class NativeRopePlayer : MonoBehaviour
{
	public string DefinitionName = "frank_shock_projectile_trail";

	public float SourceUnit = 0.0254f;

	public float EmissionSeconds = 0.2f;

	public float TravelMetres = 28f;

	public int Seed = 123;

	private Simulation simulation;

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

	private readonly List<Material> materials = new List<Material>();

	private readonly List<Data> renderers = new List<Data>();

	private Vector3 origin;

	private Vector3 direction;

	private float accumulator;

	public bool Finished { get; private set; }

	public void Begin(string name, Vector3 start, Vector3 forward, int seed)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: 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)
		DefinitionName = name;
		origin = start;
		direction = ((Vector3)(ref forward)).normalized;
		Seed = seed;
		Initialize();
	}

	public void SetSourceGraph(Data graphs, string name, Vector3 start, Vector3 forward, int seed)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: 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)
		DefinitionName = name;
		origin = start;
		direction = ((Vector3)(ref forward)).normalized;
		Seed = seed;
		Initialize(graphs);
	}

	private void Initialize(Data graphs = null)
	{
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Expected O, but got Unknown
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f6: Expected O, but got Unknown
		if (simulation != null)
		{
			throw new InvalidOperationException("Player already initialized");
		}
		if (graphs == null)
		{
			TextAsset val = Resources.Load<TextAsset>("VictorNative/native-graphs");
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new FileNotFoundException("Original native graph data missing");
			}
			using MemoryStream stream = new MemoryStream(val.bytes);
			graphs = Data.Load(stream);
		}
		string text = "particles/abilities/frank/" + DefinitionName + ".vpcf";
		simulation = new Simulation(text, graphs[text], Seed);
		V3 normalized = ToSource(direction).Normalized;
		simulation.Context.Forward = normalized;
		simulation.Context.Left = V3.Cross(new V3(0f, 0f, 1f), normalized).Normalized;
		if (simulation.Context.Left.Length < 0.01f)
		{
			simulation.Context.Left = V3.Cross(new V3(0f, 1f, 0f), normalized).Normalized;
		}
		simulation.Context.Up = V3.Cross(normalized, simulation.Context.Left).Normalized;
		foreach (Data item in simulation.Definition["m_Renderers"].Items)
		{
			if (item.S("_class") != "C_OP_RenderRopes")
			{
				throw new NotSupportedException(item.S("_class"));
			}
			if (item["m_vecTexturesInput"].Count != 1)
			{
				throw new NotSupportedException("Multilayer spritecard needs the next shader adapter");
			}
			string text2 = item.S("m_nOrientationType", "PARTICLE_ORIENTATION_SCREEN_ALIGNED");
			if (text2 != "PARTICLE_ORIENTATION_SCREEN_ALIGNED")
			{
				throw new NotSupportedException("Rope orientation: " + text2);
			}
			Shader val2 = (Object.op_Implicit((Object)(object)NativeAssets.OutputShader) ? NativeAssets.OutputShader : Shader.Find("Wish/VictorNativeRope"));
			if (!Object.op_Implicit((Object)(object)val2))
			{
				throw new InvalidOperationException("Native rope shader is not compiled");
			}
			Data data = item["m_vecTexturesInput"][0];
			string text3 = data.S("m_hTexture");
			Texture2D val3 = NativeAssets.Texture("VictorNative/" + Path.GetFileNameWithoutExtension(text3));
			if (!Object.op_Implicit((Object)(object)val3))
			{
				throw new FileNotFoundException(text3);
			}
			Material val4 = new Material(val2);
			val4.mainTexture = (Texture)(object)val3;
			string text4 = item.S("m_nOutputBlendMode", "PARTICLE_OUTPUT_BLEND_MODE_ALPHA");
			val4.SetFloat("_SrcBlend", 1f);
			if (text4 == "PARTICLE_OUTPUT_BLEND_MODE_ADD")
			{
				val4.SetFloat("_DstBlend", 1f);
			}
			else
			{
				if (!(text4 == "PARTICLE_OUTPUT_BLEND_MODE_ALPHA"))
				{
					throw new NotSupportedException("Output blend " + text4);
				}
				val4.SetFloat("_DstBlend", 10f);
			}
			val4.SetFloat("_RgbAlpha", (float)((data.S("m_nTextureChannels") == "SPRITECARD_TEXTURE_CHANNEL_MIX_RGBA_RGBALPHA") ? 1 : 0));
			val4.SetFloat("_Saturate", (float)(item.B("m_bSaturateColorPreAlphaBlend", fallback: true) ? 1 : 0));
			materials.Add(val4);
			renderers.Add(item);
			Mesh val5 = new Mesh
			{
				name = DefinitionName + " native rope"
			};
			val5.MarkDynamic();
			meshes.Add(val5);
		}
	}

	private void Update()
	{
		//IL_0074: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: 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)
		if (simulation == null || Finished)
		{
			return;
		}
		try
		{
			accumulator += Time.deltaTime;
			while (accumulator >= 1f / 120f)
			{
				float age = simulation.Context.Age;
				simulation.Emitting = age < EmissionSeconds;
				simulation.Endcap = !simulation.Emitting;
				Vector3 v = origin + direction * (TravelMetres * Mathf.Clamp01((age + 1f / 120f) / EmissionSeconds));
				simulation.Step(1f / 120f, ToSource(v));
				accumulator -= 1f / 120f;
			}
			for (int i = 0; i < meshes.Count; i++)
			{
				Draw(i);
			}
			Finished = !simulation.Emitting && simulation.Particles.Count == 0;
		}
		catch (Exception ex)
		{
			Debug.LogException(ex);
			Finished = true;
			((Behaviour)this).enabled = false;
		}
	}

	private void Draw(int pass)
	{
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0306: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_030f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_033d: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_052b: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_037d: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0411: Unknown result type (might be due to invalid IL or missing references)
		//IL_0416: Unknown result type (might be due to invalid IL or missing references)
		//IL_046f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0471: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_0474: Unknown result type (might be due to invalid IL or missing references)
		//IL_0479: Unknown result type (might be due to invalid IL or missing references)
		//IL_047b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03be: 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_03c5: Unknown result type (might be due to invalid IL or missing references)
		List<Particle> particles = simulation.Particles;
		Mesh val = meshes[pass];
		Data data = renderers[pass];
		if (particles.Count < 2)
		{
			val.Clear();
			return;
		}
		InputContext context = simulation.Context;
		Inputs inputs = simulation.Inputs;
		context.Particle = null;
		Material val2 = materials[pass];
		if (inputs.Scalar(data["m_flDiffuseAmount"], context, 1f) != 0f)
		{
			throw new NotSupportedException("Lit rope: no scene-light adapter yet");
		}
		val2.SetFloat("_SelfIllum", inputs.Scalar(data["m_flSelfIllumAmount"], context));
		val2.SetFloat("_Overbright", inputs.Scalar(data["m_flOverbrightFactor"], context, 1f));
		val2.SetFloat("_AddSelf", inputs.Scalar(data["m_flAddSelfAmount"], context));
		V3 b = inputs.Vector(data["m_vecColorScale"], context, new V3(1f, 1f, 1f));
		float num = inputs.Scalar(data["m_flRadiusScale"], context, 1f);
		float num2 = Math.Max(0.001f, inputs.Scalar(data["m_flTextureVWorldSize"], context, 200f));
		Data data2 = data["m_vecTexturesInput"][0]["m_TextureControls"];
		float num3 = inputs.Scalar(data2["m_flFinalTextureScaleU"], context, 1f);
		float num4 = inputs.Scalar(data2["m_flFinalTextureScaleV"], context, 1f);
		float num5 = inputs.Scalar(data2["m_flFinalTextureOffsetU"], context);
		float num6 = inputs.Scalar(data2["m_flFinalTextureOffsetV"], context);
		if (data2.Has("m_flFinalTextureUVRotation"))
		{
			throw new NotSupportedException("UV rotation not implemented");
		}
		Vector3[] array = (Vector3[])(object)new Vector3[particles.Count * 2];
		Vector2[] array2 = (Vector2[])(object)new Vector2[array.Length];
		Color[] array3 = (Color[])(object)new Color[array.Length];
		int[] array4 = new int[(particles.Count - 1) * 6];
		float num7 = 0f;
		Vector3 val3 = default(Vector3);
		Vector3 val4 = Vector3.zero;
		Camera main = Camera.main;
		if (!Object.op_Implicit((Object)(object)main))
		{
			return;
		}
		Color val10 = default(Color);
		for (int i = 0; i < particles.Count; i++)
		{
			Particle particle = particles[i];
			Vector3 val5 = ToUnity(particle.V[0]);
			Vector3 val6 = ToUnity(particles[Math.Max(0, i - 1)].V[0]);
			Vector3 val7 = ToUnity(particles[Math.Min(particles.Count - 1, i + 1)].V[0]);
			Vector3 val8 = val7 - val6;
			Vector3 normalized = ((Vector3)(ref val8)).normalized;
			val8 = ((Component)main).transform.position - val5;
			val8 = Vector3.Cross(normalized, ((Vector3)(ref val8)).normalized);
			Vector3 val9 = ((Vector3)(ref val8)).normalized;
			if (Vector3.Dot(val9, val4) < 0f)
			{
				val9 = -val9;
			}
			val4 = val9;
			float num8 = particle.S[3] * num * SourceUnit;
			array[i * 2] = val5 - val9 * num8;
			array[i * 2 + 1] = val5 + val9 * num8;
			if (i > 0)
			{
				float num9 = num7;
				val8 = val5 - val3;
				num7 = num9 + ((Vector3)(ref val8)).magnitude / SourceUnit;
			}
			val3 = val5;
			array2[i * 2] = new Vector2(num5, num7 / num2 * num4 + num6);
			array2[i * 2 + 1] = new Vector2(num3 + num5, num7 / num2 * num4 + num6);
			V3 v = V3.Mul(particle.V[6], b);
			((Color)(ref val10))..ctor(v.X, v.Y, v.Z, particle.S[7] * particle.S[16]);
			array3[i * 2] = (array3[i * 2 + 1] = val10);
			if (i < particles.Count - 1)
			{
				int num10 = i * 6;
				int num11 = (array4[num10] = i * 2);
				array4[num10 + 1] = num11 + 2;
				array4[num10 + 2] = num11 + 1;
				array4[num10 + 3] = num11 + 1;
				array4[num10 + 4] = num11 + 2;
				array4[num10 + 5] = num11 + 3;
			}
		}
		val.Clear();
		val.vertices = array;
		val.uv = array2;
		val.colors = array3;
		val.triangles = array4;
		val.RecalculateBounds();
		Graphics.DrawMesh(val, Matrix4x4.identity, val2, 0, (Camera)null, 0, (MaterialPropertyBlock)null, (ShadowCastingMode)0, false);
	}

	private V3 ToSource(Vector3 v)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		return new V3(v.z, 0f - v.x, v.y) / SourceUnit;
	}

	private Vector3 ToUnity(V3 v)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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)
		return new Vector3(0f - v.Y, v.Z, v.X) * SourceUnit;
	}

	private void OnDestroy()
	{
		foreach (Mesh mesh in meshes)
		{
			if (Object.op_Implicit((Object)(object)mesh))
			{
				Object.Destroy((Object)(object)mesh);
			}
		}
		foreach (Material material in materials)
		{
			if (Object.op_Implicit((Object)(object)material))
			{
				Object.Destroy((Object)(object)material);
			}
		}
	}
}
namespace Wish.Victor
{
	internal static class VictorAudio
	{
		private static readonly Dictionary<string, float[]> clips = new Dictionary<string, float[]>();

		private static readonly VictorPcmMixer mixer = new VictorPcmMixer();

		private static WaveOutEvent output;

		internal static string Status = "not loaded";

		internal static void Shutdown()
		{
			WaveOutEvent val = output;
			output = null;
			if (val == null)
			{
				return;
			}
			try
			{
				val.Stop();
				val.Dispose();
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("Victor audio shutdown: " + ex.Message));
			}
		}

		internal static void Load(string directory)
		{
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: 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_0311: Expected O, but got Unknown
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Expected O, but got Unknown
			if (!Directory.Exists(directory))
			{
				Status = "audio folder missing";
				return;
			}
			string[] files = Directory.GetFiles(directory, "*.wav");
			foreach (string path in files)
			{
				try
				{
					using BinaryReader binaryReader = new BinaryReader(File.OpenRead(path));
					if (new string(binaryReader.ReadChars(4)) != "RIFF")
					{
						throw new InvalidDataException("Not RIFF");
					}
					binaryReader.ReadInt32();
					if (new string(binaryReader.ReadChars(4)) != "WAVE")
					{
						throw new InvalidDataException("Not WAVE");
					}
					int num = 0;
					int num2 = 0;
					int num3 = 0;
					int num4 = 0;
					byte[] array = null;
					while (binaryReader.BaseStream.Position + 8 <= binaryReader.BaseStream.Length)
					{
						string text = new string(binaryReader.ReadChars(4));
						uint num5 = binaryReader.ReadUInt32();
						long num6 = binaryReader.BaseStream.Position + num5 + (num5 & 1);
						if (num6 > binaryReader.BaseStream.Length)
						{
							throw new InvalidDataException("Truncated WAV");
						}
						if (text == "fmt ")
						{
							num4 = binaryReader.ReadUInt16();
							num = binaryReader.ReadUInt16();
							num2 = binaryReader.ReadInt32();
							binaryReader.ReadInt32();
							binaryReader.ReadUInt16();
							num3 = binaryReader.ReadUInt16();
						}
						else if (text == "data")
						{
							array = binaryReader.ReadBytes(checked((int)num5));
						}
						binaryReader.BaseStream.Position = num6;
					}
					if (num4 != 1 || num3 != 16 || num != 1 || num2 != 44100 || array == null)
					{
						throw new InvalidDataException("Expected PCM16 WAV");
					}
					float[] array2 = new float[array.Length / 2];
					for (int j = 0; j < array2.Length; j++)
					{
						array2[j] = (float)(short)(array[j * 2] | (array[j * 2 + 1] << 8)) / 32768f;
					}
					clips[Path.GetFileNameWithoutExtension(path)] = array2;
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("Victor audio: " + Path.GetFileName(path) + ": " + ex.Message));
				}
			}
			Debug.Log((object)("Victor: loaded " + clips.Count + " original audio clips."));
			Status = clips.Count + " clips loaded";
			if (clips.Count == 0 || Application.isBatchMode || Environment.OSVersion.Platform != PlatformID.Win32NT)
			{
				return;
			}
			try
			{
				output = new WaveOutEvent
				{
					DesiredLatency = 80,
					NumberOfBuffers = 3
				};
				output.Init((IWaveProvider)new SampleToWaveProvider16((ISampleProvider)(object)mixer));
				output.Play();
				Status = clips.Count + " clips ready";
				Application.quitting += Shutdown;
			}
			catch (Exception ex2)
			{
				Shutdown();
				Status = "device error: " + ex2.Message;
				Debug.LogWarning((object)("Victor original audio unavailable: " + ex2.Message));
			}
		}

		internal static VictorAudioVoice Play(GameObject owner, string prefix, float volume = 0.65f, bool loop = false)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)owner) || output == null)
			{
				return null;
			}
			float[][] array = (from kv in clips
				where kv.Key.StartsWith(prefix, StringComparison.Ordinal)
				select kv.Value).ToArray();
			if (array.Length == 0)
			{
				return null;
			}
			GameObject val = new GameObject("Victor original audio " + prefix);
			val.transform.SetParent(owner.transform, false);
			VictorAudioVoice victorAudioVoice = val.AddComponent<VictorAudioVoice>();
			victorAudioVoice.Samples = array[Random.Range(0, array.Length)];
			victorAudioVoice.BaseVolume = volume;
			victorAudioVoice.Loop = loop;
			mixer.Add(victorAudioVoice);
			return victorAudioVoice;
		}

		internal static void Stop(ref VictorAudioVoice source)
		{
			if (Object.op_Implicit((Object)(object)source))
			{
				source.Stopped = true;
				Object.Destroy((Object)(object)((Component)source).gameObject);
			}
			source = null;
		}
	}
	internal sealed class VictorPcmMixer : ISampleProvider
	{
		private readonly List<VictorAudioVoice> voices = new List<VictorAudioVoice>();

		private readonly object gate = new object();

		public WaveFormat WaveFormat { get; } = WaveFormat.CreateIeeeFloatWaveFormat(44100, 2);

		internal void Add(VictorAudioVoice voice)
		{
			lock (gate)
			{
				voices.Add(voice);
			}
		}

		public int Read(float[] buffer, int offset, int count)
		{
			Array.Clear(buffer, offset, count);
			lock (gate)
			{
				for (int num = voices.Count - 1; num >= 0; num--)
				{
					VictorAudioVoice victorAudioVoice = voices[num];
					if (victorAudioVoice.Stopped)
					{
						voices.RemoveAt(num);
					}
					else
					{
						float left = victorAudioVoice.Left;
						float right = victorAudioVoice.Right;
						for (int i = 0; i + 1 < count; i += 2)
						{
							if (victorAudioVoice.Cursor >= victorAudioVoice.Samples.Length)
							{
								if (!victorAudioVoice.Loop)
								{
									victorAudioVoice.Stopped = true;
									break;
								}
								victorAudioVoice.Cursor = 0;
							}
							float num2 = victorAudioVoice.Samples[victorAudioVoice.Cursor++];
							buffer[offset + i] += num2 * left;
							buffer[offset + i + 1] += num2 * right;
						}
					}
				}
			}
			for (int j = offset; j < offset + count; j++)
			{
				buffer[j] = Math.Max(-1f, Math.Min(1f, buffer[j]));
			}
			return count;
		}
	}
	public sealed class VictorAudioVoice : MonoBehaviour
	{
		internal float[] Samples;

		internal int Cursor;

		internal float BaseVolume;

		internal bool Loop;

		internal bool Spatial = true;

		internal volatile bool Stopped;

		internal volatile float Left;

		internal volatile float Right;

		private static float gain = 1f;

		private static float nextVolumeCheck;

		private static readonly string[] VolumeSettings = new string[2] { "volume_master", "volume_sfx" };

		private void Update()
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			if (Stopped)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			if (Time.unscaledTime >= nextVolumeCheck)
			{
				nextVolumeCheck = Time.unscaledTime + 0.2f;
				gain = VictorPlugin.AudioVolume.Value;
				Console instance = Console.instance;
				if (Object.op_Implicit((Object)(object)instance))
				{
					string[] volumeSettings = VolumeSettings;
					foreach (string text in volumeSettings)
					{
						BaseConVar val = instance.FindConVar(text);
						if (val != null && float.TryParse(val.GetString(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
						{
							gain *= Mathf.Clamp01(result / 100f);
						}
					}
				}
			}
			Camera main = Camera.main;
			float num = Mathf.Clamp(gain, 0f, 2f) * BaseVolume;
			float num2 = 0f;
			if (Object.op_Implicit((Object)(object)main) && Spatial)
			{
				Vector3 val2 = ((Component)this).transform.position - ((Component)main).transform.position;
				num *= Mathf.Clamp01((45f - ((Vector3)(ref val2)).magnitude) / 41f);
				num2 = Vector3.Dot(((Component)main).transform.right, ((Vector3)(ref val2)).normalized) * 0.75f;
			}
			if (!Application.isFocused || (!Object.op_Implicit((Object)(object)main) && Spatial))
			{
				num = 0f;
			}
			Left = num * Mathf.Sqrt((1f - num2) * 0.5f);
			Right = num * Mathf.Sqrt((1f + num2) * 0.5f);
		}

		private void OnDestroy()
		{
			Stopped = true;
		}
	}
	public sealed class VictorAudioDriver : MonoBehaviour
	{
		private CharacterBody body;

		private VictorAudioVoice aura;

		private VictorAudioVoice recovery;

		private VictorAudioVoice speech;

		private float lastSpeechAt = -100f;

		private int lastSpeechPower = -1;

		private bool hadAura;

		private bool hadRecovery;

		private bool wasEmpty;

		private float previousReloadProgress = -1f;

		private void Start()
		{
			body = ((Component)this).GetComponent<CharacterBody>();
			speech = VictorAudio.Play(((Component)this).gameObject, "frank_select_", 0.6f);
		}

		internal void SayAbility(int power)
		{
			if (power != lastSpeechPower || !(Time.unscaledTime - lastSpeechAt < 0.2f))
			{
				lastSpeechAt = Time.unscaledTime;
				lastSpeechPower = power;
				VictorAudio.Stop(ref speech);
				speech = VictorAudio.Play(((Component)this).gameObject, "frank_use_power" + power + "_", 0.85f * Mathf.Clamp(VictorPlugin.AbilityVoiceVolume.Value, 0f, 2f));
			}
		}

		private void Update()
		{
			if (!Object.op_Implicit((Object)(object)body))
			{
				return;
			}
			bool flag = Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive;
			bool flag2 = flag && body.HasBuff(VictorPlugin.Aura) && !body.HasBuff(VictorPlugin.Reanimating);
			if (flag2 && !hadAura)
			{
				SayAbility(3);
				VictorAudio.Play(((Component)this).gameObject, "frank_pain_aura_cast_");
				aura = VictorAudio.Play(((Component)this).gameObject, "frank_pain_aura_lp_", 0.28f, loop: true);
			}
			if (!flag2 && hadAura)
			{
				VictorAudio.Stop(ref aura);
				if (flag)
				{
					VictorAudio.Play(((Component)this).gameObject, "frank_pain_aura_deactivate_");
				}
			}
			hadAura = flag2;
			bool flag3 = flag && body.HasBuff(VictorPlugin.Recovery);
			if (flag3 && !hadRecovery)
			{
				recovery = VictorAudio.Play(((Component)this).gameObject, "frank_jumpstart_buff_active_", 0.25f, loop: true);
			}
			if (!flag3 && hadRecovery)
			{
				VictorAudio.Stop(ref recovery);
				if (flag)
				{
					VictorAudio.Play(((Component)this).gameObject, "frank_jumpstart_buff_expire_");
				}
			}
			hadRecovery = flag3;
			GenericSkill val = (Object.op_Implicit((Object)(object)body.skillLocator) ? body.skillLocator.primary : null);
			bool flag4 = flag && Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.skillDef) && val.skillDef.skillName == "WishVictorPISTOL" && val.stock == 0;
			if (flag4 && !wasEmpty)
			{
				previousReloadProgress = -1f;
				VictorAudio.Play(((Component)this).gameObject, "frank_wpn_reload_start_");
			}
			if (flag4)
			{
				float num = Mathf.Max(0.1f, val.baseRechargeInterval * val.cooldownScale - val.flatCooldownReduction);
				float progress = Mathf.Clamp01(val.rechargeStopwatch / num);
				foreach (string item in VictorNativeAnimation.TaggedSounds("reload_idle", previousReloadProgress, progress))
				{
					string text = VictorNativeAnimation.SoundPrefix(item);
					if (text != null)
					{
						VictorAudio.Play(((Component)this).gameObject, text);
					}
				}
				if (VictorNativeEffects.ExtendedReady)
				{
					foreach (Data effect in VictorNativeAnimation.ParticleEvents("reload_idle", previousReloadProgress, progress))
					{
						VictorVfx.Safely(delegate
						{
							VictorNativeActor.CreateEvent(body, effect);
						});
					}
				}
				previousReloadProgress = progress;
			}
			if (!flag4 && wasEmpty && flag && Object.op_Implicit((Object)(object)val) && val.stock >= val.maxStock)
			{
				if (VictorNativeEffects.ExtendedReady)
				{
					foreach (Data effect2 in VictorNativeAnimation.ParticleEvents("reload_idle", previousReloadProgress, 1f))
					{
						VictorVfx.Safely(delegate
						{
							VictorNativeActor.CreateEvent(body, effect2);
						});
					}
				}
				foreach (string item2 in VictorNativeAnimation.TaggedSounds("reload_idle", previousReloadProgress, 1f))
				{
					string text2 = VictorNativeAnimation.SoundPrefix(item2);
					if (text2 != null)
					{
						VictorAudio.Play(((Component)this).gameObject, text2);
					}
				}
			}
			wasEmpty = flag4;
		}

		private void OnDisable()
		{
			VictorAudio.Stop(ref aura);
			VictorAudio.Stop(ref recovery);
			VictorAudio.Stop(ref speech);
			hadAura = (hadRecovery = (wasEmpty = false));
		}
	}
	public sealed class VictorMenuVoice : MonoBehaviour
	{
		private VictorAudioVoice speech;

		private bool played;

		private void OnEnable()
		{
			played = false;
		}

		private void Update()
		{
			//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)
			if (played)
			{
				return;
			}
			Scene scene = ((Component)this).gameObject.scene;
			if (!(((Scene)(ref scene)).name != "lobby"))
			{
				played = true;
				speech = VictorAudio.Play(((Component)this).gameObject, "frank_select_", 0.8f);
				if (Object.op_Implicit((Object)(object)speech))
				{
					speech.Spatial = false;
				}
			}
		}

		private void OnDisable()
		{
			VictorAudio.Stop(ref speech);
		}
	}
	internal sealed class VictorAuraMist : IDisposable
	{
		private const int Count = 24;

		private readonly Mesh mesh;

		private readonly Material material;

		private readonly Texture2D texture;

		private readonly Vector3[] vertices = (Vector3[])(object)new Vector3[96];

		private readonly Color[] colors = (Color[])(object)new Color[96];

		private static readonly string[] Anchors = new string[6] { "spine_1", "spine_2", "arm_upper_L", "arm_upper_R", "hand_L", "hand_R" };

		internal VictorAuraMist()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Expected O, but got Unknown
			//IL_0109: 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_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			texture = new Texture2D(64, 64, (TextureFormat)4, false, true)
			{
				name = "Victor soft irregular mist",
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = (float)j / 63f;
					float num2 = (float)i / 63f;
					float num3 = (num - 0.5f) * 2f;
					float num4 = (num2 - 0.5f) * 2f;
					float num5 = Mathf.Clamp01(1f - num3 * num3 - num4 * num4);
					float num6 = 0.55f + 0.45f * Mathf.PerlinNoise(num * 4.7f + 3.1f, num2 * 5.3f + 8.2f);
					array[i * 64 + j] = new Color(1f, 1f, 1f, num5 * num5 * num5 * num6);
				}
			}
			texture.SetPixels(array);
			texture.Apply(false, true);
			material = new Material(NativeAssets.OutputShader)
			{
				name = "Victor faint body mist",
				mainTexture = (Texture)(object)texture,
				renderQueue = 3009
			};
			material.SetFloat("_SrcBlend", 1f);
			material.SetFloat("_DstBlend", 1f);
			material.SetFloat("_SelfIllum", 1f);
			material.SetFloat("_Overbright", 1f);
			material.SetFloat("_AddSelf", 0f);
			material.SetFloat("_Saturate", 0f);
			material.SetFloat("_RgbAlpha", 0f);
			mesh = new Mesh
			{
				name = "Victor body mist wisps"
			};
			mesh.MarkDynamic();
			Vector2[] array2 = (Vector2[])(object)new Vector2[96];
			int[] array3 = new int[144];
			for (int k = 0; k < 24; k++)
			{
				int num7 = k * 4;
				int num8 = k * 6;
				array2[num7] = new Vector2(0f, 0f);
				array2[num7 + 1] = new Vector2(1f, 0f);
				array2[num7 + 2] = new Vector2(0f, 1f);
				array2[num7 + 3] = new Vector2(1f, 1f);
				array3[num8] = num7;
				array3[num8 + 1] = num7 + 2;
				array3[num8 + 2] = num7 + 1;
				array3[num8 + 3] = num7 + 1;
				array3[num8 + 4] = num7 + 2;
				array3[num8 + 5] = num7 + 3;
			}
			mesh.vertices = vertices;
			mesh.uv = array2;
			mesh.triangles = array3;
		}

		internal void Draw(Camera camera, Func<string, Transform> anchor, Transform owner, float opacity)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//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_02a2: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_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_012d: 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_013a: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: 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_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: 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_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_01b2: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: 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 right = ((Component)camera).transform.right;
			Vector3 up = ((Component)camera).transform.up;
			Vector3 val2 = default(Vector3);
			Color val6 = default(Color);
			for (int i = 0; i < 24; i++)
			{
				Transform val = anchor(Anchors[i % Anchors.Length]);
				float num = Mathf.Repeat(Time.time * 0.27f + (float)i * 0.618034f, 1f);
				float num2 = (float)i * 2.399963f + Time.time * 0.22f;
				float num3 = Mathf.Sin(num * (float)Math.PI);
				num3 *= num3;
				((Vector3)(ref val2))..ctor(Mathf.Cos(num2) * 0.18f, (num - 0.4f) * 0.55f, Mathf.Sin(num2) * 0.16f);
				Vector3 val3 = (Object.op_Implicit((Object)(object)val) ? val.position : owner.position) + owner.rotation * val2;
				float num4 = 0.24f + 0.045f * Mathf.Sin((float)i * 1.7f);
				float num5 = 0.35f + 0.08f * Mathf.Sin((float)i * 2.3f);
				float num6 = 0.25f * Mathf.Sin(Time.time * 0.5f + (float)i);
				Vector3 val4 = (right * Mathf.Cos(num6) + up * Mathf.Sin(num6)) * num4;
				Vector3 val5 = (-right * Mathf.Sin(num6) + up * Mathf.Cos(num6)) * num5;
				int num7 = i * 4;
				vertices[num7] = val3 - val4 - val5;
				vertices[num7 + 1] = val3 + val4 - val5;
				vertices[num7 + 2] = val3 - val4 + val5;
				vertices[num7 + 3] = val3 + val4 + val5;
				((Color)(ref val6))..ctor(0.12f, 0.65f, 0.055f, Object.op_Implicit((Object)(object)val) ? (0.075f * num3 * opacity) : 0f);
				for (int j = 0; j < 4; j++)
				{
					colors[num7 + j] = val6;
				}
			}
			mesh.vertices = vertices;
			mesh.colors = colors;
			mesh.RecalculateBounds();
			Graphics.DrawMesh(mesh, Matrix4x4.identity, material, LayerIndex.defaultLayer.intVal, camera, 0, (MaterialPropertyBlock)null, (ShadowCastingMode)0, false);
		}

		public void Dispose()
		{
			Object.Destroy((Object)(object)mesh);
			Object.Destroy((Object)(object)material);
			Object.Destroy((Object)(object)texture);
		}
	}
	[DefaultExecutionOrder(10000)]
	public sealed class VictorBatteryIcon : MonoBehaviour
	{
		private SkillIcon icon;

		private Image fill;

		private float shown;

		private float chargeVelocity;

		private float previousCharge;

		private CharacterBody displayedBody;

		private bool tinted;

		private Color previousColor;

		private void Awake()
		{
			icon = ((Component)this).GetComponent<SkillIcon>();
		}

		private void LateUpdate()
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: 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_0351: Unknown result type (might be due to invalid IL or missing references)
			GenericSkill val = (Object.op_Implicit((Object)(object)icon) ? icon.targetSkill : null);
			CharacterBody val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<CharacterBody>() : null);
			VictorController victorController = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<VictorController>() : null);
			if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)victorController) || (Object)(object)val != (Object)(object)val2.skillLocator.secondary)
			{
				Restore();
			}
			else if (Object.op_Implicit((Object)(object)icon.iconImage))
			{
				if (!Object.op_Implicit((Object)(object)fill))
				{
					GameObject val3 = new GameObject("VictorBatteryIconFill", new Type[3]
					{
						typeof(RectTransform),
						typeof(CanvasRenderer),
						typeof(Image)
					});
					val3.transform.SetParent(((Component)icon.iconImage).transform, false);
					fill = val3.GetComponent<Image>();
					((Graphic)fill).raycastTarget = false;
				}
				if ((Object)(object)displayedBody != (Object)(object)val2)
				{
					shown = 0f;
					chargeVelocity = 0f;
					previousCharge = 0f;
					displayedBody = val2;
				}
				float num = Mathf.Clamp01(victorController.ChargeFraction);
				if (num == 0f && previousCharge > 0f)
				{
					shown = 0f;
					chargeVelocity = 0f;
				}
				else
				{
					shown = Mathf.SmoothDamp(shown, num, ref chargeVelocity, 0.16f, float.PositiveInfinity, Time.unscaledDeltaTime);
				}
				previousCharge = num;
				bool flag = val2.GetBuffCount(VictorPlugin.Charge) >= 20;
				if (flag && 1f - shown < 0.001f)
				{
					shown = 1f;
				}
				previousColor = ((Graphic)icon.iconImage).color;
				tinted = true;
				((Graphic)icon.iconImage).color = new Color(0.22f, 0.25f, 0.23f, previousColor.a);
				fill.sprite = icon.iconImage.sprite;
				fill.type = (Type)3;
				fill.fillMethod = (FillMethod)1;
				fill.fillOrigin = 0;
				fill.preserveAspect = icon.iconImage.preserveAspect;
				fill.fillAmount = shown;
				((Graphic)fill).color = (flag ? new Color(0.65f, 1f, 0.72f, previousColor.a) : new Color(0.7f, 0.92f, 0.78f, previousColor.a));
				RectTransform rectTransform = ((Graphic)fill).rectTransform;
				rectTransform.anchorMin = Vector2.zero;
				rectTransform.anchorMax = Vector2.one;
				Vector2 offsetMin = (rectTransform.offsetMax = Vector2.zero);
				rectTransform.offsetMin = offsetMin;
				((Behaviour)fill).enabled = shown > 0f;
			}
		}

		private void Restore()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)fill))
			{
				((Behaviour)fill).enabled = false;
			}
			if (tinted && Object.op_Implicit((Object)(object)icon) && Object.op_Implicit((Object)(object)icon.iconImage))
			{
				((Graphic)icon.iconImage).color = previousColor;
			}
			tinted = false;
			shown = 0f;
			chargeVelocity = 0f;
			previousCharge = 0f;
			displayedBody = null;
		}

		private void OnDisable()
		{
			Restore();
		}

		private void OnDestroy()
		{
			Restore();
			if (Object.op_Implicit((Object)(object)fill))
			{
				Object.Destroy((Object)(object)((Component)fill).gameObject);
			}
		}
	}
	public sealed class VictorHybridEffects : MonoBehaviour
	{
		private CharacterBody body;

		private VictorVisual visual;

		private VictorNativeAttachments sockets;

		private VictorReanimationDriver revive;

		private Dictionary<string, Transform> bones;

		private Material material;

		private VictorAuraMist mist;

		private float mistOpacity;

		private readonly List<LineRenderer> arcs = new List<LineRenderer>();

		private readonly Vector3[] points = (Vector3[])(object)new Vector3[6];

		private static readonly string[] AuraA = new string[6] { "shoulder_bolt_l_fx", "shoulder_bolt_l_fx", "forearm_bolt_l_fx", "shoulder_bolt_r_fx", "spine_1", "forearm_bolt_l_fx" };

		private static readonly string[] AuraB = new string[6] { "shoulder_bolt_r_fx", "forearm_bolt_l_fx", "hand_L", "spine_2", "arm_upper_L", "spine_1" };

		private static readonly string[] ReviveA = new string[16]
		{
			"chest_upper_fx", "chest_upper_fx", "chest_lower_fx", "pelvis_upper_fx", "pelvis_upper_fx", "neck_fx", "l_arm_upper_fx", "r_arm_upper_fx", "l_arm_lower_fx", "r_arm_lower_fx",
			"l_boot_upper_fx", "r_boot_upper_fx", "neck_fx", "chest_lower_fx", "chest_upper_fx", "pelvis_upper_fx"
		};

		private static readonly string[] ReviveB = new string[16]
		{
			"l_arm_upper_fx", "r_arm_upper_fx", "pelvis_upper_fx", "l_boot_upper_fx", "r_boot_upper_fx", "chest_upper_fx", "l_arm_lower_fx", "r_arm_lower_fx", "l_hand_fx", "chest_upper_fx",
			"l_boot_lower_fx", "r_boot_lower_fx", "l_hand_fx", "r_arm_upper_fx", "l_boot_upper_fx", "r_arm_lower_fx"
		};

		private void OnEnable()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Camera.onPreCull = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(BeforeCamera));
		}

		private void OnDisable()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Camera.onPreCull = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(BeforeCamera));
			Hide();
		}

		private void Start()
		{
			body = ((Component)this).GetComponent<CharacterBody>();
			revive = ((Component)this).GetComponent<VictorReanimationDriver>();
		}

		private bool Bind()
		{
			//IL_0109: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Expected O, but got Unknown
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Expected O, but got Unknown
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)body) || !VictorNativeEffects.ExtendedReady)
			{
				return false;
			}
			VictorVisual victorVisual = ((Component)body).GetComponent<VictorController>()?.Visual;
			if (!Object.op_Implicit((Object)(object)victorVisual))
			{
				return false;
			}
			if ((Object)(object)victorVisual != (Object)(object)visual)
			{
				visual = victorVisual;
				sockets = ((Component)visual).GetComponent<VictorNativeAttachments>();
				bones = new Dictionary<string, Transform>();
				Transform[] componentsInChildren = ((Component)visual).GetComponentsInChildren<Transform>(true);
				foreach (Transform val in componentsInChildren)
				{
					if (!bones.ContainsKey(((Object)val).name))
					{
						bones.Add(((Object)val).name, val);
					}
				}
			}
			if (Object.op_Implicit((Object)(object)material))
			{
				return true;
			}
			mist = new VictorAuraMist();
			material = new Material(NativeAssets.OutputShader)
			{
				name = "Victor hybrid green spark",
				renderQueue = 3010
			};
			material.mainTexture = (Texture)(object)NativeAssets.TextureResolver("VictorNative/bendibeam_mono");
			material.SetFloat("_SrcBlend", 1f);
			material.SetFloat("_DstBlend", 1f);
			material.SetFloat("_SelfIllum", 1f);
			material.SetFloat("_Overbright", 1.2f);
			material.SetFloat("_AddSelf", 0f);
			material.SetFloat("_Saturate", 0f);
			material.SetFloat("_RgbAlpha", 1f);
			for (int j = 0; j < 16; j++)
			{
				GameObject val2 = new GameObject("Victor attached spark " + j);
				val2.transform.SetParent(((Component)this).transform, false);
				val2.layer = LayerIndex.defaultLayer.intVal;
				LineRenderer val3 = val2.AddComponent<LineRenderer>();
				((Renderer)val3).sharedMaterial = material;
				val3.useWorldSpace = true;
				val3.positionCount = points.Length;
				val3.textureMode = (LineTextureMode)0;
				val3.alignment = (LineAlignment)0;
				val3.numCornerVertices = 1;
				val3.numCapVertices = 0;
				((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)val3).receiveShadows = false;
				val3.widthCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[4]
				{
					new Keyframe(0f, 0f),
					new Keyframe(0.18f, 1f),
					new Keyframe(0.78f, 0.75f),
					new Keyframe(1f, 0f)
				});
				val3.startColor = new Color(0.22f, 1f, 0.12f, 0.75f);
				val3.endColor = new Color(0.36f, 1f, 0.18f, 0.55f);
				((Renderer)val3).enabled = false;
				arcs.Add(val3);
			}
			return true;
		}

		private Transform Anchor(string name, bool reanimating)
		{
			if (reanimating)
			{
				return Object.op_Implicit((Object)(object)revive) ? revive.EffectAnchor(name) : null;
			}
			Transform val = (Object.op_Implicit((Object)(object)sockets) ? sockets.Find(name) : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				return val;
			}
			Transform value;
			return (bones != null && bones.TryGetValue(name, out value)) ? value : null;
		}

		private static float Noise(int tick, int arc, int point, int axis)
		{
			float num = Mathf.Sin((float)tick * 12.9898f + (float)arc * 78.233f + (float)point * 19.191f + (float)axis * 34.71f) * 43758.547f;
			return Mathf.Repeat(num, 1f) * 2f - 1f;
		}

		private void BeforeCamera(Camera camera)
		{
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: 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_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: 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)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: 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_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)camera != (Object)(object)Camera.main || !Object.op_Implicit((Object)(object)body))
			{
				return;
			}
			bool flag = body.HasBuff(VictorPlugin.Reanimating);
			bool flag2 = body.HasBuff(VictorPlugin.Aura);
			mistOpacity = Mathf.MoveTowards(mistOpacity, (float)((flag2 && !flag) ? 1 : 0), Time.deltaTime * 4f);
			if ((!flag && !flag2 && mistOpacity <= 0f) || !Bind())
			{
				Hide();
				return;
			}
			if (Object.op_Implicit((Object)(object)sockets))
			{
				sockets.RefreshPose();
			}
			if (mistOpacity > 0f)
			{
				mist.Draw(camera, (string name) => Anchor(name, reanimating: false), ((Component)visual).transform, mistOpacity);
			}
			int num = Mathf.FloorToInt(Time.time * 18f);
			int num2 = (flag ? 16 : 6);
			for (int num3 = 0; num3 < arcs.Count; num3++)
			{
				LineRenderer val = arcs[num3];
				if (!(flag || flag2) || num3 >= num2 || !(flag ? ((num + num3 * 3) % 5 < 3) : ((num + num3) % 6 < 2)))
				{
					((Renderer)val).enabled = false;
					continue;
				}
				Transform val2 = Anchor(flag ? ReviveA[num3] : AuraA[num3], flag);
				Transform val3 = Anchor(flag ? ReviveB[num3] : AuraB[num3], flag);
				if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val3) || (Object)(object)val2 == (Object)(object)val3)
				{
					((Renderer)val).enabled = false;
					continue;
				}
				Vector3 position = val2.position;
				Vector3 position2 = val3.position;
				Vector3 val4 = position2 - position;
				Vector3 normalized = ((Vector3)(ref val4)).normalized;
				val4 = Vector3.Cross(normalized, Vector3.up);
				Vector3 val5 = ((Vector3)(ref val4)).normalized;
				if (((Vector3)(ref val5)).sqrMagnitude < 0.01f)
				{
					val5 = Vector3.right;
				}
				val4 = Vector3.Cross(val5, normalized);
				Vector3 normalized2 = ((Vector3)(ref val4)).normalized;
				float num4 = Vector3.Distance(position, position2);
				float num5 = Mathf.Min(flag ? 0.16f : 0.075f, num4 * 0.22f);
				for (int num6 = 0; num6 < points.Length; num6++)
				{
					float num7 = (float)num6 / (float)(points.Length - 1);
					float num8 = Mathf.Sin(num7 * (float)Math.PI);
					points[num6] = Vector3.Lerp(position, position2, num7) + (val5 * Noise(num, num3, num6, 0) + normalized2 * Noise(num, num3, num6, 1)) * num5 * num8;
				}
				val.widthMultiplier = (flag ? 0.032f : 0.012f);
				val.SetPositions(points);
				((Renderer)val).enabled = true;
			}
		}

		private void Hide()
		{
			foreach (LineRenderer arc in arcs)
			{
				if (Object.op_Implicit((Object)(object)arc))
				{
					((Renderer)arc).enabled = false;
				}
			}
		}

		private void OnDestroy()
		{
			if (mist != null)
			{
				mist.Dispose();
			}
			foreach (LineRenderer arc in arcs)
			{
				if (Object.op_Implicit((Object)(object)arc))
				{
					Object.Destroy((Object)(object)((Component)arc).gameObject);
				}
			}
			if (Object.op_Implicit((Object)(object)material))
			{
				Object.Destroy((Object)(object)material);
			}
		}
	}
	internal sealed class VictorMotionClip
	{
		public string Name;

		public float Duration;

		public int Frames;

		public float[] Values;
	}
	internal static class VictorMotionLibrary
	{
		internal static string[] Bones;

		internal static readonly Dictionary<string, VictorMotionClip> Clips = new Dictionary<string, VictorMotionClip>();

		internal static bool Ready => Bones != null && Clips.Count > 0;

		internal static void Load(string filename)
		{
			using BinaryReader binaryReader = new BinaryReader(File.OpenRead(filename));
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(8)) != "VICMOT01")
			{
				throw new InvalidDataException("Invalid Victor motion file.");
			}
			int num = binaryReader.ReadInt32();
			if (num < 1 || num > 2048)
			{
				throw new InvalidDataException("Invalid bone count.");
			}
			Bones = new string[num];
			for (int i = 0; i < num; i++)
			{
				Bones[i] = binaryReader.ReadString();
			}
			int num2 = binaryReader.ReadInt32();
			if (num2 < 1 || num2 > 512)
			{
				throw new InvalidDataException("Invalid clip count.");
			}
			Clips.Clear();
			for (int j = 0; j < num2; j++)
			{
				VictorMotionClip victorMotionClip = new VictorMotionClip
				{
					Name = binaryReader.ReadString(),
					Duration = binaryReader.ReadSingle(),
					Frames = binaryReader.ReadInt32()
				};
				if (victorMotionClip.Duration < 0f || victorMotionClip.Frames < 2 || victorMotionClip.Frames > 10000)
				{
					throw new InvalidDataException("Invalid motion clip.");
				}
				victorMotionClip.Values = new float[victorMotionClip.Frames * num * 10];
				byte[] array = binaryReader.ReadBytes(victorMotionClip.Values.Length * 4);
				if (array.Length != victorMotionClip.Values.Length * 4)
				{
					throw new EndOfStreamException();
				}
				Buffer.BlockCopy(array, 0, victorMotionClip.Values, 0, array.Length);
				Clips.Add(victorMotionClip.Name, victorMotionClip);
			}
			string[] array2 = new string[6] { "reload_idle", "reload_run", "ability_jumpstart_no_path", "weapon_stand_idle", "weapon_run_n", "out_of_combat_run_n" };
			foreach (string key in array2)
			{
				if (!Clips.ContainsKey(key))
				{
					throw new InvalidDataException("Victor requires the updated victor_motion.bin; replace the complete mod package.");
				}
			}
		}
	}
	public sealed class VictorMotionPlayer : MonoBehaviour
	{
		private static readonly string[] Runs = new string[8] { "weapon_run_n", "weapon_run_ne", "weapon_run_e", "weapon_run_se", "weapon_run_s", "weapon_run_sw", "weapon_run_w", "weapon_run_nw" };

		private static readonly string[] Sprints = Runs.Select((string n) => n.Replace("weapon_run_", "out_of_combat_run_")).ToArray();

		private Transform[] bones;

		private bool[] upper;

		private bool[] weaponMotion;

		private Vector3[] lastPositions;

		private Vector3[] lastScales;

		private Quaternion[] lastRotations;

		private CharacterBody body;

		private string locomotion;

		private string action;

		private float gait;

		private float idleTime;

		private float airAge;

		private float moveBlend;

		private float directionAngle;

		private float sprintBlend;

		private float actionLastProgress = -1f;

		private float actionAt;

		private float actionUntil;

		private float shotAt = -100f;

		private float shotUntil;

		private float reloadBlend;

		private float reloadProgress;

		private bool reloading;

		private int handIndex;

		private int gunIndex;

		private int[] parents;

		private Vector3[][] gripPositions;

		private Quaternion[][] gripRotations;

		private bool wasGrounded = true;

		public string Status => (Object.op_Implicit((Object)(object)body) ? "bound " : "no owner ") + (locomotion ?? "initializing") + ((reloadBlend > 0.1f) ? " reload" : "") + " " + ((bones != null) ? bones.Count((Transform t) => Object.op_Implicit((Object)(object)t)) : 0) + "/159";

		internal void SetOwner(CharacterBody owner)
		{
			body = owner;
		}

		internal void Initialize(Transform root, CharacterBody owner, Animator animator)
		{
			body = owner;
			Dictionary<string, Transform> map = (from t in ((Component)root).GetComponentsInChildren<Transform>(true)
				group t by ((Object)t).name).ToDictionary((IGrouping<string, Transform> g) => g.Key, (IGrouping<string, Transform> g) => g.First());
			bones = VictorMotionLibrary.Bones.Select((string n) => map.TryGetValue(n, out var value) ? value : null).ToArray();
			upper = bones.Select((Transform t) => Object.op_Implicit((Object)(object)t) && IsUpper(t, root)).ToArray();
			weaponMotion = bones.Select((Transform t) => Object.op_Implicit((Object)(object)t) && (((Object)t).name == "weaponPivot" || ((Object)t).name == "weapon" || ((Object)t).name == "clip")).ToArray();
			lastPositions = bones.Select((Transform t) => Object.op_Implicit((Object)(object)t) ? t.localPosition : Vector3.zero).ToArray();
			lastRotations = bones.Select((Transform t) => Object.op_Implicit((Object)(object)t) ? t.localRotation : Quaternion.identity).ToArray();
			lastScales = bones.Select((Transform t) => Object.op_Implicit((Object)(object)t) ? t.localScale : Vector3.one).ToArray();
			parents = bones.Select((Transform t) => Object.op_Implicit((Object)(object)t) ? Array.IndexOf(bones, t.parent) : (-1)).ToArray();
			handIndex = Array.IndexOf(VictorMotionLibrary.Bones, "hand_R");
			gunIndex = Array.IndexOf(VictorMotionLibrary.Bones, "weapon");
			BakeGrip();
			if (Object.op_Implicit((Object)(object)animator))
			{
				((Behaviour)animator).enabled = false;
			}
		}

		private void BakeGrip()
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00ad: 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_00b8: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			if (handIndex < 0 || gunIndex < 0)
			{
				return;
			}
			gripPositions = new Vector3[2][];
			gripRotations = new Quaternion[2][];
			for (int i = 0; i < 2; i++)
			{
				VictorMotionClip victorMotionClip = Clip((i == 0) ? "reload_idle" : "reload_run");
				gripPositions[i] = (Vector3[])(object)new Vector3[victorMotionClip.Frames];
				gripRotations[i] = (Quaternion[])(object)new Quaternion[victorMotionClip.Frames];
				for (int j = 0; j < victorMotionClip.Frames; j++)
				{
					float progress = (float)j / (float)(victorMotionClip.Frames - 1);
					Matrix4x4 val = SourceWorld(victorMotionClip, handIndex, progress);
					Matrix4x4 val2 = SourceWorld(victorMotionClip, gunIndex, progress);
					Matrix4x4 val3 = ((Matrix4x4)(ref val)).inverse * val2;
					gripPositions[i][j] = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(Vector3.zero);
					gripRotations[i][j] = ((Matrix4x4)(ref val3)).rotation;
				}
			}
		}

		private Matrix4x4 SourceWorld(VictorMotionClip clip, int bone, float progress)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//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_0018: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			ReadPose(clip, bone, progress, out var pos, out var rot, out var scale);
			Matrix4x4 val = Matrix4x4.TRS(pos, rot, scale);
			return (parents[bone] < 0) ? val : (SourceWorld(clip, parents[bone], progress) * val);
		}

		private void ApplyReloadGrip()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_00a3: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00e0: 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_00ec: 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_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: 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_018c: 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_0105: 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_0112: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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)
			if (gripPositions == null || reloadBlend < 0.001f || !Object.op_Implicit((Object)(object)bones[handIndex]) || !Object.op_Implicit((Object)(object)bones[gunIndex]))
			{
				return;
			}
			Vector3 val = Vector3.zero;
			Quaternion val2 = Quaternion.identity;
			for (int i = 0; i < 2; i++)
			{
				float num = reloadProgress * (float)(gripPositions[i].Length - 1);
				int num2 = Mathf.Min((int)num, gripPositions[i].Length - 2);
				float num3 = num - (float)num2;
				Vector3 val3 = Vector3.Lerp(gripPositions[i][num2], gripPositions[i][num2 + 1], num3);
				Quaternion val4 = Quaternion.Slerp(gripRotations[i][num2], gripRotations[i][num2 + 1], num3);
				if (i == 0)
				{
					val = val3;
					val2 = val4;
				}
				else
				{
					val = Vector3.Lerp(val, val3, moveBlend);
					val2 = Quaternion.Slerp(val2, val4, moveBlend);
				}
			}
			Transform val5 = bones[handIndex];
			Transform val6 = bones[gunIndex];
			val6.position = Vector3.Lerp(val6.position, val5.TransformPoint(val), reloadBlend);
			val6.rotation = Quaternion.Slerp(val6.rotation, val5.rotation * val2, reloadBlend);
		}

		private void ApplySprintGrip(VictorMotionClip a, VictorMotionClip b, float phase, float directional, float weight)
		{
			//IL_005c: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00ab: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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_011f: 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_012b: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			if (!(weight < 0.001f) && handIndex >= 0 && gunIndex >= 0 && Object.op_Implicit((Object)(object)bones[handIndex]) && Object.op_Implicit((Object)(object)bones[gunIndex]))
			{
				Matrix4x4 val = SourceWorld(a, handIndex, phase);
				Matrix4x4 val2 = ((Matrix4x4)(ref val)).inverse * SourceWorld(a, gunIndex, phase);
				val = SourceWorld(b, handIndex, phase);
				Matrix4x4 val3 = ((Matrix4x4)(ref val)).inverse * SourceWorld(b, gunIndex, phase);
				Vector3 val4 = Vector3.Lerp(((Matrix4x4)(ref val2)).MultiplyPoint3x4(Vector3.zero), ((Matrix4x4)(ref val3)).MultiplyPoint3x4(Vector3.zero), directional);
				Quaternion val5 = Quaternion.Slerp(((Matrix4x4)(ref val2)).rotation, ((Matrix4x4)(ref val3)).rotation, directional);
				Transform val6 = bones[handIndex];
				Transform val7 = bones[gunIndex];
				val7.position = Vector3.Lerp(val7.position, val6.TransformPoint(val4), weight);
				val7.rotation = Quaternion.Slerp(val7.rotation, val6.rotation * val5, weight);
			}
		}

		private static bool IsUpper(Transform bone, Transform root)
		{
			Transform val = bone;
			while (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)root)
			{
				if (((Object)val).name == "spine_1" || ((Object)val).name == "weaponPivot")
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		internal void Play(string name, float duration)
		{
			if (VictorMotionLibrary.Clips.TryGetValue(name, out var value))
			{
				if (name.StartsWith("shoot"))
				{
					shotAt = Time.time;
					shotUntil = Time.time + value.Duration;
					reloadBlend = 0f;
					reloadProgress = 0f;
				}
				else if (duration > 0f)
				{
					action = name;
					actionAt = Time.time;
					actionLastProgress = -1f;
					actionUntil = Time.time + ((value.Duration > 0f) ? value.Duration : duration);
				}
			}
		}

		private static float Damp(float seconds)
		{
			return 1f - Mathf.Exp((0f - Time.deltaTime) / seconds);
		}

		private static VictorMotionClip Clip(string name)
		{
			return VictorMotionLibrary.Clips[name];
		}

		private void LateUpdate()
		{
			//IL_005c: 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_009d: 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_00a4: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06da: Unknown result type (might be due to invalid IL or missing references)
			//IL_06df: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: Unknown result type (might be due to invalid IL or missing references)
			//IL_070e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0713: Unknown result type (might be due to invalid IL or missing references)
			//IL_0767: Unknown result type (might be due to invalid IL or missing references)
			//IL_0769: Unknown result type (might be due to invalid IL or missing references)
			//IL_076b: Unknown result type (might be due to invalid IL or missing references)
			//IL_076f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0776: Unknown result type (might be due to invalid IL or missing references)
			//IL_077b: Unknown result type (might be due to invalid IL or missing references)
			//IL_077d: Unknown result type (might be due to invalid IL or missing references)
			//IL_077f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0781: Unknown result type (might be due to invalid IL or missing references)
			//IL_0785: Unknown result type (might be due to invalid IL or missing references)
			//IL_078c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0791: Unknown result type (might be due to invalid IL or missing references)
			//IL_0793: Unknown result type (might be due to invalid IL or missing references)
			//IL_0795: Unknown result type (might be due to invalid IL or missing references)
			//IL_0797: Unknown result type (might be due to invalid IL or missing references)
			//IL_079b: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_08cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_08dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0903: Unknown result type (might be due to invalid IL or missing references)
			//IL_0905: Unknown result type (might be due to invalid IL or missing references)
			//IL_0907: Unknown result type (might be due to invalid IL or missing references)
			//IL_0909: Unknown result type (might be due to invalid IL or missing references)
			//IL_0911: Unknown result type (might be due to invalid IL or missing references)
			//IL_091f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0924: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0804: Unknown result type (might be due to invalid IL or missing references)
			//IL_0809: Unknown result type (might be due to invalid IL or missing references)
			//IL_080e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0810: Unknown result type (might be due to invalid IL or missing references)
			//IL_0815: Unknown result type (might be due to invalid IL or missing references)
			//IL_0971: Unknown result type (might be due to invalid IL or missing references)
			//IL_0973: Unknown result type (might be due to invalid IL or missing references)
			//IL_0977: Unknown result type (might be due to invalid IL or missing references)
			//IL_097c: Unknown result type (might be due to invalid IL or missing references)
			//IL_097e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0980: Unknown result type (might be due to invalid IL or missing references)
			//IL_0984: Unknown result type (might be due to invalid IL or missing references)
			//IL_0989: Unknown result type (might be due to invalid IL or missing references)
			//IL_098b: Unknown result type (might be due to invalid IL or missing references)
			//IL_098d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0991: Unknown result type (might be due to invalid IL or missing references)
			//IL_0996: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a34: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a39: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a3d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a42: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a57: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a60: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a65: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a7a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a7f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a83: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a88: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a9e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a00: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a02: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a07: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a09: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a10: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a17: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a1c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a21: Unknown result type (might be due to invalid IL or missing references)
			if (bones == null || !VictorMotionLibrary.Ready)
			{
				return;
			}
			float num = 0f;
			bool flag = true;
			if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.characterMotor))
			{
				Vector3 velocity = body.characterMotor.velocity;
				velocity.y = 0f;
				num = ((Vector3)(ref velocity)).magnitude;
				flag = body.characterMotor.isGrounded;
				if (num > 0.1f)
				{
					Vector3 val = ((Component)this).transform.InverseTransformDirection(velocity);
					float num2 = Mathf.Atan2(val.x, val.z) * 57.29578f;
					directionAngle = Mathf.LerpAngle(directionAngle, num2, Damp(0.08f));
				}
			}
			airAge = ((flag || wasGrounded) ? 0f : (airAge + Time.deltaTime));
			wasGrounded = flag;
			idleTime += Time.deltaTime;
			float num3 = Mathf.Clamp01(num / Mathf.Max(1f, Object.op_Implicit((Object)(object)body) ? (body.moveSpeed * 0.65f) : 7f));
			moveBlend = Mathf.Lerp(moveBlend, num3, Damp(0.1f));
			bool flag2 = Object.op_Implicit((Object)(object)body) && body.isSprinting && flag && num > 0.2f;
			sprintBlend = Mathf.Lerp(sprintBlend, (float)(flag2 ? 1 : 0), Damp(0.14f));
			float num4 = Mathf.Clamp(num / 7f, 0.2f, 3f);
			if (flag2)
			{
				num4 = Mathf.Sqrt(num4);
			}
			gait = Mathf.Repeat(gait + Time.deltaTime * num4 / Clip("weapon_run_n").Duration, 1f);
			float num5 = Mathf.Repeat(directionAngle, 360f) / 45f;
			int num6 = Mathf.FloorToInt(num5) % 8;
			int num7 = (num6 + 1) % 8;
			float num8 = num5 - Mathf.Floor(num5);
			VictorMotionClip clip = Clip(Runs[num6]);
			VictorMotionClip clip2 = Clip(Runs[num7]);
			VictorMotionClip victorMotionClip = Clip(Sprints[num6]);
			VictorMotionClip victorMotionClip2 = Clip(Sprints[num7]);
			VictorMotionClip victorMotionClip3 = Clip("weapon_stand_idle");
			VictorMotionClip victorMotionClip4 = Clip((airAge < 0.25f) ? "jump_ground" : "in_air_loop_apex");
			locomotion = ((!flag) ? victorMotionClip4.Name : ((moveBlend > 0.15f) ? Runs[num6] : "weapon_stand_idle"));
			if (flag2)
			{
				locomotion = Sprints[num6];
			}
			bool flag3 = action != null && Time.time < actionUntil;
			bool flag4 = flag3 && (action == "ability_reanimation" || action.StartsWith("ability_jumpstart"));
			VictorMotionClip victorMotionClip5 = (flag3 ? Clip(action) : null);
			float normalized = (flag3 ? Mathf.Clamp01((Time.time - actionAt) / (actionUntil - actionAt)) : 0f);
			if (action != null && actionUntil > actionAt && VictorNativeEffects.ExtendedReady)
			{
				float progress = Mathf.Clamp01((Time.time - actionAt) / (actionUntil - actionAt));
				foreach (Data effect in VictorNativeAnimation.ParticleEvents(action, actionLastProgress, progress))
				{
					VictorVfx.Safely(delegate
					{
						VictorNativeActor.CreateEvent(body, effect);
					});
				}
				actionLastProgress = progress;
			}
			float num9 = (flag3 ? Mathf.Clamp01(Mathf.Min((Time.time - actionAt) / 0.12f, (actionUntil - Time.time) / 0.14f)) : 0f);
			GenericSkill val2 = ((Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.skillLocator)) ? body.skillLocator.primary : null);
			bool flag5 = Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.skillDef) && val2.skillDef.skillName == "WishVictorPISTOL";
			if (!flag5 || val2.stock >= val2.maxStock)
			{
				reloading = false;
			}
			else if (val2.stock == 0)
			{
				reloading = true;
			}
			bool flag6 = flag5 && reloading;
			reloadBlend = Mathf.Lerp(reloadBlend, (float)((flag6 && !flag3) ? 1 : 0), Damp(0.09f));
			if (flag6)
			{
				float num10 = Mathf.Max(0.1f, val2.baseRechargeInterval * val2.cooldownScale - val2.flatCooldownReduction);
				reloadProgress = Mathf.Clamp01(val2.rechargeStopwatch / num10);
			}
			else if (flag5 && val2.stock >= val2.maxStock)
			{
				reloadProgress = 1f;
			}
			VictorMotionClip clip3 = Clip("reload_idle");
			VictorMotionClip clip4 = Clip("reload_run");
			bool flag7 = !flag4 && Time.time < shotUntil;
			VictorMotionClip victorMotionClip6 = Clip("shoot_idle");
			float num11 = (flag7 ? Mathf.Clamp01((Time.time - shotAt) / victorMotionClip6.Duration) : 0f);
			float num12 = (flag7 ? Mathf.Sin(num11 * (float)Math.PI) : 0f);
			float num13 = Damp(0.035f);
			Quaternion val3 = default(Quaternion);
			for (int num14 = 0; num14 < bones.Length; num14++)
			{
				if (!Object.op_Implicit((Object)(object)bones[num14]))
				{
					continue;
				}
				ReadPose(victorMotionClip3, num14, Mathf.Repeat(idleTime / victorMotionClip3.Duration, 1f), out var pos, out var rot, out var scale);
				if (flag)
				{
					ReadPose(clip, num14, gait, out var pos2, out var rot2, out var scale2);
					ReadPose(clip2, num14, gait, out var pos3, out var rot3, out var scale3);
					pos = Vector3.Lerp(pos, Vector3.Lerp(pos2, pos3, num8), moveBlend);
					rot = Quaternion.Slerp(rot, Quaternion.Slerp(rot2, rot3, num8), moveBlend);
					scale = Vector3.Lerp(scale, Vector3.Lerp(scale2, scale3, num8), moveBlend);
					if (sprintBlend > 0.001f)
					{
						ReadPose(victorMotionClip, num14, gait, out var pos4, out var rot4, out var scale4);
						ReadPose(victorMotionClip2, num14, gait, out var pos5, out var rot5, out var scale5);
						float num15 = sprintBlend * moveBlend;
						pos = Vector3.Lerp(pos, Vector3.Lerp(pos4, pos5, num8), num15);
						rot = Quaternion.Slerp(rot, Quaternion.Slerp(rot4, rot5, num8), num15);
						scale = Vector3.Lerp(scale, Vector3.Lerp(scale4, scale5, num8), num15);
						if (((Object)bones[num14]).name == "spine_0" && Object.op_Implicit((Object)(object)bones[num14].parent))
						{
							rot = Quaternion.AngleAxis(7f * sprintBlend, bones[num14].parent.InverseTransformDirection(((Component)this).transform.right)) * rot;
						}
					}
				}
				else
				{
					ReadPose(victorMotionClip4, num14, Mathf.Repeat(airAge / victorMotionClip4.Duration, 1f), out pos, out rot, out scale);
				}
				if (reloadBlend > 0.001f)
				{
					ReadPose(clip3, num14, reloadProgress, out var pos6, out var rot6, out var scale6);
					ReadPose(clip4, num14, reloadProgress, out var pos7, out var rot7, out var scale7);
					float num16 = Mathf.Lerp(VictorNativeAnimation.Mask("Reload_Idle", ((Object)bones[num14]).name), VictorNativeAnimation.Mask("Reload_Haspath", ((Object)bones[num14]).name), moveBlend);
					rot = Quaternion.Slerp(rot, Quaternion.Slerp(rot6, rot7, moveBlend), reloadBlend * num16);
					pos = Vector3.Lerp(pos, Vector3.Lerp(pos6, pos7, moveBlend), reloadBlend * num16);
					scale = Vector3.Lerp(scale, Vector3.Lerp(scale6, scale7, moveBlend), reloadBlend * num16);
				}
				if (victorMotionClip5 != null)
				{
					ReadPose(victorMotionClip5, num14, normalized, out var pos8, out var rot8, out var scale8);
					float num17 = VictorNativeAnimation.Mask(flag4 ? "FullBody" : "Cast_UpperBody", ((Object)bones[num14]).name);
					float num18 = num9 * num17;
					rot = Quaternion.Slerp(rot, rot8, num18);
					pos = Vector3.Lerp(pos, pos8, num18);
					scale = Vector3.Lerp(scale, scale8, num18);
				}
				if (flag7 && upper[num14])
				{
					ReadPose(victorMotionClip6, num14, num11, out var _, out var rot9, out var _);
					int num19 = num14 * 10;
					((Quaternion)(ref val3))..ctor(victorMotionClip6.Values[num19 + 3], victorMotionClip6.Values[num19 + 4], victorMotionClip6.Values[num19 + 5], victorMotionClip6.Values[num19 + 6]);
					rot *= Quaternion.Slerp(Quaternion.identity, Quaternion.Inverse(val3) * rot9, num12);
				}
				lastPositions[num14] = Vector3.Lerp(lastPositions[num14], pos, num13);
				lastRotations[num14] = Quaternion.Slerp(lastRotations[num14], rot, num13);
				lastScales[num14] = Vector3.Lerp(lastScales[num14], scale, num13);
				bones[num14].localPosition = lastPositions[num14];
				bones[num14].localRotation = lastRotations[num14];
				bones[num14].localScale = lastScales[num14];
			}
			if (!flag3)
			{
				ApplySprintGrip(victorMotionClip, victorMotionClip2, gait, num8, sprintBlend * moveBlend);
				ApplyReloadGrip();
			}
		}

		private static void ReadPose(VictorMotionClip clip, int bone, float normalized, out Vector3 pos, out Quaternion rot, out Vector3 scale)
		{
			//IL_005d: 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_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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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)
			float num = Mathf.Clamp01(normalized) * (float)(clip.Frames - 1);
			int num2 = Mathf.Min((int)num, clip.Frames - 2);
			float num3 = num - (float)num2;
			int num4 = (num2 * VictorMotionLibrary.Bones.Length + bone) * 10;
			int num5 = num4 + VictorMotionLibrary.Bones.Length * 10;
			float[] values = clip.Values;
			pos = Vector3.Lerp(new Vector3(values[num4], values[num4 + 1], values[num4 + 2]), new Vector3(values[num5], values[num5 + 1], values[num5 + 2]), num3);
			rot = Quaternion.Slerp(new Quaternion(values[num4 + 3], values[num4 + 4], values[num4 + 5], values[num4 + 6]), new Quaternion(values[num5 + 3], values[num5 + 4], values[num5 + 5], values[num5 + 6]), num3);
			scale = Vector3.Lerp(new Vector3(values[num4 + 7], values[num4 + 8], values[num4 + 9]), new Vector3(values[num5 + 7], values[num5 + 8], values[num5 + 9]), num3);
		}
	}
	public sealed class VictorNativeDelayedEffect : MonoBehaviour
	{
		internal float Delay;

		internal Action Effect;

		private float age;

		private void Update()
		{
			age += Time.deltaTime;
			if (!(age < Delay))
			{
				VictorVfx.Safely(delegate
				{
					Effect?.Invoke();
				});
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}
	internal static class VictorNativeAbilityEffects
	{
		internal static void CastBattery(CharacterBody body)
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			if (!VictorNativeEffects.ExtendedReady || !Object.op_Implicit((Object)(object)body))
			{
				return;
			}
			VictorVisual victorVisual = ((Component)body).GetComponent<VictorController>()?.Visual;
			VictorNativeAttachments victorNativeAttachments = (Object.op_Implicit((Object)(object)victorVisual) ? ((Component)victorVisual).GetComponent<VictorNativeAttachments>() : null);
			Transform socket = (Object.op_Implicit((Object)(object)victorNativeAttachments) ? victorNativeAttachments.Find("forearm_bolt_l_fx") : null);
			string[] array = new string[2] { "frank_shock_cast", "frank_shock_cast_build" };
			foreach (string resource in array)
			{
				VictorNativeActor victorNativeActor = VictorNativeActor.Create(body, resource, 0.35f, follow: false, Object.op_Implicit((Object)(object)socket) ? socket.position : body.corePosition, Object.op_Implicit((Object)(object)body.inputBank) ? body.inputBank.aimDirection : ((Component)body).transform.forward);
				victorNativeActor.Configure = delegate(VictorNativeActor a)
				{
					//IL_0017: Unknown result type (might be due to invalid IL or missing references)
					if (Object.op_Implicit((Object)(object)socket))
					{
						a.Position(socket.position);
					}
				};
			}
		}

		internal static void ReanimationSlow(CharacterBody body)
		{
			if (!VictorNativeEffects.ExtendedReady || !Object.op_Implicit((Object)(object)body))
			{
				return;
			}
			VictorController component = ((Component)body).GetComponent<VictorController>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return;
			}
			foreach (CharacterBody item in component.Enemies(18f))
			{
				VictorNativeActor.Create(item, "frank_revive_death_debuff", 3f);
				if (NetworkServer.active)
				{
					item.AddTimedBuff(Buffs.Slow80, 3f);
				}
			}
		}

		internal static void WorldImpact(CharacterBody body, Vector3 position, Vector3 normal, float delay)
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!VictorNativeEffects.ExtendedReady)
			{
				return;
			}
			VictorNativeDelayedEffect victorNativeDelayedEffect = new GameObject("Victor native impact timer").AddComponent<VictorNativeDelayedEffect>();
			victorNativeDelayedEffect.Delay = delay;
			victorNativeDelayedEffect.Effect = delegate
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)body))
				{
					VictorNativeActor.Create(body, "frank_shock_projectile_impact", 0f, follow: false, position, normal);
				}
			};
		}

		internal static void DischargeTargets(CharacterBody body)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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)
			if (!VictorNativeEffects.ExtendedReady || !Object.op_Implicit((Object)(object)body))
			{
				return;
			}
			VictorController component = ((Component)body).GetComponent<VictorController>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return;
			}
			Vector3 val;
			if (!Object.op_Implicit((Object)(object)body.inputBank))
			{
				val = ((Component)body).transform.forward;
			}
			else
			{
				Vector3 aimDirection = body.inputBank.aimDirection;
				val = ((Vector3)(ref aimDirection)).normalized;
			}
			Vector3 direction = val;
			float threshold = Mathf.Cos(Mathf.Clamp(VictorPlugin.BatteryConeAngle.Value, 10f, 160f) * 0.5f * ((float)Math.PI / 180f));
			foreach (CharacterBody item in component.Enemies(28f).Where(delegate(CharacterBody t)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to i