Decompiled source of ScreenshotMarker v1.2.2

Silksong.ScreenshotMarker.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.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using InControl;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Silksong.ScreenshotMarker;
using Silksong.ScreenshotMarker.Extensions;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Silksong.ScreenshotMarker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyInformationalVersion("1.2.2+b4d703337d8ce3abc66d499972bef801b8676ef1")]
[assembly: AssemblyProduct("Silksong.ScreenshotMarker")]
[assembly: AssemblyTitle("ScreenshotMarker")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/DemoJameson/Silksong.ScreenshotMarker")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.2.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;
		}
	}
}
public class ScreenshotDisplay : MonoBehaviour
{
	private static ScreenshotDisplay? instance;

	private Texture2D? screenshotTexture;

	private Sprite? screenshotSprite;

	public static bool IsShowing => (Object)(object)instance != (Object)null;

	public static void Show(string filePath)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)instance))
		{
			Close();
		}
		instance = new GameObject("ScreenshotMarker_ScreenshotDisplay").AddComponent<ScreenshotDisplay>();
		instance.InitializeUI(filePath);
	}

	public static void Close()
	{
		if (Object.op_Implicit((Object)(object)instance))
		{
			Object.Destroy((Object)(object)((Component)instance).gameObject);
			instance = null;
		}
	}

	private void InitializeUI(string filePath)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		//IL_007b: 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_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: 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_00e1: Expected O, but got Unknown
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		Canvas obj = ((Component)this).gameObject.AddComponent<Canvas>();
		obj.renderMode = (RenderMode)0;
		obj.sortingOrder = 9999;
		CanvasScaler obj2 = ((Component)this).gameObject.AddComponent<CanvasScaler>();
		obj2.uiScaleMode = (ScaleMode)1;
		obj2.referenceResolution = new Vector2((float)Screen.width, (float)Screen.height);
		GameObject val = new GameObject("ScreenshotMarker_Panel");
		val.transform.SetParent(((Component)this).transform, false);
		((Graphic)val.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.8f);
		RectTransform component = val.GetComponent<RectTransform>();
		component.anchorMin = Vector2.zero;
		component.anchorMax = Vector2.one;
		component.sizeDelta = Vector2.zero;
		GameObject val2 = new GameObject("ScreenshotMarker_Image");
		val2.transform.SetParent(val.transform, false);
		Image obj3 = val2.AddComponent<Image>();
		byte[] array = File.ReadAllBytes(filePath);
		screenshotTexture = new Texture2D(2, 2);
		ImageConversion.LoadImage(screenshotTexture, array);
		screenshotSprite = Sprite.Create(screenshotTexture, new Rect(0f, 0f, (float)((Texture)screenshotTexture).width, (float)((Texture)screenshotTexture).height), new Vector2(0.5f, 0.5f));
		obj3.sprite = screenshotSprite;
		RectTransform component2 = val2.GetComponent<RectTransform>();
		component2.anchorMin = new Vector2(0.5f, 0.5f);
		component2.anchorMax = new Vector2(0.5f, 0.5f);
		component2.pivot = new Vector2(0.5f, 0.5f);
		float value = PluginConfig.ScreenshotScale.Value;
		float num = (float)Screen.width * value;
		float num2 = (float)Screen.height * value;
		float num3 = (float)((Texture)screenshotTexture).width / (float)((Texture)screenshotTexture).height;
		float num4;
		float num5;
		if (num / num2 > num3)
		{
			num4 = num2;
			num5 = num4 * num3;
		}
		else
		{
			num5 = num;
			num4 = num5 / num3;
		}
		component2.sizeDelta = new Vector2(num5, num4);
		((Component)this).gameObject.AddComponent<ScreenshotDisplayController>();
	}

	private void OnDestroy()
	{
		if ((Object)(object)screenshotSprite != (Object)null)
		{
			Object.Destroy((Object)(object)screenshotSprite);
		}
		if ((Object)(object)screenshotTexture != (Object)null)
		{
			Object.Destroy((Object)(object)screenshotTexture);
		}
	}
}
public class ScreenshotDisplayController : MonoBehaviour
{
	private void Update()
	{
		HeroActions inputActions = ManagerSingleton<InputHandler>.Instance.inputActions;
		if (PluginConfig.ScreenshotKey.IsDown() || Input.GetKeyDown((KeyCode)27) || ((OneAxisInputControl)inputActions.MenuSubmit).WasPressed || ((OneAxisInputControl)inputActions.MenuCancel).WasPressed || ((OneAxisInputControl)inputActions.MenuExtra).WasPressed || ((OneAxisInputControl)inputActions.MenuSuper).WasPressed || ((OneAxisInputControl)inputActions.Jump).WasPressed || ((OneAxisInputControl)inputActions.Evade).WasPressed || ((OneAxisInputControl)inputActions.Dash).WasPressed || ((OneAxisInputControl)inputActions.SuperDash).WasPressed || ((OneAxisInputControl)inputActions.DreamNail).WasPressed || ((OneAxisInputControl)inputActions.Attack).WasPressed || ((OneAxisInputControl)inputActions.Cast).WasPressed || ((OneAxisInputControl)inputActions.QuickMap).WasPressed || ((OneAxisInputControl)inputActions.QuickCast).WasPressed || ((OneAxisInputControl)inputActions.Taunt).WasPressed || ((OneAxisInputControl)inputActions.OpenInventory).WasPressed || ((OneAxisInputControl)inputActions.OpenInventoryMap).WasPressed || ((OneAxisInputControl)inputActions.OpenInventoryJournal).WasPressed || ((OneAxisInputControl)inputActions.OpenInventoryTools).WasPressed || ((OneAxisInputControl)inputActions.OpenInventoryQuests).WasPressed || ((OneAxisInputControl)inputActions.Pause).WasPressed)
		{
			ScreenshotDisplay.Close();
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Silksong.ScreenshotMarker
{
	public record MarkerData
	{
		public string Name;

		public DateTime Time;

		public string FileName;

		public Vector2 Position;

		[CompilerGenerated]
		protected virtual bool PrintMembers(StringBuilder builder)
		{
			RuntimeHelpers.EnsureSufficientExecutionStack();
			builder.Append("Name = ");
			builder.Append((object?)Name);
			builder.Append(", Time = ");
			builder.Append(Time.ToString());
			builder.Append(", FileName = ");
			builder.Append((object?)FileName);
			builder.Append(", Position = ");
			builder.Append(((object)(Vector2)(ref Position)).ToString());
			return true;
		}
	}
	[HarmonyPatch]
	public class MarkerManager : PluginComponent
	{
		[CompilerGenerated]
		private sealed class <CreateFlashEffect>d__28 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			private GameObject <flashObject>5__2;

			private Image <flashImage>5__3;

			private float <defaultAlpha>5__4;

			private float <duration>5__5;

			private float <elapsed>5__6;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <CreateFlashEffect>d__28(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<flashObject>5__2 = null;
				<flashImage>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_010b: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
				{
					<>1__state = -1;
					<flashObject>5__2 = new GameObject("ScreenshotMarker_Flash");
					Canvas obj = <flashObject>5__2.AddComponent<Canvas>();
					obj.renderMode = (RenderMode)0;
					obj.sortingOrder = 9999;
					CanvasScaler obj2 = <flashObject>5__2.AddComponent<CanvasScaler>();
					obj2.uiScaleMode = (ScaleMode)1;
					obj2.referenceResolution = new Vector2(1920f, 1080f);
					<flashImage>5__3 = <flashObject>5__2.AddComponent<Image>();
					<defaultAlpha>5__4 = 0.25f;
					((Graphic)<flashImage>5__3).color = new Color(1f, 1f, 1f, <defaultAlpha>5__4);
					<duration>5__5 = 0.3f;
					<elapsed>5__6 = 0f;
					break;
				}
				case 1:
					<>1__state = -1;
					break;
				}
				if (<elapsed>5__6 < <duration>5__5)
				{
					<elapsed>5__6 += Time.deltaTime;
					float num = Mathf.Lerp(<defaultAlpha>5__4, 0f, <elapsed>5__6 / <duration>5__5);
					((Graphic)<flashImage>5__3).color = new Color(1f, 1f, 1f, num);
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				Object.Destroy((Object)(object)<flashObject>5__2);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <CreateScreenshotMarker>d__14 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <CreateScreenshotMarker>d__14(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//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)
				//IL_006b: 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_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_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_0128: Unknown result type (might be due to invalid IL or missing references)
				//IL_0163: 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)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForEndOfFrame();
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					int currentSaveSlot = MarkerManager.currentSaveSlot;
					GameMap gameMap = GameManager._instance.gameMap;
					gameMap.UpdateCurrentScene();
					Vector2 mapPosition = gameMap.GetMapPosition(Vector2.op_Implicit(HeroController._instance.transform.position), gameMap.currentScene, gameMap.currentSceneObj, gameMap.currentScenePos, gameMap.currentSceneSize);
					foreach (MarkerData item2 in markerDataList.ToList())
					{
						if (Vector2.Distance(item2.Position, mapPosition) < 0.1f)
						{
							RemoveMarkerData(item2);
						}
					}
					string fileName = DateTime.Now.ToString("yyyyMMdd_HHmmss_fff") + (RenoDxOrLumaEnabled ? ".exr" : ".png");
					string screenshotFilePath = GetScreenshotFilePath(currentSaveSlot, fileName);
					MarkerData item = new MarkerData
					{
						Name = PluginComponent.CurrentSceneName,
						Time = DateTime.Now,
						FileName = fileName,
						Position = mapPosition
					};
					Directory.CreateDirectory(GetScreenshotPath(currentSaveSlot));
					TakeScreenshot(screenshotFilePath);
					markerDataList.Add(item);
					SaveMakers(currentSaveSlot);
					MapMarkerMenu mapMarkerMenu = gameMap.mapManager.mapMarkerMenu;
					VibrationManager.PlayVibrationClipOneShot(mapMarkerMenu.placementVibration, (VibrationTarget?)null, false, "", false);
					if (!Object.op_Implicit((Object)(object)placeAudioSource))
					{
						placeAudioSource = new GameObject("ScreenshotMarker_PlaceAudioSource").AddComponent<AudioSource>();
						AudioClip placeClip = mapMarkerMenu.placeClip;
						placeAudioSource.clip = placeClip;
					}
					placeAudioSource.Play();
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static List<MarkerData> markerDataList = new List<MarkerData>();

		private static List<GameObject> spawnedMapMarkers = new List<GameObject>();

		private static Sprite sprite;

		private static string markerNamePrefix = "ScreenshotMarker_";

		private static MarkerTypes ScreenshotMarkerType = (MarkerTypes)9527;

		private static AudioSource placeAudioSource = null;

		private static bool? renoDxOrLumaEnabled;

		private static int currentSaveSlot => GameManager._instance.profileID;

		private static bool RenoDxOrLumaEnabled
		{
			get
			{
				if (renoDxOrLumaEnabled.HasValue)
				{
					return renoDxOrLumaEnabled.Value;
				}
				if (File.Exists(Path.Combine(Paths.GameRootPath, "dxgi.dll")))
				{
					renoDxOrLumaEnabled = File.Exists(Path.Combine(Paths.GameRootPath, "renodx-hollowknight-silksong.addon64")) || File.Exists(Path.Combine(Paths.GameRootPath, "Luma-Unity Engine.addon"));
				}
				else
				{
					renoDxOrLumaEnabled = false;
				}
				return renoDxOrLumaEnabled.Value;
			}
		}

		private void Awake()
		{
			//IL_000d: 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_0019: Expected O, but got Unknown
			//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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			byte[] embeddedResourceBytes = GetEmbeddedResourceBytes("ScreenshotMarker.png");
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, embeddedResourceBytes);
			sprite = Sprite.Create(val, new Rect(0f, 0f, 73f, 73f), Vector2.one / 2f);
			if (Object.op_Implicit((Object)(object)GameManager._instance) && currentSaveSlot > 0)
			{
				LoadMarkers(currentSaveSlot);
			}
		}

		private void OnDestroy()
		{
			foreach (GameObject spawnedMapMarker in spawnedMapMarkers)
			{
				Object.Destroy((Object)(object)spawnedMapMarker);
			}
			Object.Destroy((Object)(object)sprite);
			Object.Destroy((Object)(object)placeAudioSource);
			ScreenshotDisplay.Close();
		}

		private void LateUpdate()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			if (!PluginConfig.Enabled.Value || !Object.op_Implicit((Object)(object)HeroController._instance) || HeroController._instance.IsInputBlocked() || (Object.op_Implicit((Object)(object)GameManager._instance) && ((int)GameManager._instance.GameState != 4 || (GameManager._instance.IsMemoryScene() && (int)GameManager._instance.GetCurrentMapZoneEnum() != 21))))
			{
				return;
			}
			HeroActions inputActions = ManagerSingleton<InputHandler>.Instance.inputActions;
			if ((PluginConfig.ScreenshotKey.IsDown() || (((OneAxisInputControl)inputActions.QuickMap).WasPressed && ((OneAxisInputControl)inputActions.DreamNail).IsPressed)) && currentSaveSlot > 0)
			{
				((MonoBehaviour)this).StartCoroutine(CreateScreenshotMarker());
				if (PluginConfig.FlashEffect.Value)
				{
					((MonoBehaviour)this).StartCoroutine(CreateFlashEffect());
				}
			}
		}

		private static string GetScreenshotPath(int saveSlot)
		{
			return Path.Combine(Paths.ConfigPath, "ScreenshotMarker", "Save_" + saveSlot);
		}

		private static string GetScreenshotFilePath(int saveSlot, string fileName)
		{
			return Path.Combine(GetScreenshotPath(saveSlot), fileName);
		}

		private static string GetMarkerDataPath(int saveSlot)
		{
			return Path.Combine(GetScreenshotPath(saveSlot), "marker_data.json");
		}

		[IteratorStateMachine(typeof(<CreateScreenshotMarker>d__14))]
		private static IEnumerator CreateScreenshotMarker()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CreateScreenshotMarker>d__14(0);
		}

		private static GameObject CreateMarker(GameMap gameMap, int index)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			if (spawnedMapMarkers.Count > index)
			{
				return spawnedMapMarkers[index];
			}
			GameObject val = Object.Instantiate<GameObject>(gameMap.mapMarkerTemplates[0], gameMap.markerParent);
			((Object)val).name = $"{markerNamePrefix}{index}";
			SpriteRenderer componentInChildren = val.GetComponentInChildren<SpriteRenderer>();
			componentInChildren.sprite = sprite;
			MaterialPropertyBlock val2 = new MaterialPropertyBlock();
			val2.SetFloat(Shader.PropertyToID("_TimeOffset"), Random.Range(0f, 10f));
			((Renderer)componentInChildren).SetPropertyBlock(val2);
			InvMarker componentInChildren2 = val.GetComponentInChildren<InvMarker>();
			componentInChildren2.Colour = ScreenshotMarkerType;
			componentInChildren2.Index = index;
			spawnedMapMarkers.Add(val);
			return val;
		}

		[HarmonyPatch(typeof(MapMarkerMenu), "AddToCollidingList")]
		[HarmonyPostfix]
		private static void MapMarkerMenuAddToCollidingList(MapMarkerMenu __instance)
		{
			//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_0033: 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)
			List<GameObject> collidingMarkers = __instance.collidingMarkers;
			Vector3 cursorPosition = __instance.placementCursor.transform.position;
			Vector3 gameMapPosition = ((Component)__instance.gameMap).transform.parent.position;
			collidingMarkers.Sort(delegate(GameObject go1, GameObject go2)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: 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_0038: 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_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				float num = Vector2.Distance(Vector2.op_Implicit(go1.transform.position - gameMapPosition), Vector2.op_Implicit(cursorPosition));
				float num2 = Vector2.Distance(Vector2.op_Implicit(go2.transform.position - gameMapPosition), Vector2.op_Implicit(cursorPosition)) - num;
				if (num2 > 0f)
				{
					return 1;
				}
				return (num2 < 0f) ? (-1) : 0;
			});
		}

		[HarmonyPatch(typeof(Platform), "GetMenuAction", new Type[]
		{
			typeof(HeroActions),
			typeof(bool),
			typeof(bool)
		})]
		[HarmonyPrefix]
		private static bool InventoryItemSelectedActionDoAction()
		{
			if (ScreenshotDisplay.IsShowing)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(MapMarkerMenu), "Update")]
		[HarmonyPrefix]
		private static bool MapMarkerMenuUpdate(MapMarkerMenu __instance)
		{
			//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_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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			if (__instance.inPlacementMode && __instance.collidingMarkers.Count > 0 && !ScreenshotDisplay.IsShowing)
			{
				HeroActions inputActions = ManagerSingleton<InputHandler>.Instance.inputActions;
				MenuActions menuAction = Platform.Current.GetMenuAction(inputActions, false, false);
				if (PluginConfig.ScreenshotKey.IsDown() || ((OneAxisInputControl)inputActions.QuickMap).WasPressed || (int)menuAction == 3)
				{
					List<GameObject> collidingMarkers = __instance.collidingMarkers;
					InvMarker component = collidingMarkers[collidingMarkers.Count - 1].GetComponent<InvMarker>();
					if (component.Colour != ScreenshotMarkerType)
					{
						return true;
					}
					MarkerData markerData = markerDataList[component.Index];
					string screenshotFilePath = GetScreenshotFilePath(currentSaveSlot, markerData.FileName);
					if (File.Exists(screenshotFilePath))
					{
						ScreenshotDisplay.Show(screenshotFilePath);
					}
					else
					{
						RemoveScreenshotMarker(__instance);
					}
					return false;
				}
			}
			if (ScreenshotDisplay.IsShowing)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(MapMarkerMenu), "RemoveMarker")]
		[HarmonyPrefix]
		private static bool RemoveMarker(MapMarkerMenu __instance)
		{
			//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)
			List<GameObject> collidingMarkers = __instance.collidingMarkers;
			if (collidingMarkers[collidingMarkers.Count - 1].GetComponent<InvMarker>().Colour != ScreenshotMarkerType)
			{
				return true;
			}
			RemoveScreenshotMarker(__instance);
			return false;
		}

		private static void RemoveScreenshotMarker(MapMarkerMenu markerMenu)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			List<GameObject> collidingMarkers = markerMenu.collidingMarkers;
			GameObject val = collidingMarkers[collidingMarkers.Count - 1];
			InvMarker component = val.GetComponent<InvMarker>();
			RemoveMarkerData(markerDataList[component.Index]);
			collidingMarkers.Remove(val);
			if (collidingMarkers.Count <= 0)
			{
				markerMenu.IsNotColliding();
			}
			markerMenu.audioSource.PlayOneShot(markerMenu.removeClip);
			VibrationManager.PlayVibrationClipOneShot(markerMenu.placementVibration, (VibrationTarget?)null, false, "", false);
			markerMenu.gameMap.SetupMapMarkers();
		}

		[HarmonyPatch(typeof(GameMap), "SetupMapMarkers")]
		[HarmonyPostfix]
		private static void SetupMapMarkers(GameMap __instance)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (PluginConfig.Enabled.Value && !CollectableItemManager.IsInHiddenMode())
			{
				for (int i = 0; i < IEnumerableExtensions.GetCount((IEnumerable)markerDataList); i++)
				{
					GameObject obj = CreateMarker(__instance, i);
					obj.SetActive(true);
					Extensions.SetLocalPosition2D(obj.transform, markerDataList[i].Position);
				}
			}
		}

		[HarmonyPatch(typeof(GameMap), "DisableMarkers")]
		[HarmonyPostfix]
		private static void DisableMarkers()
		{
			foreach (GameObject spawnedMapMarker in spawnedMapMarkers)
			{
				Object.Destroy((Object)(object)spawnedMapMarker);
			}
			spawnedMapMarkers.Clear();
		}

		[HarmonyPatch(typeof(GameManager), "SetLoadedGameData", new Type[]
		{
			typeof(SaveGameData),
			typeof(int)
		})]
		[HarmonyPostfix]
		private static void LoadMarkers(int saveSlot)
		{
			if (!File.Exists(GetMarkerDataPath(saveSlot)))
			{
				markerDataList.Clear();
			}
			else
			{
				markerDataList = JsonConvert.DeserializeObject<List<MarkerData>>(File.ReadAllText(GetMarkerDataPath(saveSlot))) ?? new List<MarkerData>();
			}
		}

		[HarmonyPatch(typeof(GameManager), "ClearSaveFile")]
		[HarmonyPostfix]
		private static void ClearMarkers(int saveSlot)
		{
			if (Directory.Exists(GetScreenshotPath(saveSlot)))
			{
				Directory.Delete(GetScreenshotPath(saveSlot), recursive: true);
			}
			markerDataList.Clear();
		}

		private static void SaveMakers(int saveSlot)
		{
			File.WriteAllText(GetMarkerDataPath(saveSlot), JsonConvert.SerializeObject((object)markerDataList));
		}

		private static void RemoveMarkerData(MarkerData markerData)
		{
			if (markerDataList.Remove(markerData))
			{
				File.Delete(GetScreenshotFilePath(currentSaveSlot, markerData.FileName));
				SaveMakers(currentSaveSlot);
			}
		}

		private static void TakeScreenshot(string filePath)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			int width = Screen.width;
			int height = Screen.height;
			float num = (float)width / (float)height;
			int num2 = Mathf.Min(height, 1080);
			int num3 = Mathf.RoundToInt(num * (float)num2);
			Camera main = Camera.main;
			RenderTexture targetTexture = main.targetTexture;
			RenderTexture active = RenderTexture.active;
			RenderTexture val2 = (main.targetTexture = new RenderTexture(num3, num2, 24, (RenderTextureFormat)(RenoDxOrLumaEnabled ? 2 : 7)));
			main.Render();
			RenderTexture.active = val2;
			Texture2D val3 = new Texture2D(num3, num2, (TextureFormat)(RenoDxOrLumaEnabled ? 17 : 3), false);
			val3.ReadPixels(new Rect(0f, 0f, (float)num3, (float)num2), 0, 0);
			if (RenoDxOrLumaEnabled)
			{
				Color[] pixels = val3.GetPixels();
				for (int i = 0; i < pixels.Length; i++)
				{
					pixels[i].a = 1f;
				}
				val3.SetPixels(pixels);
			}
			val3.Apply();
			if (RenoDxOrLumaEnabled)
			{
				File.WriteAllBytes(filePath, ImageConversion.EncodeToEXR(val3, (EXRFlags)8));
			}
			else
			{
				File.WriteAllBytes(filePath, ImageConversion.EncodeToPNG(val3));
			}
			main.targetTexture = targetTexture;
			RenderTexture.active = active;
			Object.Destroy((Object)(object)val2);
			Object.Destroy((Object)(object)val3);
		}

		[IteratorStateMachine(typeof(<CreateFlashEffect>d__28))]
		private static IEnumerator CreateFlashEffect()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CreateFlashEffect>d__28(0);
		}

		private static byte[] GetEmbeddedResourceBytes(string resourceName)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = "Silksong.ScreenshotMarker." + resourceName;
			using Stream stream = executingAssembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				throw new ArgumentException("找不到资源: " + text);
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}
	}
	[BepInPlugin("mod.silksong.screenshotmarker", "Screenshot Marker", "1.2.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Id = "mod.silksong.screenshotmarker";

		public static Plugin Instance { get; private set; }

		public static ManualLogSource LogSource => ((BaseUnityPlugin)Instance).Logger;

		public static string Name => "Screenshot Marker";

		public static string Version => "1.2.2";

		private void Awake()
		{
			Instance = this;
			PluginComponent.Initialize(((Component)this).gameObject);
		}
	}
	public abstract class PluginComponent : MonoBehaviour
	{
		private static string? currentSceneName;

		public static ManualLogSource Logger => Plugin.LogSource;

		public static string CurrentSceneName => GameManager.instance.sceneName;

		public static string PreviousSceneName => GameManager.instance.lastSceneName;

		public static void Initialize(GameObject gameObject)
		{
			List<Type> list = (from type in Assembly.GetExecutingAssembly().GetTypes()
				where !type.IsAbstract && type.IsSubclassOf(typeof(PluginComponent))
				select type).ToList();
			list.Sort((Type type, Type otherType) => GetPriority(otherType) - GetPriority(type));
			foreach (Type item in list)
			{
				gameObject.AddComponent(item);
			}
		}

		private static int GetPriority(Type type)
		{
			object[] customAttributes = type.GetCustomAttributes(typeof(PluginComponentPriorityAttribute), inherit: false);
			int num = 0;
			if (num < customAttributes.Length)
			{
				return ((PluginComponentPriorityAttribute)customAttributes[num]).Priority;
			}
			return 0;
		}
	}
	[AttributeUsage(AttributeTargets.Class)]
	public class PluginComponentPriorityAttribute : Attribute
	{
		public int Priority { get; }

		public PluginComponentPriorityAttribute(int priority)
		{
			Priority = priority;
			base..ctor();
		}
	}
	public class PluginConfig : PluginComponent
	{
		public static ConfigEntry<bool> Enabled { get; private set; }

		public static ConfigEntry<bool> FlashEffect { get; private set; }

		public static ConfigEntry<float> ScreenshotScale { get; private set; }

		public static ConfigEntry<KeyboardShortcut> ScreenshotKey { get; private set; }

		private void Awake()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			ConfigFile config = ((BaseUnityPlugin)Plugin.Instance).Config;
			Enabled = config.Bind<bool>("General", "Screenshot Marker", true, "Whether to enable screenshot marker");
			FlashEffect = config.Bind<bool>("General", "Flash Effect", true, "Whether to enable flash effect when taking a screenshot");
			ScreenshotScale = config.Bind<float>("General", "Screenshot Scale", 0.75f, new ConfigDescription("The scale of the screenshot", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			ScreenshotKey = config.Bind<KeyboardShortcut>("General", "Screenshot Key", new KeyboardShortcut((KeyCode)112, Array.Empty<KeyCode>()), "The key to take a screenshot and remove marker");
		}
	}
	public class PluginPatch : PluginComponent
	{
		private Harmony harmony;

		private void Awake()
		{
			harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
}
namespace Silksong.ScreenshotMarker.Extensions
{
	public static class ConfigEntryExtensions
	{
		public static bool IsDown(this ConfigEntry<KeyboardShortcut> configEntry)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_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)
			KeyboardShortcut value = configEntry.Value;
			if (!((KeyboardShortcut)(ref value)).Modifiers.Any())
			{
				IInputSystem current = UnityInput.Current;
				value = configEntry.Value;
				return current.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey);
			}
			value = configEntry.Value;
			return ((KeyboardShortcut)(ref value)).IsDown();
		}
	}
	public static class ListExtensions
	{
		public static T? GetOrDefault<T>(this List<T> list, int index)
		{
			if (list.Count > index)
			{
				return list[index];
			}
			return default(T);
		}
	}
}