Decompiled source of CamStickers v1.6.2

FreshPolakkeCamStickers.dll

Decompiled 13 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Camera_sticker_2(moodie)")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Camera_sticker_2(moodie)")]
[assembly: AssemblyTitle("Camera_sticker_2(moodie)")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
}
namespace Camera_custom_stickers
{
	[BepInPlugin("FreshPolakkeCamStickers", "CamStickers", "1.6.2")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private ConfigEntry<string> stickerPaths;

		private ConfigEntry<int> maxStickers;

		private ConfigEntry<float> maxHeightPercent;

		private ConfigEntry<float> maxWidthPercent;

		private ConfigEntry<float> offsetXPercent;

		private ConfigEntry<float> offsetYPercent;

		private ConfigEntry<float> spacingPercent;

		private ConfigEntry<bool> removeWhiteEdges;

		private ConfigEntry<float> whiteThreshold;

		private ConfigEntry<KeyCode> pickKey;

		private ConfigEntry<KeyCode> clearKey;

		private readonly List<Texture2D> textures = new List<Texture2D>();

		private readonly Dictionary<Canvas, GameObject> holders = new Dictionary<Canvas, GameObject>();

		private string lastPaths = "";

		private bool dirty;

		private float nextScan;

		private int lastTargetCount = -1;

		private void Awake()
		{
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Log = ((BaseUnityPlugin)this).Logger;
			stickerPaths = ((BaseUnityPlugin)this).Config.Bind<string>("Stickers", "Paths", "", "Image paths separated by semicolons");
			maxStickers = ((BaseUnityPlugin)this).Config.Bind<int>("Stickers", "MaxStickers", 5, "Maximum number of stickers");
			maxHeightPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "MaxHeightPercent", 10f, "Maximum sticker height in percent of the camera screen height");
			maxWidthPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "MaxWidthPercent", 22f, "Maximum sticker width in percent of the camera screen width");
			offsetXPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "OffsetXPercent", 6f, "Distance from the right edge in percent");
			offsetYPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "OffsetYPercent", 8f, "Distance from the bottom edge in percent");
			spacingPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "SpacingPercent", 2f, "Gap between stickers in percent");
			removeWhiteEdges = ((BaseUnityPlugin)this).Config.Bind<bool>("Image", "RemoveWhiteEdges", true, "Make white borders transparent and crop them");
			whiteThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Image", "WhiteThreshold", 0.8f, "How bright a border pixel must be to count as white (0.5 - 1.0)");
			pickKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotkeys", "AddStickerKey", (KeyCode)286, "Open file picker and add a sticker");
			clearKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotkeys", "ClearStickersKey", (KeyCode)287, "Remove all stickers");
			Log.LogInfo((object)"FreshPolakkeCamStickers 1.0.0 loaded");
		}

		private void Update()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(pickKey.Value))
			{
				string text = FilePicker.Open();
				if (!string.IsNullOrEmpty(text))
				{
					List<string> list = SplitPaths(stickerPaths.Value);
					if (list.Count >= Mathf.Max(1, maxStickers.Value))
					{
						list.RemoveAt(0);
					}
					list.Add(text);
					stickerPaths.Value = string.Join(";", list.ToArray());
				}
			}
			if (Input.GetKeyDown(clearKey.Value))
			{
				stickerPaths.Value = "";
			}
			if (stickerPaths.Value != lastPaths)
			{
				lastPaths = stickerPaths.Value;
				LoadAll();
				dirty = true;
			}
			if (Time.unscaledTime > nextScan)
			{
				nextScan = Time.unscaledTime + 1f;
				Refresh();
			}
		}

		private void Refresh()
		{
			if (dirty)
			{
				ClearHolders();
				dirty = false;
			}
			List<Canvas> list = new List<Canvas>();
			foreach (KeyValuePair<Canvas, GameObject> holder in holders)
			{
				if ((Object)(object)holder.Key == (Object)null || (Object)(object)holder.Value == (Object)null)
				{
					list.Add(holder.Key);
				}
			}
			foreach (Canvas item in list)
			{
				holders.Remove(item);
			}
			if (textures.Count == 0)
			{
				return;
			}
			List<Canvas> list2 = FindTargets();
			if (list2.Count != lastTargetCount)
			{
				lastTargetCount = list2.Count;
				Log.LogInfo((object)("Camera canvases found: " + list2.Count));
			}
			foreach (Canvas item2 in list2)
			{
				if (!holders.ContainsKey(item2))
				{
					Build(item2);
				}
			}
		}

		private void ClearHolders()
		{
			foreach (GameObject value in holders.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)value);
				}
			}
			holders.Clear();
		}

		private static bool IsOk(Canvas c)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0026: Invalid comparison between Unknown and I4
			int result;
			if ((Object)(object)c != (Object)null)
			{
				Scene scene = ((Component)c).gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					result = (((int)c.renderMode > 0) ? 1 : 0);
					goto IL_002b;
				}
			}
			result = 0;
			goto IL_002b;
			IL_002b:
			return (byte)result != 0;
		}

		private List<Canvas> FindTargets()
		{
			//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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			HashSet<Canvas> hashSet = new HashSet<Canvas>();
			MonoBehaviour[] array = Resources.FindObjectsOfTypeAll<MonoBehaviour>();
			Scene scene;
			foreach (MonoBehaviour val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				scene = ((Component)val).gameObject.scene;
				if (!((Scene)(ref scene)).IsValid() || ((object)val).GetType().Name != "Camera")
				{
					continue;
				}
				Canvas[] componentsInChildren = ((Component)val).GetComponentsInChildren<Canvas>(true);
				foreach (Canvas val2 in componentsInChildren)
				{
					if (IsOk(val2))
					{
						hashSet.Add(val2);
					}
				}
			}
			TMP_Text[] array2 = Resources.FindObjectsOfTypeAll<TMP_Text>();
			foreach (TMP_Text val3 in array2)
			{
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				scene = ((Component)val3).gameObject.scene;
				if (((Scene)(ref scene)).IsValid() && val3.text != null && !(val3.text.Trim() != "REC"))
				{
					Canvas componentInParent = ((Component)val3).GetComponentInParent<Canvas>();
					if (IsOk(componentInParent))
					{
						hashSet.Add(componentInParent);
					}
				}
			}
			Text[] array3 = Resources.FindObjectsOfTypeAll<Text>();
			foreach (Text val4 in array3)
			{
				if ((Object)(object)val4 == (Object)null)
				{
					continue;
				}
				scene = ((Component)val4).gameObject.scene;
				if (((Scene)(ref scene)).IsValid() && val4.text != null && !(val4.text.Trim() != "REC"))
				{
					Canvas componentInParent2 = ((Component)val4).GetComponentInParent<Canvas>();
					if (IsOk(componentInParent2))
					{
						hashSet.Add(componentInParent2);
					}
				}
			}
			List<Canvas> list = new List<Canvas>();
			foreach (Canvas item in hashSet)
			{
				Canvas val5 = (((Object)(object)((Component)item).transform.parent != (Object)null) ? ((Component)((Component)item).transform.parent).GetComponentInParent<Canvas>() : null);
				if (!((Object)(object)val5 != (Object)null) || !hashSet.Contains(val5))
				{
					list.Add(item);
				}
			}
			return list;
		}

		private static List<string> SplitPaths(string value)
		{
			List<string> list = new List<string>();
			if (string.IsNullOrEmpty(value))
			{
				return list;
			}
			string[] array = value.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text in array)
			{
				string text2 = text.Trim();
				if (text2.Length > 0)
				{
					list.Add(text2);
				}
			}
			return list;
		}

		private void LoadAll()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			foreach (Texture2D texture in textures)
			{
				if ((Object)(object)texture != (Object)null)
				{
					Object.Destroy((Object)(object)texture);
				}
			}
			textures.Clear();
			foreach (string item in SplitPaths(stickerPaths.Value))
			{
				if (File.Exists(item))
				{
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
					if (!ImageConversion.LoadImage(val, File.ReadAllBytes(item)))
					{
						Log.LogWarning((object)("Could not load image: " + item));
						Object.Destroy((Object)(object)val);
						continue;
					}
					Texture2D val2 = Process(val);
					((Texture)val2).wrapMode = (TextureWrapMode)1;
					((Texture)val2).filterMode = (FilterMode)1;
					textures.Add(val2);
					Log.LogInfo((object)("Picture loaded sucessful: " + Path.GetFileName(item) + " (" + ((Texture)val2).width + "x" + ((Texture)val2).height + ")"));
				}
			}
		}

		private Texture2D Process(Texture2D src)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_051f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Expected O, but got Unknown
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = src;
			int num = 512;
			if (Mathf.Max(((Texture)src).width, ((Texture)src).height) > num)
			{
				float num2 = (float)num / (float)Mathf.Max(((Texture)src).width, ((Texture)src).height);
				int num3 = Mathf.Max(1, Mathf.RoundToInt((float)((Texture)src).width * num2));
				int num4 = Mathf.Max(1, Mathf.RoundToInt((float)((Texture)src).height * num2));
				RenderTexture temporary = RenderTexture.GetTemporary(num3, num4, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
				RenderTexture active = RenderTexture.active;
				try
				{
					Graphics.Blit((Texture)(object)src, temporary);
					RenderTexture.active = temporary;
					val = new Texture2D(num3, num4, (TextureFormat)4, false);
					val.ReadPixels(new Rect(0f, 0f, (float)num3, (float)num4), 0, 0);
					val.Apply();
				}
				finally
				{
					RenderTexture.active = active;
					RenderTexture.ReleaseTemporary(temporary);
				}
				Object.Destroy((Object)(object)src);
			}
			if (!removeWhiteEdges.Value)
			{
				return val;
			}
			int width = ((Texture)val).width;
			int height = ((Texture)val).height;
			Color32[] pixels = val.GetPixels32();
			int num5 = Mathf.Clamp(Mathf.RoundToInt(Mathf.Clamp(whiteThreshold.Value, 0.5f, 1f) * 255f), 0, 255);
			bool[] array = new bool[width * height];
			Stack<int> stack = new Stack<int>();
			for (int i = 0; i < width; i++)
			{
				TrySeed(pixels, array, stack, i, num5);
				TrySeed(pixels, array, stack, (height - 1) * width + i, num5);
			}
			for (int j = 0; j < height; j++)
			{
				TrySeed(pixels, array, stack, j * width, num5);
				TrySeed(pixels, array, stack, j * width + width - 1, num5);
			}
			while (stack.Count > 0)
			{
				int num6 = stack.Pop();
				int num7 = num6 % width;
				int num8 = num6 / width;
				if (num7 > 0)
				{
					TrySeed(pixels, array, stack, num6 - 1, num5);
				}
				if (num7 < width - 1)
				{
					TrySeed(pixels, array, stack, num6 + 1, num5);
				}
				if (num8 > 0)
				{
					TrySeed(pixels, array, stack, num6 - width, num5);
				}
				if (num8 < height - 1)
				{
					TrySeed(pixels, array, stack, num6 + width, num5);
				}
			}
			List<int> list = new List<int>();
			int num9 = Mathf.Max(0, num5 - 45);
			for (int k = 0; k < height; k++)
			{
				for (int l = 0; l < width; l++)
				{
					int num10 = k * width + l;
					if (!array[num10] && ((l > 0 && array[num10 - 1]) || (l < width - 1 && array[num10 + 1]) || (k > 0 && array[num10 - width]) || (k < height - 1 && array[num10 + width])) && Mathf.Min((int)pixels[num10].r, Mathf.Min((int)pixels[num10].g, (int)pixels[num10].b)) >= num9)
					{
						list.Add(num10);
					}
				}
			}
			foreach (int item in list)
			{
				array[item] = true;
			}
			int num11 = width;
			int num12 = height;
			int num13 = -1;
			int num14 = -1;
			for (int m = 0; m < height; m++)
			{
				for (int n = 0; n < width; n++)
				{
					int num15 = m * width + n;
					if (array[num15])
					{
						pixels[num15] = new Color32((byte)0, (byte)0, (byte)0, (byte)0);
						continue;
					}
					if (n < num11)
					{
						num11 = n;
					}
					if (n > num13)
					{
						num13 = n;
					}
					if (m < num12)
					{
						num12 = m;
					}
					if (m > num14)
					{
						num14 = m;
					}
				}
			}
			if (num13 < num11 || num14 < num12)
			{
				return val;
			}
			num11 = Mathf.Min(num11 + 1, num13);
			num12 = Mathf.Min(num12 + 1, num14);
			num13 = Mathf.Max(num13 - 1, num11);
			num14 = Mathf.Max(num14 - 1, num12);
			int num16 = num13 - num11 + 1;
			int num17 = num14 - num12 + 1;
			Color32[] array2 = (Color32[])(object)new Color32[num16 * num17];
			for (int num18 = 0; num18 < num17; num18++)
			{
				for (int num19 = 0; num19 < num16; num19++)
				{
					array2[num18 * num16 + num19] = pixels[(num12 + num18) * width + (num11 + num19)];
				}
			}
			Texture2D val2 = new Texture2D(num16, num17, (TextureFormat)4, false);
			val2.SetPixels32(array2);
			val2.Apply();
			Object.Destroy((Object)(object)val);
			return val2;
		}

		private static void TrySeed(Color32[] px, bool[] visited, Stack<int> stack, int i, int thr)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			if (!visited[i])
			{
				Color32 val = px[i];
				if (val.a == 0 || Mathf.Min((int)val.r, Mathf.Min((int)val.g, (int)val.b)) >= thr)
				{
					visited[i] = true;
					stack.Push(i);
				}
			}
		}

		private void Build(Canvas canvas)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Expected O, but got Unknown
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: 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_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)canvas).transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			float num;
			Rect rect;
			if (!((Object)(object)val != (Object)null))
			{
				num = 0f;
			}
			else
			{
				rect = val.rect;
				num = ((Rect)(ref rect)).height;
			}
			float num2 = num;
			float num3;
			if (!((Object)(object)val != (Object)null))
			{
				num3 = 0f;
			}
			else
			{
				rect = val.rect;
				num3 = ((Rect)(ref rect)).width;
			}
			float num4 = num3;
			if (num2 < 1f)
			{
				num2 = 420f;
			}
			if (num4 < 1f)
			{
				num4 = 420f;
			}
			GameObject val2 = new GameObject("CustomCameraStickers", new Type[1] { typeof(RectTransform) });
			RectTransform component = val2.GetComponent<RectTransform>();
			((Transform)component).SetParent(((Component)canvas).transform, false);
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			((Transform)component).localScale = Vector3.one;
			((Transform)component).SetAsLastSibling();
			float num5 = num2 * maxHeightPercent.Value / 100f;
			float num6 = num4 * maxWidthPercent.Value / 100f;
			float num7 = num4 * spacingPercent.Value / 100f;
			float num8 = (0f - num4) * offsetXPercent.Value / 100f;
			float num9 = num2 * offsetYPercent.Value / 100f;
			for (int i = 0; i < textures.Count; i++)
			{
				Texture2D val3 = textures[i];
				if (!((Object)(object)val3 == (Object)null))
				{
					float num10 = (float)((Texture)val3).width / (float)((Texture)val3).height;
					float num11 = num5;
					float num12 = num11 * num10;
					if (num12 > num6)
					{
						num12 = num6;
						num11 = num12 / num10;
					}
					GameObject val4 = new GameObject("Sticker_" + i, new Type[2]
					{
						typeof(RectTransform),
						typeof(RawImage)
					});
					RectTransform component2 = val4.GetComponent<RectTransform>();
					((Transform)component2).SetParent((Transform)(object)component, false);
					component2.anchorMin = new Vector2(1f, 0f);
					component2.anchorMax = new Vector2(1f, 0f);
					component2.pivot = new Vector2(1f, 0f);
					component2.sizeDelta = new Vector2(num12, num11);
					component2.anchoredPosition = new Vector2(num8, num9);
					num8 -= num12 + num7;
					RawImage component3 = val4.GetComponent<RawImage>();
					component3.texture = (Texture)(object)val3;
					((Graphic)component3).raycastTarget = false;
				}
			}
			holders[canvas] = val2;
			Log.LogInfo((object)("Picture attached to canvas " + GetPath(((Component)canvas).transform) + " (" + ((object)canvas.renderMode/*cast due to .constrained prefix*/).ToString() + ", " + num4 + "x" + num2 + ")"));
		}

		private static string GetPath(Transform t)
		{
			string text = ((Object)t).name;
			while ((Object)(object)t.parent != (Object)null)
			{
				t = t.parent;
				text = ((Object)t).name + "/" + text;
			}
			return text;
		}
	}
	internal static class FilePicker
	{
		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
		private class OpenFileName
		{
			public int structSize = Marshal.SizeOf(typeof(OpenFileName));

			public IntPtr dlgOwner = IntPtr.Zero;

			public IntPtr instance = IntPtr.Zero;

			public string filter;

			public string customFilter;

			public int maxCustFilter;

			public int filterIndex;

			public string file;

			public int maxFile;

			public string fileTitle;

			public int maxFileTitle;

			public string initialDir;

			public string title;

			public int flags;

			public short fileOffset;

			public short fileExtension;

			public string defExt;

			public IntPtr custData = IntPtr.Zero;

			public IntPtr hook = IntPtr.Zero;

			public string templateName;

			public IntPtr reservedPtr = IntPtr.Zero;

			public int reservedInt;

			public int flagsEx;
		}

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

		public static string Open()
		{
			OpenFileName openFileName = new OpenFileName
			{
				filter = "Images (*.png;*.jpg)\0*.png;*.jpg;*.jpeg\0\0",
				file = new string('\0', 260),
				maxFile = 260,
				fileTitle = new string('\0', 64),
				maxFileTitle = 64,
				title = "Choose picture",
				flags = 6152
			};
			return GetOpenFileName(openFileName) ? openFileName.file.TrimEnd('\0') : null;
		}
	}
}