Decompiled source of BetterMap v1.1.0

BetterMap.dll

Decompiled 3 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
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("BetterMap")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds a direction cone to the Crawlspace 2 minimap")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterMap")]
[assembly: AssemblyTitle("BetterMap")]
[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 BetterMap
{
	[BepInPlugin("com.mrbub.crawlspace2.bettermap", "BetterMap", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static ConfigEntry<bool> EnableDirectionCone;

		internal static ConfigEntry<float> ConeLength;

		internal static ConfigEntry<float> ConeWidth;

		internal static ConfigEntry<float> ConeAlpha;

		private static Transform playerHead;

		private static GameObject coneObject;

		private static RectTransform coneRect;

		private static bool coneCreated;

		private void Awake()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			EnableDirectionCone = ((BaseUnityPlugin)this).Config.Bind<bool>("DirectionCone", "Enabled", true, "Show a direction cone on the player dot indicating which way you're facing");
			ConeLength = ((BaseUnityPlugin)this).Config.Bind<float>("DirectionCone", "Length", 30f, new ConfigDescription("How far the cone extends from the player dot (in minimap units)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 80f), Array.Empty<object>()));
			ConeWidth = ((BaseUnityPlugin)this).Config.Bind<float>("DirectionCone", "Width", 20f, new ConfigDescription("How wide the cone spreads at its tip", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 50f), Array.Empty<object>()));
			ConeAlpha = ((BaseUnityPlugin)this).Config.Bind<float>("DirectionCone", "Alpha", 0.75f, new ConfigDescription("Transparency of the cone", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			Logger.LogInfo((object)"BetterMap v1.1.0 loaded!");
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		[HarmonyPatch(typeof(MinimapControl), "setMapIconPos")]
		[HarmonyPostfix]
		private static void AfterSetMapIconPos(MinimapControl __instance)
		{
			//IL_00cd: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			if (!EnableDirectionCone.Value)
			{
				return;
			}
			if (coneCreated && (Object)(object)coneObject == (Object)null)
			{
				coneCreated = false;
				coneRect = null;
				playerHead = null;
			}
			if ((Object)(object)playerHead == (Object)null)
			{
				Camera main = Camera.main;
				if (!((Object)(object)main != (Object)null))
				{
					return;
				}
				playerHead = ((Component)main).transform;
			}
			if (!coneCreated)
			{
				coneCreated = true;
				CreateCone(__instance);
			}
			if (!((Object)(object)coneObject == (Object)null) && !((Object)(object)coneRect == (Object)null))
			{
				coneRect.anchoredPosition = __instance.playerIndicator.GetComponent<RectTransform>().anchoredPosition;
				float y = playerHead.eulerAngles.y;
				((Transform)coneRect).localRotation = Quaternion.Euler(0f, 0f, 0f - y);
			}
		}

		private static void CreateCone(MinimapControl instance)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			RectTransform minimapRect = instance.minimapRect;
			if ((Object)(object)minimapRect == (Object)null)
			{
				Logger.LogWarning((object)"minimapRect is null");
				return;
			}
			float value = ConeLength.Value;
			float num = ConeWidth.Value / 2f;
			float value2 = ConeAlpha.Value;
			coneObject = new GameObject("DirectionCone");
			coneObject.transform.SetParent(((Component)minimapRect).transform, false);
			coneObject.transform.SetSiblingIndex(0);
			coneRect = coneObject.AddComponent<RectTransform>();
			coneRect.anchorMin = new Vector2(0.5f, 0.5f);
			coneRect.anchorMax = new Vector2(0.5f, 0.5f);
			coneRect.sizeDelta = new Vector2(num * 2f, value);
			coneRect.pivot = new Vector2(0.5f, 0f);
			coneObject.AddComponent<CanvasRenderer>();
			int num2 = 64;
			int num3 = 64;
			Texture2D val = new Texture2D(num2, num3, (TextureFormat)4, false);
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
			Color[] array = (Color[])(object)new Color[num2 * num3];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = val2;
			}
			float num4 = (float)num2 / 2f;
			Color val3 = default(Color);
			for (int j = 0; j < num3; j++)
			{
				float num5 = (float)j / (float)(num3 - 1);
				float num6 = num5 * num4;
				int num7 = Mathf.Max(0, Mathf.FloorToInt(num4 - num6));
				int num8 = Mathf.Min(num2 - 1, Mathf.CeilToInt(num4 + num6));
				float num9 = value2 * (1f - num5 * 0.4f);
				((Color)(ref val3))..ctor(0.2f, 1f, 0.5f, num9);
				for (int k = num7; k <= num8; k++)
				{
					float num10 = Mathf.Abs((float)k - num4);
					float num11 = 1f;
					if (num6 > 1f)
					{
						num11 = 1f - Mathf.Clamp01((num10 - num6 + 2f) / 2f);
					}
					Color val4 = val3;
					val4.a *= num11;
					array[j * num2 + k] = val4;
				}
			}
			val.SetPixels(array);
			val.Apply();
			RawImage val5 = coneObject.AddComponent<RawImage>();
			val5.texture = (Texture)(object)val;
			((Graphic)val5).raycastTarget = false;
			Logger.LogInfo((object)$"Direction cone created as sibling of PlayerIcon. Size: {num * 2f}x{value}");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.mrbub.crawlspace2.bettermap";

		public const string PLUGIN_NAME = "BetterMap";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}