Decompiled source of Minimap v0.1.0

BepInEx/plugins/Minimap.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
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 Flow.StatusEffects;
using FlowStudio.Map;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Minimap.Behaviours;
using Minimap.Patches;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;

[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("smrkn")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+4384b30e6cb745755a610db215cc58e5cd0cf7a6")]
[assembly: AssemblyProduct("Minimap")]
[assembly: AssemblyTitle("Minimap")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/csh/lens-island-minimap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 Minimap
{
	public enum MinimapRenderStyle
	{
		Orthographic,
		Perspective
	}
	[BepInPlugin("com.smrkn.minimap", "Minimap", "0.1.0")]
	public class MinimapPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private const string DefaultOverlayFilename = "Overlay.png";

		internal ConfigEntry<MinimapRenderStyle> RenderingStyle;

		internal ConfigEntry<string> OverlayFilename;

		internal ConfigEntry<bool> RotateWithPlayer;

		internal ConfigEntry<bool> ReplaceCompass;

		internal ConfigEntry<float> ZoomHeight;

		internal ConfigEntry<bool> Flatten;

		private Harmony _harmony;

		internal static MinimapPlugin Instance { get; private set; }

		internal static string OverlayRoot { get; private set; }

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("com.smrkn.minimap");
			_harmony.PatchAll(typeof(MapPatches));
			Logger.LogInfo((object)"Plugin Minimap is loaded!");
			if (((Object)((Component)this).transform).name.Contains("ScriptEngine"))
			{
				OverlayRoot = Path.Combine(Paths.BepInExRootPath, "scripts", "Overlays");
			}
			else
			{
				OverlayRoot = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new Exception("Failed to query assembly location."), "Overlays");
			}
			if (!Directory.Exists(OverlayRoot))
			{
				Logger.LogInfo((object)"Creating Overlays directory");
				Directory.CreateDirectory(OverlayRoot);
			}
			string path = Path.Combine(OverlayRoot, "Overlay.png");
			if (!File.Exists(path))
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				try
				{
					Logger.LogInfo((object)"Saving default overlay as Overlays/Overlay.png");
					using Stream stream = executingAssembly.GetManifestResourceStream("Minimap.Overlay.png");
					if (stream == null)
					{
						throw new FileNotFoundException("Failed to find default overlay");
					}
					using FileStream destination = File.OpenWrite(path);
					stream.CopyTo(destination);
				}
				catch (Exception arg)
				{
					Logger.LogError((object)$"Failed to save default overlay to disk; {arg}");
				}
			}
			ReplaceCompass = ((BaseUnityPlugin)this).Config.Bind<bool>("Minimap", "Replace Compass", true, "Should the minimap hide the vanilla compass and shift status effects to the left to fill the empty space?");
			RotateWithPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("Minimap", "Rotation Enabled", true, "Should the minimap rotate with the player camera or remain fixed?");
			OverlayFilename = ((BaseUnityPlugin)this).Config.Bind<string>("Minimap", "Overlay", "Overlay.png", "Name of the overlay file to use.\nCustom overlay files should be placed in the 'Overlays' subdirectory.");
			ZoomHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Minimap", "Camera Height", 60f, new ConfigDescription("How many units above the player should the minimap camera be?", (AcceptableValueBase)(object)new AcceptableValueRange<float>(30f, 100f), Array.Empty<object>()));
			RenderingStyle = ((BaseUnityPlugin)this).Config.Bind<MinimapRenderStyle>("Minimap", "Rendering Style", MinimapRenderStyle.Perspective, (ConfigDescription)null);
			Flatten = ((BaseUnityPlugin)this).Config.Bind<bool>("Orthographic", "Flatten", false, "Would you like to apply a shader that makes the art style of the map appear more flat?\nHelps with making water look slightly less bad in orthographic mode.");
			RenderingStyle.SettingChanged += OnRenderingStyleChanged;
			Flatten.SettingChanged += OnFlattenChanged;
			OverlayFilename.SettingChanged += OnOverlayChanged;
		}

		private void OnOverlayChanged(object sender, EventArgs e)
		{
			MinimapCameraComponent instance = MinimapCameraComponent.Instance;
			if (!Object.op_Implicit((Object)(object)instance))
			{
				Logger.LogWarning((object)"Failed to find Minimap component; if you're not in game yet you can safely ignore this message.");
			}
			else
			{
				instance.ReplaceOverlay(OverlayFilename.Value);
			}
		}

		private void OnFlattenChanged(object sender, EventArgs e)
		{
			MinimapCameraComponent instance = MinimapCameraComponent.Instance;
			if (!Object.op_Implicit((Object)(object)instance))
			{
				Logger.LogWarning((object)"Failed to find Minimap component; if you're not in game yet you can safely ignore this message.");
			}
			else if (RenderingStyle.Value == MinimapRenderStyle.Orthographic)
			{
				if (Flatten.Value)
				{
					instance.ApplyFlattenShader();
				}
				else
				{
					instance.RemoveFlattenShader();
				}
			}
		}

		private void OnRenderingStyleChanged(object sender, EventArgs e)
		{
			MinimapCameraComponent instance = MinimapCameraComponent.Instance;
			if (!Object.op_Implicit((Object)(object)instance))
			{
				Logger.LogWarning((object)"Failed to find Minimap component; if you're not in game yet you can safely ignore this message.");
			}
			else if (RenderingStyle.Value == MinimapRenderStyle.Perspective)
			{
				instance.SwitchToPerspective();
			}
			else
			{
				instance.SwitchToOrthographic();
			}
		}

		private void OnDestroy()
		{
			RenderingStyle.SettingChanged -= OnRenderingStyleChanged;
			OverlayFilename.SettingChanged -= OnOverlayChanged;
			Flatten.SettingChanged -= OnFlattenChanged;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			DestroyMinimapComponents();
		}

		private static void DestroyMinimapComponents()
		{
			Logger.LogInfo((object)"Destroying minimap components.");
			MinimapCameraComponent[] array = Object.FindObjectsOfType<MinimapCameraComponent>(true);
			for (int i = 0; i < array.Length; i++)
			{
				Object.Destroy((Object)(object)array[i]);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.smrkn.minimap";

		public const string PLUGIN_NAME = "Minimap";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace Minimap.Patches
{
	public static class MapPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(MapUIManager), "Start")]
		public static void StartPostfix(MapUIManager __instance)
		{
			InjectMinimap(__instance);
		}

		internal static void InjectMinimap(MapUIManager mapManager)
		{
			MinimapCameraComponent minimapCameraComponent = default(MinimapCameraComponent);
			if (Object.op_Implicit((Object)(object)mapManager) && !((Component)mapManager).gameObject.TryGetComponent<MinimapCameraComponent>(ref minimapCameraComponent))
			{
				((Component)mapManager).gameObject.AddComponent<MinimapCameraComponent>();
				MinimapPlugin.Logger.LogInfo((object)"Minimap injected successfully!");
			}
		}
	}
}
namespace Minimap.Behaviours
{
	[DisallowMultipleComponent]
	public class MinimapCameraComponent : MonoBehaviour
	{
		private static readonly Vector2 MinimapSize = new Vector2(160f, 160f);

