Decompiled source of FPV Deathsquito v1.5.0

FpvDeathsquito.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FpvDeathsquito")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyInformationalVersion("1.5.0")]
[assembly: AssemblyProduct("FpvDeathsquito")]
[assembly: AssemblyTitle("FpvDeathsquito")]
[assembly: AssemblyVersion("1.5.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;
		}
	}
}
namespace FpvDeathsquito
{
	internal static class ConfigSync
	{
		private const string MsgConfig = "FpvDeathsquito_Cfg";

		private const string MsgRequest = "FpvDeathsquito_CfgReq";

		private static readonly Dictionary<string, ConfigEntryBase> ById = new Dictionary<string, ConfigEntryBase>();

		private static readonly Dictionary<ConfigEntryBase, object> Over = new Dictionary<ConfigEntryBase, object>();

		private static bool _active;

		private static bool _want;

		private static bool _received;

		private static bool _gaveUp;

		private static bool _warnedSender;

		private static int _tries;

		private static float _timer;

		private static string Id(ConfigEntryBase e)
		{
			return e.Definition.Section + "." + e.Definition.Key;
		}

		internal static void Track(params ConfigEntryBase[] entries)
		{
			foreach (ConfigEntryBase val in entries)
			{
				if (val != null)
				{
					ById[Id(val)] = val;
				}
			}
		}

		internal static void Init(ConfigFile cfg)
		{
			cfg.SettingChanged += OnSettingChanged;
		}

		internal static T Get<T>(ConfigEntry<T> e)
		{
			if (_active && Over.TryGetValue((ConfigEntryBase)(object)e, out var value) && value is T)
			{
				return (T)value;
			}
			return e.Value;
		}

		private static bool IsServer()
		{
			if ((Object)(object)ZNet.instance != (Object)null)
			{
				return ZNet.instance.IsServer();
			}
			return false;
		}

		internal static void Reset()
		{
			Over.Clear();
			_active = false;
			_want = false;
			_received = false;
			_gaveUp = false;
			_tries = 0;
			_timer = 0f;
		}

		internal static void Register(ZRoutedRpc rpc)
		{
			rpc.Register<string>("FpvDeathsquito_Cfg", (Action<long, string>)RPC_Config);
			rpc.Register<string>("FpvDeathsquito_CfgReq", (Action<long, string>)RPC_Request);
		}

		internal static void Request()
		{
			if (!IsServer() && Plugin.CfgSync.Value)
			{
				_want = true;
				_timer = 99f;
			}
		}

		internal static void Tick(float dt)
		{
			if (!_want || _received || _gaveUp)
			{
				return;
			}
			_timer += dt;
			if (_timer < 3f)
			{
				return;
			}
			_timer = 0f;
			if (_tries >= 6)
			{
				_gaveUp = true;
				Plugin.Log.LogInfo((object)"Сервер не прислал настройки (на нём нет мода?) — используются локальные.");
				return;
			}
			ZRoutedRpc instance = ZRoutedRpc.instance;
			long num = ServerPeerId();
			if (instance != null && num != 0L)
			{
				_tries++;
				instance.InvokeRoutedRPC(num, "FpvDeathsquito_CfgReq", new object[1] { "1.5.0" });
			}
		}

		private static void RPC_Request(long sender, string version)
		{
			if (IsServer())
			{
				ZRoutedRpc instance = ZRoutedRpc.instance;
				if (instance != null)
				{
					instance.InvokeRoutedRPC(sender, "FpvDeathsquito_Cfg", new object[1] { BuildPayload() });
				}
			}
		}

		private static void RPC_Config(long sender, string payload)
		{
			if (IsServer() || !Plugin.CfgSync.Value)
			{
				return;
			}
			long num = ServerPeerId();
			if (num == 0L || sender != num)
			{
				if (!_warnedSender)
				{
					_warnedSender = true;
					Plugin.Log.LogWarning((object)"Настройки от не-сервера проигнорированы.");
				}
			}
			else
			{
				Apply(payload);
			}
		}

		private static void OnSettingChanged(object sender, SettingChangedEventArgs e)
		{
			try
			{
				if (e != null && e.ChangedSetting != null && ById.ContainsKey(Id(e.ChangedSetting)))
				{
					ZRoutedRpc instance = ZRoutedRpc.instance;
					if (instance != null && IsServer())
					{
						instance.InvokeRoutedRPC(0L, "FpvDeathsquito_Cfg", new object[1] { BuildPayload() });
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Рассылка настроек: " + ex.Message));
			}
		}

		private static string BuildPayload()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (KeyValuePair<string, ConfigEntryBase> item in ById)
			{
				stringBuilder.Append(item.Key).Append('=').Append(Convert.ToString(item.Value.BoxedValue, CultureInfo.InvariantCulture))
					.Append('\n');
			}
			return stringBuilder.ToString();
		}

		private static void Apply(string payload)
		{
			if (string.IsNullOrEmpty(payload))
			{
				return;
			}
			int num = 0;
			string[] array = payload.Split('\n');
			foreach (string text in array)
			{
				int num2 = text.IndexOf('=');
				if (num2 > 0 && ById.TryGetValue(text.Substring(0, num2), out var value) && TryParse(value.SettingType, text.Substring(num2 + 1), out var v))
				{
					Over[value] = v;
					num++;
				}
			}
			_active = num > 0;
			_received = true;
			Plugin.Log.LogInfo((object)("Настройки синхронизированы с сервером: " + num + " параметров."));
		}

		private static bool TryParse(Type t, string s, out object v)
		{
			v = null;
			try
			{
				if (t == typeof(bool))
				{
					v = bool.Parse(s);
					return true;
				}
				if (t == typeof(int))
				{
					v = int.Parse(s, CultureInfo.InvariantCulture);
					return true;
				}
				if (t == typeof(float))
				{
					v = float.Parse(s, CultureInfo.InvariantCulture);
					return true;
				}
				if (t == typeof(string))
				{
					v = s;
					return true;
				}
			}
			catch (Exception)
			{
			}
			return false;
		}

		private static long ServerPeerId()
		{
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance == null)
			{
				return 0L;
			}
			try
			{
				MethodInfo method = typeof(ZRoutedRpc).GetMethod("GetServerPeerID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					return (long)method.Invoke(instance, null);
				}
				FieldInfo field = typeof(ZRoutedRpc).GetField("m_serverPeerID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					return (long)field.GetValue(instance);
				}
			}
			catch (Exception)
			{
			}
			return 0L;
		}
	}
	internal sealed class Deafen : MonoBehaviour
	{
		private static Deafen _inst;

		private AudioLowPassFilter _lp;

		private AudioSource _ring;

		private float _t = 999f;

		private float _dur = 3f;

		private float _strength;

		private float _minCut = 600f;

