Decompiled source of HatterMiscellaneousPack v1.0.0

HatterMiscellaneousPack.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using REPOLib.Modules;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("HatterMiscellaneousPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HatterMiscellaneousPack")]
[assembly: AssemblyTitle("HatterMiscellaneousPack")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HatterMiscellaneousPack;

internal static class BuildHelpers
{
	private static Material neutral;

	private static bool neutralTried;

	internal static Bounds LocalMeshBounds(Transform root)
	{
		//IL_0004: 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_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00c0: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		Bounds result = default(Bounds);
		Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix;
		MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true);
		foreach (MeshFilter val in componentsInChildren)
		{
			if ((Object)(object)val.sharedMesh == (Object)null)
			{
				continue;
			}
			MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
			if ((Object)(object)component == (Object)null || !((Renderer)component).enabled)
			{
				continue;
			}
			Matrix4x4 val2 = worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
			Bounds bounds = val.sharedMesh.bounds;
			for (int j = 0; j < 8; j++)
			{
				Vector3 val3 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
				Vector3 val4 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(val3);
				if (!flag)
				{
					((Bounds)(ref result))..ctor(val4, Vector3.zero);
					flag = true;
				}
				else
				{
					((Bounds)(ref result)).Encapsulate(val4);
				}
			}
		}
		return result;
	}

	internal static void LogComponents(GameObject go, string label, string source)
	{
		StringBuilder stringBuilder = new StringBuilder(label + ": " + source + "'s parts:");
		Transform[] componentsInChildren = go.GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			List<string> list = new List<string>();
			Component[] components = ((Component)val).GetComponents<Component>();
			foreach (Component val2 in components)
			{
				if ((Object)(object)val2 != (Object)null && !(val2 is Transform))
				{
					list.Add(((object)val2).GetType().Name);
				}
			}
			stringBuilder.Append("\n  " + ((Object)val).name + ": " + string.Join(", ", list));
		}
		Plugin.Log.LogInfo((object)stringBuilder.ToString());
	}

	internal static void ReplaceColliders(Transform root, (Vector3 centre, Quaternion rotation, Vector3 size)[] boxes, string label, string source)
	{
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: 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_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		List<Collider> list = new List<Collider>();
		Collider[] componentsInChildren = ((Component)root).GetComponentsInChildren<Collider>(true);
		foreach (Collider val in componentsInChildren)
		{
			if (!val.isTrigger)
			{
				list.Add(val);
			}
		}
		Collider val2 = null;
		foreach (Collider item in list)
		{
			if ((Object)(object)((Component)item).GetComponent<PhysGrabObjectCollider>() != (Object)null && ((Component)item).CompareTag("Phys Grab Object"))
			{
				val2 = item;
				break;
			}
		}
		if ((Object)(object)val2 == (Object)null && list.Count > 0)
		{
			val2 = list[0];
		}
		string text = (((Object)(object)val2 != (Object)null) ? ((Component)val2).tag : "Phys Grab Object");
		int num = (((Object)(object)val2 != (Object)null) ? ((Component)val2).gameObject.layer : ((Component)root).gameObject.layer);
		PhysicsMaterial sharedMaterial = (((Object)(object)val2 != (Object)null) ? val2.sharedMaterial : null);
		StringBuilder stringBuilder = new StringBuilder(label + ": " + source + "'s colliders (removed):");
		foreach (Collider item2 in list)
		{
			stringBuilder.Append("\n  '" + ((Object)item2).name + "' " + ((object)item2).GetType().Name + ", tag " + ((Component)item2).tag + ", layer " + LayerMask.LayerToName(((Component)item2).gameObject.layer));
		}
		Plugin.Log.LogInfo((object)stringBuilder.ToString());
		foreach (Collider item3 in list)
		{
			GameObject gameObject = ((Component)item3).gameObject;
			PhysGrabObjectBoxCollider[] components = gameObject.GetComponents<PhysGrabObjectBoxCollider>();
			for (int i = 0; i < components.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)components[i]);
			}
			PhysGrabObjectCapsuleCollider[] components2 = gameObject.GetComponents<PhysGrabObjectCapsuleCollider>();
			for (int i = 0; i < components2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)components2[i]);
			}
			PhysGrabObjectSphereCollider[] components3 = gameObject.GetComponents<PhysGrabObjectSphereCollider>();
			for (int i = 0; i < components3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)components3[i]);
			}
			PhysGrabObjectMeshCollider[] components4 = gameObject.GetComponents<PhysGrabObjectMeshCollider>();
			for (int i = 0; i < components4.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)components4[i]);
			}
		}
		foreach (Collider item4 in list)
		{
			Object.DestroyImmediate((Object)(object)item4);
		}
		for (int j = 0; j < boxes.Length; j++)
		{
			GameObject val3 = new GameObject($"{label} Collider {j + 1}")
			{
				tag = text,
				layer = num
			};
			Transform transform = val3.transform;
			transform.SetParent(root, false);
			transform.localPosition = boxes[j].centre;
			transform.localRotation = boxes[j].rotation;
			BoxCollider obj = val3.AddComponent<BoxCollider>();
			obj.size = boxes[j].size;
			((Collider)obj).sharedMaterial = sharedMaterial;
			val3.AddComponent<PhysGrabObjectCollider>();
		}
		Plugin.Log.LogInfo((object)$"{label}: {boxes.Length} colliders, tag {text}, layer {LayerMask.LayerToName(num)}.");
	}

	internal static Sound MakeSound(Sound template, AudioClip clip, float volume)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		if ((Object)(object)clip == (Object)null)
		{
			return null;
		}
		Sound val = new Sound();
		if (template != null)
		{
			Sound.CopySound(template, val);
		}
		val.Sounds = (AudioClip[])(object)new AudioClip[1] { clip };
		val.Volume = volume;
		return val;
	}

	internal static Material NeutralTemplate(Material fallback)
	{
		if (!neutralTried)
		{
			neutralTried = true;
			GameObject val = Resources.Load<GameObject>("Items/Item Gun Shotgun");
			Transform val2 = (((Object)(object)val != (Object)null) ? val.transform.Find("Mesh") : null);
			Renderer val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponentInChildren<Renderer>(true) : null);
			neutral = (((Object)(object)val3 != (Object)null) ? val3.sharedMaterial : null);
			ManualLogSource log = Plugin.Log;
			object obj;
			if (!((Object)(object)neutral != (Object)null))
			{
				obj = "the shotgun's wasn't found, using each item's own";
			}
			else
			{
				string[] obj2 = new string[5]
				{
					"'",
					((Object)neutral).name,
					"' (",
					null,
					null
				};
				Shader shader = neutral.shader;
				obj2[3] = ((shader != null) ? ((Object)shader).name : null);
				obj2[4] = ")";
				obj = string.Concat(obj2);
			}
			log.LogInfo((object)("Material template: " + (string?)obj + "."));
		}
		if (!((Object)(object)neutral != (Object)null))
		{
			return fallback;
		}
		return neutral;
	}

	internal static Bounds ColliderBounds(Transform root, out int count)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0074: 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_008a: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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_014f: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: 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_0181: 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_0190: 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_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		count = 0;
		Bounds result = default(Bounds);
		((Bounds)(ref result))..ctor(Vector3.zero, Vector3.one * 0.1f);
		Collider[] componentsInChildren = ((Component)root).GetComponentsInChildren<Collider>(true);
		foreach (Collider val in componentsInChildren)
		{
			if (val.isTrigger)
			{
				continue;
			}
			BoxCollider val2 = (BoxCollider)(object)((val is BoxCollider) ? val : null);
			Vector3 center;
			Vector3 val3;
			if (val2 != null)
			{
				center = val2.center;
				val3 = val2.size;
			}
			else
			{
				SphereCollider val4 = (SphereCollider)(object)((val is SphereCollider) ? val : null);
				if (val4 != null)
				{
					center = val4.center;
					val3 = Vector3.one * val4.radius * 2f;
				}
				else
				{
					CapsuleCollider val5 = (CapsuleCollider)(object)((val is CapsuleCollider) ? val : null);
					if (val5 != null)
					{
						center = val5.center;
						val3 = Vector3.one * val5.radius * 2f;
						((Vector3)(ref val3))[val5.direction] = Mathf.Max(val5.height, val5.radius * 2f);
					}
					else
					{
						MeshCollider val6 = (MeshCollider)(object)((val is MeshCollider) ? val : null);
						if (val6 == null || !((Object)(object)val6.sharedMesh != (Object)null))
						{
							continue;
						}
						Bounds bounds = val6.sharedMesh.bounds;
						center = ((Bounds)(ref bounds)).center;
						bounds = val6.sharedMesh.bounds;
						val3 = ((Bounds)(ref bounds)).size;
					}
				}
			}
			Transform transform = ((Component)val).transform;
			for (int j = 0; j < 8; j++)
			{
				Vector3 val7 = center + Vector3.Scale(val3 * 0.5f, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
				Vector3 val8 = root.InverseTransformPoint(transform.TransformPoint(val7));
				if (count == 0 && j == 0)
				{
					((Bounds)(ref result))..ctor(val8, Vector3.zero);
				}
				else
				{
					((Bounds)(ref result)).Encapsulate(val8);
				}
			}
			count++;
		}
		return result;
	}

	internal static int MuteToggleListeners(ItemToggle toggle)
	{
		if ((Object)(object)toggle == (Object)null || toggle.onToggle == null)
		{
			return 0;
		}
		int persistentEventCount = ((UnityEventBase)toggle.onToggle).GetPersistentEventCount();
		for (int i = 0; i < persistentEventCount; i++)
		{
			((UnityEventBase)toggle.onToggle).SetPersistentListenerState(i, (UnityEventCallState)0);
		}
		return persistentEventCount;
	}
}
internal class CompassArrow3D : MonoBehaviour
{
	private const int TextureSize = 160;