		private static readonly Vector2 OverlaySize = new Vector2(250f, 250f);

		private static readonly int DefaultMask = LayerMask.GetMask(new string[7] { "Default", "Terrain", "Water", "Player", "InteractIgnore", "Construct", "Decoration" });

		private static readonly float OrthographicSizeFactor = 0.25f;

		private const string OrthographicWaterShader = "Legacy Shaders/Diffuse";

		private const string OrthographicShader = "Legacy Shaders/Diffuse";

		private const int OrthographicWaterLayer = 6;

		internal const float MinCameraHeight = 30f;

		internal const float MaxCameraHeight = 100f;

		private const float ZoomStep = 10f;

		private float _cameraHeightTarget = 60f;

		private float _cameraHeight = 60f;

		private bool _wasCompassReplaced;

		private RenderTexture _minimapRenderTexture;

		private GameObject _minimapContainer;

		private Material _brightnessMaterial;

		private Transform _cameraTransform;

		private GameObject _overlayRoot;

		private RawImage _minimapImage;

		private GameObject _waterPlane;

		private Camera _minimapCamera;

		private Image _overlayImage;

		public static MinimapCameraComponent Instance { get; private set; }

		private static bool RotateWithPlayer => MinimapPlugin.Instance.RotateWithPlayer.Value;