		internal static void OnExplosion(Vector3 pos)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.CfgDeafen.Value)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).IsDead())
			{
				float num = Mathf.Max(1f, ConfigSync.Get<float>(Plugin.CfgBlastRadius));
				float num2 = Vector3.Distance(((Character)localPlayer).GetCenterPoint(), pos);
				if (!(num2 > num))
				{
					Trigger(Mathf.Lerp(0.35f, 1f, 1f - num2 / num));
				}
			}
		}

		internal static void Trigger(float strength)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if ((Object)(object)_inst == (Object)null)
			{
				GameObject val = new GameObject("FPV_Deafen");
				Object.DontDestroyOnLoad((Object)val);
				_inst = val.AddComponent<Deafen>();
			}
			_inst.Begin(strength);
		}

		private void Begin(float strength)
		{
			_dur = Mathf.Max(0.5f, Plugin.CfgDeafenSeconds.Value);
			_strength = Mathf.Clamp01(strength);
			_minCut = Mathf.Lerp(2200f, 420f, _strength);
			_t = -0.08f;
			if ((Object)(object)_ring == (Object)null)
			{
				_ring = ((Component)this).gameObject.AddComponent<AudioSource>();
				_ring.playOnAwake = false;
				_ring.loop = false;
				_ring.spatialBlend = 0f;
				_ring.bypassListenerEffects = true;
				AudioMixerGroup val = DroneAudio.Group;
				if ((Object)(object)val != (Object)null)
				{
					_ring.outputAudioMixerGroup = val;
				}
			}
			_ring.clip = DroneAudio.Ringing;
			_ring.volume = 0f;
			_ring.Play();
		}

		private bool EnsureFilter()
		{
			if ((Object)(object)_lp != (Object)null)
			{
				return true;
			}
			AudioListener val = null;
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null)
			{
				val = ((Component)main).GetComponent<AudioListener>();
			}
			if ((Object)(object)val == (Object)null)
			{
				AudioListener[] array = Resources.FindObjectsOfTypeAll<AudioListener>();
				foreach (AudioListener val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && ((Behaviour)val2).isActiveAndEnabled)
					{
						val = val2;
						break;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			_lp = ((Component)val).GetComponent<AudioLowPassFilter>();
			if ((Object)(object)_lp == (Object)null)
			{
				_lp = ((Component)val).gameObject.AddComponent<AudioLowPassFilter>();
			}
			_lp.cutoffFrequency = 22000f;
			((Behaviour)_lp).enabled = false;
			return true;
		}

		private void Update()
		{
			float num = _dur + 1.5f;
			if (_t > num)
			{
				return;
			}
			_t += Time.unscaledDeltaTime;
			if (_t < 0f)
			{
				return;
			}
			float num2 = _dur * 0.35f;
			float num3 = _dur * 0.65f;
			float num4 = ((_t < num2) ? 1f : (1f - Mathf.Clamp01((_t - num2) / num3)));
			num4 = num4 * num4 * (3f - 2f * num4);
			if (EnsureFilter())
			{
				if (num4 > 0.001f)
				{
					((Behaviour)_lp).enabled = true;
					_lp.cutoffFrequency = Mathf.Exp(Mathf.Lerp(Mathf.Log(22000f), Mathf.Log(_minCut), num4));
				}
				else
				{
					((Behaviour)_lp).enabled = false;
				}
			}
			if ((Object)(object)_ring != (Object)null)
			{
				float num5 = Mathf.Clamp01(_t / 0.05f);
				float num6 = Mathf.Exp((0f - _t) / (_dur * 0.55f + 0.6f));
				float num7 = Mathf.Clamp01((num - _t) / 0.6f);
				_ring.volume = Mathf.Clamp01(0.35f * _strength * num5 * num6 * num7);
				if (_t >= num && _ring.isPlaying)
				{
					_ring.Stop();
				}
			}
		}

		private void OnDisable()
		{
			if ((Object)(object)_lp != (Object)null)
			{
				((Behaviour)_lp).enabled = false;
			}
		}
	}
	internal static class DroneAudio
	{
		private const int Rate = 44100;

		private static AudioClip _loop;

		private static AudioClip _loopStar;

		private static AudioClip _launch;

		private static AudioClip _boom;

		private static AudioClip _crash;

		private static AudioClip _ringing;

		private static AudioClip _warning;

		private static AudioClip _squeal;

		private static AudioClip _zap;

		private static AudioMixerGroup _group;

		private static float _nextGroupSearch;

		internal static AudioClip Loop
		{
			get
			{
				object obj = _loop;
				if (obj == null)
				{
					obj = LoadWav("fpv_loop.wav") ?? BuildLoop();
					_loop = (AudioClip)obj;
				}
				return (AudioClip)obj;
			}
		}

		internal static AudioClip LoopStar
		{
			get
			{
				object obj = _loopStar;
				if (obj == null)
				{
					obj = LoadWav("fpv_loop_star.wav") ?? BuildLoopStar();
					_loopStar = (AudioClip)obj;
				}
				return (AudioClip)obj;
			}
		}

		internal static AudioClip Launch
		{
			get
			{
				object obj = _launch;
				if (obj == null)
				{
					obj = LoadWav("fpv_launch_star.wav") ?? BuildLaunch();
					_launch = (AudioClip)obj;
				}
				return (AudioClip)obj;
			}
		}

		internal static AudioClip Ringing
		{
			get
			{
				object obj = _ringing;
				if (obj == null)
				{
					obj = LoadWav("fpv_ringing.wav") ?? BuildRinging();
					_ringing = (AudioClip)obj;
				}
				return (AudioClip)obj;
			}
		}

		internal static AudioClip Warning
		{
			get
			{
				object obj = _warning;
				if (obj == null)
				{
					obj = LoadWav("fpv_warning.wav") ?? BuildWarning();
					_warning = (AudioClip)obj;
				}
				return (AudioClip)obj;
			}
		}

		internal static AudioClip Squeal
		{
			get
			{
				object obj = _squeal;
				if (obj == null)
				{
					obj = LoadWav("fpv_squeal.wav") ?? BuildSqueal();
					_squeal = (AudioClip)obj;
				}
				return (AudioClip)obj;
			}
		}

		internal static AudioClip Zap
		{
			get
			{
				object obj = _zap;
				if (obj == null)
				{
					obj = LoadWav("fpv_zap.wav") ?? BuildZap();
					_zap = (AudioClip)obj;
				}
				return (AudioClip)obj;
			}
		}

		internal static AudioClip Boom
		{
			get
			{
				object obj = _boom;
				if (obj == null)
				{
					obj = LoadWav("fpv_boom.wav") ?? BuildBoom();
					_boom = (AudioClip)obj;
				}
				return (AudioClip)obj;
			}
		}

		internal static AudioClip Crash
		{
			get
			{
				object obj = _crash;
				if (obj == null)
				{
					obj = LoadWav("fpv_crash.wav") ?? BuildCrash();
					_crash = (AudioClip)obj;
				}
				return (AudioClip)obj;
			}
		}

		internal static AudioMixerGroup Group
		{
			get
			{
				if ((Object)(object)_group == (Object)null && Time.unscaledTime >= _nextGroupSearch)
				{
					_nextGroupSearch = Time.unscaledTime + 5f;
					AudioSource[] array = Resources.FindObjectsOfTypeAll<AudioSource>();
					for (int i = 0; i < array.Length; i++)
					{
						AudioMixerGroup outputAudioMixerGroup = array[i].outputAudioMixerGroup;
						if (!((Object)(object)outputAudioMixerGroup == (Object)null))
						{
							string name = ((Object)outputAudioMixerGroup).name;
							if (name.IndexOf("sfx", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("effect", StringComparison.OrdinalIgnoreCase) >= 0)
							{
								_group = outputAudioMixerGroup;
								break;
							}
						}
					}
				}
				return _group;
			}
		}

		internal static void Prewarm()
		{
			try
			{
				_ = Loop;
				_ = Boom;
				_ = Crash;
				_ = LoopStar;
				_ = Launch;
				_ = Ringing;
				_ = Warning;
				_ = Squeal;
				_ = Zap;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Синтез звука: " + ex));
			}
		}

		internal static void LearnGroup(List<AudioSource> sources)
		{
			if ((Object)(object)_group != (Object)null)
			{
				return;
			}
			foreach (AudioSource source in sources)
			{
				if ((Object)(object)source != (Object)null && (Object)(object)source.outputAudioMixerGroup != (Object)null)
				{
					_group = source.outputAudioMixerGroup;
					break;
				}
			}
		}

		internal static void ApplyRolloff(AudioSource s, float minDist, float maxDist)
		{
			//IL_007b: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			s.minDistance = minDist;
			s.maxDistance = maxDist;
			float[] array = new float[4] { 1f, 2f, 4f, 8f };
			float[] array2 = new float[4] { 1f, 0.5f, 0.25f, 0.12f };
			List<Keyframe> list = new List<Keyframe>();
			for (int i = 0; i < array.Length; i++)
			{
				float num = minDist * array[i];
				if (num >= maxDist * 0.7f)
				{
					break;
				}
				list.Add(new Keyframe(num / maxDist, array2[i]));
			}
			list.Add(new Keyframe(0.85f, 0.04f));
			list.Add(new Keyframe(1f, 0f));
			AnimationCurve val = new AnimationCurve(list.ToArray());
			for (int j = 0; j < val.length; j++)
			{
				val.SmoothTangents(j, 0f);
			}
			s.rolloffMode = (AudioRolloffMode)2;
			s.SetCustomCurve((AudioSourceCurveType)0, val);
		}

		internal static void PlayAt(AudioClip clip, Vector3 pos, float volume, float minDist, float maxDist, float pitch)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			if (!((Object)(object)clip == (Object)null))
			{
				GameObject val = new GameObject("FPV_OneShot");
				val.transform.position = pos;
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.clip = clip;
				val2.volume = Mathf.Clamp01(volume);
				val2.pitch = pitch;
				val2.spatialBlend = 1f;
				ApplyRolloff(val2, minDist, maxDist);
				val2.dopplerLevel = 0f;
				val2.playOnAwake = false;
				AudioMixerGroup val3 = Group;
				if ((Object)(object)val3 != (Object)null)
				{
					val2.outputAudioMixerGroup = val3;
				}
				val2.Play();
				Object.Destroy((Object)val, clip.length / Mathf.Max(0.1f, pitch) + 0.5f);
			}
		}

		private static void AddSine(float[] d, double freq, double amp, double phase)
		{
			double num = Math.PI * 2.0 * freq / 44100.0;
			double num2 = Math.Cos(num);
			double num3 = Math.Sin(num);
			double num4 = Math.Sin(phase);
			double num5 = Math.Cos(phase);
			for (int i = 0; i < d.Length; i++)
			{
				d[i] += (float)(amp * num4);
				double num6 = num4 * num2 + num5 * num3;
				num5 = num5 * num2 - num4 * num3;
				num4 = num6;
			}
		}

		private static void Normalize(float[] d, float peak)
		{
			float num = 1E-06f;
			for (int i = 0; i < d.Length; i++)
			{
				num = Mathf.Max(num, Mathf.Abs(d[i]));
			}
			float num2 = peak / num;
			for (int j = 0; j < d.Length; j++)
			{
				d[j] *= num2;
			}
		}

		private static AudioClip MakeClip(string name, float[] d)
		{
			AudioClip obj = AudioClip.Create(name, d.Length, 1, 44100, false);
			obj.SetData(d, 0);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static AudioClip BuildLoop()
		{
			int num = 88200;
			float[] array = new float[num];
			Random random = new Random(1337);
			double[] array2 = new double[4] { 392.0, 401.5, 386.5, 409.0 };
			foreach (double num2 in array2)
			{
				for (int j = 1; j <= 7; j++)
				{
					AddSine(array, num2 * (double)j, 0.16 / Math.Pow(j, 1.3), random.NextDouble() * 6.283);
				}
			}
			AddSine(array, 4200.0, 0.02, 0.3);
			AddSine(array, 8400.0, 0.01, 1.1);
			for (int k = 0; k < 90; k++)
			{
				double num3 = Math.Round((900.0 + random.NextDouble() * 6000.0) * 2.0) / 2.0;
				AddSine(array, num3, 0.01 * (1500.0 / num3) + 0.002, random.NextDouble() * 6.283);
			}
			for (int l = 0; l < num; l++)
			{
				array[l] = (float)Math.Tanh((double)array[l] * 1.8);
			}
			Normalize(array, 0.7f);
			return MakeClip("fpv_loop", array);
		}

		private static AudioClip BuildLoopStar()
		{
			int num = 88200;
			float[] array = new float[num];
			Random random = new Random(4242);
			double[] array2 = new double[4] { 246.0, 254.5, 238.0, 262.5 };
			foreach (double num2 in array2)
			{
				for (int j = 1; j <= 10; j++)
				{
					AddSine(array, num2 * (double)j, 0.2 / Math.Pow(j, 0.95), random.NextDouble() * 6.283);
				}
			}
			AddSine(array, 62.0, 0.3, 0.0);
			AddSine(array, 124.0, 0.12, 0.7);
			AddSine(array, 489.0, 0.07, 0.4);
			AddSine(array, 503.0, 0.07, 0.4);
			AddSine(array, 3100.0, 0.03, 0.3);
			AddSine(array, 6200.0, 0.018, 1.1);
			for (int k = 0; k < 120; k++)
			{
				double num3 = Math.Round((500.0 + random.NextDouble() * 4500.0) * 2.0) / 2.0;
				AddSine(array, num3, 0.012 * (1200.0 / num3) + 0.003, random.NextDouble() * 6.283);
			}
			for (int l = 0; l < num; l++)
			{
				array[l] = (float)Math.Tanh((double)array[l] * 2.6);
			}
			Normalize(array, 0.75f);
			return MakeClip("fpv_loop_star", array);
		}

		private static AudioClip BuildLaunch()
		{
			int num = 48510;
			float[] array = new float[num];
			Random random = new Random(2718);
			double num2 = 0.0;
			double num3 = 0.0;
			double[] array2 = new double[3] { 0.0, 0.09, 0.18 };
			double[] array3 = new double[3] { 0.06, 0.15, 0.3 };
			double[] array4 = new double[3] { 2400.0, 3000.0, 3800.0 };
			for (int i = 0; i < num; i++)
			{
				double num4 = (double)i / 44100.0;
				double num5 = 90.0 + 900.0 * (1.0 - Math.Exp((0.0 - num4) * 5.5));
				num2 += Math.PI * 2.0 * num5 / 44100.0;
				double num6 = Math.Sin(num2) + 0.6 * Math.Sin(2.0 * num2) + 0.35 * Math.Sin(3.0 * num2) + 0.2 * Math.Sin(4.0 * num2);
				double num7 = Math.Min(1.0, num4 / 0.05);
				double num8 = Math.Tanh(num6 * 1.6) * num7 * 0.5;
				double num9 = random.NextDouble() * 2.0 - 1.0;
				num3 += 0.12 * (num9 - num3);
				num8 += num3 * Math.Min(1.0, num4 / 0.08) * Math.Exp((0.0 - num4) * 2.8) * 3.0;
				for (int j = 0; j < 3; j++)
				{
					if (num4 >= array2[j] && num4 < array3[j])
					{
						double num10 = num4 - array2[j];
						double num11 = array3[j] - array2[j];
						double num12 = Math.Min(1.0, Math.Min(num10 / 0.004, (num11 - num10) / 0.004));
						num8 += Math.Sin(Math.PI * 2.0 * array4[j] * num10) * num12 * 0.35;
					}
				}
				array[i] = (float)num8;
			}
			Normalize(array, 0.9f);
			int num13 = 11025;
			for (int k = 0; k < num13; k++)
			{
				array[num - 1 - k] *= (float)k / (float)num13;
			}
			return MakeClip("fpv_launch_star", array);
		}

		private static AudioClip BuildRinging()
		{
			int num = 308700;
			float[] array = new float[num];
			AddSine(array, 4100.0, 0.5, 0.0);
			AddSine(array, 4137.0, 0.35, 1.3);
			AddSine(array, 5300.0, 0.22, 0.4);
			AddSine(array, 2850.0, 0.15, 2.0);
			for (int i = 0; i < num; i++)
			{
				array[i] *= (float)(0.85 + 0.15 * Math.Sin(33.3008821280518 * (double)i / 44100.0));
			}
			Normalize(array, 0.8f);
			int num2 = 882;
			for (int j = 0; j < num2; j++)
			{
				float num3 = (float)j / (float)num2;
				array[j] *= num3;
				array[num - 1 - j] *= num3;
			}
			return MakeClip("fpv_ringing", array);
		}

		private static AudioClip BuildWarning()
		{
			int num = 15876;
			float[] array = new float[num];
			double[] array2 = new double[3] { 0.0, 0.11, 0.22 };
			for (int i = 0; i < num; i++)
			{
				double num2 = (double)i / 44100.0;
				for (int j = 0; j < 3; j++)
				{
					double num3 = num2 - array2[j];
					if (!(num3 < 0.0) && !(num3 >= 0.06))
					{
						double num4 = Math.Min(1.0, Math.Min(num3 / 0.004, (0.06 - num3) / 0.004));
						double num5 = Math.PI * 6400.0 * num3;
						array[i] += (float)((Math.Sin(num5) + 0.3 * Math.Sin(2.0 * num5)) * num4);
					}
				}
			}
			Normalize(array, 0.8f);
			return MakeClip("fpv_warning", array);
		}

		private static AudioClip BuildSqueal()
		{
			int num = 88200;
			float[] array = new float[num];
			Random random = new Random(555);
			for (int i = 0; i < 10; i++)
			{
				double num2 = (double)i * 0.2;
				double num3 = ((i % 2 == 0) ? 3400.0 : 2700.0);
				int num4 = (int)(num2 * 44100.0);
				int num5 = (int)((num2 + 0.13) * 44100.0);
				for (int j = num4; j < num5 && j < num; j++)
				{
					double num6 = (double)j / 44100.0 - num2;
					double num7 = Math.Min(1.0, Math.Min(num6 / 0.006, (0.13 - num6) / 0.012));
					double num8 = Math.PI * 2.0 * num3 * num6 + 0.6 * Math.Sin(Math.PI * 16.0 * num6);
					double num9 = (random.NextDouble() * 2.0 - 1.0) * 0.12;
					array[j] += (float)((Math.Sin(num8) + 0.35 * Math.Sin(2.0 * num8) + num9) * num7);
				}
			}
			for (int k = 0; k < num; k++)
			{
				array[k] = (float)Math.Tanh((double)array[k] * 1.6);
			}
			Normalize(array, 0.7f);
			return MakeClip("fpv_squeal", array);
		}

		private static AudioClip BuildZap()
		{
			int num = 19845;
			float[] array = new float[num];
			Random random = new Random(808);
			double num2 = 0.0;
			for (int i = 0; i < num; i++)
			{
				double num3 = (double)i / 44100.0;
				double num4 = 300.0 + 2100.0 * Math.Exp((0.0 - num3) * 9.0);
				num2 += Math.PI * 2.0 * num4 / 44100.0;
				double num5 = Math.Sin(num2) * Math.Exp((0.0 - num3) * 7.0) * 0.6;
				double num6 = ((random.NextDouble() > 0.55) ? (random.NextDouble() * 2.0 - 1.0) : 0.0) * Math.Exp((0.0 - num3) * 9.0);
				double num7 = (random.NextDouble() * 2.0 - 1.0) * Math.Exp((0.0 - num3) * 200.0) * 1.5;
				array[i] = (float)(num5 + num6 + num7);
			}
			Normalize(array, 0.9f);
			int num8 = 882;
			for (int j = 0; j < num8; j++)
			{
				array[num - 1 - j] *= (float)j / (float)num8;
			}
			return MakeClip("fpv_zap", array);
		}

		private static AudioClip BuildBoom()
		{
			int num = 149940;
			float[] array = new float[num];
			Random random = new Random(7);
			double num2 = 0.0;
			double num3 = 0.0;
			double num4 = 0.0;
			for (int i = 0; i < num; i++)
			{
				double num5 = (double)i / 44100.0;
				double num6 = random.NextDouble() * 2.0 - 1.0;
				num2 += (0.02 + 0.55 * Math.Exp((0.0 - num5) * 9.0)) * (num6 - num2);
				num3 += 0.03 * (num6 - num3);
				double num7 = num6 * Math.Exp((0.0 - num5) * 140.0) * 1.2;
				double num8 = num2 * Math.Exp((0.0 - num5) * 2.1) * 2.2;
				double num9 = num3 * Math.Exp((0.0 - num5) * 1.1) * 6.0;
				num4 += Math.PI * 2.0 * (26.0 + 70.0 * Math.Exp((0.0 - num5) * 7.0)) / 44100.0;
				double num10 = Math.Sin(num4) * Math.Exp((0.0 - num5) * 2.6);
				array[i] = (float)(num7 + num8 + num9 + num10);
			}
			float[] array2 = (float[])array.Clone();
			int[] array3 = new int[3] { 4851, 10143, 18081 };
			float[] array4 = new float[3] { 0.32f, 0.2f, 0.12f };
			for (int j = 0; j < array3.Length; j++)
			{
				for (int k = array3[j]; k < num; k++)
				{
					array[k] += array2[k - array3[j]] * array4[j];
				}
			}
			for (int l = 0; l < num; l++)
			{
				array[l] = (float)Math.Tanh((double)array[l] * 1.3);
			}
			Normalize(array, 0.95f);
			int num11 = 11025;
			for (int m = 0; m < num11; m++)
			{
				array[num - 1 - m] *= (float)m / (float)num11;
			}
			return MakeClip("fpv_boom", array);
		}

		private static AudioClip BuildCrash()
		{
			int num = 83790;
			float[] array = new float[num];
			Random random = new Random(99);
			double num2 = 0.0;
			double num3 = 0.0;
			double num4 = 0.0;
			for (int i = 0; i < num; i++)
			{
				double num5 = (double)i / 44100.0;
				double num6 = 80.0 + 1100.0 * Math.Exp((0.0 - num5) * 2.4);
				num2 += Math.PI * 2.0 * num6 / 44100.0;
				double num7 = Math.Sin(num2) + 0.5 * Math.Sin(2.0 * num2) + 0.25 * Math.Sin(3.0 * num2);
				double num8 = ((num5 < 1.05) ? Math.Exp((0.0 - num5) * 0.9) : (Math.Exp(-0.9450000000000001) * Math.Exp((0.0 - (num5 - 1.05)) * 30.0)));
				double num9 = Math.Tanh(num7 * 1.4) * num8 * 0.5;
				if (random.NextDouble() < 0.002 * Math.Exp((0.0 - num5) * 1.5))
				{
					num3 += (random.NextDouble() * 2.0 - 1.0) * 1.5;
				}
				num3 *= 0.9;
				num9 += num3 * 0.5;
				if (num5 >= 1.05)
				{
					double num10 = num5 - 1.05;
					double num11 = random.NextDouble() * 2.0 - 1.0;
					num4 += 0.25 * (num11 - num4);
					num9 += num4 * Math.Exp((0.0 - num10) * 14.0) * 2.0 + Math.Sin(Math.PI * 130.0 * num10) * Math.Exp((0.0 - num10) * 9.0) * 1.2;
				}
				array[i] = (float)num9;
			}
			Normalize(array, 0.85f);
			int num12 = 4410;
			for (int j = 0; j < num12; j++)
			{
				array[num - 1 - j] *= (float)j / (float)num12;
			}
			return MakeClip("fpv_crash", array);
		}

		private static AudioClip LoadWav(string file)
		{
			try
			{
				string path = Path.Combine(Plugin.Dir ?? "", file);
				if (!File.Exists(path))
				{
					return null;
				}
				byte[] array = File.ReadAllBytes(path);
				if (array.Length < 44 || Encoding.ASCII.GetString(array, 0, 4) != "RIFF")
				{
					return null;
				}
				int num = 12;
				int num2 = 1;
				int num3 = 44100;
				int num4 = 16;
				int num5 = -1;
				int num6 = 0;
				while (num + 8 <= array.Length)
				{
					string text = Encoding.ASCII.GetString(array, num, 4);
					int num7 = BitConverter.ToInt32(array, num + 4);
					int num8 = num + 8;
					if (text == "fmt ")
					{
						num2 = BitConverter.ToInt16(array, num8 + 2);
						num3 = BitConverter.ToInt32(array, num8 + 4);
						num4 = BitConverter.ToInt16(array, num8 + 14);
					}
					else if (text == "data")
					{
						num5 = num8;
						num6 = Math.Min(num7, array.Length - num8);
						break;
					}
					num = num8 + num7 + (num7 & 1);
				}
				if (num5 < 0 || num4 != 16 || num2 < 1)
				{
					Plugin.Log.LogWarning((object)(file + ": нужен PCM 16 бит."));
					return null;
				}
				int num9 = num6 / 2;
				float[] array2 = new float[num9];
				for (int i = 0; i < num9; i++)
				{
					array2[i] = (float)BitConverter.ToInt16(array, num5 + i * 2) / 32768f;
				}
				AudioClip obj = AudioClip.Create(Path.GetFileNameWithoutExtension(file), num9 / num2, num2, num3, false);
				obj.SetData(array2, 0);
				((Object)obj).hideFlags = (HideFlags)61;
				Plugin.Log.LogInfo((object)("Загружен свой звук: " + file));
				return obj;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Не удалось прочитать " + file + ": " + ex.Message));
				return null;
			}
		}
	}
	internal sealed class DroneBehaviour : MonoBehaviour
	{
		private const string StateKey = "FpvDeathsquito_State";

		private const string RolledKey = "FpvDeathsquito_Rolled";

		private const string DeadPropKey = "FpvDeathsquito_DeadProp";

		private const int StateDormant = 0;

		private const int StateLaunching = 1;

		private const int StateHunting = 2;

		private const int StateStunned = 3;

		private const int StateStriking = 4;

		private const string StunRpc = "FpvDeathsquito_Stun";

		internal DroneRig Rig;

		internal bool IsRagdoll;

		private Character _ch;

		private ZNetView _nv;

		private MonsterAI _ai;

		private Rigidbody _body;

		private AudioSource _loop;

		private RigidbodyConstraints _origConstraints;

		private Vector3 _lastPos;

		private Vector3 _vel;

		private float _age;

		private float _armClock;

		private float _pitch;

		private float _roll;

		private float _spin = 1f;

		private float _seed;

		private float _nextSweep;

		private float _revT = 10f;

		private float _scan;

		private float _groundTimer;

		private float _launchT;

		private float _launchStartY;

		private float _lastHealth;

		private float[] _ang;

		private bool _detonated;

		private bool _reported;

		private bool _dead;

		private bool _frozen;

		private bool _grounded;

		private bool _launchInit;

		private int _state = 2;

		private int _prevState = 2;

		private bool _heavy;

		private float _hpFrac = 1f;

		private float _yaw;

		private int _deadProp = -1;

		private float[] _propK;

		private Renderer[] _blur;

		private ParticleSystem _smoke;

		private bool _tumbled;

		private float _strikeT;

		private float _stunT;

		private float _fallV;

		private float _fallDist;

		private bool _stunRequested;

		private bool _sentStun;

		private bool _stunGrounded;

		private AudioSource _stunSrc;

		private static readonly List<AudioSource> Tmp = new List<AudioSource>();

		private static int _losMask = -1;

		private static int _groundMask = -1;

		private static bool _warnedSpeed;

		private static bool _warnedRange;

		private static int LosMask
		{
			get
			{
				if (_losMask == -1)
				{
					_losMask = LayerMask.GetMask(new string[4] { "Default", "static_solid", "terrain", "piece" });
				}
				return _losMask;
			}
		}

		private void Start()
		{
			//IL_0037: 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)
			_ch = ((Component)this).GetComponent<Character>();
			_nv = ((Component)this).GetComponent<ZNetView>();
			_ai = ((Component)this).GetComponent<MonsterAI>();
			_body = ((Component)this).GetComponent<Rigidbody>();
			_lastPos = ((Component)this).transform.position;
			_seed = Random.value * 100f;
			if ((Object)(object)Rig != (Object)null && Rig.Props != null)
			{
				int num = Rig.Props.Length;
				_ang = new float[num];
				_propK = new float[num];
				_blur = (Renderer[])(object)new Renderer[num];
				for (int i = 0; i < num; i++)
				{
					_propK[i] = 1f;
					Transform val = Rig.Props[i];
					Transform val2 = (((Object)(object)val != (Object)null) ? val.Find("Blur") : null);
					if ((Object)(object)val2 != (Object)null)
					{
						_blur[i] = ((Component)val2).GetComponent<Renderer>();
					}
				}
			}
			DroneFx.EnsureRpc();
			if (IsRagdoll)
			{
				_dead = true;
				if (Plugin.CfgDamageFx.Value)
				{
					StartTumble();
					if ((Object)(object)Rig != (Object)null && (Object)(object)Rig.Rig != (Object)null)
					{
						_smoke = ParticleFx.CreateSmoke(Rig.Rig, Plugin.CfgScale.Value);
					}
				}
				return;
			}
			try
			{
				if ((Object)(object)_nv != (Object)null && _nv.IsValid())
				{
					_nv.Register("FpvDeathsquito_Stun", (Action<long>)RPC_Stun);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("RPC оглушения: " + ex.Message));
			}
			RollStar();
			_lastHealth = (((Object)(object)_ch != (Object)null) ? _ch.GetHealth() : 0f);
			_state = ReadState();
			_prevState = _state;
			if (_state == 0)
			{
				_spin = 0f;
			}
			ApplyVariantTweaks();
			SweepVanillaAudio(learn: true);
		}

		private Vector3 GroundPoint()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			if (RaycastGround(position, out var y))
			{
				return new Vector3(position.x, y, position.z);
			}
			return position - Vector3.up * (0.078f * Plugin.CfgScale.Value - Plugin.CfgYOffset.Value);
		}

		private void UpdateDamage(float dt)
		{
			_hpFrac = 1f;
			if (!Plugin.CfgDamageFx.Value || (Object)(object)_ch == (Object)null)
			{
				return;
			}
			_hpFrac = Mathf.Clamp01(_ch.GetHealth() / Mathf.Max(1f, _ch.GetMaxHealth()));
			if (_hpFrac < Plugin.CfgPropHp.Value)
			{
				PickDeadProp();
			}
			float value = Plugin.CfgSmokeHp.Value;
			if (_hpFrac < value)
			{
				if ((Object)(object)_smoke == (Object)null && (Object)(object)Rig != (Object)null && (Object)(object)Rig.Rig != (Object)null)
				{
					_smoke = ParticleFx.CreateSmoke(Rig.Rig, Plugin.CfgScale.Value);
				}
				float num = 1f - Mathf.Clamp01(_hpFrac / Mathf.Max(0.01f, value));
				ParticleFx.SetSmokeRate(_smoke, Mathf.Lerp(8f, 55f, num));
			}
			else if ((Object)(object)_smoke != (Object)null)
			{
				ParticleFx.SetSmokeRate(_smoke, 0f);
			}
			float value2 = Plugin.CfgSpinHp.Value;
			if (_hpFrac < value2)
			{
				float num2 = 1f - Mathf.Clamp01(_hpFrac / Mathf.Max(0.01f, value2));
				float num3 = Mathf.Lerp(90f, 540f, num2) * (1f + 0.4f * (Mathf.PerlinNoise(_seed + 3f, _age * 2f) - 0.5f));
				_yaw = Mathf.Repeat(_yaw + num3 * dt, 360f);
			}
			else if (Mathf.Abs(Mathf.DeltaAngle(_yaw, 0f)) > 0.5f)
			{
				_yaw = Mathf.LerpAngle(_yaw, 0f, 1f - Mathf.Exp(-2f * dt));
			}
		}

		private void PickDeadProp()
		{
			if (_deadProp >= 0 || (Object)(object)Rig == (Object)null || Rig.Props == null || Rig.Props.Length == 0 || (Object)(object)_nv == (Object)null || !_nv.IsValid())
			{
				return;
			}
			ZDO zDO = _nv.GetZDO();
			if (zDO != null)
			{
				int num = zDO.GetInt("FpvDeathsquito_DeadProp", -1);
				if (num < 0 && _nv.IsOwner())
				{
					num = Random.Range(0, Rig.Props.Length);
					zDO.Set("FpvDeathsquito_DeadProp", num);
				}
				_deadProp = num;
			}
		}

		private void StartTumble()
		{
			//IL_002d: 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)
			Rigidbody[] componentsInChildren = ((Component)this).GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !val.isKinematic)
				{
					val.maxAngularVelocity = 30f;
					val.angularVelocity = Random.onUnitSphere * Random.Range(9f, 16f);
				}
			}
		}

		private void RagdollTick()
		{
			if (!_tumbled && _age > 0.06f)
			{
				_tumbled = true;
				if (Plugin.CfgDamageFx.Value)
				{
					StartTumble();
				}
			}
			if ((Object)(object)_smoke != (Object)null && _age > 8f)
			{
				ParticleFx.SetSmokeRate(_smoke, 0f);
			}
		}

		private void ApplyVariantTweaks()
		{
			if ((Object)(object)_ch == (Object)null)
			{
				return;
			}
			string[] array;
			if (IsAmbusher())
			{
				if (Plugin.CfgStarColor.Value && (Object)(object)Rig != (Object)null && (Object)(object)Rig.Rig != (Object)null)
				{
					DroneBuilder.ApplyStarPaint(Rig.Rig);
				}
				float num = ConfigSync.Get<float>(Plugin.CfgAmbushSpeed);
				if (!(num > 1.001f))
				{
					return;
				}
				int num2 = 0;
				array = new string[3] { "m_flyFastSpeed", "m_flySlowSpeed", "m_runSpeed" };
				foreach (string field in array)
				{
					if (ScaleField(_ch, field, num, 0f))
					{
						num2++;
					}
				}
				if (num2 == 0 && !_warnedSpeed)
				{
					_warnedSpeed = true;
					Plugin.Log.LogWarning((object)"Скорость ждуна: поля скорости Character не найдены — множитель не применён.");
				}
				return;
			}
			float num3 = ConfigSync.Get<float>(Plugin.CfgRangeBonus);
			if (!(num3 > 0f) || !((Object)(object)_ai != (Object)null))
			{
				return;
			}
			int num4 = 0;
			array = new string[2] { "m_viewRange", "m_hearRange" };
			foreach (string field2 in array)
			{
				if (ScaleField(_ai, field2, 1f, num3))
				{
					num4++;
				}
			}
			if (num4 == 0 && !_warnedRange)
			{
				_warnedRange = true;
				Plugin.Log.LogWarning((object)"Дальность обнаружения: поля MonsterAI не найдены — прибавка не применена.");
			}
		}

		private static bool ScaleField(object target, string field, float mul, float add)
		{
			try
			{
				FieldInfo field2 = target.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field2 == null || field2.FieldType != typeof(float))
				{
					return false;
				}
				float num = (float)field2.GetValue(target);
				field2.SetValue(target, num * mul + add);
				if (Plugin.CfgDebug.Value)
				{
					Plugin.Log.LogInfo((object)(field + ": " + num + " -> " + (num * mul + add)));
				}
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Поле " + field + ": " + ex.Message));
				return false;
			}
		}

		private bool IsAmbusher()
		{
			if (ConfigSync.Get<bool>(Plugin.CfgAmbush) && (Object)(object)_ch != (Object)null)
			{
				return _ch.GetLevel() == ConfigSync.Get<int>(Plugin.CfgAmbushLevel);
			}
			return false;
		}

		private void RollStar()
		{
			if (!ConfigSync.Get<bool>(Plugin.CfgAmbush) || (Object)(object)_ch == (Object)null || (Object)(object)_nv == (Object)null || !_nv.IsValid() || !_nv.IsOwner())
			{
				return;
			}
			ZDO zDO = _nv.GetZDO();
			if (zDO != null && zDO.GetInt("FpvDeathsquito_Rolled", 0) == 0)
			{
				zDO.Set("FpvDeathsquito_Rolled", 1);
				if (_ch.GetLevel() <= 1 && !(Random.value * 100f >= ConfigSync.Get<float>(Plugin.CfgStarChance)))
				{
					_ch.SetLevel(ConfigSync.Get<int>(Plugin.CfgAmbushLevel));
					zDO.Set("FpvDeathsquito_State", 0);
				}
			}
		}

		private int ReadState()
		{
			if ((Object)(object)_nv == (Object)null || !_nv.IsValid())
			{
				return _state;
			}
			ZDO zDO = _nv.GetZDO();
			if (zDO != null)
			{
				return zDO.GetInt("FpvDeathsquito_State", (!IsAmbusher()) ? 2 : 0);
			}
			return _state;
		}

		private void SetState(int s)
		{
			_state = s;
			if ((Object)(object)_nv != (Object)null && _nv.IsValid() && _nv.IsOwner())
			{
				ZDO zDO = _nv.GetZDO();
				if (zDO != null)
				{
					zDO.Set("FpvDeathsquito_State", s);
				}
			}
		}

		private void Update()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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)
			if ((Object)(object)Rig == (Object)null || (Object)(object)Rig.Rig == (Object)null)
			{
				return;
			}
			float deltaTime = Time.deltaTime;
			if (deltaTime <= 0f)
			{
				return;
			}
			_age += deltaTime;
			Vector3 position = ((Component)this).transform.position;
			Vector3 val = (position - _lastPos) / deltaTime;
			_lastPos = position;
			if (((Vector3)(ref val)).sqrMagnitude > 900f)
			{
				val = Vector3.zero;
			}
			_vel = Vector3.Lerp(_vel, val, 1f - Mathf.Exp(-8f * deltaTime));
			float magnitude = ((Vector3)(ref _vel)).magnitude;
			if (!IsRagdoll && !_dead && (Object)(object)_ch != (Object)null && _ch.IsDead())
			{
				OnDied();
			}
			if (!IsRagdoll && !_dead)
			{
				_state = ReadState();
				if ((Object)(object)_nv != (Object)null && _nv.IsValid() && _nv.IsOwner())
				{
					ControlOwner(deltaTime);
				}
				if (_state != _prevState)
				{
					OnStateChanged(_prevState, _state);
				}
				_prevState = _state;
				if (_state != 3 && (Object)(object)_stunSrc != (Object)null)
				{
					StopSqueal();
				}
				if (_state == 0)
				{
					DormantVisuals();
				}
				else if (_state == 3)
				{
					StunnedVisuals();
				}
				else
				{
					if ((Object)(object)_loop == (Object)null)
					{
						StartLoop();
						_revT = ((_state == 1) ? 0f : 10f);
					}
					UpdateDamage(deltaTime);
					Tilt(deltaTime, magnitude);
					UpdateAudio(magnitude, deltaTime);
					if (_state == 2)
					{
						_armClock += deltaTime;
						Fuse();
					}
					else if (_state == 4)
					{
						ParryCheck();
					}
				}
			}
			if (IsRagdoll)
			{
				RagdollTick();
			}
			SpinProps(deltaTime, magnitude);
			Blink();
			if (!IsRagdoll && Time.time >= _nextSweep)
			{
				_nextSweep = Time.time + 0.75f;
				SweepVanillaAudio(learn: false);
			}
		}

		private void ControlOwner(float dt)
		{
			if (_state == 0)
			{
				if (!_frozen)
				{
					Freeze();
				}
				if (!_grounded && !TryGround(dt))
				{
					return;
				}
				_scan -= dt;
				if (_scan <= 0f)
				{
					_scan = 0.1f;
					if (ShouldWake(out var target))
					{
						Wake(target);
						return;
					}
				}
				if (HealthDropped())
				{
					Wake(null);
				}
			}
			else if (_state == 1)
			{
				if (!_frozen)
				{
					Freeze();
				}
				LaunchTick(dt);
			}
			else if (_state == 3)
			{
				StunTick(dt);
			}
			else if (_state == 4)
			{
				if (!_frozen)
				{
					Freeze();
				}
				StrikeTick(dt);
			}
			else if (_frozen)
			{
				Release();
			}
		}

		private void BeginStrike()
		{
			_strikeT = 0f;
			_stunRequested = false;
			SetState(4);
		}

		private void StrikeTick(float dt)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			_strikeT += dt;
			if (_stunRequested)
			{
				EnterStun();
			}
			else if (_strikeT >= ConfigSync.Get<float>(Plugin.CfgStrikeTime))
			{
				Detonate(Rig.Rig.position);
			}
		}

		private void EnterStun()
		{
			_stunRequested = false;
			_stunT = 0f;
			_fallV = 0f;
			_fallDist = 0f;
			_stunGrounded = false;
			_armClock = 0f;
			SetState(3);
		}

		private void StunTick(float dt)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			if (!_frozen)
			{
				Freeze();
			}
			_stunT += dt;
			if (!_stunGrounded)
			{
				Vector3 position = ((Component)this).transform.position;
				_fallV += 25f * dt;
				float num = _fallV * dt;
				position.y -= num;
				_fallDist += num;
				float num2 = 0.078f * Plugin.CfgScale.Value - Plugin.CfgYOffset.Value;
				if ((RaycastGround(position, out var y) && position.y <= y + num2) || _fallDist > 40f)
				{
					if (_fallDist <= 40f)
					{
						position.y = y + num2;
					}
					_stunGrounded = true;
				}
				((Component)this).transform.position = position;
			}
			if (_stunT >= ConfigSync.Get<float>(Plugin.CfgStunSeconds))
			{
				_launchT = 0f;
				_launchInit = false;
				SetState(1);
			}
		}

		private void ParryCheck()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if (_sentStun || !ConfigSync.Get<bool>(Plugin.CfgParryStun))
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead())
			{
				return;
			}
			float num = ConfigSync.Get<float>(Plugin.CfgParryRange);
			Vector3 val = ((Character)localPlayer).GetCenterPoint() - Rig.Rig.position;
			if (!(((Vector3)(ref val)).sqrMagnitude > num * num) && ParryTracker.IsParrying())
			{
				_sentStun = true;
				if ((Object)(object)_nv != (Object)null && _nv.IsValid())
				{
					_nv.InvokeRPC("FpvDeathsquito_Stun", Array.Empty<object>());
				}
			}
		}

		private void RPC_Stun(long sender)
		{
			if ((Object)(object)_nv != (Object)null && _nv.IsValid() && _nv.IsOwner() && _state == 4)
			{
				_stunRequested = true;
			}
		}

		private void OnStateChanged(int from, int to)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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)
			Vector3 position = Rig.Rig.position;
			if ((from == 0 || from == 3) && (to == 1 || to == 2))
			{
				if (Plugin.CfgStarSound.Value && IsAmbusher())
				{
					DroneAudio.PlayAt(DroneAudio.Launch, position, Plugin.CfgVolume.Value, 3f, 65f, 1f);
				}
				ParticleFx.Dust(GroundPoint(), Plugin.CfgScale.Value);
				return;
			}
			switch (to)
			{
			case 4:
				_sentStun = false;
				DroneAudio.PlayAt(DroneAudio.Warning, position, Plugin.CfgVolume.Value, 3f, 45f, 1f);
				break;
			case 3:
				DroneAudio.PlayAt(DroneAudio.Zap, position, Plugin.CfgVolume.Value, 3f, 45f, 1f);
				DroneFx.FlashColor(position, 6f, 3.5f, 0.18f, new Color(0.55f, 0.75f, 1f));
				break;
			}
		}

		private void StunnedVisuals()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_loop != (Object)null)
			{
				_loop.Stop();
				Object.Destroy((Object)(object)_loop);
				_loop = null;
			}
			if ((Object)(object)_stunSrc == (Object)null)
			{
				StartSqueal();
			}
			float num = Time.time + _seed;
			Rig.Rig.localRotation = Quaternion.Euler(9f * Mathf.Sin(num * 13f), 0f, 15f + 6f * Mathf.Sin(num * 9f));
			Rig.Rig.localPosition = Vector3.zero;
		}

		private void StartSqueal()
		{
			if (!((Object)(object)Rig == (Object)null) && !((Object)(object)Rig.Rig == (Object)null))
			{
				_stunSrc = ((Component)Rig.Rig).gameObject.AddComponent<AudioSource>();
				_stunSrc.clip = DroneAudio.Squeal;
				_stunSrc.loop = true;
				_stunSrc.playOnAwake = false;
				_stunSrc.spatialBlend = 1f;
				_stunSrc.dopplerLevel = 0.3f;
				DroneAudio.ApplyRolloff(_stunSrc, 2f, Plugin.CfgMaxDist.Value);
				_stunSrc.volume = Plugin.CfgVolume.Value * 0.9f;
				AudioMixerGroup val = DroneAudio.Group;
				if ((Object)(object)val != (Object)null)
				{
					_stunSrc.outputAudioMixerGroup = val;
				}
				_stunSrc.Play();
			}
		}

		private void StopSqueal()
		{
			if (!((Object)(object)_stunSrc == (Object)null))
			{
				_stunSrc.Stop();
				Object.Destroy((Object)(object)_stunSrc);
				_stunSrc = null;
			}
		}

		private void Freeze()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_ai == (Object)null)
			{
				_ai = ((Component)this).GetComponent<MonsterAI>();
			}
			if ((Object)(object)_ai != (Object)null)
			{
				((Behaviour)_ai).enabled = false;
			}
			if ((Object)(object)_body == (Object)null)
			{
				_body = ((Component)this).GetComponent<Rigidbody>();
			}
			if ((Object)(object)_body != (Object)null)
			{
				_origConstraints = _body.constraints;
				_body.constraints = (RigidbodyConstraints)126;
			}
			_frozen = true;
		}

		private void Release()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_body != (Object)null)
			{
				_body.constraints = _origConstraints;
			}
			_frozen = false;
			if ((Object)(object)_ai == (Object)null)
			{
				_ai = ((Component)this).GetComponent<MonsterAI>();
			}
			if ((Object)(object)_ai != (Object)null)
			{
				((Behaviour)_ai).enabled = true;
				CallOptional(_ai, "SetHuntPlayer", true);
				CallOptional(_ai, "Alert");
			}
		}

		private static void CallOptional(object target, string method, params object[] args)
		{
			try
			{
				Type[] array = new Type[args.Length];
				for (int i = 0; i < args.Length; i++)
				{
					array[i] = args[i].GetType();
				}
				MethodInfo method2 = target.GetType().GetMethod(method, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, array, null);
				if (method2 != null)
				{
					method2.Invoke(target, args);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Не удалось вызвать " + method + ": " + ex.Message));
			}
		}

		private static bool RaycastGround(Vector3 p, out float y)
		{
			//IL_0042: 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_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_0057: 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)
			if (_groundMask == -1)
			{
				int mask = LayerMask.GetMask(new string[1] { "terrain" });
				_groundMask = ((mask != 0) ? mask : LayerMask.GetMask(new string[2] { "Default", "static_solid" }));
			}
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(p + Vector3.up * 15f, Vector3.down, ref val, 80f, _groundMask, (QueryTriggerInteraction)1))
			{
				y = ((RaycastHit)(ref val)).point.y;
				return true;
			}
			y = 0f;
			return false;
		}

		private bool TryGround(float dt)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			if (RaycastGround(position, out var y))
			{
				float num = 0.078f * Plugin.CfgScale.Value - Plugin.CfgYOffset.Value;
				((Component)this).transform.position = new Vector3(position.x, y + num, position.z);
				((Component)this).transform.rotation = Quaternion.Euler(0f, ((Component)this).transform.eulerAngles.y, 0f);
				_grounded = true;
				return true;
			}
			_groundTimer += dt;
			if (_groundTimer > 4f)
			{
				Plugin.Log.LogWarning((object)"Ждун: поверхность под ним не найдена, работает как обычный дрон.");
				SetState(2);
			}
			return false;
		}

		private bool ShouldWake(out Player target)
		{
			//IL_000e: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			target = null;
			Vector3 val = Rig.Rig.position + Vector3.up * 0.1f;
			float num = ConfigSync.Get<float>(Plugin.CfgWakeRadius);
			float num2 = ConfigSync.Get<float>(Plugin.CfgHearRadius);
			List<Player> allPlayers = Player.GetAllPlayers();
			for (int i = 0; i < allPlayers.Count; i++)
			{
				Player val2 = allPlayers[i];
				if (!((Object)(object)val2 == (Object)null) && !((Character)val2).IsDead())
				{
					Vector3 centerPoint = ((Character)val2).GetCenterPoint();
					float num3 = Vector3.Distance(centerPoint, val);
					if (num3 <= num2)
					{
						target = val2;
						return true;
					}
					if (!(num3 > num) && (!ConfigSync.Get<bool>(Plugin.CfgLineOfSight) || !Physics.Linecast(val, centerPoint, LosMask, (QueryTriggerInteraction)1)))
					{
						target = val2;
						return true;
					}
				}
			}
			return false;
		}

		private bool HealthDropped()
		{
			if ((Object)(object)_ch == (Object)null)
			{
				return false;
			}
			float health = _ch.GetHealth();
			bool result = health < _lastHealth - 0.01f;
			_lastHealth = health;
			return result;
		}

		private void Wake(Player target)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target != (Object)null)
			{
				Vector3 val = ((Character)target).GetCenterPoint() - ((Component)this).transform.position;
				val.y = 0f;
				if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
				{
					((Component)this).transform.rotation = Quaternion.LookRotation(((Vector3)(ref val)).normalized);
				}
			}
			_launchT = 0f;
			_launchInit = false;
			SetState(1);
		}

		private void LaunchTick(float dt)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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)
			if (!_launchInit)
			{
				_launchStartY = ((Component)this).transform.position.y;
				_launchInit = true;
			}
			_launchT += dt;
			float num = Mathf.Max(0.1f, ConfigSync.Get<float>(Plugin.CfgTakeoffTime));
			float num2 = Mathf.Clamp01(_launchT / num);
			float num3 = 1f - (1f - num2) * (1f - num2);
			Vector3 position = ((Component)this).transform.position;
			position.y = _launchStartY + ConfigSync.Get<float>(Plugin.CfgTakeoffHeight) * num3;
			((Component)this).transform.position = position;
			if (num2 >= 1f)
			{
				SetState(2);
				Release();
			}
		}

		private void DormantVisuals()
		{
			//IL_004c: 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)
			if ((Object)(object)_loop != (Object)null)
			{
				_loop.Stop();
				Object.Destroy((Object)(object)_loop);
				_loop = null;
			}
			_pitch = 0f;
			_roll = 0f;
			Rig.Rig.localRotation = Quaternion.identity;
			Rig.Rig.localPosition = Vector3.zero;
		}

		private void StartLoop()
		{
			if (!((Object)(object)Rig == (Object)null))
			{
				_loop = ((Component)Rig.Rig).gameObject.AddComponent<AudioSource>();
				_heavy = Plugin.CfgStarSound.Value && IsAmbusher();
				_loop.clip = (_heavy ? DroneAudio.LoopStar : DroneAudio.Loop);
				_loop.loop = true;
				_loop.playOnAwake = false;
				_loop.spatialBlend = 1f;
				DroneAudio.ApplyRolloff(_loop, 2.5f, Plugin.CfgMaxDist.Value);
				_loop.dopplerLevel = 0.6f;
				_loop.volume = Plugin.CfgVolume.Value;
				AudioMixerGroup val = DroneAudio.Group;
				if ((Object)(object)val != (Object)null)
				{
					_loop.outputAudioMixerGroup = val;
				}
				if ((Object)(object)_loop.clip != (Object)null)
				{
					_loop.time = Random.value * _loop.clip.length * 0.99f;
				}
				_loop.Play();
			}
		}

		private void Tilt(float dt, float speed)
		{
			//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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.InverseTransformDirection(_vel);
			float num = Mathf.Clamp(val.z * 5f, -20f, 55f) - Mathf.Clamp(_vel.y * 1.5f, 0f, 25f);
			float num2 = Mathf.Clamp((0f - val.x) * 7f, -35f, 35f);
			float num3 = 1f - Mathf.Exp(-6f * dt);
			_pitch = Mathf.Lerp(_pitch, num, num3);
			_roll = Mathf.Lerp(_roll, num2, num3);
			float num4 = ((_deadProp >= 0 && _propK != null && _deadProp < _propK.Length) ? (1f - _propK[_deadProp]) : 0f);
			float num5 = (1.6f + speed * 0.15f) * (1f + num4 * 2.5f);
			float num6 = (Mathf.PerlinNoise(_seed, _age * 7f) - 0.5f) * num5;
			float num7 = (Mathf.PerlinNoise(_seed + 11f, _age * 7f) - 0.5f) * num5;
			float num8 = 0f;
			float num9 = 0f;
			if (num4 > 0f)
			{
				float num10 = ((_deadProp == 0 || _deadProp == 1) ? 1f : (-1f));
				num8 = ((_deadProp == 0 || _deadProp == 3) ? 1f : (-1f)) * 14f * num4;
				num9 = (0f - num10) * 14f * num4;
			}
			Rig.Rig.localRotation = Quaternion.Euler(_pitch + num6 + num8, _yaw, _roll + num7 + num9);
			Rig.Rig.localPosition = new Vector3(0f, (Mathf.PerlinNoise(_seed + 5f, _age * 5f) - 0.5f) * 0.02f, 0f);
		}

		private void SpinProps(float dt, float speed)
		{
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			Transform[] props = Rig.Props;
			if (props == null || _ang == null)
			{
				return;
			}
			float num = ((!_dead && _state != 0 && _state != 3) ? 1f : 0f);
			if (!_dead && _state == 3)
			{
				num = ((Mathf.PerlinNoise(_seed, Time.time * 6f) > 0.55f) ? 0.25f : 0f);
			}
			_spin = Mathf.MoveTowards(_spin, num, dt * ((num > _spin) ? 4f : (_dead ? 0.7f : 8f)));
			float num2 = Mathf.Lerp(15000f, 26000f, Mathf.Clamp01(speed / 12f)) * _spin;
			for (int i = 0; i < props.Length; i++)
			{
				if (!((Object)(object)props[i] == (Object)null))
				{
					_propK[i] = Mathf.MoveTowards(_propK[i], (!_dead && i == _deadProp) ? 0f : 1f, dt * 1f);
					float num3 = ((Rig.PropDir != null && i < Rig.PropDir.Length) ? Rig.PropDir[i] : 1f);
					_ang[i] = Mathf.Repeat(_ang[i] + num2 * _propK[i] * dt * num3 * (0.85f + 0.3f * Random.value), 360f);
					props[i].localRotation = Quaternion.Euler(0f, _ang[i], 0f);
					if ((Object)(object)_blur[i] != (Object)null)
					{
						_blur[i].enabled = _spin > 0.3f && _propK[i] > 0.45f;
					}
				}
			}
		}

		private void Blink()
		{
			Renderer[] leds = Rig.Leds;
			if (leds == null || leds.Length < 2)
			{
				return;
			}
			bool flag = Mathf.Repeat(Time.time * 2.2f + _seed, 1f) < 0.5f;
			if (!_dead && _state == 3)
			{
				if ((Object)(object)leds[0] != (Object)null)
				{
					leds[0].enabled = false;
				}
				if ((Object)(object)leds[1] != (Object)null)
				{
					leds[1].enabled = Mathf.Repeat(Time.time * 9f, 1f) < 0.5f;
				}
				return;
			}
			bool flag2 = !_dead && _state != 0 && _spin > 0.4f;
			if ((Object)(object)leds[0] != (Object)null)
			{
				leds[0].enabled = flag2 && flag;
			}
			if ((Object)(object)leds[1] != (Object)null)
			{
				leds[1].enabled = flag2 && !flag;
			}
		}

		private void UpdateAudio(float speed, float dt)
		{
			if (!((Object)(object)_loop == (Object)null))
			{
				_revT += dt;
				float num = Mathf.Clamp01(_revT / 0.7f);
				float num2 = 1f - (1f - num) * (1f - num);
				float num3 = Mathf.Clamp01(speed / 14f);
				float num4 = (_heavy ? 0.85f : 0.92f);
				float num5 = (_heavy ? 1.75f : 1.55f);
				_loop.pitch = (Mathf.Lerp(num4, num5, num3) + (Mathf.PerlinNoise(_seed, Time.time * 3f) - 0.5f) * 0.04f) * Mathf.Lerp(0.55f, 1f, num2);
				float num6 = Plugin.CfgVolume.Value * Mathf.Lerp(0.7f, 1f, num3) * Mathf.Lerp(0.5f, 1f, num2);
				_loop.volume = (_heavy ? Mathf.Min(1f, num6 * 1.15f) : num6);
				if (Plugin.CfgDamageFx.Value && _hpFrac < Plugin.CfgPropHp.Value)
				{
					float num7 = Mathf.Clamp01(1f - _hpFrac / Mathf.Max(0.01f, Plugin.CfgPropHp.Value));
					AudioSource loop = _loop;
					loop.pitch *= (1f - 0.08f * num7) * (1f + 0.07f * num7 * Mathf.Sin(Time.time * 11f));
				}
			}
		}

		private void SweepVanillaAudio(bool learn)
		{
			((Component)((Component)this).transform).GetComponentsInChildren<AudioSource>(true, Tmp);
			if (learn)
			{
				DroneAudio.LearnGroup(Tmp);
			}
			if (!Plugin.CfgMuteVanilla.Value)
			{
				return;
			}
			for (int i = 0; i < Tmp.Count; i++)
			{
				AudioSource val = Tmp[i];
				if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)_loop && (Object)(object)val != (Object)(object)_stunSrc)
				{
					val.mute = true;
				}
			}
		}

		private void OnDied()
		{
			_dead = true;
			if ((Object)(object)_loop != (Object)null)
			{
				_loop.Stop();
			}
		}

		private void Fuse()
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			if (!ConfigSync.Get<bool>(Plugin.CfgKamikaze) || _detonated || (Object)(object)_ch == (Object)null || (Object)(object)_nv == (Object)null || !_nv.IsValid() || !_nv.IsOwner() || _armClock < ConfigSync.Get<float>(Plugin.CfgArmDelay) || _ch.IsDead() || _ch.IsTamed())
			{
				return;
			}
			Vector3 position = Rig.Rig.position;
			float num = ConfigSync.Get<float>(Plugin.CfgTrigger) * ConfigSync.Get<float>(Plugin.CfgTrigger);
			List<Player> allPlayers = Player.GetAllPlayers();
			for (int i = 0; i < allPlayers.Count; i++)
			{
				Player val = allPlayers[i];
				if ((Object)(object)val == (Object)null || ((Character)val).IsDead())
				{
					continue;
				}
				Vector3 val2 = ((Character)val).GetCenterPoint() - position;
				if (((Vector3)(ref val2)).sqrMagnitude <= num)
				{
					if (ConfigSync.Get<float>(Plugin.CfgStrikeTime) <= 0.01f)
					{
						Detonate(position);
					}
					else
					{
						BeginStrike();
					}
					break;
				}
			}
		}

		private void Detonate(Vector3 pos)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			_detonated = true;
			DroneFx.Broadcast(pos, 0);
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				ZNetScene.instance.Destroy(((Component)this).gameObject);
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		internal void OnShotDown()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			if (!_reported && !IsRagdoll && !_detonated)
			{
				_reported = true;
				Vector3 pos = (((Object)(object)Rig != (Object)null && (Object)(object)Rig.Rig != (Object)null) ? Rig.Rig.position : ((Component)this).transform.position);
				if (ConfigSync.Get<bool>(Plugin.CfgShotDownDetonates))
				{
					DroneFx.Broadcast(pos, 0);
				}
				else
				{
					DroneFx.Broadcast(pos, 1);
				}
			}
		}
	}
	internal sealed class DroneRig : MonoBehaviour
	{
		public Transform Rig;

		public Transform[] Props;

		public float[] PropDir;

		public Renderer[] Leds;
	}
	internal static class DroneBuilder
	{
		private sealed class PartList
		{
			private readonly Dictionary<string, List<CombineInstance>> _d = new Dictionary<string, List<CombineInstance>>();

			public void Add(string mat, Mesh m, Vector3 pos, Quaternion rot)
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				if (!_d.TryGetValue(mat, out var value))
				{
					value = new List<CombineInstance>();
					_d[mat] = value;
				}
				List<CombineInstance> list = value;
				CombineInstance item = default(CombineInstance);
				((CombineInstance)(ref item)).mesh = m;
				((CombineInstance)(ref item)).transform = Matrix4x4.TRS(pos, rot, Vector3.one);
				list.Add(item);
			}

			public void Flush(Transform parent, Func<string, Material> mats)
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				foreach (KeyValuePair<string, List<CombineInstance>> item in _d)
				{
					Mesh val = new Mesh
					{
						name = "fpv_" + item.Key
					};
					val.CombineMeshes(item.Value.ToArray(), true, true);
					val.RecalculateBounds();
					((Object)val).hideFlags = (HideFlags)61;
					GameObject val2 = new GameObject("Part_" + item.Key);
					val2.transform.SetParent(parent, false);
					val2.AddComponent<MeshFilter>().sharedMesh = val;
					MeshRenderer obj = val2.AddComponent<MeshRenderer>();
					((Renderer)obj).sharedMaterial = mats(item.Key);
					((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1;
					((Renderer)obj).receiveShadows = true;
				}
			}
		}

		private static readonly Dictionary<string, Material> Mats = new Dictionary<string, Material>();

		private static readonly Dictionary<string, Material> StarMats = new Dictionary<string, Material>();

		internal static void ApplyStarPaint(Transform rig)
		{
			//IL_0015: 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)
			Recolor(rig, "olive", new Color(1.5f, 1.2f, 1.15f));
			Recolor(rig, "orange", new Color(0.85f, 0.1f, 0.06f));
		}

		private static void Recolor(Transform rig, string key, Color c)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rig == (Object)null || !Mats.TryGetValue(key, out var value))
			{
				return;
			}
			Transform val = rig.Find("Part_" + key);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			if (!StarMats.TryGetValue(key, out var value2) || (Object)(object)value2 == (Object)null)
			{
				value2 = new Material(value)
				{
					hideFlags = (HideFlags)61
				};
				if (value2.HasProperty("_Color"))
				{
					value2.SetColor("_Color", c);
				}
				StarMats[key] = value2;
			}
			((Renderer)component).sharedMaterial = value2;
		}

		private static Shader FindShader(params string[] names)
		{
			for (int i = 0; i < names.Length; i++)
			{
				Shader val = Shader.Find(names[i]);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		private static Material MakeMat(Shader s, Texture tex, Color c, float metallic, float gloss)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(s)
			{
				hideFlags = (HideFlags)61
			};
			if (val.HasProperty("_MainTex"))
			{
				val.SetTexture("_MainTex", tex);
			}
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", c);
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", metallic);
			}
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", gloss);
			}
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", gloss);
			}
			return val;
		}

		private static Vector2[] Scale(Vector2[] p, float k)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			Vector2[] array = (Vector2[])(object)new Vector2[p.Length];
			for (int i = 0; i < p.Length; i++)
			{
				array[i] = p[i] * k;
			}
			return array;
		}

		internal static GameObject Build(Shader lit)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_01ab: 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_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: 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_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Expected O, but got Unknown
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Expected O, but got Unknown
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_050e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_0524: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_053a: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0550: Unknown result type (might be due to invalid IL or missing references)
			//IL_0555: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_060d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0612: Unknown result type (might be due to invalid IL or missing references)
			//IL_0617: Unknown result type (might be due to invalid IL or missing references)
			//IL_061d: Unknown result type (might be due to invalid IL or missing references)
			//IL_061f: Unknown result type (might be due to invalid IL or missing references)
			//IL_062d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0639: Unknown result type (might be due to invalid IL or missing references)
			//IL_0640: Unknown result type (might be due to invalid IL or missing references)
			//IL_0645: Unknown result type (might be due to invalid IL or missing references)
			//IL_0658: Unknown result type (might be due to invalid IL or missing references)
			//IL_0664: Unknown result type (might be due to invalid IL or missing references)
			//IL_066b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0670: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_068f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0696: Unknown result type (might be due to invalid IL or missing references)
			//IL_069b: 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_06eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0712: Unknown result type (might be due to invalid IL or missing references)
			//IL_0717: Unknown result type (might be due to invalid IL or missing references)
			//IL_0739: Unknown result type (might be due to invalid IL or missing references)
			//IL_073e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0772: Unknown result type (might be due to invalid IL or missing references)
			//IL_0777: Unknown result type (might be due to invalid IL or missing references)
			//IL_0788: Unknown result type (might be due to invalid IL or missing references)
			//IL_078d: Unknown result type (might be due to invalid IL or missing references)
			//IL_079e: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0824: Unknown result type (might be due to invalid IL or missing references)
			//IL_083d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0842: Unknown result type (might be due to invalid IL or missing references)
			//IL_0860: Unknown result type (might be due to invalid IL or missing references)
			//IL_0884: Unknown result type (might be due to invalid IL or missing references)
			//IL_0889: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_090c: 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_0944: Unknown result type (might be due to invalid IL or missing references)
			//IL_094e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0950: Unknown result type (might be due to invalid IL or missing references)
			//IL_096b: 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_0982: Unknown result type (might be due to invalid IL or missing references)
			//IL_0993: Unknown result type (might be due to invalid IL or missing references)
			//IL_0998: Unknown result type (might be due to invalid IL or missing references)
			//IL_099d: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_09cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_09db: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a15: 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_0a28: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a2d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a32: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a37: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a6e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a73: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a78: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a7d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0acd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b0a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b0f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b14: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b91: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b96: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bb6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bbb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bcc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bd1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bf8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bfd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c0e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c13: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c20: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c22: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c48: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c4d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c5e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c63: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c74: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c79: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c8a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c8f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cb6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cbb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ccc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cd1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ce2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ce7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cf8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cfd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d0f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d14: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d23: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d47: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d58: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d5d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d62: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d8a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d9b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0da0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0da5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0db5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dc6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dcb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0deb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e0a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e17: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e1c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e39: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e46: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e4b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e69: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b35: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b37: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b48: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b4d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b52: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b57: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e93: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e98: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ea3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ea5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0eb6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ebb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ec0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ec5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f18: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f5c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f61: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f74: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f94: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f9e: Unknown result type (might be due to invalid IL or missing references)
			//IL_103a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1041: Expected O, but got Unknown
			//IL_107d: Unknown result type (might be due to invalid IL or missing references)
			//IL_10a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_10f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_10fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_110f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1124: Unknown result type (might be due to invalid IL or missing references)
			//IL_112e: Unknown result type (might be due to invalid IL or missing references)
			Mats.Clear();
			Shader unlit = FindShader("Sprites/Default", "UI/Default", "Legacy Shaders/Particles/Alpha Blended", "Unlit/Transparent");
			Texture white = (Texture)(object)Texture2D.whiteTexture;
			Mats["carbon"] = MakeMat(lit, (Texture)(object)TextureFactory.Carbon(), Color.white, 0.25f, 0.55f);
			Mats["olive"] = MakeMat(lit, (Texture)(object)TextureFactory.Olive(), Color.white, 0.15f, 0.3f);
			Mats["tape"] = MakeMat(lit, (Texture)(object)TextureFactory.Tape(), Color.white, 0f, 0.25f);
			Mats["metal"] = MakeMat(lit, (Texture)(object)TextureFactory.Metal(), Color.white, 0.85f, 0.55f);
			Mats["motor"] = MakeMat(lit, (Texture)(object)TextureFactory.Metal(), new Color(0.3f, 0.3f, 0.32f), 0.9f, 0.65f);
			Mats["orange"] = MakeMat(lit, white, new Color(0.95f, 0.42f, 0.05f), 0f, 0.35f);
			Mats["yellow"] = MakeMat(lit, white, new Color(0.95f, 0.78f, 0.08f), 0f, 0.4f);
			Mats["glass"] = MakeMat(lit, white, new Color(0.03f, 0.06f, 0.14f), 0.9f, 0.95f);
			Mats["white"] = MakeMat(lit, white, new Color(0.85f, 0.85f, 0.82f), 0f, 0.4f);
			Mats["pcb"] = MakeMat(lit, (Texture)(object)TextureFactory.Pcb(), Color.white, 0.2f, 0.5f);
			Mats["antenna"] = MakeMat(lit, (Texture)(object)TextureFactory.Tape(), new Color(0.6f, 0.6f, 0.6f), 0f, 0.5f);
			Mats["prop"] = MakeMat(lit, (Texture)(object)TextureFactory.Carbon(), new Color(1.6f, 1.6f, 1.7f), 0f, 0.45f);
			Func<Color, Material> func = delegate(Color c)
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Expected O, but got Unknown
				//IL_001a: 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)
				if ((Object)(object)unlit == (Object)null)
				{
					return MakeMat(lit, white, c, 0f, 0.1f);
				}
				Material val17 = new Material(unlit)
				{
					hideFlags = (HideFlags)61
				};
				if (val17.HasProperty("_Color"))
				{
					val17.SetColor("_Color", c);
				}
				return val17;
			};
			Mats["ledA"] = func(new Color(0.1f, 1f, 0.2f, 1f));
			Mats["ledB"] = func(new Color(1f, 0.1f, 0.05f, 1f));
			Material val = (((Object)(object)unlit != (Object)null) ? func(new Color(0.8f, 0.85f, 0.9f, 0.09f)) : null);
			GameObject val2 = new GameObject("FPV_Template");
			GameObject val3 = new GameObject("Rig");
			val3.transform.SetParent(val2.transform, false);
			DroneRig droneRig = val2.AddComponent<DroneRig>();
			droneRig.Rig = val3.transform;
			PartList partList = new PartList();
			Vector2[] p = (Vector2[])(object)new Vector2[8]
			{
				new Vector2(-0.026f, -0.075f),
				new Vector2(0.026f, -0.075f),
				new Vector2(0.034f, -0.02f),
				new Vector2(0.034f, 0.05f),
				new Vector2(0.02f, 0.085f),
				new Vector2(-0.02f, 0.085f),
				new Vector2(-0.034f, 0.05f),
				new Vector2(-0.034f, -0.02f)
			};
			partList.Add("carbon", MeshFactory.Extrude("plate_bottom", p, 0.003f), new Vector3(0f, -0.004f, 0f), Quaternion.identity);
			partList.Add("carbon", MeshFactory.Extrude("plate_top", Scale(p, 0.88f), 0.003f), new Vector3(0f, 0.0395f, 0f), Quaternion.identity);
			Mesh m = MeshFactory.Extrude("arm", (Vector2[])(object)new Vector2[4]
			{
				new Vector2(-0.0135f, 0.02f),
				new Vector2(0.0135f, 0.02f),
				new Vector2(0.0105f, 0.162f),
				new Vector2(-0.0105f, 0.162f)
			}, 0.005f);
			Mesh m2 = MeshFactory.Cylinder("motor_base", 0.013f, 0.004f, 16);
			Mesh m3 = MeshFactory.Cylinder("motor_bell", 0.0165f, 0.016f, 20);
			Mesh m4 = MeshFactory.Cylinder("motor_ring", 0.0168f, 0.0022f, 20);
			float[] array = new float[4] { 45f, 135f, 225f, 315f };
			Vector3[] array2 = (Vector3[])(object)new Vector3[4];
			for (int num = 0; num < 4; num++)
			{
				Quaternion val4 = Quaternion.Euler(0f, array[num], 0f);
				partList.Add("carbon", m, Vector3.zero, val4);
				Vector3 val5 = (array2[num] = val4 * new Vector3(0f, 0f, 0.155f));
				partList.Add("metal", m2, new Vector3(val5.x, 0.0045f, val5.z), Quaternion.identity);
				partList.Add("motor", m3, new Vector3(val5.x, 0.0145f, val5.z), Quaternion.identity);
				partList.Add("orange", m4, new Vector3(val5.x, 0.0125f, val5.z), Quaternion.identity);
			}
			Mesh m5 = MeshFactory.Box("board", new Vector3(0.036f, 0.0016f, 0.036f));
			partList.Add("pcb", m5, new Vector3(0f, 0.01f, 0f), Quaternion.identity);
			partList.Add("pcb", m5, new Vector3(0f, 0.018f, 0f), Quaternion.identity);
			partList.Add("pcb", m5, new Vector3(0f, 0.026f, 0f), Quaternion.identity);
			Mesh m6 = MeshFactory.Cylinder("standoff", 0.0035f, 0.036f, 10);
			Vector2[] array3 = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0.025f, 0.055f),
				new Vector2(-0.025f, 0.055f),
				new Vector2(0.025f, -0.055f),
				new Vector2(-0.025f, -0.055f)
			};
			foreach (Vector2 val6 in array3)
			{
				partList.Add("metal", m6, new Vector3(val6.x, 0.0175f, val6.y), Quaternion.identity);
			}
			partList.Add("tape", MeshFactory.Box("battery", new Vector3(0.046f, 0.032f, 0.1f)), new Vector3(0f, 0.057f, -0.008f), Quaternion.identity);
			Mesh m7 = MeshFactory.Box("strap", new Vector3(0.049f, 0.036f, 0.008f));
			partList.Add("orange", m7, new Vector3(0f, 0.057f, -0.038f), Quaternion.identity);
			partList.Add("orange", m7, new Vector3(0f, 0.057f, 0.022f), Quaternion.identity);
			partList.Add("yellow", MeshFactory.Box("xt60", new Vector3(0.016f, 0.009f, 0.02f)), new Vector3(0f, 0.052f, -0.068f), Quaternion.identity);
			Quaternion val7 = Quaternion.Euler(-32f, 0f, 0f);
			Vector3 val8 = default(Vector3);
			((Vector3)(ref val8))..ctor(0f, 0.053f, 0.075f);
			partList.Add("tape", MeshFactory.Box("cam_body", new Vector3(0.022f, 0.022f, 0.026f)), val8, val7);
			Mesh m8 = MeshFactory.Box("cam_plate", new Vector3(0.003f, 0.03f, 0.03f));
			partList.Add("carbon", m8, val8 + val7 * new Vector3(0.0135f, 0f, 0f), val7);
			partList.Add("carbon", m8, val8 + val7 * new Vector3(-0.0135f, 0f, 0f), val7);
			Quaternion rot = val7 * Quaternion.Euler(90f, 0f, 0f);
			partList.Add("metal", MeshFactory.Cylinder("cam_lens", 0.0075f, 0.01f, 16), val8 + val7 * new Vector3(0f, 0f, 0.018f), rot);
			partList.Add("glass", MeshFactory.Cylinder("cam_glass", 0.0062f, 0.0012f, 16), val8 + val7 * new Vector3(0f, 0f, 0.0235f), rot);
			Mesh m9 = MeshFactory.Cylinder("whip", 0.0016f, 0.12f, 6);
			Mesh m10 = MeshFactory.Cylinder("sleeve", 0.0035f, 0.035f, 8);
			Vector3 val10 = default(Vector3);
			for (int num3 = -1; num3 <= 1; num3 += 2)
			{
				Quaternion val9 = Quaternion.Euler(-28f, 0f, -14f * (float)num3);
				((Vector3)(ref val10))..ctor(0.012f * (float)num3, 0.043f, -0.072f);
				partList.Add("antenna", m9, val10 + val9 * new Vector3(0f, 0.06f, 0f), val9);
				partList.Add((num3 > 0) ? "white" : "antenna", m10, val10 + val9 * new Vector3(0f, 0.0175f, 0f), val9);
			}
			Vector3 val11 = default(Vector3);
			((Vector3)(ref val11))..ctor(0f, -0.05f, 0.006f);
			Quaternion rot2 = Quaternion.Euler(90f, 0f, 0f);
			partList.Add("olive", MeshFactory.Lathe("wh_body", (Vector2[])(object)new Vector2[5]
			{
				new Vector2(0f, -0.13f),
				new Vector2(0.008f, -0.13f),
				new Vector2(0.008f, -0.08f),
				new Vector2(0.027f, -0.045f),
				new Vector2(0.027f, 0.048f)
			}, 24, smooth: false), val11, rot2);
			partList.Add("olive", MeshFactory.Lathe("wh_nose", (Vector2[])(object)new Vector2[10]
			{
				new Vector2(0.027f, 0.048f),
				new Vector2(0.0262f, 0.056f),
				new Vector2(0.0242f, 0.066f),
				new Vector2(0.0215f, 0.077f),
				new Vector2(0.018f, 0.088f),
				new Vector2(0.0138f, 0.099f),
				new Vector2(0.0095f, 0.108f),
				new Vector2(0.0055f, 0.115f),
				new Vector2(0.0035f, 0.119f),
				new Vector2(0f, 0.119f)
			}, 24, smooth: true), val11, rot2);
			partList.Add("metal", MeshFactory.Cylinder("wh_fuze", 0.0045f, 0.014f, 12), val11 + new Vector3(0f, 0f, 0.122f), rot2);
			Mesh m11 = MeshFactory.Cylinder("wh_tape", 0.0277f, 0.014f, 24);
			partList.Add("tape", m11, val11 + new Vector3(0f, 0f, -0.02f), rot2);
			partList.Add("tape", m11, val11 + new Vector3(0f, 0f, 0.03f), rot2);
			Mesh m12 = MeshFactory.Box("wh_mount", new Vector3(0.012f, 0.022f, 0.014f));
			partList.Add("tape", m12, new Vector3(0f, -0.0135f, val11.z - 0.02f), Quaternion.identity);
			partList.Add("tape", m12, new Vector3(0f, -0.0135f, val11.z + 0.03f), Quaternion.identity);
			Mesh m13 = MeshFactory.Box("wh_fin", new Vector3(0.0015f, 0.022f, 0.032f));
			for (int num4 = 0; num4 < 4; num4++)
			{
				Quaternion val12 = Quaternion.Euler(0f, 0f, (float)num4 * 90f + 45f);
				partList.Add("metal", m13, val11 + val12 * new Vector3(0f, 0.018f, -0.105f), val12);
			}
			partList.Flush(val3.transform, (string key) => Mats[key]);
			Mesh sharedMesh = MeshFactory.Box("led", new Vector3(0.005f, 0.003f, 0.005f));
			List<Renderer> list = new List<Renderer>();
			string[] array4 = new string[2] { "ledA", "ledB" };