Decompiled source of Minimap v1.2.3

SpellBrigadeMinimap.dll

Decompiled 7 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using Microsoft.CodeAnalysis;
using SpellBrigadeMinimap.Core;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.UI;
using UnityEngine.VFX;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SpellBrigadeMinimap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.3.0")]
[assembly: AssemblyInformationalVersion("1.2.3+7d70683ba475930864e0be5093e202c0bc7e056a")]
[assembly: AssemblyProduct("SpellBrigadeMinimap")]
[assembly: AssemblyTitle("SpellBrigadeMinimap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SpellBrigadeMinimap
{
	internal static class DebugImages
	{
		private static string runStamp = "run";

		public static void BeginRun()
		{
			runStamp = DateTime.Now.ToString("yyyyMMdd-HHmmss");
		}

		public static void Save(string name, PixelBuffer img)
		{
			if (img != null && Mod.Settings.SaveDebugImages.Value)
			{
				Write(runStamp + "-" + name + ".png", delegate(string path)
				{
					File.WriteAllBytes(path, PngWriter.Encode(img));
				});
			}
		}

		public static void SaveText(string name, string text)
		{
			if (text != null && Mod.Settings.SaveDebugImages.Value)
			{
				Write(runStamp + "-" + name + ".txt", delegate(string path)
				{
					File.WriteAllText(path, text);
				});
			}
		}

		private static void Write(string fileName, Action<string> write)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			try
			{
				string text = Path.Combine(Paths.BepInExRootPath, "minimap-debug");
				Directory.CreateDirectory(text);
				string text2 = Path.Combine(text, fileName);
				write(text2);
				ManualLogSource log = Mod.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(6, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Saved ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text2);
				}
				log.LogInfo(val);
			}
			catch (Exception e)
			{
				LogOnce.Error("saving a debug file", e);
			}
		}
	}
	internal static class GameFont
	{
		private const float RetrySeconds = 2f;

		private const float FailRetrySeconds = 30f;

		private static TMP_FontAsset font;

		private static float nextTry;

		public static TMP_FontAsset Font
		{
			get
			{
				if (!((Object)(object)font != (Object)null))
				{
					return null;
				}
				return font;
			}
		}

		public static bool TryFind(float now)
		{
			if ((Object)(object)font != (Object)null)
			{
				return true;
			}
			if (now < nextTry)
			{
				return false;
			}
			nextTry = now + 2f;
			try
			{
				Il2CppArrayBase<TextMeshProUGUI> val = Object.FindObjectsOfType<TextMeshProUGUI>();
				Dictionary<IntPtr, (TMP_FontAsset, int)> dictionary = new Dictionary<IntPtr, (TMP_FontAsset, int)>();
				int num = 0;
				for (int i = 0; i < val.Length; i++)
				{
					TextMeshProUGUI val2 = val[i];
					if (!((Object)(object)val2 == (Object)null) && ((Behaviour)val2).isActiveAndEnabled)
					{
						TMP_FontAsset val3 = ((TMP_Text)val2).font;
						if (!((Object)(object)val3 == (Object)null))
						{
							num++;
							dictionary.TryGetValue(((Il2CppObjectBase)val3).Pointer, out var value);
							dictionary[((Il2CppObjectBase)val3).Pointer] = (val3, value.Item2 + 1);
						}
					}
				}
				if (dictionary.Count == 0)
				{
					return false;
				}
				List<(TMP_FontAsset, int)> list = dictionary.Values.OrderByDescending<(TMP_FontAsset, int), int>(((TMP_FontAsset font, int n) tuple) => tuple.n).ToList();
				font = list[0].Item1;
				string text = string.Join(", ", from tuple in list.Skip(1).Take(4)
					select $"'{((Object)tuple.font).name}' {tuple.n}");
				Mod.Log.LogInfo((object)($"Game font for the minimap's numbers: '{((Object)font).name}' ({list[0].Item2} of {num} texts on screen)" + ((text.Length > 0) ? ("; also " + text + ".") : ".")));
				return true;
			}
			catch (Exception e)
			{
				nextTry = now + 30f;
				LogOnce.Error("finding the game's font", e);
				return false;
			}
		}
	}
	internal static class GameIcons
	{
		public const string Collect = "ui_ping_objective_collect";

		public const string Order = "ui_ping_objective_order";

		public const string Herding = "ui_ping_objective_herding";

		public const string HerdingZone = "ui_ping_objective_herding_zone";

		public const string Push = "ui_ping_objective_push";

		public const string PushZone = "ui_ping_objective_push_zone";

		public const string Petrified = "ui_ping_objective_petrifiedenemies";

		public const string Hunt = "ui_ping_objective_hunttarget";

		public const string Capture = "ui_ping_objective_capture";

		public const string Clean = "ui_ping_objective_clean";

		public const string Sacrifice = "ui_ping_objective_sacrifice";

		private const string Prefix = "ui_ping_objective_";

		private const float SweepSeconds = 5f;

		private const int MaxSweepsPerLevel = 4;

		private static readonly Dictionary<string, Sprite> originals = new Dictionary<string, Sprite>();

		private static readonly HashSet<IntPtr> offered = new HashSet<IntPtr>();

		private static readonly Dictionary<IntPtr, string> names = new Dictionary<IntPtr, string>();

		private static float nextSweep;

		private static int sweeps;

		public static string PieceName(PieceKind kind)
		{
			return kind switch
			{
				PieceKind.Mushroom => "ui_ping_objective_collect", 
				PieceKind.Crate => "ui_ping_objective_push", 
				PieceKind.Herd => "ui_ping_objective_herding", 
				PieceKind.Hunt => "ui_ping_objective_hunttarget", 
				_ => "ui_ping_objective_petrifiedenemies", 
			};
		}

		public static void Reset()
		{
			originals.Clear();
			offered.Clear();
			names.Clear();
			nextSweep = 0f;
			sweeps = 0;
		}

		public static void Offer(Sprite icon)
		{
			if ((Object)(object)icon == (Object)null)
			{
				return;
			}
			try
			{
				if (offered.Add(((Il2CppObjectBase)icon).Pointer))
				{
					if (offered.Count > 512)
					{
						offered.Clear();
					}
					string name = ((Object)icon).name;
					if (name != null && name.StartsWith("ui_ping_objective_", StringComparison.Ordinal) && !originals.ContainsKey(name))
					{
						originals[name] = icon;
					}
				}
			}
			catch (Exception e)
			{
				LogOnce.Error("reading a game icon's name", e);
			}
		}

		public static Sprite White(string name)
		{
			Sprite val = Original(name);
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return IconRecolor.White(val, null);
		}

		public static Sprite Statue()
		{
			Sprite val = Original("ui_ping_objective_petrifiedenemies");
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return IconRecolor.Statue(val);
		}

		public static string NameOf(Sprite icon)
		{
			if ((Object)(object)icon == (Object)null)
			{
				return null;
			}
			if (names.TryGetValue(((Il2CppObjectBase)icon).Pointer, out var value))
			{
				return value;
			}
			try
			{
				value = ((Object)icon).name;
			}
			catch
			{
				value = null;
			}
			if (names.Count > 512)
			{
				names.Clear();
			}
			names[((Il2CppObjectBase)icon).Pointer] = value;
			return value;
		}

		private static Sprite Original(string name)
		{
			if (originals.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Sweep();
			if (!originals.TryGetValue(name, out value))
			{
				return null;
			}
			return value;
		}

		private static void Sweep()
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			float unscaledTime = Time.unscaledTime;
			if (sweeps >= 4 || unscaledTime < nextSweep)
			{
				return;
			}
			nextSweep = unscaledTime + 5f;
			sweeps++;
			try
			{
				Il2CppArrayBase<Sprite> val = Resources.FindObjectsOfTypeAll<Sprite>();
				int num = 0;
				for (int i = 0; i < val.Length; i++)
				{
					Sprite val2 = val[i];
					if (!((Object)(object)val2 == (Object)null))
					{
						string name = ((Object)val2).name;
						if (name != null && name.StartsWith("ui_ping_objective_", StringComparison.Ordinal) && !originals.ContainsKey(name))
						{
							originals[name] = val2;
							num++;
						}
					}
				}
				ManualLogSource log = Mod.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(74, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Game objective icons: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(originals.Count);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" known after looking through ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(val.Length);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" loaded sprites (");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" new).");
				}
				log.LogInfo(val3);
			}
			catch (Exception e)
			{
				LogOnce.Error("looking for the game's objective icons", e);
			}
		}
	}
	internal sealed class HudAvoider
	{
		private const float RefreshSeconds = 3f;

		private const float ScanSeconds = 0.25f;

		private const float MaxPieceShare = 0.4f;

		private const float MoveSpeed = 900f;

		private const int MaxLogs = 20;

		private readonly HudClearance clearance = new HudClearance(1f, 1.5f, 0f, float.MaxValue);

		private readonly List<Graphic> candidates = new List<Graphic>();

		private readonly List<(long, ScreenBox)> boxes = new List<(long, ScreenBox)>();

		private readonly Il2CppStructArray<Vector3> corners = new Il2CppStructArray<Vector3>(4L);

		private readonly HashSet<string> logged = new HashSet<string>();

		private float nextRefresh;

		private float nextScan;

		private float target;

		private float current;

		private int logs;

		public void Reset()
		{
			clearance.Reset();
			candidates.Clear();
			nextRefresh = (nextScan = (target = (current = 0f)));
		}

		public float Tick(float now, float dt, ScreenBox home, bool bottomCorner, Canvas own, float scale, float gap, float maxMove)
		{
			try
			{
				if (now >= nextRefresh)
				{
					nextRefresh = now + 3f;
					Refresh(in home, own);
				}
				if (now >= nextScan)
				{
					nextScan = now + 0.25f;
					boxes.Clear();
					foreach (Graphic candidate in candidates)
					{
						if (Visible(candidate) && TryBox(candidate, out var box))
						{
							boxes.Add((((Il2CppObjectBase)candidate).Pointer.ToInt64(), box));
						}
					}
					float num = clearance.Update(now, in home, bottomCorner, boxes);
					float num2 = ((num > 0f) ? Math.Min(num / scale + gap, maxMove) : 0f);
					if (num2 > target + 0.5f)
					{
						LogCause(in home, bottomCorner, num2);
					}
					target = num2;
				}
			}
			catch (Exception e)
			{
				LogOnce.Error("keeping the minimap clear of the game's HUD", e);
				target = 0f;
			}
			current = Mathf.MoveTowards(current, target, 900f * dt);
			return current;
		}

		private void Refresh(in ScreenBox home, Canvas own)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Invalid comparison between Unknown and I4
			candidates.Clear();
			float num = (home.YMax - home.YMin) * 1.5f;
			ScreenBox o = new ScreenBox(home.XMin - num, home.YMin - num, home.XMax + num, home.YMax + num);
			Il2CppArrayBase<Canvas> val = Object.FindObjectsOfType<Canvas>();
			for (int i = 0; i < val.Length; i++)
			{
				Canvas val2 = val[i];
				if ((Object)(object)val2 == (Object)null || !((Behaviour)val2).isActiveAndEnabled || !val2.isRootCanvas || (int)val2.renderMode == 2 || ((Object)(object)own != (Object)null && ((Il2CppObjectBase)val2).Pointer == ((Il2CppObjectBase)own).Pointer))
				{
					continue;
				}
				Il2CppArrayBase<Graphic> componentsInChildren = ((Component)val2).GetComponentsInChildren<Graphic>(false);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					Graphic val3 = componentsInChildren[j];
					if (!((Object)(object)val3 == (Object)null) && TryBox(val3, out var box) && box.Overlaps(in o) && !((Object)(object)((Component)val3).GetComponentInParent<ScreenPointer>() != (Object)null))
					{
						candidates.Add(val3);
					}
				}
			}
		}

		private static bool Visible(Graphic g)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)g == (Object)null || !((Behaviour)g).isActiveAndEnabled || g.color.a < 0.1f)
			{
				return false;
			}
			CanvasRenderer canvasRenderer = g.canvasRenderer;
			if ((Object)(object)canvasRenderer != (Object)null && canvasRenderer.cull)
			{
				return false;
			}
			Il2CppArrayBase<CanvasGroup> componentsInParent = ((Component)g).GetComponentsInParent<CanvasGroup>();
			float num = 1f;
			for (int i = 0; i < componentsInParent.Length; i++)
			{
				CanvasGroup val = componentsInParent[i];
				if (!((Object)(object)val == (Object)null) && ((Behaviour)val).enabled)
				{
					num *= val.alpha;
					if (val.ignoreParentGroups)
					{
						break;
					}
				}
			}
			return num >= 0.1f;
		}

		private bool TryBox(Graphic g, out ScreenBox box)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_008c: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			box = default(ScreenBox);
			Canvas canvas = g.canvas;
			if ((Object)(object)canvas == (Object)null)
			{
				return false;
			}
			g.rectTransform.GetWorldCorners(corners);
			Camera val = (((int)canvas.renderMode == 1) ? canvas.worldCamera : null);
			float num = float.MaxValue;
			float num2 = float.MaxValue;
			float num3 = float.MinValue;
			float num4 = float.MinValue;
			for (int i = 0; i < 4; i++)
			{
				Vector2 val2 = (((Object)(object)val != (Object)null) ? RectTransformUtility.WorldToScreenPoint(val, ((Il2CppArrayBase<Vector3>)(object)corners)[i]) : Vector2.op_Implicit(((Il2CppArrayBase<Vector3>)(object)corners)[i]));
				num = Math.Min(num, val2.x);
				num3 = Math.Max(num3, val2.x);
				num2 = Math.Min(num2, val2.y);
				num4 = Math.Max(num4, val2.y);
			}
			float num5 = num3 - num;
			float num6 = num4 - num2;
			if (num5 < 4f || num6 < 4f || num5 > (float)Screen.width * 0.4f || num6 > (float)Screen.height * 0.4f)
			{
				return false;
			}
			box = new ScreenBox(num, num2, num3, num4);
			return true;
		}

		private void LogCause(in ScreenBox home, bool bottomCorner, float units)
		{
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			if (logs >= 20)
			{
				return;
			}
			List<string> list = new List<string>();
			foreach (Graphic candidate in candidates)
			{
				if (Visible(candidate) && TryBox(candidate, out var box) && box.Overlaps(in home) && !(bottomCorner ? (box.CenterY > home.CenterY) : (box.CenterY < home.CenterY)))
				{
					Transform transform = ((Component)candidate).transform;
					string item = (((Object)(object)transform.parent != (Object)null) ? (((Object)transform.parent).name + "/" + ((Object)transform).name) : ((Object)transform).name);
					if (!list.Contains(item))
					{
						list.Add(item);
					}
				}
			}
			string text = string.Join(", ", list);
			if (list.Count != 0 && logged.Add(text))
			{
				logs++;
				ManualLogSource log = Mod.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(38, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Moving the minimap ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(units, "0");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" units ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(bottomCorner ? "up" : "down");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" to clear: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(".");
				}
				log.LogInfo(val2);
			}
		}
	}
	internal sealed class IconPool
	{
		private readonly RectTransform parent;

		private readonly List<Image> images = new List<Image>();

		private int used;

		public IconPool(RectTransform parent)
		{
			this.parent = parent;
		}

		public void Begin()
		{
			used = 0;
		}

		public void Place(Sprite sprite, Color color, Vector2 position, float size, float rotation)
		{
			//IL_0002: 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)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			Place(sprite, color, position, new Vector2(size, size), rotation);
		}

		public void Place(Sprite sprite, Color color, Vector2 position, Vector2 size, float rotation)
		{
			//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_0083: 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_009d: 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)
			Image val;
			if (used < images.Count)
			{
				val = images[used];
			}
			else
			{
				val = UiBuilder.NewImage("Icon", (Transform)(object)parent);
				images.Add(val);
			}
			used++;
			if ((Object)(object)val.sprite != (Object)(object)sprite)
			{
				val.sprite = sprite;
			}
			if (((Graphic)val).color != color)
			{
				((Graphic)val).color = color;
			}
			RectTransform rectTransform = ((Graphic)val).rectTransform;
			rectTransform.anchoredPosition = position;
			rectTransform.sizeDelta = size;
			((Transform)rectTransform).localEulerAngles = new Vector3(0f, 0f, rotation);
			if (!((Behaviour)val).enabled)
			{
				((Behaviour)val).enabled = true;
			}
		}

		public void End()
		{
			for (int i = used; i < images.Count; i++)
			{
				if (((Behaviour)images[i]).enabled)
				{
					((Behaviour)images[i]).enabled = false;
				}
			}
		}
	}
	internal static class IconRecolor
	{
		private const float EdgeShare = 0.07f;

		private static readonly Rgba Edge = new Rgba(22, 22, 22);

		private static readonly Rgba Stone = new Rgba(168, 172, 182);

		private static readonly Rgba StoneDetail = new Rgba(110, 180, byte.MaxValue);

		private static readonly Dictionary<IntPtr, Sprite> white = new Dictionary<IntPtr, Sprite>();

		private static readonly Dictionary<IntPtr, Sprite> statue = new Dictionary<IntPtr, Sprite>();

		private static bool broken;

		public static Sprite White(Sprite icon, Transform forWhat)
		{
			if ((Object)(object)icon == (Object)null || broken)
			{
				return null;
			}
			if (white.TryGetValue(((Il2CppObjectBase)icon).Pointer, out var value))
			{
				return value;
			}
			value = Make(icon, ((Object)(object)forWhat != (Object)null) ? ("'" + ((Object)forWhat).name + "'") : "the minimap", "white", (PixelBuffer img) => IconMask.ToWhite(img));
			white[((Il2CppObjectBase)icon).Pointer] = value;
			return value;
		}

		public static Sprite Statue(Sprite icon)
		{
			if ((Object)(object)icon == (Object)null || broken)
			{
				return null;
			}
			if (statue.TryGetValue(((Il2CppObjectBase)icon).Pointer, out var value))
			{
				return value;
			}
			value = Make(icon, "the statues", "statue", (PixelBuffer img) => IconMask.Statue(img, Stone, StoneDetail));
			statue[((Il2CppObjectBase)icon).Pointer] = value;
			return value;
		}

		private static Sprite Make(Sprite icon, string label, string kind, Func<PixelBuffer, PixelBuffer> recolour)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			try
			{
				PixelBuffer pixelBuffer = ReadIcon(icon);
				if (pixelBuffer == null)
				{
					return null;
				}
				int width = Math.Max(1, (int)Math.Round((float)Math.Max(pixelBuffer.Width, pixelBuffer.Height) * 0.07f));
				PixelBuffer img = IconMask.Outline(recolour(pixelBuffer), width, Edge);
				Rgba rgba = IconMask.AverageColour(pixelBuffer);
				ManualLogSource log = Mod.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(63, 8, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Game icon '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)icon).name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' (for ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(label);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(pixelBuffer.Width);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" x ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(pixelBuffer.Height);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" px, average colour (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<byte>(rgba.R);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<byte>(rgba.G);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<byte>(rgba.B);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("); ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(kind);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" copy made.");
				}
				log.LogInfo(val);
				string text = Safe(((Object)icon).name);
				DebugImages.Save("icon-" + text, pixelBuffer);
				DebugImages.Save("icon-" + text + "-" + kind, img);
				return SpriteFactory.ToSprite(img, (FilterMode)1);
			}
			catch (Exception e)
			{
				broken = true;
				LogOnce.Error("recolouring a game icon (objectives fall back to the minimap's own icons)", e);
				return null;
			}
		}

		private static PixelBuffer ReadIcon(Sprite icon)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			Texture2D texture = icon.texture;
			if ((Object)(object)texture == (Object)null)
			{
				return null;
			}
			Rect val;
			try
			{
				val = icon.textureRect;
			}
			catch
			{
				val = icon.rect;
			}
			int num = (int)((Rect)(ref val)).x;
			int num2 = (int)((Rect)(ref val)).y;
			int num3 = Math.Max(1, (int)((Rect)(ref val)).width);
			int num4 = Math.Max(1, (int)((Rect)(ref val)).height);
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			Texture2D val2 = null;
			try
			{
				Graphics.Blit((Texture)(object)texture, temporary);
				RenderTexture.active = temporary;
				val2 = new Texture2D(num3, num4, (TextureFormat)4, false);
				val2.ReadPixels(new Rect((float)num, (float)num2, (float)num3, (float)num4), 0, 0, false);
				RenderTexture.active = active;
				Il2CppStructArray<Color32> pixels = val2.GetPixels32();
				if (((Il2CppArrayBase<Color32>)(object)pixels).Length < num3 * num4)
				{
					return null;
				}
				PixelBuffer pixelBuffer = new PixelBuffer(num3, num4);
				Marshal.Copy(IntPtr.Add(((Il2CppObjectBase)pixels).Pointer, 4 * IntPtr.Size), pixelBuffer.Data, 0, pixelBuffer.Data.Length);
				return pixelBuffer;
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
			}
		}

		private static string Safe(string name)
		{
			char[] array = (name ?? "icon").ToCharArray();
			for (int i = 0; i < array.Length; i++)
			{
				if (!char.IsLetterOrDigit(array[i]) && array[i] != '-' && array[i] != '_')
				{
					array[i] = '_';
				}
			}
			return new string(array);
		}
	}
	internal static class LevelSnapshot
	{
		private const int Supersample = 4;

		private const int MaxTextureSide = 2048;

		private const float CameraHeight = 12f;

		private const int UiLayer = 5;

		private static readonly Rgba CoverageKey = new Rgba(byte.MaxValue, 0, byte.MaxValue);

		private static bool fogLogged;

		private static bool gradingLogged;

		private static bool layersLogged;

		public static PixelBuffer CaptureLevel(float originX, float originZ, int cellsW, int cellsH, float cellSize, float groundY, IList<Renderer> alsoHide = null)
		{
			//IL_0094: 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_002b: Expected O, but got Unknown
			if (!fogLogged)
			{
				fogLogged = true;
				try
				{
					ManualLogSource log = Mod.Log;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(14, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Scene fog is ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(RenderSettings.fog ? "on" : "off");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
					}
					log.LogInfo(val);
				}
				catch
				{
				}
			}
			int num = SupersampleFor(cellsW, cellsH);
			List<Renderer> hidden = new List<Renderer>();
			List<VolumeComponent> lensEffectsOff = new List<VolumeComponent>();
			return PixelBuffer.Downsample(RenderTopDown(originX, originZ, cellsW, cellsH, cellSize, groundY, num, GameLayers(), Color.black, delegate(Camera cam)
			{
				HideMovingThings(hidden);
				if (alsoHide != null)
				{
					foreach (Renderer item in alsoHide)
					{
						if ((Object)(object)item != (Object)null && item.enabled)
						{
							item.enabled = false;
							hidden.Add(item);
						}
					}
				}
				DisableLensEffects(lensEffectsOff);
				UseGameColourGrading(cam);
			}, delegate
			{
				foreach (Renderer item2 in hidden)
				{
					if ((Object)(object)item2 != (Object)null)
					{
						item2.enabled = true;
					}
				}
				foreach (VolumeComponent item3 in lensEffectsOff)
				{
					if ((Object)(object)item3 != (Object)null)
					{
						item3.active = true;
					}
				}
			}), cellsW * num, cellsH * num, num);
		}

		private static int GameLayers()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			int num = -33;
			try
			{
				Camera main = Camera.main;
				if ((Object)(object)main != (Object)null && (main.cullingMask & num & 1) != 0)
				{
					num &= main.cullingMask;
				}
				if (!layersLogged)
				{
					layersLogged = true;
					List<int> list = new List<int>();
					for (int i = 0; i < 32; i++)
					{
						if ((num & (1 << i)) == 0)
						{
							list.Add(i);
						}
					}
					ManualLogSource log = Mod.Log;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(54, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Level picture skips layers ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(string.Join(", ", list));
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (as the game camera does).");
					}
					log.LogInfo(val);
				}
			}
			catch (Exception e)
			{
				LogOnce.Error("reading the game camera's layers", e);
			}
			return num;
		}

		public static int FreeLayer()
		{
			bool[] array = new bool[32];
			Il2CppArrayBase<Renderer> val = Object.FindObjectsOfType<Renderer>();
			for (int i = 0; i < val.Length; i++)
			{
				if ((Object)(object)val[i] != (Object)null)
				{
					array[((Component)val[i]).gameObject.layer] = true;
				}
			}
			for (int num = 31; num >= 8; num--)
			{
				if (!array[num])
				{
					return num;
				}
			}
			return -1;
		}

		public static T OnLayer<T>(IEnumerable<GameObject> objects, int layer, Func<T> body)
		{
			List<(GameObject, int)> list = new List<(GameObject, int)>();
			try
			{
				foreach (GameObject @object in objects)
				{
					if (!((Object)(object)@object == (Object)null))
					{
						list.Add((@object, @object.layer));
						@object.layer = layer;
					}
				}
				return body();
			}
			finally
			{
				foreach (var (val, layer2) in list)
				{
					if ((Object)(object)val != (Object)null)
					{
						val.layer = layer2;
					}
				}
			}
		}

		public static float[] CaptureCoverage(float originX, float originZ, int cellsW, int cellsH, float cellSize, float groundY, int layer)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			int num = SupersampleFor(cellsW, cellsH);
			return PixelBuffer.CoverageOfNonKey(RenderTopDown(originX, originZ, cellsW, cellsH, cellSize, groundY, num, 1 << layer, new Color(1f, 0f, 1f, 1f), null, null), cellsW * num, cellsH * num, num, CoverageKey, 24);
		}

		private static int SupersampleFor(int cellsW, int cellsH)
		{
			int num = 4;
			while (num > 1 && (cellsW * num > 2048 || cellsH * num > 2048))
			{
				num--;
			}
			return num;
		}

		private static byte[] RenderTopDown(float originX, float originZ, int cellsW, int cellsH, float cellSize, float groundY, int ss, int cullingMask, Color background, Action<Camera> before, Action after)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			int num = cellsW * ss;
			int num2 = cellsH * ss;
			float num3 = (float)cellsW * cellSize;
			float num4 = (float)cellsH * cellSize;
			RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 24, (RenderTextureFormat)0);
			GameObject val = new GameObject("SpellBrigadeMinimap_Snapshot");
			Camera val2 = null;
			try
			{
				val2 = val.AddComponent<Camera>();
				((Behaviour)val2).enabled = false;
				val2.orthographic = true;
				val2.orthographicSize = num4 * 0.5f;
				val2.aspect = num3 / num4;
				val2.nearClipPlane = 0.3f;
				val2.farClipPlane = 92f;
				val2.clearFlags = (CameraClearFlags)2;
				val2.backgroundColor = background;
				val2.cullingMask = cullingMask;
				val2.targetTexture = temporary;
				val.transform.position = new Vector3(originX + num3 * 0.5f, groundY + 12f, originZ + num4 * 0.5f);
				val.transform.rotation = Quaternion.Euler(90f, 0f, 0f);
				try
				{
					before?.Invoke(val2);
					val2.Render();
				}
				finally
				{
					after?.Invoke();
				}
				return ReadBack(temporary, num, num2);
			}
			finally
			{
				if ((Object)(object)val2 != (Object)null)
				{
					val2.targetTexture = null;
				}
				Object.Destroy((Object)(object)val);
				RenderTexture.ReleaseTemporary(temporary);
			}
		}

		public static PixelBuffer CaptureGameView(int width, out Matrix4x4 clipToWorld)
		{
			//IL_006d: 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)
			clipToWorld = Matrix4x4.Identity;
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return null;
			}
			float num = ((main.pixelHeight > 0) ? ((float)main.pixelWidth / (float)main.pixelHeight) : 1.7777778f);
			int num2 = Math.Max(1, (int)((float)width / num));
			RenderTexture temporary = RenderTexture.GetTemporary(width, num2, 24, (RenderTextureFormat)0);
			RenderTexture targetTexture = main.targetTexture;
			try
			{
				main.targetTexture = temporary;
				main.Render();
				if (!Matrix4x4.Invert(ToNumerics(main.worldToCameraMatrix) * ToNumerics(main.projectionMatrix), out clipToWorld))
				{
					clipToWorld = Matrix4x4.Identity;
				}
				main.targetTexture = targetTexture;
				return PixelBuffer.Downsample(ReadBack(temporary, width, num2), width, num2, 1);
			}
			finally
			{
				main.targetTexture = targetTexture;
				RenderTexture.ReleaseTemporary(temporary);
			}
		}

		private static Matrix4x4 ToNumerics(Matrix4x4 m)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			return new Matrix4x4(m.m00, m.m10, m.m20, m.m30, m.m01, m.m11, m.m21, m.m31, m.m02, m.m12, m.m22, m.m32, m.m03, m.m13, m.m23, m.m33);
		}

		private static byte[] ReadBack(RenderTexture rt, int w, int h)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			RenderTexture active = RenderTexture.active;
			Texture2D val = null;
			try
			{
				RenderTexture.active = rt;
				val = new Texture2D(w, h, (TextureFormat)4, false);
				val.ReadPixels(new Rect(0f, 0f, (float)w, (float)h), 0, 0, false);
				RenderTexture.active = active;
				Il2CppStructArray<Color32> pixels = val.GetPixels32();
				if (((Il2CppArrayBase<Color32>)(object)pixels).Length < w * h)
				{
					throw new InvalidOperationException($"expected {w * h} pixels, got {((Il2CppArrayBase<Color32>)(object)pixels).Length}");
				}
				byte[] array = new byte[w * h * 4];
				Marshal.Copy(IntPtr.Add(((Il2CppObjectBase)pixels).Pointer, 4 * IntPtr.Size), array, 0, array.Length);
				return array;
			}
			finally
			{
				RenderTexture.active = active;
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		private static void UseGameColourGrading(Camera cam)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			try
			{
				UniversalAdditionalCameraData universalAdditionalCameraData = CameraExtensions.GetUniversalAdditionalCameraData(cam);
				universalAdditionalCameraData.renderPostProcessing = true;
				Camera main = Camera.main;
				if ((Object)(object)main != (Object)null)
				{
					UniversalAdditionalCameraData universalAdditionalCameraData2 = CameraExtensions.GetUniversalAdditionalCameraData(main);
					universalAdditionalCameraData.volumeLayerMask = universalAdditionalCameraData2.volumeLayerMask;
					universalAdditionalCameraData.volumeTrigger = (((Object)(object)universalAdditionalCameraData2.volumeTrigger != (Object)null) ? universalAdditionalCameraData2.volumeTrigger : ((Component)main).transform);
					if (!gradingLogged)
					{
						gradingLogged = true;
						ManualLogSource log = Mod.Log;
						bool flag = default(bool);
						BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(64, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Game camera post-processing is ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(universalAdditionalCameraData2.renderPostProcessing ? "on" : "off");
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; using it for the level picture.");
						}
						log.LogInfo(val);
					}
				}
				CameraExtensions.UpdateVolumeStack(cam, universalAdditionalCameraData);
			}
			catch (Exception e)
			{
				LogOnce.Error("using the game's colour grading for the level picture", e);
			}
		}

		private static void DisableLensEffects(List<VolumeComponent> disabled)
		{
			try
			{
				Il2CppArrayBase<Volume> val = Object.FindObjectsOfType<Volume>();
				for (int i = 0; i < val.Length; i++)
				{
					Volume val2 = val[i];
					if ((Object)(object)val2 == (Object)null || !((Behaviour)val2).isActiveAndEnabled)
					{
						continue;
					}
					VolumeProfile val3 = (val2.HasInstantiatedProfile() ? val2.profile : val2.sharedProfile);
					if ((Object)(object)val3 == (Object)null || val3.components == null)
					{
						continue;
					}
					List<VolumeComponent> components = val3.components;
					for (int j = 0; j < components.Count; j++)
					{
						VolumeComponent val4 = components[j];
						if (!((Object)(object)val4 == (Object)null) && val4.active && IsLensEffect(val4))
						{
							val4.active = false;
							disabled.Add(val4);
						}
					}
				}
			}
			catch (Exception e)
			{
				LogOnce.Error("turning off lens effects for the level picture", e);
			}
		}

		private static bool IsLensEffect(VolumeComponent c)
		{
			if (!((Object)(object)((Il2CppObjectBase)c).TryCast<Vignette>() != (Object)null) && !((Object)(object)((Il2CppObjectBase)c).TryCast<DepthOfField>() != (Object)null) && !((Object)(object)((Il2CppObjectBase)c).TryCast<MotionBlur>() != (Object)null) && !((Object)(object)((Il2CppObjectBase)c).TryCast<ChromaticAberration>() != (Object)null) && !((Object)(object)((Il2CppObjectBase)c).TryCast<LensDistortion>() != (Object)null) && !((Object)(object)((Il2CppObjectBase)c).TryCast<PaniniProjection>() != (Object)null))
			{
				return (Object)(object)((Il2CppObjectBase)c).TryCast<FilmGrain>() != (Object)null;
			}
			return true;
		}

		private static void HideMovingThings(List<Renderer> hidden)
		{
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			HashSet<IntPtr> keep = new HashSet<IntPtr>();
			try
			{
				Il2CppArrayBase<River> val = Object.FindObjectsOfType<River>();
				for (int i = 0; i < val.Length; i++)
				{
					LineRenderer val2 = (((Object)(object)val[i] != (Object)null) ? val[i].riverRenderer : null);
					if ((Object)(object)val2 != (Object)null)
					{
						keep.Add(((Il2CppObjectBase)val2).Pointer);
					}
				}
			}
			catch (Exception e)
			{
				LogOnce.Error("finding the river for the level picture", e);
			}
			int num = 0;
			try
			{
				Il2CppArrayBase<Tornado> val3 = Object.FindObjectsOfType<Tornado>();
				for (int j = 0; j < val3.Length; j++)
				{
					if ((Object)(object)val3[j] != (Object)null)
					{
						HideUnder((Component)(object)val3[j]);
						num++;
					}
				}
			}
			catch (Exception e2)
			{
				LogOnce.Error("hiding tornadoes for the level picture", e2);
			}
			if (num > 0 || keep.Count > 0)
			{
				ManualLogSource log = Mod.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(49, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Level picture: ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" tornadoes hidden, ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(keep.Count);
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" river(s) kept.");
				}
				log.LogInfo(val4);
			}
			try
			{
				GameplayPlayerManager instance = Singleton<GameplayPlayerManager>.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					List<GameplayPlayer> alivePlayers = instance.AlivePlayers;
					if (alivePlayers != null)
					{
						for (int k = 0; k < alivePlayers.Count; k++)
						{
							HideUnder((Component)(object)alivePlayers[k]);
						}
					}
					List<PlayerGhost> playerGhosts = instance.PlayerGhosts;
					if (playerGhosts != null)
					{
						for (int l = 0; l < playerGhosts.Count; l++)
						{
							HideUnder((Component)(object)playerGhosts[l]);
						}
					}
				}
				List<Enemy> allEnemies = Enemy.AllEnemies;
				if (allEnemies != null)
				{
					for (int m = 0; m < allEnemies.Count; m++)
					{
						HideUnder((Component)(object)allEnemies[m]);
					}
				}
			}
			catch (Exception e3)
			{
				LogOnce.Error("hiding players and enemies for the level picture", e3);
			}
			HideAll<ParticleSystemRenderer>();
			HideAll<TrailRenderer>();
			HideAll<LineRenderer>();
			HideAll<VFXRenderer>();
			void Hide(Renderer r)
			{
				if (!((Object)(object)r == (Object)null) && r.enabled && !keep.Contains(((Il2CppObjectBase)r).Pointer))
				{
					r.enabled = false;
					hidden.Add(r);
				}
			}
			void HideAll<T>() where T : Renderer
			{
				try
				{
					Il2CppArrayBase<T> val5 = Object.FindObjectsOfType<T>();
					for (int n = 0; n < val5.Length; n++)
					{
						Hide((Renderer)(object)val5[n]);
					}
				}
				catch (Exception e4)
				{
					LogOnce.Error("hiding " + typeof(T).Name + " for the level picture", e4);
				}
			}
			void HideUnder(Component root)
			{
				if (!((Object)(object)root == (Object)null))
				{
					Il2CppArrayBase<Renderer> componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
					for (int n = 0; n < componentsInChildren.Length; n++)
					{
						Hide(componentsInChildren[n]);
					}
				}
			}
		}
	}
	public class MinimapBehaviour : MonoBehaviour
	{
		private const float ZoomStep = 1.25f;

		private const float SettleSeconds = 1f;

		private const float SettleFallbackSeconds = 6f;

		private const float SpawnPointRetrySeconds = 1f;

		private MinimapView view;

		private readonly WorldScanner scanner = new WorldScanner();

		private readonly NavMeshMapper mapper = new NavMeshMapper();

		private readonly MoreEventsBridge bridge = new MoreEventsBridge();

		private readonly ObjectiveDiscovery discovery = new ObjectiveDiscovery();

		private readonly List<EventMarker> markers = new List<EventMarker>();

		private IntPtr runPtr;

		private float radius;

		private float runStartedAt = -1f;

		private float groundedSince = -1f;

		private float nextSpawnPointSearch;

		private Vector3? spawnPoint;

		private bool hidden;

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

		private void Start()
		{
			radius = Mod.Settings.Radius.Value;
			try
			{
				view = new MinimapView(Mod.Settings);
				view.SetVisible(show: false);
			}
			catch (Exception e)
			{
				LogOnce.Error("building the minimap UI", e);
			}
		}

		private void LateUpdate()
		{
			if (view == null)
			{
				return;
			}
			try
			{
				Tick();
			}
			catch (Exception e)
			{
				LogOnce.Error("drawing the minimap", e);
				view.SetVisible(show: false);
			}
		}

		private void Tick()
		{
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			MinimapConfig settings = Mod.Settings;
			float unscaledTime = Time.unscaledTime;
			HandleKeys(settings);
			RunManager instance = NetworkSingleton<RunManager>.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				if (runPtr != IntPtr.Zero)
				{
					EndRun();
				}
				view.SetVisible(show: false);
				return;
			}
			if (((Il2CppObjectBase)instance).Pointer != runPtr)
			{
				StartRun(instance);
			}
			scanner.Tick(unscaledTime, settings.ShowEnemies.Value, settings.ShowObjectives.Value || settings.ShowPickups.Value, settings.ShowMapFeatures.Value);
			discovery.Tick(unscaledTime, scanner.Pois, scanner.Objectives);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(scanner.Center.X, scanner.CenterY, scanner.Center.Y);
			Vector3 point;
			if (scanner.HasCenter)
			{
				mapper.SeedNear(unscaledTime, val);
			}
			else if (TryFindSpawnPoint(unscaledTime, out point))
			{
				mapper.SeedNear(unscaledTime, point);
			}
			bool runHasStarted = instance.runHasStarted;
			if (runHasStarted && runStartedAt < 0f)
			{
				runStartedAt = unscaledTime;
			}
			if (scanner.HasCenter && mapper.IsOnGround(val))
			{
				if (groundedSince < 0f)
				{
					groundedSince = unscaledTime;
				}
			}
			else
			{
				groundedSince = -1f;
			}
			bool viewSettled = runHasStarted && ((groundedSince >= 0f && unscaledTime - groundedSince >= 1f) || unscaledTime - runStartedAt >= 6f);
			if (mapper.Tick(unscaledTime, viewSettled, val))
			{
				view.SetMap(mapper.Map);
			}
			if (!runHasStarted || !scanner.HasCenter || !settings.Enabled.Value || hidden || Time.timeScale == 0f)
			{
				view.SetVisible(show: false);
				return;
			}
			if (settings.ShowMoreEvents.Value)
			{
				bridge.Collect(markers);
			}
			else
			{
				markers.Clear();
			}
			view.SetVisible(show: true);
			view.Render(scanner, markers, discovery, settings.RotateWithCamera.Value ? CameraYaw() : 0f, radius);
		}

		private bool TryFindSpawnPoint(float now, out Vector3 point)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (!spawnPoint.HasValue && now >= nextSpawnPointSearch)
			{
				nextSpawnPointSearch = now + 1f;
				ObjectiveSpawnPoint val = Object.FindObjectOfType<ObjectiveSpawnPoint>();
				if ((Object)(object)val != (Object)null)
				{
					spawnPoint = ((Component)val).transform.position;
				}
			}
			point = spawnPoint.GetValueOrDefault();
			return spawnPoint.HasValue;
		}

		private void StartRun(RunManager rm)
		{
			EndRun();
			runPtr = ((Il2CppObjectBase)rm).Pointer;
			scanner.ResetRun(rm);
			DebugImages.BeginRun();
			runStartedAt = (groundedSince = -1f);
			spawnPoint = null;
			nextSpawnPointSearch = 0f;
			MinimapConfig settings = Mod.Settings;
			radius = Mathf.Clamp(settings.Radius.Value, settings.MinRadius.Value, settings.MaxRadius.Value);
		}

		private void EndRun()
		{
			runPtr = IntPtr.Zero;
			view.SetMap(null);
			mapper.Reset();
			discovery.Reset();
		}

		private void HandleKeys(MinimapConfig cfg)
		{
			Keyboard current = Keyboard.current;
			if (current != null)
			{
				if (Pressed(current, cfg.ToggleKey.Value))
				{
					hidden = !hidden;
				}
				if (Pressed(current, cfg.ZoomInKey.Value))
				{
					radius = Mathf.Max(cfg.MinRadius.Value, radius / 1.25f);
				}
				if (Pressed(current, cfg.ZoomOutKey.Value))
				{
					radius = Mathf.Min(cfg.MaxRadius.Value, radius * 1.25f);
				}
			}
		}

		private static bool Pressed(Keyboard kb, string keyName)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(keyName) || !Enum.TryParse<Key>(keyName, ignoreCase: true, out Key result) || (int)result == 0)
			{
				return false;
			}
			KeyControl val = kb[result];
			if (val != null)
			{
				return ((ButtonControl)val).wasPressedThisFrame;
			}
			return false;
		}

		private static float CameraYaw()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!((Object)(object)main != (Object)null))
			{
				return 0f;
			}
			return ((Component)main).transform.eulerAngles.y;
		}
	}
	internal enum ScreenCorner
	{
		TopLeft,
		TopRight,
		BottomLeft,
		BottomRight
	}
	internal enum MapShape
	{
		Round,
		Square
	}
	internal enum MapStyle
	{
		Pixelated,
		Flat
	}
	internal sealed class MinimapConfig
	{
		public readonly ConfigEntry<bool> Enabled;

		public readonly ConfigEntry<string> ToggleKey;

		public readonly ConfigEntry<string> ZoomInKey;

		public readonly ConfigEntry<string> ZoomOutKey;

		public readonly ConfigEntry<ScreenCorner> Corner;

		public readonly ConfigEntry<MapShape> Shape;

		public readonly ConfigEntry<MapStyle> Style;

		public readonly ConfigEntry<bool> HighlightObstacles;

		public readonly ConfigEntry<bool> TrimOutsideArena;

		public readonly ConfigEntry<bool> PaintFromGameView;

		public readonly ConfigEntry<bool> LiftDarkGround;

		public readonly ConfigEntry<string> ObstacleKeywords;

		public readonly ConfigEntry<string> TintKeywords;

		public readonly ConfigEntry<float> Size;

		public readonly ConfigEntry<float> Margin;

		public readonly ConfigEntry<float> BottomOffset;

		public readonly ConfigEntry<float> Opacity;

		public readonly ConfigEntry<float> Radius;

		public readonly ConfigEntry<float> MinRadius;

		public readonly ConfigEntry<float> MaxRadius;

		public readonly ConfigEntry<float> BigEnemyHealth;

		public readonly ConfigEntry<float> HeavyEnemyHealth;

		public readonly ConfigEntry<bool> RotateWithCamera;

		public readonly ConfigEntry<bool> AvoidGameHud;

		public readonly ConfigEntry<bool> ShowEnemies;

		public readonly ConfigEntry<bool> ShowObjectives;

		public readonly ConfigEntry<bool> ShowPickups;

		public readonly ConfigEntry<bool> ShowTeammates;

		public readonly ConfigEntry<bool> ShowMoreEvents;

		public readonly ConfigEntry<bool> ShowMapFeatures;

		public readonly ConfigEntry<bool> HideUndiscoveredObjectives;

		public readonly ConfigEntry<bool> SaveDebugImages;

		public MinimapConfig(ConfigFile f)
		{
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Expected O, but got Unknown
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Expected O, but got Unknown
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Expected O, but got Unknown
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Expected O, but got Unknown
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Expected O, but got Unknown
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Expected O, but got Unknown
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Expected O, but got Unknown
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Expected O, but got Unknown
			Enabled = f.Bind<bool>("General", "Enabled", true, "Show the minimap during runs.");
			ToggleKey = f.Bind<string>("General", "ToggleKey", "M", "Key that hides or shows the minimap (Unity Input System key name, e.g. M, Tab, F6).");
			ZoomInKey = f.Bind<string>("General", "ZoomInKey", "Equals", "Key that zooms in.");
			ZoomOutKey = f.Bind<string>("General", "ZoomOutKey", "Minus", "Key that zooms out.");
			Corner = f.Bind<ScreenCorner>("Layout", "Corner", ScreenCorner.BottomRight, "Screen corner for the minimap.");
			Shape = f.Bind<MapShape>("Layout", "Shape", MapShape.Round, "Round or square minimap.");
			Style = f.Bind<MapStyle>("Look", "Style", MapStyle.Pixelated, "Pixelated: a pixel-art picture of the level itself, taken at the start of each run. Flat: plain colours for ground and obstacles.");
			HighlightObstacles = f.Bind<bool>("Look", "HighlightObstacles", true, "Pixelated style: draw a rim around obstacles (rocks, trees, walls) so they stand out.");
			TrimOutsideArena = f.Bind<bool>("Look", "TrimOutsideArena", true, "Hide the ground beyond the arena's walls (where enemies come from). Turn off if a map loses parts it shouldn't.");
			PaintFromGameView = f.Bind<bool>("Look", "PaintFromGameView", false, "Experimental: recolour the minimap every few seconds with what the game camera shows. Off by default: the map keeps changing while you play.");
			ObstacleKeywords = f.Bind<string>("Look", "ObstacleKeywords", "rock,boulder,border,wall,cliff,pillar,stone,volcano,vulcano", "Scenery at least 1 unit tall whose material, mesh or object name contains one of these words is drawn as an obstacle (things you can't walk through), even if the game keeps its collider elsewhere. Pebbles, grass, bushes, flowers and trees never count. Comma-separated.");
			LiftDarkGround = f.Bind<bool>("Look", "LiftDarkGround", true, "Pixelated style: brighten the darkest patches of ground toward the map's lighter ground, so only obstacles are near-black. Helps on the fire and astral maps.");
			TintKeywords = f.Bind<string>("Look", "TintKeywords", "deathbush:962434", "Pixelated style: scenery whose material, mesh or object name contains the word is coloured on the map, as word:RRGGBB. Comma-separated (e.g. deathbush:962434).");
			if (TintKeywords.Value == "deathbush:C8343C")
			{
				TintKeywords.Value = "deathbush:962434";
			}
			Size = f.Bind<float>("Layout", "Size", 220f, new ConfigDescription("Side length in pixels at 1080p.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(100f, 600f), Array.Empty<object>()));
			Margin = f.Bind<float>("Layout", "Margin", 16f, new ConfigDescription("Gap from the screen edges in pixels at 1080p.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
			BottomOffset = f.Bind<float>("Layout", "BottomOffset", 30f, new ConfigDescription("Extra gap below the minimap in a bottom corner, so it sits above the game's text bar (pixels at 1080p).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 400f), Array.Empty<object>()));
			AvoidGameHud = f.Bind<bool>("Layout", "AvoidGameHud", true, "Move the minimap out of the way of the game's HUD in its corner (collected artifacts, the revive counter, other mods' panels), and back when they're gone.");
			Opacity = f.Bind<float>("Layout", "Opacity", 0.85f, new ConfigDescription("Opacity of the whole minimap.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 1f), Array.Empty<object>()));
			Radius = f.Bind<float>("View", "Radius", 40f, new ConfigDescription("World units shown from the center to the edge when a run starts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 500f), Array.Empty<object>()));
			MinRadius = f.Bind<float>("View", "MinRadius", 15f, new ConfigDescription("Closest zoom (world units).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 500f), Array.Empty<object>()));
			MaxRadius = f.Bind<float>("View", "MaxRadius", 120f, new ConfigDescription("Farthest zoom (world units).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 1000f), Array.Empty<object>()));
			RotateWithCamera = f.Bind<bool>("View", "RotateWithCamera", true, "Turn the map so up on the minimap is up on screen. Off = world-fixed.");
			ShowEnemies = f.Bind<bool>("Layers", "ShowEnemies", true, "Enemies by rank: red circles for the swarm, orange triangles for bigger ones, pink squares for heavy ones, purple stars for mini-bosses (elites, the Hydra's healers, the Hoarder); bosses get their own icon.");
			BigEnemyHealth = f.Bind<float>("Layers", "BigEnemyHealth", 3f, new ConfigDescription("An enemy is drawn as a bigger (orange) one when its base health is at least this many times that of the swarm (the weakest common enemy).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1.5f, 50f), Array.Empty<object>()));
			HeavyEnemyHealth = f.Bind<float>("Layers", "HeavyEnemyHealth", 8f, new ConfigDescription("An enemy is drawn as a heavy one (pink square) when its base health is at least this many times that of the swarm. Should be more than BigEnemyHealth.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 100f), Array.Empty<object>()));
			ShowObjectives = f.Bind<bool>("Layers", "ShowObjectives", true, "Objectives, the boss, downed teammates and danger pings.");
			ShowPickups = f.Bind<bool>("Layers", "ShowPickups", true, "Artifact, health and magnet pickups the game points at.");
			ShowTeammates = f.Bind<bool>("Layers", "ShowTeammates", true, "Other players.");
			ShowMoreEvents = f.Bind<bool>("Layers", "ShowMoreEvents", true, "MoreEvents targets and zones (only when MoreEvents is installed).");
			ShowMapFeatures = f.Bind<bool>("Layers", "ShowMapFeatures", true, "Geysers on the ice map (yellow bursts), tornadoes on the fire map (following them as they move) and teleport portals (bright when open).");
			HideUndiscoveredObjectives = f.Bind<bool>("Layers", "HideUndiscoveredObjectives", true, "Only show an objective, each of its pieces (every mushroom, object to push, llama, statue and hunt target on its own), its zone or pen, and each pickup (artifacts, magnets, potions), once someone in the party has had it on screen, or once the game points at it from the edge of the screen. Discoveries are shared with other players who run this mod, through the host.");
			SaveDebugImages = f.Bind<bool>("Debug", "SaveDebugImages", false, "Save the level picture, the game-view colour sample and the finished minimap as PNGs in BepInEx/minimap-debug each run.");
		}
	}
	internal sealed class MinimapView
	{
		private const int DotTextureSize = 192;

		private const float DotOutline = 1.2f;

		private static readonly float[] RankRadius = new float[4] { 1.85f, 4f, 3.9f, 5.6f };

		private static readonly Rgba[] RankColor = new Rgba[4]
		{
			new Rgba(235, 64, 52),
			new Rgba(byte.MaxValue, 150, 40),
			new Rgba(240, 78, 168),
			new Rgba(180, 90, byte.MaxValue)
		};

		private const float PinnedEnemySize = 18f;

		private const float BossSize = 26f;

		private static readonly Rgba EnemyOutline = new Rgba(20, 20, 22, 235);

		private const float SquareBorder = 2f;

		private static readonly Color FrameColor = new Color(0.85f, 0.88f, 0.95f, 0.9f);

		private static readonly Color Background = new Color(0.09f, 0.09f, 0.1f, 0.92f);

		private static readonly Color BadgeColor = new Color(0.08f, 0.08f, 0.09f, 0.95f);

		private static readonly Color Cream = new Color(0.99215686f, 0.972549f, 0.80784315f, 1f);

		private static readonly Color HealthColor = new Color(0.95f, 0.25f, 0.3f, 1f);

		private static readonly Color ObjectiveColor = new Color(1f, 0.85f, 0.3f, 1f);

		private static readonly Color BossColor = new Color(0.8f, 0.2f, 1f, 1f);

		private static readonly Color DownedColor = new Color(1f, 0.35f, 0.35f, 1f);

		private static readonly Color DangerColor = new Color(1f, 0.3f, 0.2f, 1f);

		private static readonly Color PickupColor = new Color(0.5f, 1f, 0.6f, 1f);

		private static readonly Color PortalOpen = new Color(0.62f, 0.99f, 0.98f, 1f);

		private static readonly Color PortalClosed = new Color(0.62f, 0.99f, 0.98f, 0.35f);

		private const float GeyserSize = 16f;

		private const float SpentGeyserSize = 14f;

		private const float EruptingGeyserSize = 19f;

		private const float PortalSize = 18f;

		private const float TornadoSize = 18f;

		private readonly MinimapConfig cfg;

		private readonly GameObject root;

		private readonly RectTransform frame;

		private readonly RectTransform panel;

		private readonly RectTransform mapRoot;

		private readonly Image frameImg;

		private readonly Image panelImg;

		private readonly Image bezel;

		private readonly RectMask2D squareMask;

		private readonly Mask roundMask;

		private readonly CanvasGroup group;

		private readonly RawImage layout;

		private readonly IconPool zones;

		private readonly IconPool icons;

		private readonly Image you;

		private readonly PixelBuffer dotPixels = new PixelBuffer(192, 192);

		private readonly List<(float x, float y, int rank)> dotSpots = new List<(float, float, int)>();

		private readonly Texture2D dotTexture;

		private readonly Sprite disc;

		private readonly Sprite ring;

		private readonly Sprite arrow;

		private readonly Sprite diamond;

		private readonly Sprite roundShape;

		private readonly Sprite badgeRing;

		private readonly Sprite burst;

		private readonly Sprite burstErupting;

		private readonly Sprite burstSpent;

		private readonly Sprite portal;

		private readonly Sprite tornado;

		private readonly Sprite boss;

		private readonly Sprite ghost;

		private readonly Sprite[] pieceSprites;

		private readonly Sprite crosshair;

		private readonly Sprite[] enemyMarks;

		private readonly Dictionary<string, Sprite> counterSprites = new Dictionary<string, Sprite>();

		private readonly RectTransform counterRoot;

		private readonly List<TextMeshProUGUI> counterTexts = new List<TextMeshProUGUI>();

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

		private readonly List<float> counterWidth = new List<float>();

		private readonly Dictionary<int, Sprite> pills = new Dictionary<int, Sprite>();

		private bool gameFontBroken;

		private const float CounterHeight = 18f;

		private const float CounterFontSize = 15f;

		private const float CounterIcon = 16f;

		private static readonly Color CounterPillColor = new Color(8f / 85f, 8f / 85f, 0.101960786f, 0.92f);

		private static readonly Color CounterTextColor = new Color(0.99215686f, 0.972549f, 0.80784315f, 1f);

		private readonly Dictionary<IntPtr, Vector2> spriteAspect = new Dictionary<IntPtr, Vector2>();

		private const float PieceSize = 15f;

		private const float CrosshairSize = 26f;

		private const float GuideDotSize = 3f;

		private const float GuideDotSpacing = 7f;

		private const float PinnedPieceSize = 18f;

		private const float GameIconSize = 18f;

		private const float ObjectiveIconSize = 22f;

		private const float ZoneIconSize = 18f;

		private const int CounterScale = 2;

		private const int CounterPadLeft = 6;

		private static readonly Color GuideColor = new Color(0.99f, 0.97f, 0.81f, 0.55f);

		private static readonly Color DonePiece = new Color(1f, 1f, 1f, 0.45f);

		private static readonly Rgba CounterText = new Rgba(253, 248, 206);

		private static readonly Rgba CounterPill = new Rgba(24, 24, 26, 235);

		private const float GhostSize = 16f;

		private const float PillarSize = 18f;

		private static readonly Color ObjectiveBlue = new Color(0.36f, 0.62f, 1f, 1f);

		private static readonly Color PenGreen = new Color(0.47f, 0.86f, 0.55f, 1f);

		private static readonly Color PushYellow = new Color(1f, 0.82f, 0.25f, 1f);

		private static readonly Color HuntGold = new Color(1f, 0.76f, 0.18f, 1f);

		private static readonly Color SacrificeRed = new Color(0.96f, 0.3f, 0.28f, 1f);

		private const float ZoneRingAlpha = 0.9f;

		private const float ZoneFillAlpha = 0.15f;

		private const float DoneAlpha = 0.45f;

		private static readonly Color PillarIdle = ObjectiveBlue;

		private static readonly Color PillarCorrect = new Color(0.36f, 0.95f, 0.45f, 1f);

		private static readonly Color PillarWrong = new Color(1f, 0.32f, 0.3f, 1f);

		private BakedMap map;

		private bool visible = true;

		private bool dotsEmpty;

		private bool round;

		private float panelInset = 2f;

		private float lastSize = -1f;

		private float lastMargin = -1f;

		private float lastBottomOffset = -1f;

		private float lastLift = -1f;

		private float lift;

		private readonly HudAvoider hud = new HudAvoider();

		private readonly Canvas canvas;

		private const float HudGap = 8f;

		private const float MaxHudMoveShare = 0.45f;

		private ScreenCorner lastCorner = (ScreenCorner)(-1);

		private MapShape lastShape = (MapShape)(-1);

		public MinimapView(MinimapConfig cfg)
		{
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Expected O, but got Unknown
			//IL_035e: 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_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0559: Unknown result type (might be due to invalid IL or missing references)
			this.cfg = cfg;
			disc = SpriteFactory.ToSprite(ShapeSprites.Disc(32, 0.12f), (FilterMode)1);
			ring = SpriteFactory.ToSprite(ShapeSprites.Ring(128, 0.03f), (FilterMode)1);
			arrow = SpriteFactory.ToSprite(ShapeSprites.Arrow(32), (FilterMode)1);
			diamond = SpriteFactory.ToSprite(ShapeSprites.Diamond(32, 0.1f), (FilterMode)1);
			roundShape = SpriteFactory.ToSprite(ShapeSprites.Disc(256, 0f), (FilterMode)1);
			badgeRing = SpriteFactory.ToSprite(ShapeSprites.Ring(64, 0.12f), (FilterMode)1);
			burst = SpriteFactory.ToSprite(ShapeSprites.Burst(48), (FilterMode)1);
			burstErupting = SpriteFactory.ToSprite(ShapeSprites.Burst(48, new Rgba(byte.MaxValue, 140, 30), new Rgba(214, 80, 12)), (FilterMode)1);
			burstSpent = SpriteFactory.ToSprite(ShapeSprites.Burst(48, new Rgba(150, 152, 158), new Rgba(112, 114, 120)), (FilterMode)1);
			portal = SpriteFactory.ToSprite(ShapeSprites.Portal(48), (FilterMode)1);
			tornado = SpriteFactory.ToSprite(ShapeSprites.Tornado(48), (FilterMode)1);
			boss = SpriteFactory.ToSprite(ShapeSprites.BossSkull(64, new Rgba(222, 58, 58)), (FilterMode)1);
			ghost = SpriteFactory.ToSprite(ShapeSprites.Ghost(48), (FilterMode)1);
			crosshair = SpriteFactory.ToSprite(ShapeSprites.Crosshair(64), (FilterMode)1);
			pieceSprites = (Sprite[])(object)new Sprite[5]
			{
				SpriteFactory.ToSprite(ShapeSprites.Mushroom(48), (FilterMode)1),
				SpriteFactory.ToSprite(ShapeSprites.Crate(48), (FilterMode)1),
				SpriteFactory.ToSprite(ShapeSprites.Paw(48), (FilterMode)1),
				SpriteFactory.ToSprite(ShapeSprites.Statue(48), (FilterMode)1),
				crosshair
			};
			enemyMarks = (Sprite[])(object)new Sprite[4]
			{
				SpriteFactory.ToSprite(ShapeSprites.EnemyMark(48, EnemyShape.Circle), (FilterMode)1),
				SpriteFactory.ToSprite(ShapeSprites.EnemyMark(48, EnemyShape.Triangle), (FilterMode)1),
				SpriteFactory.ToSprite(ShapeSprites.EnemyMark(48, EnemyShape.Square), (FilterMode)1),
				SpriteFactory.ToSprite(ShapeSprites.EnemyMark(48, EnemyShape.Star), (FilterMode)1)
			};
			root = new GameObject("SpellBrigadeMinimap");
			Object.DontDestroyOnLoad((Object)(object)root);
			canvas = root.AddComponent<Canvas>();
			canvas.renderMode = (RenderMode)0;
			canvas.sortingOrder = 300;
			CanvasScaler obj = root.AddComponent<CanvasScaler>();
			obj.uiScaleMode = (ScaleMode)1;
			obj.referenceResolution = new Vector2(1920f, 1080f);
			obj.matchWidthOrHeight = 1f;
			frameImg = UiBuilder.NewImage("Frame", root.transform);
			((Graphic)frameImg).color = FrameColor;
			frame = ((Graphic)frameImg).rectTransform;
			group = ((Component)frame).gameObject.AddComponent<CanvasGroup>();
			group.blocksRaycasts = false;
			group.interactable = false;
			panelImg = UiBuilder.NewImage("Panel", (Transform)(object)frame);
			((Graphic)panelImg).color = Background;
			panel = ((Graphic)panelImg).rectTransform;
			UiBuilder.Stretch(panel, 2f);
			squareMask = ((Component)panel).gameObject.AddComponent<RectMask2D>();
			roundMask = ((Component)panel).gameObject.AddComponent<Mask>();
			roundMask.showMaskGraphic = true;
			mapRoot = UiBuilder.NewRect("MapRoot", (Transform)(object)panel);
			layout = UiBuilder.NewRawImage("Layout", (Transform)(object)mapRoot);
			((Behaviour)layout).enabled = false;
			zones = new IconPool(UiBuilder.NewRect("Zones", (Transform)(object)panel));
			RawImage obj2 = UiBuilder.NewRawImage("Enemies", (Transform)(object)panel);
			UiBuilder.Stretch(((Graphic)obj2).rectTransform, 0f);
			dotTexture = SpriteFactory.ToTexture(dotPixels, (FilterMode)1, keepReadable: true);
			obj2.texture = (Texture)(object)dotTexture;
			icons = new IconPool(UiBuilder.NewRect("Icons", (Transform)(object)panel));
			counterRoot = UiBuilder.NewRect("Counters", (Transform)(object)panel);
			you = UiBuilder.NewImage("You", (Transform)(object)panel);
			you.sprite = arrow;
			((Graphic)you).rectTransform.sizeDelta = new Vector2(18f, 18f);
			bezel = UiBuilder.NewImage("Bezel", (Transform)(object)frame);
			bezel.sprite = SpriteFactory.ToSprite(ShapeSprites.Bezel(384), (FilterMode)1);
			UiBuilder.Stretch(((Graphic)bezel).rectTransform, 0f);
			ApplyLayout();
		}

		public void SetVisible(bool show)
		{
			if (show != visible)
			{
				visible = show;
				root.SetActive(show);
			}
		}

		public void SetMap(BakedMap baked)
		{
			map = baked;
			layout.texture = (Texture)(object)baked?.Texture;
			((Behaviour)layout).enabled = baked != null;
		}

		public void Render(WorldScanner s, List<EventMarker> markers, ObjectiveDiscovery discovery, float yaw, float radius)
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: 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_0444: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: 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_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: 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_0656: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06db: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0817: Unknown result type (might be due to invalid IL or missing references)
			//IL_081c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0820: Unknown result type (might be due to invalid IL or missing references)
			//IL_0827: Unknown result type (might be due to invalid IL or missing references)
			//IL_0878: Unknown result type (might be due to invalid IL or missing references)
			//IL_0862: Unknown result type (might be due to invalid IL or missing references)
			//IL_0779: Unknown result type (might be due to invalid IL or missing references)
			//IL_095a: Unknown result type (might be due to invalid IL or missing references)
			lift = (cfg.AvoidGameHud.Value ? hud.Tick(Time.unscaledTime, Time.unscaledDeltaTime, HomeScreenBox(out var bottom), bottom, canvas, Mathf.Max(0.01f, canvas.scaleFactor), 8f, 486f) : 0f);
			ApplyLayout();
			group.alpha = cfg.Opacity.Value;
			float num = (cfg.Size.Value - 2f * panelInset) * 0.5f;
			MapView view = new MapView(s.Center, yaw, radius, num);
			float scale = view.Scale;
			((Transform)mapRoot).localEulerAngles = new Vector3(0f, 0f, yaw);
			if (map != null)
			{
				RectTransform rectTransform = ((Graphic)layout).rectTransform;
				rectTransform.sizeDelta = new Vector2(map.WorldWidth * scale, map.WorldHeight * scale);
				float num2 = map.OriginX + map.WorldWidth * 0.5f - s.Center.X;
				float num3 = map.OriginZ + map.WorldHeight * 0.5f - s.Center.Y;
				rectTransform.anchoredPosition = new Vector2(num2 * scale, num3 * scale);
			}
			zones.Begin();
			if (cfg.ShowMoreEvents.Value)
			{
				foreach (EventMarker marker in markers)
				{
					if (marker.Zone && marker.Radius > 0f)
					{
						zones.Place(ring, marker.Color, ToUnity(MapMath.WorldToPanel(in view, marker.Pos)), marker.Radius * 2f * scale, 0f);
					}
				}
			}
			if (cfg.ShowObjectives.Value)
			{
				foreach (ObjectiveZone zone in s.Objectives.Zones)
				{
					ObjectiveZone z = zone;
					if (!cfg.HideUndiscoveredObjectives.Value || discovery.IsKnown(z.Key))
					{
						Vector2 position = ToUnity(MapMath.WorldToPanel(in view, z.Center));
						Color c = ZoneTint(in z);
						zones.Place(roundShape, WithAlpha(c, 0.15f), position, z.Radius * 2f * scale, 0f);
						zones.Place(ring, WithAlpha(c, 0.9f), position, z.Radius * 2f * scale, 0f);
					}
				}
			}
			if (cfg.ShowMapFeatures.Value)
			{
				foreach (GeyserDot geyser in s.Geysers)
				{
					if (geyser.State != GeyserState.Erupting)
					{
						DrawFeature(zones, (geyser.State == GeyserState.Ready) ? burst : burstSpent, Color.white, geyser.Pos, in view, (geyser.State == GeyserState.Ready) ? 16f : 14f);
					}
				}
			}
			zones.End();
			DrawEnemies(s, in view);
			icons.Begin();
			if (cfg.ShowMapFeatures.Value)
			{
				foreach (FeatureDot feature in s.Features)
				{
					if (feature.Kind == FeatureKind.Portal)
					{
						DrawFeature(icons, portal, feature.Active ? PortalOpen : PortalClosed, feature.Pos, in view, 18f);
					}
				}
			}
			if (cfg.ShowMapFeatures.Value)
			{
				foreach (Vector2 tornado in s.Tornadoes)
				{
					DrawFeature(icons, this.tornado, Color.white, tornado, in view, 18f);
				}
				float unscaledTime = Time.unscaledTime;
				foreach (GeyserDot geyser2 in s.Geysers)
				{
					if (geyser2.State == GeyserState.Erupting)
					{
						DrawFeature(icons, burstErupting, Color.white, geyser2.Pos, in view, 19f, new Vector2(Mathf.Sin(unscaledTime * 53f) * 1.3f, Mathf.Cos(unscaledTime * 61f) * 1.1f), Mathf.Sin(unscaledTime * 41f) * 7f);
					}
				}
			}
			if (cfg.ShowObjectives.Value)
			{
				DrawPieces(s.Objectives, in view, discovery);
				DrawZoneIcons(s.Objectives, in view, discovery);
			}
			foreach (Poi poi in s.Pois)
			{
				if (poi.Kind != PoiKind.Boss || s.Bosses.Count <= 0 || !cfg.ShowEnemies.Value)
				{
					DrawPoi(poi, in view, discovery, s.Objectives);
				}
			}
			if (cfg.ShowEnemies.Value)
			{
				foreach (Vector2 boss in s.Bosses)
				{
					DrawPoint(this.boss, Color.white, MapMath.WorldToPanel(in view, boss), 26f, num, clamp: true);
				}
			}
			if (cfg.ShowEnemies.Value)
			{
				foreach (PointedEnemy pointedEnemy in s.PointedEnemies)
				{
					if (!((Object)(object)pointedEnemy.Target == (Object)null))
					{
						Vector3 position2 = pointedEnemy.Target.position;
						Vector2 p = MapMath.WorldToPanel(in view, new Vector2(position2.x, position2.z));
						if (!(round ? MapMath.IsInsideCircle(p, num) : MapMath.IsInside(p, num)))
						{
							int num4 = Mathf.Min((int)pointedEnemy.Rank, RankColor.Length - 1);
							Rgba rgba = RankColor[num4];
							DrawPoint(enemyMarks[(int)EnemyMarks.ShapeOf(pointedEnemy.Rank)], new Color((float)(int)rgba.R / 255f, (float)(int)rgba.G / 255f, (float)(int)rgba.B / 255f, 1f), p, 18f, num, clamp: true);
						}
					}
				}
			}
			if (cfg.ShowObjectives.Value)
			{
				foreach (Piece huntTarget in s.Objectives.HuntTargets)
				{
					if (!((Object)(object)huntTarget.Target == (Object)null) && (!cfg.HideUndiscoveredObjectives.Value || discovery.IsKnown(huntTarget.Key)))
					{
						Vector3 position3 = huntTarget.Target.position;
						Vector2 p2 = MapMath.WorldToPanel(in view, new Vector2(position3.x, position3.z));
						Sprite val = s.Objectives.PieceIcon(huntTarget.Target, PieceKind.Hunt);
						if ((Object)(object)val != (Object)null)
						{
							DrawIcon(p2, 22f, num, HuntGold, val, pin: true);
						}
						else
						{
							DrawPoint(crosshair, Color.white, p2, 26f, num, clamp: true);
						}
					}
				}
			}
			if (cfg.ShowMoreEvents.Value)
			{
				foreach (EventMarker marker2 in markers)
				{
					if (!marker2.Zone)
					{
						DrawPoint(diamond, marker2.Color, MapMath.WorldToPanel(in view, marker2.Pos), 16f, num, clamp: true);
					}
				}
			}
			if (cfg.ShowTeammates.Value)
			{
				foreach (PlayerDot player in s.Players)
				{
					DrawPoint(player.Ghost ? ghost : disc, player.Color, MapMath.WorldToPanel(in view, player.Pos), player.Ghost ? 16f : 13f, num, clamp: true);
				}
			}
			if (cfg.ShowObjectives.Value)
			{
				DrawCounters(s.Objectives, num);
			}
			icons.End();
			((Transform)((Graphic)you).rectTransform).localEulerAngles = new Vector3(0f, 0f, MapMath.HeadingToPanelAngle(s.Facing, yaw));
		}

		private void DrawEnemies(WorldScanner s, in MapView view)
		{
			bool flag = false;
			dotPixels.Clear();
			if (cfg.ShowEnemies.Value)
			{
				float num = 192f / (2f * view.HalfSize);
				dotSpots.Clear();
				foreach (EnemyDot enemy in s.Enemies)
				{
					Vector2 vector = MapMath.WorldToPanel(in view, enemy.Pos);
					if (MapMath.IsInside(vector, view.HalfSize))
					{
						flag = true;
						float num2 = (vector.X + view.HalfSize) * num;
						float num3 = (vector.Y + view.HalfSize) * num;
						int num4 = Mathf.Min((int)enemy.Rank, RankRadius.Length - 1);
						dotSpots.Add((num2, num3, num4));
						EnemyShape enemyShape = EnemyMarks.ShapeOf((EnemyRank)num4);
						if (enemyShape == EnemyShape.Circle)
						{
							dotPixels.FillCircle(num2, num3, RankRadius[num4] + 1.2f, EnemyOutline);
						}
						else
						{
							EnemyMarks.Fill(dotPixels, enemyShape, num2, num3, RankRadius[num4], 1.2f, EnemyOutline);
						}
					}
				}
				for (int i = 0; i < RankRadius.Length; i++)
				{
					EnemyShape enemyShape2 = EnemyMarks.ShapeOf((EnemyRank)i);
					foreach (var dotSpot in dotSpots)
					{
						var (cx, cy, _) = dotSpot;
						if (dotSpot.rank == i)
						{
							if (enemyShape2 == EnemyShape.Circle)
							{
								dotPixels.FillCircle(cx, cy, RankRadius[i], RankColor[i]);
							}
							else
							{
								EnemyMarks.Fill(dotPixels, enemyShape2, cx, cy, RankRadius[i], 0f, RankColor[i]);
							}
						}
					}
				}
			}
			if (flag || !dotsEmpty)
			{
				SpriteFactory.Upload(dotTexture, dotPixels, keepReadable: true);
				dotsEmpty = !flag;
			}
		}

		private void DrawPoi(Poi poi, in MapView view, ObjectiveDiscovery discovery, ObjectivePieces o)
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00ba: 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_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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Invalid comparison between Unknown and I4
			//IL_00e1: 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_00d1: Invalid comparison between Unknown and I4
			//IL_00e6: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: 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_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: 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)
			if ((Object)(object)poi.Target == (Object)null)
			{
				return;
			}
			bool flag = poi.Kind == PoiKind.Pickup || poi.Kind == PoiKind.Health;
			if (flag ? (!cfg.ShowPickups.Value) : (!cfg.ShowObjectives.Value))
			{
				return;
			}
			bool flag2 = discovery.IsKnown(poi.Key);
			if ((poi.Kind == PoiKind.Objective || flag) && cfg.HideUndiscoveredObjectives.Value && !flag2)
			{
				return;
			}
			Vector3 position = poi.Target.position;
			Vector2 vector = MapMath.WorldToPanel(in view, new Vector2(position.x, position.z));
			if ((Object)(object)poi.Pillar != (Object)null)
			{
				Color color = PillarIdle;
				try
				{
					OrderObjectiveInteractableState state = poi.Pillar.state;
					color = (((int)state == 1) ? PillarCorrect : (((int)state == 2) ? PillarWrong : PillarIdle));
				}
				catch
				{
				}
				DrawIcon(vector, 18f, view.HalfSize, color, ((Object)(object)poi.WhiteSprite != (Object)null) ? poi.WhiteSprite : GameIcons.White("ui_ping_objective_order"), poi.Shown);
				return;
			}
			if (poi.Kind == PoiKind.Objective)
			{
				if (CoveredByZone(o, position, discovery))
				{
					return;
				}
				string text = GameIcons.NameOf(poi.Sprite);
				bool flag3 = text == "ui_ping_objective_petrifiedenemies";
				Sprite val = (flag3 ? GameIcons.Statue() : poi.WhiteSprite);
				if ((Object)(object)val != (Object)null)
				{
					DrawIcon(vector, 22f, view.HalfSize, flag3 ? Color.white : ObjectiveTint(text, o), val, poi.ClampToEdge);
					return;
				}
			}
			if (flag)
			{
				if (round ? MapMath.IsInsideCircle(vector, view.HalfSize) : MapMath.IsInside(vector, view.HalfSize))
				{
					bool num = poi.Kind == PoiKind.Health;
					float num2 = (num ? 24f : 18f);
					Vector2 position2 = ToUnity(vector);
					icons.Place(disc, BadgeColor, position2, num2, 0f);
					if (num)
					{
						icons.Place(badgeRing, Cream, position2, num2, 0f);
					}
					if ((Object)(object)poi.Sprite != (Object)null)
					{
						icons.Place(poi.Sprite, poi.Color, position2, num2 * 0.7f, 0f);
					}
					else
					{
						icons.Place(disc, KindColor(poi.Kind), position2, num2 * 0.5f, 0f);
					}
				}
			}
			else
			{
				Sprite sprite = (((Object)(object)poi.Sprite != (Object)null) ? poi.Sprite : diamond);
				Color color2 = (((Object)(object)poi.Sprite != (Object)null) ? poi.Color : KindColor(poi.Kind));
				float size = ((poi.Kind == PoiKind.Boss) ? 24f : 20f);
				DrawPoint(sprite, color2, vector, size, view.HalfSize, poi.ClampToEdge);
			}
		}

		private void DrawPieces(ObjectivePieces o, in MapView view, ObjectiveDiscovery discovery)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_017c: 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_01a6: 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_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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)
			bool value = cfg.HideUndiscoveredObjectives.Value;
			foreach (Piece piece in o.Pieces)
			{
				if ((Object)(object)piece.Target == (Object)null || (value && !discovery.IsKnown(piece.Key)))
				{
					continue;
				}
				Vector3 position = piece.Target.position;
				Vector2 vector = MapMath.WorldToPanel(in view, new Vector2(position.x, position.z));
				if (piece.HasGoal && !piece.Done && (!value || discovery.IsKnown(piece.GoalKey)))
				{
					Vector2 value2 = MapMath.WorldToPanel(in view, piece.Goal);
					int num = (int)(Vector2.Distance(vector, value2) / 7f);
					for (int i = 1; i < num; i++)
					{
						Vector2 v = Vector2.Lerp(vector, value2, (float)i / (float)num);
						if (round ? MapMath.IsInsideCircle(v, view.HalfSize) : MapMath.IsInside(v, view.HalfSize))
						{
							icons.Place(disc, GuideColor, ToUnity(v), 3f, 0f);
						}
					}
				}
				bool flag = o.IsPointedAt(piece.Target);
				Sprite val = PieceIcon(o, piece.Target, piece.Kind);
				if ((Object)(object)val != (Object)null || piece.Kind == PieceKind.Mushroom)
				{
					DrawIcon(vector, 18f, view.HalfSize, PieceTint(piece.Kind, piece.Done), val, flag);
					continue;
				}
				Sprite sprite = pieceSprites[(int)piece.Kind];
				Color color = (piece.Done ? DonePiece : Color.white);
				if (!(round ? MapMath.IsInsideCircle(vector, view.HalfSize) : MapMath.IsInside(vector, view.HalfSize)))
				{
					if (flag)
					{
						DrawPoint(sprite, color, vector, 18f, view.HalfSize, clamp: true);
					}
				}
				else
				{
					icons.Place(sprite, color, ToUnity(vector), 15f, 0f);
				}
			}
		}

		private void DrawZoneIcons(ObjectivePieces o, in MapView view, ObjectiveDiscovery discovery)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			foreach (ObjectiveZone zone in o.Zones)
			{
				ObjectiveZone z = zone;
				if (!cfg.HideUndiscoveredObjectives.Value || discovery.IsKnown(z.Key))
				{
					Sprite val = GameIcons.White(z.Icon);
					if (!((Object)(object)val == (Object)null))
					{
						DrawIcon(MapMath.WorldToPanel(in view, z.Center), 18f, view.HalfSize, ZoneTint(in z), val, pin: true);
					}
				}
			}
		}

		private bool CoveredByZone(ObjectivePieces o, Vector3 w, ObjectiveDiscovery discovery)
		{
			//IL_0016: 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)
			foreach (ObjectiveZone zone in o.Zones)
			{
				float num = w.x - zone.Center.X;
				float num2 = w.z - zone.Center.Y;
				if (!(num * num + num2 * num2 > zone.Radius * zone.Radius * 0.25f) && !((Object)(object)GameIcons.White(zone.Icon) == (Object)null) && (!cfg.HideUndiscoveredObjectives.Value || discovery.IsKnown(zone.Key)))
				{
					return true;
				}
			}
			return false;
		}

		private static Sprite PieceIcon(ObjectivePieces o, Transform piece, PieceKind kind)
		{
			if (kind != PieceKind.Statue)
			{
				return o.PieceIcon(piece, kind);
			}
			return GameIcons.Statue();
		}

		private static Color PieceTint(PieceKind kind, bool done)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			switch (kind)
			{
			case PieceKind.Crate:
				if (!done)
				{
					return PushYellow;
				}
				return ObjectiveBlue;
			case PieceKind.Herd:
				if (!done)
				{
					return ObjectiveBlue;
				}
				return WithAlpha(ObjectiveBlue, 0.45f);
			case PieceKind.Statue:
				return Color.white;
			case PieceKind.Hunt:
				return HuntGold;
			default:
				return ObjectiveBlue;
			}
		}

		private static Color ZoneTint(in ObjectiveZone z)
		{
			//IL_0018: 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 (!(z.Icon == "ui_ping_objective_herding_zone"))
			{
				return ObjectiveBlue;
			}
			return PenGreen;
		}

		private static Color ObjectiveTint(string icon, ObjectivePieces o)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			return (Color)(icon switch
			{
				"ui_ping_objective_sacrifice" => SacrificeRed, 
				"ui_ping_objective_hunttarget" => HuntGold, 
				"ui_ping_objective_clean" => ((??)o.GooColour) ?? ObjectiveBlue, 
				"ui_ping_objective_herding_zone" => PenGreen, 
				"ui_ping_objective_push" => PushYellow, 
				_ => ObjectiveBlue, 
			});
		}

		private static Color WithAlpha(Color c, float a)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			c.a = a;
			return c;
		}

		private void DrawCounters(ObjectivePieces o, float half)
		{
			//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_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			bool flag = !gameFontBroken && GameFont.TryFind(Time.unscaledTime) && EnsureCounterTexts(o.Counts.Count);
			for (int i = 0; i < counterTexts.Count; i++)
			{
				bool flag2 = flag && i < o.Counts.Count;
				if (((Behaviour)counterTexts[i]).enabled != flag2)
				{
					((Behaviour)counterTexts[i]).enabled = flag2;
				}
			}
			Vector2 val2 = default(Vector2);
			for (int j = 0; j < o.Counts.Count; j++)
			{
				ObjectiveCount objectiveCount = o.Counts[j];
				string text = $"{objectiveCount.Done}/{objectiveCount.Total}";
				if (flag)
				{
					try
					{
						DrawGameFontCounter(j, objectiveCount.Kind, text, o, half);
					}
					catch (Exception e)
					{
						flag = false;
						gameFontBroken = true;
						foreach (TextMeshProUGUI counterText in counterTexts)
						{
							((Behaviour)counterText).enabled = false;
						}
						LogOnce.Error("drawing a counter in the game's font (keeping the pixel font)", e);
						goto IL_0131;
					}
					continue;
				}
				goto IL_0131;
				IL_0131:
				if (!counterSprites.TryGetValue(text, out var value))
				{
					PixelBuffer img = PixelFont.Render(text, 2, CounterText, CounterPill, 2, 1, 6);
					value = (counterSprites[text] = SpriteFactory.ToSprite(img, (FilterMode)0));
				}
				Rect rect = value.rect;
				float width = ((Rect)(ref rect)).width;
				rect = value.rect;
				float height = ((Rect)(ref rect)).height;
				((Vector2)(ref val2))..ctor(0f, half - 12f - (float)j * (height + 4f));
				icons.Place(value, Color.white, val2, new Vector2(width, height), 0f);
				Vector2 at = val2 + new Vector2((0f - width) * 0.5f + 6f + 2f, 0f);
				PlaceCounterIcon(at, height - 2f, objectiveCount.Kind, o);
			}
		}

		private void DrawGameFontCounter(int i, PieceKind kind, string text, ObjectivePieces o, float half)
		{
			//IL_003e: 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_00d4: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = counterTexts[i];
			if (counterShown[i] != text)
			{
				counterShown[i] = text;
				((TMP_Text)val).text = text;
				counterWidth[i] = Mathf.Ceil(((TMP_Text)val).GetPreferredValues(text).x);
			}
			float num = counterWidth[i];
			int num2 = Mathf.CeilToInt(23f + num + 8f);
			if (!pills.TryGetValue(num2, out var value))
			{
				value = (pills[num2] = SpriteFactory.ToSprite(ShapeSprites.Pill(num2, 18), (FilterMode)1));
			}
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, half - 13f - (float)i * 22f);
			float num3 = val3.x - (float)num2 * 0.5f;
			icons.Place(value, CounterPillColor, val3, new Vector2((float)num2, 18f), 0f);
			Vector2 at = default(Vector2);
			((Vector2)(ref at))..ctor(num3 + 4f + 8f + 1f, val3.y);
			PlaceCounterIcon(at, 16f, kind, o);
			RectTransform rectTransform = ((TMP_Text)val).rectTransform;
			rectTransform.anchoredPosition = new Vector2(num3 + 4f + 16f + 3f + num * 0.5f, val3.y);
			rectTransform.sizeDelta = new Vector2(num + 2f, 18f);
		}

		private bool EnsureCounterTexts(int n)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				while (counterTexts.Count < n)
				{
					GameObject val = new GameObject("Counter");
					val.transform.SetParent((Transform)(object)counterRoot, false);
					TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
					((TMP_Text)val2).font = GameFont.Font;
					((TMP_Text)val2).fontSize = 15f;
					((Graphic)val2).color = CounterTextColor;
					((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
					((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
					((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
					((TMP_Text)val2).richText = false;
					((Graphic)val2).raycastTarget = false;
					((Behaviour)val2).enabled = false;
					counterTexts.Add(val2);
					counterShown.Add(null);
					counterWidth.Add(0f);
				}
				return true;
			}
			catch (Exception e)
			{
				gameFontBroken = true;
				LogOnce.Error("making the counters in the game's font (keeping the pixel font)", e);
				return false;
			}
		}

		private void DrawFeature(IconPool pool, Sprite sprite, Color color, Vector2 world, in MapView view, float size, Vector2 shake = default(Vector2), float tilt = 0f)
		{
			//IL_0033: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			Vector2 v = MapMath.WorldToPanel(in view, world);
			if (round ? MapMath.IsInsideCircle(v, view.HalfSize) : MapMath.IsInside(v, view.HalfSize))
			{
				pool.Place(sprite, color, ToUnity(v) + shake, size, tilt);
			}