Decompiled source of Ancient Ley Lines v0.5.2

plugins/WorldPortal.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("WorldPortal")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c80e7e8a2c08d31e02f5771e9294719ba4ef3165")]
[assembly: AssemblyProduct("WorldPortal")]
[assembly: AssemblyTitle("WorldPortal")]
[assembly: AssemblyVersion("1.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 WorldPortal
{
	[BepInPlugin("dioksy.worldportal", "Ancient Ley Lines", "0.5.2")]
	public class Plugin : BaseUnityPlugin
	{
		private class CirclePortal : MonoBehaviour, Hoverable, Interactable
		{
			public int Slot;

			public Vector3 Circle;

			private (string name, Vector3 pos, Biome biome)? dest;

			private EffectFade[] fades;

			private float nextCheck;

			private void Start()
			{
				//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_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: 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_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				fades = ((Component)this).GetComponentsInChildren<EffectFade>(true);
				GameObject val = new GameObject("hover")
				{
					layer = LayerMask.NameToLayer("piece_nonsolid")
				};
				val.transform.SetParent(((Component)this).transform, false);
				BoxCollider obj = val.AddComponent<BoxCollider>();
				obj.center = ((fades.Length != 0) ? ((Component)fades[0]).transform.localPosition : (Vector3.up * 1.5f));
				obj.size = new Vector3(2.5f, 3f, 0.5f);
			}

			private void Update()
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				if (!(Time.time < nextCheck))
				{
					nextCheck = Time.time + 2f;
					dest = Destination(Circle, Slot);
					EffectFade[] array = fades;
					for (int i = 0; i < array.Length; i++)
					{
						array[i].SetActive(dest.HasValue);
					}
				}
			}

			public string GetHoverName()
			{
				return "Ancient Portal";
			}

			public float GetHoverOffset()
			{
				return 0f;
			}

			public string GetHoverText()
			{
				//IL_001e: 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_0069: 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)
				if (!dest.HasValue)
				{
					return "Ancient Portal\nThe stones are silent. Explore further.";
				}
				string text = Dare(dest.Value.biome);
				return Localization.instance.Localize("Ancient Portal\n<i>" + Lore(dest.Value.biome) + ", " + Farness(Flat(dest.Value.pos, Circle)) + ".</i>" + ((text == null) ? "" : ("\n[<color=yellow><b>$KEY_Use</b></color>] " + text)));
			}

			public void WalkIn(Player player)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				if (dest.HasValue && Dare(dest.Value.biome) == null)
				{
					Enter(player);
				}
			}

			public bool Interact(Humanoid user, bool hold, bool alt)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				if (hold || !dest.HasValue || Dare(dest.Value.biome) == null || (Object)(object)user != (Object)(object)Player.m_localPlayer)
				{
					return false;
				}
				Enter(Player.m_localPlayer);
				return true;
			}

			public bool UseItem(Humanoid user, ItemData item)
			{
				return false;
			}

			private void Enter(Player player)
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: 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_0055: 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_005f: 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_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: 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_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: 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_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)
				(string, Vector3, Biome) value = dest.Value;
				Vector3 val = Circle - value.Item2;
				val.y = 0f;
				Vector3 pos = value.Item2 + ((Vector3)(ref val)).normalized * (Matches(value.Item1, "StoneCircle") ? 2f : 5f);
				if (Teleport(player, pos, Quaternion.LookRotation(-val)))
				{
					player.m_customData["worldportal_arrival"] = Save(value.Item2);
					player.m_customData["worldportal_return"] = Save(((Component)this).transform.position + ((Component)this).transform.forward * 2f);
				}
			}
		}

		private class PortalTrigger : MonoBehaviour
		{
			private CirclePortal portal;

			private EffectFade[] gateFades;

			private float nextCheck;

			private void Start()
			{
				portal = ((Component)this).GetComponentInParent<CirclePortal>();
				if (!Object.op_Implicit((Object)(object)portal))
				{
					gateFades = ((Component)((Component)this).transform.parent).GetComponentsInChildren<EffectFade>(true);
				}
				if (Targets == null && ZRoutedRpc.instance != null)
				{
					Targets = new List<(string, Vector3, Biome)>();
					ZRoutedRpc.instance.InvokeRoutedRPC("WorldPortal_RequestTargets", Array.Empty<object>());
				}
			}

			private void Update()
			{
				//IL_002d: 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)
				if (gateFades != null && !(Time.time < nextCheck))
				{
					nextCheck = Time.time + 2f;
					bool active = LinkedCircle(((Component)this).transform.position).HasValue || (Object.op_Implicit((Object)(object)Player.m_localPlayer) && CanReturn(Player.m_localPlayer, ((Component)this).transform.position));
					EffectFade[] array = gateFades;
					for (int i = 0; i < array.Length; i++)
					{
						array[i].SetActive(active);
					}
				}
			}

			private void OnTriggerEnter(Collider other)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: 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_007c: 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_008b: Unknown result type (might be due to invalid IL or missing references)
				Player componentInParent = ((Component)other).GetComponentInParent<Player>();
				if (!Object.op_Implicit((Object)(object)componentInParent) || (Object)(object)componentInParent != (Object)(object)Player.m_localPlayer)
				{
					return;
				}
				if (Object.op_Implicit((Object)(object)portal))
				{
					portal.WalkIn(componentInParent);
					return;
				}
				Vector3? val = LinkedCircle(((Component)this).transform.position);
				if (CanReturn(componentInParent, ((Component)this).transform.position))
				{
					TryReturn(componentInParent);
				}
				else if (val.HasValue)
				{
					TryReturn(componentInParent, val.Value + Vector3.forward * 2f);
				}
			}
		}

		private const string ArrivalKey = "worldportal_arrival";

		private const string ReturnKey = "worldportal_return";

		private const Biome Edge = (Biome)0;

		private static ManualLogSource Log;

		private static ConfigEntry<int> MaxPortals;

		private static ConfigEntry<float> BandAnchor;

		private static ConfigEntry<KeyCode> ReturnHotkey;

		private const string CircleLocations = "StoneCircle";

		private static ConfigEntry<string> TargetLocations;

		private static ConfigEntry<string> UndiscoveredLocations;

		private static ConfigEntry<string> GateLocations;

		private static ConfigEntry<string>[] BandWeights;

		private static GameObject SwirlTemplate;

		private static bool loggedStones;

		private static List<(string name, Vector3 pos, Biome biome)> Targets;

		private static readonly List<(Vector3 circle, List<(string name, Vector3 pos, Biome biome)?> dests)> Plan = new List<(Vector3, List<(string, Vector3, Biome)?>)>();

		private const string ShiftKey = "worldportal_shift";

		private const string LastShiftKey = "worldportal_lastshift";

		private static readonly string[] SecretNames = new string[30]
		{
			"RAVEN", "FROST", "EMBER", "SKALD", "STORM", "SPEAR", "FJORD", "GRAVE", "BLOOD", "FLAME",
			"STONE", "SWORD", "BLADE", "GHOST", "BONES", "FLINT", "SPIRE", "TROLL", "SAGAS", "HORNS",
			"NORNS", "RUNES", "THORN", "SLEET", "TIDES", "OATHS", "ASHES", "EAGLE", "GLOOM", "AMBER"
		};

		private static readonly Dictionary<char, string> Runes = new Dictionary<char, string>
		{
			['F'] = "Fehu",
			['U'] = "Uruz",
			['A'] = "Ansuz",
			['R'] = "Raidho",
			['K'] = "Kenaz",
			['G'] = "Gebo",
			['W'] = "Wunjo",
			['V'] = "Wunjo",
			['H'] = "Hagalaz",
			['N'] = "Naudiz",
			['I'] = "Isa",
			['J'] = "Jera",
			['Y'] = "Jera",
			['P'] = "Perthro",
			['Z'] = "Algiz",
			['S'] = "Sowilo",
			['T'] = "Tiwaz",
			['B'] = "Berkano",
			['E'] = "Ehwaz",
			['M'] = "Mannaz",
			['L'] = "Laguz",
			['O'] = "Othala",
			['D'] = "Dagaz"
		};

		private static ConfigEntry<bool> RitualEnabled;

		private static ConfigEntry<bool> OpenByBiome;

		private static ConfigEntry<bool> LeaveEntrance;

		private static ConfigEntry<int> RitualPortals;

		private static ConfigEntry<int> RitualCooldownDays;

		private static Plugin Instance;

		private static float ritualSentAt = -100f;

		private static readonly Func<Minimap, Vector3, bool> IsExplored = AccessTools.MethodDelegate<Func<Minimap, Vector3, bool>>(AccessTools.Method(typeof(Minimap), "IsExplored", (Type[])null, (Type[])null), (object)null, true);

		private static readonly Func<Player, bool> TakeInput = AccessTools.MethodDelegate<Func<Player, bool>>(AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null), (object)null, true);

		private static readonly Action<Player> SetupAwake = AccessTools.MethodDelegate<Action<Player>>(AccessTools.Method(typeof(Player), "SetupAwake", (Type[])null, (Type[])null), (object)null, true);

		private const string BiomesKey = "worldportal_biomes";

		private static readonly string[] Strain = new string[4] { "The ley lines are being strained.", "The ley lines groan beneath the stones.", "The stones tremble. The ley lines strain to breaking.", "Something old stirs beneath the circle." };

		private static string SecretName(int shift)
		{
			return SecretNames[new Random(WorldGenerator.instance.GetSeed() ^ shift).Next(SecretNames.Length)];
		}

		private void Awake()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			RitualEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Ritual", "Enabled", true, "Building portals inside a stone circle strains the ley lines; enough of them named what the stones whisper reroll every circle's destinations.");
			RitualPortals = ((BaseUnityPlugin)this).Config.Bind<int>("Ritual", "Portals", 5, "Portals named what the stones whisper needed inside one stone circle. The name has five runes, so at 5 each gate whispers one.");
			RitualCooldownDays = ((BaseUnityPlugin)this).Config.Bind<int>("Ritual", "CooldownDays", 30, "In-game days the ley lines need to recover after a shift. Completing the ritual sooner crumbles the portals and restarts the cooldown. Read on the server.");
			MaxPortals = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxPortals", 5, new ConfigDescription("Max portals per stone circle. A circle gets one per gap between its stones.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5), Array.Empty<object>()));
			LeaveEntrance = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "LeaveEntrance", false, "Leave the widest gap between the stones without a portal, as an entrance. This means one portal fewer per circle. Off: every gap gets one; they're wide enough to walk past.");
			OpenByBiome = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "OpenByBiome", true, "Portals open once you've set foot in their destination's biome. Off: only once the destination itself is explored on your map.");
			TargetLocations = ((BaseUnityPlugin)this).Config.Bind<string>("General", "TargetLocations", "Dolmen,Runestone", "Location prefab name prefixes the portals lead to (comma separated). For example, add StoneHenge for the Plains' standing stones (StoneHenge1-6), but they usually have goblins around them. Read on the server.");
			UndiscoveredLocations = ((BaseUnityPlugin)this).Config.Bind<string>("General", "UndiscoveredLocations", "", "Destinations usable before you've discovered them (comma separated, empty = none). Portals to anything else stay dark until you have.");
			BandAnchor = ((BaseUnityPlugin)this).Config.Bind<float>("Bands", "AnchorPercentile", 0.95f, "Caution: changing anything in this section changes where every portal leads. Circles get a latitude band from 0 (the world's east-west centre line) to 3, separately for the north and south half. The bands are scaled so this percentile of the circles' distance from the centre line is the far end of band 3; circles beyond it count as band 3. 1 = the farthest circle.");
			BandWeights = new ConfigEntry<string>[4]
			{
				((BaseUnityPlugin)this).Config.Bind<string>("Bands", "Band0", "Meadows:45,BlackForest:45,Swamp:5,Mountain:5", "Biome weights for portals of circles nearest the centre line (Biome:weight, comma separated). Biomes: Meadows, BlackForest, Swamp, Mountain, Plains, Mistlands, AshLands, DeepNorth, or Edge = AshLands for southern circles and DeepNorth for northern ones."),
				((BaseUnityPlugin)this).Config.Bind<string>("Bands", "Band1", "Meadows:10,BlackForest:20,Swamp:25,Mountain:25,Plains:20", "Biome weights for band 1."),
				((BaseUnityPlugin)this).Config.Bind<string>("Bands", "Band2", "BlackForest:5,Swamp:20,Mountain:20,Plains:30,Mistlands:25", "Biome weights for band 2."),
				((BaseUnityPlugin)this).Config.Bind<string>("Bands", "Band3", "Plains:10,Mistlands:30,Edge:60", "Biome weights for the outermost band. Every circle here also gets at least one Edge portal.")
			};
			ReturnHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ReturnKey", (KeyCode)103, "Key to travel back from the runestone you arrived at to the portal you came from.");
			GateLocations = ((BaseUnityPlugin)this).Config.Bind<string>("General", "GateLocations", "Dolmen", "Location prefab name prefixes that get a gate (portal swirl you walk into) in their centre (comma separated). It opens both ways once the circle portal leading here is open.");
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		private static bool Matches(string name, string prefixes)
		{
			return (from p in prefixes.Split(',')
				select p.Trim()).Any((string p) => p.Length > 0 && name.StartsWith(p, StringComparison.OrdinalIgnoreCase));
		}

		private static string Save(Vector3 v)
		{
			//IL_000d: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			return FormattableString.Invariant($"{v.x},{v.y},{v.z}");
		}

		private static Vector3? Load(Player player, string key)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!player.m_customData.TryGetValue(key, out var value))
			{
				return null;
			}
			float[] array = (from f in value.Split(',')
				select float.Parse(f, CultureInfo.InvariantCulture)).ToArray();
			return new Vector3(array[0], array[1], array[2]);
		}

		private static bool CanReturn(Player player, Vector3 pos)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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)
			Vector3? val = Load(player, "worldportal_arrival");
			if (!val.HasValue)
			{
				return false;
			}
			Vector3 val2 = pos - val.Value;
			val2.y = 0f;
			return ((Vector3)(ref val2)).magnitude < 25f;
		}

		private static bool Teleport(Player player, Vector3 pos, Quaternion rot)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (((Humanoid)player).IsTeleportable(false))
			{
				return ((Character)player).TeleportTo(pos, rot, true);
			}
			((Character)player).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false);
			return false;
		}

		private static void TryReturn(Player player, Vector3? fallback = null)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			Vector3? val = Load(player, "worldportal_return") ?? fallback;
			if (val.HasValue && Teleport(player, val.Value, ((Component)player).transform.rotation))
			{
				player.m_customData.Remove("worldportal_arrival");
				player.m_customData.Remove("worldportal_return");
			}
		}

		private static bool Reachable((string name, Vector3 pos, Biome biome) t)
		{
			//IL_002e: 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)
			if (!Matches(t.name, UndiscoveredLocations.Value))
			{
				if (!OpenByBiome.Value)
				{
					return IsExplored(Minimap.instance, t.pos);
				}
				if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					return KnowsBiome(Player.m_localPlayer, t.biome);
				}
				return false;
			}
			return true;
		}

		private unsafe static bool KnowsBiome(Player player, Biome biome)
		{
			if (player.m_customData.TryGetValue("worldportal_biomes", out var value))
			{
				return value.Split(',').Contains<string>(((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString());
			}
			return false;
		}

		[HarmonyPatch(typeof(Player), "AddKnownBiome")]
		[HarmonyPostfix]
		private static void RememberBiome(Player __instance, BiomeSector __0)
		{
			//IL_0002: 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)
			if (!KnowsBiome(__instance, __0.Biome))
			{
				__instance.m_customData.TryGetValue("worldportal_biomes", out var value);
				__instance.m_customData["worldportal_biomes"] = (string.IsNullOrEmpty(value) ? ((object)Unsafe.As<Biome, Biome>(ref __0.Biome)/*cast due to .constrained prefix*/).ToString() : $"{value},{__0.Biome}");
			}
		}

		private static Vector3? LinkedCircle(Vector3 gate)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_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)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			foreach (var item3 in Plan)
			{
				Vector3 item = item3.circle;
				List<(string, Vector3, Biome)?> item2 = item3.dests;
				for (int i = 0; i < item2.Count; i++)
				{
					(string, Vector3, Biome)? tuple = item2[i];
					if (tuple.HasValue && Flat(tuple.GetValueOrDefault().Item2, gate) < 25f)
					{
						return Destination(item, i).HasValue ? new Vector3?(item) : ((Vector3?)null);
					}
				}
			}
			return null;
		}

		private static float Flat(Vector3 a, Vector3 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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)
			Vector2 val = new Vector2(a.x - b.x, a.z - b.z);
			return ((Vector2)(ref val)).magnitude;
		}

		private static (string name, Vector3 pos, Biome biome)? Destination(Vector3 circle, int slot)
		{
			//IL_0007: 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)
			if (!Object.op_Implicit((Object)(object)Minimap.instance))
			{
				return null;
			}
			(Vector3, List<(string, Vector3, Biome)?>) tuple = Plan.FirstOrDefault(((Vector3 circle, List<(string name, Vector3 pos, Biome biome)?> dests) p) => Flat(p.circle, circle) < 50f);
			(string, Vector3, Biome)? result = ((tuple.Item2 != null && slot < tuple.Item2.Count) ? tuple.Item2[slot] : (((string, Vector3, Biome)?)null));
			if (!result.HasValue || !Reachable(result.Value))
			{
				return null;
			}
			return result;
		}

		private static List<(Biome biome, int weight)> ParseWeights(ConfigEntry<string> entry)
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			List<(Biome, int)> list = new List<(Biome, int)>();
			foreach (string[] item in from p in entry.Value.Split(',')
				select p.Split(':') into p
				where p.Length == 2
				select p)
			{
				string text = item[0].Trim();
				if (text.Equals("Edge", StringComparison.OrdinalIgnoreCase))
				{
					list.Add(((Biome)0, int.Parse(item[1])));
					continue;
				}
				try
				{
					list.Add(((Biome)Enum.Parse(typeof(Biome), text, ignoreCase: true), int.Parse(item[1])));
				}
				catch (ArgumentException)
				{
					Log.LogError((object)(((ConfigEntryBase)entry).Definition.Key + ": unknown biome '" + text + "'"));
				}
			}
			return list;
		}

		private static float Percentile(List<float> values, float p)
		{
			if (values.Count == 0)
			{
				return 1f;
			}
			values.Sort();
			float num = Mathf.Clamp01(p) * (float)(values.Count - 1);
			int num2 = (int)num;
			if (num2 + 1 >= values.Count)
			{
				return values[num2];
			}
			return Mathf.Lerp(values[num2], values[num2 + 1], num - (float)num2);
		}

		private static void BuildPlan(int shift)
		{
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			Plan.Clear();
			List<(string, Vector3, Biome)> list = (from t in Targets
				where Matches(t.name, "StoneCircle")
				orderby Mathf.Abs(t.pos.z)
				select t).ToList();
			if (shift > 0)
			{
				Random order = new Random(shift);
				list = list.OrderBy<(string, Vector3, Biome), int>(((string name, Vector3 pos, Biome biome) _) => order.Next()).ToList();
			}
			List<(string name, Vector3 pos, Biome biome)> targets = Targets.Where(((string name, Vector3 pos, Biome biome) t) => !Matches(t.name, "StoneCircle")).ToList();
			List<(Biome, int)>[] array = BandWeights.Select(ParseWeights).ToArray();
			float num = Mathf.Max(1f, Percentile((from tuple in list
				where tuple.pos.z >= 0f
				select tuple.pos.z).ToList(), BandAnchor.Value));
			float num2 = Mathf.Max(1f, Percentile((from tuple in list
				where tuple.pos.z < 0f
				select 0f - tuple.pos.z).ToList(), BandAnchor.Value));
			HashSet<int> used = new HashSet<int>();
			float[] minDist = targets.Select(((string name, Vector3 pos, Biome biome) _) => float.MaxValue).ToArray();
			foreach (var c in list)
			{
				float z = c.Item2.z;
				int num3 = Mathf.Min(3, (int)(Mathf.Abs(z) / ((z >= 0f) ? num : num2) * 3.5f + 0.5f));
				List<(Biome, int)> source = array[num3];
				Random random = new Random(((int)c.Item2.x * 73856093) ^ ((int)z * 19349663) ^ (shift * 83492791));
				List<(string, Vector3, Biome)?> list2 = new List<(string, Vector3, Biome)?>();
				for (int num4 = 0; num4 < MaxPortals.Value; num4++)
				{
					int roll = random.Next(Math.Max(1, source.Sum<(Biome, int)>(((Biome biome, int weight) w) => w.weight)));
					Biome biome = source.FirstOrDefault<(Biome, int)>(((Biome biome, int weight) w) => (roll -= w.weight) < 0).Item1;
					if (num4 == 0 && num3 == 3)
					{
						biome = (Biome)0;
					}
					if ((int)biome == 0)
					{
						biome = (Biome)((z < 0f) ? 32 : 64);
					}
					int num5 = (from i in Enumerable.Range(0, targets.Count)
						where !used.Contains(i) && targets[i].biome == biome
						orderby targets[i].pos.z < 0f == z < 0f descending, minDist[i] descending, Flat(targets[i].pos, c.Item2)
						select i).DefaultIfEmpty(-1).First();
					if (num5 < 0)
					{
						list2.Add(null);
						continue;
					}
					used.Add(num5);
					list2.Add(targets[num5]);
					for (int num6 = 0; num6 < targets.Count; num6++)
					{
						minDist[num6] = Mathf.Min(minDist[num6], Flat(targets[num6].pos, targets[num5].pos));
					}
				}
				Plan.Add((c.Item2, list2));
			}
			Log.LogInfo((object)($"Portal plan: {list.Count} circles, {Plan.Sum(((Vector3 circle, List<(string name, Vector3 pos, Biome biome)?> dests) p) => p.dests.Count(((string name, Vector3 pos, Biome biome)? d) => d.HasValue))} destinations: " + string.Join(", ", from d in Plan.SelectMany(((Vector3 circle, List<(string name, Vector3 pos, Biome biome)?> dests) p) => p.dests)
				where d.HasValue
				group d by d.Value.biome into g
				select $"{g.Key} {g.Count()}")));
		}

		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		[HarmonyPostfix]
		private static void BuildTemplates(ZNetScene __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)SwirlTemplate))
			{
				return;
			}
			GameObject val = new GameObject("WorldPortalTemplates");
			val.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val);
			GameObject prefab = __instance.GetPrefab("portal_wood");
			TeleportWorld component = prefab.GetComponent<TeleportWorld>();
			SwirlTemplate = new GameObject("WorldPortalSwirl");
			SwirlTemplate.transform.SetParent(val.transform);
			Transform[] array = (Transform[])(object)new Transform[2]
			{
				((Component)component.m_target_found).transform,
				((Component)prefab.GetComponentInChildren<TeleportWorldTrigger>(true)).transform
			};
			foreach (Transform val2 in array)
			{
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, SwirlTemplate.transform);
				val3.transform.localPosition = prefab.transform.InverseTransformPoint(val2.position);
				val3.transform.localRotation = Quaternion.Inverse(prefab.transform.rotation) * val2.rotation;
				val3.SetActive(true);
				TeleportWorldTrigger component2 = val3.GetComponent<TeleportWorldTrigger>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					Object.DestroyImmediate((Object)(object)component2);
					val3.AddComponent<PortalTrigger>();
				}
			}
		}

		[HarmonyPatch(typeof(Game), "Start")]
		[HarmonyPostfix]
		private static void RegisterRpcs()
		{
			Targets = null;
			ZRoutedRpc.instance.Register("WorldPortal_RequestTargets", (Action<long>)delegate(long sender)
			{
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Expected O, but got Unknown
				//IL_0063: 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_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: 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_009c: Expected I4, but got Unknown
				if (ZNet.instance.IsServer())
				{
					List<LocationInstance> list = ZoneSystem.instance.m_locationInstances.Values.Where((LocationInstance l) => Matches(l.m_location.m_prefabName, TargetLocations.Value) || Matches(l.m_location.m_prefabName, "StoneCircle")).ToList();
					ZPackage val = new ZPackage();
					val.Write(list.Count);
					foreach (LocationInstance item in list)
					{
						val.Write(item.m_location.m_prefabName);
						val.Write(item.m_position);
						val.Write((int)WorldGenerator.instance.GetBiome(item.m_position));
					}
					ZRoutedRpc.instance.InvokeRoutedRPC(sender, "WorldPortal_Targets", new object[1] { val });
				}
			});
			ZRoutedRpc.instance.Register<ZPackage>("WorldPortal_Targets", (Action<long, ZPackage>)delegate(long sender, ZPackage pkg)
			{
				int count = pkg.ReadInt();
				Targets = (from _ in Enumerable.Range(0, count)
					select (pkg.ReadString(), pkg.ReadVector3(), (Biome)pkg.ReadInt())).ToList();
				BuildPlan(GlobalInt("worldportal_shift", 0));
			});
			ZRoutedRpc.instance.Register<Vector3, string>("WorldPortal_Ritual", (Action<long, Vector3, string>)delegate(long sender, Vector3 circle, string name)
			{
				//IL_00e9: 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_009f: Unknown result type (might be due to invalid IL or missing references)
				if (ZNet.instance.IsServer())
				{
					if (name != SecretName(GlobalInt("worldportal_shift", 0)).ToLowerInvariant())
					{
						ZRoutedRpc.instance.InvokeRoutedRPC(sender, "WorldPortal_NameUnknown", Array.Empty<object>());
					}
					else
					{
						int day = EnvMan.instance.GetDay();
						bool num = day - GlobalInt("worldportal_lastshift", -1073741824) >= RitualCooldownDays.Value;
						ZoneSystem.instance.SetGlobalKey(string.Format("{0} {1}", "worldportal_lastshift", day));
						if (!num)
						{
							ZRoutedRpc.instance.InvokeRoutedRPC(sender, "WorldPortal_Overloaded", new object[1] { circle });
						}
						else
						{
							int num2 = GlobalInt("worldportal_shift", 0) + 1;
							ZoneSystem.instance.SetGlobalKey(string.Format("{0} {1}", "worldportal_shift", num2));
							Log.LogInfo((object)$"Ley lines shifted (shift {num2}) by a ritual at {circle}");
							ZRoutedRpc.instance.InvokeRoutedRPC(0L, "WorldPortal_Shifted", new object[3] { sender, num2, circle });
						}
					}
				}
			});
			ZRoutedRpc.instance.Register<long, int, Vector3>("WorldPortal_Shifted", (Action<long, long, int, Vector3>)delegate(long sender, long ritualist, int shift, Vector3 circle)
			{
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				List<(string name, Vector3 pos, Biome biome)> targets = Targets;
				if (targets != null && targets.Count > 0)
				{
					BuildPlan(shift);
				}
				Player localPlayer = Player.m_localPlayer;
				if (Object.op_Implicit((Object)(object)localPlayer))
				{
					if (ritualist != ZNet.GetUID())
					{
						Announce(localPlayer, "The ley lines shift…");
					}
					else
					{
						CrumbleAll(circle);
						((MonoBehaviour)Instance).StartCoroutine(KnockedOut(localPlayer));
					}
				}
			});
			ZRoutedRpc.instance.Register<Vector3>("WorldPortal_Overloaded", (Action<long, Vector3>)delegate(long sender, Vector3 circle)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				Player localPlayer = Player.m_localPlayer;
				if (Object.op_Implicit((Object)(object)localPlayer))
				{
					CrumbleAll(circle);
					GameCamera.instance.AddShake(((Component)localPlayer).transform.position, 30f, 2f, false);
					Announce(localPlayer, "The ley lines are overloaded. The stones reject the gates.");
				}
			});
			ZRoutedRpc.instance.Register("WorldPortal_NameUnknown", (Action<long>)delegate
			{
				if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					Announce(Player.m_localPlayer, "The stones do not know that name.");
				}
			});
			ZRoutedRpc.instance.Register<Vector3, string, float>("WorldPortal_Strain", (Action<long, Vector3, string, float>)delegate(long sender, Vector3 pos, string message, float shake)
			{
				//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_002c: Unknown result type (might be due to invalid IL or missing references)
				Player localPlayer = Player.m_localPlayer;
				if (Object.op_Implicit((Object)(object)localPlayer) && !(Vector3.Distance(((Component)localPlayer).transform.position, pos) > 50f))
				{
					GameCamera.instance.AddShake(pos, 30f, shake, false);
					Announce(localPlayer, message);
				}
			});
		}

		private static void Announce(Player player, string message)
		{
			((Character)player).Message((MessageType)2, message, 0, (Sprite)null, false);
			Chat instance = Chat.instance;
			if (instance != null)
			{
				((Terminal)instance).AddString("<color=#9fd3ff>" + message + "</color>");
			}
		}

		private static string GlobalString(string key)
		{
			string result = default(string);
			if (!Object.op_Implicit((Object)(object)ZoneSystem.instance) || !ZoneSystem.instance.GetGlobalKey(key, ref result))
			{
				return "";
			}
			return result;
		}

		private static int GlobalInt(string key, int fallback)
		{
			if (!int.TryParse(GlobalString(key), out var result))
			{
				return fallback;
			}
			return result;
		}

		private static bool Recovering()
		{
			if (Object.op_Implicit((Object)(object)EnvMan.instance))
			{
				return EnvMan.instance.GetDay() - GlobalInt("worldportal_lastshift", -1073741824) < RitualCooldownDays.Value;
			}
			return false;
		}

		private static Location CircleAt(Vector3 pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Location location = Location.GetLocation(pos, false);
			if (!Object.op_Implicit((Object)(object)location) || !Matches(Utils.GetPrefabName(((Component)location).gameObject), "StoneCircle"))
			{
				return null;
			}
			return location;
		}

		private static List<TeleportWorld> PortalsIn(Location circle)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			List<Piece> list = new List<Piece>();
			Piece.GetAllPiecesInRadius(((Component)circle).transform.position, circle.m_exteriorRadius, list);
			return (from p in list
				select ((Component)p).GetComponent<TeleportWorld>() into t
				where Object.op_Implicit((Object)(object)t) && ((Component)t).GetComponent<ZNetView>().IsValid()
				select t).ToList();
		}

		[HarmonyPatch(typeof(Player), "PlacePiece")]
		[HarmonyPostfix]
		private static void WarnStrain(Piece piece, Vector3 pos)
		{
			//IL_001a: 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)
			if (!RitualEnabled.Value || !Object.op_Implicit((Object)(object)((Component)piece).GetComponent<TeleportWorld>()))
			{
				return;
			}
			Location val = CircleAt(pos);
			if (Object.op_Implicit((Object)(object)val))
			{
				int count = PortalsIn(val).Count;
				List<string> list = (from c in SecretName(GlobalInt("worldportal_shift", 0))
					select Runes[c]).ToList();
				string text = (Recovering() ? ((count >= RitualPortals.Value) ? "The stones are silent. The ley lines have not recovered." : "The ley lines are still recovering.") : ((count < RitualPortals.Value) ? (Strain[Mathf.Clamp(count - 1 + Strain.Length - (RitualPortals.Value - 1), 0, Strain.Length - 1)] + ((count <= list.Count) ? (" The stones whisper " + list[count - 1] + ".") : "")) : (((RitualPortals.Value == 5) ? "Five" : RitualPortals.Value.ToString()) + " gates, one name. The stones chant: " + string.Join(", ", list) + ".")));
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "WorldPortal_Strain", new object[3]
				{
					pos,
					text,
					0.4f * (float)Mathf.Min(count, RitualPortals.Value)
				});
			}
		}

		[HarmonyPatch(typeof(TeleportWorld), "SetText")]
		[HarmonyPostfix]
		private static void CheckRitual(TeleportWorld __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (RitualEnabled.Value && Object.op_Implicit((Object)(object)CircleAt(((Component)__instance).transform.position)))
			{
				((MonoBehaviour)Instance).StartCoroutine(CheckRitualSoon(((Component)__instance).transform.position));
			}
		}

		private static IEnumerator CheckRitualSoon(Vector3 pos)
		{
			//IL_0007: 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)
			yield return (object)new WaitForSeconds(1f);
			Location val = CircleAt(pos);
			if (Object.op_Implicit((Object)(object)val) && !(Time.time - ritualSentAt < 10f))
			{
				List<TeleportWorld> list = PortalsIn(val);
				List<string> list2 = list.Select((TeleportWorld p) => p.GetText().Trim().ToLowerInvariant()).Distinct().ToList();
				if (list.Count >= RitualPortals.Value && list2.Count == 1 && list2[0].Length != 0)
				{
					ritualSentAt = Time.time;
					ZRoutedRpc.instance.InvokeRoutedRPC("WorldPortal_Ritual", new object[2]
					{
						((Component)val).transform.position,
						list2[0]
					});
				}
			}
		}

		private static void CrumbleAll(Vector3 circlePos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Location val = CircleAt(circlePos);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			foreach (TeleportWorld item in PortalsIn(val))
			{
				Crumble(item);
			}
		}

		private static void Crumble(TeleportWorld portal)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)portal).transform.position + Vector3.up;
			foreach (Requirement item in ((Component)portal).GetComponent<Piece>().m_resources.Where((Requirement r) => Object.op_Implicit((Object)(object)r.m_resItem) && r.m_amount / 2 > 0))
			{
				Object.Instantiate<GameObject>(((Component)item.m_resItem).gameObject, val, Quaternion.identity).GetComponent<ItemDrop>().SetStack(item.m_amount / 2);
			}
			((Component)portal).GetComponent<WearNTear>().Remove(true);
		}

		private static IEnumerator KnockedOut(Player player)
		{
			CameraEffects fx = CameraEffects.instance;
			bool forceDof = fx.m_forceDof;
			bool dofAutoFocus = fx.m_dofAutoFocus;
			float dofMinDistance = fx.m_dofMinDistance;
			float dofMaxDistance = fx.m_dofMaxDistance;
			float maxDist = dofMaxDistance;
			float minDist = dofMinDistance;
			bool autoFocus = dofAutoFocus;
			bool forceDof2 = forceDof;
			fx.m_forceDof = true;
			fx.m_dofAutoFocus = false;
			for (float t = 0f; t < 3f; t += Time.deltaTime)
			{
				GameCamera.instance.AddShake(((Component)player).transform.position, 10f, 0.5f + t, false);
				fx.m_dofMinDistance = (fx.m_dofMaxDistance = Mathf.Lerp(maxDist, 0.2f, t / 3f));
				yield return null;
			}
			Vector3 here = ((Component)player).transform.position;
			List<(string, Vector3, Biome)> list = (Targets ?? new List<(string, Vector3, Biome)>()).Where(((string name, Vector3 pos, Biome biome) c) => Matches(c.name, "StoneCircle") && Flat(c.pos, here) > 100f).ToList();
			Vector3 val = ((list.Count > 0) ? list[Random.Range(0, list.Count)].Item2 : here);
			player.m_customData.Remove("worldportal_arrival");
			player.m_customData.Remove("worldportal_return");
			((Character)player).TeleportTo(val + Vector3.forward * 2f, ((Component)player).transform.rotation, true);
			yield return (object)new WaitForSeconds(1f);
			CameraEffects val2 = fx;
			CameraEffects val3 = fx;
			CameraEffects val4 = fx;
			dofAutoFocus = forceDof2;
			forceDof = autoFocus;
			dofMaxDistance = minDist;
			dofMinDistance = maxDist;
			fx.m_forceDof = dofAutoFocus;
			val2.m_dofAutoFocus = forceDof;
			val3.m_dofMinDistance = dofMaxDistance;
			val4.m_dofMaxDistance = dofMinDistance;
			while (Object.op_Implicit((Object)(object)player) && ((Character)player).IsTeleporting())
			{
				yield return null;
			}
			if (Object.op_Implicit((Object)(object)player))
			{
				((Component)player).GetComponent<ZNetView>().GetZDO().Set(ZDOVars.s_wakeup, true);
				SetupAwake(player);
				yield return (object)new WaitForSeconds(4f);
				((Character)player).Message((MessageType)2, "The ley lines shift…", 0, (Sprite)null, false);
			}
		}

		[HarmonyPatch(typeof(Location), "Awake")]
		[HarmonyPostfix]
		private static void DecorateLocation(Location __instance)
		{
			//IL_0035: 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)
			if (Object.op_Implicit((Object)(object)SwirlTemplate))
			{
				string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject);
				if (Matches(prefabName, GateLocations.Value))
				{
					Object.Instantiate<GameObject>(SwirlTemplate, ((Component)__instance).transform.position, ((Component)__instance).transform.rotation, ((Component)__instance).transform);
				}
				if (Matches(prefabName, "StoneCircle"))
				{
					PlacePortals(__instance);
				}
			}
		}

		private static void PlacePortals(Location circle)
		{
			//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_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			Vector3 centre = ((Component)circle).transform.position;
			List<Collider> source = ((Component)circle).GetComponentsInChildren<Collider>().Where(delegate(Collider c)
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				if (!c.isTrigger)
				{
					Bounds bounds = c.bounds;
					return ((Bounds)(ref bounds)).size.y > 1.5f;
				}
				return false;
			}).ToList();
			if (!loggedStones)
			{
				loggedStones = true;
				Log.LogInfo((object)("Stone circle colliders (name, height, distance from centre): " + string.Join("; ", source.Select(delegate(Collider c)
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					//IL_0014: 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_0029: 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_0032: Unknown result type (might be due to invalid IL or missing references)
					string name = ((Object)c).name;
					Bounds bounds = c.bounds;
					object arg = ((Bounds)(ref bounds)).size.y;
					bounds = c.bounds;
					return $"{name} {arg:0.0}m {Vector3.Distance(((Bounds)(ref bounds)).center, centre):0.0}m";
				}))));
			}
			List<Vector2> source2 = (from d in ((IEnumerable<Collider>)source).Select((Func<Collider, Vector2>)delegate(Collider c)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_0009: 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_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_001a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0020: Unknown result type (might be due to invalid IL or missing references)
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					Bounds bounds = c.bounds;
					Vector3 val3 = ((Bounds)(ref bounds)).center - centre;
					return new Vector2(val3.x, val3.z);
				})
				where ((Vector2)(ref d)).magnitude > 2f && ((Vector2)(ref d)).magnitude < circle.m_exteriorRadius
				select d).ToList();
			List<float> angles = new List<float>();
			foreach (float item in from d in source2
				select Mathf.Atan2(d.y, d.x) * 57.29578f into a
				orderby a
				select a)
			{
				if (angles.Count == 0 || item - angles[angles.Count - 1] > 15f)
				{
					angles.Add(item);
				}
			}
			if (angles.Count > 1 && angles[0] + 360f - angles[angles.Count - 1] < 15f)
			{
				angles.RemoveAt(angles.Count - 1);
			}
			if (angles.Count < 3)
			{
				Log.LogWarning((object)$"Stone circle at {centre}: found {angles.Count} stones, no portals placed.");
				return;
			}
			float radius = source2.Average((Vector2 d) => ((Vector2)(ref d)).magnitude);
			List<(float, float)> source3 = angles.Select((float a, int i) => (from: a, to: (i + 1 < angles.Count) ? angles[i + 1] : (angles[0] + 360f))).ToList();
			(float from, float to) entrance = source3.OrderByDescending<(float, float), float>(((float from, float to) g) => g.to - g.from).First();
			List<Vector3> list = (from g in source3.Where<(float, float)>(delegate((float @from, float to) g)
				{
					if (LeaveEntrance.Value)
					{
						(float, float) tuple = g;
						(float, float) tuple2 = entrance;
						if (tuple.Item1 == tuple2.Item1)
						{
							return tuple.Item2 != tuple2.Item2;
						}
						return true;
					}
					return true;
				}).Take(MaxPortals.Value)
				select (g.@from + g.to) / 2f * ((float)Math.PI / 180f) into a
				select centre + new Vector3(Mathf.Cos(a), 0f, Mathf.Sin(a)) * radius).ToList();
			float num = list.Max((Vector3 p) => ZoneSystem.instance.GetGroundHeight(p));
			int num2 = 0;
			Vector3 val = default(Vector3);
			foreach (Vector3 item2 in list)
			{
				((Vector3)(ref val))..ctor(item2.x, num, item2.z);
				Vector3 val2 = centre - val;
				val2.y = 0f;
				CirclePortal circlePortal = Object.Instantiate<GameObject>(SwirlTemplate, val, Quaternion.LookRotation(val2), ((Component)circle).transform).AddComponent<CirclePortal>();
				circlePortal.Slot = num2++;
				circlePortal.Circle = centre;
			}
		}

		private static string Lore(Biome biome)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected I4, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Invalid comparison between Unknown and I4
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			if ((int)biome <= 16)
			{
				switch (biome - 1)
				{
				default:
					if ((int)biome != 8)
					{
						if ((int)biome != 16)
						{
							break;
						}
						return "Golden fields beneath a burning sun";
					}
					return "A dark wood where the trees grow close";
				case 0:
					return "A calm place of soft grass and gentle wind";
				case 1:
					return "A drowned land that smells of rot";
				case 3:
					return "Cold stone and howling wind, high above the clouds";
				case 2:
					break;
				}
			}
			else
			{
				if ((int)biome == 32)
				{
					return "Fire and ash, where the sky burns red";
				}
				if ((int)biome == 64)
				{
					return "Endless ice, where the cold never sleeps";
				}
				if ((int)biome == 512)
				{
					return "A land swallowed by mist";
				}
			}
			return "Restless waters";
		}

		private static string Farness(float meters)
		{
			if (!(meters < 1500f))
			{
				if (!(meters < 4000f))
				{
					if (!(meters < 7000f))
					{
						return "at the very edge of the world";
					}
					return "far, far away";
				}
				return "far away";
			}
			return "not far from here";
		}

		private static string Dare(Biome biome)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)biome != 32)
			{
				if ((int)biome != 64)
				{
					return null;
				}
				return "Challenge the blizzard";
			}
			return "Brave the heat";
		}

		[HarmonyPatch(typeof(RuneStone), "GetHoverText")]
		[HarmonyPostfix]
		private static void ShowReturn(RuneStone __instance, ref string __result)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && CanReturn(Player.m_localPlayer, ((Component)__instance).transform.position))
			{
				__result += $"\n[<color=yellow><b>{ReturnHotkey.Value}</b></color>] Return to the stone circle";
			}
		}

		[HarmonyPatch(typeof(Player), "Update")]
		[HarmonyPostfix]
		private static void ReturnOnKey(Player __instance)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && TakeInput(__instance) && ZInput.GetKeyDown(ReturnHotkey.Value, false))
			{
				GameObject hoverObject = ((Humanoid)__instance).GetHoverObject();
				RuneStone val = ((hoverObject != null) ? hoverObject.GetComponentInParent<RuneStone>() : null);
				if (Object.op_Implicit((Object)(object)val) && CanReturn(__instance, ((Component)val).transform.position))
				{
					TryReturn(__instance);
				}
			}
		}
	}
}