	private const float ViewPitch = 35f;

	private static int layer = -2;

	private static int count;

	private static float nextMaskFix;

	private static readonly List<Camera> ours = new List<Camera>();

	private static Material material;

	private static readonly Vector3 LightDir;

	internal RenderTexture texture;

	private Camera cam;

	private Transform arrow;

	private Mesh mesh;

	private Vector3[] normals;

	private Color[] colors;

	internal static CompassArrow3D Create()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_003e: 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_00a7: Expected O, but got Unknown
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Expected O, but got Unknown
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Expected O, but got Unknown
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0095: Expected O, but got Unknown
		int num = ArrowLayer();
		GameObject val = new GameObject("HatterMiscellaneousPack Compass Arrow Rig");
		val.transform.position = new Vector3(0f, -5000f - 25f * (float)(count++ % 40), 0f);
		CompassArrow3D compassArrow3D = val.AddComponent<CompassArrow3D>();
		if ((Object)(object)material == (Object)null)
		{
			Shader val2 = Shader.Find("Sprites/Default");
			material = new Material(((Object)(object)val2 != (Object)null) ? val2 : Shader.Find("Unlit/Color"))
			{
				name = "HMP Compass Arrow"
			};
		}
		GameObject val3 = new GameObject("Arrow")
		{
			layer = num
		};
		val3.transform.SetParent(val.transform, false);
		compassArrow3D.mesh = ArrowMesh();
		compassArrow3D.normals = compassArrow3D.mesh.normals;
		compassArrow3D.colors = (Color[])(object)new Color[compassArrow3D.normals.Length];
		val3.AddComponent<MeshFilter>().sharedMesh = compassArrow3D.mesh;
		MeshRenderer obj = val3.AddComponent<MeshRenderer>();
		((Renderer)obj).sharedMaterial = material;
		((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)obj).receiveShadows = false;
		compassArrow3D.arrow = val3.transform;
		GameObject val4 = new GameObject("Arrow Camera");
		val4.transform.SetParent(val.transform, false);
		val4.transform.localRotation = Quaternion.Euler(35f, 0f, 0f);
		val4.transform.localPosition = val4.transform.localRotation * new Vector3(0f, 0f, -3f);
		compassArrow3D.cam = val4.AddComponent<Camera>();
		compassArrow3D.cam.orthographic = true;
		compassArrow3D.cam.orthographicSize = 0.62f;
		compassArrow3D.cam.nearClipPlane = 0.5f;
		compassArrow3D.cam.farClipPlane = 6f;
		compassArrow3D.cam.clearFlags = (CameraClearFlags)2;
		compassArrow3D.cam.backgroundColor = new Color(0f, 0f, 0f, 0f);
		compassArrow3D.cam.cullingMask = 1 << num;
		compassArrow3D.cam.depth = -100f;
		compassArrow3D.cam.allowHDR = false;
		compassArrow3D.cam.allowMSAA = true;
		compassArrow3D.cam.useOcclusionCulling = false;
		compassArrow3D.texture = new RenderTexture(160, 160, 16, (RenderTextureFormat)0)
		{
			name = "HMP Compass Arrow",
			antiAliasing = 4
		};
		compassArrow3D.texture.Create();
		compassArrow3D.cam.targetTexture = compassArrow3D.texture;
		ours.Add(compassArrow3D.cam);
		compassArrow3D.Point(Vector3.forward, Color.white);
		return compassArrow3D;
	}

	internal void Point(Vector3 dirInView, Color colour)
	{
		//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_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: 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)
		if (((Vector3)(ref dirInView)).sqrMagnitude < 1E-06f)
		{
			dirInView = Vector3.forward;
		}
		Vector3 val = ((Mathf.Abs(Vector3.Dot(((Vector3)(ref dirInView)).normalized, Vector3.up)) > 0.98f) ? Vector3.forward : Vector3.up);
		arrow.localRotation = Quaternion.LookRotation(dirInView, val);
		for (int i = 0; i < normals.Length; i++)
		{
			float num = 0.38f + 0.62f * Mathf.Max(0f, Vector3.Dot(arrow.localRotation * normals[i], LightDir));
			colors[i] = new Color(colour.r * num, colour.g * num, colour.b * num, 1f);
		}
		mesh.colors = colors;
	}

	private void LateUpdate()
	{
		if (Time.unscaledTime < nextMaskFix)
		{
			return;
		}
		nextMaskFix = Time.unscaledTime + 0.5f;
		ours.RemoveAll((Camera x) => (Object)(object)x == (Object)null);
		int num = 1 << ArrowLayer();
		Camera[] allCameras = Camera.allCameras;
		foreach (Camera val in allCameras)
		{
			if ((Object)(object)val != (Object)null && !ours.Contains(val) && (val.cullingMask & num) != 0)
			{
				val.cullingMask &= ~num;
			}
		}
	}

	private void OnDestroy()
	{
		ours.Remove(cam);
		if ((Object)(object)cam != (Object)null)
		{
			cam.targetTexture = null;
		}
		if ((Object)(object)texture != (Object)null)
		{
			texture.Release();
			Object.Destroy((Object)(object)texture);
		}
		if ((Object)(object)mesh != (Object)null)
		{
			Object.Destroy((Object)(object)mesh);
		}
	}

	private static int ArrowLayer()
	{
		if (layer >= 0)
		{
			return layer;
		}
		layer = 31;
		for (int num = 31; num >= 8; num--)
		{
			if (string.IsNullOrEmpty(LayerMask.LayerToName(num)))
			{
				layer = num;
				break;
			}
		}
		Plugin.Log.LogInfo((object)$"Pocket compass: the 3D arrows use layer {layer}.");
		return layer;
	}

	private static Mesh ArrowMesh()
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_0095: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: 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_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: 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_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: 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_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Expected O, but got Unknown
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(0f, 0f, 0.55f);
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(0.46f, 0f, -0.42f);
		Vector3 val3 = default(Vector3);
		((Vector3)(ref val3))..ctor(0f, 0f, -0.16f);
		Vector3 val4 = default(Vector3);
		((Vector3)(ref val4))..ctor(-0.46f, 0f, -0.42f);
		Vector3 val5 = Vector3.up * 0.13f;
		List<Vector3> v = new List<Vector3>();
		List<Vector3> n = new List<Vector3>();
		List<int> tris = new List<int>();
		Tri(val + val5 * 0.35f, val2, val3 + val5, Vector3.up);
		Tri(val + val5 * 0.35f, val3 + val5, val4, Vector3.up);
		Tri(val - val5 * 0.35f, val2, val3 - val5, Vector3.down);
		Tri(val - val5 * 0.35f, val3 - val5, val4, Vector3.down);
		Tri(val + val5 * 0.35f, val - val5 * 0.35f, val2, new Vector3(1f, 0f, 1f));
		Tri(val + val5 * 0.35f, val4, val - val5 * 0.35f, new Vector3(-1f, 0f, 1f));
		Tri(val2, val3 - val5, val3 + val5, new Vector3(0.3f, 0f, -1f));
		Tri(val4, val3 + val5, val3 - val5, new Vector3(-0.3f, 0f, -1f));
		Mesh val6 = new Mesh
		{
			name = "HMP Compass Arrow"
		};
		val6.SetVertices(v);
		val6.SetNormals(n);
		val6.SetTriangles(tris, 0);
		val6.RecalculateBounds();
		return val6;
		void Tri(Vector3 a, Vector3 b, Vector3 c, Vector3 outward)
		{
			//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_0002: 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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_007f: 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_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)
			//IL_002c: 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_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)
			Vector3 val7 = Vector3.Cross(b - a, c - a);
			Vector3 val8 = ((Vector3)(ref val7)).normalized;
			if (Vector3.Dot(val8, outward) < 0f)
			{
				Vector3 val9 = b;
				b = c;
				c = val9;
				val8 = -val8;
			}
			int num = v.Count;
			v.Add(a);
			v.Add(b);
			v.Add(c);
			n.Add(val8);
			n.Add(val8);
			n.Add(val8);
			tris.Add(num);
			tris.Add(num + 1);
			tris.Add(num + 2);
		}
	}

	static CompassArrow3D()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		Vector3 val = new Vector3(-0.45f, 0.8f, -0.4f);
		LightDir = ((Vector3)(ref val)).normalized;
	}
}
internal class CompassArrows : MonoBehaviour
{
	private class Entry
	{
		public CompassTargets.Kind kind;