		private void Start()
		{
			if (Object.op_Implicit((Object)(object)Camera.main))
			{
				_cameraTransform = ((Component)Camera.main).transform;
			}
			if (!Object.op_Implicit((Object)(object)_cameraTransform))
			{
				MinimapPlugin.Logger.LogError((object)"Could not find main camera.");
				((Behaviour)this).enabled = false;
				return;
			}
			_cameraHeight = (_cameraHeightTarget = MinimapPlugin.Instance.ZoomHeight.Value);
			CreateMinimapUI();
			CreateMinimapCamera();
			InitializeBrightnessControl();
			if (Object.op_Implicit((Object)(object)Instance))
			{
				MinimapPlugin.Logger.LogWarning((object)"Multiple Minimap instances detected, something has likely gone wrong.");
				MinimapPlugin.Logger.LogWarning((object)"Existing instances will be disposed of; if you have enabled compass replacement your UI may adjust briefly.");
				Object.Destroy((Object)(object)Instance);
			}
			Instance = this;
		}

		private void InitializeBrightnessControl()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			Shader val = Shader.Find("UI/Default");
			if (!Object.op_Implicit((Object)(object)val))
			{
				MinimapPlugin.Logger.LogError((object)"Could not find shader for brightness control, minimap brightness will be static");
				return;
			}
			_brightnessMaterial = new Material(val)
			{
				color = new Color(1.25f, 1.25f, 1.25f, 1f)
			};
			TOD_Time.OnSunrise += OnSunrise;
			TOD_Time.OnSunset += OnSunset;
			TOD_Sky val2 = Object.FindObjectOfType<TOD_Sky>();
			if (Object.op_Implicit((Object)(object)val2) && val2.IsNight)
			{
				OnSunset();
			}
		}

		private void OnSunrise()
		{
			if (Object.op_Implicit((Object)(object)_brightnessMaterial))
			{
				((Graphic)_minimapImage).material = null;
			}
		}

		private void OnSunset()
		{
			if (Object.op_Implicit((Object)(object)_brightnessMaterial))
			{
				((Graphic)_minimapImage).material = _brightnessMaterial;
			}
		}

