Decompiled source of SkyGuard v2.3.1

Mods/SkyGuard.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.AI;
using Il2CppSLZ.Marrow.Pool;
using Il2CppSystem;
using Il2CppSystem.Reflection;
using LabFusion.Entities;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using SkyGuard;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(SkyGuardMod), "SkyGuard", "2.3.1", "callofike", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonAdditionalDependencies(new string[] { "BoneLib" })]
[assembly: MelonOptionalDependencies(new string[] { "LabFusion" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SkyGuard
{
	internal sealed class Canvas
	{
		public readonly int W;

		public readonly int H;

		private readonly Color32[] _px;

		private readonly Il2CppStructArray<Color32> _native;

		private readonly Texture2D _tex;

		public readonly GameObject Quad;

		public Canvas(Transform overlay, int w, int h)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			W = w;
			H = h;
			_px = (Color32[])(object)new Color32[w * h];
			_native = new Il2CppStructArray<Color32>((long)(w * h));
			_tex = new Texture2D(w, h, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			((Object)_tex).hideFlags = (HideFlags)32;
			Quad = ((Component)overlay).gameObject;
			((Renderer)((Component)overlay).GetComponent<MeshRenderer>()).material.SetTexture("_MainTex", (Texture)(object)_tex);
			Quad.SetActive(true);
		}

		public void Dispose()
		{
			if ((Object)(object)_tex != (Object)null)
			{
				Object.Destroy((Object)(object)_tex);
			}
		}

		public void Clear()
		{
			Array.Clear(_px, 0, _px.Length);
		}

		public void Show()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _px.Length; i++)
			{
				((Il2CppArrayBase<Color32>)(object)_native)[i] = _px[i];
			}
			_tex.SetPixels32(_native);
			_tex.Apply(false);
		}

		public void Dot(int x, int y, Color32 c)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (x >= 0 && y >= 0 && x < W && y < H)
			{
				_px[y * W + x] = c;
			}
		}

		public void Box(int x, int y, int r, Color32 c)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			for (int i = -r; i <= r; i++)
			{
				for (int j = -r; j <= r; j++)
				{
					Dot(x + j, y + i, c);
				}
			}
		}

		public void Line(int x0, int y0, int x1, int y1, Color32 c)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Abs(x1 - x0);
			int num2 = -Mathf.Abs(y1 - y0);
			int num3 = ((x0 < x1) ? 1 : (-1));
			int num4 = ((y0 < y1) ? 1 : (-1));
			int num5 = num + num2;
			for (int i = 0; i < 2000; i++)
			{
				Dot(x0, y0, c);
				if (x0 != x1 || y0 != y1)
				{
					int num6 = 2 * num5;
					if (num6 >= num2)
					{
						num5 += num2;
						x0 += num3;
					}
					if (num6 <= num)
					{
						num5 += num;
						y0 += num4;
					}
					continue;
				}
				break;
			}
		}

		public void Ring(int x, int y, int r, Color32 c)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 32; i++)
			{
				float num = (float)i * (float)Math.PI / 16f;
				Dot(x + Mathf.RoundToInt((float)r * Mathf.Cos(num)), y + Mathf.RoundToInt((float)r * Mathf.Sin(num)), c);
			}
		}

		public void Text(string s, int x, int y, Color32 c, int scale = 1)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			string text = s.ToUpperInvariant();
			foreach (char key in text)
			{
				if (Glyphs.Rows.TryGetValue(key, out var value))
				{
					for (int j = 0; j < 7; j++)
					{
						for (int k = 0; k < 5; k++)
						{
							if (value[j * 5 + k] != '1')
							{
								continue;
							}
							for (int l = 0; l < scale; l++)
							{
								for (int m = 0; m < scale; m++)
								{
									Dot(x + k * scale + l, y - j * scale - m, c);
								}
							}
						}
					}
				}
				x += 6 * scale;
			}
		}
	}
	internal sealed class ConsoleDriver
	{
		private sealed class RigState
		{
			public Transform T;

			public Transform Missile;

			public Transform Trail;

			public Transform Mod;

			public Transform Point;

			public Animator Anim;

			public bool Flying;

			public bool Corrected;

			public bool Hit;

			public Vector3 Offset;

			public Vector3 Prev;

			public Vector3 Launch;

			public float Started;

			public float Len;

			public List<Vector3> Path = new List<Vector3>();
		}

		private const float MapHalf = 3400f;

		private const float RadarRange = 4000f;

		private const float Near = 15f;

		private const float Tilt = 33.109f;

		private const float YawRate = 20f;

		private const float ElevRate = 10f;

		private const float YawMax = 135f;

		private static readonly float[] RangeBins = new float[6] { 200f, 400f, 800f, 1200f, 2000f, 3000f };

		public readonly Transform Root;

		private readonly Animator _a;

		private readonly Animator _con;

		private readonly Transform _turret;

		private readonly Transform _box;

		private readonly Transform _stickL;

		private readonly Transform _stickR;

		private readonly Transform _knobRange;

		private readonly Transform _manual;

		private readonly Transform _ghostCam;

		private readonly Transform _ghostPip;

		private readonly Transform _aimGate;

		private readonly Transform _aimMode;

		private readonly Transform _mastMode;

		private readonly Transform _mastCam;

		private readonly Transform _clearCap;

		private readonly Transform _videoCap;

		private readonly Transform _radarSweep;

		private readonly Quaternion _restL;

		private readonly Quaternion _restR;

		private readonly Quaternion _knobRest;

		private readonly RigState[] _rigs = new RigState[4];

		private readonly Canvas _radar;

		private readonly Canvas _map;

		private readonly Canvas _status;

		private readonly Canvas _log;

		private readonly Canvas _main;

		private readonly List<string> _lines = new List<string>();

		private readonly List<(Vector3 p, float t)> _booms = new List<(Vector3, float)>();

		private float _next;

		private float _rangeM = 800f;

		private int _step;

		private bool _clearDown;

		private bool _videoDown;

		private bool _video;

		private bool _wasPower;

		private bool _wasArmed;

		private int _wasLoaded = 4;

		private float _ftOn;

		private float _ftOff;

		private float _ftNext;

		private int _nOn;

		private int _nOff;

		private GameObject _lamp;

		private GameObject _videoGo;

		private Camera _videoCamera;

		private static bool _noSpectatorLogged;

		private Vector3 _tp;

		private float _tpAt = -1f;

		private Transform _droneT;

		private float _pressOk;

		private static readonly Color32 Clear0 = new Color32((byte)0, (byte)0, (byte)0, (byte)0);

		private static readonly Color32 White = new Color32((byte)235, (byte)245, byte.MaxValue, byte.MaxValue);

		private static readonly Color32 Blue = new Color32((byte)90, (byte)190, byte.MaxValue, byte.MaxValue);

		private static readonly Color32 Amber = new Color32(byte.MaxValue, (byte)170, (byte)30, byte.MaxValue);

		private static readonly Color32 Red = new Color32(byte.MaxValue, (byte)40, (byte)25, byte.MaxValue);

		private static readonly Color32 Green = new Color32((byte)60, byte.MaxValue, (byte)100, byte.MaxValue);

		private static readonly Color32 Yellow = new Color32(byte.MaxValue, (byte)240, (byte)70, byte.MaxValue);

		private static readonly Color32 Grey = new Color32((byte)120, (byte)160, (byte)190, byte.MaxValue);

		public bool Gone
		{
			get
			{
				if (!((Object)(object)Root == (Object)null))
				{
					return !((Component)Root).gameObject.activeInHierarchy;
				}
				return true;
			}
		}

		private Vector3 _pivot => _turret.position;

		private Transform Deep(string n)
		{
			foreach (Transform componentsInChild in ((Component)Root).GetComponentsInChildren<Transform>(true))
			{
				if (((Object)componentsInChild).name == n)
				{
					return componentsInChild;
				}
			}
			return null;
		}

		public ConsoleDriver(Transform root)
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			Root = root;
			_a = ((Component)root).GetComponent<Animator>();
			_con = ((Component)root.Find("Console")).GetComponent<Animator>();
			_turret = Deep("Turret");
			_box = Deep("Patriot_Box");
			_stickL = Deep("Stick_L");
			_stickR = Deep("Stick_R");
			_knobRange = Deep("Knob_RANGE");
			_restL = _stickL.localRotation;
			_restR = _stickR.localRotation;
			_knobRest = _knobRange.localRotation;
			_manual = Deep("ManualMarkers");
			_aimGate = Deep("AimGate");
			_aimMode = Deep("AimMode");
			_mastMode = Deep("MastMode");
			_mastCam = Deep("CamMast");
			_radarSweep = Deep("SweepNode");
			_ghostCam = root.Find("Cams/DroneGhost/Cam");
			_ghostPip = root.Find("Cams/DroneGhost/Pip");
			_clearCap = Deep("Btn_CLEAR").Find("Cap");
			Transform val = Deep("Btn_VIDEO");
			((Component)val).gameObject.SetActive(true);
			_videoCap = val.Find("Cap");
			_lamp = ((Component)val.Find("Sel")).gameObject;
			for (int i = 0; i < 4; i++)
			{
				Transform val2 = Deep("Rig" + (i + 1));
				_rigs[i] = new RigState
				{
					T = val2,
					Anim = ((Component)val2).GetComponent<Animator>(),
					Missile = val2.Find("Missile"),
					Trail = val2.Find("Trail"),
					Point = val2.Find("Point"),
					Mod = val2.Find("Point/Mod")
				};
			}
			_radar = new Canvas(Deep("ModOverlay_Radar"), 192, 192);
			_map = new Canvas(Deep("ModOverlay_Map"), 192, 192);
			_status = new Canvas(Deep("ModOverlay_Status"), 280, 190);
			_log = new Canvas(Deep("ModOverlay_Log"), 150, 138);
			_main = new Canvas(Deep("ModOverlay_Main"), 340, 22);
			Log("SKYGUARD MOD ONLINE");
			MelonLogger.Msg("[SkyGuard] " + ((Object)root).name + " found at " + ((object)root.position/*cast due to .constrained prefix*/).ToString());
		}

		public void Dispose()
		{
			if (_video)
			{
				SetVideo(on: false);
			}
			Canvas[] array = new Canvas[5] { _radar, _map, _status, _log, _main };
			for (int i = 0; i < array.Length; i++)
			{
				array[i]?.Dispose();
			}
		}

		private void Log(string s)
		{
			_lines.Add(s);
			if (_lines.Count > 9)
			{
				_lines.RemoveAt(0);
			}
		}

		private float Elev()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			float num = _box.localEulerAngles.z;
			if (num > 180f)
			{
				num -= 360f;
			}
			return 33.109f - num;
		}

		private float Yaw()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			float y = _turret.localEulerAngles.y;
			if (!(y > 180f))
			{
				return y;
			}
			return y - 360f;
		}

		private Vector3 Aim()
		{
			//IL_0024: 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)
			float num = Yaw() * ((float)Math.PI / 180f);
			return Root.TransformDirection(new Vector3(Mathf.Sin(num), 0f, Mathf.Cos(num)));
		}

		private static float StickAngle(Transform stick, Quaternion rest, Vector3 axis)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			Quaternion val = Quaternion.Inverse(rest) * stick.localRotation;
			float num = default(float);
			Vector3 val2 = default(Vector3);
			((Quaternion)(ref val)).ToAngleAxis(ref num, ref val2);
			if (num > 180f)
			{
				num -= 360f;
			}
			return num * Mathf.Sign(Vector3.Dot(val2, axis));
		}

		private bool Ignored(Collider c)
		{
			if (!((Object)(object)c == (Object)null) && !((Component)c).transform.IsChildOf(Root))
			{
				return c.isTrigger;
			}
			return true;
		}

		private bool Ground(Vector3 p, out Vector3 hit)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			hit = p;
			float num = float.MaxValue;
			bool result = false;
			foreach (RaycastHit item in (Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(p + Vector3.up * 1500f, Vector3.down, 3000f, -1, (QueryTriggerInteraction)1))
			{
				RaycastHit current = item;
				if (!Ignored(((RaycastHit)(ref current)).collider) && !((Object)(object)((RaycastHit)(ref current)).collider.attachedRigidbody != (Object)null) && ((RaycastHit)(ref current)).distance < num)
				{
					num = ((RaycastHit)(ref current)).distance;
					hit = ((RaycastHit)(ref current)).point;
					result = true;
				}
			}
			return result;
		}

		private Vector3 TargetPoint()
		{
			//IL_0026: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time - _tpAt < 0.1f)
			{
				return _tp;
			}
			_tpAt = Time.time;
			Vector3 val = _pivot + Aim() * _rangeM;
			val.y = Root.position.y;
			Vector3 hit;
			return _tp = (Ground(val, out hit) ? hit : val);
		}

		public void Update()
		{
			//IL_002c: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: 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_01f6: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: 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)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			bool flag = _a.GetBool("Power");
			Transform head = Player.Head;
			if ((Object)(object)head != (Object)null)
			{
				_a.SetBool("Near", Vector3.Distance(head.position, Root.Find("Console").position) < 15f);
			}
			float slow;
			if (SkyGuardMod.PrefSmooth.Value)
			{
				if (((Component)_mastMode).gameObject.activeInHierarchy)
				{
					float num = StickAngle(_stickL, _restL, Vector3.up);
					float num2 = StickAngle(_stickR, _restR, Vector3.right);
					slow = Mathf.Lerp(1f, 0.08f, (float)_a.GetInteger("Zoom") / 4f);
					if (Mathf.Abs(num) > 3f)
					{
						_a.SetFloat("PanSpeed", Curve(0f - num));
					}
					if (Mathf.Abs(num2) > 3f)
					{
						_a.SetFloat("TiltSpeed", Curve(0f - num2));
					}
				}
				else if (((Component)_aimMode).gameObject.activeInHierarchy)
				{
					float num3 = StickAngle(_stickL, _restL, Vector3.up);
					float num4 = StickAngle(_stickR, _restR, Vector3.right);
					if (Mathf.Abs(num3) > 3f)
					{
						_a.SetFloat("YawSpeed", Mathf.Clamp((0f - num3) / 21f, -1f, 1f));
					}
					if (Mathf.Abs(num4) > 3f)
					{
						_a.SetFloat("ElevSpeed", Mathf.Clamp((0f - num4) / 21f, -1f, 1f));
					}
				}
				Quaternion val = Quaternion.Inverse(Quaternion.identity) * _knobRange.localRotation;
				float num5 = default(float);
				Vector3 val2 = default(Vector3);
				((Quaternion)(ref val)).ToAngleAxis(ref num5, ref val2);
				float num6 = ((num5 > 180f) ? (num5 - 360f) : num5) * Mathf.Sign(val2.z);
				_rangeM = Mathf.Lerp(200f, 3000f, Mathf.InverseLerp(135f, -135f, num6));
			}
			else
			{
				_rangeM = RangeBins[Mathf.Clamp(_a.GetInteger("Range"), 0, 5)];
			}
			if (((Component)_manual).gameObject.activeSelf)
			{
				foreach (Transform componentsInChild in ((Component)_manual).GetComponentsInChildren<Transform>(false))
				{
					if (((Object)componentsInChild).name.StartsWith("Marker"))
					{
						componentsInChild.position = TargetPoint();
						break;
					}
				}
			}
			RigState[] rigs = _rigs;
			foreach (RigState r in rigs)
			{
				Track(r);
			}
			int num7 = 0;
			AnimatorStateInfo currentAnimatorStateInfo;
			for (int j = 0; j <= 4; j++)
			{
				currentAnimatorStateInfo = _a.GetCurrentAnimatorStateInfo(1);
				if (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("Ready" + j))
				{
					num7 = j;
				}
			}
			currentAnimatorStateInfo = _a.GetCurrentAnimatorStateInfo(1);
			if (!((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("Reloading"))
			{
				if (num7 == 4 && _wasLoaded < 4)
				{
					Log("RELOADED");
				}
				_wasLoaded = num7;
			}
			if (flag != _wasPower)
			{
				Log(flag ? "POWER ON" : "POWER OFF");
				_wasPower = flag;
			}
			Transform val3 = Root.Find("Console/Logic/Powered/Armed");
			bool flag2 = val3 != null && ((Component)val3).gameObject.activeSelf;
			if (flag2 != _wasArmed)
			{
				Log(flag2 ? "ARMED" : "SAFE");
				_wasArmed = flag2;
			}
			if (Pressed(_clearCap, ref _clearDown))
			{
				foreach (GameObject warhead in World.Warheads)
				{
					if ((Object)(object)warhead != (Object)null)
					{
						warhead.SetActive(false);
					}
				}
			}
			if (Pressed(_videoCap, ref _videoDown))
			{
				SetVideo(!_video);
			}
			World.Thing thing = World.NearestDrone(Root.position, 3500f);
			if (thing != null)
			{
				_a.SetBool("DroneUp", true);
				_droneT = thing.T;
			}
			else
			{
				_droneT = null;
			}
			if (SkyGuardMod.PrefLogFrames.Value && _a.GetBool("Near"))
			{
				if (flag)
				{
					_ftOn += Time.unscaledDeltaTime;
					_nOn++;
				}
				else
				{
					_ftOff += Time.unscaledDeltaTime;
					_nOff++;
				}
				if (Time.unscaledTime > _ftNext)
				{
					_ftNext = Time.unscaledTime + 30f;
					if (_nOn + _nOff > 0)
					{
						MelonLogger.Msg($"[SkyGuard] frame time at the console: power on {((_nOn > 0) ? (1000f * _ftOn / (float)_nOn) : 0f):F2} ms, power off {((_nOff > 0) ? (1000f * _ftOff / (float)_nOff) : 0f):F2} ms");
					}
					_ftOn = (_ftOff = 0f);
					_nOn = (_nOff = 0);
				}
			}
			if (Time.unscaledTime < _next)
			{
				return;
			}
			_next = Time.unscaledTime + 0.05f;
			if (flag && _a.GetBool("Near"))
			{
				switch (_step++ % 5)
				{
				case 0:
					DrawRadar();
					break;
				case 1:
					DrawMap();
					break;
				case 2:
					DrawStatus();
					break;
				case 3:
					DrawLog();
					break;
				case 4:
					DrawMain();
					break;
				}
			}
			float Curve(float deg)
			{
				float num8 = Mathf.Clamp(deg / 21f, -1f, 1f);
				return num8 * Mathf.Abs(num8) * slow;
			}
		}

		private bool Pressed(Transform cap, ref bool down)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			float z = cap.localPosition.z;
			if (down)
			{
				if (z < -0.066f)
				{
					down = false;
				}
				return false;
			}
			if (z < -0.056f || Time.unscaledTime < _pressOk)
			{
				return false;
			}
			down = true;
			_pressOk = Time.unscaledTime + 1f;
			return true;
		}

		private string Bearing(Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = p - Root.position;
			string[] array = new string[8] { "N", "NE", "E", "SE", "S", "SW", "W", "NW" };
			int num = Mathf.RoundToInt(Mathf.Repeat(Mathf.Atan2(val.x, val.z) * 57.29578f, 360f) / 45f) % 8;
			DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(4, 2);
			Vector2 val2 = new Vector2(val.x, val.z);
			defaultInterpolatedStringHandler.AppendFormatted(((Vector2)(ref val2)).magnitude / 1000f, "F1");
			defaultInterpolatedStringHandler.AppendLiteral(" KM ");
			defaultInterpolatedStringHandler.AppendFormatted(array[num]);
			return defaultInterpolatedStringHandler.ToStringAndClear();
		}

		private void Track(RigState r)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			bool activeSelf = ((Component)r.Missile).gameObject.activeSelf;
			if (activeSelf && !r.Flying)
			{
				r.Flying = true;
				r.Corrected = false;
				r.Hit = false;
				r.Started = Time.time;
				r.Path.Clear();
				r.Prev = r.Missile.position;
				r.Launch = r.Prev;
				r.Mod.localPosition = Vector3.zero;
				r.Offset = Vector3.zero;
				Log("MISSILE " + ((Object)r.T).name.Substring(3) + " LAUNCHED");
			}
			else if (!activeSelf && r.Flying)
			{
				r.Flying = false;
				AnimatorStateInfo currentAnimatorStateInfo = r.Anim.GetCurrentAnimatorStateInfo(0);
				if (!((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsName("Aborted"))
				{
					Vector3 val = r.Point.position + r.Mod.localPosition;
					_booms.Add((val, Time.time));
					Log("DETONATION " + Bearing(val));
				}
				else
				{
					Log("MISSILE " + ((Object)r.T).name.Substring(3) + " ABORTED");
				}
			}
		}

		public void LateUpdate()
		{
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: 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_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: 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_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			RigState[] rigs = _rigs;
			foreach (RigState rigState in rigs)
			{
				if (!rigState.Flying || !((Component)rigState.Missile).gameObject.activeSelf)
				{
					continue;
				}
				bool num = rigState.Anim.GetInteger("Target") == 3;
				AnimatorStateInfo currentAnimatorStateInfo = rigState.Anim.GetCurrentAnimatorStateInfo(0);
				float normalizedTime = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime;
				if (num)
				{
					if (!rigState.Corrected)
					{
						rigState.Corrected = true;
						_tpAt = -1f;
						rigState.Offset = TargetPoint() - rigState.Point.position;
						rigState.Mod.position = rigState.Point.position + rigState.Offset;
						currentAnimatorStateInfo = rigState.Anim.GetCurrentAnimatorStateInfo(0);
						rigState.Len = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).length;
					}
					float num2 = Mathf.Clamp01(normalizedTime * rigState.Len / Mathf.Max(0.1f, rigState.Len - 0.3f));
					Vector3 val = rigState.Offset * num2 * num2 * (3f - 2f * num2);
					Transform missile = rigState.Missile;
					missile.position += val;
					Transform trail = rigState.Trail;
					trail.position += val;
					Vector3 position = rigState.Missile.position;
					if (!rigState.Hit && Time.time - rigState.Started > 1.5f && Vector3.Distance(position, rigState.Launch) > 60f)
					{
						Vector3 val2 = position - rigState.Prev;
						foreach (RaycastHit item in (Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(rigState.Prev, ((Vector3)(ref val2)).normalized, ((Vector3)(ref val2)).magnitude + 0.5f, -1, (QueryTriggerInteraction)1))
						{
							RaycastHit current = item;
							if (!Ignored(((RaycastHit)(ref current)).collider))
							{
								rigState.Hit = true;
								rigState.Mod.position = ((RaycastHit)(ref current)).point;
								float num3 = (rigState.Len - 0.3f) / rigState.Len;
								Animator anim = rigState.Anim;
								currentAnimatorStateInfo = rigState.Anim.GetCurrentAnimatorStateInfo(0);
								anim.Play(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash, 0, num3);
								break;
							}
						}
					}
					rigState.Prev = position;
				}
				if (rigState.Path.Count != 0)
				{
					Vector3 val3 = rigState.Path[rigState.Path.Count - 1] - rigState.Missile.position;
					if (!(((Vector3)(ref val3)).sqrMagnitude > 900f))
					{
						continue;
					}
				}
				rigState.Path.Add(rigState.Missile.position);
			}
			if ((Object)(object)_droneT != (Object)null)
			{
				Vector3 val4 = _droneT.position - _droneT.forward * 14f + Vector3.up * 3f;
				Transform[] array = (Transform[])(object)new Transform[2] { _ghostCam, _ghostPip };
				foreach (Transform obj in array)
				{
					obj.position = val4;
					obj.rotation = Quaternion.LookRotation(_droneT.position - val4);
				}
			}
			if (_video)
			{
				Video();
			}
		}

		private Transform SelectedCam()
		{
			int num = Mathf.Clamp(_a.GetInteger("LastTube"), 1, 4) - 1;
			bool num2 = _a.GetBool("Flying");
			int integer = _a.GetInteger("CamSel");
			if (num2 || integer == 1 || integer == 2)
			{
				Transform missile = _rigs[num].Missile;
				if (((Component)missile).gameObject.activeInHierarchy)
				{
					return missile.Find((integer == 2) ? "CamChase" : "CamNose");
				}
			}
			switch (integer)
			{
			case 3:
				if (!_a.GetBool("Manual"))
				{
					return Root.Find("Cams/TgtFixed");
				}
				return Deep("TgtManual");
			case 4:
				return Root.Find("Cams/Overhead");
			case 5:
				return _ghostCam;
			case 6:
				return _mastCam;
			default:
				return Deep("CamLauncher");
			}
		}

		private void SetVideo(bool on)
		{
			_video = on;
			if (on)
			{
				GameObject val = FindSpectator();
				if ((Object)(object)val == (Object)null)
				{
					_video = false;
					if (!_noSpectatorLogged)
					{
						_noSpectatorLogged = true;
						Log("VIDEO OUT: NO CAMERA FOUND");
						MelonLogger.Warning("[SkyGuard] VIDEO OUT: no Spectator Camera found under the rig");
					}
					return;
				}
				_videoGo = Object.Instantiate<GameObject>(val);
				((Object)_videoGo).name = "SkyGuard Video Out";
				foreach (MonoBehaviour componentsInChild in _videoGo.GetComponentsInChildren<MonoBehaviour>(true))
				{
					string name = ((MemberInfo)((Object)componentsInChild).GetIl2CppType()).Name;
					if (name == "SmoothFollower" || name == "CameraController")
					{
						((Behaviour)componentsInChild).enabled = false;
						Object.Destroy((Object)(object)componentsInChild);
					}
				}
				_videoCamera = _videoGo.GetComponentInChildren<Camera>(true);
				_videoGo.SetActive(true);
				((Component)_videoCamera).gameObject.SetActive(true);
				((Behaviour)_videoCamera).enabled = true;
				_videoCamera.depth = 100f;
				Log("VIDEO OUT ON");
				MelonLogger.Msg("[SkyGuard] VIDEO OUT on");
			}
			else
			{
				if ((Object)(object)_videoGo != (Object)null)
				{
					Object.Destroy((Object)(object)_videoGo);
				}
				_videoGo = null;
				_videoCamera = null;
				Log("VIDEO OUT OFF");
			}
			if ((Object)(object)_lamp != (Object)null)
			{
				_lamp.SetActive(_video);
			}
		}

		private static GameObject FindSpectator()
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			RigManager rigManager = Player.RigManager;
			if ((Object)(object)rigManager != (Object)null)
			{
				Transform val = ((Component)rigManager).transform;
				while ((Object)(object)val != (Object)null)
				{
					Transform val2 = val.Find("Spectator Camera");
					if ((Object)(object)val2 != (Object)null)
					{
						return ((Component)val2).gameObject;
					}
					val = val.parent;
				}
				foreach (Transform componentsInChild in ((Component)rigManager).GetComponentsInChildren<Transform>(true))
				{
					if (((Object)componentsInChild).name == "Spectator Camera")
					{
						return ((Component)componentsInChild).gameObject;
					}
				}
			}
			GameObject val3 = null;
			foreach (RigScreenOptions item in Resources.FindObjectsOfTypeAll<RigScreenOptions>())
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				Scene scene = ((Component)item).gameObject.scene;
				if (((Scene)(ref scene)).IsValid() && !(((Object)item).name == "SkyGuard Video Out"))
				{
					if (((Object)item).name == "Spectator Camera")
					{
						return ((Component)item).gameObject;
					}
					val3 = val3 ?? ((Component)item).gameObject;
				}
			}
			return val3;
		}

		private void Video()
		{
			//IL_0033: 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)
			if ((Object)(object)_videoCamera == (Object)null)
			{
				SetVideo(on: false);
				return;
			}
			Transform val = SelectedCam();
			if (!((Object)(object)val == (Object)null))
			{
				((Component)_videoCamera).transform.SetPositionAndRotation(val.position, val.rotation);
				Camera component = ((Component)val).GetComponent<Camera>();
				if ((Object)(object)component != (Object)null)
				{
					_videoCamera.fieldOfView = component.fieldOfView;
				}
			}
		}

		private void Blip(Canvas c, Vector3 world, float half, Color32 col, int r)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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)
			Vector3 val = Root.InverseTransformPoint(world);
			int x = Mathf.RoundToInt((val.x / half * 0.5f + 0.5f) * (float)c.W);
			int y = Mathf.RoundToInt((val.z / half * 0.5f + 0.5f) * (float)c.H);
			c.Box(x, y, r, col);
		}

		private List<(Vector3 p, Color32 c)> Contacts()
		{
			//IL_0022: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			List<(Vector3, Color32)> list = new List<(Vector3, Color32)>();
			foreach (World.Thing thing in World.Things)
			{
				list.Add((thing.T.position, (thing.Kind == 'D') ? Amber : ((thing.Kind == 'B') ? Red : Yellow)));
			}
			RigState[] rigs = _rigs;
			foreach (RigState rigState in rigs)
			{
				if (rigState.Flying)
				{
					list.Add((rigState.Missile.position, White));
				}
			}
			foreach (Vector3 item in FusionPlayers.Heads())
			{
				list.Add((item, Green));
			}
			return list;
		}

		private void DrawRadar()
		{
			//IL_0033: 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_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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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)
			_radar.Clear();
			if (((Component)_radarSweep).gameObject.activeInHierarchy)
			{
				foreach (var item3 in Contacts())
				{
					Vector3 item = item3.p;
					Color32 item2 = item3.c;
					Vector3 val = item - Root.position;
					if (((Vector3)(ref val)).sqrMagnitude < 16000000f)
					{
						Blip(_radar, item, 4080f, item2, 2);
					}
				}
			}
			_radar.Show();
		}

		private void DrawMap()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: 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_020b: 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_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			_map.Clear();
			Canvas map = _map;
			RigState[] rigs = _rigs;
			foreach (RigState rigState in rigs)
			{
				for (int j = 1; j < rigState.Path.Count; j++)
				{
					Seg(map, rigState.Path[j - 1], rigState.Path[j], White);
				}
				if (rigState.Flying)
				{
					Blip(map, rigState.Missile.position, 3400f, White, 2);
				}
			}
			foreach (World.Thing thing in World.Things)
			{
				if (thing.Kind != 'N')
				{
					Blip(map, thing.T.position, 3400f, (thing.Kind == 'D') ? Amber : Red, 1);
				}
			}
			_booms.RemoveAll(((Vector3 p, float t) b) => Time.time - b.t > 20f);
			foreach (var boom in _booms)
			{
				Vector3 item = boom.p;
				float item2 = boom.t;
				Vector3 val = Root.InverseTransformPoint(item);
				int x = Mathf.RoundToInt((val.x / 3400f * 0.5f + 0.5f) * (float)map.W);
				int y = Mathf.RoundToInt((val.z / 3400f * 0.5f + 0.5f) * (float)map.H);
				map.Ring(x, y, 3 + (int)((Time.time - item2) * 0.6f), Red);
			}
			if (_a.GetBool("Manual"))
			{
				Vector3 val2 = TargetPoint();
				Vector3 val3 = Root.InverseTransformPoint(val2);
				int num = Mathf.RoundToInt((val3.x / 3400f * 0.5f + 0.5f) * (float)map.W);
				int num2 = Mathf.RoundToInt((val3.z / 3400f * 0.5f + 0.5f) * (float)map.H);
				map.Line(num - 4, num2, num + 4, num2, Red);
				map.Line(num, num2 - 4, num, num2 + 4, Red);
			}
			map.Show();
		}

		private void Seg(Canvas c, Vector3 a, Vector3 b, Color32 col)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_003d: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Root.InverseTransformPoint(a);
			Vector3 val2 = Root.InverseTransformPoint(b);
			c.Line(F(val.x, c.W), F(val.z, c.H), F(val2.x, c.W), F(val2.z, c.H), col);
			static int F(float v, int size)
			{
				return Mathf.RoundToInt((v / 3400f * 0.5f + 0.5f) * (float)size);
			}
		}

		private void DrawStatus()
		{
			//IL_003a: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			Canvas status = _status;
			status.Clear();
			int x = 228;
			status.Text($"{Yaw(),4:0}", x, 44, White, 2);
			status.Text($"{Elev(),4:0}", x, 27, White, 2);
			if (_a.GetBool("Manual"))
			{
				status.Text($"EXACT {_rangeM:0} M", 170, 120, Amber);
			}
			status.Text("GROUND " + (TargetPoint().y - Root.position.y).ToString("+0;-0;0") + " M", 170, 105, Grey);
			status.Show();
		}

		private void DrawLog()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Canvas log = _log;
			log.Clear();
			int num = log.H - 22;
			foreach (string line in _lines)
			{
				log.Text((line.Length > 24) ? line.Substring(0, 24) : line, 3, num, Blue);
				num -= 12;
			}
			log.Show();
		}

		private void DrawMain()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			Canvas main = _main;
			main.Clear();
			int num = Mathf.Clamp(_a.GetInteger("LastTube"), 1, 4) - 1;
			Vector3 val = (_a.GetBool("Flying") ? _rigs[num].Missile.position : (_a.GetBool("Manual") ? TargetPoint() : _turret.position));
			if (_a.GetInteger("CamSel") == 6 && !_a.GetBool("Flying"))
			{
				float num2 = 5000f;
				val = _mastCam.position + _mastCam.forward * 5000f;
				foreach (RaycastHit item in (Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(_mastCam.position, _mastCam.forward, 5000f, -1, (QueryTriggerInteraction)1))
				{
					RaycastHit current = item;
					if (!Ignored(((RaycastHit)(ref current)).collider) && ((RaycastHit)(ref current)).distance < num2)
					{
						num2 = ((RaycastHit)(ref current)).distance;
						val = ((RaycastHit)(ref current)).point;
					}
				}
				main.Text($"ZOOM {(new int[5] { 1, 2, 5, 10, 20 })[Mathf.Clamp(_a.GetInteger("Zoom"), 0, 4)]}X", 244, 15, Amber);
			}
			Vector2 val2 = new Vector2(val.x - Root.position.x, val.z - Root.position.z);
			float magnitude = ((Vector2)(ref val2)).magnitude;
			float value = val.y - Root.position.y;
			main.Text($"RANGE {magnitude,5:0} M   ALT {value,5:0} M", 20, 15, White, 2);
			main.Show();
		}
	}
	internal static class FusionPlayers
	{
		private static bool? _loaded;

		private static readonly List<Vector3> Empty = new List<Vector3>();

		public static List<Vector3> Heads()
		{
			if (!_loaded.HasValue)
			{
				_loaded = false;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				for (int i = 0; i < assemblies.Length; i++)
				{
					if (assemblies[i].GetName().Name == "LabFusion")
					{
						_loaded = true;
					}
				}
			}
			if (_loaded != true)
			{
				return Empty;
			}
			try
			{
				return Read();
			}
			catch
			{
				_loaded = false;
				return Empty;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static List<Vector3> Read()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			foreach (NetworkPlayer player in NetworkPlayer.Players)
			{
				if (player != null && player.HasRig)
				{
					list.Add(player.RigRefs.Head.position);
				}
			}
			return list;
		}
	}
	internal static class Glyphs
	{
		public static readonly Dictionary<char, string> Rows = new Dictionary<char, string>
		{
			['A'] = "01110100011000111111100011000110001",
			['B'] = "11110100011000111110100011000111110",
			['C'] = "01110100011000010000100001000101110",
			['D'] = "11110100011000110001100011000111110",
			['E'] = "11111100001000011110100001000011111",
			['F'] = "11111100001000011110100001000010000",
			['G'] = "01111100001000010111100011000101111",
			['H'] = "10001100011000111111100011000110001",
			['I'] = "01110001000010000100001000010001110",
			['J'] = "00111000100001000010000101001001100",
			['K'] = "10001100101010011000101001001010001",
			['L'] = "10000100001000010000100001000011111",
			['M'] = "10001110111010110101100011000110001",
			['N'] = "10001110011010110011100011000110001",
			['O'] = "01110100011000110001100011000101110",
			['P'] = "11110100011000111110100001000010000",
			['Q'] = "01110100011000110001101011001001101",
			['R'] = "11110100011000111110101001001010001",
			['S'] = "01111100001000001110000010000111110",
			['T'] = "11111001000010000100001000010000100",
			['U'] = "10001100011000110001100011000101110",
			['V'] = "10001100011000110001100010101000100",
			['W'] = "10001100011000110101101011101110001",
			['X'] = "10001100010101000100010101000110001",
			['Y'] = "10001100010101000100001000010000100",
			['Z'] = "11111000010001000100010001000011111",
			['0'] = "01110100011001110101110011000101110",
			['1'] = "00100011000010000100001000010001110",
			['2'] = "01110100010000100010001000100011111",
			['3'] = "11110000010000101110000010000111110",
			['4'] = "00010001100101010010111110001000010",
			['5'] = "11111100001111000001000011000101110",
			['6'] = "00110010001000011110100011000101110",
			['7'] = "11111000010001000100010000100001000",
			['8'] = "01110100011000101110100011000101110",
			['9'] = "01110100011000101111000010001001100",
			['-'] = "00000000000000011111000000000000000",
			['.'] = "00000000000000000000000000110001100",
			[':'] = "00000011000110000000011000110000000",
			['/'] = "00001000010001000100010001000010000",
			['+'] = "00000001000010011111001000010000000",
			['%'] = "11001110010001000100010001001110011",
			['<'] = "00010001000100010000010000010000010",
			['>'] = "01000001000001000001000100010001000",
			['('] = "00010001000100001000010000010000010",
			[')'] = "01000001000001000010000100010001000",
			['['] = "01110010000100001000010000100001110",
			[']'] = "01110000100001000010000100001001110"
		};
	}
	public class SkyGuardMod : MelonMod
	{
		internal static MelonPreferences_Entry<bool> PrefSmooth;

		internal static MelonPreferences_Entry<bool> PrefLogFrames;

		private static float _errorUntil;

		private static int _errors;

		public override void OnInitializeMelon()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			MelonPreferences_Category obj = MelonPreferences.CreateCategory("SkyGuard");
			PrefSmooth = obj.CreateEntry<bool>("SmoothControls", true, "Sticks and knobs work smoothly instead of in steps", (string)null, false, false, (ValueValidator)null, (string)null);
			PrefLogFrames = obj.CreateEntry<bool>("LogFrameTime", true, "Writes frame time near the console to the log", (string)null, false, false, (ValueValidator)null, (string)null);
			Hooking.OnLevelUnloaded += World.Clear;
			Page obj2 = Page.Root.CreatePage("SkyGuard", new Color(0.35f, 0.75f, 1f), 0, true);
			obj2.CreateBool("Smooth sticks and knobs", Color.white, PrefSmooth.Value, (Action<bool>)delegate(bool v)
			{
				PrefSmooth.Value = v;
				MelonPreferences.Save();
			});
			obj2.CreateBool("Log frame time", Color.white, PrefLogFrames.Value, (Action<bool>)delegate(bool v)
			{
				PrefLogFrames.Value = v;
				MelonPreferences.Save();
			});
			((MelonBase)this).LoggerInstance.Msg("SkyGuard 2.3.1 loaded: extras for the MK2 and MK3 consoles.");
		}

		public override void OnUpdate()
		{
			Guard(World.Update);
		}

		public override void OnLateUpdate()
		{
			Guard(World.LateUpdate);
		}

		private void Guard(Action a)
		{
			if (Time.unscaledTime < _errorUntil)
			{
				return;
			}
			try
			{
				a();
			}
			catch (Exception ex)
			{
				if (_errors++ < 5)
				{
					((MelonBase)this).LoggerInstance.Warning("[SkyGuard] " + ex);
				}
				_errorUntil = Time.unscaledTime + 5f;
			}
		}
	}
	internal static class World
	{
		public sealed class Thing
		{
			public Transform T;

			public char Kind;

			public Transform Model;
		}

		public static readonly List<Thing> Things = new List<Thing>();

		public static readonly List<GameObject> Warheads = new List<GameObject>();

		private static readonly List<ConsoleDriver> Consoles = new List<ConsoleDriver>();

		private static readonly List<GameObject> Pending = new List<GameObject>();

		public static void Seen(Poolee p)
		{
			GameObject val = (((Object)(object)p != (Object)null) ? ((Component)p).gameObject : null);
			if ((Object)(object)val != (Object)null)
			{
				Pending.Add(val);
			}
		}

		public static void Clear()
		{
			Things.Clear();
			Warheads.Clear();
			Pending.Clear();
			foreach (ConsoleDriver console in Consoles)
			{
				console.Dispose();
			}
			Consoles.Clear();
		}

		private static void Handle(GameObject go)
		{
			if ((Object)(object)go == (Object)null || !go.activeInHierarchy)
			{
				return;
			}
			string name = ((Object)go).name;
			if (name.StartsWith("SkyGuard_SAMLauncherMK"))
			{
				if (!Consoles.Exists((ConsoleDriver c) => (Object)(object)c.Root == (Object)(object)go.transform))
				{
					Consoles.Add(new ConsoleDriver(go.transform));
				}
				return;
			}
			if (name.StartsWith("SkyGuard_TargetDrone") || name.StartsWith("SkyGuard_RangeDrone"))
			{
				foreach (Transform componentsInChild in go.GetComponentsInChildren<Transform>(true))
				{
					if (((Object)componentsInChild).name == "SkyGuardTargetDrone")
					{
						Things.Add(new Thing
						{
							T = componentsInChild,
							Kind = 'D',
							Model = componentsInChild.Find("Model")
						});
						break;
					}
				}
				return;
			}
			if (name.StartsWith("NukeBomber") || name.StartsWith("SpiritBomber"))
			{
				Things.Add(new Thing
				{
					T = go.transform,
					Kind = 'B'
				});
			}
			else if (name.StartsWith("SkyGuard_NukeGround_") || name.StartsWith("SkyGuard_NukeAir_") || name.StartsWith("SkyGuardAirburst"))
			{
				Warheads.Add(go);
			}
			else if ((Object)(object)go.GetComponentInChildren<AIBrain>() != (Object)null)
			{
				Things.Add(new Thing
				{
					T = go.transform,
					Kind = 'N'
				});
			}
		}

		public static void Update()
		{
			if (Pending.Count > 0)
			{
				GameObject[] array = Pending.ToArray();
				foreach (GameObject go in array)
				{
					try
					{
						Handle(go);
					}
					catch
					{
					}
				}
				Pending.Clear();
			}
			Things.RemoveAll((Thing t) => (Object)(object)t.T == (Object)null || !((Component)t.T).gameObject.activeInHierarchy || ((Object)(object)t.Model != (Object)null && !((Component)t.Model).gameObject.activeSelf));
			Warheads.RemoveAll((GameObject w) => (Object)(object)w == (Object)null);
			for (int num = Consoles.Count - 1; num >= 0; num--)
			{
				if (Consoles[num].Gone)
				{
					Consoles[num].Dispose();
					Consoles.RemoveAt(num);
				}
				else
				{
					Consoles[num].Update();
				}
			}
		}

		public static void LateUpdate()
		{
			foreach (ConsoleDriver console in Consoles)
			{
				console.LateUpdate();
			}
		}

		public static Thing NearestDrone(Vector3 p, float max)
		{
			//IL_002b: 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_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)
			Thing result = null;
			float num = max * max;
			foreach (Thing thing in Things)
			{
				if (thing.Kind == 'D')
				{
					Vector3 val = thing.T.position - p;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = thing;
					}
				}
			}
			return result;
		}
	}
	[HarmonyPatch(typeof(Poolee), "OnSpawnEvent")]
	internal static class SpawnPatch
	{
		public static void Postfix(Poolee __instance)
		{
			try
			{
				World.Seen(__instance);
			}
			catch
			{
			}
		}
	}
}