Decompiled source of MageFlagImporter v1.5.0

MageFlagImporter.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DrawPixels_Done;
using HarmonyLib;
using MageConfigurationAPI.Data;
using MageConfigurationAPI.Enums;
using MageFlagImporter.Helpers;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("MageFlagImporter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MageFlagImporter")]
[assembly: AssemblyTitle("MageFlagImporter")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 MageFlagImporter
{
	[BepInProcess("MageArena")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.d1gq.mage.flag.importer", "MageFlagImporter", "1.5.0")]
	public class MFIPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.d1gq.mage.flag.importer";

		private const string PluginName = "MageFlagImporter";

		private const string VersionString = "1.5.0";

		private static Harmony? Harmony;

		private ManualLogSource? _log;

		internal static MFIPlugin Instance { get; private set; }

		internal static ManualLogSource Log => Instance._log;

		internal static ConfigEntry<bool> PresetModificationEnabled { get; private set; }

		internal static ConfigEntry<bool> SyncByPixels { get; private set; }

		internal static ConfigEntry<int> FlagPreset { get; private set; }

		internal static ConfigEntry<string> FlagDataPresetsString { get; private set; }

		internal static Dictionary<int, string> FlagDataDictionary { get; set; } = new Dictionary<int, string>();


		private void Awake()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			_log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Harmony = new Harmony("com.d1gq.mage.flag.importer");
			Harmony.PatchAll();
			LoadOptions();
			Log.LogInfo((object)"MageFlagImporter v1.5.0 loaded!");
		}

		private void LoadOptions()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			PresetModificationEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("MageFlagImporter", "PresetModificationEnabled", true, "If enabled, adds 10 different presets to save and load from, disabled if conflicting with other mods!");
			SyncByPixels = ((BaseUnityPlugin)this).Config.Bind<bool>("MageFlagImporter", "SyncByPixelsEnabled", false, "If enabled, when a image is done loading from file or disk, each pixel is individually synced via SyncPix RPC instead of ServerLoadFlag RPC. This is done due to ServerLoadFlag RPC having issues depending on device language!");
			FlagPreset = ((BaseUnityPlugin)this).Config.Bind<int>("MageFlagImporter", "FlagPreset", 0, new ConfigDescription("", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			FlagDataPresetsString = ((BaseUnityPlugin)this).Config.Bind<string>("MageFlagImporter", "FlagDataPresets", "", "This is a Dictionary<int, string> converted into a single string so it can be stored within the config file.");
			LoadDataPresets();
			new ModConfig((BaseUnityPlugin)(object)this, (ConfigEntryBase)(object)PresetModificationEnabled, (SettingsFlag)1);
			new ModConfig((BaseUnityPlugin)(object)this, (ConfigEntryBase)(object)SyncByPixels, (SettingsFlag)3);
		}

		private static void LoadDataPresets()
		{
			FlagDataDictionary.Clear();
			if (string.IsNullOrEmpty(FlagDataPresetsString.Value))
			{
				return;
			}
			string[] array = FlagDataPresetsString.Value.Split('|');
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split('=', 2);
				if (array3.Length == 2 && int.TryParse(array3[0], out var result))
				{
					FlagDataDictionary[result] = array3[1];
				}
			}
		}

		internal static void SaveFlagDataPresets()
		{
			FlagDataPresetsString.Value = string.Join("|", FlagDataDictionary.Select<KeyValuePair<int, string>, string>((KeyValuePair<int, string> kv) => $"{kv.Key}={kv.Value}"));
		}
	}
}
namespace MageFlagImporter.Patches.Game
{
	[HarmonyPatch(typeof(DrawPixels))]
	internal class DrawPixelsPatch
	{
		[HarmonyPatch("SaveFlagPermanently")]
		[HarmonyPrefix]
		private static bool SaveFlagPermanently_Prefix(DrawPixels __instance)
		{
			if (!MFIPlugin.PresetModificationEnabled.Value)
			{
				return true;
			}
			string value = __instance.SerializeGrid();
			MFIPlugin.FlagDataDictionary[MFIPlugin.FlagPreset.Value] = value;
			MFIPlugin.SaveFlagDataPresets();
			return false;
		}

		[HarmonyPatch("loadflag")]
		[HarmonyPrefix]
		private static bool loadflag_Prefix(DrawPixels __instance)
		{
			if (!MFIPlugin.PresetModificationEnabled.Value)
			{
				return true;
			}
			if (MFIPlugin.FlagDataDictionary.TryGetValue(MFIPlugin.FlagPreset.Value, out string value))
			{
				__instance.ServerLoadFlag(value);
			}
			return false;
		}