		public float until;

		public float noTargetFor;

		public float nextSearch;

		public bool hasTarget;

		public bool aimed;

		public Vector3 dir = Vector3.forward;

		public CompassArrow3D rig;

		public Vector3 target;

		public RectTransform rect;

		public RawImage image;

		public TextMeshProUGUI timer;

		public CanvasGroup group;

		public float started;

		public float length;
	}

	private static CompassArrows instance;

	private static readonly FieldInfo DisabledField = AccessTools.Field(typeof(PlayerAvatar), "isDisabled");

	private static readonly FieldInfo HaulTextField = AccessTools.Field(typeof(HaulUI), "Text");

	private static readonly FieldInfo GoalTextField = AccessTools.Field(typeof(GoalUI), "Text");

	private static readonly Color EnemyColour = new Color(0.95f, 0.18f, 0.12f);

	private static readonly Color ExtractionColour = new Color(0.45f, 0.82f, 0.28f);

	private readonly List<Entry> entries = new List<Entry>();

	private Transform parent;

	private Vector3 anchor;

	private float unit = 40f;

	private bool anchored;

	private Canvas fallbackCanvas;

	private string lastAnchorLog;

	internal static void Begin(CompassTargets.Kind kind)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)instance == (Object)null)
		{
			instance = new GameObject("HatterMiscellaneousPack Compass Arrows").AddComponent<CompassArrows>();
		}
		Entry entry = instance.entries.Find((Entry x) => x.kind == kind);
		if (entry == null)
		{
			entry = new Entry
			{
				kind = kind
			};
			instance.entries.Add(entry);
			instance.entries.Sort((Entry a, Entry b) => b.kind.CompareTo(a.kind));
		}
		entry.started = Time.time;
		entry.length = Settings.CompassEffectSeconds.Value;
		entry.until = entry.started + entry.length;
		entry.noTargetFor = 0f;
		entry.nextSearch = 0f;
		if (Settings.CompassDebugLog.Value)
		{
			Plugin.Log.LogInfo((object)$"Pocket compass: {CompassTargets.Describe(kind)} arrow on for {Settings.CompassEffectSeconds.Value:0} s.");
		}
	}

	private void Update()
	{
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_030f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0320: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: 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_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0354: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0370: Unknown result type (might be due to invalid IL or missing references)
		//IL_0375: Unknown result type (might be due to invalid IL or missing references)
		//IL_0395: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04df: Unknown result type (might be due to invalid IL or missing references)
		//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0503: Unknown result type (might be due to invalid IL or missing references)
		if (!SemiFunc.RunIsLevel())
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		Transform val = ViewTransform();
		PlayerAvatar val2 = PlayerAvatar.instance;
		bool flag = (Object)(object)val2 == (Object)null || (DisabledField != null && (bool)DisabledField.GetValue(val2));
		FindAnchor();
		for (int num = entries.Count - 1; num >= 0; num--)
		{
			Entry entry = entries[num];
			string text = null;
			if (Time.time >= entry.until)
			{
				text = "time's up";
			}
			else if ((Object)(object)val != (Object)null)
			{
				if (Time.time >= entry.nextSearch)
				{
					entry.nextSearch = Time.time + 0.2f;
					entry.hasTarget = CompassTargets.Find(entry.kind, val.position, out entry.target);
				}
				if (entry.hasTarget)
				{
					entry.noTargetFor = 0f;
				}
				else if ((entry.noTargetFor += Time.deltaTime) >= Settings.CompassNoTargetGrace.Value)
				{
					text = "no " + CompassTargets.Describe(entry.kind) + " left";
				}
			}
			if (text != null)
			{
				if (Settings.CompassDebugLog.Value)
				{
					Plugin.Log.LogInfo((object)("Pocket compass: the " + CompassTargets.Describe(entry.kind) + " arrow ended (" + text + ")."));
				}
				if ((Object)(object)entry.rect != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)entry.rect).gameObject);
				}
				if ((Object)(object)entry.rig != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)entry.rig).gameObject);
				}
				entries.RemoveAt(num);
			}
		}
		if (entries.Count == 0)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		for (int i = 0; i < entries.Count; i++)
		{
			Entry entry2 = entries[i];
			if (!EnsureUI(entry2))
			{
				continue;
			}
			float num2 = unit * Settings.ArrowSizeVsText.Value;
			entry2.rect.sizeDelta = new Vector2(num2, num2);
			float num3 = unit * Settings.TimerSizeVsText.Value * 1.2f;
			float num4 = num2 + num3 + unit * 0.15f;
			((Transform)entry2.rect).localPosition = anchor + new Vector3(Settings.ArrowOffsetX.Value * num2, (0f - unit) * 0.25f - num2 / 2f - (float)i * num4 + Settings.ArrowOffsetY.Value * num2, 0f);
			RectTransform val3 = (RectTransform)((TMP_Text)entry2.timer).transform;
			val3.sizeDelta = new Vector2(num2 * 3f, num3);
			val3.anchoredPosition = new Vector2(0f, (0f - num3) / 2f);
			((Transform)entry2.rect).localScale = Vector3.one;
			((Transform)entry2.rect).localRotation = Quaternion.identity;
			if (entry2.hasTarget && (Object)(object)val != (Object)null)
			{
				Vector3 val4 = entry2.target - val.position;
				if (((Vector3)(ref val4)).sqrMagnitude > 1E-06f)
				{
					Vector3 val5 = val.InverseTransformDirection(val4);
					Vector3 normalized = ((Vector3)(ref val5)).normalized;
					if (!entry2.aimed)
					{
						entry2.dir = normalized;
						entry2.aimed = true;
					}
					val5 = Vector3.Slerp(entry2.dir, normalized, 1f - Mathf.Exp(-14f * Time.deltaTime));
					entry2.dir = ((Vector3)(ref val5)).normalized;
				}
			}
			Color colour = ((entry2.kind == CompassTargets.Kind.Enemy) ? EnemyColour : ExtractionColour);
			entry2.rig.Point(entry2.dir, colour);
			float num5 = (entry2.hasTarget ? 1f : 0.35f);
			float num6 = entry2.until - Time.time;
			if (num6 < 10f)
			{
				num5 *= 0.55f + 0.45f * Mathf.Cos(Time.time * Mathf.Lerp(18f, 6f, num6 / 10f));
			}
			if (flag)
			{
				num5 = 0f;
			}
			entry2.group.alpha = num5;
			int num7 = Mathf.Max(0, Mathf.CeilToInt(entry2.until - Time.time));
			((TMP_Text)entry2.timer).text = $"{num7 / 60}:{num7 % 60:00}";
			((TMP_Text)entry2.timer).fontSize = Mathf.Max(6f, unit * Settings.TimerSizeVsText.Value);
			Color color = Color.Lerp((entry2.kind == CompassTargets.Kind.Enemy) ? EnemyColour : ExtractionColour, Color.white, 0.35f);
			((Graphic)entry2.timer).color = color;
		}
	}

	private void OnDestroy()
	{
		foreach (Entry entry in entries)
		{
			if ((Object)(object)entry.rect != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)entry.rect).gameObject);
			}
			if ((Object)(object)entry.rig != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)entry.rig).gameObject);
			}
		}
		entries.Clear();
		if ((Object)(object)fallbackCanvas != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)fallbackCanvas).gameObject);
		}
		if ((Object)(object)instance == (Object)(object)this)
		{
			instance = null;
		}
	}

	private static Transform ViewTransform()
	{
		Camera main = Camera.main;
		if ((Object)(object)main != (Object)null)
		{
			return ((Component)main).transform;
		}
		PlayerAvatar val = PlayerAvatar.instance;
		if (!((Object)(object)val != (Object)null) || !((Object)(object)val.localCamera != (Object)null))
		{
			return null;
		}
		return ((Component)val.localCamera).transform;
	}

	private void FindAnchor()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_030f: Expected O, but got Unknown
		//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: 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_02a1: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: 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_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: 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_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: 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_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		Transform val = null;
		bool flag = false;
		Vector3 val2 = default(Vector3);
		float num = unit;
		string text = null;
		SemiUI[] array = (SemiUI[])(object)new SemiUI[2]
		{
			(SemiUI)HaulUI.instance,
			(SemiUI)GoalUI.instance
		};
		foreach (SemiUI val3 in array)
		{
			if ((Object)(object)val3 == (Object)null)
			{
				continue;
			}
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)val3).transform.parent;
			}
			if (val3.isHidden || (Object)(object)((Component)val3).transform.parent != (Object)(object)val)
			{
				continue;
			}
			TMP_Text val4 = (TMP_Text)(object)val3.uiText;
			if ((Object)(object)val4 == (Object)null)
			{
				object? obj = ((val3 is HaulUI) ? HaulTextField : GoalTextField)?.GetValue(val3);
				val4 = (TMP_Text)((obj is TMP_Text) ? obj : null);
			}
			if ((Object)(object)val4 == (Object)null || !((Behaviour)val4).isActiveAndEnabled || string.IsNullOrEmpty(val4.text))
			{
				continue;
			}
			Bounds textBounds = val4.textBounds;
			if (((Bounds)(ref textBounds)).size.y > 0f && !float.IsNaN(((Bounds)(ref textBounds)).size.y) && !(((Bounds)(ref textBounds)).size.y > 100000f))
			{
				Vector3 val5 = val.InverseTransformPoint(val4.transform.TransformPoint(new Vector3(((Bounds)(ref textBounds)).center.x, ((Bounds)(ref textBounds)).min.y, 0f)));
				Vector3 val6 = val.InverseTransformPoint(val4.transform.TransformPoint(new Vector3(((Bounds)(ref textBounds)).center.x, ((Bounds)(ref textBounds)).max.y, 0f)));
				if (!flag || val5.y < val2.y)
				{
					flag = true;
					val2 = val5;
					num = Mathf.Max(0.001f, val6.y - val5.y);
					text = ((val3 is HaulUI) ? "haul" : "goal");
				}
			}
		}
		if ((Object)(object)val != (Object)null)
		{
			if ((Object)(object)parent != (Object)(object)val)
			{
				parent = val;
				DetachAll();
			}
			if (flag)
			{
				anchor = val2;
				unit = num;
				anchored = true;
			}
			if (!anchored)
			{
				RectTransform val7 = (RectTransform)(object)((val is RectTransform) ? val : null);
				? val8;
				if (!((Object)(object)val7 != (Object)null))
				{
					val8 = Vector3.zero;
				}
				else
				{
					Rect rect = val7.rect;
					float x = ((Rect)(ref rect)).center.x;
					rect = val7.rect;
					float yMax = ((Rect)(ref rect)).yMax;
					rect = val7.rect;
					val8 = new Vector3(x, yMax - ((Rect)(ref rect)).height * 0.12f, 0f);
				}
				anchor = (Vector3)val8;
			}
			if (Settings.CompassDebugLog.Value && text != null && text != lastAnchorLog)
			{
				lastAnchorLog = text;
				Plugin.Log.LogInfo((object)$"Pocket compass: arrow under the {text} text ('{((Object)val).name}', text height {unit:0.#}).");
			}
			return;
		}
		if ((Object)(object)fallbackCanvas == (Object)null)
		{
			GameObject val9 = new GameObject("HatterMiscellaneousPack Arrow Canvas");
			fallbackCanvas = val9.AddComponent<Canvas>();
			fallbackCanvas.renderMode = (RenderMode)0;
			fallbackCanvas.sortingOrder = 30000;
			val9.AddComponent<CanvasScaler>();
			if (Settings.CompassDebugLog.Value)
			{
				Plugin.Log.LogWarning((object)"Pocket compass: the haul text wasn't found; the arrow uses its own place at the top of the screen.");
			}
		}
		if ((Object)(object)parent != (Object)(object)((Component)fallbackCanvas).transform)
		{
			parent = ((Component)fallbackCanvas).transform;
			DetachAll();
		}
		anchor = new Vector3(0f, (float)Screen.height * 0.5f - (float)Screen.height * 0.12f, 0f);
		unit = (float)Screen.height * 0.035f;
	}

	private static void TMP_Font(TMP_Text t)
	{
		TMP_FontAsset val = null;
		if ((Object)(object)HaulUI.instance != (Object)null && (Object)(object)((SemiUI)HaulUI.instance).uiText != (Object)null)
		{
			val = ((TMP_Text)((SemiUI)HaulUI.instance).uiText).font;
		}
		else if ((Object)(object)GoalUI.instance != (Object)null && (Object)(object)((SemiUI)GoalUI.instance).uiText != (Object)null)
		{
			val = ((TMP_Text)((SemiUI)GoalUI.instance).uiText).font;
		}
		if ((Object)(object)val != (Object)null)
		{
			t.font = val;
		}
	}

	private void DetachAll()
	{
		foreach (Entry entry in entries)
		{
			if ((Object)(object)entry.rect != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)entry.rect).gameObject);
				entry.rect = null;
				entry.image = null;
				entry.timer = null;
				entry.group = null;
			}
		}
	}

	private bool EnsureUI(Entry e)
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: 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_018c: Expected O, but got Unknown
		//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_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)e.rig == (Object)null)
		{
			e.rig = CompassArrow3D.Create();
		}
		if ((Object)(object)e.rect != (Object)null && (Object)(object)e.image != (Object)null && (Object)(object)e.timer != (Object)null)
		{
			return true;
		}
		if ((Object)(object)e.rect != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)e.rect).gameObject);
		}
		if ((Object)(object)parent == (Object)null)
		{
			return false;
		}
		GameObject val = new GameObject($"Pocket Compass Arrow ({e.kind})", new Type[1] { typeof(RectTransform) });
		val.layer = ((Component)parent).gameObject.layer;
		e.rect = (RectTransform)val.transform;
		((Transform)e.rect).SetParent(parent, false);
		RectTransform rect = e.rect;
		RectTransform rect2 = e.rect;
		RectTransform rect3 = e.rect;
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(0.5f, 0.5f);
		rect3.pivot = val2;
		Vector2 val3 = (rect.anchorMin = (rect2.anchorMax = val2));
		((Transform)e.rect).SetAsLastSibling();
		e.group = val.AddComponent<CanvasGroup>();
		e.group.interactable = false;
		e.group.blocksRaycasts = false;
		e.image = val.AddComponent<RawImage>();
		e.image.texture = (Texture)(object)e.rig.texture;
		((Graphic)e.image).raycastTarget = false;
		GameObject val6 = new GameObject("Timer", new Type[1] { typeof(RectTransform) });
		val6.layer = val.layer;
		RectTransform val7 = (RectTransform)val6.transform;
		((Transform)val7).SetParent((Transform)(object)e.rect, false);
		((Vector2)(ref val3))..ctor(0.5f, 0f);
		val7.anchorMax = val3;
		val7.anchorMin = val3;
		val7.pivot = new Vector2(0.5f, 0.5f);
		e.timer = val6.AddComponent<TextMeshProUGUI>();
		TMP_Font((TMP_Text)(object)e.timer);
		((TMP_Text)e.timer).alignment = (TextAlignmentOptions)514;
		((TMP_Text)e.timer).textWrappingMode = (TextWrappingModes)0;
		((Graphic)e.timer).raycastTarget = false;
		((TMP_Text)e.timer).outlineWidth = 0.25f;
		((TMP_Text)e.timer).outlineColor = new Color32((byte)0, (byte)0, (byte)0, (byte)220);
		return true;
	}
}
public class CompassItem : MonoBehaviour
{
	public int kindValue;

