Decompiled source of BigChoppa v3.0.3

BigChoppa.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using LobbyNetworking;
using Microsoft.CodeAnalysis;
using Mirror;
using Rewired;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BigChoppa")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6a5c10082f66590222a68ee59d67be1fd68254b3")]
[assembly: AssemblyProduct("BigChoppa")]
[assembly: AssemblyTitle("BigChoppa")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BigChoppa
{
	internal static class ChoppaAudio
	{
		private const int Rate = 44100;

		private static AudioClip rotorClip;

		private static AudioClip turbineClip;

		private static AudioClip[] bonkClips;

		private static AudioMixerGroup mixerGroup;

		private static bool mixerSearched;

		public static void Attach(Helicopter heli)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (EnsureClips())
			{
				GameObject val = new GameObject("Audio");
				val.transform.SetParent(((Component)heli).transform, false);
				val.transform.localPosition = new Vector3(0f, 2.5f, 0f) * heli.Scale;
				heli.RotorAudio = Loop(val, rotorClip, 12f * heli.Scale);
				heli.TurbineAudio = Loop(val, turbineClip, 6f * heli.Scale);
			}
		}

		private static AudioSource Loop(GameObject go, AudioClip clip, float minDistance)
		{
			AudioSource obj = go.AddComponent<AudioSource>();
			Setup(obj, minDistance);
			obj.clip = clip;
			obj.loop = true;
			obj.volume = 0f;
			return obj;
		}

		private static void Setup(AudioSource s, float minDistance)
		{
			s.playOnAwake = false;
			s.spatialBlend = 1f;
			s.rolloffMode = (AudioRolloffMode)0;
			s.minDistance = minDistance;
			s.maxDistance = ChoppaConfig.AudioMaxDistance.Value;
			s.dopplerLevel = 0.6f;
			s.spread = 60f;
			s.priority = 64;
			AudioMixerGroup val = MixerGroup();
			if ((Object)(object)val != (Object)null)
			{
				s.outputAudioMixerGroup = val;
			}
		}

		public static void Drive(Helicopter h)
		{
			if ((Object)(object)h.RotorAudio == (Object)null || (Object)(object)h.TurbineAudio == (Object)null)
			{
				return;
			}
			float value = ChoppaConfig.AudioVolume.Value;
			float num = (h.Broken ? 0f : h.RotorSpin);
			float collective = h.Collective;
			bool flag = num > 0.005f && value > 0f;
			AudioSource[] array = (AudioSource[])(object)new AudioSource[2] { h.RotorAudio, h.TurbineAudio };
			foreach (AudioSource val in array)
			{
				if (flag && !val.isPlaying)
				{
					val.time = Random.value * val.clip.length * 0.99f;
					val.Play();
				}
				else if (!flag && val.isPlaying)
				{
					val.Stop();
				}
			}
			if (flag)
			{
				h.RotorAudio.volume = value * Mathf.Pow(num, 1.3f) * (0.55f + 0.45f * collective);
				h.RotorAudio.pitch = 0.35f + 0.65f * num + 0.1f * (collective - 0.5f) * num;
				h.TurbineAudio.volume = value * 0.12f * Mathf.Pow(num, 0.7f);
				h.TurbineAudio.pitch = 0.4f + 0.6f * num + 0.1f * collective;
			}
		}

		public static void Bonk(AudioSource src, float impactSpeed, float size, float volume = 1f)
		{
			float value = ChoppaConfig.AudioVolume.Value;
			if (!(value <= 0f) && !((Object)(object)src == (Object)null) && EnsureClips())
			{
				float num = Mathf.Clamp01((impactSpeed - 0.5f) / 8f);
				if (!(num <= 0.02f))
				{
					src.pitch = Mathf.Lerp(1.35f, 0.55f, size) * Random.Range(0.9f, 1.1f);
					src.PlayOneShot(bonkClips[Random.Range(0, bonkClips.Length)], value * volume * num * Mathf.Lerp(0.6f, 1f, size));
				}
			}
		}

		public static AudioSource OneShotSource(GameObject go, float minDistance)
		{
			minDistance *= ChoppaConfig.HeliScale.Value;
			AudioSource obj = go.AddComponent<AudioSource>();
			Setup(obj, minDistance);
			obj.loop = false;
			return obj;
		}

		public static void PlayCrash(Vector3 position)
		{
			//IL_001e: 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)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0058: Expected O, but got Unknown
			if (!(ChoppaConfig.AudioVolume.Value <= 0f) && EnsureClips())
			{
				GameObject val = new GameObject("ChoppaCrashSound");
				val.transform.position = position;
				Bonk(OneShotSource(val, 15f), 20f, 1f);
				Object.Destroy((Object)val, 2f);
			}
		}

		private static AudioMixerGroup MixerGroup()
		{
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			if ((Object)(object)mixerGroup != (Object)null && !((Il2CppObjectBase)mixerGroup).WasCollected)
			{
				return mixerGroup;
			}
			if (mixerSearched)
			{
				return null;
			}
			mixerSearched = true;
			bool flag = default(bool);
			try
			{
				Dictionary<string, (AudioMixerGroup, int)> dictionary = new Dictionary<string, (AudioMixerGroup, int)>();
				foreach (AudioSource item in Object.FindObjectsByType<AudioSource>((FindObjectsInactive)1, (FindObjectsSortMode)0))
				{
					AudioMixerGroup outputAudioMixerGroup = item.outputAudioMixerGroup;
					if (!((Object)(object)outputAudioMixerGroup == (Object)null))
					{
						dictionary[((Object)outputAudioMixerGroup).name] = (dictionary.TryGetValue(((Object)outputAudioMixerGroup).name, out var value) ? (outputAudioMixerGroup, value.Item2 + 1) : (outputAudioMixerGroup, 1));
					}
				}
				Plugin.Verbose("Game mixer groups: " + string.Join(", ", dictionary.Select<KeyValuePair<string, (AudioMixerGroup, int)>, string>((KeyValuePair<string, (AudioMixerGroup g, int n)> kv) => $"{kv.Key}x{kv.Value.n}")));
				string text = null;
				foreach (KeyValuePair<string, (AudioMixerGroup, int)> item2 in dictionary)
				{
					if (Score(item2.Key) >= 0 && (text == null || Score(item2.Key) > Score(text) || (Score(item2.Key) == Score(text) && item2.Value.Item2 > dictionary[text].Item2)))
					{
						text = item2.Key;
					}
				}
				if (text != null)
				{
					mixerGroup = dictionary[text].Item1;
					ManualLogSource l = Plugin.L;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(38, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Choppa audio routed to mixer group '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'.");
					}
					l.LogInfo(val);
				}
				else
				{
					Plugin.L.LogInfo((object)"No game mixer group found; choppa audio plays direct.");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource l2 = Plugin.L;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Mixer group search failed: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				l2.LogWarning(val2);
			}
			return mixerGroup;
			static int Score(string name)
			{
				string text2 = name.ToLowerInvariant();
				if (text2.Contains("music") || text2.Contains("ui") || text2.Contains("voice") || text2.Contains("amb"))
				{
					return -1;
				}
				if (text2.Contains("sfx") || text2.Contains("effect"))
				{
					return 3;
				}
				if (text2.Contains("world") || text2.Contains("game") || text2.Contains("prop"))
				{
					return 2;
				}
				return 1;
			}
		}

		private static bool EnsureClips()
		{
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			try
			{
				if (Dead(rotorClip))
				{
					rotorClip = MakeClip("ChoppaRotor", SynthRotor());
				}
				if (Dead(turbineClip))
				{
					turbineClip = MakeClip("ChoppaTurbine", SynthTurbine());
				}
				if (bonkClips == null || Array.Exists(bonkClips, Dead))
				{
					bonkClips = (AudioClip[])(object)new AudioClip[4];
					for (int i = 0; i < bonkClips.Length; i++)
					{
						bonkClips[i] = MakeClip($"ChoppaBonk{i}", SynthBonk(i));
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Choppa audio synthesis failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				l.LogError(val);
				return false;
			}
		}

		private static bool Dead(AudioClip c)
		{
			if (!((Object)(object)c == (Object)null))
			{
				return ((Il2CppObjectBase)c).WasCollected;
			}
			return true;
		}

		private static AudioClip MakeClip(string name, float[] data)
		{
			Normalize(data, 0.9f);
			AudioClip obj = AudioClip.Create(name, data.Length, 1, 44100, false);
			obj.SetData(Il2CppStructArray<float>.op_Implicit(data), 0);
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}

		private static float[] SynthRotor()
		{
			int num = 44100;
			Random rng = new Random(1234);
			float[] array = LowPassLoop(WhiteNoise(num, rng), 420f);
			float[] array2 = LowPassLoop(WhiteNoise(num, rng), 120f);
			float[] array3 = new float[num];
			int num2 = num / 10;
			for (int i = 0; i < num; i++)
			{
				float num3 = (float)(i % num2) / 44100f;
				float num4 = Mathf.Exp((0f - num3) / 0.035f) * Mathf.Clamp01(num3 / 0.003f);
				float num5 = Mathf.Sin((float)Math.PI * 140f * num3) * Mathf.Exp((0f - num3) / 0.05f);
				array3[i] = num4 * array[i] * 2.2f + num5 * 0.7f + array2[i] * 1.2f;
			}
			return array3;
		}

		private static float[] SynthTurbine()
		{
			int num = 44100;
			float[] array = new float[num];
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)i / 44100f;
				float num3 = 0.5f + 0.5f * Mathf.Sin((float)Math.PI * 68f * num2);
				array[i] = Mathf.Sin((float)Math.PI * 1240f * num2) * num3;
			}
			return array;
		}

		private static float[] SynthBonk(int variant)
		{
			int num = 15435;
			Random rng = new Random(500 + variant);
			float num2 = 260f + (float)variant * 70f;
			float[] array = LowPass(WhiteNoise(num, rng), 3000f);
			float[] array2 = new float[num];
			double num3 = 0.0;
			double num4 = 0.0;
			for (int i = 0; i < num; i++)
			{
				float num5 = (float)i / 44100f;
				float num6 = num2 * (1f + 0.6f * Mathf.Exp((0f - num5) / 0.012f));
				num3 += Math.PI * 2.0 * (double)num6 / 44100.0;
				num4 += Math.PI * 2.0 * (double)num6 * 2.31 / 44100.0;
				float num7 = Mathf.Exp((0f - num5) / 0.07f) * Mathf.Clamp01(num5 / 0.001f);
				array2[i] = num7 * ((float)Math.Sin(num3) + 0.35f * (float)Math.Sin(num4) * Mathf.Exp((0f - num5) / 0.03f)) + array[i] * 1.5f * Mathf.Exp((0f - num5) / 0.004f);
			}
			return array2;
		}

		private static float[] WhiteNoise(int n, Random rng)
		{
			float[] array = new float[n];
			for (int i = 0; i < n; i++)
			{
				array[i] = (float)(rng.NextDouble() * 2.0 - 1.0);
			}
			return array;
		}

		private static float[] LowPass(float[] x, float cutoff)
		{
			float num = 1f - Mathf.Exp((float)Math.PI * -2f * cutoff / 44100f);
			float[] array = new float[x.Length];
			float num2 = 0f;
			for (int i = 0; i < x.Length; i++)
			{
				num2 = (array[i] = num2 + num * (x[i] - num2));
			}
			return array;
		}

		private static float[] LowPassLoop(float[] x, float cutoff)
		{
			float num = 1f - Mathf.Exp((float)Math.PI * -2f * cutoff / 44100f);
			float[] array = new float[x.Length];
			float num2 = 0f;
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < x.Length; j++)
				{
					num2 = (array[j] = num2 + num * (x[j] - num2));
				}
			}
			return array;
		}

		private static void Normalize(float[] d, float peak)
		{
			float num = 1E-06f;
			foreach (float num2 in d)
			{
				num = Mathf.Max(num, Mathf.Abs(num2));
			}
			float num3 = peak / num;
			for (int j = 0; j < d.Length; j++)
			{
				d[j] *= num3;
			}
		}
	}
	public sealed class ChoppaAutopilot
	{
		private const float MaxSpeed = 40f;

		private const float MaxTiltDeg = 35f;

		private const float MaxAccel = 9f;

		private const float TimeoutSeconds = 75f;

		private readonly Vector3 target;

		private readonly float cruiseY;

		private readonly float startTime;

		private Vector3 heading;

		private bool descending;

		public ChoppaAutopilot(Helicopter h, Vector3 target, float cruiseY)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			this.target = target;
			this.cruiseY = cruiseY;
			startTime = Time.time;
			Vector3 val = Flat(target - ((Component)h).transform.position);
			heading = ((Vector3)(ref val)).normalized;
			h.EngineOn = true;
			h.RotorSpin = 1f;
			h.Collective = h.HoverCollective;
			h.Body.linearVelocity = heading * 20f;
		}

		public bool Step(Helicopter h, float dt)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			if (h.Occupants[0] != 0)
			{
				return false;
			}
			if (Time.time - startTime > 75f)
			{
				Finish(h, "gave up");
				return false;
			}
			h.EngineOn = true;
			Transform transform = ((Component)h).transform;
			Vector3 position = transform.position;
			Vector3 linearVelocity = h.Body.linearVelocity;
			Vector3 val = Flat(target - position);
			float magnitude = ((Vector3)(ref val)).magnitude;
			Vector3 val2 = Flat(linearVelocity);
			if (!descending && magnitude < 5f && ((Vector3)(ref val2)).magnitude < 3f)
			{
				descending = true;
				Plugin.Verbose("Autopilot: over the spot, descending.");
			}
			if (descending && h.Grounded)
			{
				Finish(h, "landed");
				return false;
			}
			Vector3 val3 = Vector3.ClampMagnitude((((magnitude > 0.01f) ? (val / magnitude * Mathf.Min(40f, magnitude * 0.5f)) : Vector3.zero) - val2) * 1.3f, 9f);
			Vector3 val4 = Flat(transform.forward);
			Vector3 normalized = ((Vector3)(ref val4)).normalized;
			val4 = Flat(transform.right);
			Vector3 normalized2 = ((Vector3)(ref val4)).normalized;
			float num = Mathf.Abs(Physics.gravity.y);
			float num2 = Mathf.Clamp(Mathf.Atan2(Vector3.Dot(val3, normalized), num) * 57.29578f, -35f, 35f);
			float num3 = Mathf.Clamp((0f - Mathf.Atan2(Vector3.Dot(val3, normalized2), num)) * 57.29578f, -35f, 35f);
			float num4 = (0f - Mathf.Asin(Mathf.Clamp(transform.forward.y, -1f, 1f))) * 57.29578f;
			float num5 = Mathf.Asin(Mathf.Clamp(transform.right.y, -1f, 1f)) * 57.29578f;
			if (magnitude > 25f)
			{
				heading = val / magnitude;
			}
			float num6 = Vector3.SignedAngle(normalized, heading, Vector3.up);
			h.CommandedRates = new Vector3(Mathf.Clamp((num2 - num4) * 3f, -60f, 60f), Mathf.Clamp(num6 * 1.2f, -40f, 40f), Mathf.Clamp((num3 - num5) * 3f, -60f, 60f));
			float num7 = ((!descending) ? Mathf.Clamp((Mathf.Max(Mathf.Min(cruiseY, target.y + 6f + Mathf.Max(0f, magnitude - 35f) * 0.8f), GroundAhead(h, position, val, magnitude) + 12f) - position.y) * 0.8f, -10f, 8f) : (0f - Mathf.Clamp((position.y - target.y) * 0.6f, 1f, 8f)));
			float num8 = num + (num7 - linearVelocity.y) * 1.5f;
			float num9 = Mathf.Max(0.5f, transform.up.y);
			h.Collective = Mathf.Clamp01(num8 / (ChoppaConfig.MaxLiftG.Value * num * num9));
			return true;
		}

		private void Finish(Helicopter h, string why)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(36, 3, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Autopilot: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(why);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
				Vector3 val2 = Flat(target - ((Component)h).transform.position);
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(((Vector3)(ref val2)).magnitude, "0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("m from the spot after ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(Time.time - startTime, "0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("s.");
			}
			l.LogInfo(val);
			h.CommandedRates = Vector3.zero;
			h.EngineOn = h.Occupants[0] != 0;
		}

		private static float GroundAhead(Helicopter h, Vector3 p, Vector3 toTarget, float dist)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b8: Unknown result type (might be due to invalid IL or missing references)
			float num = float.MinValue;
			if (dist < 8f)
			{
				return num;
			}
			Vector3 val = toTarget / dist;
			float num2 = Mathf.Min(80f, dist - 6f);
			for (float num3 = 0f; num3 <= num2; num3 += 10f)
			{
				foreach (RaycastHit item in (Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(p + val * num3 + Vector3.up * 200f, Vector3.down, 400f, -1, (QueryTriggerInteraction)1))
				{
					RaycastHit current = item;
					if ((Object)(object)((RaycastHit)(ref current)).collider != (Object)null && !((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)h).transform) && (Object)(object)((RaycastHit)(ref current)).collider.attachedRigidbody == (Object)null)
					{
						num = Mathf.Max(num, ((RaycastHit)(ref current)).point.y);
					}
				}
			}
			return num;
		}

		private static Vector3 Flat(Vector3 v)
		{
			//IL_0000: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(v.x, 0f, v.z);
		}
	}
	internal sealed class ChoppaBenches
	{
		public const int MaxSpots = 4;

		private const int TicketOffset = 6;

		private static bool templateSearched;

		private static PlayerPose template;

		private static int castLayer = -1;

		private static bool castTrigger;

		private Helicopter heli;

		private readonly List<PlayerPose> poses = new List<PlayerPose>();

		private readonly List<PlayerCharacter> seen = new List<PlayerCharacter>();

		private static float bottomRadius = -1f;

		private static readonly List<(PlayerPose pose, float at)> dying = new List<(PlayerPose, float)>();

		private const float DyingSeconds = 3f;

		public int RiderCount
		{
			get
			{
				int num = 0;
				foreach (PlayerPose pose in poses)
				{
					if ((Object)(object)pose != (Object)null && (Object)(object)pose.occupant != (Object)null)
					{
						num++;
					}
				}
				return num;
			}
		}

		public int FreeSpots
		{
			get
			{
				int num = 0;
				foreach (PlayerPose pose in poses)
				{
					if ((Object)(object)pose != (Object)null && (Object)(object)pose.occupant == (Object)null)
					{
						num++;
					}
				}
				return num;
			}
		}

		public bool Owns(PlayerPose pose)
		{
			if ((Object)(object)pose == (Object)null)
			{
				return false;
			}
			foreach (PlayerPose pose2 in poses)
			{
				if ((Object)(object)pose2 != (Object)null && ((Il2CppObjectBase)pose2).Pointer == ((Il2CppObjectBase)pose).Pointer)
				{
					return true;
				}
			}
			return false;
		}

		public static ChoppaBenches Build(Transform model, Helicopter heli, Transform[] spots)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_005c: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			ChoppaBenches choppaBenches = new ChoppaBenches
			{
				heli = heli
			};
			for (int i = 0; i < spots.Length && i < 4; i++)
			{
				GameObject val = new GameObject($"BenchSpot{i}");
				val.SetActive(false);
				val.transform.SetParent(model, false);
				val.transform.localPosition = spots[i].localPosition;
				val.transform.localRotation = spots[i].localRotation;
				BoxCollider obj = val.AddComponent<BoxCollider>();
				obj.center = new Vector3(0f, 0.15f, 0f);
				obj.size = new Vector3(0.45f, 0.35f, 0.4f);
				choppaBenches.poses.Add(val.AddComponent<PlayerPose>());
				choppaBenches.seen.Add(null);
			}
			return choppaBenches;
		}

		public void Activate()
		{
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Expected O, but got Unknown
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			FindTemplate();
			TicketOffice instance = TicketOffice.instance;
			float num = BottomRadius();
			float num2 = ((heli.Scale > 0f) ? heli.Scale : 1f);
			bool flag = default(bool);
			for (int i = 0; i < poses.Count; i++)
			{
				PlayerPose val = poses[i];
				ushort num3 = ChoppaPockets.Ticket(heli.Id, 6 + i);
				try
				{
					if ((Object)(object)template == (Object)null || !ChoppaPockets.FreeTicket(instance, num3))
					{
						Plugin.L.LogWarning((object)(((Object)(object)template == (Object)null) ? "Bench spots: no game seat to copy; benches disabled." : $"Bench spot {i} of choppa {heli.Id:X8}: ticket {num3} is already used by the game; spot disabled."));
						Object.Destroy((Object)(object)((Component)val).gameObject);
						poses[i] = null;
						continue;
					}
					GameObject gameObject = ((Component)val).gameObject;
					Transform transform = gameObject.transform;
					transform.localPosition += gameObject.transform.localRotation * new Vector3(0f, num, num) / num2;
					if (castLayer >= 0)
					{
						gameObject.layer = castLayer;
					}
					((Collider)gameObject.GetComponent<BoxCollider>()).isTrigger = castTrigger;
					CopyFrom(template, val);
					val._ticket_k__BackingField = num3;
					val.shellReference = new ShellReference(num3);
					gameObject.AddComponent<CastableTarget>().outcomes = new Il2CppReferenceArray<CastableOutcome>(1L) { [0] = new CastableOutcome
					{
						playerPose = val
					} };
					gameObject.SetActive(true);
					if (val.ticket != num3)
					{
						val._ticket_k__BackingField = num3;
					}
					if (!instance.tickets.ContainsKey(num3))
					{
						TicketOffice.AddTicket(new ITicketed(((Il2CppObjectBase)val).Pointer));
					}
				}
				catch (Exception ex)
				{
					ManualLogSource l = Plugin.L;
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(26, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Bench spot ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(i);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" setup failed: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
					}
					l.LogError(val2);
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)val).gameObject);
					}
					poses[i] = null;
				}
			}
		}

		private static float BottomRadius()
		{
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_0051: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			if (bottomRadius > 0f)
			{
				return bottomRadius;
			}
			bool flag = default(bool);
			try
			{
				PlayerCharacter val = Object.FindObjectOfType<PlayerCharacter>();
				if ((Object)(object)val == (Object)null)
				{
					return 0.3f;
				}
				float num = 0f;
				foreach (Collider componentsInChild in ((Component)val).GetComponentsInChildren<Collider>(true))
				{
					float num2 = Mathf.Max(((Component)componentsInChild).transform.lossyScale.x, ((Component)componentsInChild).transform.lossyScale.z);
					SphereCollider val2 = ((Il2CppObjectBase)componentsInChild).TryCast<SphereCollider>();
					CapsuleCollider val3 = ((Il2CppObjectBase)componentsInChild).TryCast<CapsuleCollider>();
					float num3 = (((Object)(object)val2 != (Object)null) ? (val2.radius * num2) : (((Object)(object)val3 != (Object)null) ? (val3.radius * num2) : 0f));
					num = Mathf.Max(num, num3);
				}
				bottomRadius = ((num > 0.1f && num < 0.6f) ? num : 0.3f);
				ManualLogSource l = Plugin.L;
				BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(48, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Bench spots: rider bottom radius ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<float>(bottomRadius, "0.00");
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" m (measured ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<float>(num, "0.00");
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(").");
				}
				l.LogInfo(val4);
			}
			catch (Exception ex)
			{
				ManualLogSource l2 = Plugin.L;
				BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(41, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Bench spots: measuring the rider failed: ");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
				}
				l2.LogWarning(val5);
				return 0.3f;
			}
			return bottomRadius;
		}

		private static void CopyFrom(PlayerPose t, PlayerPose p)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			p.animatorPoseId = t.animatorPoseId;
			p.noCrouching = t.noCrouching;
			p.noHolding = t.noHolding;
			p.allowSitting = t.allowSitting;
			p.hasFootsteps = t.hasFootsteps;
			p.noPlacingOthers = t.noPlacingOthers;
			p.allowKicking = t.allowKicking;
			p.useFullRetractions = t.useFullRetractions;
			p.leaveWithUseAction = t.leaveWithUseAction;
			p.leaveWithJump = t.leaveWithJump;
			p.eyeMood = t.eyeMood;
			p.hasDifferentRightEye = t.hasDifferentRightEye;
			p.seperateRightEye = t.seperateRightEye;
			p.cameraOffset = t.cameraOffset;
			p.cameraOffsetCrouching = t.cameraOffsetCrouching;
			p.noCameraDampening = t.noCameraDampening;
			p.defaultPropLimits = t.defaultPropLimits;
			p.taggedPropLimits = t.taggedPropLimits;
			p.localBumOffset = t.localBumOffset;
			p.localBumOffsetSitting = t.localBumOffsetSitting;
			p.hasCustomColliderState = t.hasCustomColliderState;
			p.colliderState = t.colliderState;
			p.hasCustomCrouchingColliderState = t.hasCustomCrouchingColliderState;
			p.crouchingColliderState = t.crouchingColliderState;
			p.hasCustomSittingColliderState = t.hasCustomSittingColliderState;
			p.sittingColliderState = t.sittingColliderState;
			p.audioIdentifier = t.audioIdentifier;
			p.enterSound = t.enterSound;
			p.exitSound = t.exitSound;
			p.slideSound = t.slideSound;
			p.dropSound = t.dropSound;
			p.legWiggleSound = t.legWiggleSound;
			p.idleSound = t.idleSound;
			p.leaveIfNotUpright = false;
			p.entryIsBlocked = false;
			p.emptyAllPockets = false;
			p.emptyNonBlindfoldPockets = false;
			p.lockPockets = false;
		}

		public void Tick()
		{
			for (int i = 0; i < poses.Count; i++)
			{
				PlayerPose val = poses[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				PlayerCharacter occupant = val.occupant;
				if (!((Object)(object)occupant == (Object)(object)seen[i]))
				{
					if ((Object)(object)seen[i] != (Object)null)
					{
						IgnoreCollisions(seen[i], ignore: false);
					}
					if ((Object)(object)occupant != (Object)null)
					{
						IgnoreCollisions(occupant, ignore: true);
					}
					seen[i] = occupant;
					Plugin.Verbose($"Choppa {heli.Id:X8} bench spot {i}: {(((Object)(object)occupant != (Object)null) ? $"player {((NetworkBehaviour)occupant).netId}" : "empty")}");
				}
			}
		}

		private void IgnoreCollisions(PlayerCharacter pc, bool ignore)
		{
			if ((Object)(object)pc == (Object)null || (Object)(object)heli == (Object)null)
			{
				return;
			}
			Il2CppArrayBase<Collider> componentsInChildren = ((Component)pc).GetComponentsInChildren<Collider>(true);
			foreach (Collider componentsInChild in ((Component)heli).GetComponentsInChildren<Collider>(true))
			{
				if ((Object)(object)componentsInChild == (Object)null)
				{
					continue;
				}
				foreach (Collider item in componentsInChildren)
				{
					if ((Object)(object)item != (Object)null)
					{
						Physics.IgnoreCollision(componentsInChild, item, ignore);
					}
				}
			}
		}

		public void Release(PlayerCharacter local)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Expected O, but got Unknown
			for (int i = 0; i < seen.Count; i++)
			{
				if ((Object)(object)seen[i] != (Object)null)
				{
					IgnoreCollisions(seen[i], ignore: false);
				}
				seen[i] = null;
			}
			bool flag = default(bool);
			foreach (PlayerPose pose in poses)
			{
				if ((Object)(object)pose == (Object)null)
				{
					continue;
				}
				try
				{
					PlayerCharacter occupant = pose.occupant;
					if ((Object)(object)occupant != (Object)null && (Object)(object)local != (Object)null && ((Il2CppObjectBase)occupant).Pointer == ((Il2CppObjectBase)local).Pointer)
					{
						if (local.actions != null)
						{
							local.actions.ActionExitPose();
						}
						else
						{
							local.poser.ExitPose((AudioAsset)null);
						}
					}
					else if ((Object)(object)occupant != (Object)null && NetworkServer.active)
					{
						PlayerNetworking playerNetworking = occupant.playerNetworking;
						if (playerNetworking != null)
						{
							playerNetworking.ServerExitPoseAuto();
						}
					}
				}
				catch (Exception ex)
				{
					ManualLogSource l = Plugin.L;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(20, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Leaving bench spot: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					l.LogWarning(val);
				}
				try
				{
					GameObject gameObject = ((Component)pose).gameObject;
					gameObject.transform.SetParent((Transform)null, true);
					CastableTarget component = gameObject.GetComponent<CastableTarget>();
					if ((Object)(object)component != (Object)null)
					{
						Object.Destroy((Object)(object)component);
					}
					BoxCollider component2 = gameObject.GetComponent<BoxCollider>();
					if ((Object)(object)component2 != (Object)null)
					{
						((Collider)component2).enabled = false;
					}
					dying.Add((pose, Time.time + 3f));
				}
				catch (Exception ex2)
				{
					ManualLogSource l2 = Plugin.L;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(22, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Detaching bench spot: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
					}
					l2.LogWarning(val);
				}
			}
			poses.Clear();
			seen.Clear();
		}

		public static void TickDying()
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			if (dying.Count == 0)
			{
				return;
			}
			TicketOffice instance = TicketOffice.instance;
			bool flag = default(bool);
			for (int num = dying.Count - 1; num >= 0; num--)
			{
				var (val, num2) = dying[num];
				if (!((Object)(object)val != (Object)null) || !(Time.time < num2))
				{
					dying.RemoveAt(num);
					if (!((Object)(object)val == (Object)null))
					{
						try
						{
							if ((Object)(object)val.occupant != (Object)null)
							{
								ManualLogSource l = Plugin.L;
								BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(42, 2, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Bench spot ");
									((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<ushort>(val.ticket);
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": player ");
									((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<uint>(((NetworkBehaviour)val.occupant).netId);
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" never left; evicting.");
								}
								l.LogWarning(val2);
								val.Evict();
							}
						}
						catch (Exception ex)
						{
							ManualLogSource l2 = Plugin.L;
							BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(22, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Evicting bench rider: ");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
							}
							l2.LogWarning(val2);
						}
						ChoppaPockets.ReturnTicket(instance, val.ticket, ((Il2CppObjectBase)val).Pointer);
						Object.Destroy((Object)(object)((Component)val).gameObject);
					}
				}
			}
		}

		private static void FindTemplate()
		{
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Expected O, but got Unknown
			if (templateSearched)
			{
				return;
			}
			templateSearched = true;
			bool flag = default(bool);
			try
			{
				Il2CppArrayBase<PlayerPose> val = Resources.FindObjectsOfTypeAll<PlayerPose>();
				PlayerPose val2 = null;
				int num = int.MaxValue;
				string[] array = new string[6] { "chair", "lift", "train", "seat", "bench", "sit" };
				foreach (PlayerPose item in val)
				{
					if (!((Object)(object)item == (Object)null) && !((Object)(object)item.isCarryPoseOfCharacter != (Object)null))
					{
						string path = Path(((Component)item).transform).ToLowerInvariant();
						int num2 = Array.FindIndex(array, (string k) => path.Contains(k));
						if (num2 < 0)
						{
							num2 = array.Length;
						}
						if (num2 < num)
						{
							num = num2;
							val2 = item;
						}
					}
				}
				if ((Object)(object)val2 == (Object)null || num >= array.Length)
				{
					ManualLogSource l = Plugin.L;
					BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(57, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Bench spots: none of the game's ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(val.Length);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" poses looks like a seat.");
					}
					l.LogWarning(val3);
					if ((Object)(object)val2 == (Object)null)
					{
						return;
					}
				}
				template = val2;
				foreach (CastableTarget item2 in Resources.FindObjectsOfTypeAll<CastableTarget>())
				{
					Il2CppReferenceArray<CastableOutcome> outcomes = item2.outcomes;
					if (outcomes == null)
					{
						continue;
					}
					bool flag2 = false;
					for (int num3 = 0; num3 < ((Il2CppArrayBase<CastableOutcome>)(object)outcomes).Length; num3++)
					{
						if (flag2)
						{
							break;
						}
						CastableOutcome obj = ((Il2CppArrayBase<CastableOutcome>)(object)outcomes)[num3];
						flag2 = (Object)(object)((obj != null) ? obj.playerPose : null) != (Object)null && ((Il2CppObjectBase)((Il2CppArrayBase<CastableOutcome>)(object)outcomes)[num3].playerPose).Pointer == ((Il2CppObjectBase)val2).Pointer;
					}
					if (flag2)
					{
						Collider val4 = ((Component)item2).GetComponent<Collider>() ?? ((Component)item2).GetComponentInChildren<Collider>(true);
						castLayer = (((Object)(object)val4 != (Object)null) ? ((Component)val4).gameObject.layer : ((Component)item2).gameObject.layer);
						castTrigger = (Object)(object)val4 != (Object)null && val4.isTrigger;
						break;
					}
				}
				ManualLogSource l2 = Plugin.L;
				BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(65, 4, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Bench spots: copying seat '");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(Path(((Component)val2).transform));
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("' (anim ");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(val2.animatorPoseId);
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("); crosshair layer ");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(castLayer);
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(", trigger ");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<bool>(castTrigger);
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(".");
				}
				l2.LogInfo(val5);
			}
			catch (Exception ex)
			{
				ManualLogSource l3 = Plugin.L;
				BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(37, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Bench spots: template search failed: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
				}
				l3.LogWarning(val3);
			}
		}

		private static string Path(Transform t)
		{
			string text = ((Object)t).name;
			Transform parent = t.parent;
			while ((Object)(object)parent != (Object)null)
			{
				text = ((Object)parent).name + "/" + text;
				parent = parent.parent;
			}
			return text;
		}
	}
	public class ChoppaBonker : MonoBehaviour
	{
		public AudioSource Source;

		public float Size = 0.5f;

		public float MinSpeed = 1f;

		public float Volume = 1f;

		public float Cooldown = 0.08f;

		private Rigidbody body;

		private Vector3 lastVelocity;

		private bool haveLast;

		private float nextAllowed;

		private static float windowStart;

		private static int windowCount;

		public ChoppaBonker(IntPtr ptr)
			: base(ptr)
		{
		}

		public static ChoppaBonker Add(GameObject go, float size, float minSpeed, float volume = 1f, float cooldown = 0.08f)
		{
			//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)
			ChoppaBonker choppaBonker = go.AddComponent<ChoppaBonker>();
			choppaBonker.Size = size;
			choppaBonker.MinSpeed = minSpeed;
			choppaBonker.Volume = volume;
			choppaBonker.Cooldown = cooldown;
			choppaBonker.body = go.GetComponent<Rigidbody>();
			if ((Object)(object)choppaBonker.body != (Object)null)
			{
				choppaBonker.lastVelocity = choppaBonker.body.linearVelocity;
				choppaBonker.haveLast = true;
			}
			choppaBonker.Source = ChoppaAudio.OneShotSource(go, 4f + 6f * size);
			return choppaBonker;
		}

		private void FixedUpdate()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)body == (Object)null))
			{
				lastVelocity = body.linearVelocity;
				haveLast = true;
			}
		}

		private void OnCollisionEnter(Collision c)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)body == (Object)null || body.isKinematic || !haveLast)
			{
				return;
			}
			Vector3 val = body.linearVelocity - lastVelocity;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (!(magnitude < MinSpeed) && !(Time.time < nextAllowed))
			{
				nextAllowed = Time.time + Cooldown;
				if (Time.time - windowStart > 0.1f)
				{
					windowStart = Time.time;
					windowCount = 0;
				}
				if (++windowCount <= 6)
				{
					ChoppaAudio.Bonk(Source, magnitude, Size, Volume);
				}
			}
		}
	}
	internal enum InputBackend
	{
		Auto,
		Rewired,
		Unity
	}
	internal static class ChoppaConfig
	{
		public static ConfigEntry<KeyCode> CollectiveUpKey;

		public static ConfigEntry<KeyCode> CollectiveDownKey;

		public static ConfigEntry<KeyCode> PedalLeftKey;

		public static ConfigEntry<KeyCode> PedalRightKey;

		public static ConfigEntry<KeyCode> SpawnKey;

		public static ConfigEntry<KeyCode> EnterExitKey;

		public static ConfigEntry<KeyCode> ResetKey;

		public static ConfigEntry<KeyCode> CameraKey;

		public static ConfigEntry<KeyCode> FreeLookKey;

		public static ConfigEntry<KeyCode> HudKey;

		public static ConfigEntry<float> MouseSensitivity;

		public static ConfigEntry<float> FreelookMouseSensitivity;

		public static ConfigEntry<bool> InvertPitch;

		public static ConfigEntry<bool> InvertRoll;

		public static ConfigEntry<InputBackend> Backend;

		public static ConfigEntry<bool> RequireCursorLock;

		public static ConfigEntry<float> MaxLiftG;

		public static ConfigEntry<float> CollectiveRate;

		public static ConfigEntry<float> MaxPitchRollRate;

		public static ConfigEntry<float> YawRate;

		public static ConfigEntry<float> ControlResponse;

		public static ConfigEntry<float> MouseSmoothing;

		public static ConfigEntry<float> AutoLevel;

		public static ConfigEntry<float> Weathervane;

		public static ConfigEntry<float> SpinUpSeconds;

		public static ConfigEntry<float> ForwardDrag;

		public static ConfigEntry<float> SideDrag;

		public static ConfigEntry<float> VerticalDrag;

		public static ConfigEntry<float> LinearDrag;

		public static ConfigEntry<float> Mass;

		public static ConfigEntry<float> CenterOfMassHeight;

		public static ConfigEntry<bool> CollectiveSpringBack;

		public static ConfigEntry<bool> HoverTiltCompensation;

		public static ConfigEntry<float> CollectiveReturnRate;

		public static ConfigEntry<bool> BreakApart;

		public static ConfigEntry<float> CrashDeltaV;

		public static ConfigEntry<float> CrashBlast;

		public static ConfigEntry<float> DebrisSeconds;

		public static ConfigEntry<float> CrashStunRadius;

		public static ConfigEntry<float> HeliScale;

		public static ConfigEntry<float> SeatHeightOffset;

		public static ConfigEntry<float> SeatForwardOffset;

		public static ConfigEntry<float> EnterDistance;

		public static ConfigEntry<float> ChaseDistance;

		public static ConfigEntry<float> ChaseHeight;

		public static ConfigEntry<float> CockpitEyeHeight;

		public static ConfigEntry<bool> SitWhileFlying;

		public static ConfigEntry<int> ChoppaLayer;

		public static ConfigEntry<float> HeadlightIntensity;

		public static ConfigEntry<float> HeadlightRange;

		public static ConfigEntry<float> HeadlightAngle;

		public static ConfigEntry<float> HeadlightTilt;

		public static ConfigEntry<float> GlowIntensity;

		public static ConfigEntry<float> AudioVolume;

		public static ConfigEntry<float> AudioMaxDistance;

		public static ConfigEntry<bool> LogbookEnabled;

		public static ConfigEntry<string> LogbookInstallId;

		public static ConfigEntry<bool> NetEnabled;

		public static ConfigEntry<float> NetSendRate;

		public static ConfigEntry<float> NetInterpDelay;

		public static ConfigEntry<bool> ShowHud;

		public static ConfigEntry<bool> VerboseLogging;

		private const int CurrentConfigVersion = 3;

		private static ConfigFile file;

		private static FileSystemWatcher watcher;

		private static long lastChangeMs = -1L;

		public static void Bind(ConfigFile cfg)
		{
			CollectiveUpKey = cfg.Bind<KeyCode>("Controls", "CollectiveUp", (KeyCode)119, "Hold to raise collective (more lift).");
			CollectiveDownKey = cfg.Bind<KeyCode>("Controls", "CollectiveDown", (KeyCode)115, "Hold to lower collective (less lift).");
			PedalLeftKey = cfg.Bind<KeyCode>("Controls", "PedalLeft", (KeyCode)97, "Left anti-torque pedal (yaw left).");
			PedalRightKey = cfg.Bind<KeyCode>("Controls", "PedalRight", (KeyCode)100, "Right anti-torque pedal (yaw right).");
			SpawnKey = cfg.Bind<KeyCode>("Controls", "Spawn", (KeyCode)289, "Open the choppa chooser: call one in or spawn it in front of you (replaces your previous one if nobody is in it).");
			EnterExitKey = cfg.Bind<KeyCode>("Controls", "EnterExit", (KeyCode)103, "Board or leave the choppa.");
			ResetKey = cfg.Bind<KeyCode>("Controls", "ResetUpright", (KeyCode)290, "Flip the choppa back upright where it is.");
			CameraKey = cfg.Bind<KeyCode>("Controls", "ToggleCamera", (KeyCode)118, "Switch between chase and cockpit camera.");
			FreeLookKey = cfg.Bind<KeyCode>("Controls", "FreeLook", (KeyCode)308, "Hold to look around with the mouse instead of flying with it.");
			HudKey = cfg.Bind<KeyCode>("Controls", "ToggleHud", (KeyCode)291, "Show/hide the flight HUD.");
			MouseSensitivity = cfg.Bind<float>("Controls", "MouseSensitivity", 0.3f, "Degrees of pitch/roll per unit of mouse movement. Mouse forward = nose down, mouse left = roll left.");
			FreelookMouseSensitivity = cfg.Bind<float>("Controls", "FreelookMouseSensitivity", 0.4f, "Degrees of camera turn per unit of mouse movement while holding the free look key.");
			InvertPitch = cfg.Bind<bool>("Controls", "InvertPitch", false, "Swap mouse forward/back for pitch.");
			InvertRoll = cfg.Bind<bool>("Controls", "InvertRoll", false, "Swap mouse left/right for roll.");
			Backend = cfg.Bind<InputBackend>("Controls", "InputBackend", InputBackend.Auto, "Where to read keys/mouse from. Auto tries the game's Rewired input first, then Unity's legacy Input.");
			RequireCursorLock = cfg.Bind<bool>("Controls", "RequireCursorLock", true, "Ignore flight inputs while the cursor is unlocked (menus open).");
			MaxLiftG = cfg.Bind<float>("Flight", "MaxLiftG", 2f, "Lift at full collective as a multiple of gravity. 2.0 means hover at ~50% collective.");
			CollectiveRate = cfg.Bind<float>("Flight", "CollectiveRate", 0.45f, "How fast holding W/S moves the collective (fraction of full range per second).");
			MaxPitchRollRate = cfg.Bind<float>("Flight", "MaxPitchRollRate", 90f, "Cap on pitch/roll rotation speed (deg/s).");
			YawRate = cfg.Bind<float>("Flight", "YawRate", 65f, "Yaw speed with a pedal fully held (deg/s).");
			ControlResponse = cfg.Bind<float>("Flight", "ControlResponse", 6f, "How snappily the airframe reaches the commanded rotation rate. Higher = twitchier.");
			MouseSmoothing = cfg.Bind<float>("Flight", "MouseSmoothing", 0.08f, "Seconds of smoothing on mouse cyclic input.");
			AutoLevel = cfg.Bind<float>("Flight", "AutoLevel", 0f, "Self-levelling tendency. 0 = none (Arma-like, holds whatever attitude you set). Try 0.3 for an easier ride.");
			Weathervane = cfg.Bind<float>("Flight", "Weathervane", 0.5f, "How strongly the tail swings the nose into the direction of travel at speed.");
			SpinUpSeconds = cfg.Bind<float>("Flight", "SpinUpSeconds", 3f, "Rotor spin up/down time when you board/leave.");
			ForwardDrag = cfg.Bind<float>("Flight", "ForwardDrag", 0.003f, "Quadratic drag along the nose. Lower = higher top speed.");
			SideDrag = cfg.Bind<float>("Flight", "SideDrag", 0.02f, "Quadratic drag sideways.");
			VerticalDrag = cfg.Bind<float>("Flight", "VerticalDrag", 0.04f, "Quadratic drag up/down.");
			LinearDrag = cfg.Bind<float>("Flight", "LinearDrag", 0.15f, "Low-speed drag in all directions (stops endless drifting).");
			Mass = cfg.Bind<float>("Flight", "Mass", 600f, "Rigidbody mass. Mostly affects how it shoves things it bumps into.");
			CenterOfMassHeight = cfg.Bind<float>("Flight", "CenterOfMassHeight", 1.8f, "Height (m, before Scale) of the point the choppa pivots around. Higher = swings like it hangs from the rotor; lower = tips like a bottom-heavy toy.");
			CollectiveSpringBack = cfg.Bind<bool>("Flight", "CollectiveSpringBack", true, "Release W/S and the collective returns to hover (or to idle when sitting on the ground). Off = it stays where you leave it.");
			CollectiveReturnRate = cfg.Bind<float>("Flight", "CollectiveReturnRate", 1f, "How fast the collective springs back when released (fraction of full range per second).");
			HoverTiltCompensation = cfg.Bind<bool>("Flight", "HoverTiltCompensation", true, "Spring-back point adds a bit of lift when tilted so forward flight roughly holds altitude.");
			BreakApart = cfg.Bind<bool>("Crashing", "BreakApart", true, "Hard impacts smash the choppa into pieces.");
			CrashDeltaV = cfg.Bind<float>("Crashing", "CrashSpeed", 10f, "Sudden speed change (m/s in one physics step) that counts as a crash. Higher = sturdier.");
			CrashBlast = cfg.Bind<float>("Crashing", "CrashBlast", 8f, "How hard the pieces fly apart.");
			DebrisSeconds = cfg.Bind<float>("Crashing", "DebrisSeconds", 30f, "How long wreckage lies around. 0 = forever.");
			CrashStunRadius = cfg.Bind<float>("Crashing", "StunRadius", 6f, "Your character gets knocked down if within this distance of a crash (pilot always is).");
			HeliScale = cfg.Bind<float>("Model", "Scale", 0.6f, "Overall size of the choppa.");
			SeatHeightOffset = cfg.Bind<float>("Model", "SeatHeightOffset", 0f, "Raise/lower where you sit (metres, before Scale).");
			SeatForwardOffset = cfg.Bind<float>("Model", "SeatForwardOffset", 0f, "Move where you sit forward/back (metres, before Scale).");
			EnterDistance = cfg.Bind<float>("Model", "EnterDistance", 5f, "How close you need to be to the nearest part of the choppa to board.");
			ChaseDistance = cfg.Bind<float>("Model", "ChaseCameraDistance", 12f, "Chase camera distance behind the choppa.");
			ChaseHeight = cfg.Bind<float>("Model", "ChaseCameraHeight", 3.5f, "Chase camera height above the choppa.");
			CockpitEyeHeight = cfg.Bind<float>("Model", "CockpitEyeHeightOffset", 0f, "Nudge the cockpit camera up/down.");
			SitWhileFlying = cfg.Bind<bool>("Model", "SitWhileFlying", true, "Ask the game to put your character in its sitting pose while flying.");
			ChoppaLayer = cfg.Bind<int>("Model", "PhysicsLayer", -1, "Unity layer for the choppa's colliders. -1 = auto-detect one that collides with the ground (see LogOutput.log).");
			HeadlightIntensity = cfg.Bind<float>("Lights", "HeadlightIntensity", 1f, "Headlight brightness. Small changes go a long way. 0 = off.");
			HeadlightRange = cfg.Bind<float>("Lights", "HeadlightRange", 250f, "How far the headlight reaches (metres).");
			HeadlightAngle = cfg.Bind<float>("Lights", "HeadlightAngle", 40f, "Width of the headlight cone (degrees).");
			HeadlightTilt = cfg.Bind<float>("Lights", "HeadlightTilt", 6f, "How far the headlight points below the nose (degrees).");
			GlowIntensity = cfg.Bind<float>("Lights", "CabinGlow", 2f, "Faint always-on cabin light so a choppa is visible in the dark. 0 = off.");
			AudioVolume = cfg.Bind<float>("Audio", "Volume", 0.4f, "Choppa sound volume (rotor, motor, bonks). 0 = silent.");
			AudioMaxDistance = cfg.Bind<float>("Audio", "MaxHearingDistance", 250f, "How far away you can hear a choppa (metres).");
			LogbookEnabled = cfg.Bind<bool>("Pilot Logbook", "Enabled", true, "Send a few anonymous flight stats (spawns, boardings, flight time/height/speed) so the author can see how the choppa gets used. No names, Steam IDs or locations. Set to false to turn it off completely.");
			LogbookInstallId = cfg.Bind<string>("Pilot Logbook", "AnonymousId", "", "Random id generated on first use so your flights can be told apart from other people's. Not linked to you. Delete it to get a new one.");
			NetEnabled = cfg.Bind<bool>("Networking", "Enabled", true, "Share choppas with other players. Everyone in the lobby (host included) needs the mod; a host without it may kick you when you join.");
			NetSendRate = cfg.Bind<float>("Networking", "SendRate", 20f, "Position updates per second sent for a choppa you're flying.");
			NetInterpDelay = cfg.Bind<float>("Networking", "InterpolationDelay", 0.15f, "Seconds other players' choppas are shown in the past so their motion stays smooth. Raise if they stutter.");
			ShowHud = cfg.Bind<bool>("Debug", "ShowHud", true, "Show the flight HUD while flying.");
			VerboseLogging = cfg.Bind<bool>("Debug", "VerboseLogging", false, "Log extra detail to LogOutput.log and show a network status line on screen.");
			Migrate(cfg);
		}

		public static void WatchForEdits(ConfigFile cfg)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			file = cfg;
			try
			{
				watcher = new FileSystemWatcher(Path.GetDirectoryName(cfg.ConfigFilePath), Path.GetFileName(cfg.ConfigFilePath))
				{
					NotifyFilter = (NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite)
				};
				watcher.Changed += delegate
				{
					lastChangeMs = Environment.TickCount64;
				};
				watcher.Created += delegate
				{
					lastChangeMs = Environment.TickCount64;
				};
				watcher.Renamed += delegate
				{
					lastChangeMs = Environment.TickCount64;
				};
				watcher.EnableRaisingEvents = true;
			}
			catch (Exception ex)
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(32, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Config live reload unavailable: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				l.LogWarning(val);
			}
		}

		public static void Tick()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			long num = lastChangeMs;
			if (num < 0 || Environment.TickCount64 - num < 300)
			{
				return;
			}
			lastChangeMs = -1L;
			bool saveOnConfigSet = file.SaveOnConfigSet;
			file.SaveOnConfigSet = false;
			try
			{
				file.Reload();
				Plugin.L.LogInfo((object)"Config reloaded from disk.");
			}
			catch (Exception ex)
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(22, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Config reload failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				l.LogWarning(val);
			}
			finally
			{
				file.SaveOnConfigSet = saveOnConfigSet;
			}
		}

		private static void Migrate(ConfigFile cfg)
		{
			ConfigEntry<int> val = cfg.Bind<int>("Internal", "ConfigVersion", 0, "Used to apply updated defaults when the mod updates. Don't edit.");
			int value = val.Value;
			if (value < 3)
			{
				if (value < 1)
				{
					Upgrade(CenterOfMassHeight, 1.4f);
				}
				if (value < 2)
				{
					Upgrade(HeliScale, 1f);
				}
				if (value < 3)
				{
					Upgrade(AudioVolume, 0.8f);
				}
				val.Value = 3;
			}
		}

		private static void Upgrade<T>(ConfigEntry<T> entry, T oldDefault)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if (EqualityComparer<T>.Default.Equals(entry.Value, oldDefault))
			{
				entry.Value = (T)((ConfigEntryBase)entry).DefaultValue;
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(56, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Config: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ConfigDefinition>(((ConfigEntryBase)entry).Definition);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" updated to new default ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<T>(entry.Value);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (was the old default ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<T>(oldDefault);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
				}
				l.LogInfo(val);
			}
		}
	}
	internal static class ChoppaCrash
	{
		public static void Break(Helicopter heli, int seed)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			State state = Random.state;
			Random.InitState(seed);
			try
			{
				BreakSeeded(heli);
			}
			finally
			{
				Random.state = state;
			}
		}

		private static void BreakSeeded(Helicopter heli)
		{
			//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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)heli).transform.Find("Model");
			Vector3 impactVelocity = heli.ImpactVelocity;
			heli.Body.isKinematic = true;
			Vector3 val2 = ((Component)heli).transform.TransformPoint(heli.Body.centerOfMass);
			float scale = heli.Scale;
			float value = ChoppaConfig.DebrisSeconds.Value;
			ChoppaAudio.PlayCrash(val2);
			List<Transform> list = new List<Transform>();
			if ((Object)(object)heli.MainRotor != (Object)null)
			{
				list.Add(heli.MainRotor);
			}
			if ((Object)(object)heli.TailRotor != (Object)null)
			{
				list.Add(heli.TailRotor);
			}
			if ((Object)(object)val != (Object)null)
			{
				foreach (MeshRenderer componentsInChild in ((Component)val).GetComponentsInChildren<MeshRenderer>(true))
				{
					Transform transform = ((Component)componentsInChild).transform;
					if ((!((Object)(object)heli.MainRotor != (Object)null) || !transform.IsChildOf(heli.MainRotor)) && (!((Object)(object)heli.TailRotor != (Object)null) || !transform.IsChildOf(heli.TailRotor)))
					{
						list.Add(transform);
					}
				}
			}
			foreach (Transform item in list)
			{
				item.SetParent((Transform)null, true);
				foreach (MeshRenderer componentsInChild2 in ((Component)item).GetComponentsInChildren<MeshRenderer>(true))
				{
					if ((Object)(object)((Component)componentsInChild2).GetComponent<Collider>() == (Object)null)
					{
						AddCollider(((Component)componentsInChild2).gameObject, heli.Vehicle);
					}
				}
				Rigidbody val3 = ((Component)item).gameObject.AddComponent<Rigidbody>();
				bool flag = (Object)(object)item == (Object)(object)heli.MainRotor || (Object)(object)item == (Object)(object)heli.TailRotor;
				val3.mass = (flag ? 40f : 15f);
				val3.interpolation = (RigidbodyInterpolation)1;
				val3.maxAngularVelocity = 60f;
				val3.angularDamping = 0.3f;
				Vector3 val4 = item.position - val2;
				val4 = ((((Vector3)(ref val4)).sqrMagnitude < 0.01f) ? Random.onUnitSphere : ((Vector3)(ref val4)).normalized);
				float value2 = ChoppaConfig.CrashBlast.Value;
				val3.linearVelocity = impactVelocity * 0.5f + val4 * Random.Range(0.4f, 1f) * value2 * scale + Vector3.up * Random.Range(0.3f, 0.8f) * value2 * scale;
				val3.angularVelocity = Random.insideUnitSphere * 12f;
				ChoppaPhysics.CollideWithEverything(((Component)item).gameObject);
				ChoppaBonker.Add(((Component)item).gameObject, flag ? 0.8f : Random.Range(0.1f, 0.6f), 2f, flag ? 0.35f : 0.2f, 0.3f);
				if ((Object)(object)item == (Object)(object)heli.MainRotor)
				{
					val3.linearVelocity += ((Component)heli).transform.up * (value2 * 0.8f * scale);
					val3.angularVelocity = ((Component)heli).transform.up * (heli.RotorSpin * 40f + 5f);
				}
				if (value > 0f)
				{
					Object.Destroy((Object)(object)((Component)item).gameObject, value + Random.Range(0f, 3f));
				}
			}
			Object.Destroy((Object)(object)((Component)heli).gameObject);
		}

		private static void AddCollider(GameObject go, Vehicle vehicle)
		{
			MeshFilter component = go.GetComponent<MeshFilter>();
			Mesh val = ((component != null) ? component.sharedMesh : null);
			if (vehicle == Vehicle.LittleBird && (Object)(object)val != (Object)null && val.isReadable)
			{
				MeshCollider obj = go.AddComponent<MeshCollider>();
				obj.sharedMesh = val;
				obj.convex = true;
			}
			else
			{
				go.AddComponent<BoxCollider>();
			}
		}
	}
	internal static class ChoppaInput
	{
		private static bool rewiredBroken;

		private static bool unityBroken;

		private static readonly Dictionary<KeyCode, bool> prev = new Dictionary<KeyCode, bool>();

		private static readonly Dictionary<KeyCode, bool> cur = new Dictionary<KeyCode, bool>();

		public static string ActiveBackend { get; private set; } = "none";

		public static void Tick()
		{
			//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_0024: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyCode item in new List<KeyCode>(cur.Keys))
			{
				prev[item] = cur[item];
				cur[item] = RawKey(item);
			}
		}

		public static bool Held(KeyCode k)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if ((int)k == 0)
			{
				return false;
			}
			if (!cur.ContainsKey(k))
			{
				cur[k] = RawKey(k);
				prev[k] = cur[k];
			}
			return cur[k];
		}

		public static bool Pressed(KeyCode k)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (Held(k))
			{
				return !prev[k];
			}
			return false;
		}

		public static float Axis(KeyCode negative, KeyCode positive)
		{
			//IL_0000: 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)
			return (Held(positive) ? 1f : 0f) - (Held(negative) ? 1f : 0f);
		}

		public static Vector2 MouseDelta()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			if (UseRewired())
			{
				try
				{
					if (ReInput.isReady)
					{
						Mouse mouse = ReInput.controllers.Mouse;
						ActiveBackend = "Rewired";
						return new Vector2(((ControllerWithAxes)mouse).GetAxisRaw(0), ((ControllerWithAxes)mouse).GetAxisRaw(1));
					}
				}
				catch (Exception e)
				{
					MarkRewiredBroken(e);
				}
			}
			if (UseUnity())
			{
				try
				{
					ActiveBackend = "Unity";
					return new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
				}
				catch (Exception e2)
				{
					MarkUnityBroken(e2);
				}
			}
			return Vector2.zero;
		}

		private static bool RawKey(KeyCode k)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (UseRewired())
			{
				try
				{
					if (ReInput.isReady && ReInput.controllers.keyboardEnabled)
					{
						return ReInput.controllers.Keyboard.GetKey(k);
					}
				}
				catch (Exception e)
				{
					MarkRewiredBroken(e);
				}
			}
			if (UseUnity())
			{
				try
				{
					return Input.GetKey(k);
				}
				catch (Exception e2)
				{
					MarkUnityBroken(e2);
				}
			}
			return false;
		}

		private static bool UseRewired()
		{
			if (!rewiredBroken)
			{
				return ChoppaConfig.Backend.Value != InputBackend.Unity;
			}
			return false;
		}

		private static bool UseUnity()
		{
			if (!unityBroken)
			{
				return ChoppaConfig.Backend.Value != InputBackend.Rewired;
			}
			return false;
		}

		private static void MarkRewiredBroken(Exception e)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			rewiredBroken = true;
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(51, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Rewired input failed, falling back to Unity Input: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.Message);
			}
			l.LogWarning(val);
		}

		private static void MarkUnityBroken(Exception e)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			unityBroken = true;
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Unity legacy Input failed: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.Message);
			}
			l.LogWarning(val);
		}
	}
	internal sealed class ChoppaLights
	{
		private struct Lens
		{
			public MeshRenderer Renderer;

			public Material On;

			public Material Off;

			public void Set(bool on)
			{
				if ((Object)(object)Renderer != (Object)null)
				{
					((Renderer)Renderer).sharedMaterial = (on ? On : Off);
				}
			}
		}

		public enum LensKind
		{
			Steady,
			Beacon,
			Strobe
		}

		public readonly record struct LensSpec(string Name, Vector3 Pos, float Size, Color Color, LensKind Kind);

		public sealed class Layout
		{
			public readonly List<LensSpec> Lenses = new List<LensSpec>();

			public Vector3 Headlight;

			public Vector3 Glow;

			public Vector3 BeaconGlow;
		}

		private static readonly Color NavRed = new Color(1f, 0.08f, 0.05f);

		private static readonly Color NavGreen = new Color(0.1f, 1f, 0.25f);

		private static readonly Color White = new Color(1f, 0.97f, 0.9f);

		private static readonly Color Warm = new Color(1f, 0.85f, 0.6f);

		private Light headlight;

		private Light glow;

		private Light beaconLight;

		private Lens[] steady;

		private Lens[] beacons;

		private Lens[] strobes;

		private float phase;

		private bool wasPowered = true;

		public static Layout Classic()
		{
			//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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006d: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			return new Layout
			{
				Headlight = new Vector3(0f, 0.75f, 2.15f),
				Glow = new Vector3(0f, 2.4f, 0.1f),
				BeaconGlow = new Vector3(0f, 3.45f, -0.95f),
				Lenses = 
				{
					new LensSpec("NavLeft", new Vector3(-1.03f, 1.2f, 1f), 0.16f, NavRed, LensKind.Steady),
					new LensSpec("NavRight", new Vector3(1.03f, 1.2f, 1f), 0.16f, NavGreen, LensKind.Steady),
					new LensSpec("TailLight", new Vector3(0f, 1.15f, -4.85f), 0.14f, White, LensKind.Steady),
					new LensSpec("HeadlightLeft", new Vector3(-0.5f, 0.75f, 1.92f), 0.24f, White, LensKind.Steady),
					new LensSpec("HeadlightRight", new Vector3(0.5f, 0.75f, 1.92f), 0.24f, White, LensKind.Steady),
					new LensSpec("BeaconTop", new Vector3(0f, 3.25f, -0.95f), 0.22f, NavRed, LensKind.Beacon),
					new LensSpec("BeaconBelly", new Vector3(0f, 0.48f, -0.5f), 0.2f, NavRed, LensKind.Beacon),
					new LensSpec("StrobeLeft", new Vector3(-0.72f, 1.2f, -4.3f), 0.12f, White, LensKind.Strobe),
					new LensSpec("StrobeRight", new Vector3(0.72f, 1.2f, -4.3f), 0.12f, White, LensKind.Strobe)
				}
			};
		}

		public static ChoppaLights Build(Transform model, uint id, float scale, Layout layout)
		{
			//IL_0067: 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_009a: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			ChoppaLights obj = new ChoppaLights
			{
				phase = (float)(id % 1000) * 0.137f,
				steady = Make(LensKind.Steady),
				beacons = Make(LensKind.Beacon),
				strobes = Make(LensKind.Strobe),
				headlight = MakeLight(model, "Headlight", layout.Headlight, (LightType)0, White)
			};
			obj.headlight.renderMode = (LightRenderMode)1;
			obj.glow = MakeLight(model, "CabinGlow", layout.Glow, (LightType)2, Warm);
			obj.glow.range = 6f * scale;
			obj.beaconLight = MakeLight(model, "BeaconGlow", layout.BeaconGlow, (LightType)2, NavRed);
			obj.beaconLight.range = 10f * scale;
			obj.beaconLight.intensity = 3f;
			return obj;
			Lens[] Make(LensKind kind)
			{
				return (from s in layout.Lenses
					where s.Kind == kind
					select MakeLens(model, s.Name, s.Pos, s.Size, s.Color)).ToArray();
			}
		}

		public void Drive(bool powered)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			((Component)headlight).transform.localRotation = Quaternion.Euler(ChoppaConfig.HeadlightTilt.Value, 0f, 0f);
			headlight.range = ChoppaConfig.HeadlightRange.Value;
			headlight.spotAngle = ChoppaConfig.HeadlightAngle.Value;
			headlight.innerSpotAngle = ChoppaConfig.HeadlightAngle.Value * 0.5f;
			headlight.intensity = ChoppaConfig.HeadlightIntensity.Value;
			((Behaviour)headlight).enabled = powered && headlight.intensity > 0f;
			glow.intensity = ChoppaConfig.GlowIntensity.Value;
			((Behaviour)glow).enabled = glow.intensity > 0f;
			if (powered != wasPowered)
			{
				wasPowered = powered;
				Lens[] array = steady;
				foreach (Lens lens in array)
				{
					lens.Set(powered);
				}
				if (!powered)
				{
					((Behaviour)beaconLight).enabled = false;
					array = beacons;
					foreach (Lens lens2 in array)
					{
						lens2.Set(on: false);
					}
					array = strobes;
					foreach (Lens lens3 in array)
					{
						lens3.Set(on: false);
					}
				}
			}
			if (powered)
			{
				float num = Time.time + phase;
				bool flag = Mathf.Repeat(num, 1f) < 0.12f;
				float num2 = Mathf.Repeat(num * 0.83f, 1.2f);
				bool flag2 = num2 < 0.05f || (num2 > 0.15f && num2 < 0.2f);
				((Behaviour)beaconLight).enabled = flag;
				Lens[] array = beacons;
				foreach (Lens lens4 in array)
				{
					lens4.Set(flag);
				}
				array = strobes;
				foreach (Lens lens5 in array)
				{
					lens5.Set(flag2);
				}
			}
		}

		private static Lens MakeLens(Transform model, string name, Vector3 pos, float size, Color color)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			Transform val = HeliModel.Part(model, (PrimitiveType)0, name, pos, Vector3.zero, Vector3.one * size, color, solid: false);
			return new Lens
			{
				Renderer = ((Component)val).GetComponent<MeshRenderer>(),
				On = ChoppaMaterials.GetGlow(color),
				Off = ChoppaMaterials.Get(new Color(color.r * 0.35f, color.g * 0.35f, color.b * 0.35f))
			};
		}

		private static Light MakeLight(Transform model, string name, Vector3 pos, LightType type, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(model, false);
			val.transform.localPosition = pos;
			Light obj = val.AddComponent<Light>();
			obj.type = type;
			obj.color = color;
			obj.shadows = (LightShadows)0;
			return obj;
		}
	}
	internal static class ChoppaLogbook
	{
		public struct Flight
		{
			public float Seconds;

			public float Distance;

			public float MaxAltitude;

			public float TopSpeedKmh;

			public float EndSpeedKmh;

			public float UpsideDownSeconds;

			public float CockpitPercent;

			public string How;

			public string Vehicle;

			public int Riders;

			public int MaxRiders;

			public int Rolls;

			public int Loops;

			public int PocketItems;
		}

		private const string Endpoint = "https://us.i.posthog.com/batch/";

		private const string ProjectKey = "phc_ubbcXrLXwRGBKUnLChUj6uzMQpCMNrcmjLALTKQMivbg";

		private static readonly HttpClient http = new HttpClient
		{
			Timeout = TimeSpan.FromSeconds(10.0)
		};

		private static readonly List<Dictionary<string, object>> queue = new List<Dictionary<string, object>>();

		private static float nextFlush;

		private static bool sending;

		private static bool On => ChoppaConfig.LogbookEnabled.Value;

		public static void Spawned(Vehicle vehicle)
		{
			Log("choppa_spawned", new Dictionary<string, object> { ["vehicle"] = Vehicles.Id(vehicle) });
		}

		public static void Boarded(string seat)
		{
			Log("choppa_boarded", new Dictionary<string, object> { ["seat"] = seat });
		}

		public static void FlightEnded(Flight f)
		{
			Log("flight_ended", new Dictionary<string, object>
			{
				["duration_s"] = Mathf.Round(f.Seconds),
				["distance_m"] = Mathf.Round(f.Distance),
				["max_altitude_m"] = Mathf.Round(f.MaxAltitude),
				["top_speed_kmh"] = Mathf.Round(f.TopSpeedKmh),
				["end_speed_kmh"] = Mathf.Round(f.EndSpeedKmh),
				["how"] = f.How,
				["vehicle"] = f.Vehicle,
				["riders"] = f.Riders,
				["max_riders"] = f.MaxRiders,
				["pocket_items"] = f.PocketItems,
				["rolls"] = f.Rolls,
				["loops"] = f.Loops,
				["upside_down_s"] = Mathf.Round(f.UpsideDownSeconds),
				["cockpit_view_pct"] = Mathf.Round(f.CockpitPercent)
			});
		}

		public static void RideEnded(float seconds, string how)
		{
			Log("ride_ended", new Dictionary<string, object>
			{
				["duration_s"] = Mathf.Round(seconds),
				["how"] = how
			});
		}

		public static void EndedAbruptly(float impactKmh, int riders, bool piloted, int pocketItems)
		{
			Log("choppa_ended_abruptly", new Dictionary<string, object>
			{
				["impact_kmh"] = Mathf.Round(impactKmh),
				["riders"] = riders,
				["piloted"] = piloted,
				["pocket_items"] = pocketItems
			});
		}

		public static void PocketUsed(bool stowed, string item)
		{
			Log("pocket_used", new Dictionary<string, object>
			{
				["action"] = (stowed ? "stowed" : "taken"),
				["item"] = (item ?? "").Replace("(Clone)", "").Trim()
			});
		}

		public static void FlippedUpright(bool seated)
		{
			Log("flipped_upright", new Dictionary<string, object> { ["from"] = (seated ? "inside" : "outside") });
		}

		public static void JumpedOut(string seat, float height, float speedKmh)
		{
			Log("jumped_out", new Dictionary<string, object>
			{
				["seat"] = seat,
				["height_m"] = Mathf.Round(height),
				["speed_kmh"] = Mathf.Round(speedKmh)
			});
		}

		private static void Log(string evt, Dictionary<string, object> props)
		{
			if (!On)
			{
				return;
			}
			if (props == null)
			{
				props = new Dictionary<string, object>();
			}
			props["distinct_id"] = InstallId();
			props["mod_version"] = "3.0.3";
			props["$process_person_profile"] = false;
			props["$geoip_disable"] = true;
			props["$ip"] = "";
			lock (queue)
			{
				queue.Add(new Dictionary<string, object>
				{
					["event"] = evt,
					["properties"] = props,
					["timestamp"] = DateTime.UtcNow.ToString("o")
				});
				if (queue.Count > 200)
				{
					queue.RemoveAt(0);
				}
			}
			Plugin.Verbose("Logbook: " + evt);
		}

		private static string InstallId()
		{
			string text = ChoppaConfig.LogbookInstallId.Value;
			if (string.IsNullOrEmpty(text))
			{
				text = Guid.NewGuid().ToString("N");
				ChoppaConfig.LogbookInstallId.Value = text;
			}
			return text;
		}

		public static void Tick()
		{
			if (Time.unscaledTime < nextFlush)
			{
				return;
			}
			nextFlush = Time.unscaledTime + 30f;
			string json = TakeBatch();
			if (json == null || sending)
			{
				return;
			}
			sending = true;
			Task.Run(async delegate
			{
				try
				{
					await http.PostAsync("https://us.i.posthog.com/batch/", new StringContent(json, Encoding.UTF8, "application/json"));
				}
				catch
				{
				}
				finally
				{
					sending = false;
				}
			});
		}

		public static void FlushNow()
		{
			string text = TakeBatch();
			if (text == null)
			{
				return;
			}
			try
			{
				http.PostAsync("https://us.i.posthog.com/batch/", new StringContent(text, Encoding.UTF8, "application/json")).Wait(TimeSpan.FromSeconds(2.0));
			}
			catch
			{
			}
		}

		private static string TakeBatch()
		{
			lock (queue)
			{
				if (queue.Count == 0)
				{
					return null;
				}
				if (!On)
				{
					queue.Clear();
					return null;
				}
				string result = JsonSerializer.Serialize(new Dictionary<string, object>
				{
					["api_key"] = "phc_ubbcXrLXwRGBKUnLChUj6uzMQpCMNrcmjLALTKQMivbg",
					["batch"] = queue
				});
				queue.Clear();
				return result;
			}
		}
	}
	public class ChoppaManager : MonoBehaviour
	{
		private enum CamMode
		{
			Chase,
			Cockpit
		}

		private PlayerCharacter local;

		private float nextPlayerSearch;

		private readonly Dictionary<uint, Helicopter> helis = new Dictionary<uint, Helicopter>();

		private readonly Dictionary<uint, PlayerCharacter> players = new Dictionary<uint, PlayerCharacter>();

		private readonly Dictionary<uint, float> sendTimers = new Dictionary<uint, float>();

		private float nextPlayerScan;

		private int choppaLayer = -1;

		private bool seated;

		private Helicopter seatHeli;

		private int seatIndex;

		private uint pendingBoardId;

		private float pendingBoardUntil;

		private uint pendingSpawnId;

		private Rigidbody playerBody;

		private Transform playerRoot;

		private Collider[] playerColliders = Array.Empty<Collider>();

		private bool savedKinematic;

		private bool savedDetect;

		private bool savedBypassUpdate;

		private bool savedBypassFixed;

		private bool savedBypassLate;

		private RigidbodyInterpolation savedInterp;

		private Transform kernal;

		private Quaternion savedKernalLocalRot;

		private Camera cam;

		private Transform camParent;

		private Vector3 camLocalPos;

		private Quaternion camLocalRot;

		private Vector3 eyeOffset;

		private CamMode camMode;

		private Vector2 smoothedCyclic;

		private float lookYaw;

		private float lookPitch;

		private Vector3 chaseVel;

		private bool showHud;

		private string lastHint;

		private ChoppaMenu menu;

		private const float FlyInDistance = 220f;

		private (Vector3 target, float cruiseY)? pendingFlyIn;

		private Helicopter spawnHeli;

		private float spawnY;

		private float spawnCheckAt = -1f;

		private readonly List<Renderer> shownBody = new List<Renderer>();

		private bool bodyShown;

		private float flightStart = -1f;

		private float flightMaxAlt;

		private float flightTopSpeed;

		private float flightDistance;

		private float groundedSince = -1f;

		private float flightUpsideDown;

		private float flightCockpitTime;

		private float flightRollAccum;

		private float flightPitchAccum;

		private float rideStart = -1f;

		private int flightRolls;

		private int flightLoops;

		private int flightMaxRiders;

		private Vector3 flightLastPos;

		private Helicopter benchHeli;

		private float hintUntil;

		private uint Me => ChoppaNet.LocalNetId;

		public ChoppaManager(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Start()
		{
			showHud = ChoppaConfig.ShowHud.Value;
			menu = new ChoppaMenu(RequestSpawn, MenuStatus);
			Helicopter.Crashed += OnOwnCrash;
			ChoppaNet.ServerReceived = ChoppaServer.OnMessage;
			ChoppaNet.ClientReceived = OnClientMessage;
			ChoppaNet.ModeChanged = ClearWorld;
		}

		private void OnDestroy()
		{
			Helicopter.Crashed -= OnOwnCrash;
		}

		private void OnApplicationQuit()
		{
			ChoppaLogbook.FlushNow();
		}

		private void Update()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			try
			{
				Tick();
			}
			catch (Exception ex)
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ChoppaManager.Update: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				l.LogError(val);
			}
		}

		private void Tick()
		{
			//IL_00bc: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Invalid comparison between Unknown and I4
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Invalid comparison between Unknown and I4
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			ChoppaConfig.Tick();
			ChoppaInput.Tick();
			ChoppaNet.Tick();
			ChoppaBenches.TickDying();
			if (!FindLocalPlayer())
			{
				if (seated)
				{
					ForceUnseat("local player disappeared");
				}
				return;
			}
			ChoppaNet.LocalNetId = ((((NetworkBehaviour)local).netId == 0) ? 1u : ((NetworkBehaviour)local).netId);
			PruneDead();
			if (Time.unscaledTime >= nextPlayerScan)
			{
				ScanPlayers();
			}
			TrackBench();
			if (menu.IsOpen)
			{
				if (seated || ChoppaInput.Pressed(ChoppaConfig.SpawnKey.Value))
				{
					menu.Close();
				}
				else
				{
					menu.Tick();
				}
			}
			else if (!seated && ChoppaInput.Pressed(ChoppaConfig.SpawnKey.Value) && (!ChoppaConfig.RequireCursorLock.Value || (int)Cursor.lockState == 1))
			{
				if (!ChoppaNet.Ready)
				{
					Hint("Waiting for the host's Big Choppa to answer (does the host have the mod?).");
				}
				else
				{
					menu.Open();
				}
			}
			bool flag = !menu.IsOpen && (!ChoppaConfig.RequireCursorLock.Value || (int)Cursor.lockState == 1);
			if (flag && ChoppaInput.Pressed(ChoppaConfig.HudKey.Value))
			{
				showHud = !showHud;
			}
			if (flag && ChoppaInput.Pressed(ChoppaConfig.ResetKey.Value))
			{
				ResetMine();
			}
			if (flag && ChoppaInput.Pressed(ChoppaConfig.EnterExitKey.Value))
			{
				if (seated)
				{
					Leave();
				}
				else if (!InGamePose())
				{
					TryBoard();
				}
			}
			if (pendingBoardId != 0 && Time.time > pendingBoardUntil)
			{
				pendingBoardId = 0u;
				Hint("Couldn't board - the seat was taken or the host didn't answer.");
			}
			CheckSpawnSettled();
			foreach (Helicopter value in helis.Values)
			{
				if (!value.IsProxy && (!seated || !((Object)(object)seatHeli == (Object)(object)value) || seatIndex != 0))
				{
					value.CommandedRates = Vector3.zero;
				}
			}
			if (seated && seatIndex == 0 && !seatHeli.IsProxy)
			{
				FlyInput(flag);
				TrackFlight(seatHeli);
			}
			SendStates();
			ChoppaLogbook.Tick();
		}

		private void FixedUpdate()
		{
			if (seated)
			{
				PinPlayer();
			}
			PinRemotePassengers();
		}

		private void LateUpdate()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			try
			{
				PinRemotePassengers();
				if (seated)
				{
					PinPlayer();
					UpdateCamera();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(26, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ChoppaManager.LateUpdate: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				l.LogError(val);
			}
		}

		private bool FindLocalPlayer()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			if ((Object)(object)local != (Object)null && Alive((Objec