		[HarmonyPatch("ServerLoadFlag")]
		[HarmonyPrefix]
		private static bool ServerLoadFlag_Prefix(DrawPixels __instance, string flagdata)
		{
			if (!MFIPlugin.SyncByPixels.Value)
			{
				return true;
			}
			SyncByPixels(__instance, flagdata);
			return false;
		}

		private static void SyncByPixels(DrawPixels __instance, string serializedData)
		{
			//IL_0089: 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)
			if (string.IsNullOrEmpty(serializedData))
			{
				return;
			}
			Grid<PixelGridObject> grid = __instance.GetGrid();
			if (grid == null)
			{
				return;
			}
			int num = 0;
			int width = grid.GetWidth();
			int height = grid.GetHeight();
			string[] array = serializedData.Split(',');
			for (int i = 0; i < width; i++)
			{
				for (int j = 0; j < height; j++)
				{
					string[] array2 = array[num].Split(':');
					PixelGridObject gridObject = grid.GetGridObject(i, j);
					if (gridObject != null)
					{
						__instance.SyncPix(new Vector2(float.Parse(array2[0]), float.Parse(array2[1])), new Vector3((float)i, (float)j, 0f));
						num++;
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(DrawPixelsUI))]
	internal class DrawPixelsUIPatch
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__3_0;

			internal void <Awake_Prefix>b__3_0()
			{
				GameObject obj = GameObject.Find("t1draw/DrawPixels");
				DrawPixels val = ((obj != null) ? obj.GetComponent<DrawPixels>() : null);
				if (val == null)
				{
					GameObject obj2 = GameObject.Find("t2draw/DrawPixels");
					val = ((obj2 != null) ? obj2.GetComponent<DrawPixels>() : null);
				}
				if ((Object)(object)val != (Object)null)
				{
					Utils.ImportImageToPixelArt(val);
				}
			}
		}

		private static Button? loadFromImageButton;

		private static Button?[] PresetButtons = Array.Empty<Button>();

		private static (int min, int max) limit = (0, 10);

		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		private static void Awake_Prefix(DrawPixelsUI __instance)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			//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_013d: 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_014e: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Expected O, but got Unknown
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Expected O, but got Unknown
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Expected O, but got Unknown
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Expected O, but got Unknown
			if (!((Object)(object)loadFromImageButton == (Object)null))
			{
				return;
			}
			loadFromImageButton = Object.Instantiate<Button>(((Component)((Component)__instance).transform.Find("load")).gameObject.GetComponent<Button>(), ((Component)__instance).transform);
			((Object)loadFromImageButton).name = "loadFromImage";
			Vector3 localPosition = ((Component)loadFromImageButton).transform.localPosition;
			((Component)loadFromImageButton).transform.localPosition = new Vector3(localPosition.x, -0.9852f, localPosition.z);
			Text[] componentsInChildren = ((Component)loadFromImageButton).GetComponentsInChildren<Text>();
			foreach (Text val in componentsInChildren)
			{
				val.text = "Load from image file";
			}
			loadFromImageButton.onClick = new ButtonClickedEvent();
			ButtonClickedEvent onClick = loadFromImageButton.onClick;
			object obj = <>c.<>9__3_0;
			if (obj == null)
			{
				UnityAction val2 = delegate
				{
					GameObject obj2 = GameObject.Find("t1draw/DrawPixels");
					DrawPixels val8 = ((obj2 != null) ? obj2.GetComponent<DrawPixels>() : null);
					if (val8 == null)
					{
						GameObject obj3 = GameObject.Find("t2draw/DrawPixels");
						val8 = ((obj3 != null) ? obj3.GetComponent<DrawPixels>() : null);
					}
					if ((Object)(object)val8 != (Object)null)
					{
						Utils.ImportImageToPixelArt(val8);
					}
				};
				<>c.<>9__3_0 = val2;
				obj = (object)val2;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			TextMeshProUGUI val3 = Object.Instantiate<TextMeshProUGUI>(((Component)((Component)__instance).transform.Find("warnign")).gameObject.GetComponent<TextMeshProUGUI>(), ((Component)__instance).transform);
			((Object)val3).name = "warnign";
			Vector3 localPosition2 = ((TMP_Text)val3).transform.localPosition;
			((TMP_Text)val3).transform.localPosition = new Vector3(localPosition2.x, -90.2156f, localPosition2.z);
			((TMP_Text)val3).SetText("This will overwrite\nthe current flag!");
			if (!MFIPlugin.PresetModificationEnabled.Value)
			{
				return;
			}
			TextMeshProUGUI presetText = Object.Instantiate<TextMeshProUGUI>(((Component)((Component)__instance).transform.Find("warnign")).gameObject.GetComponent<TextMeshProUGUI>(), ((Component)__instance).transform);
			((Object)presetText).name = "preset";
			((TMP_Text)presetText).transform.localPosition = new Vector3(1255.856f, -488.6f, 0f);
			((TMP_Text)presetText).SetText($"(Preset {MFIPlugin.FlagPreset.Value})");
			Button val4 = Object.Instantiate<Button>(((Component)((Component)__instance).transform.Find("LargeBtn")).gameObject.GetComponent<Button>(), ((Component)__instance).transform);
			((Object)val4).name = "presetUpButton";
			((Component)val4).transform.localPosition = new Vector3(((TMP_Text)presetText).transform.localPosition.x + 95f, -488.7611f, -116.5f);
			((Component)val4).transform.localScale = new Vector3(0.5f, 0.5f);
			Text[] componentsInChildren2 = ((Component)val4).GetComponentsInChildren<Text>();
			foreach (Text val5 in componentsInChildren2)
			{
				val5.text = "+";
			}
			val4.onClick = new ButtonClickedEvent();
			((UnityEvent)val4.onClick).AddListener((UnityAction)delegate
			{
				if (MFIPlugin.FlagPreset.Value < limit.max)
				{
					ConfigEntry<int> flagPreset2 = MFIPlugin.FlagPreset;
					int value2 = flagPreset2.Value;
					flagPreset2.Value = value2 + 1;
					((TMP_Text)presetText).SetText($"(Preset {MFIPlugin.FlagPreset.Value})");
				}
			});
			Button val6 = Object.Instantiate<Button>(val4, ((Component)__instance).transform);
			((Object)val6).name = "presetDownButton";
			((Component)val6).transform.localPosition = new Vector3(((TMP_Text)presetText).transform.localPosition.x - 95f, -488.7611f, -116.5f);
			Text[] componentsInChildren3 = ((Component)val6).GetComponentsInChildren<Text>();
			foreach (Text val7 in componentsInChildren3)
			{
				val7.text = "-";
			}
			val6.onClick = new ButtonClickedEvent();
			((UnityEvent)val6.onClick).AddListener((UnityAction)delegate
			{
				if (MFIPlugin.FlagPreset.Value > limit.min)
				{
					ConfigEntry<int> flagPreset = MFIPlugin.FlagPreset;
					int value = flagPreset.Value;
					flagPreset.Value = value - 1;
					((TMP_Text)presetText).SetText($"(Preset {MFIPlugin.FlagPreset.Value})");
				}
			});
		}
	}
}
namespace MageFlagImporter.Helpers
{
	internal static class Utils
	{
		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
		private struct OpenFileName
		{
			public int lStructSize;