	public Transform emblem;

	public Vector3 centre;

	public float size;

	public Sound rejectSound;

	public Sound breakSound;

	private ItemToggle toggle;

	private PhotonView photonView;

	private PhysGrabObject physGrabObject;

	private ItemAttributes attributes;

	private PhysGrabObjectImpactDetector impact;

	private bool used;

	private bool emblemDone;

	private float rejectedUntil;

	private static readonly FieldInfo ToggleIdField = AccessTools.Field(typeof(ItemToggle), "playerTogglePhotonID");

	private static readonly FieldInfo InstanceNameField = AccessTools.Field(typeof(ItemAttributes), "instanceName");

	private CompassTargets.Kind Kind => (CompassTargets.Kind)kindValue;

	private string Label
	{
		get
		{
			if (Kind != CompassTargets.Kind.Enemy)
			{
				return "Pocket Extraction Compass";
			}
			return "Pocket Enemy Compass";
		}
	}

	private void Awake()
	{
		toggle = ((Component)this).GetComponent<ItemToggle>();
		photonView = ((Component)this).GetComponent<PhotonView>();
		physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
		attributes = ((Component)this).GetComponent<ItemAttributes>();
		impact = ((Component)this).GetComponent<PhysGrabObjectImpactDetector>();
	}

	private void Start()
	{
		if ((Object)(object)emblem == (Object)null || emblemDone)
		{
			return;
		}
		emblemDone = true;
		try
		{
			if ((Kind == CompassTargets.Kind.Enemy) ? ((Object)(object)RobeMini.Spawn(emblem, CompassItemBuilder.EmblemHeight, Settings.CompassRobeYaw.Value) != (Object)null) : ((Object)(object)ExtractionMini.Spawn(emblem, CompassItemBuilder.EmblemHeight) != (Object)null))
			{
				Transform val = emblem.Find("Emblem (built in)");
				if ((Object)(object)val != (Object)null)
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogWarning((object)$"{Label}: the emblem copy failed: {arg}");
		}
	}

	private void Update()
	{
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
		if (used || (Object)(object)toggle == (Object)null || !toggle.toggleState || !SemiFunc.IsMasterClientOrSingleplayer() || Time.time < rejectedUntil)
		{
			return;
		}
		int num = ((ToggleIdField != null) ? ((int)ToggleIdField.GetValue(toggle)) : (-1));
		PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(num);
		if ((Object)(object)val == (Object)null && !SemiFunc.IsMultiplayer())
		{
			val = PlayerAvatar.instance;
		}
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		string text = null;
		Vector3 target;
		if (!SemiFunc.RunIsLevel())
		{
			text = "not in a level";
		}
		else if (!CompassTargets.Find(Kind, ((Component)val).transform.position, out target))
		{
			text = "no " + CompassTargets.Describe(Kind) + " to point to";
		}
		if (text != null)
		{
			Reject(text);
			return;
		}
		used = true;
		toggle.ToggleDisable(true);
		try
		{
			string text2 = ((InstanceNameField != null) ? (InstanceNameField.GetValue(attributes) as string) : null);
			if (!string.IsNullOrEmpty(text2) && (Object)(object)StatsManager.instance != (Object)null)
			{
				StatsManager.instance.ItemRemove(text2);
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogWarning((object)$"{Label}: removing it from the owned items failed: {arg}");
		}
		Vector3 val2 = ((Component)this).transform.TransformPoint(centre);
		if (SemiFunc.IsMultiplayer())
		{
			photonView.RPC("HMPCompassUsedRPC", (RpcTarget)0, new object[2] { num, val2 });
		}
		else
		{
			Broken(mine: true, val2);
		}
		if (Settings.CompassDebugLog.Value)
		{
			Plugin.Log.LogInfo((object)(Label + ": broken by " + SafeName(val) + "."));
		}
		if ((Object)(object)impact != (Object)null)
		{
			impact.DestroyObject(false, true);
		}
		if ((Object)(object)physGrabObject != (Object)null)
		{
			physGrabObject.DestroyPhysGrabObject();
		}
	}

	private void Reject(string why)
	{
		//IL_00bb: 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_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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)
		rejectedUntil = Time.time + 0.5f;
		toggle.ToggleItem(false, -1);
		if ((Object)(object)physGrabObject != (Object)null && (Object)(object)physGrabObject.rb != (Object)null)
		{
			physGrabObject.rb.AddForce(Vector3.up * 2f, (ForceMode)1);
			physGrabObject.rb.AddTorque(-((Component)physGrabObject).transform.right * 0.05f, (ForceMode)1);
		}
		if (SemiFunc.IsMultiplayer())
		{
			photonView.RPC("HMPCompassRejectRPC", (RpcTarget)0, Array.Empty<object>());
		}
		else
		{
			Play(rejectSound, ((Component)this).transform.position);
		}
		if (Settings.CompassDebugLog.Value)
		{
			Plugin.Log.LogInfo((object)(Label + ": not used (" + why + ")."));
		}
	}

	[PunRPC]
	public void HMPCompassRejectRPC(PhotonMessageInfo info)
	{
		//IL_0000: 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)
		if (SemiFunc.MasterOnlyRPC(info))
		{
			Play(rejectSound, ((Component)this).transform.position);
		}
	}

	[PunRPC]
	public void HMPCompassUsedRPC(int who, Vector3 at, PhotonMessageInfo info)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if (SemiFunc.MasterOnlyRPC(info))
		{
			Broken(who == SemiFunc.PhotonViewIDPlayerAvatarLocal(), at);
		}
	}

	private void Broken(bool mine, Vector3 at)
	{
		//IL_004a: 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)
		used = true;
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			componentsInChildren[i].enabled = false;
		}
		Collider[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Collider>();
		for (int i = 0; i < componentsInChildren2.Length; i++)
		{
			componentsInChildren2[i].enabled = false;
		}
		Play(breakSound, at);
		try
		{
			CompassShatter.Spawn(at, size);
		}
		catch (Exception arg)
		{
			Plugin.Log.LogWarning((object)$"{Label}: the breaking effect failed: {arg}");
		}
		if (mine)
		{
			CompassArrows.Begin(Kind);
		}
	}

	private void Play(Sound s, Vector3 position)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (s == null)
		{
			return;
		}
		try
		{
			s.Play(position, 1f, 1f, 1f, 1f);
		}
		catch (Exception arg)
		{
			Plugin.Log.LogWarning((object)$"{Label}: sound failed: {arg}");
		}
	}

