Decompiled source of MorePins v420.0.1

plugins/kg_MoreMapPins.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MoreMapPins")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreMapPins")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("A553B0DC-CA26-4A15-A369-F6D81739C483")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[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 MoreMapPins
{
	[BepInPlugin("kg.moremappins", "kg.moremappins", "1.0.0")]
	public class MoreMapPins : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Minimap), "Start")]
		private static class SetMaxPins
		{
			public static RectTransform CurrentWindow;

			private static void GenerateAdditionalWindow(Minimap map)
			{
				//IL_0065: 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)
				//IL_00fa: 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_010c: 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_0123: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Unknown result type (might be due to invalid IL or missing references)
				//IL_0171: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: 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_0175: Unknown result type (might be due to invalid IL or missing references)
				//IL_017b: Invalid comparison between Unknown and I4
				if (AdditionalIcons.Count == 0)
				{
					return;
				}
				CurrentWindow = Object.Instantiate<GameObject>(_windowPrefab, map.m_mapLarge.transform).GetComponent<RectTransform>();
				Transform val = ((Component)CurrentWindow).transform.Find("Scroll View/Viewport/Content");
				GameObject gameObject = ((Component)val.GetChild(0)).gameObject;
				PinType val2 = (PinType)750;
				foreach (Sprite additionalIcon in AdditionalIcons)
				{
					GameObject val3 = Object.Instantiate<GameObject>(gameObject, val);
					val3.GetComponent<Image>().sprite = additionalIcon;
					val3.SetActive(true);
					Image component = ((Component)val3.transform.Find("Selected")).GetComponent<Image>();
					((Behaviour)component).enabled = false;
					map.m_selectedIcons[val2] = component;
					map.m_icons.Add(new SpriteData
					{
						m_icon = additionalIcon,
						m_name = val2
					});
					UIInputHandler component2 = val3.GetComponent<UIInputHandler>();
					PinType localEnum = val2;
					component2.m_onLeftClick = (Action<UIInputHandler>)Delegate.Combine(component2.m_onLeftClick, (Action<UIInputHandler>)delegate
					{
						//IL_000c: Unknown result type (might be due to invalid IL or missing references)
						map.SelectIcon(localEnum);
					});
					component2.m_onRightClick = (Action<UIInputHandler>)Delegate.Combine(component2.m_onRightClick, (Action<UIInputHandler>)delegate
					{
						//IL_000c: Unknown result type (might be due to invalid IL or missing references)
						map.ToggleIconFilter(localEnum);
					});
					val2 = (PinType)(val2 + 1);
					if ((int)val2 >= 1000)
					{
						break;
					}
				}
			}

			[UsedImplicitly]
			public static void Postfix(Minimap __instance)
			{
				if (__instance.m_visibleIconTypes.Length < 1000)
				{
					__instance.m_visibleIconTypes = new bool[1000];
					for (int i = 0; i < __instance.m_visibleIconTypes.Length; i++)
					{
						__instance.m_visibleIconTypes[i] = true;
					}
				}
				GenerateAdditionalWindow(__instance);
			}
		}

		[HarmonyPatch(typeof(Minimap), "UpdateMap")]
		private static class Minimap_UpdateMap_Patch
		{
			private static void Modify(ref float mult)
			{
				//IL_0012: 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)
				if (Object.op_Implicit((Object)(object)SetMaxPins.CurrentWindow) && RectTransformUtility.RectangleContainsScreenPoint(SetMaxPins.CurrentWindow, Vector2.op_Implicit(Input.mousePosition)))
				{
					mult = 0f;
				}
			}

			[UsedImplicitly]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> code)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Expected O, but got Unknown
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Expected O, but got Unknown
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Expected O, but got Unknown
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Expected O, but got Unknown
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(code, (ILGenerator)null);
				CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[3]
				{
					CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Mul, (object)null)),
					CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Add, (object)null)),
					CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Stloc_0, (object)null))
				};
				val.MatchForward(false, array);
				if (val.IsInvalid)
				{
					return val.Instructions();
				}
				val.Advance(3);
				val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldloca_S, (object)0)
				});
				val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Minimap_UpdateMap_Patch), "Modify", (Type[])null, (Type[])null))
				});
				return val.Instructions();
			}
		}

		private const string GUID = "kg.moremappins";

		private const string VERSION = "1.0.0";

		private static AssetBundle _asset;

		private static readonly List<Sprite> AdditionalIcons = new List<Sprite>();

		private static GameObject _windowPrefab;

		private const PinType StartPin = 750;

		private const PinType EndPin = 1000;

		private const string FolderName = "MoreMapPins";

		private void Awake()
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00ee: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			_asset = GetAssetBundle("moremappins");
			_windowPrefab = _asset.LoadAsset<GameObject>("MoreMapPinsPanel");
			string text = Path.Combine(Paths.ConfigPath, "MoreMapPins");
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			MonoBehaviour.print((object)("[MoreMapPins] Loading icons from " + text));
			int result;
			IEnumerable<string> enumerable = from f in Directory.GetFiles(text, "*.png", SearchOption.TopDirectoryOnly)
				where int.TryParse(Path.GetFileNameWithoutExtension(f), out result)
				orderby int.Parse(Path.GetFileNameWithoutExtension(f))
				select f;
			foreach (string item2 in enumerable)
			{
				byte[] array = File.ReadAllBytes(item2);
				Texture2D val = new Texture2D(1, 1);
				ImageConversion.LoadImage(val, array);
				Sprite item = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0f, 0f));
				AdditionalIcons.Add(item);
			}
			new Harmony("kg.moremappins").PatchAll();
		}

		private static AssetBundle GetAssetBundle(string filename)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string name = executingAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(filename));
			using Stream stream = executingAssembly.GetManifestResourceStream(name);
			return AssetBundle.LoadFromStream(stream);
		}
	}
}