			public IntPtr hwndOwner;

			public IntPtr hInstance;

			public string lpstrFilter;

			public string lpstrCustomFilter;

			public int nMaxCustFilter;

			public int nFilterIndex;

			public string lpstrFile;

			public int nMaxFile;

			public string lpstrFileTitle;

			public int nMaxFileTitle;

			public string lpstrInitialDir;

			public string lpstrTitle;

			public int Flags;

			public short nFileOffset;

			public short nFileExtension;

			public string lpstrDefExt;

			public IntPtr lCustData;

			public IntPtr lpfnHook;

			public string lpTemplateName;

			public IntPtr pvReserved;

			public int dwReserved;

			public int flagsEx;
		}

		private static Dictionary<Color, Vector2> _colorCache = new Dictionary<Color, Vector2>();

		private static Color[] _paletteColors = Array.Empty<Color>();

		private static int _paletteWidth;

		private static int _paletteHeight;

		[DllImport("comdlg32.dll", CharSet = CharSet.Auto, SetLastError = true)]
		private static extern bool GetOpenFileName(ref OpenFileName ofn);

		private static string? ShowFileDialog()
		{
			try
			{
				OpenFileName openFileName = default(OpenFileName);
				openFileName.lStructSize = Marshal.SizeOf(typeof(OpenFileName));
				openFileName.lpstrFilter = "Image Files\0*.bmp;*.jpg;*.jpeg;*.png\0All Files\0*.*\0";
				openFileName.lpstrFile = new string(new char[256]);
				openFileName.nMaxFile = 256;
				openFileName.lpstrTitle = "Select an image file";
				openFileName.Flags = 528384;
				OpenFileName ofn = openFileName;
				if (GetOpenFileName(ref ofn))
				{
					return ofn.lpstrFile;
				}
				return null;
			}
			catch (Exception arg)
			{
				MFIPlugin.Log.LogError((object)$"File dialog error: {arg}");
				return null;
			}
		}