	private static string SafeName(PlayerAvatar p)
	{
		try
		{
			return SemiFunc.PlayerGetName(p);
		}
		catch
		{
			return ((Object)(object)p != (Object)null) ? ((Object)p).name : "?";
		}
	}
}
internal static class CompassShatter
{
	private class ShatterLife : MonoBehaviour
	{
		public Light glint;

		private float t;

		private void Update()
		{
			t += Time.deltaTime;
			if ((Object)(object)glint != (Object)null)
			{
				glint.intensity = Mathf.Max(0f, 2.5f * (1f - t / 0.25f));
			}
		}
	}

	private static Material material;

	internal static void Spawn(Vector3 at, float size)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Expected O, but got Unknown
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: 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_00da: 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_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: 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_0160: 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_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: 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_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Expected O, but got Unknown
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: 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_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		if ((Object)(object)material == (Object)null)
		{
			Shader val = Shader.Find("Sprites/Default");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			material = new Material(val)
			{
				name = "HMP Compass Shards"
			};
		}
		float num = Mathf.Clamp(size / 0.23f, 0.4f, 3f);
		GameObject val2 = new GameObject("Compass Shatter");
		val2.SetActive(false);
		val2.transform.position = at;
		ParticleSystem val3 = val2.AddComponent<ParticleSystem>();
		MainModule main = val3.main;
		((MainModule)(ref main)).playOnAwake = false;
		((MainModule)(ref main)).loop = false;
		((MainModule)(ref main)).duration = 0.1f;
		((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.5f, 1.1f);
		((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.8f * num, 3f * num);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.008f * num, 0.022f * num);
		((MainModule)(ref main)).startRotation = new MinMaxCurve(0f, MathF.PI * 2f);
		((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(0.8f, 0.95f, 1f, 0.85f), new Color(0.95f, 0.75f, 0.35f, 1f));
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(1.2f);
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		((MainModule)(ref main)).maxParticles = 80;
		EmissionModule emission = val3.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
		((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
		{
			new Burst(0f, (short)45)
		});
		ShapeModule shape = val3.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
		((ShapeModule)(ref shape)).radius = 0.04f * num;
		ColorOverLifetimeModule colorOverLifetime = val3.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		Gradient val4 = new Gradient();
		val4.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
		{
			new GradientColorKey(Color.white, 0f),
			new GradientColorKey(Color.white, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
		{
			new GradientAlphaKey(1f, 0f),
			new GradientAlphaKey(1f, 0.6f),
			new GradientAlphaKey(0f, 1f)
		});
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val4);
		RotationOverLifetimeModule rotationOverLifetime = val3.rotationOverLifetime;
		((RotationOverLifetimeModule)(ref rotationOverLifetime)).enabled = true;
		((RotationOverLifetimeModule)(ref rotationOverLifetime)).z = new MinMaxCurve(-12f, 12f);
		ParticleSystemRenderer component = val2.GetComponent<ParticleSystemRenderer>();
		((Renderer)component).sharedMaterial = material;
		component.renderMode = (ParticleSystemRenderMode)0;
		GameObject val5 = new GameObject("Glint");
		val5.transform.SetParent(val2.transform, false);
		Light val6 = val5.AddComponent<Light>();
		val6.type = (LightType)2;
		val6.color = new Color(0.85f, 0.95f, 1f);
		val6.range = 1.2f * num;
		val6.intensity = 2.5f;
		val6.shadows = (LightShadows)0;
		val2.AddComponent<ShatterLife>().glint = val6;
		val2.SetActive(true);
		val3.Play();
		Object.Destroy((Object)(object)val2, 2f);
	}
}
internal static class CompassItemBuilder
{
	internal const string EnemyName = "Pocket Enemy Compass";

	internal const string ExtractionName = "Pocket Extraction Compass";

	private const string BasePath = "Items/Item Health Pack Small";

	private const string CrystalPath = "Valuables/03 Medium/Valuable Wizard Power Crystal";

	internal static readonly Vector3 SphereCentre = new Vector3(0f, 0.046f, 0f);

	internal static readonly Vector3 Top = new Vector3(0f, 0.09f, 0f);

	private const float FrameWidth = 0.083f;

	internal const float FrameHeight = 0.09f;

	private const float BuiltInEmblemHeight = 0.03f;

	internal const string SimpleEmblemName = "Emblem (built in)";

	private static GameObject holder;

	internal static float EmblemHeight => 0.09f * Settings.CompassEmblemVsCompass.Value;

	private static bool HasClips(Sound s)
	{
		if (s != null && s.Sounds != null)
		{
			return s.Sounds.Length != 0;
		}
		return false;
	}

	internal static GameObject BuildEnemy()
	{
		return Build("Pocket Enemy Compass", "Item Hatter Pocket Enemy Compass", CompassTargets.Kind.Enemy);
	}

	internal static GameObject BuildExtraction()
	{
		return Build("Pocket Extraction Compass", "Item Hatter Pocket Extraction Compass", CompassTargets.Kind.Extraction);
	}

	private static GameObject Build(string label, string prefabName, CompassTargets.Kind kind)
	{
		//IL_00fb: 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_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Expected O, but got Unknown
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0354: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0376: Unknown result type (might be due to invalid IL or missing references)
		//IL_038c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_042e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		//IL_044c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0464: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04de: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Unknown result type (might be due to invalid IL or missing references)
		//IL_0514: Unknown result type (might be due to invalid IL or missing references)
		//IL_051b: Unknown result type (might be due to invalid IL or missing references)
		//IL_052c: Unknown result type (might be due to invalid IL or missing references)
		//IL_052e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0533: Unknown result type (might be due to invalid IL or missing references)
		//IL_053d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0547: Unknown result type (might be due to invalid IL or missing references)
		//IL_054c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0553: Unknown result type (might be due to invalid IL or missing references)
		//IL_0558: Unknown result type (might be due to invalid IL or missing references)
		//IL_055d: Unknown result type (might be due to invalid IL or missing references)
		//IL_057d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0584: Unknown result type (might be due to invalid IL or missing references)
		//IL_0492: Unknown result type (might be due to invalid IL or missing references)
		//IL_0498: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0647: Unknown result type (might be due to invalid IL or missing references)
		//IL_0649: Unknown result type (might be due to invalid IL or missing references)
		//IL_0650: Unknown result type (might be due to invalid IL or missing references)
		//IL_0655: Unknown result type (might be due to invalid IL or missing references)
		//IL_065a: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Resources.Load<GameObject>("Items/Item Health Pack Small");
		if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<ItemAttributes>() == (Object)null)
		{
			Plugin.Log.LogError((object)(label + ": 'Items/Item Health Pack Small' not found."));
			return null;
		}
		MeshLibrary.Model model = MeshLibrary.Get("compass.mesh", "Compass_Frame");
		MeshLibrary.Model model2 = MeshLibrary.Get("compass.mesh", "Compass_Glass");
		MeshLibrary.Model model3 = MeshLibrary.Get("compass.mesh", "Compass_Needle");
		MeshLibrary.Model model4 = MeshLibrary.Get("compass.mesh", (kind == CompassTargets.Kind.Enemy) ? "Compass_EmblemEnemy" : "Compass_EmblemExtraction");
		if (model == null || model3 == null)
		{
			return null;
		}
		if ((Object)(object)holder == (Object)null)
		{
			holder = new GameObject("HatterMiscellaneousPack.PrefabHolder");
			holder.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)holder);
			((Object)holder).hideFlags = (HideFlags)61;
		}
		GameObject val2 = Object.Instantiate<GameObject>(val, holder.transform);
		((Object)val2).name = prefabName;
		Transform transform = val2.transform;
		BuildHelpers.LogComponents(val2, label, "the small health pack");
		Bounds val3 = BuildHelpers.LocalMeshBounds(transform);
		Sound val4 = null;
		ItemHealthPack component = val2.GetComponent<ItemHealthPack>();
		if ((Object)(object)component != (Object)null)
		{
			val4 = component.soundReject;
			Object.DestroyImmediate((Object)(object)component);
		}
		PropLight[] componentsInChildren = val2.GetComponentsInChildren<PropLight>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			((Behaviour)componentsInChildren[i]).enabled = false;
		}
		ParticleSystem[] componentsInChildren2 = val2.GetComponentsInChildren<ParticleSystem>(true);
		for (int i = 0; i < componentsInChildren2.Length; i++)
		{
			((Component)componentsInChildren2[i]).gameObject.SetActive(false);
		}
		Light[] componentsInChildren3 = val2.GetComponentsInChildren<Light>(true);
		for (int i = 0; i < componentsInChildren3.Length; i++)
		{
			((Behaviour)componentsInChildren3[i]).enabled = false;
		}
		Material val5 = null;
		Renderer[] componentsInChildren4 = val2.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val6 in componentsInChildren4)
		{
			if ((Object)(object)val5 == (Object)null && val6 is MeshRenderer && (Object)(object)val6.sharedMaterial != (Object)null)
			{
				val5 = val6.sharedMaterial;
			}
			val6.enabled = false;
		}
		val5 = BuildHelpers.NeutralTemplate(val5);
		NotValuableObject component2 = val2.GetComponent<NotValuableObject>();
		if ((Object)(object)component2 != (Object)null)
		{
			component2.hasHealth = false;
		}
		ItemAttributes component3 = val2.GetComponent<ItemAttributes>();
		Item val7 = Object.Instantiate<Item>(component3.item);
		((Object)val7).name = prefabName;
		val7.itemName = label;
		val7.itemNameLocalized = null;
		float num = Settings.CompassEffectSeconds.Value / 60f;
		string text = ((kind == CompassTargets.Kind.Enemy) ? "the nearest enemy" : "the nearest unfinished extraction point");
		val7.description = "A little brass compass with a stuck needle. Press [E] to break it: an arrow under your haul then points to " + text + " " + $"for {num:0.#} minutes, or until there's nothing left to find. Only you see it.";
		val7.itemType = (itemType)10;
		int num2 = ((kind == CompassTargets.Kind.Enemy) ? Settings.EnemyCompassPriceK.Value : Settings.ExtractionCompassPriceK.Value);
		val7.value = ShopPrice.Fixed(prefabName, num2);
		component3.item = val7;
		component3.icon = null;
		float value = Settings.CompassScale.Value;
		float num3 = (0.09f + EmblemHeight) * value;
		Transform transform2 = new GameObject("Compass Model").transform;
		transform2.SetParent(transform, false);
		((Component)transform2).gameObject.layer = val2.layer;
		Vector3 localPosition = ((Bounds)(ref val3)).size;
		transform2.localPosition = ((((Vector3)(ref localPosition)).sqrMagnitude > 1E-06f) ? (((Bounds)(ref val3)).center - Vector3.up * num3 / 2f) : Vector3.zero);
		transform2.localScale = Vector3.one * value;
		Material template = val5;
		localPosition = default(Vector3);
		MeshLibrary.Attach(model, transform2, "Compass Frame", template, localPosition).layer = val2.layer;
		if (model2 != null)
		{
			Material template2 = val5;
			localPosition = default(Vector3);
			MeshLibrary.Attach(model2, transform2, "Compass Glass", template2, localPosition).layer = val2.layer;
		}
		Transform transform3 = new GameObject("Needle Pivot").transform;
		transform3.SetParent(transform2, false);
		transform3.localPosition = SphereCentre;
		transform3.localRotation = Quaternion.Euler(14f, 37f, 6f);
		((Component)transform3).gameObject.layer = val2.layer;
		Material template3 = val5;
		localPosition = default(Vector3);
		MeshLibrary.Attach(model3, transform3, "Needle", template3, localPosition).layer = val2.layer;
		Transform transform4 = new GameObject("Emblem").transform;
		transform4.SetParent(transform2, false);
		transform4.localPosition = Top;
		((Component)transform4).gameObject.layer = val2.layer;
		if (model4 != null)
		{
			Material template4 = val5;
			localPosition = default(Vector3);
			GameObject obj = MeshLibrary.Attach(model4, transform4, "Emblem (built in)", template4, localPosition);
			obj.layer = val2.layer;
			obj.transform.localScale = Vector3.one * (EmblemHeight / 0.03f);
		}
		Vector3 localPosition2 = transform2.localPosition;
		BuildHelpers.ReplaceColliders(transform, new(Vector3, Quaternion, Vector3)[2]
		{
			(localPosition2 + new Vector3(0f, 0.045f, 0f) * value, Quaternion.identity, new Vector3(0.083f, 0.09f, 0.083f) * value),
			(localPosition2 + (Top + Vector3.up * EmblemHeight / 2f) * value, Quaternion.identity, new Vector3(EmblemHeight * 0.6f, EmblemHeight, EmblemHeight * 0.6f) * value)
		}, label, "the small health pack");
		Sound val8 = null;
		GameObject obj2 = Resources.Load<GameObject>("Valuables/03 Medium/Valuable Wizard Power Crystal");
		ValuableObject val9 = ((obj2 != null) ? obj2.GetComponent<ValuableObject>() : null);
		if ((Object)(object)val9 != (Object)null && (Object)(object)val9.audioPreset != (Object)null)
		{
			val8 = (HasClips(val9.audioPreset.destroy) ? val9.audioPreset.destroy : (HasClips(val9.audioPreset.breakHeavy) ? val9.audioPreset.breakHeavy : null));
		}
		if (val8 == null)
		{
			Plugin.Log.LogWarning((object)(label + ": the power crystal's break sound wasn't found; it breaks silently."));
		}
		CompassItem compassItem = val2.AddComponent<CompassItem>();
		compassItem.kindValue = (int)kind;
		compassItem.emblem = transform4;
		compassItem.centre = localPosition2 + SphereCentre * value;
		compassItem.size = num3;
		compassItem.rejectSound = (HasClips(val4) ? val4 : null);
		compassItem.breakSound = val8;
		Plugin.Log.LogInfo((object)(string.Format("{0}: built from {1} (its model measured {2:0.00} x {3:0.00} x {4:0.00} m), ", label, "the small health pack", ((Bounds)(ref val3)).size.x, ((Bounds)(ref val3)).size.y, ((Bounds)(ref val3)).size.z) + string.Format("{0:0} cm tall, ${1}K, material '{2}'.", num3 * 100f, num2, ((Object)(object)val5 != (Object)null) ? ((Object)val5).name : "none")));
		return val2;
	}
}
internal static class CompassTargets
{
	internal enum Kind
	{
		Enemy,
		Extraction
	}

