Decompiled source of Valheim Map Rings v1.0.0

Valheim_MapRings.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 Valheim_MapRings
{
	public static class MapRingsConfig
	{
		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<bool> Haldor;

		public static ConfigEntry<bool> Hildir;

		public static ConfigEntry<bool> BogWitch;

		public static ConfigEntry<bool> TraderMaxDistance;

		public static ConfigEntry<bool> Biomes;

		public static ConfigEntry<bool> AshlandsDeepNorth;

		public static ConfigEntry<bool> Labels;

		public static ConfigEntry<float> LineWidth;

		public static ConfigEntry<float> Opacity;

		public static ConfigEntry<float> LabelSize;

		public static ConfigEntry<Color> TraderColor;

		public static ConfigEntry<bool> LogRings;

		public static event Action Changed;

		public static void Bind(ConfigFile config)
		{
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			Enabled = config.Bind<bool>("General", "Enabled", true, "Master switch. Turn off to hide every ring without uninstalling the mod.");
			Haldor = config.Bind<bool>("Traders", "Haldor", true, "Ring at the minimum distance from the world centre where Haldor can be placed.");
			Hildir = config.Bind<bool>("Traders", "Hildir", true, "Rings at the minimum and maximum distances from the world centre where Hildir can be placed.");
			BogWitch = config.Bind<bool>("Traders", "BogWitch", true, "Rings at the minimum and maximum distances from the world centre where the Bog Witch can be placed.");
			TraderMaxDistance = config.Bind<bool>("Traders", "MaxDistance", true, "Also draw the maximum distance of the traders that have one (dashed).");
			Biomes = config.Bind<bool>("Biomes", "Boundaries", false, "Rings where the world generator lets a biome start (solid) or stops it (dashed): Black Forest, Mountains, Swamp, Plains, end of Meadows, Mistlands, and so on.");
			AshlandsDeepNorth = config.Bind<bool>("Biomes", "AshlandsDeepNorth", true, "With Boundaries on, also draw the off-centre edges of the Ashlands (south) and the Deep North (north).");
			Labels = config.Bind<bool>("Display", "Labels", true, "Write the distance and what it stands for on each ring, at the point of the ring closest to the middle of the view.");
			LineWidth = config.Bind<float>("Display", "LineWidth", 1.5f, new ConfigDescription("Thickness of the rings, in pixels of the map.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 6f), Array.Empty<object>()));
			Opacity = config.Bind<float>("Display", "Opacity", 0.8f, new ConfigDescription("Opacity of the rings and of their dark edging.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			LabelSize = config.Bind<float>("Display", "LabelSize", 16f, new ConfigDescription("Font size of the labels.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(8f, 40f), Array.Empty<object>()));
			TraderColor = config.Bind<Color>("Display", "TraderColor", new Color(1f, 0.62f, 0.2f, 1f), "Colour of the trader rings. Biome rings take the colour of their biome.");
			LogRings = config.Bind<bool>("Advanced", "LogRings", false, "Write every ring, with where its distance was read, to the BepInEx log when the rings are built.");
			config.SettingChanged += delegate
			{
				MapRingsConfig.Changed?.Invoke();
			};
		}
	}
	[BepInPlugin("Tchernobill.Valheim_MapRings", "Map Rings", "1.0.0")]
	public class MapRingsPlugin : BaseUnityPlugin
	{
		public const string GUID = "Tchernobill.Valheim_MapRings";

		public const string NAME = "Map Rings";

		public const string VERSION = "1.0.0";

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			MapRingsConfig.Bind(((BaseUnityPlugin)this).Config);
			new Harmony("Tchernobill.Valheim_MapRings").PatchAll();
			Log.LogInfo((object)"Map Rings 1.0.0 ready.");
		}
	}
	[HarmonyPatch(typeof(Minimap), "Start")]
	internal static class MinimapStartPatch
	{
		private static void Postfix(Minimap __instance)
		{
			RingOverlay.Attach(__instance);
		}
	}
	public sealed class RingDef
	{
		public Vector2 Center;

		public float Radius;

		public float Wave;

		public bool Dashed;

		public Color Color;

		public string Name;

		public string Suffix;

		public string Source;

		public bool OffCenter => ((Vector2)(ref Center)).sqrMagnitude > 1f;

		public Vector2 PointAt(float psi)
		{
			//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)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(Mathf.Sin(psi), Mathf.Cos(psi));
			float num = Radius;
			if (Wave != 0f)
			{
				int num2 = ((!OffCenter) ? 1 : 3);
				for (int i = 0; i < num2; i++)
				{
					Vector2 val2 = Center + val * num;
					num = Radius + Wave * Mathf.Sin(Mathf.Atan2(val2.x, val2.y) * 20f);
				}
			}
			return Center + val * num;
		}
	}
	public static class RingCatalog
	{
		public const float WorldEdge = 10500f;

		private const float Wave = 100f;

		private static readonly Color Meadows = new Color(0.55f, 0.9f, 0.35f);

		private static readonly Color BlackForest = new Color(0.2f, 0.55f, 0.25f);

		private static readonly Color Swamp = new Color(0.62f, 0.45f, 0.28f);

		private static readonly Color Mountain = new Color(0.92f, 0.95f, 1f);

		private static readonly Color Plains = new Color(0.95f, 0.85f, 0.3f);

		private static readonly Color Mistlands = new Color(0.72f, 0.52f, 0.95f);

		private static readonly Color AshLands = new Color(1f, 0.3f, 0.18f);

		private static readonly Color DeepNorth = new Color(0.55f, 0.85f, 1f);

		public static List<RingDef> Build()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			List<RingDef> list = new List<RingDef>();
			if (!MapRingsConfig.Enabled.Value)
			{
				return list;
			}
			Color value = MapRingsConfig.TraderColor.Value;
			if (MapRingsConfig.Haldor.Value)
			{
				AddTrader(list, "Haldor", "Vendor_BlackForest", 1500f, 0f, value);
			}
			if (MapRingsConfig.Hildir.Value)
			{
				AddTrader(list, "Hildir", "Hildir_camp", 3000f, 8000f, value);
			}
			if (MapRingsConfig.BogWitch.Value)
			{
				AddTrader(list, "Bog Witch", "BogWitch_Camp", 3000f, 8000f, value);
			}
			if (MapRingsConfig.Biomes.Value)
			{
				AddBiomes(list);
			}
			if (MapRingsConfig.LogRings.Value)
			{
				foreach (RingDef item in list)
				{
					MapRingsPlugin.Log.LogInfo((object)($"Ring {item.Name} {item.Suffix}: centre ({item.Center.x:0}, {item.Center.y:0}), radius {item.Radius:0}" + ((item.Wave != 0f) ? $" +/- {item.Wave:0}" : "") + (item.Dashed ? ", dashed" : "") + " [" + item.Source + "]"));
				}
			}
			return list;
		}

		private static void AddTrader(List<RingDef> rings, string name, string location, float defMin, float defMax, Color color)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			float num = defMin;
			float num2 = defMax;
			string source = "built-in default, location not found";
			ZoneSystem instance = ZoneSystem.instance;
			if ((Object)(object)instance != (Object)null)
			{
				foreach (ZoneLocation location2 in instance.m_locations)
				{
					if (location2 != null && location2.m_enable && !(location2.m_prefabName != location))
					{
						num = Mathf.Max(location2.m_minDistance, location2.m_minDistanceFromCenter);
						num2 = MinLimit(location2.m_maxDistance, location2.m_maxDistanceFromCenter);
						source = "ZoneSystem location " + location;
						break;
					}
				}
			}
			if (num > 0f)
			{
				rings.Add(new RingDef
				{
					Radius = num,
					Color = color,
					Name = name,
					Suffix = "",
					Source = source
				});
			}
			if (num2 > 0f && MapRingsConfig.TraderMaxDistance.Value)
			{
				rings.Add(new RingDef
				{
					Radius = num2,
					Color = color,
					Dashed = true,
					Name = name,
					Suffix = "(max)",
					Source = source
				});
			}
		}

		private static float MinLimit(float a, float b)
		{
			if (a <= 0f)
			{
				return b;
			}
			if (!(b <= 0f))
			{
				return Mathf.Min(a, b);
			}
			return a;
		}

		private static void AddBiomes(List<RingDef> rings)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			WorldGenerator instance = WorldGenerator.instance;
			string source;
			float radius = ReadFloat(instance, "m_minMountainDistance", 1000f, out source);
			string source2;
			float radius2 = ReadFloat(instance, "maxMarshDistance", 6000f, out source2);
			rings.Add(Biome("$biome_blackforest", BlackForest, 600f, 100f, dashed: false, "WorldGenerator.GetBiome"));
			rings.Add(Biome("$biome_mountain", Mountain, radius, 0f, dashed: false, source));
			rings.Add(Biome("$biome_swamp", Swamp, 2000f, 0f, dashed: false, "WorldGenerator.GetBiome"));
			rings.Add(Biome("$biome_plains", Plains, 3000f, 100f, dashed: false, "WorldGenerator.GetBiome"));
			rings.Add(Biome("$biome_meadows", Meadows, 5000f, 100f, dashed: true, "WorldGenerator.GetBiome"));
			rings.Add(Biome("$biome_swamp", Swamp, radius2, 0f, dashed: true, source2));
			rings.Add(Biome("$biome_mistlands", Mistlands, 6000f, 100f, dashed: false, "WorldGenerator.GetBiome"));
			rings.Add(Biome("$biome_plains", Plains, 8000f, 0f, dashed: true, "WorldGenerator.GetBiome"));
			rings.Add(Biome("$biome_mistlands", Mistlands, 10000f, 0f, dashed: true, "WorldGenerator.GetBiome"));
			if (MapRingsConfig.AshlandsDeepNorth.Value)
			{
				float num = 0f - WorldGenerator.ashlandsYOffset;
				RingDef ringDef = Biome("$biome_ashlands", AshLands, WorldGenerator.ashlandsMinDistance, 100f, dashed: false, "WorldGenerator.IsAshlands");
				ringDef.Center = new Vector2(0f, num);
				rings.Add(ringDef);
				RingDef ringDef2 = Biome("$biome_deepnorth", DeepNorth, 12000f, 100f, dashed: false, "WorldGenerator.IsDeepnorth");
				ringDef2.Center = new Vector2(0f, -4000f);
				rings.Add(ringDef2);
			}
		}

		private static RingDef Biome(string token, Color color, float radius, float wave, bool dashed, string source)
		{
			//IL_0032: 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)
			string name = ((Localization.instance != null) ? Localization.instance.Localize(token) : token);
			return new RingDef
			{
				Radius = radius,
				Wave = wave,
				Dashed = dashed,
				Color = color,
				Name = name,
				Suffix = (dashed ? "(end)" : ""),
				Source = source
			};
		}

		private static float ReadFloat(WorldGenerator wg, string field, float fallback, out string source)
		{
			if (wg != null && AccessTools.Field(typeof(WorldGenerator), field)?.GetValue(wg) is float result)
			{
				source = "WorldGenerator." + field;
				return result;
			}
			source = "built-in default, WorldGenerator." + field + " unreadable";
			return fallback;
		}
	}
	public struct RingSegment
	{
		public Vector2 A;

		public Vector2 B;

		public Color Color;
	}
	public class RingGraphic : MaskableGraphic
	{
		private const int MaxVertices = 64000;

		public List<RingSegment> Segments;

		public float Width = 1.5f;

		public Color? Override;

		protected override void OnPopulateMesh(VertexHelper vh)
		{
			//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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0092: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_00ba: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			vh.Clear();
			if (Segments == null)
			{
				return;
			}
			float num = Width * 0.5f;
			UIVertex simpleVert = UIVertex.simpleVert;
			Vector2 val3 = default(Vector2);
			foreach (RingSegment segment in Segments)
			{
				if (vh.currentVertCount + 4 > 64000)
				{
					break;
				}
				Vector2 val = segment.B - segment.A;
				float magnitude = ((Vector2)(ref val)).magnitude;
				if (!(magnitude < 0.01f))
				{
					Vector2 val2 = val / magnitude * num;
					((Vector2)(ref val3))..ctor(0f - val2.y, val2.x);
					Vector2 val4 = segment.A - val2;
					Vector2 val5 = segment.B + val2;
					simpleVert.color = Color32.op_Implicit((Color)(((??)Override) ?? segment.Color));
					int currentVertCount = vh.currentVertCount;
					simpleVert.position = Vector2.op_Implicit(val4 - val3);
					vh.AddVert(simpleVert);
					simpleVert.position = Vector2.op_Implicit(val4 + val3);
					vh.AddVert(simpleVert);
					simpleVert.position = Vector2.op_Implicit(val5 + val3);
					vh.AddVert(simpleVert);
					simpleVert.position = Vector2.op_Implicit(val5 - val3);
					vh.AddVert(simpleVert);
					vh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
					vh.AddTriangle(currentVertCount, currentVertCount + 2, currentVertCount + 3);
				}
			}
		}
	}
	public class RingOverlay : MonoBehaviour
	{
		private sealed class LabelGroup
		{
			public RingDef Anchor;

			public readonly List<RingDef> Rings = new List<RingDef>();

			public TextMeshProUGUI Text;
		}

		private const float DashOn = 9f;

		private const float DashOff = 6f;

		private Minimap m_minimap;

		private RawImage m_map;

		private RectTransform m_rect;

		private RingGraphic m_shadow;

		private RingGraphic m_line;

		private RectTransform m_labelRoot;

		private readonly List<RingSegment> m_segments = new List<RingSegment>();

		private readonly List<LabelGroup> m_groups = new List<LabelGroup>();

		private List<RingDef> m_rings;

		private bool m_dirty = true;

		private Rect m_lastUv;

		private Rect m_lastRect;

		private Rect m_uv;

		private Rect m_local;

		private float m_worldToUv;

		public static void Attach(Minimap minimap)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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)
			RawImage mapImageLarge = minimap.m_mapImageLarge;
			if (!((Object)(object)mapImageLarge == (Object)null) && !((Object)(object)((Component)mapImageLarge).GetComponentInChildren<RingOverlay>(true) != (Object)null))
			{
				GameObject val = new GameObject("MapRings", new Type[2]
				{
					typeof(RectTransform),
					typeof(RectMask2D)
				});
				RectTransform val2 = (RectTransform)val.transform;
				RectTransform rectTransform = ((Graphic)mapImageLarge).rectTransform;
				if ((Object)(object)minimap.m_pinRootLarge != (Object)null && ((Transform)minimap.m_pinRootLarge).IsChildOf((Transform)(object)rectTransform))
				{
					((Transform)val2).SetParent((Transform)(object)rectTransform, false);
					Stretch(val2);
					((Transform)val2).SetAsFirstSibling();
				}
				else
				{
					((Transform)val2).SetParent(((Transform)rectTransform).parent, false);
					val2.anchorMin = rectTransform.anchorMin;
					val2.anchorMax = rectTransform.anchorMax;
					val2.pivot = rectTransform.pivot;
					val2.anchoredPosition = rectTransform.anchoredPosition;
					val2.sizeDelta = rectTransform.sizeDelta;
					((Transform)val2).localScale = ((Transform)rectTransform).localScale;
					((Transform)val2).localRotation = ((Transform)rectTransform).localRotation;
					((Transform)val2).SetSiblingIndex(((Transform)rectTransform).GetSiblingIndex() + 1);
				}
				val.AddComponent<RingOverlay>().Init(minimap, mapImageLarge, val2);
			}
		}

		private static void Stretch(RectTransform rt)
		{
			//IL_0001: 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_0021: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = Vector2.zero;
			rt.anchorMax = Vector2.one;
			rt.pivot = new Vector2(0.5f, 0.5f);
			rt.offsetMin = Vector2.zero;
			rt.offsetMax = Vector2.zero;
		}

		private void Init(Minimap minimap, RawImage map, RectTransform rt)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			m_minimap = minimap;
			m_map = map;
			m_rect = rt;
			m_shadow = MakeGraphic("Shadow");
			m_line = MakeGraphic("Line");
			GameObject val = new GameObject("Labels", new Type[1] { typeof(RectTransform) });
			m_labelRoot = (RectTransform)val.transform;
			((Transform)m_labelRoot).SetParent((Transform)(object)rt, false);
			Stretch(m_labelRoot);
			MapRingsConfig.Changed += MarkDirty;
		}

		private RingGraphic MakeGraphic(string name)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)m_rect, false);
			Stretch(val2);
			RingGraphic ringGraphic = val.AddComponent<RingGraphic>();
			((Graphic)ringGraphic).raycastTarget = false;
			ringGraphic.Segments = m_segments;
			return ringGraphic;
		}

		private void MarkDirty()
		{
			m_rings = null;
			m_dirty = true;
		}

		private void OnEnable()
		{
			m_dirty = true;
		}

		private void OnDestroy()
		{
			MapRingsConfig.Changed -= MarkDirty;
		}

		private void LateUpdate()
		{
			//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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m_map == (Object)null)
			{
				return;
			}
			if (m_rings == null)
			{
				if (WorldGenerator.instance == null)
				{
					return;
				}
				m_rings = RingCatalog.Build();
				BuildLabels();
				m_dirty = true;
			}
			Rect uvRect = m_map.uvRect;
			Rect rect = ((Graphic)m_line).rectTransform.rect;
			if (m_dirty || !(uvRect == m_lastUv) || !(rect == m_lastRect))
			{
				m_dirty = false;
				m_lastUv = uvRect;
				m_lastRect = rect;
				Redraw(uvRect, rect);
			}
		}

		private Vector2 Project(Vector2 w)
		{
			//IL_0000: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			float num = w.x * m_worldToUv + 0.5f;
			float num2 = w.y * m_worldToUv + 0.5f;
			return new Vector2(((Rect)(ref m_local)).xMin + (num - ((Rect)(ref m_uv)).xMin) / ((Rect)(ref m_uv)).width * ((Rect)(ref m_local)).width, ((Rect)(ref m_local)).yMin + (num2 - ((Rect)(ref m_uv)).yMin) / ((Rect)(ref m_uv)).height * ((Rect)(ref m_local)).height);
		}

		private void Redraw(Rect uv, Rect rect)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_00c9: 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)
			m_uv = uv;
			m_local = rect;
			m_worldToUv = 1f / (m_minimap.m_pixelSize * (float)m_minimap.m_textureSize);
			float pxPerMeter = m_worldToUv * ((Rect)(ref rect)).width / ((Rect)(ref uv)).width;
			float value = MapRingsConfig.LineWidth.Value;
			float value2 = MapRingsConfig.Opacity.Value;
			Rect visible = default(Rect);
			((Rect)(ref visible))..ctor(((Rect)(ref rect)).xMin - 4f * value, ((Rect)(ref rect)).yMin - 4f * value, ((Rect)(ref rect)).width + 8f * value, ((Rect)(ref rect)).height + 8f * value);
			m_segments.Clear();
			foreach (RingDef ring in m_rings)
			{
				AddRing(ring, pxPerMeter, visible, value2);
			}
			m_line.Width = value;
			m_line.Override = null;
			m_shadow.Width = value + 2f;
			m_shadow.Override = new Color(0f, 0f, 0f, 0.45f * value2);
			((Graphic)m_shadow).SetVerticesDirty();
			((Graphic)m_line).SetVerticesDirty();
			PlaceLabels();
		}

		private void AddRing(RingDef ring, float pxPerMeter, Rect visible, float opacity)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_008f: 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)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_0121: 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_0125: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Clamp((int)((float)Math.PI * 2f * ring.Radius * pxPerMeter / 5f), (ring.Wave != 0f) ? 480 : 120, 6000);
			Color color = ring.Color;
			color.a *= opacity;
			float num2 = (float)Math.PI * 2f / (float)num;
			float num3 = 0f;
			Vector2 w = ring.PointAt(0f);
			Vector2 val = Project(w);
			for (int i = 1; i <= num; i++)
			{
				Vector2 val2 = ring.PointAt((float)i * num2);
				Vector2 val3 = Project(val2);
				Vector2 val4 = val3 - val;
				float magnitude = ((Vector2)(ref val4)).magnitude;
				if (((Vector2)(ref w)).sqrMagnitude <= 110250000f && ((Vector2)(ref val2)).sqrMagnitude <= 110250000f && SegmentMayShow(val, val3, visible))
				{
					if (ring.Dashed)
					{
						AddDashes(val, val3, magnitude, num3, color);
					}
					else
					{
						m_segments.Add(new RingSegment
						{
							A = val,
							B = val3,
							Color = color
						});
					}
				}
				num3 += magnitude;
				val = val3;
				w = val2;
			}
		}

		private static bool SegmentMayShow(Vector2 a, Vector2 b, Rect r)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if ((!(a.x < ((Rect)(ref r)).xMin) || !(b.x < ((Rect)(ref r)).xMin)) && (!(a.x > ((Rect)(ref r)).xMax) || !(b.x > ((Rect)(ref r)).xMax)) && (!(a.y < ((Rect)(ref r)).yMin) || !(b.y < ((Rect)(ref r)).yMin)))
			{
				if (a.y > ((Rect)(ref r)).yMax)
				{
					return !(b.y > ((Rect)(ref r)).yMax);
				}
				return true;
			}
			return false;
		}

		private void AddDashes(Vector2 a, Vector2 b, float len, float travelled, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = (b - a) / Mathf.Max(len, 0.0001f);
			float num = 0f;
			while (num < len)
			{
				float num2 = (travelled + num) % 15f;
				if (num2 < 9f)
				{
					float num3 = Mathf.Min(len, num + 9f - num2);
					m_segments.Add(new RingSegment
					{
						A = a + val * num,
						B = a + val * num3,
						Color = color
					});
					num = num3;
				}
				else
				{
					num += 15f - num2;
				}
			}
		}

		private void BuildLabels()
		{
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			foreach (LabelGroup group in m_groups)
			{
				if ((Object)(object)group.Text != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)group.Text).gameObject);
				}
			}
			m_groups.Clear();
			if (!MapRingsConfig.Labels.Value)
			{
				return;
			}
			foreach (RingDef ring in m_rings)
			{
				LabelGroup labelGroup = m_groups.Find((LabelGroup g) => g.Anchor.Center == ring.Center && Mathf.Abs(g.Anchor.Radius - ring.Radius) < 1f);
				if (labelGroup == null)
				{
					labelGroup = new LabelGroup
					{
						Anchor = ring
					};
					m_groups.Add(labelGroup);
				}
				labelGroup.Rings.Add(ring);
			}
			TMP_Text biomeNameLarge = m_minimap.m_biomeNameLarge;
			foreach (LabelGroup group2 in m_groups)
			{
				GameObject val = new GameObject("Label", new Type[1] { typeof(RectTransform) });
				RectTransform val2 = (RectTransform)val.transform;
				((Transform)val2).SetParent((Transform)(object)m_labelRoot, false);
				val2.sizeDelta = new Vector2(600f, 40f);
				TextMeshProUGUI val3 = val.AddComponent<TextMeshProUGUI>();
				if ((Object)(object)biomeNameLarge != (Object)null)
				{
					((TMP_Text)val3).font = biomeNameLarge.font;
					((TMP_Text)val3).fontSharedMaterial = biomeNameLarge.fontSharedMaterial;
				}
				((TMP_Text)val3).fontSize = MapRingsConfig.LabelSize.Value;
				((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val3).textWrappingMode = (TextWrappingModes)0;
				((TMP_Text)val3).overflowMode = (TextOverflowModes)0;
				((Graphic)val3).raycastTarget = false;
				((TMP_Text)val3).richText = true;
				((Graphic)val3).color = new Color(1f, 1f, 1f, Mathf.Clamp01(MapRingsConfig.Opacity.Value + 0.15f));
				((TMP_Text)val3).text = LabelText(group2);
				group2.Text = val3;
			}
		}

		private static string LabelText(LabelGroup group)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			if (!group.Anchor.OffCenter)
			{
				stringBuilder.Append("<b>").Append(group.Anchor.Radius.ToString("0")).Append(" m</b>  ");
			}
			HashSet<RingDef> hashSet = new HashSet<RingDef>();
			bool flag = true;
			foreach (RingDef ring in group.Rings)
			{
				if (hashSet.Contains(ring))
				{
					continue;
				}
				List<string> list = new List<string>();
				foreach (RingDef ring2 in group.Rings)
				{
					if (!hashSet.Contains(ring2) && ring2.Color == ring.Color && ring2.Suffix == ring.Suffix && ring2.Dashed == ring.Dashed)
					{
						hashSet.Add(ring2);
						if (!list.Contains(ring2.Name))
						{
							list.Add(ring2.Name);
						}
					}
				}
				if (!flag)
				{
					stringBuilder.Append("  ");
				}
				flag = false;
				Color color = ring.Color;
				color.a = Mathf.Clamp01(MapRingsConfig.Opacity.Value + 0.15f);
				stringBuilder.Append("<color=#").Append(ColorUtility.ToHtmlStringRGBA(color)).Append('>')
					.Append(string.Join(", ", list));
				if (!string.IsNullOrEmpty(ring.Suffix))
				{
					stringBuilder.Append(' ').Append(ring.Suffix);
				}
				stringBuilder.Append("</color>");
			}
			return stringBuilder.ToString();
		}

		private void PlaceLabels()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_002f: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: 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_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			if (m_groups.Count == 0)
			{
				return;
			}
			Vector2 center = ((Rect)(ref m_uv)).center;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor((center.x - 0.5f) / m_worldToUv, (center.y - 0.5f) / m_worldToUv);
			Vector2 val2 = Project(val);
			float value = MapRingsConfig.LabelSize.Value;
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(((Rect)(ref m_local)).xMin + value, ((Rect)(ref m_local)).yMin + value, ((Rect)(ref m_local)).width - 2f * value, ((Rect)(ref m_local)).height - 2f * value);
			Vector2 val6 = default(Vector2);
			foreach (LabelGroup group in m_groups)
			{
				RingDef anchor = group.Anchor;
				Vector2 val4 = val - anchor.Center;
				float num = ((((Vector2)(ref val4)).sqrMagnitude < 1f) ? 0f : Mathf.Atan2(val4.x, val4.y));
				Vector2 w = anchor.PointAt(num);
				Vector2 val5 = Project(w);
				bool flag = ((Vector2)(ref w)).magnitude <= 10500f && ((Rect)(ref val3)).Contains(val5);
				((Component)group.Text).gameObject.SetActive(flag);
				if (flag)
				{
					((Vector2)(ref val6))..ctor(Mathf.Sin(num), Mathf.Cos(num));
					float num2 = Mathf.Atan2(0f - val6.x, val6.y) * 57.29578f;
					if (num2 > 90f)
					{
						num2 -= 180f;
					}
					else if (num2 < -90f)
					{
						num2 += 180f;
					}
					Vector2 val7 = val2 - val5;
					val7 = ((((Vector2)(ref val7)).sqrMagnitude > 1f) ? ((Vector2)(ref val7)).normalized : (-val6));
					Vector2 val8 = ((Vector2.Dot(val7, val6) >= 0f) ? val6 : (-val6));
					RectTransform val9 = (RectTransform)((TMP_Text)group.Text).transform;
					((Transform)val9).localPosition = Vector2.op_Implicit(val5 + val8 * (value * 0.75f));
					((Transform)val9).localRotation = Quaternion.Euler(0f, 0f, num2);
				}
			}
		}
	}
}