		public static void ImportImageToPixelArt(DrawPixels drawPixels)
		{
			((MonoBehaviour)drawPixels).StartCoroutine(CoImportImageToPixelArt(drawPixels));
		}

		private static IEnumerator CoImportImageToPixelArt(DrawPixels drawPixels)
		{
			string imagePath = "";
			bool dialogCompleted = false;
			Task.Run(delegate
			{
				imagePath = ShowFileDialog();
				dialogCompleted = true;
			});
			while (!dialogCompleted && imagePath == "")
			{
				yield return null;
			}
			if (!string.IsNullOrEmpty(imagePath))
			{
				yield return CoProcessImageProgressive(drawPixels, imagePath);
			}
		}

		private static Texture2D ScaleTexture(Texture2D source, int width, int height)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			RenderTexture val = (RenderTexture.active = RenderTexture.GetTemporary(width, height));
			Graphics.Blit((Texture)(object)source, val);
			Texture2D val2 = new Texture2D(width, height);
			val2.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
			val2.Apply();
			RenderTexture.active = null;
			RenderTexture.ReleaseTemporary(val);
			return val2;
		}

		private static void InitializePaletteCache(Texture2D colorsTexture)
		{
			_paletteColors = colorsTexture.GetPixels();
			_paletteWidth = ((Texture)colorsTexture).width;
			_paletteHeight = ((Texture)colorsTexture).height;
			_colorCache.Clear();
		}

		private static IEnumerator CoProcessImageProgressive(DrawPixels drawPixels, string imagePath)
		{
			Texture2D texture = null;
			Texture2D scaledTexture = null;
			try
			{
				byte[] fileData = File.ReadAllBytes(imagePath);
				texture = new Texture2D(2, 2);
				ImageConversion.LoadImage(texture, fileData);
				int gridWidth = drawPixels.GetGrid().GetWidth();
				int gridHeight = drawPixels.GetGrid().GetHeight();
				Texture2D colorsTexture = drawPixels.colorsTexture;
				InitializePaletteCache(colorsTexture);
				scaledTexture = ScaleTexture(texture, gridWidth, gridHeight);
				Cursor.visible = false;
				Cursor.lockState = (CursorLockMode)1;
				yield return ((MonoBehaviour)drawPixels).StartCoroutine(ConvertToGridDataProgressive(drawPixels, scaledTexture, gridWidth, gridHeight));
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
			}
			finally
			{
				if ((Object)(object)texture != (Object)null)
				{
					Object.Destroy((Object)(object)texture);
				}
				if ((Object)(object)scaledTexture != (Object)null)
				{
					Object.Destroy((Object)(object)scaledTexture);
				}
			}
		}

		private static IEnumerator ConvertToGridDataProgressive(DrawPixels drawPixels, Texture2D texture, int width, int height)
		{
			Color[] allPixels = texture.GetPixels();
			List<string> gridData = new List<string>(width * height);
			int pixelsPerFrame = 100;
			for (int x = 0; x < width; x++)
			{
				for (int y = 0; y < height; y++)
				{
					if ((Object)(object)drawPixels == (Object)null)
					{
						yield break;
					}
					int index = y * width + x;
					Vector2 uv = FindClosestColorUV(allPixels[index]);
					gridData.Add($"{uv.x:F2}:{uv.y:F2}");
					drawPixels.GetGrid().GetGridObject(x, y).SetColorUV(uv);
					if ((x * height + y) % pixelsPerFrame == 0)
					{
						yield return null;
					}
				}
			}
			if (!((Object)(object)drawPixels == (Object)null))
			{
				drawPixels.ServerLoadFlag(string.Join(",", gridData));
			}
		}

		private static Vector2 FindClosestColorUV(Color targetColor)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			if (_colorCache.TryGetValue(targetColor, out var value))
			{
				return value;
			}
			Vector2 zero = Vector2.zero;
			float num = float.MaxValue;
			for (int i = 0; i < _paletteColors.Length; i++)
			{
				Color val = _paletteColors[i];
				float num2 = val.r - targetColor.r;
				float num3 = val.g - targetColor.g;
				float num4 = val.b - targetColor.b;
				float num5 = num2 * num2 + num3 * num3 + num4 * num4;
				if (num5 < num)
				{
					num = num5;
					int num6 = i % _paletteWidth;
					int num7 = i / _paletteWidth;
					((Vector2)(ref zero))..ctor((float)num6 / (float)_paletteWidth, (float)num7 / (float)_paletteHeight);
					if (num <= 1.0000001E-06f)
					{
						_colorCache[targetColor] = zero;
						return zero;
					}
				}
			}
			_colorCache[targetColor] = zero;
			return zero;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}