	private static readonly FieldInfo SpawnedField = AccessTools.Field(typeof(EnemyParent), "Spawned");

	private static readonly FieldInfo ParentEnemyField = AccessTools.Field(typeof(EnemyParent), "Enemy");

	private static readonly FieldInfo HealthField = AccessTools.Field(typeof(Enemy), "Health");

	private static readonly FieldInfo DeadField = AccessTools.Field(typeof(EnemyHealth), "dead");

	private static readonly FieldInfo StateField = AccessTools.Field(typeof(ExtractionPoint), "currentState");

	private static readonly FieldInfo ShopField = AccessTools.Field(typeof(ExtractionPoint), "isShop");

	private static ExtractionPoint[] points = (ExtractionPoint[])(object)new ExtractionPoint[0];

	private static float pointsAt = -10f;

	internal static bool Find(Kind kind, Vector3 from, out Vector3 target)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		if (kind != Kind.Enemy)
		{
			return NearestExtraction(from, out target);
		}
		return NearestEnemy(from, out target);
	}

	internal static string Describe(Kind kind)
	{
		if (kind != Kind.Enemy)
		{
			return "extraction point";
		}
		return "enemy";
	}

	private static bool NearestEnemy(Vector3 from, out Vector3 best)
	{
		//IL_0001: 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_011a: 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_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: 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)
		best = default(Vector3);
		EnemyDirector instance = EnemyDirector.instance;
		if ((Object)(object)instance == (Object)null || instance.enemiesSpawned == null)
		{
			return false;
		}
		float num = float.MaxValue;
		foreach (EnemyParent item in instance.enemiesSpawned)
		{
			if ((Object)(object)item == (Object)null || (SpawnedField != null && !(bool)SpawnedField.GetValue(item)))
			{
				continue;
			}
			Enemy val = (Enemy)(((object)((ParentEnemyField != null) ? /*isinst with value type is only supported in some contexts*/: null)) ?? ((object)((Component)item).GetComponentInChildren<Enemy>()));
			if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
			{
				continue;
			}
			EnemyHealth val2 = (EnemyHealth)((HealthField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if (!((Object)(object)val2 != (Object)null) || !(DeadField != null) || !(bool)DeadField.GetValue(val2))
			{
				Vector3 val3 = (((Object)(object)val.CenterTransform != (Object)null) ? val.CenterTransform.position : ((Component)val).transform.position);
				Vector3 val4 = val3 - from;
				float sqrMagnitude = ((Vector3)(ref val4)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
					best = val3;
				}
			}
		}
		return num < float.MaxValue;
	}

	private static bool NearestExtraction(Vector3 from, out Vector3 best)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		best = default(Vector3);
		if (Time.time - pointsAt > 3f || Time.time < pointsAt)
		{
			pointsAt = Time.time;
			points = Object.FindObjectsByType<ExtractionPoint>((FindObjectsSortMode)0);
		}
		float num = float.MaxValue;
		ExtractionPoint[] array = points;
		foreach (ExtractionPoint val in array)
		{
			if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeInHierarchy && (!(ShopField != null) || !(bool)ShopField.GetValue(val)) && (!(StateField != null) || !(StateField.GetValue(val)?.ToString() == "Complete")))
			{
				Vector3 val2 = ((Component)val).transform.position - from;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
					best = ((Component)val).transform.position;
				}
			}
		}
		return num < float.MaxValue;
	}
}
internal class ExtractionMini : MonoBehaviour
{
	private TMP_Text emojiCopy;

