Decompiled source of LuggageXRay v1.0.0

LuggageXRay.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LuggageXRay")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LuggageXRay")]
[assembly: AssemblyTitle("LuggageXRay")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LuggageXRay
{
	internal sealed class BoxOutline
	{
		private static readonly int[,] Edges = new int[12, 2]
		{
			{ 0, 1 },
			{ 1, 3 },
			{ 3, 2 },
			{ 2, 0 },
			{ 4, 5 },
			{ 5, 7 },
			{ 7, 6 },
			{ 6, 4 },
			{ 0, 4 },
			{ 1, 5 },
			{ 2, 6 },
			{ 3, 7 }
		};

		private readonly Transform _target;

		private readonly GameObject _go;

		private readonly LineRenderer[] _lines = (LineRenderer[])(object)new LineRenderer[12];

		private readonly Vector3[] _corners = (Vector3[])(object)new Vector3[8];

		private bool _visible = true;

		public Bounds LocalBounds { get; }

		public Vector3 TopCenter { get; private set; }

		public BoxOutline(Luggage luggage, Transform parent, Material material)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			_target = ((Component)luggage).transform;
			LocalBounds = ComputeLocalBounds(luggage);
			_go = new GameObject("XRay_" + ((Object)luggage).name);
			_go.transform.SetParent(parent, false);
			for (int i = 0; i < 12; i++)
			{
				GameObject val = new GameObject("edge" + i);
				val.transform.SetParent(_go.transform, false);
				LineRenderer val2 = val.AddComponent<LineRenderer>();
				((Renderer)val2).sharedMaterial = material;
				val2.useWorldSpace = true;
				val2.positionCount = 2;
				val2.numCapVertices = 2;
				val2.alignment = (LineAlignment)0;
				((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)val2).receiveShadows = false;
				((Renderer)val2).allowOcclusionWhenDynamic = false;
				_lines[i] = val2;
			}
		}

		public void SetVisible(bool v)
		{
			if (_visible != v && Object.op_Implicit((Object)(object)_go))
			{
				_visible = v;
				_go.SetActive(v);
			}
		}

		public void Update(float padding, float width, Color color)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0111: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: 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_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: 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_00cb: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_target))
			{
				return;
			}
			Bounds localBounds = LocalBounds;
			Vector3 min = ((Bounds)(ref localBounds)).min;
			localBounds = LocalBounds;
			Vector3 max = ((Bounds)(ref localBounds)).max;
			Vector3 lossyScale = _target.lossyScale;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(padding / Mathf.Max(0.0001f, Mathf.Abs(lossyScale.x)), padding / Mathf.Max(0.0001f, Mathf.Abs(lossyScale.y)), padding / Mathf.Max(0.0001f, Mathf.Abs(lossyScale.z)));
			min -= val;
			max += val;
			Vector3 val2 = default(Vector3);
			for (int i = 0; i < 8; i++)
			{
				((Vector3)(ref val2))..ctor(((i & 1) == 0) ? min.x : max.x, ((i & 4) == 0) ? min.y : max.y, ((i & 2) == 0) ? min.z : max.z);
				_corners[i] = _target.TransformPoint(val2);
			}
			Vector3 val3 = _corners[0];
			Vector3 val4 = Vector3.zero;
			for (int j = 0; j < 8; j++)
			{
				val4 += _corners[j];
				if (_corners[j].y > val3.y)
				{
					val3 = _corners[j];
				}
			}
			val4 /= 8f;
			TopCenter = new Vector3(val4.x, val3.y + 0.15f, val4.z);
			for (int k = 0; k < 12; k++)
			{
				LineRenderer obj = _lines[k];
				obj.SetPosition(0, _corners[Edges[k, 0]]);
				obj.SetPosition(1, _corners[Edges[k, 1]]);
				float startWidth = (obj.endWidth = width);
				obj.startWidth = startWidth;
				Color startColor = (obj.endColor = color);
				obj.startColor = startColor;
			}
		}

		public void Destroy()
		{
			if (Object.op_Implicit((Object)(object)_go))
			{
				Object.Destroy((Object)(object)_go);
			}
		}

		private static Bounds ComputeLocalBounds(Luggage luggage)
		{
			//IL_001c: 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_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0113: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			Transform root = ((Component)luggage).transform;
			bool any = false;
			Bounds b = default(Bounds);
			List<Vector3> list = new List<Vector3>(8);
			Collider[] componentsInChildren = ((Component)luggage).GetComponentsInChildren<Collider>(false);
			for (int i = 0; i < 2; i++)
			{
				if (any)
				{
					break;
				}
				bool flag = i == 1;
				Collider[] array = componentsInChildren;
				foreach (Collider val in array)
				{
					if (!Object.op_Implicit((Object)(object)val) || !val.enabled || val.isTrigger != flag)
					{
						continue;
					}
					list.Clear();
					ColliderCorners(val, list);
					foreach (Vector3 item in list)
					{
						Encapsulate(item);
					}
				}
			}
			if (!any)
			{
				Renderer[] componentsInChildren2 = ((Component)luggage).GetComponentsInChildren<Renderer>(false);
				foreach (Renderer val2 in componentsInChildren2)
				{
					if (!Object.op_Implicit((Object)(object)val2) || (!(val2 is MeshRenderer) && !(val2 is SkinnedMeshRenderer)))
					{
						continue;
					}
					Bounds bounds = val2.bounds;
					AabbCorners(((Bounds)(ref bounds)).min, ((Bounds)(ref bounds)).max, Matrix4x4.identity, list);
					foreach (Vector3 item2 in list)
					{
						Encapsulate(item2);
					}
					list.Clear();
				}
			}
			if (!any)
			{
				b = new Bounds(Vector3.up * 0.4f, Vector3.one * 0.8f);
			}
			return b;
			void Encapsulate(Vector3 worldPoint)
			{
				//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_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val3 = root.InverseTransformPoint(worldPoint);
				if (!any)
				{
					b = new Bounds(val3, Vector3.zero);
					any = true;
				}
				else
				{
					((Bounds)(ref b)).Encapsulate(val3);
				}
			}
		}

		private static void ColliderCorners(Collider col, List<Vector3> pts)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 localToWorldMatrix = ((Component)col).transform.localToWorldMatrix;
			BoxCollider val = (BoxCollider)(object)((col is BoxCollider) ? col : null);
			if (val == null)
			{
				SphereCollider val2 = (SphereCollider)(object)((col is SphereCollider) ? col : null);
				if (val2 == null)
				{
					CapsuleCollider val3 = (CapsuleCollider)(object)((col is CapsuleCollider) ? col : null);
					if (val3 == null)
					{
						MeshCollider val4 = (MeshCollider)(object)((col is MeshCollider) ? col : null);
						if (val4 != null && (Object)(object)val4.sharedMesh != (Object)null)
						{
							Bounds bounds = val4.sharedMesh.bounds;
							AabbCorners(((Bounds)(ref bounds)).min, ((Bounds)(ref bounds)).max, localToWorldMatrix, pts);
						}
						else
						{
							Bounds bounds2 = col.bounds;
							AabbCorners(((Bounds)(ref bounds2)).min, ((Bounds)(ref bounds2)).max, Matrix4x4.identity, pts);
						}
					}
					else
					{
						Vector3 val5 = Vector3.one * val3.radius;
						((Vector3)(ref val5))[Mathf.Clamp(val3.direction, 0, 2)] = Mathf.Max(val3.radius, val3.height * 0.5f);
						AabbCorners(val3.center - val5, val3.center + val5, localToWorldMatrix, pts);
					}
				}
				else
				{
					Vector3 val6 = Vector3.one * val2.radius;
					AabbCorners(val2.center - val6, val2.center + val6, localToWorldMatrix, pts);
				}
			}
			else
			{
				AabbCorners(val.center - val.size * 0.5f, val.center + val.size * 0.5f, localToWorldMatrix, pts);
			}
		}

		private static void AabbCorners(Vector3 min, Vector3 max, Matrix4x4 m, List<Vector3> pts)
		{
			//IL_0013: 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_0026: 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_0039: 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_0047: 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)
			Vector3 val = default(Vector3);
			for (int i = 0; i < 8; i++)
			{
				((Vector3)(ref val))..ctor(((i & 1) == 0) ? min.x : max.x, ((i & 2) == 0) ? min.y : max.y, ((i & 4) == 0) ? min.z : max.z);
				pts.Add(((Matrix4x4)(ref m)).MultiplyPoint3x4(val));
			}
		}
	}
	public enum ActivationMode
	{
		Toggle,
		Hold
	}
	[BepInPlugin("xtyob.luggagexray", "LuggageXRay", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class TypeSettings
		{
			public ConfigEntry<Color> color;

			public ConfigEntry<bool> show;
		}

		private struct LabelInfo
		{
			public Vector3 world;

			public string text;

			public Color color;
		}

		public const string Guid = "xtyob.luggagexray";

		public const string Name = "LuggageXRay";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		private static readonly (string type, string hex)[] KnownTypes = new(string, string)[6]
		{
			("Luggage", "FFD24AFF"),
			("Big Luggage", "FF8C1AFF"),
			("Explorer's Luggage", "3CFF5AFF"),
			("Clown Luggage", "FF4FD8FF"),
			("Ancient Luggage", "A64DFFFF"),
			("Ancient Statue", "3CE6FFFF")
		};

		private ConfigEntry<Key> _key;

		private ConfigEntry<ActivationMode> _mode;

		private ConfigEntry<bool> _startEnabled;

		private ConfigEntry<float> _maxDistance;

		private ConfigEntry<float> _lineWidth;

		private ConfigEntry<bool> _scaleWidth;

		private ConfigEntry<float> _padding;

		private ConfigEntry<bool> _showLabels;

		private ConfigEntry<bool> _showDistance;

		private ConfigEntry<int> _labelSize;

		private ConfigEntry<Color> _defaultColor;

		private readonly Dictionary<string, TypeSettings> _types = new Dictionary<string, TypeSettings>();

		private readonly Dictionary<Luggage, BoxOutline> _outlines = new Dictionary<Luggage, BoxOutline>();

		private readonly List<Luggage> _scratch = new List<Luggage>();

		private readonly List<LabelInfo> _labels = new List<LabelInfo>();

		private bool _toggled;

		private bool _active;

		private GameObject _root;

		private Material _material;

		private GUIStyle _labelStyle;

		private Material Mat
		{
			get
			{
				//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_005d: Expected O, but got Unknown
				if (Object.op_Implicit((Object)(object)_material))
				{
					return _material;
				}
				Shader val = Shader.Find("Hidden/Internal-Colored") ?? Shader.Find("Sprites/Default") ?? Shader.Find("Universal Render Pipeline/Unlit") ?? Shader.Find("Unlit/Color");
				_material = new Material(val)
				{
					hideFlags = (HideFlags)61
				};
				if (_material.HasProperty("_ZTest"))
				{
					_material.SetInt("_ZTest", 8);
				}
				if (_material.HasProperty("_ZWrite"))
				{
					_material.SetInt("_ZWrite", 0);
				}
				if (_material.HasProperty("_Cull"))
				{
					_material.SetInt("_Cull", 0);
				}
				if (_material.HasProperty("_SrcBlend"))
				{
					_material.SetInt("_SrcBlend", 5);
				}
				if (_material.HasProperty("_DstBlend"))
				{
					_material.SetInt("_DstBlend", 10);
				}
				_material.renderQueue = 4000;
				return _material;
			}
		}

		private Transform Root
		{
			get
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Expected O, but got Unknown
				if (!Object.op_Implicit((Object)(object)_root))
				{
					_root = new GameObject("LuggageXRay");
					Object.DontDestroyOnLoad((Object)(object)_root);
				}
				return _root.transform;
			}
		}

		private void Awake()
		{
			//IL_0188: 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_021f: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			_key = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "Key", (Key)26, "Key that activates the luggage x-ray. Uses Unity Input System key names (e.g. L, F3, Backquote, Numpad0).");
			_mode = ((BaseUnityPlugin)this).Config.Bind<ActivationMode>("Controls", "ActivationMode", ActivationMode.Toggle, "Toggle = press once to turn on, again to turn off. Hold = only visible while the key is held.");
			_startEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "StartEnabled", false, "Toggle mode only: whether the x-ray is on when the game starts.");
			_maxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "MaxDistance", 400f, "Only highlight luggage within this many metres of the camera (0 = no limit).");
			_lineWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "LineWidth", 0.04f, "Outline thickness in metres (at 10 m distance when ScaleWithDistance is on).");
			_scaleWidth = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ScaleWithDistance", true, "Thicken lines with distance so far-away boxes stay visible.");
			_padding = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "BoxPadding", 0.05f, "Extra metres added around the hitbox on every side.");
			_showLabels = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowLabels", true, "Draw the luggage name above each box.");
			_showDistance = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowDistance", true, "Append the distance in metres to labels.");
			_labelSize = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "LabelFontSize", 13, "Label font size.");
			_defaultColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Colors", "Default", new Color(1f, 1f, 1f, 1f), "Colour for luggage types not listed here. New types found in-game are added to this file automatically. Format: RRGGBBAA hex.");
			(string, string)[] knownTypes = KnownTypes;
			Color value = default(Color);
			for (int i = 0; i < knownTypes.Length; i++)
			{
				var (type, text) = knownTypes[i];
				ColorUtility.TryParseHtmlString("#" + text, ref value);
				GetSettings(type, value);
			}
			_toggled = _startEnabled.Value;
			Log.LogInfo((object)string.Format("{0} {1} loaded. Press {2} to x-ray luggage ({3}).", "LuggageXRay", "1.0.0", _key.Value, _mode.Value));
		}

		private static string SafeKey(string s)
		{
			StringBuilder stringBuilder = new StringBuilder(s.Length);
			foreach (char value in s)
			{
				if ("=\n\t\\\"'[]".IndexOf(value) < 0)
				{
					stringBuilder.Append(value);
				}
			}
			string text = stringBuilder.ToString().Trim();
			if (text.Length != 0)
			{
				return text;
			}
			return "Unnamed";
		}

		private TypeSettings GetSettings(string type, Color? fallback = null)
		{
			//IL_0054: 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)
			if (string.IsNullOrEmpty(type))
			{
				type = "Luggage";
			}
			if (_types.TryGetValue(type, out var value))
			{
				return value;
			}
			string text = SafeKey(type);
			value = new TypeSettings
			{
				color = ((BaseUnityPlugin)this).Config.Bind<Color>("Colors", text, (Color)(((??)fallback) ?? _defaultColor.Value), "Outline colour for \"" + type + "\" (RRGGBBAA hex)."),
				show = ((BaseUnityPlugin)this).Config.Bind<bool>("Filter", "Show " + text, true, "Highlight \"" + type + "\".")
			};
			_types[type] = value;
			return value;
		}

		private static Camera CurrentCamera()
		{
			if (Object.op_Implicit((Object)(object)MainCamera.instance))
			{
				Camera component = ((Component)MainCamera.instance).GetComponent<Camera>();
				if (Object.op_Implicit((Object)(object)component))
				{
					return component;
				}
			}
			return Camera.main;
		}

		private void Update()
		{
			//IL_0011: 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)
			Keyboard current = Keyboard.current;
			bool flag = false;
			if (current != null && (int)_key.Value != 0)
			{
				try
				{
					KeyControl obj = current[_key.Value];
					flag = ((ButtonControl)obj).isPressed;
					if (((ButtonControl)obj).wasPressedThisFrame && _mode.Value == ActivationMode.Toggle)
					{
						_toggled = !_toggled;
					}
				}
				catch (ArgumentException)
				{
				}
			}
			_active = ((_mode.Value == ActivationMode.Hold) ? flag : _toggled);
			_labels.Clear();
			if (!_active)
			{
				if (Object.op_Implicit((Object)(object)_root) && _root.activeSelf)
				{
					_root.SetActive(false);
				}
			}
			else
			{
				((Component)Root).gameObject.SetActive(true);
				Refresh();
			}
		}

		private void Refresh()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: 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_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			Camera val = CurrentCamera();
			Vector3 val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).transform.position : Vector3.zero);
			float value = _maxDistance.Value;
			float num = Mathf.Max(0.001f, _lineWidth.Value);
			_scratch.Clear();
			foreach (KeyValuePair<Luggage, BoxOutline> outline in _outlines)
			{
				if (!Object.op_Implicit((Object)(object)outline.Key) || outline.Key.IsOpen || !Luggage.ALL_LUGGAGE.Contains(outline.Key))
				{
					_scratch.Add(outline.Key);
				}
			}
			foreach (Luggage item in _scratch)
			{
				_outlines[item]?.Destroy();
				_outlines.Remove(item);
			}
			foreach (Luggage item2 in Luggage.ALL_LUGGAGE)
			{
				if (!Object.op_Implicit((Object)(object)item2) || item2.IsOpen)
				{
					continue;
				}
				if (!_outlines.TryGetValue(item2, out var value2))
				{
					value2 = new BoxOutline(item2, Root, Mat);
					_outlines[item2] = value2;
				}
				TypeSettings settings = GetSettings(item2.displayName);
				bool flag = settings.show.Value && ((Component)item2).gameObject.activeInHierarchy;
				Transform transform = ((Component)item2).transform;
				Bounds localBounds = value2.LocalBounds;
				Vector3 val3 = transform.TransformPoint(((Bounds)(ref localBounds)).center);
				float num2 = Vector3.Distance(val2, val3);
				if (flag && Object.op_Implicit((Object)(object)val) && value > 0f && num2 > value)
				{
					flag = false;
				}
				if (!flag)
				{
					value2.SetVisible(v: false);
					continue;
				}
				float width = (_scaleWidth.Value ? (num * Mathf.Max(1f, num2 / 10f)) : num);
				Color value3 = settings.color.Value;
				value2.Update(_padding.Value, width, value3);
				value2.SetVisible(v: true);
				if (_showLabels.Value)
				{
					string text = (string.IsNullOrEmpty(item2.displayName) ? "Luggage" : item2.displayName);
					_labels.Add(new LabelInfo
					{
						world = value2.TopCenter,
						text = (_showDistance.Value ? $"{text} [{num2:0}m]" : text),
						color = value3
					});
				}
			}
		}

		private void OnGUI()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: 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_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_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			if (!_active || !_showLabels.Value || _labels.Count == 0 || (int)Event.current.type != 7)
			{
				return;
			}
			Camera val = CurrentCamera();
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			if (_labelStyle == null)
			{
				_labelStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)7,
					fontStyle = (FontStyle)1,
					wordWrap = false,
					clipping = (TextClipping)0
				};
			}
			_labelStyle.fontSize = Mathf.Clamp(_labelSize.Value, 6, 64);
			Rect val3 = default(Rect);
			foreach (LabelInfo label in _labels)
			{
				Vector3 val2 = val.WorldToScreenPoint(label.world);
				if (!(val2.z <= 0f))
				{
					float num = val2.x * (float)Screen.width / (float)Mathf.Max(1, val.pixelWidth);
					float num2 = (float)Screen.height - val2.y * (float)Screen.height / (float)Mathf.Max(1, val.pixelHeight);
					((Rect)(ref val3))..ctor(num - 150f, num2 - 40f, 300f, 36f);
					_labelStyle.normal.textColor = new Color(0f, 0f, 0f, 0.85f * label.color.a);
					GUI.Label(new Rect(((Rect)(ref val3)).x + 1f, ((Rect)(ref val3)).y + 1f, ((Rect)(ref val3)).width, ((Rect)(ref val3)).height), label.text, _labelStyle);
					_labelStyle.normal.textColor = new Color(label.color.r, label.color.g, label.color.b, Mathf.Max(0.4f, label.color.a));
					GUI.Label(val3, label.text, _labelStyle);
				}
			}
		}

		private void OnDestroy()
		{
			foreach (BoxOutline value in _outlines.Values)
			{
				value?.Destroy();
			}
			_outlines.Clear();
			if (Object.op_Implicit((Object)(object)_root))
			{
				Object.Destroy((Object)(object)_root);
			}
			if (Object.op_Implicit((Object)(object)_material))
			{
				Object.Destroy((Object)(object)_material);
			}
		}
	}
}