		private void CreateMinimapUI()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00e2: Expected O, but got Unknown
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_0168: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Expected O, but got Unknown
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Expected O, but got Unknown
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			CompassSpinner val = Object.FindObjectOfType<CompassSpinner>(true);
			if (!Object.op_Implicit((Object)(object)val))
			{
				MinimapPlugin.Logger.LogInfo((object)"Failed to find compass for UI injection");
				return;
			}
			if (MinimapPlugin.Instance.ReplaceCompass.Value)
			{
				((MonoBehaviour)this).StartCoroutine(ReplaceCompass());
			}
			_minimapContainer = new GameObject("MinimapContainer");
			_minimapContainer.transform.SetParent(((Component)val).transform.parent, false);
			RectTransform obj = _minimapContainer.AddComponent<RectTransform>();
			obj.sizeDelta = OverlaySize;
			obj.anchorMin = new Vector2(0f, 1f);
			obj.anchorMax = new Vector2(0f, 1f);
			obj.pivot = new Vector2(0f, 1f);
			obj.anchoredPosition = new Vector2(40f, -200f);
			_overlayRoot = new GameObject("MinimapRotatingRoot");
			_overlayRoot.transform.SetParent(_minimapContainer.transform, false);
			RectTransform obj2 = _overlayRoot.AddComponent<RectTransform>();
			obj2.sizeDelta = OverlaySize;
			obj2.anchorMin = new Vector2(0.5f, 0.5f);
			obj2.anchorMax = new Vector2(0.5f, 0.5f);
			obj2.pivot = new Vector2(0.5f, 0.5f);
			obj2.anchoredPosition = Vector2.zero;
			GameObject val2 = new GameObject("Minimap");
			val2.transform.SetParent(_overlayRoot.transform, false);
			RectTransform obj3 = val2.AddComponent<RectTransform>();
			obj3.sizeDelta = MinimapSize;
			obj3.anchorMin = new Vector2(0.5f, 0.5f);
			obj3.anchorMax = new Vector2(0.5f, 0.5f);
			obj3.pivot = new Vector2(0.5f, 0.5f);
			obj3.anchoredPosition = Vector2.zero;
			val2.AddComponent<Image>().sprite = CreateCircleSprite((int)MinimapSize.x);
			val2.AddComponent<Mask>().showMaskGraphic = false;
			GameObject val3 = new GameObject("MinimapImage");
			val3.transform.SetParent(val2.transform, false);
			_minimapImage = val3.AddComponent<RawImage>();
			RectTransform component = val3.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			GameObject val4 = new GameObject("MinimapOverlayImage");
			val4.transform.SetParent(_overlayRoot.transform, false);
			_overlayImage = val4.AddComponent<Image>();
			string filePath = Path.Combine(MinimapPlugin.OverlayRoot, Path.GetFileName(MinimapPlugin.Instance.OverlayFilename.Value));
			_overlayImage.sprite = LoadSpriteFromFile(filePath);
			RectTransform component2 = val4.GetComponent<RectTransform>();
			component2.sizeDelta = OverlaySize;
			component2.anchorMin = new Vector2(0.5f, 0.5f);
			component2.anchorMax = new Vector2(0.5f, 0.5f);
			component2.pivot = new Vector2(0.5f, 0.5f);
			component2.anchoredPosition = Vector2.zero;
		}

		public void ReplaceOverlay(string fileName)
		{
			if (!Object.op_Implicit((Object)(object)_overlayImage))
			{
				return;
			}
			try
			{
				Sprite val = LoadSpriteFromFile(Path.Combine(MinimapPlugin.OverlayRoot, Path.GetFileName(fileName)));
				if (Object.op_Implicit((Object)(object)val))
				{
					Sprite sprite = _overlayImage.sprite;
					if (Object.op_Implicit((Object)(object)sprite))
					{
						Object.Destroy((Object)(object)sprite);
					}
					_overlayImage.sprite = val;
				}
				else
				{
					MinimapPlugin.Logger.LogWarning((object)("Could not load replacement overlay, are you sure a file named " + fileName + " exists?"));
				}
			}
			catch (Exception ex)
			{
				MinimapPlugin.Logger.LogError((object)"Failed to load replacement overlay, falling back to default.");
				MinimapPlugin.Logger.LogError((object)ex);
				ReplaceOverlay(((ConfigEntryBase)MinimapPlugin.Instance.OverlayFilename).DefaultValue as string);
			}
		}

		private IEnumerator ReplaceCompass()
		{
			StatusEffectSlots statusEffects = null;
			while (statusEffects == null)
			{
				statusEffects = Object.FindObjectOfType<StatusEffectSlots>();
				yield return (object)new WaitForSecondsRealtime(0.2f);
			}
			CompassSpinner val = Object.FindObjectOfType<CompassSpinner>();
			if (Object.op_Implicit((Object)(object)val))
			{
				((Component)val).gameObject.SetActive(false);
			}
			Transform transform = ((Component)statusEffects).transform;
			Vector3 localPosition = ((Component)statusEffects).transform.localPosition;
			localPosition.x = 20f;
			transform.localPosition = localPosition;
			_wasCompassReplaced = true;
		}

		private static Sprite LoadSpriteFromFile(string filePath)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			if (!File.Exists(filePath))
			{
				Debug.LogError((object)("File not found: " + filePath));
				return null;
			}
			byte[] array = File.ReadAllBytes(filePath);
			Texture2D val = new Texture2D((int)OverlaySize.x, (int)OverlaySize.y);
			if (ImageConversion.LoadImage(val, array))
			{
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
			MinimapPlugin.Logger.LogError((object)"Failed to load image data");
			Object.Destroy((Object)(object)val);
			return null;
		}

		private void HandleZoomInput()
		{
			if (!Object.op_Implicit((Object)(object)PauseMenu.Instance) || !PauseMenu.Instance.IsVisible)
			{
				if (Input.GetKeyDown((KeyCode)57))
				{
					_cameraHeightTarget = Mathf.Min(_cameraHeightTarget + 10f, 100f);
				}
				else if (Input.GetKeyDown((KeyCode)48))
				{
					_cameraHeightTarget = Mathf.Max(_cameraHeightTarget - 10f, 30f);
				}
				((MonoBehaviour)this).StartCoroutine(PushTargetHeightToConfig());
			}
		}

		private IEnumerator PushTargetHeightToConfig()
		{
			yield return (object)new WaitForEndOfFrame();
			MinimapPlugin.Instance.ZoomHeight.Value = _cameraHeightTarget;
		}

		private void SmoothZoom()
		{
			_cameraHeight = Mathf.MoveTowards(_cameraHeight, _cameraHeightTarget, 40f * Time.deltaTime);
		}

		private void CreateMinimapCamera()
		{
			//IL_002d: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			bool orthographic = MinimapPlugin.Instance.RenderingStyle.Value == MinimapRenderStyle.Orthographic;
			_minimapRenderTexture = new RenderTexture((int)MinimapSize.x, (int)MinimapSize.y, 16, (RenderTextureFormat)0)
			{
				name = "MinimapRT",
				filterMode = (FilterMode)1,
				antiAliasing = 2
			};
			_minimapRenderTexture.Create();
			GameObject val = new GameObject("MinimapCamera");
			val.transform.SetParent(((Component)this).transform, false);
			_minimapCamera = val.AddComponent<Camera>();
			_minimapCamera.orthographic = orthographic;
			_minimapCamera.clearFlags = (CameraClearFlags)2;
			_minimapCamera.backgroundColor = Color.clear;
			_minimapCamera.nearClipPlane = 1f;
			_minimapCamera.farClipPlane = 600f;
			_minimapCamera.fieldOfView = 45f;
			_minimapCamera.cullingMask = DefaultMask;
			_minimapCamera.targetTexture = _minimapRenderTexture;
			_minimapCamera.depth = -100f;
			_minimapCamera.allowHDR = false;
			_minimapCamera.allowMSAA = true;
			if (_minimapCamera.orthographic)
			{
				SwitchToOrthographic();
			}
			else
			{
				SwitchToPerspective();
			}
			_minimapImage.texture = (Texture)(object)_minimapRenderTexture;
		}

		public void ApplyFlattenShader()
		{
			if (Object.op_Implicit((Object)(object)_minimapCamera))
			{
				Shader val = Shader.Find("Legacy Shaders/Diffuse");
				if (Object.op_Implicit((Object)(object)val))
				{
					_minimapCamera.SetReplacementShader(val, "RenderType");
				}
				else
				{
					MinimapPlugin.Logger.LogWarning((object)"Could not find \"Legacy Shaders/Diffuse\" shader");
				}
			}
		}

		public void RemoveFlattenShader()
		{
			if (Object.op_Implicit((Object)(object)_minimapCamera))
			{
				_minimapCamera.ResetReplacementShader();
			}
		}

		public void SwitchToOrthographic()
		{
			if (Object.op_Implicit((Object)(object)_minimapCamera))
			{
				_minimapCamera.orthographic = true;
				_minimapCamera.orthographicSize = _cameraHeight * OrthographicSizeFactor;
				if (MinimapPlugin.Instance.Flatten.Value)
				{
					ApplyFlattenShader();
				}
				else
				{
					RemoveFlattenShader();
				}
				Camera minimapCamera = _minimapCamera;
				minimapCamera.cullingMask |= 0x40;
				if (!Object.op_Implicit((Object)(object)_waterPlane))
				{
					CreateMinimapWaterPlane();
				}
			}
		}

		public void SwitchToPerspective()
		{
			if (Object.op_Implicit((Object)(object)_minimapCamera))
			{
				_minimapCamera.orthographic = false;
				_minimapCamera.cullingMask = DefaultMask;
				RemoveFlattenShader();
				if (Object.op_Implicit((Object)(object)_waterPlane))
				{
					Object.Destroy((Object)(object)_waterPlane);
					_waterPlane = null;
				}
			}
		}

		private void CreateMinimapWaterPlane()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0043: 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_006d: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			_waterPlane = GameObject.CreatePrimitive((PrimitiveType)4);
			((Object)_waterPlane).name = "MinimapWater";
			Vector3 position = ((Component)_minimapCamera).transform.position;
			_waterPlane.transform.position = new Vector3(position.x, 3.82f, position.z);
			_waterPlane.transform.localScale = new Vector3(200f, 1f, 200f);
			_waterPlane.layer = 6;
			Material val = new Material(Shader.Find("Legacy Shaders/Diffuse"));
			val.color = new Color(0.2f, 0.55f, 0.92f, 1f);
			val.renderQueue = 1000;
			Renderer component = _waterPlane.GetComponent<Renderer>();
			component.material = val;
			component.enabled = true;
			component.shadowCastingMode = (ShadowCastingMode)0;
			component.receiveShadows = false;
			Object.Destroy((Object)(object)_waterPlane.GetComponent<Collider>());
		}

		private void Update()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_cameraTransform) && Object.op_Implicit((Object)(object)_minimapCamera))
			{
				HandleZoomInput();
				SmoothZoom();
				Vector2 playerPos2D = Player.PlayerPos2D;
				if (_minimapCamera.orthographic)
				{
					_minimapCamera.orthographicSize = _cameraHeight * OrthographicSizeFactor;
				}
				((Component)_minimapCamera).transform.position = new Vector3(playerPos2D.x, _cameraHeight, playerPos2D.y);
				((Component)_minimapCamera).transform.rotation = Quaternion.Euler(90f, 0f, 0f);
				if (RotateWithPlayer)
				{
					float y = _cameraTransform.eulerAngles.y;
					_overlayRoot.transform.localEulerAngles = new Vector3(0f, 0f, y - 45f);
				}
				else
				{
					_overlayRoot.transform.localEulerAngles = Vector3.zero;
				}
			}
		}

		private static Sprite CreateCircleSprite(int size)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)5, false)
			{
				name = "MinimapMask",
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[size * size];
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor((float)size / 2f, (float)size / 2f);
			float num = (float)size / 2f;
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num2 = Vector2.Distance(new Vector2((float)j, (float)i), val2);
					array[j + i * size] = Color32.op_Implicit((num2 <= num) ? Color.white : Color.clear);
				}
			}
			val.SetPixels32(array);
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, (float)size, (float)size), new Vector2(0.5f, 0.5f));
		}

		private void OnDestroy()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			Instance = null;
			if (_wasCompassReplaced)
			{
				CompassSpinner val = Object.FindObjectOfType<CompassSpinner>();
				if (Object.op_Implicit((Object)(object)val))
				{
					((Component)val).gameObject.SetActive(true);
				}
				StatusEffectSlots val2 = Object.FindObjectOfType<StatusEffectSlots>();
				if (Object.op_Implicit((Object)(object)val2))
				{
					Transform transform = ((Component)val2).transform;
					Vector3 localPosition = ((Component)val2).transform.localPosition;
					localPosition.x = 100f;
					transform.localPosition = localPosition;
				}
			}
			if (Object.op_Implicit((Object)(object)_overlayImage) && Object.op_Implicit((Object)(object)_overlayImage.sprite))
			{
				Object.Destroy((Object)(object)_overlayImage.sprite);
				Object.Destroy((Object)(object)_overlayImage);
			}
			if (Object.op_Implicit((Object)(object)_brightnessMaterial))
			{
				TOD_Time.OnSunrise -= OnSunrise;
				TOD_Time.OnSunset -= OnSunset;
				Object.Destroy((Object)(object)_brightnessMaterial);
			}
			if (Object.op_Implicit((Object)(object)_minimapRenderTexture))
			{
				_minimapRenderTexture.Release();
				Object.Destroy((Object)(object)_minimapRenderTexture);
			}
			if (Object.op_Implicit((Object)(object)_minimapCamera))
			{
				Object.Destroy((Object)(object)((Component)_minimapCamera).gameObject);
			}
			if (Object.op_Implicit((Object)(object)_minimapContainer))
			{
				Object.Destroy((Object)(object)_minimapContainer);
			}
			if (Object.op_Implicit((Object)(object)_waterPlane))
			{
				Object.Destroy((Object)(object)_waterPlane);
			}
		}
	}
}