	private TMP_Text haulCopy;

	private TMP_Text emojiSource;

	private TMP_Text haulSource;

	private float nextSync;

	private static bool logged;

	internal static ExtractionMini Spawn(Transform parent, float height)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Expected O, but got Unknown
		//IL_00b1: 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_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: 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_014c: 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_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: 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_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: Unknown result type (might be due to invalid IL or missing references)
		//IL_035a: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: 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_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_0380: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0408: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0420: Unknown result type (might be due to invalid IL or missing references)
		//IL_0422: Unknown result type (might be due to invalid IL or missing references)
		//IL_0424: Unknown result type (might be due to invalid IL or missing references)
		//IL_042b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0430: Unknown result type (might be due to invalid IL or missing references)
		ExtractionPoint val = null;
		ExtractionPoint[] array = Object.FindObjectsByType<ExtractionPoint>((FindObjectsSortMode)0);
		foreach (ExtractionPoint val2 in array)
		{
			if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.emojiScreen == (Object)null))
			{
				val = val2;
				break;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		Transform transform = ((Component)val).transform;
		Matrix4x4 toFrame = transform.worldToLocalMatrix;
		string report;
		List<Renderer> list = Pick(val, out report);
		if (!logged)
		{
			logged = true;
			Plugin.Log.LogInfo((object)report);
		}
		if (list.Count == 0 && (Object)(object)val.emojiScreen == (Object)null)
		{
			return null;
		}
		GameObject val3 = new GameObject("Little Extraction Screen (from the level)");
		Transform transform2 = new GameObject("Pieces").transform;
		transform2.SetParent(val3.transform, false);
		bool any = false;
		Bounds b = default(Bounds);
		foreach (Renderer item in list)
		{
			MeshFilter component = ((Component)item).GetComponent<MeshFilter>();
			if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
			{
				GameObject val4 = new GameObject(((Object)item).name);
				val4.transform.SetParent(transform2, false);
				Place(val4.transform, toFrame * ((Component)item).transform.localToWorldMatrix);
				val4.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh;
				MeshRenderer obj = val4.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterials = item.sharedMaterials;
				((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
				Grow(item.bounds);
			}
		}
		int childCount = transform2.childCount;
		ExtractionMini extractionMini = val3.AddComponent<ExtractionMini>();
		extractionMini.emojiSource = (TMP_Text)(object)val.emojiScreen;
		extractionMini.haulSource = (TMP_Text)(object)val.haulGoalScreen;
		extractionMini.emojiCopy = CopyText((TMP_Text)(object)val.emojiScreen, transform2, toFrame, Grow);
		extractionMini.haulCopy = CopyText((TMP_Text)(object)val.haulGoalScreen, transform2, toFrame, Grow);
		float num = (any ? Mathf.Max(new float[3]
		{
			((Bounds)(ref b)).size.x,
			((Bounds)(ref b)).size.y,
			((Bounds)(ref b)).size.z
		}) : 0f);
		Plugin.Log.LogInfo((object)$"Extraction Compass: copied {childCount} piece(s) from '{((Object)val).name}', {((Bounds)(ref b)).size.x:0.00} x {((Bounds)(ref b)).size.y:0.00} x {((Bounds)(ref b)).size.z:0.00} m.");
		if (!any || childCount == 0 || ((Bounds)(ref b)).size.y < 0.15f || num > 4f)
		{
			Plugin.Log.LogWarning((object)"Extraction Compass: the copied screen doesn't look right (no pieces, or the wrong size); the built-in dollar sign stays. Send the 'extraction point's pieces' list to fix the pick, or set ExtractionScreenParts.");
			Object.Destroy((Object)(object)val3);
			return null;
		}
		Vector3 val5 = (((Object)(object)val.emojiScreen != (Object)null) ? ((Matrix4x4)(ref toFrame)).MultiplyVector(-val.emojiScreen.transform.forward) : Vector3.forward);
		val5.y = 0f;
		Quaternion val6 = ((((Vector3)(ref val5)).sqrMagnitude > 0.0001f) ? Quaternion.FromToRotation(((Vector3)(ref val5)).normalized, Vector3.forward) : Quaternion.identity);
		float num2 = height / ((Bounds)(ref b)).size.y;
		Vector3 val7 = default(Vector3);
		((Vector3)(ref val7))..ctor(((Bounds)(ref b)).center.x, ((Bounds)(ref b)).min.y, ((Bounds)(ref b)).center.z);
		val3.transform.SetParent(parent, false);
		val3.transform.localRotation = val6;
		val3.transform.localScale = Vector3.one * num2;
		val3.transform.localPosition = val6 * (-val7 * num2);
		SetLayer(val3.transform, ((Component)parent).gameObject.layer);
		extractionMini.Sync();
		return extractionMini;
		void Grow(Bounds wb)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			for (int j = 0; j < 8; j++)
			{
				Vector3 val8 = ((Bounds)(ref wb)).center + Vector3.Scale(((Bounds)(ref wb)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
				Vector3 val9 = ((Matrix4x4)(ref toFrame)).MultiplyPoint3x4(val8);
				if (!any)
				{
					b = new Bounds(val9, Vector3.zero);
					any = true;
				}
				else
				{
					((Bounds)(ref b)).Encapsulate(val9);
				}
			}
		}
	}

	private static void Place(Transform t, Matrix4x4 m)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		t.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn(3));
		t.localRotation = ((Matrix4x4)(ref m)).rotation;
		t.localScale = ((Matrix4x4)(ref m)).lossyScale;
	}

	private static TMP_Text CopyText(TMP_Text source, Transform parent, Matrix4x4 toFrame, Action<Bounds> grow)
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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_0131: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: 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_010f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)source == (Object)null)
		{
			return null;
		}
		GameObject val = Object.Instantiate<GameObject>(((Component)source).gameObject, parent, false);
		((Object)val).name = ((Object)source).name;
		MonoBehaviour[] componentsInChildren = val.GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val2 in componentsInChildren)
		{
			if ((Object)(object)val2 != (Object)null && !(val2 is TMP_Text) && !(val2 is TMP_SubMesh))
			{
				Object.DestroyImmediate((Object)(object)val2);
			}
		}
		foreach (Transform item in val.transform)
		{
			Transform val3 = item;
			if ((Object)(object)((Component)val3).GetComponent<TMP_SubMesh>() == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val3).gameObject);
			}
		}
		val.SetActive(true);
		Place(val.transform, toFrame * source.