Decompiled source of NoMapDiscordAdditions v1.1.1

plugins/NoMapDiscordAdditions.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
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 System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Extensions;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using NoMapDiscordAdditions.MapCompile;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyCompany("NoMapDiscordAdditions")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b65614dffee2d29f02a8d9546d4579fe4b048e87")]
[assembly: AssemblyProduct("NoMapDiscordAdditions")]
[assembly: AssemblyTitle("NoMapDiscordAdditions")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 NoMapDiscordAdditions
{
	public static class CaptureButton
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction<bool> <>9__15_2;

			public static UnityAction <>9__15_0;

			public static UnityAction <>9__15_1;

			internal void <Create>b__15_2(bool val)
			{
				if (Plugin.ShowBiomeText != null)
				{
					Plugin.ShowBiomeText.Value = val;
				}
			}

			internal void <Create>b__15_0()
			{
				Plugin instance = Plugin.Instance;
				if (!((Object)(object)instance == (Object)null))
				{
					PinCaptureFilter.ArmFromCurrentInput();
					instance.TriggerDiscordSend();
				}
			}

			internal void <Create>b__15_1()
			{
				Plugin instance = Plugin.Instance;
				if (!((Object)(object)instance == (Object)null))
				{
					PinCaptureFilter.ArmFromCurrentInput();
					instance.TriggerClipboardCopy();
				}
			}
		}

		private static GameObject _containerObj;

		private static Button _captureBtn;

		private static TextMeshProUGUI _captureBtnText;

		private static Button _clipboardBtn;

		private static TextMeshProUGUI _clipboardBtnText;

		private static GameObject _biomeToggleObj;

		private static Toggle _biomeToggle;

		private static Image _biomeToggleCheckmark;

		private static float _biomeToggleWidth = 130f;

		private static float _biomeToggleHeight = 38f;

		private const string ContainerName = "CaptureButtonPanel";

		private const float BtnWidth = 180f;

		private const float BtnHeight = 38f;

		private const float HlgPadVertical = 6f;

		private const float HlgSpacing = 8f;

		public static void Create()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Expected O, but got Unknown
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Expected O, but got Unknown
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_largeRoot == (Object)null)
			{
				return;
			}
			Transform transform = instance.m_largeRoot.transform;
			DestroyExisting(transform);
			if ((Object)(object)_containerObj != (Object)null)
			{
				return;
			}
			_containerObj = new GameObject("CaptureButtonPanel");
			_containerObj.transform.SetParent(transform, false);
			RectTransform obj = _containerObj.AddComponent<RectTransform>();
			obj.pivot = new Vector2(0.5f, 1f);
			float num = Mathf.Max(_biomeToggleHeight, 38f) + 12f;
			obj.sizeDelta = new Vector2(8f + _biomeToggleWidth + 8f + 180f + 8f, num);
			ApplyAlignment(obj);
			MapUI.ApplyPanelBackground(_containerObj.AddComponent<Image>(), instance);
			HorizontalLayoutGroup obj2 = _containerObj.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj2).spacing = 8f;
			((LayoutGroup)obj2).padding = new RectOffset(8, 8, 6, 6);
			Transform val2 = Utils.FindChild(((Component)instance).transform, "SharedPanel", (IterativeSearchType)0);
			if ((Object)(object)val2 != (Object)null)
			{
				_biomeToggleObj = Object.Instantiate<GameObject>(((Component)val2).gameObject, _containerObj.transform);
				((Object)_biomeToggleObj).name = "BiomeToggle";
				_biomeToggleObj.SetActive(true);
				RectTransform component = _biomeToggleObj.GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					if (component.sizeDelta.x > 0f)
					{
						_biomeToggleWidth = component.sizeDelta.x;
					}
					_biomeToggleHeight = 38f;
					component.sizeDelta = new Vector2(_biomeToggleWidth, 38f);
				}
				_biomeToggle = _biomeToggleObj.GetComponentInChildren<Toggle>(true);
				if ((Object)(object)_biomeToggle != (Object)null)
				{
					((UnityEventBase)_biomeToggle.onValueChanged).RemoveAllListeners();
					_biomeToggle.isOn = Plugin.ShowBiomeText?.Value ?? false;
					((UnityEvent<bool>)(object)_biomeToggle.onValueChanged).AddListener((UnityAction<bool>)delegate(bool val)
					{
						if (Plugin.ShowBiomeText != null)
						{
							Plugin.ShowBiomeText.Value = val;
						}
					});
				}
				Transform val3 = Utils.FindChild(_biomeToggleObj.transform, "Label", (IterativeSearchType)0);
				if ((Object)(object)val3 != (Object)null)
				{
					TextMeshProUGUI component2 = ((Component)val3).GetComponent<TextMeshProUGUI>();
					if ((Object)(object)component2 != (Object)null)
					{
						((TMP_Text)component2).text = "Show Biome Text";
					}
				}
				Transform obj3 = Utils.FindChild(_biomeToggleObj.transform, "Checkmark", (IterativeSearchType)0);
				_biomeToggleCheckmark = ((obj3 != null) ? ((Component)obj3).GetComponent<Image>() : null);
			}
			else
			{
				ModLog.Warn("[NoMapDiscordAdditions] SharedPanel not found — biome toggle skipped.");
			}
			_captureBtn = MapUI.CreateButton("CaptureBtn", _containerObj.transform, 180f, 38f, BuildSendLabel(), out _captureBtnText);
			ButtonClickedEvent onClick = _captureBtn.onClick;
			object obj4 = <>c.<>9__15_0;
			if (obj4 == null)
			{
				UnityAction val4 = delegate
				{
					Plugin instance3 = Plugin.Instance;
					if (!((Object)(object)instance3 == (Object)null))
					{
						PinCaptureFilter.ArmFromCurrentInput();
						instance3.TriggerDiscordSend();
					}
				};
				<>c.<>9__15_0 = val4;
				obj4 = (object)val4;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj4);
			_clipboardBtn = MapUI.CreateButton("ClipboardBtn", _containerObj.transform, 180f, 38f, BuildCopyLabel(), out _clipboardBtnText);
			ButtonClickedEvent onClick2 = _clipboardBtn.onClick;
			object obj5 = <>c.<>9__15_1;
			if (obj5 == null)
			{
				UnityAction val5 = delegate
				{
					Plugin instance2 = Plugin.Instance;
					if (!((Object)(object)instance2 == (Object)null))
					{
						PinCaptureFilter.ArmFromCurrentInput();
						instance2.TriggerClipboardCopy();
					}
				};
				<>c.<>9__15_1 = val5;
				obj5 = (object)val5;
			}
			((UnityEvent)onClick2).AddListener((UnityAction)obj5);
			Plugin.SendingStateChanged -= RefreshLoadingState;
			Plugin.SendingStateChanged += RefreshLoadingState;
			_containerObj.SetActive(true);
			RefreshEnabledState();
			RefreshBiomeToggleState();
			RefreshLoadingState();
			ModLog.Info("[NoMapDiscordAdditions] Map button container created.");
		}

		public static void RefreshLoadingState()
		{
			if (!((Object)(object)_captureBtn == (Object)null) && !((Object)(object)_clipboardBtn == (Object)null) && !((Object)(object)_captureBtnText == (Object)null) && !((Object)(object)_clipboardBtnText == (Object)null))
			{
				bool isSendingInProgress = Plugin.IsSendingInProgress;
				Plugin.SendingOp currentSendingOp = Plugin.CurrentSendingOp;
				bool flag = !string.IsNullOrEmpty(ModHelpers.EffectiveConfig.WebhookUrl);
				((Selectable)_captureBtn).interactable = !isSendingInProgress && flag;
				((Selectable)_clipboardBtn).interactable = !isSendingInProgress;
				((TMP_Text)_captureBtnText).text = ((isSendingInProgress && currentSendingOp == Plugin.SendingOp.Send) ? "SENDING..." : BuildSendLabel());
				((TMP_Text)_clipboardBtnText).text = ((isSendingInProgress && currentSendingOp == Plugin.SendingOp.Copy) ? "COPYING..." : BuildCopyLabel());
			}
		}

		public static void RefreshEnabledState()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_containerObj == (Object)null))
			{
				bool flag = false;
				if ((Object)(object)_captureBtn != (Object)null)
				{
					flag = !string.IsNullOrEmpty(ModHelpers.EffectiveConfig.WebhookUrl);
					((Component)_captureBtn).gameObject.SetActive(flag);
				}
				RectTransform component = _containerObj.GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					float num = 8f + _biomeToggleWidth + 8f + 180f + 8f + (flag ? 188f : 0f);
					float num2 = Mathf.Max(_biomeToggleHeight, 38f) + 12f;
					component.sizeDelta = new Vector2(num, num2);
					ApplyAlignment(component);
				}
			}
		}

		public static void RefreshHotkeyLabels()
		{
			if ((Object)(object)_captureBtnText != (Object)null)
			{
				((TMP_Text)_captureBtnText).text = BuildSendLabel();
			}
			if ((Object)(object)_clipboardBtnText != (Object)null)
			{
				((TMP_Text)_clipboardBtnText).text = BuildCopyLabel();
			}
		}

		private static string BuildSendLabel()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<KeyCode> sendKey = Plugin.SendKey;
			object obj;
			if (sendKey == null)
			{
				obj = null;
			}
			else
			{
				KeyCode value = sendKey.Value;
				obj = ((object)(KeyCode)(ref value)).ToString();
			}
			if (obj == null)
			{
				obj = "F10";
			}
			return "SEND MAP (" + (string?)obj + ")";
		}

		private static string BuildCopyLabel()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<KeyCode> copyKey = Plugin.CopyKey;
			object obj;
			if (copyKey == null)
			{
				obj = null;
			}
			else
			{
				KeyCode value = copyKey.Value;
				obj = ((object)(KeyCode)(ref value)).ToString();
			}
			if (obj == null)
			{
				obj = "F11";
			}
			return "COPY MAP (" + (string?)obj + ")";
		}

		public static void RefreshBiomeToggleState()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_biomeToggle == (Object)null))
			{
				bool flag = Plugin.ShowBiomeText?.Value ?? false;
				_biomeToggle.isOn = flag;
				if ((Object)(object)_biomeToggleCheckmark != (Object)null)
				{
					((Graphic)_biomeToggleCheckmark).color = (Color)(flag ? new Color(1f, 0.631f, 0.235f, 1f) : Color.white);
				}
			}
		}

		public static void SetVisible(bool visible)
		{
			if (!((Object)(object)_containerObj == (Object)null))
			{
				_containerObj.SetActive(visible);
				if (visible)
				{
					RefreshEnabledState();
					RefreshLoadingState();
				}
			}
		}

		public static void ApplyAlignment()
		{
			if (!((Object)(object)_containerObj == (Object)null))
			{
				ApplyAlignment(_containerObj.GetComponent<RectTransform>());
			}
		}

		private static void ApplyAlignment(RectTransform rect)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			if (!((Object)(object)rect == (Object)null))
			{
				float num = rect.sizeDelta.x * 0.5f;
				rect.anchorMin = new Vector2(1f, 0f);
				rect.anchorMax = new Vector2(1f, 0f);
				rect.anchoredPosition = new Vector2(0f - (8f + num), -8f);
			}
		}

		private static void DestroyExisting(Transform largeRoot)
		{
			for (int num = largeRoot.childCount - 1; num >= 0; num--)
			{
				Transform child = largeRoot.GetChild(num);
				if (!((Object)(object)child == (Object)null) && ((Object)child).name == "CaptureButtonPanel")
				{
					Object.Destroy((Object)(object)((Component)child).gameObject);
				}
			}
			if (!Object.op_Implicit((Object)(object)_containerObj))
			{
				_containerObj = null;
			}
			if (!Object.op_Implicit((Object)(object)_captureBtn))
			{
				_captureBtn = null;
			}
			if (!Object.op_Implicit((Object)(object)_captureBtnText))
			{
				_captureBtnText = null;
			}
			if (!Object.op_Implicit((Object)(object)_clipboardBtn))
			{
				_clipboardBtn = null;
			}
			if (!Object.op_Implicit((Object)(object)_clipboardBtnText))
			{
				_clipboardBtnText = null;
			}
			if (!Object.op_Implicit((Object)(object)_biomeToggleObj))
			{
				_biomeToggleObj = null;
			}
			if (!Object.op_Implicit((Object)(object)_biomeToggle))
			{
				_biomeToggle = null;
			}
			if (!Object.op_Implicit((Object)(object)_biomeToggleCheckmark))
			{
				_biomeToggleCheckmark = null;
			}
			MapUI.InvalidateCaches();
		}
	}
	[HarmonyPatch]
	public static class CartographyTablePatch
	{
		[HarmonyPatch(typeof(MapTable), "OnRead", new Type[]
		{
			typeof(Switch),
			typeof(Humanoid),
			typeof(ItemData)
		})]
		[HarmonyPostfix]
		private static void OnRead_Postfix(MapTable __instance)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null))
			{
				MapCompileSession.SetActiveTable(((Component)__instance).transform.position);
			}
		}
	}
	public static class DiscordWebhook
	{
		private sealed class BypassCertificateHandler : CertificateHandler
		{
			protected override bool ValidateCertificate(byte[] certificateData)
			{
				return true;
			}
		}

		public struct OutgoingImage
		{
			public byte[] Bytes;

			public string FileName;
		}

		public const int MaxImagesPerMessage = 5;

		public static IEnumerator SendImages(IList<OutgoingImage> images, string message, bool useSpoilerTag)
		{
			if (images == null || images.Count == 0)
			{
				yield break;
			}
			string webhookUrl = ModHelpers.EffectiveConfig.WebhookUrl;
			if (string.IsNullOrEmpty(webhookUrl))
			{
				ModLog.Warn("[NoMapDiscordAdditions] Webhook URL not configured.");
				yield break;
			}
			WWWForm val = new WWWForm();
			int count = Mathf.Min(images.Count, 5);
			for (int i = 0; i < count; i++)
			{
				val.AddBinaryData($"files[{i}]", images[i].Bytes, GetAttachmentFileName(images[i].FileName, useSpoilerTag), "image/png");
			}
			if (!string.IsNullOrEmpty(message))
			{
				val.AddField("payload_json", JsonConvert.SerializeObject((object)new
				{
					content = message
				}));
			}
			UnityWebRequest request = UnityWebRequest.Post(webhookUrl, val);
			try
			{
				request.certificateHandler = (CertificateHandler)(object)new BypassCertificateHandler();
				yield return request.SendWebRequest();
				if ((int)request.result != 1)
				{
					ModLog.Error("[NoMapDiscordAdditions] Discord webhook failed: " + request.error);
				}
				else
				{
					ModLog.Info($"[NoMapDiscordAdditions] Sent {count} image(s) to Discord.");
				}
			}
			finally
			{
				((IDisposable)request)?.Dispose();
			}
		}

		public static IEnumerator SendImageBatches(IList<OutgoingImage> images, string message, bool useSpoilerTag)
		{
			if (images == null || images.Count == 0)
			{
				yield break;
			}
			for (int start = 0; start < images.Count; start += 5)
			{
				int num = Mathf.Min(5, images.Count - start);
				List<OutgoingImage> list = new List<OutgoingImage>(num);
				for (int i = 0; i < num; i++)
				{
					list.Add(images[start + i]);
				}
				string message2 = ((start == 0) ? message : null);
				yield return SendImages(list, message2, useSpoilerTag);
			}
		}

		public static IEnumerator SendImage(byte[] imageData, string filename, string message, bool useSpoilerTag)
		{
			string webhookUrl = ModHelpers.EffectiveConfig.WebhookUrl;
			if (string.IsNullOrEmpty(webhookUrl))
			{
				ModLog.Warn("[NoMapDiscordAdditions] Webhook URL not configured.");
				yield break;
			}
			WWWForm val = new WWWForm();
			val.AddBinaryData("files[0]", imageData, GetAttachmentFileName(filename, useSpoilerTag), "image/png");
			if (!string.IsNullOrEmpty(message))
			{
				val.AddField("payload_json", JsonConvert.SerializeObject((object)new
				{
					content = message
				}));
			}
			UnityWebRequest request = UnityWebRequest.Post(webhookUrl, val);
			try
			{
				request.certificateHandler = (CertificateHandler)(object)new BypassCertificateHandler();
				yield return request.SendWebRequest();
				if ((int)request.result != 1)
				{
					ModLog.Error("[NoMapDiscordAdditions] Discord webhook failed: " + request.error);
				}
				else
				{
					ModLog.Info("[NoMapDiscordAdditions] Map screenshot sent to Discord.");
				}
			}
			finally
			{
				((IDisposable)request)?.Dispose();
			}
		}

		private static string GetAttachmentFileName(string filename, bool useSpoilerTag)
		{
			if (!useSpoilerTag || string.IsNullOrEmpty(filename) || filename.StartsWith("SPOILER_"))
			{
				return filename;
			}
			return "SPOILER_" + filename;
		}
	}
	public static class MapCaptureTexture
	{
		public const int OutputWidth = 1920;

		public const int OutputHeight = 1080;

		private static readonly Dictionary<Texture2D, Color32[]> _atlasCache = new Dictionary<Texture2D, Color32[]>();

		private static bool _uvRemapActive;

		private static float _ruX0;

		private static float _ruX1;

		private static float _ruY0;

		private static float _ruY1;

		private static float _cuX0;

		private static float _cuY0;

		private static float _cuW;

		private static float _cuH;

		public static void GetDefaultCaptureSize(out int width, out int height)
		{
			width = 1920;
			height = 1080;
			Minimap instance = Minimap.instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.m_mapImageLarge == (Object)null))
			{
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				((Graphic)instance.m_mapImageLarge).rectTransform.GetWorldCorners(array);
				int num = Mathf.RoundToInt(Mathf.Abs(array[2].x - array[0].x));
				int num2 = Mathf.RoundToInt(Mathf.Abs(array[2].y - array[0].y));
				if (num >= 64 && num2 >= 64)
				{
					width = num;
					height = num2;
				}
			}
		}

		public static byte[] CaptureMap()
		{
			GetDefaultCaptureSize(out var width, out var height);
			return CaptureMap(width, height);
		}

		public static byte[] CaptureMap(int outputWidth, int outputHeight, Texture2D styledBase = null, bool drawPinIcons = true)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_0135: 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)
			if (outputWidth < 64 || outputHeight < 64)
			{
				ModLog.Error($"[NoMapDiscordAdditions] CaptureMap: invalid size {outputWidth}x{outputHeight}.");
				return null;
			}
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance == (Object)null || (int)instance.m_mode != 2)
			{
				ModLog.Error("[NoMapDiscordAdditions] Large map not active.");
				return null;
			}
			Texture2D mapTexture = instance.m_mapTexture;
			RawImage mapImageLarge = instance.m_mapImageLarge;
			RectTransform pinRootLarge = instance.m_pinRootLarge;
			if ((Object)(object)mapTexture == (Object)null || (Object)(object)mapImageLarge == (Object)null)
			{
				ModLog.Error("[NoMapDiscordAdditions] Required Minimap fields not available.");
				return null;
			}
			Material val = instance.m_mapLargeShader;
			if ((Object)(object)val == (Object)null)
			{
				val = ((Graphic)mapImageLarge).material;
			}
			RectTransform rectTransform = ((Graphic)mapImageLarge).rectTransform;
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rectTransform.GetWorldCorners(array);
			float x = array[0].x;
			float y = array[0].y;
			float x2 = array[2].x;
			float y2 = array[2].y;
			float num = x2 - x;
			float num2 = y2 - y;
			if (num <= 0f || num2 <= 0f)
			{
				ModLog.Error("[NoMapDiscordAdditions] Map RectTransform has zero size.");
				return null;
			}
			RenderTexture temporary = RenderTexture.GetTemporary(outputWidth, outputHeight, 0, (RenderTextureFormat)0);
			Color32[] array2;
			try
			{
				if ((Object)(object)styledBase != (Object)null)
				{
					DrawStyledBase(temporary, styledBase);
				}
				else
				{
					DrawMapBase(temporary, mapTexture, val, mapImageLarge.uvRect);
				}
				array2 = ReadRTPixels(temporary);
			}
			finally
			{
				RenderTexture.ReleaseTemporary(temporary);
			}
			if (array2 == null)
			{
				ModLog.Error("[NoMapDiscordAdditions] GPU pass failed.");
				return null;
			}
			BeginUvRemap(mapImageLarge.uvRect);
			PinCaptureFilter.State state = default(PinCaptureFilter.State);
			if (drawPinIcons)
			{
				state = PinCaptureFilter.Apply();
			}
			try
			{
				if ((Object)(object)pinRootLarge != (Object)null && drawPinIcons)
				{
					BlitUIChildren(array2, outputWidth, outputHeight, x, y, num, num2, (Transform)(object)pinRootLarge);
				}
				if ((Object)(object)instance.m_pinNameRootLarge != (Object)null && drawPinIcons)
				{
					BlitUIChildren(array2, outputWidth, outputHeight, x, y, num, num2, (Transform)(object)instance.m_pinNameRootLarge);
				}
				BlitMarker(instance.m_largeMarker, array2, outputWidth, outputHeight, x, y, num, num2);
				BlitMarker(instance.m_largeShipMarker, array2, outputWidth, outputHeight, x, y, num, num2);
				return Encode(array2, outputWidth, outputHeight);
			}
			finally
			{
				PinCaptureFilter.Restore(state);
				_atlasCache.Clear();
				EndUvRemap();
			}
		}

		private static void BeginUvRemap(Rect uv)
		{
			_ruX0 = ((Rect)(ref uv)).xMin;
			_ruX1 = ((Rect)(ref uv)).xMax;
			_ruY0 = ((Rect)(ref uv)).yMin;
			_ruY1 = ((Rect)(ref uv)).yMax;
			_cuX0 = Mathf.Clamp01(_ruX0);
			_cuY0 = Mathf.Clamp01(_ruY0);
			_cuW = Mathf.Clamp01(_ruX1) - _cuX0;
			_cuH = Mathf.Clamp01(_ruY1) - _cuY0;
			float num = _ruX1 - _ruX0;
			float num2 = _ruY1 - _ruY0;
			_uvRemapActive = _cuW > 1E-06f && _cuH > 1E-06f && num > 1E-06f && num2 > 1E-06f && (Mathf.Abs(num - _cuW) > 1E-05f || Mathf.Abs(num2 - _cuH) > 1E-05f);
		}

		private static void EndUvRemap()
		{
			_uvRemapActive = false;
		}

		private static float ProjectX(float screenX, float mapMinX, float mapW, int outW)
		{
			float num = (screenX - mapMinX) / mapW;
			if (!_uvRemapActive)
			{
				return num * (float)outW;
			}
			return (_ruX0 + num * (_ruX1 - _ruX0) - _cuX0) / _cuW * (float)outW;
		}

		private static float ProjectY(float screenY, float mapMinY, float mapH, int outH)
		{
			float num = (screenY - mapMinY) / mapH;
			if (!_uvRemapActive)
			{
				return num * (float)outH;
			}
			return (_ruY0 + num * (_ruY1 - _ruY0) - _cuY0) / _cuH * (float)outH;
		}

		private static float RemapScaleX(float mapW, int outW)
		{
			if (!_uvRemapActive)
			{
				return (float)outW / mapW;
			}
			return (float)outW / _cuW * ((_ruX1 - _ruX0) / mapW);
		}

		private static float RemapScaleY(float mapH, int outH)
		{
			if (!_uvRemapActive)
			{
				return (float)outH / mapH;
			}
			return (float)outH / _cuH * ((_ruY1 - _ruY0) / mapH);
		}

		private static void DrawMapBase(RenderTexture target, Texture2D mapTex, Material mat, Rect uv)
		{
			//IL_00be: 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_017f: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(((Rect)(ref uv)).xMin);
			float num2 = Mathf.Clamp01(((Rect)(ref uv)).yMin);
			float num3 = Mathf.Clamp01(((Rect)(ref uv)).xMax);
			float num4 = Mathf.Clamp01(((Rect)(ref uv)).yMax);
			List<ModHelpers.SavedShaderProp> list = null;
			Texture val = null;
			bool flag = (Object)(object)mat != (Object)null && mat.HasProperty("_MainTex");
			bool num5 = Plugin.NormalizeCaptureLighting?.Value ?? true;
			ModHelpers.SavedLighting saved = default(ModHelpers.SavedLighting);
			if (num5)
			{
				saved = ModHelpers.OverrideLightingToNoon();
			}
			if (ModHelpers.EffectiveConfig.HideClouds && (Object)(object)mat != (Object)null)
			{
				list = ModHelpers.SuppressShaderPropsContaining(mat, "cloud");
			}
			if (flag)
			{
				val = mat.GetTexture("_MainTex");
				mat.SetTexture("_MainTex", (Texture)(object)mapTex);
			}
			RenderTexture active = RenderTexture.active;
			try
			{
				RenderTexture.active = target;
				GL.Clear(true, true, Color.black);
				bool flag2 = false;
				if ((Object)(object)mat != (Object)null && mat.SetPass(0))
				{
					GL.PushMatrix();
					GL.LoadOrtho();
					GL.Begin(7);
					GL.TexCoord2(num, num2);
					GL.Vertex3(0f, 0f, 0f);
					GL.TexCoord2(num3, num2);
					GL.Vertex3(1f, 0f, 0f);
					GL.TexCoord2(num3, num4);
					GL.Vertex3(1f, 1f, 0f);
					GL.TexCoord2(num, num4);
					GL.Vertex3(0f, 1f, 0f);
					GL.End();
					GL.PopMatrix();
					flag2 = true;
				}
				if (!flag2)
				{
					Graphics.Blit((Texture)(object)mapTex, target, new Vector2(num3 - num, num4 - num2), new Vector2(num, num2));
				}
			}
			finally
			{
				RenderTexture.active = active;
				if (flag && (Object)(object)val != (Object)null)
				{
					mat.SetTexture("_MainTex", val);
				}
				if (list != null)
				{
					ModHelpers.RestoreShaderProps(mat, list);
				}
				ModHelpers.RestoreLighting(saved);
			}
		}

		private static void DrawStyledBase(RenderTexture target, Texture2D styled)
		{
			Graphics.Blit((Texture)(object)styled, target);
		}

		private static Color32[] ReadRTPixels(RenderTexture rt)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = rt;
			Texture2D val = new Texture2D(((Texture)rt).width, ((Texture)rt).height, (TextureFormat)4, false);
			val.ReadPixels(new Rect(0f, 0f, (float)((Texture)rt).width, (float)((Texture)rt).height), 0, 0);
			val.Apply();
			RenderTexture.active = active;
			Color32[] pixels = val.GetPixels32();
			Object.Destroy((Object)val);
			return pixels;
		}

		private static void BlitUIChildren(Color32[] output, int outputWidth, int outputHeight, float mapMinX, float mapMinY, float mapW, float mapH, Transform parent)
		{
			int childCount = parent.childCount;
			for (int i = 0; i < childCount; i++)
			{
				Transform child = parent.GetChild(i);
				if ((Object)(object)child == (Object)null || !((Component)child).gameObject.activeInHierarchy)
				{
					continue;
				}
				RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null);
				if (!((Object)(object)val == (Object)null))
				{
					Image component = ((Component)child).GetComponent<Image>();
					if ((Object)(object)component != (Object)null && ((Behaviour)component).enabled && (Object)(object)component.sprite != (Object)null)
					{
						BlitImage(output, outputWidth, outputHeight, mapMinX, mapMinY, mapW, mapH, val, component);
					}
					TMP_Text component2 = ((Component)child).GetComponent<TMP_Text>();
					if ((Object)(object)component2 != (Object)null && ((Behaviour)component2).enabled && !string.IsNullOrEmpty(component2.text))
					{
						BlitText(output, outputWidth, outputHeight, mapMinX, mapMinY, mapW, mapH, component2, forceMeshUpdate: true, drawOutline: true);
					}
					if (child.childCount > 0)
					{
						BlitUIChildren(output, outputWidth, outputHeight, mapMinX, mapMinY, mapW, mapH, child);
					}
				}
			}
		}

		private static void BlitMarker(RectTransform rt, Color32[] output, int outputWidth, int outputHeight, float mapMinX, float mapMinY, float mapW, float mapH)
		{
			if (!((Object)(object)rt == (Object)null) && ((Component)rt).gameObject.activeInHierarchy)
			{
				Image component = ((Component)rt).GetComponent<Image>();
				if ((Object)(object)component != (Object)null && ((Behaviour)component).enabled && (Object)(object)component.sprite != (Object)null)
				{
					BlitImage(output, outputWidth, outputHeight, mapMinX, mapMinY, mapW, mapH, rt, component);
				}
			}
		}

		private static void BlitImage(Color32[] output, int outputWidth, int outputHeight, float mapMinX, float mapMinY, float mapW, float mapH, RectTransform target, Image img)
		{
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: 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_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			target.GetWorldCorners(array);
			float screenX = (array[0].x + array[2].x) * 0.5f;
			float screenY = (array[0].y + array[2].y) * 0.5f;
			float num = array[2].x - array[0].x;
			float num2 = array[2].y - array[0].y;
			if (num <= 0f || num2 <= 0f)
			{
				return;
			}
			int num3 = Mathf.RoundToInt(ProjectX(screenX, mapMinX, mapW, outputWidth));
			int num4 = Mathf.RoundToInt(ProjectY(screenY, mapMinY, mapH, outputHeight));
			float num5 = RemapScaleX(mapW, outputWidth);
			float num6 = RemapScaleY(mapH, outputHeight);
			int num7 = Mathf.Max(1, Mathf.RoundToInt(num * num5));
			int num8 = Mathf.Max(1, Mathf.RoundToInt(num2 * num6));
			int num9 = num7 / 2;
			int num10 = num8 / 2;
			if (num3 + num9 < 0 || num3 - num9 >= outputWidth || num4 + num10 < 0 || num4 - num10 >= outputHeight)
			{
				return;
			}
			Sprite sprite = img.sprite;
			Rect textureRect = sprite.textureRect;
			int num11 = Mathf.RoundToInt(((Rect)(ref textureRect)).x);
			int num12 = Mathf.RoundToInt(((Rect)(ref textureRect)).y);
			int num13 = Mathf.RoundToInt(((Rect)(ref textureRect)).width);
			int num14 = Mathf.RoundToInt(((Rect)(ref textureRect)).height);
			if (num13 <= 0 || num14 <= 0)
			{
				return;
			}
			Color32[] cachedAtlasPixels = GetCachedAtlasPixels(sprite.texture);
			if (cachedAtlasPixels == null)
			{
				return;
			}
			int width = ((Texture)sprite.texture).width;
			Color32 val = Color32.op_Implicit(((Graphic)img).color);
			float num15 = (float)num13 / (float)num7;
			float num16 = (float)num14 / (float)num8;
			for (int i = 0; i < num8; i++)
			{
				int num17 = num4 - num10 + i;
				if (num17 < 0 || num17 >= outputHeight)
				{
					continue;
				}
				int num18 = Mathf.Clamp((int)((float)i * num16), 0, num14 - 1);
				int num19 = (num12 + num18) * width + num11;
				int num20 = num17 * outputWidth;
				for (int j = 0; j < num7; j++)
				{
					int num21 = num3 - num9 + j;
					if (num21 < 0 || num21 >= outputWidth)
					{
						continue;
					}
					int num22 = Mathf.Clamp((int)((float)j * num15), 0, num13 - 1);
					Color32 val2 = cachedAtlasPixels[num19 + num22];
					int num23 = val2.a * val.a / 255;
					if (num23 != 0)
					{
						int num24 = val2.r * val.r / 255;
						int num25 = val2.g * val.g / 255;
						int num26 = val2.b * val.b / 255;
						int num27 = num20 + num21;
						if (num23 >= 250)
						{
							output[num27] = new Color32((byte)num24, (byte)num25, (byte)num26, byte.MaxValue);
							continue;
						}
						Color32 val3 = output[num27];
						int num28 = 255 - num23;
						output[num27] = new Color32((byte)((num24 * num23 + val3.r * num28) / 255), (byte)((num25 * num23 + val3.g * num28) / 255), (byte)((num26 * num23 + val3.b * num28) / 255), byte.MaxValue);
					}
				}
			}
		}

		private static void BlitText(Color32[] output, int outputWidth, int outputHeight, float mapMinX, float mapMinY, float mapW, float mapH, TMP_Text tmp, bool forceMeshUpdate = true, bool drawOutline = false)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: 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_02a0: 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_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: 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_02bb: 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_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			if (forceMeshUpdate)
			{
				tmp.ForceMeshUpdate(false, false);
			}
			TMP_TextInfo textInfo = tmp.textInfo;
			if (textInfo == null || textInfo.characterCount == 0)
			{
				return;
			}
			RectTransform rectTransform = tmp.rectTransform;
			for (int i = 0; i < textInfo.characterCount; i++)
			{
				TMP_CharacterInfo val = textInfo.characterInfo[i];
				if (!val.isVisible)
				{
					continue;
				}
				Texture obj = (((Object)(object)val.material != (Object)null) ? val.material.mainTexture : null);
				Texture2D val2 = (Texture2D)(object)((obj is Texture2D) ? obj : null);
				if ((Object)(object)val2 == (Object)null && (Object)(object)val.fontAsset != (Object)null)
				{
					val2 = val.fontAsset.atlasTexture;
				}
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Color32[] cachedAtlasPixels = GetCachedAtlasPixels(val2);
				if (cachedAtlasPixels == null)
				{
					continue;
				}
				int width = ((Texture)val2).width;
				int height = ((Texture)val2).height;
				Vector3 val3 = ((Transform)rectTransform).TransformPoint(val.vertex_BL.position);
				Vector3 val4 = ((Transform)rectTransform).TransformPoint(val.vertex_TR.position);
				float num = ProjectX(val3.x, mapMinX, mapW, outputWidth);
				float num2 = ProjectX(val4.x, mapMinX, mapW, outputWidth);
				float num3 = ProjectY(val3.y, mapMinY, mapH, outputHeight);
				float num4 = ProjectY(val4.y, mapMinY, mapH, outputHeight);
				int num5 = Mathf.FloorToInt(Mathf.Min(num, num2));
				int num6 = Mathf.CeilToInt(Mathf.Max(num, num2));
				int num7 = Mathf.FloorToInt(Mathf.Min(num3, num4));
				int num8 = Mathf.CeilToInt(Mathf.Max(num3, num4));
				if (num6 <= num5 || num8 <= num7 || num6 < 0 || num5 >= outputWidth || num8 < 0 || num7 >= outputHeight)
				{
					continue;
				}
				Vector4 uv = val.vertex_BL.uv;
				Vector4 uv2 = val.vertex_TR.uv;
				float x = uv.x;
				float x2 = uv2.x;
				float y = uv.y;
				float y2 = uv2.y;
				Color32 val5 = val.color;
				if (val5.a == 0)
				{
					val5 = Color32.op_Implicit(((Graphic)tmp).color);
				}
				float num9 = 1f / (num2 - num);
				float num10 = 1f / (num4 - num3);
				for (int j = Mathf.Max(num7, 0); j < Mathf.Min(num8, outputHeight); j++)
				{
					float num11 = ((float)j + 0.5f - num3) * num10;
					int num12 = Mathf.Clamp((int)(Mathf.Lerp(y, y2, Mathf.Clamp01(num11)) * (float)height), 0, height - 1) * width;
					int num13 = j * outputWidth;
					for (int k = Mathf.Max(num5, 0); k < Mathf.Min(num6, outputWidth); k++)
					{
						float num14 = ((float)k + 0.5f - num) * num9;
						int num15 = Mathf.Clamp((int)(Mathf.Lerp(x, x2, Mathf.Clamp01(num14)) * (float)width), 0, width - 1);
						Color32 val6 = cachedAtlasPixels[num12 + num15];
						int num16 = val6.a;
						if (val6.r > num16)
						{
							num16 = val6.r;
						}
						if (val6.g > num16)
						{
							num16 = val6.g;
						}
						if (val6.b > num16)
						{
							num16 = val6.b;
						}
						float num17 = (float)num16 / 255f;
						float num18 = Mathf.Clamp01((num17 - 0.46f) / 0.08f);
						float num19 = (drawOutline ? Mathf.Clamp01((num17 - 0.3f) / 0.08f) : num18);
						if (num19 <= 0f)
						{
							continue;
						}
						int num20 = (int)(num19 * (float)(int)val5.a);
						if (num20 > 0)
						{
							float num21 = (drawOutline ? (num18 / num19) : 1f);
							byte b = (byte)((float)(int)val5.r * num21);
							byte b2 = (byte)((float)(int)val5.g * num21);
							byte b3 = (byte)((float)(int)val5.b * num21);
							int num22 = num13 + k;
							Color32 val7 = output[num22];
							if (num20 >= 255)
							{
								output[num22] = new Color32(b, b2, b3, byte.MaxValue);
								continue;
							}
							int num23 = 255 - num20;
							output[num22] = new Color32((byte)((b * num20 + val7.r * num23) / 255), (byte)((b2 * num20 + val7.g * num23) / 255), (byte)((b3 * num20 + val7.b * num23) / 255), byte.MaxValue);
						}
					}
				}
			}
		}

		private static Color32[] GetCachedAtlasPixels(Texture2D src)
		{
			if ((Object)(object)src == (Object)null)
			{
				return null;
			}
			if (_atlasCache.TryGetValue(src, out var value))
			{
				return value;
			}
			Color32[] array = ReadPixelsSafe(src);
			_atlasCache[src] = array;
			return array;
		}

		private static Color32[] ReadPixelsSafe(Texture2D src)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			if ((Object)(object)src == (Object)null)
			{
				return null;
			}
			try
			{
				return src.GetPixels32();
			}
			catch
			{
				RenderTexture temporary = RenderTexture.GetTemporary(((Texture)src).width, ((Texture)src).height, 0, (RenderTextureFormat)0);
				Graphics.Blit((Texture)(object)src, temporary);
				RenderTexture active = RenderTexture.active;
				RenderTexture.active = temporary;
				Texture2D val = new Texture2D(((Texture)src).width, ((Texture)src).height, (TextureFormat)4, false);
				val.ReadPixels(new Rect(0f, 0f, (float)((Texture)src).width, (float)((Texture)src).height), 0, 0);
				val.Apply();
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				Color32[] pixels = val.GetPixels32();
				Object.Destroy((Object)val);
				return pixels;
			}
		}

		internal static void RasterizeTmpInto(Color32[] buf, int w, int h, TMP_Text tmp, bool forceMeshUpdate = true, bool drawOutline = false)
		{
			BlitText(buf, w, h, 0f, 0f, w, h, tmp, forceMeshUpdate, drawOutline);
		}

		internal static void BlitSpriteInto(Color32[] buf, int w, int h, Sprite sprite, Color32 tint, float centerPx, float centerPyBottom, float widthPx, float heightPx)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: 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_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: 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)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)sprite == (Object)null || buf == null || widthPx < 1f || heightPx < 1f)
			{
				return;
			}
			Rect textureRect = sprite.textureRect;
			int num = Mathf.RoundToInt(((Rect)(ref textureRect)).x);
			int num2 = Mathf.RoundToInt(((Rect)(ref textureRect)).y);
			int num3 = Mathf.RoundToInt(((Rect)(ref textureRect)).width);
			int num4 = Mathf.RoundToInt(((Rect)(ref textureRect)).height);
			if (num3 <= 0 || num4 <= 0)
			{
				return;
			}
			Color32[] cachedAtlasPixels = GetCachedAtlasPixels(sprite.texture);
			if (cachedAtlasPixels == null)
			{
				return;
			}
			int width = ((Texture)sprite.texture).width;
			int num5 = Mathf.Max(1, Mathf.RoundToInt(widthPx));
			int num6 = Mathf.Max(1, Mathf.RoundToInt(heightPx));
			int num7 = num5 / 2;
			int num8 = num6 / 2;
			int num9 = Mathf.RoundToInt(centerPx);
			int num10 = Mathf.RoundToInt(centerPyBottom);
			if (num9 + num7 < 0 || num9 - num7 >= w || num10 + num8 < 0 || num10 - num8 >= h)
			{
				return;
			}
			float num11 = (float)num3 / (float)num5;
			float num12 = (float)num4 / (float)num6;
			for (int i = 0; i < num6; i++)
			{
				int num13 = num10 - num8 + i;
				if (num13 < 0 || num13 >= h)
				{
					continue;
				}
				int num14 = Mathf.Clamp((int)((float)i * num12), 0, num4 - 1);
				int num15 = (num2 + num14) * width + num;
				int num16 = num13 * w;
				for (int j = 0; j < num5; j++)
				{
					int num17 = num9 - num7 + j;
					if (num17 < 0 || num17 >= w)
					{
						continue;
					}
					int num18 = Mathf.Clamp((int)((float)j * num11), 0, num3 - 1);
					Color32 val = cachedAtlasPixels[num15 + num18];
					int num19 = val.a * tint.a / 255;
					if (num19 != 0)
					{
						int num20 = val.r * tint.r / 255;
						int num21 = val.g * tint.g / 255;
						int num22 = val.b * tint.b / 255;
						int num23 = num16 + num17;
						if (num19 >= 250)
						{
							buf[num23] = new Color32((byte)num20, (byte)num21, (byte)num22, byte.MaxValue);
							continue;
						}
						Color32 val2 = buf[num23];
						int num24 = 255 - num19;
						buf[num23] = new Color32((byte)((num20 * num19 + val2.r * num24) / 255), (byte)((num21 * num19 + val2.g * num24) / 255), (byte)((num22 * num19 + val2.b * num24) / 255), byte.MaxValue);
					}
				}
			}
		}

		internal static void ClearLabelAtlasCache()
		{
			_atlasCache.Clear();
		}

		private static byte[] Encode(Color32[] output, int outputWidth, int outputHeight)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0022: Expected O, but got Unknown
			Texture2D val = new Texture2D(outputWidth, outputHeight, (TextureFormat)3, false);
			val.SetPixels32(output);
			val.Apply();
			byte[] result = ImageConversion.EncodeToPNG(val);
			Object.Destroy((Object)val);
			return result;
		}
	}
	internal sealed class MapStyleContext
	{
		private static readonly Color32 Parchment = new Color32((byte)203, (byte)155, (byte)87, byte.MaxValue);

		public int OutWidth;

		public int OutHeight;

		public bool Failed;

		public string Error;

		public Color32[] Result;

		private Plugin.MapStyleMode _style;

		private int _srcSize;

		private float _waterLevel;

		private Color32 _heathColor;

		private Color32[] _srcBiome;

		private float[] _srcHeight;

		private bool[] _srcExplored;

		private float _u0;

		private float _v0;

		private float _u1;

		private float _v1;

		private int _width;

		private int _height;

		private float _shadowScale;

		private Color32[] _biomeLayer;

		private Color32[] _biomeNearest;

		private Color32[] _heightLayer;

		private Color32[] _fogLayer;

		private float[] _shallowField;

		private static readonly Color32 BiomeEdge = new Color32((byte)35, (byte)25, (byte)18, (byte)235);

		private static readonly Color32 ShallowWater = new Color32((byte)155, (byte)215, (byte)230, byte.MaxValue);

		private float GrainTightness => (float)Mathf.Max(_width, _height) / 16f;

		public static MapStyleContext CaptureLayers(Rect uvRect, int outWidth, int outHeight)
		{
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			if (outWidth < 64 || outHeight < 64)
			{
				return null;
			}
			Minimap instance = Minimap.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return null;
			}
			ZoneSystem instance2 = ZoneSystem.instance;
			if ((Object)(object)instance2 == (Object)null)
			{
				return null;
			}
			int textureSize = instance.m_textureSize;
			if (textureSize <= 0)
			{
				return null;
			}
			int num = textureSize * textureSize;
			float num2 = Mathf.Clamp01(((Rect)(ref uvRect)).xMin);
			float num3 = Mathf.Clamp01(((Rect)(ref uvRect)).yMin);
			float num4 = Mathf.Clamp01(((Rect)(ref uvRect)).xMax);
			float num5 = Mathf.Clamp01(((Rect)(ref uvRect)).yMax);
			if (num4 - num2 < 1E-05f || num5 - num3 < 1E-05f)
			{
				return null;
			}
			Texture2D mapTexture = instance.m_mapTexture;
			Texture2D heightTexture = instance.m_heightTexture;
			bool[] explored = instance.m_explored;
			if ((Object)(object)mapTexture == (Object)null || (Object)(object)heightTexture == (Object)null || explored == null)
			{
				return null;
			}
			if (explored.Length < num)
			{
				return null;
			}
			Color32[] pixels = mapTexture.GetPixels32();
			if (pixels.Length < num)
			{
				return null;
			}
			Color[] pixels2 = heightTexture.GetPixels();
			if (pixels2.Length < num)
			{
				return null;
			}
			float[] array = new float[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = pixels2[i].r;
			}
			bool[] exploredOthers = instance.m_exploredOthers;
			bool flag = exploredOthers != null && exploredOthers.Length >= num;
			bool[] array2 = new bool[num];
			for (int j = 0; j < num; j++)
			{
				array2[j] = explored[j] || (flag && exploredOthers[j]);
			}
			ModLog.Info($"[NoMapDiscordAdditions] Map style: source {textureSize}px, viewport " + $"{(num4 - num2) * 100f:F0}%x{(num5 - num3) * 100f:F0}% -> {outWidth}x{outHeight} output.");
			return new MapStyleContext
			{
				_style = Plugin.MapStyle.Value,
				_srcSize = textureSize,
				_srcBiome = pixels,
				_srcHeight = array,
				_srcExplored = array2,
				_waterLevel = instance2.m_waterLevel,
				_heathColor = Color32.op_Implicit(instance.m_heathColor),
				_u0 = num2,
				_v0 = num3,
				_u1 = num4,
				_v1 = num5,
				OutWidth = outWidth,
				OutHeight = outHeight
			};
		}

		public void RunPipeline()
		{
			try
			{
				_width = OutWidth;
				_height = OutHeight;
				_shadowScale = (float)Mathf.Max(_width, _height) / 2048f;
				_biomeLayer = SampleColour(_srcBiome, _srcSize);
				_biomeNearest = SampleColourNearest(_srcBiome, _srcSize);
				_heightLayer = SampleHeight(_srcHeight, _srcSize, _waterLevel);
				_fogLayer = SampleFog(_srcExplored, _srcSize);
				float num = (float)_width / Mathf.Max(1f, (_u1 - _u0) * (float)_srcSize);
				int radius = Mathf.Clamp(Mathf.RoundToInt(num * 0.35f), 1, 28);
				_biomeLayer = BlurBiomeColours(_biomeLayer, radius);
				_biomeLayer = BlurBiomeColours(_biomeLayer, radius);
				int radius2 = Mathf.Clamp(Mathf.RoundToInt(num * 0.8f), 2, 48);
				_shallowField = BuildShallowField(radius2);
				switch (_style)
				{
				case Plugin.MapStyleMode.Chart:
					Result = GenerateChartMap();
					break;
				case Plugin.MapStyleMode.Topographical:
					Result = GenerateTopographicalMap();
					break;
				case Plugin.MapStyleMode.Satellite:
					Result = GenerateSatelliteImage();
					break;
				default:
					Result = GenerateOldMap();
					break;
				}
			}
			catch (Exception ex)
			{
				Failed = true;
				Error = ex.Message;
				Result = null;
			}
		}

		private Color32[] SampleColour(Color32[] src, int srcSize)
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[_width * _height];
			for (int i = 0; i < _height; i++)
			{
				float num = (_v0 + ((float)i + 0.5f) / (float)_height * (_v1 - _v0)) * (float)srcSize - 0.5f;
				int num2 = Mathf.Clamp(Mathf.FloorToInt(num), 0, srcSize - 1);
				int num3 = Mathf.Min(num2 + 1, srcSize - 1);
				float num4 = Mathf.Clamp01(num - (float)num2);
				int num5 = i * _width;
				for (int j = 0; j < _width; j++)
				{
					float num6 = (_u0 + ((float)j + 0.5f) / (float)_width * (_u1 - _u0)) * (float)srcSize - 0.5f;
					int num7 = Mathf.Clamp(Mathf.FloorToInt(num6), 0, srcSize - 1);
					int num8 = Mathf.Min(num7 + 1, srcSize - 1);
					float num9 = Mathf.Clamp01(num6 - (float)num7);
					Color val = Color32.op_Implicit(src[num2 * srcSize + num7]);
					Color val2 = Color32.op_Implicit(src[num2 * srcSize + num8]);
					Color val3 = Color32.op_Implicit(src[num3 * srcSize + num7]);
					Color val4 = Color32.op_Implicit(src[num3 * srcSize + num8]);
					array[num5 + j] = Color32.op_Implicit(Color.Lerp(Color.Lerp(val, val2, num9), Color.Lerp(val3, val4, num9), num4));
				}
			}
			return array;
		}

		private Color32[] SampleColourNearest(Color32[] src, int srcSize)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[_width * _height];
			for (int i = 0; i < _height; i++)
			{
				int num = Mathf.Clamp((int)((_v0 + ((float)i + 0.5f) / (float)_height * (_v1 - _v0)) * (float)srcSize), 0, srcSize - 1) * srcSize;
				int num2 = i * _width;
				for (int j = 0; j < _width; j++)
				{
					int num3 = Mathf.Clamp((int)((_u0 + ((float)j + 0.5f) / (float)_width * (_u1 - _u0)) * (float)srcSize), 0, srcSize - 1);
					array[num2 + j] = src[num + num3];
				}
			}
			return array;
		}

		private Color32[] SampleHeight(float[] src, int srcSize, float waterLevel)
		{
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[_width * _height];
			for (int i = 0; i < _height; i++)
			{
				float num = (_v0 + ((float)i + 0.5f) / (float)_height * (_v1 - _v0)) * (float)srcSize - 0.5f;
				int num2 = Mathf.Clamp(Mathf.FloorToInt(num), 0, srcSize - 1);
				int num3 = Mathf.Min(num2 + 1, srcSize - 1);
				float num4 = Mathf.Clamp01(num - (float)num2);
				int num5 = i * _width;
				for (int j = 0; j < _width; j++)
				{
					float num6 = (_u0 + ((float)j + 0.5f) / (float)_width * (_u1 - _u0)) * (float)srcSize - 0.5f;
					int num7 = Mathf.Clamp(Mathf.FloorToInt(num6), 0, srcSize - 1);
					int num8 = Mathf.Min(num7 + 1, srcSize - 1);
					float num9 = Mathf.Clamp01(num6 - (float)num7);
					float num10 = Mathf.Lerp(src[num2 * srcSize + num7], src[num2 * srcSize + num8], num9);
					float num11 = Mathf.Lerp(src[num3 * srcSize + num7], src[num3 * srcSize + num8], num9);
					float num12 = Mathf.Lerp(num10, num11, num4) - waterLevel;
					if (num12 > 0f)
					{
						array[num5 + j] = new Color32((byte)Mathf.Clamp(Mathf.RoundToInt(num12 / 512f * 255f), 0, 255), (byte)0, (byte)0, byte.MaxValue);
					}
					else
					{
						array[num5 + j] = new Color32((byte)0, (byte)0, (byte)Mathf.Clamp(Mathf.RoundToInt((0f - num12) / 256f * 255f), 0, 255), byte.MaxValue);
					}
				}
			}
			return array;
		}

		private Color32[] SampleFog(bool[] explored, int srcSize)
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[_width * _height];
			Color32 val = default(Color32);
			((Color32)(ref val))..ctor((byte)128, (byte)128, (byte)128, byte.MaxValue);
			for (int i = 0; i < _height; i++)
			{
				int num = Mathf.Clamp((int)((_v0 + ((float)i + 0.5f) / (float)_height * (_v1 - _v0)) * (float)srcSize), 0, srcSize - 1) * srcSize;
				int num2 = i * _width;
				for (int j = 0; j < _width; j++)
				{
					int num3 = Mathf.Clamp((int)((_u0 + ((float)j + 0.5f) / (float)_width * (_u1 - _u0)) * (float)srcSize), 0, srcSize - 1);
					if (!explored[num + num3])
					{
						array[num2 + j] = val;
					}
				}
			}
			return array;
		}

		private Color32[] BlurBiomeColours(Color32[] src, int radius)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			if (radius < 1)
			{
				return src;
			}
			int num = _width * _height;
			float[] array = new float[num];
			float[] array2 = new float[num];
			float[] array3 = new float[num];
			float[] array4 = new float[num];
			for (int i = 0; i < _height; i++)
			{
				int num2 = i * _width;
				float num3 = 0f;
				float num4 = 0f;
				float num5 = 0f;
				float num6 = 0f;
				for (int j = -radius; j <= radius; j++)
				{
					int num7 = num2 + Mathf.Clamp(j, 0, _width - 1);
					if (_heightLayer[num7].b <= 0)
					{
						Color32 val = src[num7];
						num3 += (float)(int)val.r;
						num4 += (float)(int)val.g;
						num5 += (float)(int)val.b;
						num6 += 1f;
					}
				}
				array[num2] = num3;
				array2[num2] = num4;
				array3[num2] = num5;
				array4[num2] = num6;
				for (int k = 1; k < _width; k++)
				{
					int num8 = num2 + Mathf.Clamp(k + radius, 0, _width - 1);
					int num9 = num2 + Mathf.Clamp(k - radius - 1, 0, _width - 1);
					if (_heightLayer[num8].b <= 0)
					{
						Color32 val2 = src[num8];
						num3 += (float)(int)val2.r;
						num4 += (float)(int)val2.g;
						num5 += (float)(int)val2.b;
						num6 += 1f;
					}
					if (_heightLayer[num9].b <= 0)
					{
						Color32 val3 = src[num9];
						num3 -= (float)(int)val3.r;
						num4 -= (float)(int)val3.g;
						num5 -= (float)(int)val3.b;
						num6 -= 1f;
					}
					int num10 = num2 + k;
					array[num10] = num3;
					array2[num10] = num4;
					array3[num10] = num5;
					array4[num10] = num6;
				}
			}
			Color32[] array5 = (Color32[])src.Clone();
			for (int l = 0; l < _width; l++)
			{
				float num11 = 0f;
				float num12 = 0f;
				float num13 = 0f;
				float num14 = 0f;
				for (int m = -radius; m <= radius; m++)
				{
					int num15 = Mathf.Clamp(m, 0, _height - 1) * _width + l;
					num11 += array[num15];
					num12 += array2[num15];
					num13 += array3[num15];
					num14 += array4[num15];
				}
				if (_heightLayer[l].b <= 0 && num14 > 0f)
				{
					array5[l] = new Color32((byte)(num11 / num14), (byte)(num12 / num14), (byte)(num13 / num14), byte.MaxValue);
				}
				for (int n = 1; n < _height; n++)
				{
					int num16 = Mathf.Clamp(n + radius, 0, _height - 1) * _width + l;
					int num17 = Mathf.Clamp(n - radius - 1, 0, _height - 1) * _width + l;
					num11 += array[num16] - array[num17];
					num12 += array2[num16] - array2[num17];
					num13 += array3[num16] - array3[num17];
					num14 += array4[num16] - array4[num17];
					int num18 = n * _width + l;
					if (_heightLayer[num18].b <= 0 && num14 > 0f)
					{
						array5[num18] = new Color32((byte)(num11 / num14), (byte)(num12 / num14), (byte)(num13 / num14), byte.MaxValue);
					}
				}
			}
			return array5;
		}

		private float[] BuildShallowField(int radius)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			int num = _width * _height;
			float[] array = new float[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = (IsOceanBiome(_biomeNearest[i]) ? 0f : 1f);
			}
			array = BoxBlur(array, radius);
			return BoxBlur(array, radius);
		}

		private Color32[] GenerateOldMap()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = GenerateOceanTexture(_heightLayer, clear: false);
			Color32[] array2 = ReplaceColour(_biomeLayer, new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue), Parchment);
			array2 = OverlayTexture(array2, array);
			Color32[] solidColour = GetSolidColour(Parchment);
			array2 = LerpTextures(array2, solidColour);
			array2 = LerpTextures(array2, solidColour);
			array2 = LerpTextures(array2, solidColour);
			array2 = AddPerlinNoise(array2, GrainTightness, 16f);
			Color32[] array3 = GenerateContourMap(_heightLayer, 8, 128);
			array2 = OverlayTexture(array2, array3);
			Color32[] array4 = StylizeFog(_fogLayer);
			array2 = OverlayTexture(array2, array4);
			return SmoothImage(array2);
		}

		private Color32[] GenerateChartMap()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = GenerateOceanTexture(_heightLayer, clear: false);
			Color32[] array2 = ReplaceColour(_biomeLayer, new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue), Parchment);
			array2 = OverlayTexture(array2, array);
			Color32[] solidColour = GetSolidColour(Parchment);
			array2 = LerpTextures(array2, solidColour);
			array2 = AddPerlinNoise(array2, GrainTightness, 16f);
			Color32[] array3 = GenerateContourMap(_heightLayer, 10, 128);
			array2 = OverlayTexture(array2, array3);
			Color32[] array4 = StylizeFog(_fogLayer);
			return OverlayTexture(array2, array4);
		}

		private Color32[] GenerateTopographicalMap()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Color32[] input = GenerateOceanTexture(_heightLayer, clear: true);
			input = AddPerlinNoise(input, GrainTightness / 16f, 64f);
			Color32[] input2 = CreateSand();
			input2 = ReplaceColour(input2, new Color32((byte)51, (byte)51, (byte)51, byte.MaxValue), new Color32((byte)65, (byte)75, (byte)70, byte.MaxValue));
			Color32[] array = OverlayTexture(input2, input);
			Color32[] array2 = CreateShadowMap(_heightLayer, 23);
			array = DarkenTextureLinear(array, 20);
			Color32[] array3 = GenerateContourMap(_heightLayer, 8, 128);
			array = OverlayTexture(array, array2);
			array = OverlayTexture(array, array3);
			Color32[] array4 = StylizeFog(_fogLayer);
			array = OverlayTexture(array, array4);
			return SmoothImage(array);
		}

		private Color32[] GenerateSatelliteImage()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Color32[] input = GenerateOceanTexture(_heightLayer, clear: true);
			input = AddPerlinNoise(input, GrainTightness / 16f, 64f);
			Color32[] input2 = CreateSand();
			input2 = ReplaceColour(input2, new Color32((byte)51, (byte)51, (byte)51, byte.MaxValue), new Color32((byte)65, (byte)75, (byte)70, byte.MaxValue));
			Color32[] array = OverlayTexture(input2, input);
			Color32[] array2 = CreateShadowMap(_heightLayer, 23);
			array = DarkenTextureLinear(array, 20);
			array = OverlayTexture(array, array2);
			Color32[] array3 = StylizeFog(_fogLayer);
			array = OverlayTexture(array, array3);
			return SmoothImage(array);
		}

		private Color32[] GenerateOceanTexture(Color32[] height, bool clear)
		{
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[_width * _height];
			for (int i = 0; i < _height; i++)
			{
				int num = Mathf.RoundToInt((_v0 + ((float)i + 0.5f) / (float)_height * (_v1 - _v0)) * 256f) - 128;
				int num2 = i * _width;
				for (int j = 0; j < _width; j++)
				{
					int num3 = num2 + j;
					if (height[num3].b > 0)
					{
						int num4 = Mathf.RoundToInt((_u0 + ((float)j + 0.5f) / (float)_width * (_u1 - _u0)) * 256f) - 128;
						int num5 = num * num / 128 + num4 * num4 / 512;
						Color32 val = ((num < 0) ? new Color32((byte)(10 + num5), (byte)(136 - num5 / 4), (byte)193, byte.MaxValue) : new Color32((byte)(10 + num5 / 2), (byte)136, (byte)(193 - num5 / 2), byte.MaxValue));
						float num6 = _shallowField[num3];
						if (num6 > 0f)
						{
							val = Color32.Lerp(val, ShallowWater, 0.5f * num6);
						}
						if (clear)
						{
							int num7 = Mathf.Min(height[num3].b * 16 + 128, 255);
							array[num3] = new Color32(val.r, val.g, val.b, (byte)num7);
						}
						else
						{
							array[num3] = new Color32(val.r, val.g, val.b, byte.MaxValue);
						}
					}
				}
			}
			return array;
		}

		private Color32[] CreateSand()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			int num = _width * _height;
			Color32[] array = (Color32[])(object)new Color32[num];
			for (int i = 0; i < num; i++)
			{
				if (_heightLayer[i].b > 0)
				{
					Color32 val = _biomeLayer[i];
					if (val.r != 0 && val.g != 0 && val.b != 0)
					{
						array[i] = _heathColor;
					}
				}
				else
				{
					array[i] = _biomeLayer[i];
				}
			}
			return array;
		}

		private Color32[] ReplaceColour(Color32[] input, Color32 from, Color32 to)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0041: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[input.Length];
			for (int i = 0; i < input.Length; i++)
			{
				Color32 val = input[i];
				array[i] = ((val.r == from.r && val.g == from.g && val.b == from.b) ? to : val);
			}
			return array;
		}

		private Color32[] GetSolidColour(Color32 colour)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			int num = _width * _height;
			Color32[] array = (Color32[])(object)new Color32[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = colour;
			}
			return array;
		}

		private Color32[] OverlayTexture(Color32[] array1, Color32[] array2)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			int num = _width * _height;
			Color32[] array3 = (Color32[])(object)new Color32[num];
			for (int i = 0; i < num; i++)
			{
				Color val = Color32.op_Implicit(array1[i]);
				Color val2 = Color32.op_Implicit(array2[i]);
				float a = val2.a;
				float a2 = val.a;
				Color val3 = Color.Lerp(val, val2, a);
				val3.a = Mathf.Min(a + a2, 1f);
				array3[i] = Color32.op_Implicit(val3);
			}
			return array3;
		}

		private Color32[] LerpTextures(Color32[] array1, Color32[] array2)
		{
			//IL_0097: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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)
			int num = _width * _height;
			Color32[] array3 = (Color32[])(object)new Color32[num];
			for (int i = 0; i < num; i++)
			{
				int num2 = array2[i].a - array1[i].a;
				int num3 = Mathf.Min(array1[i].a + array2[i].a, 255);
				int num4 = Mathf.Max((int)array1[i].a, (int)array2[i].a) * 2;
				float num5 = ((num4 == 0) ? 0.5f : ((float)num2 / (float)num4 + 0.5f));
				Color32 val = Color32.Lerp(array1[i], array2[i], num5);
				val.a = (byte)num3;
				array3[i] = val;
			}
			return array3;
		}

		private Color32[] DarkenTextureLinear(Color32[] array, byte d)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			int num = _width * _height;
			Color32[] array2 = (Color32[])(object)new Color32[num];
			for (int i = 0; i < num; i++)
			{
				Color32 val = array[i];
				array2[i] = new Color32((byte)Mathf.Max(val.r - d, 0), (byte)Mathf.Max(val.g - d, 0), (byte)Mathf.Max(val.b - d, 0), val.a);
			}
			return array2;
		}

		private Color32[] AddPerlinNoise(Color32[] input, float tightness, float damping)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[_width * _height];
			for (int i = 0; i < _height; i++)
			{
				for (int j = 0; j < _width; j++)
				{
					int num = i * _width + j;
					Color val = Color32.op_Implicit(input[num]);
					float num2 = Mathf.PerlinNoise((float)i / tightness, (float)j / tightness);
					num2 = (num2 - 0.5f) / damping;
					array[num] = Color32.op_Implicit(new Color(val.r + num2, val.g + num2, val.b + num2, val.a));
				}
			}
			return array;
		}

		private Color32[] GetPerlin(float tightness, float damping)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[_width * _height];
			for (int i = 0; i < _height; i++)
			{
				for (int j = 0; j < _width; j++)
				{
					float num = Mathf.PerlinNoise((float)i / tightness, (float)j / tightness);
					num = (num - 0.5f) / damping + 0.5f;
					array[i * _width + j] = Color32.op_Implicit(new Color(num, num, num, 0.2f));
				}
			}
			return array;
		}

		private Color32[] StylizeFog(Color32[] fog)
		{
			//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)
			Color32[] perlin = GetPerlin(GrainTightness, 16f);
			int num = _width * _height;
			Color32[] array = (Color32[])(object)new Color32[num];
			for (int i = 0; i < num; i++)
			{
				if (fog[i].a > 0)
				{
					array[i] = new Color32((byte)(203 + (perlin[i].r - 128)), (byte)(155 + (perlin[i].g - 128)), (byte)(87 + (perlin[i].b - 128)), byte.MaxValue);
				}
			}
			return array;
		}

		private Color32[] CreateShadowMap(Color32[] heightmap, byte intensity)
		{
			Color32[] array = CreateHardShadowMap(heightmap, intensity);
			Color32[] array2 = CreateSoftShadowMap(heightmap);
			return LerpTextures(array2, array);
		}

		private Color32[] CreateSoftShadowMap(Color32[] input)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[_width * _height];
			for (int i = 0; i < _height; i++)
			{
				for (int j = 0; j < _width; j++)
				{
					int num = 0;
					if (i < _height - 1)
					{
						num = (int)((float)(input[i * _width + j].r - input[(i + 1) * _width + j].r) * _shadowScale * 8f);
					}
					byte b = (byte)Mathf.Abs(num);
					byte b2 = (byte)((num >= 0) ? 255u : 0u);
					array[i * _width + j] = new Color32(b2, b2, b2, b);
				}
			}
			return array;
		}

		private Color32[] CreateHardShadowMap(Color32[] input, byte intensity)
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			int num = _width * _height;
			Color32[] array = (Color32[])(object)new Color32[num];
			bool[] array2 = new bool[num];
			for (int num2 = _height - 1; num2 > -1; num2--)
			{
				for (int i = 0; i < _width; i++)
				{
					int num3 = num2 * _width + i;
					if (!array2[num3])
					{
						array[num3] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)0);
						for (int j = 1; num2 - j > 0 && (float)(int)input[num3].r * _shadowScale > (float)(int)input[(num2 - j) * _width + i].r * _shadowScale + (float)(j * 2); j++)
						{
							array2[(num2 - j) * _width + i] = true;
						}
					}
					else
					{
						array[num3] = new Color32((byte)0, (byte)0, (byte)0, intensity);
					}
				}
			}
			return array;
		}

		private Color32[] GenerateContourMap(Color32[] start, int graduations, byte alpha)
		{
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			int num = _width * _height;
			Color32[] array = (Color32[])(object)new Color32[num];
			Color32[] array2 = (Color32[])(object)new Color32[num];
			for (int i = 0; i < num; i++)
			{
				int num2 = start[i].r + graduations;
				if (num2 > 255)
				{
					num2 = 255;
				}
				if (start[i].b > 0)
				{
					num2 = 0;
				}
				array[i].r = (byte)num2;
			}
			for (int j = 1; j < _height - 1; j++)
			{
				int num3 = j * _width;
				for (int k = 1; k < _width - 1; k++)
				{
					int num4 = num3 + k;
					int num5 = array[num4].r / graduations;
					for (int l = -1; l < 2; l++)
					{
						int num6 = l * _width;
						for (int m = -1; m < 2; m++)
						{
							if (l == 0 && m == 0)
							{
								continue;
							}
							int num7 = array[num4 + num6 + m].r / graduations;
							if (num7 < num5)
							{
								byte b = alpha;
								if ((num5 - 1) / 5 == (num7 - 1) / 5)
								{
									b /= 2;
								}
								if (num7 == 0)
								{
									b = alpha;
								}
								if (l == 0 || m == 0 || array2[num4].a == b)
								{
									array2[num4] = new Color32((byte)0, (byte)0, (byte)0, b);
									break;
								}
								array2[num4] = new Color32((byte)0, (byte)0, (byte)0, (byte)(b / 2));
							}
						}
					}
				}
			}
			return array2;
		}

		private Color32[] GenerateBiomeEdges(Color32[] biome)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			int num = _width * _height;
			float[] array = new float[num];
			for (int i = 1; i < _height - 1; i++)
			{
				int num2 = i * _width;
				for (int j = 1; j < _width - 1; j++)
				{
					int num3 = num2 + j;
					if (_heightLayer[num3].b <= 0)
					{
						Color32 c = biome[num3];
						if (LandBiomeDiffers(c, biome, num3 - 1) || LandBiomeDiffers(c, biome, num3 + 1) || LandBiomeDiffers(c, biome, num3 - _width) || LandBiomeDiffers(c, biome, num3 + _width))
						{
							array[num3] = 1f;
						}
					}
				}
			}
			array = BoxBlur(array, 2);
			array = BoxBlur(array, 2);
			float num4 = 0f;
			for (int k = 0; k < num; k++)
			{
				if (array[k] > num4)
				{
					num4 = array[k];
				}
			}
			if (num4 <= 0f)
			{
				return (Color32[])(object)new Color32[num];
			}
			float num5 = 1f / num4;
			Color32[] array2 = (Color32[])(object)new Color32[num];
			for (int l = 0; l < num; l++)
			{
				if (!(array[l] <= 0f))
				{
					float num6 = Mathf.Clamp01((array[l] * num5 - 0.5f) / 0.4f);
					num6 = num6 * num6 * (3f - 2f * num6);
					if (!(num6 <= 0f))
					{
						array2[l] = new Color32(BiomeEdge.r, BiomeEdge.g, BiomeEdge.b, (byte)(num6 * (float)(int)BiomeEdge.a));
					}
				}
			}
			return array2;
		}

		private float[] BoxBlur(float[] src, int radius)
		{
			int num = _width * _height;
			float num2 = 1f / (float)(2 * radius + 1);
			float[] array = new float[num];
			for (int i = 0; i < _height; i++)
			{
				int num3 = i * _width;
				for (int j = 0; j < _width; j++)
				{
					float num4 = 0f;
					for (int k = -radius; k <= radius; k++)
					{
						num4 += src[num3 + Mathf.Clamp(j + k, 0, _width - 1)];
					}
					array[num3 + j] = num4 * num2;
				}
			}
			float[] array2 = new float[num];
			for (int l = 0; l < _height; l++)
			{
				for (int m = 0; m < _width; m++)
				{
					float num5 = 0f;
					for (int n = -radius; n <= radius; n++)
					{
						num5 += array[Mathf.Clamp(l + n, 0, _height - 1) * _width + m];
					}
					array2[l * _width + m] = num5 * num2;
				}
			}
			return array2;
		}

		private bool LandBiomeDiffers(Color32 c, Color32[] biome, int nIdx)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002c: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (_heightLayer[nIdx].b > 0)
			{
				return false;
			}
			Color32 val = biome[nIdx];
			if (c.r == val.r && c.g == val.g)
			{
				return c.b != val.b;
			}
			return true;
		}

		private static bool IsOceanBiome(Color32 c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (c.r == byte.MaxValue && c.g == byte.MaxValue)
			{
				return c.b == byte.MaxValue;
			}
			return false;
		}

		private Color32[] SmoothImage(Color32[] input)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])input.Clone();
			for (int i = 1; i < _height - 1; i++)
			{
				for (int j = 1; j < _width - 1; j++)
				{
					int num = i * _width + j;
					Color32 val = input[num - _width];
					Color32 val2 = input[num + 1];
					Color32 val3 = input[num + _width];
					Color32 val4 = input[num - 1];
					Color32 val5 = Color32.Lerp(val2, val4, 0.5f);
					Color32 val6 = Color32.Lerp(val, val3, 0.5f);
					Color32 val7 = Color32.Lerp(val5, val6, 0.5f);
					array[num] = Color32.Lerp(input[num], val7, 0.5f);
				}
			}
			return array;
		}
	}
	public static class MapStyleRender
	{
		public static bool IsStyleActive()
		{
			if (Plugin.MapStyle != null)
			{
				return Plugin.MapStyle.Value != Plugin.MapStyleMode.None;
			}
			return false;
		}

		public static IEnumerator BuildAsync(Rect uvRect, int width, int height, Action<Texture2D> onDone)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if (!IsStyleActive())
			{
				onDone(null);
				yield break;
			}
			MapStyleContext ctx;
			try
			{
				ctx = MapStyleContext.CaptureLayers(uvRect, width, height);
			}
			catch (Exception ex)
			{
				ModLog.Warn("[NoMapDiscordAdditions] Map style: layer capture failed: " + ex.Message);
				ctx = null;
			}
			if (ctx == null)
			{
				onDone(null);
				yield break;
			}
			Thread thread = new Thread(ctx.RunPipeline)
			{
				IsBackground = true,
				Name = "NMDA-MapStyle"
			};
			thread.Start();
			while (thread.IsAlive)
			{
				yield return null;
			}
			if (ctx.Failed || ctx.Result == null)
			{
				ModLog.Warn("[NoMapDiscordAdditions] Map style render failed, using normal capture" + (string.IsNullOrEmpty(ctx.Error) ? "." : (": " + ctx.Error)));
				onDone(null);
				yield break;
			}
			Texture2D obj;
			try
			{
				Texture2D val = new Texture2D(ctx.OutWidth, ctx.OutHeight, (TextureFormat)3, false)
				{
					wrapMode = (TextureWrapMode)1
				};
				val.SetPixels32(ctx.Result);
				val.Apply(false);
				obj = val;
			}
			catch (Exception ex2)
			{
				ModLog.Warn("[NoMapDiscordAdditions] Map style: texture upload failed: " + ex2.Message);
				obj = null;
			}
			onDone(obj);
		}
	}
	[HarmonyPatch]
	public static class MinimapPatch
	{
		[HarmonyPatch(typeof(Minimap), "Start")]
		[HarmonyAfter(new string[] { "ZenDragon.ZenMap" })]
		[HarmonyPostfix]
		private static void Minimap_Start_Postfix()
		{
			CaptureButton.Create();
			MapCompileButtons.Create();
		}

		[HarmonyPatch(typeof(Minimap), "ShowPointOnMap")]
		[HarmonyPostfix]
		private static void ShowPointOnMap_Postfix(Vector3 point)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if (ModHelpers.EffectiveConfig.AllowCompileFromMapItems)
			{
				MapCompileSession.SetActiveTable(point);
			}
		}

		[HarmonyPatch(typeof(Minimap), "UpdateDynamicPins")]
		[HarmonyAfter(new string[] { "ZenDragon.ZenMap" })]
		[HarmonyPostfix]
		private static void UpdateDynamicPins_ForceCaptionsDuringCapture(Minimap __instance)
		{
			if (!PinCaptureFilter.s_forceShowLabels)
			{
				return;
			}
			List<PinData> list = __instance?.m_pins;
			if (list == null)
			{
				return;
			}
			int count = list.Count;
			for (int i = 0; i < count; i++)
			{
				PinData val = list[i];
				if (val == null)
				{
					continue;
				}
				PinNameData namePinData = val.m_NamePinData;
				GameObject val2 = ((namePinData != null) ? namePinData.PinNameGameObject : null);
				if (!((Object)(object)val2 == (Object)null) && !string.IsNullOrEmpty(val.m_name))
				{
					PinNameData namePinData2 = val.m_NamePinData;
					TMP_Text val3 = ((namePinData2 != null) ? namePinData2.PinNameText : null);
					if ((!((Object)(object)val3 != (Object)null) || ((Behaviour)val3).enabled) && !val2.activeSelf)
					{
						val2.SetActive(true);
					}
				}
			}
		}

		[HarmonyPatch(typeof(Minimap), "SetMapMode")]
		[HarmonyPostfix]
		private static void SetMapMode_Postfix(MapMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			bool num = (int)mode == 2;
			CaptureButton.SetVisible(num);
			MapCompileButtons.SetVisible(num);
			if (!num)
			{
				MapCompileSession.ClearActiveTable();
				if (MapCompileResultPanel.IsVisible)
				{
					MapCompileResultPanel.HideKeepingResult();
				}
			}
			else if (MapCompileSession.CurrentState == MapCompileSession.State.Reviewing && !MapCompileResultPanel.IsVisible && !MapCompileResultPanel.HasPendingResult)
			{
				MapCompileSession.ReturnToCompiling();
				MapCompileButtons.SetVisible(visible: true);
			}
		}
	}
	internal static class ModHelpers
	{
		public static class EffectiveConfig
		{
			public static string WebhookUrl => Plugin.WebhookUrl?.Value;

			public static bool SpoilerImageData => Plugin.SpoilerImageData.Value;

			public static bool HideClouds => Plugin.HideClouds.Value;

			public static bool AllowCompileFromMapItems => Plugin.AllowCompileFromMapItems?.Value ?? true;

			public static string CompileMessageTemplate => Plugin.CompileMessageTemplate?.Value ?? "{player} compiled a map from {tileCount} cartography tables.";

			public static string MessageTemplate => Plugin.MessageTemplate?.Value ?? "{player} shared a map update from {biome}{table}";

			public static bool EnableCompileMapSharing => Plugin.EnableCompileMapSharing?.Value ?? true;

			public static string CompileShareMessageTemplate => Plugin.CompileShareMessageTemplate?.Value ?? "{player} shared {tileCount} map tile(s) for compile mode.";
		}

		public struct SavedLighting
		{
			public bool Active;

			public Vector4 SunDir;

			public Color SunColor;

			public Color Ambient;

			public Color SunFogColor;
		}

		public struct SavedShaderProp
		{
			public string Name;

			public ShaderPropertyType Type;

			public Texture Tex;

			public float Float;

			public Color Color;

			public Vector4 Vec;
		}

		private static readonly int _idSunDir = Shader.PropertyToID("_SunDir");

		private static readonly int _idSunColor = Shader.PropertyToID("_SunColor");

		private static readonly int _idAmbient = Shader.PropertyToID("_AmbientColor");

		private static readonly int _idSunFogColor = Shader.PropertyToID("_SunFogColor");

		public static SavedLighting OverrideLightingToNoon()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown r