Decompiled source of BiggerMap v0.9.8

plugins/BiggerMap.dll

Decompiled 11 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Cinemachine;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using Microsoft.CodeAnalysis;
using Unity.AI.Navigation;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BiggerMap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c2f166f8637088c8a5e98b6b9aa812f84bb42412")]
[assembly: AssemblyProduct("BiggerMap")]
[assembly: AssemblyTitle("BiggerMap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 BiggerMap
{
	internal static class Blockers
	{
		private const float Cell = 4f;

		internal static int Clean(Transform managerRoot, Transform variantRoot, HashSet<int> obstacleLayers)
		{
			//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e8: Expected O, but got Unknown
			//IL_056b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0572: Expected O, but got Unknown
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: 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_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			Physics.SyncTransforms();
			List<Bounds> list = new List<Bounds>();
			Dictionary<long, List<int>> dictionary = new Dictionary<long, List<int>>();
			foreach (Renderer item in Object.FindObjectsOfType<Renderer>())
			{
				try
				{
					if ((Object)(object)item == (Object)null || !item.enabled || !((Component)item).gameObject.activeInHierarchy)
					{
						continue;
					}
					switch (((MemberInfo)((Object)item).GetIl2CppType()).Name)
					{
					case "LineRenderer":
						continue;
					case "TrailRenderer":
						continue;
					case "SpriteRenderer":
						continue;
					}
					Bounds bounds = item.bounds;
					if (((Bounds)(ref bounds)).size.y < 0.3f)
					{
						continue;
					}
					int count = list.Count;
					list.Add(bounds);
					int num = Key(((Bounds)(ref bounds)).min.x);
					int num2 = Key(((Bounds)(ref bounds)).max.x);
					int num3 = Key(((Bounds)(ref bounds)).min.z);
					int num4 = Key(((Bounds)(ref bounds)).max.z);
					if ((num2 - num + 1) * (num4 - num3 + 1) > 400)
					{
						num = (num2 = (num3 = (num4 = int.MinValue)));
					}
					for (int i = num; i <= num2 && i != int.MinValue; i++)
					{
						for (int j = num3; j <= num4; j++)
						{
							long key = ((long)i << 32) ^ (uint)j;
							if (!dictionary.TryGetValue(key, out var value))
							{
								value = (dictionary[key] = new List<int>());
							}
							value.Add(count);
						}
					}
				}
				catch
				{
				}
			}
			int num5 = 0;
			List<Collider> list3 = new List<Collider>();
			List<string> list4 = new List<string>();
			Ray val = default(Ray);
			RaycastHit val2 = default(RaycastHit);
			foreach (Collider componentsInChild in ((Component)variantRoot).GetComponentsInChildren<Collider>(false))
			{
				try
				{
					if ((Object)(object)componentsInChild == (Object)null || !componentsInChild.enabled || componentsInChild.isTrigger || ((MemberInfo)((Object)componentsInChild).GetIl2CppType()).Name == "TerrainCollider")
					{
						continue;
					}
					GameObject gameObject = ((Component)componentsInChild).gameObject;
					if (!obstacleLayers.Contains(gameObject.layer) || ((Object)gameObject).name == "FloorCollider" || (((Object)gameObject).name == "Wall" && (Object)(object)gameObject.transform.parent != (Object)null && ((Object)gameObject.transform.parent).name == "BiggerMap_Wall") || IsGameplay(((Component)componentsInChild).transform, variantRoot))
					{
						continue;
					}
					Bounds bounds2 = componentsInChild.bounds;
					if (((Bounds)(ref bounds2)).size.x < 0.2f && ((Bounds)(ref bounds2)).size.z < 0.2f)
					{
						continue;
					}
					int num6 = 0;
					int num7 = 0;
					for (int k = 0; k < 6; k++)
					{
						for (int l = 0; l < 6; l++)
						{
							float num8 = Mathf.Lerp(((Bounds)(ref bounds2)).min.x, ((Bounds)(ref bounds2)).max.x, ((float)k + 0.5f) / 6f);
							float num9 = Mathf.Lerp(((Bounds)(ref bounds2)).min.z, ((Bounds)(ref bounds2)).max.z, ((float)l + 0.5f) / 6f);
							((Ray)(ref val))..ctor(new Vector3(num8, ((Bounds)(ref bounds2)).max.y + 1f, num9), Vector3.down);
							if (componentsInChild.Raycast(val, ref val2, ((Bounds)(ref bounds2)).size.y + 2f))
							{
								num6++;
								if (Visible(new Vector3(num8, ((RaycastHit)(ref val2)).point.y, num9), bounds2, list, dictionary))
								{
									num7++;
								}
							}
						}
					}
					if (num6 < 3)
					{
						continue;
					}
					num5++;
					if (!((float)num7 >= (float)num6 * 0.4f))
					{
						list3.Add(componentsInChild);
						if (list4.Count < 8)
						{
							list4.Add($"{((Object)gameObject).name} ({num7}/{num6})");
						}
					}
				}
				catch
				{
				}
			}
			bool flag = default(bool);
			if (list3.Count > 0 && list3.Count > Math.Max(10, num5 / 4))
			{
				ManualLogSource log = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(115, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Invisible blockers: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(list3.Count);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" of ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(num5);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" solid pieces looked invisible; that's too many to trust, so none were switched off. E.g. ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(string.Join(", ", list4));
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(".");
				}
				log.LogWarning(val3);
				return 0;
			}
			foreach (Collider item2 in list3)
			{
				try
				{
					item2.enabled = false;
				}
				catch
				{
				}
			}
			if (list3.Count > 0)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(83, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Switched off ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(list3.Count);
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" invisible blockers (solid with nothing visible there) out of ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(num5);
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(", e.g. ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(string.Join(", ", list4));
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(".");
				}
				log2.LogInfo(val4);
			}
			else
			{
				ManualLogSource log3 = Plugin.Log;
				BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(48, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("No invisible blockers found among ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(num5);
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" solid pieces.");
				}
				log3.LogInfo(val4);
			}
			return list3.Count;
		}

		private static int Key(float v)
		{
			return Mathf.FloorToInt(v / 4f);
		}

		private static bool Visible(Vector3 p, Bounds collider, List<Bounds> boxes, Dictionary<long, List<int>> buckets)
		{
			//IL_0000: 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_0031: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			long key = ((long)Key(p.x) << 32) ^ (uint)Key(p.z);
			if (!buckets.TryGetValue(key, out var value))
			{
				return false;
			}
			float num = Mathf.Min(1f, ((Bounds)(ref collider)).size.y * 0.5f);
			foreach (int item in value)
			{
				Bounds val = boxes[item];
				if (!(((Bounds)(ref val)).size.y < num) && !(p.x < ((Bounds)(ref val)).min.x - 0.4f) && !(p.x > ((Bounds)(ref val)).max.x + 0.4f) && !(p.z < ((Bounds)(ref val)).min.z - 0.4f) && !(p.z > ((Bounds)(ref val)).max.z + 0.4f) && !(((Bounds)(ref val)).max.y < ((Bounds)(ref collider)).min.y) && !(((Bounds)(ref val)).min.y > ((Bounds)(ref collider)).max.y + 0.5f))
				{
					return true;
				}
			}
			return false;
		}

		private static bool IsGameplay(Transform t, Transform root)
		{
			Transform val = t;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
			{
				if ((Object)(object)((Component)val).GetComponent<NetworkObject>() != (Object)null)
				{
					return true;
				}
				foreach (MonoBehaviour component in ((Component)val).GetComponents<MonoBehaviour>())
				{
					if ((Object)(object)component != (Object)null && !((Object)component).GetIl2CppType().FullName.StartsWith("UnityEngine.", StringComparison.Ordinal))
					{
						return true;
					}
				}
				val = val.parent;
			}
			return false;
		}
	}
	internal static class HostConfig
	{
		private static ConfigFile cfg;

		private static string messageName;

		private static string[] personal;

		private static Dictionary<string, string> whenHostLacksMod;

		private static Func<bool> active;

		private static HandleNamedMessageDelegate handler;

		private static IntPtr registeredOn;

		private static float nextSend;

		private static float joinedAt;

		private static string lastSent;

		private static string lastApplied;

		private static bool overriding;

		private static bool heardFromHost;

		private static bool warnedMissing;

		private static bool savedFlag;

		private static bool savingPersonal;

		private static readonly Dictionary<ConfigEntryBase, string> originals = new Dictionary<ConfigEntryBase, string>();

		internal static bool FromHost
		{
			get
			{
				if (overriding)
				{
					return heardFromHost;
				}
				return false;
			}
		}

		internal static void Init(BasePlugin plugin, string guid, string[] personalKeys, Dictionary<string, string> offWithoutHost, Func<bool> isActive = null)
		{
			cfg = plugin.Config;
			messageName = guid + ".HostConfig";
			personal = personalKeys ?? Array.Empty<string>();
			whenHostLacksMod = offWithoutHost ?? new Dictionary<string, string>();
			active = isActive;
			cfg.SettingChanged += OnSettingChanged;
			plugin.AddComponent<HostConfigRunner>();
		}

		private static void OnSettingChanged(object sender, SettingChangedEventArgs e)
		{
			try
			{
				if (overriding && !savingPersonal && IsPersonal(e.ChangedSetting.Definition))
				{
					SavePersonal();
				}
			}
			catch
			{
			}
		}

		private static string Id(ConfigDefinition d)
		{
			return d.Section + "." + d.Key;
		}

		private static bool IsPersonal(ConfigDefinition d)
		{
			string[] array = personal;
			foreach (string text in array)
			{
				if (text.EndsWith(".*") ? (d.Section == text.Substring(0, text.Length - 2)) : (Id(d) == text))
				{
					return true;
				}
			}
			return false;
		}

		internal static void Tick()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			try
			{
				NetworkManager singleton = NetworkManager.Singleton;
				bool flag = (Object)(object)singleton != (Object)null && singleton.IsListening;
				if (!flag || singleton.IsServer || (active != null && !active()))
				{
					if (overriding)
					{
						Restore();
					}
					if (flag && singleton.IsServer)
					{
						HostTick(singleton);
					}
					if (!flag)
					{
						registeredOn = IntPtr.Zero;
					}
				}
				else
				{
					ClientTick(singleton);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag2 = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(15, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Host settings: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogError(val);
			}
		}

		private static void HostTick(NetworkManager nm)
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < nextSend || nm.CustomMessagingManager == null)
			{
				return;
			}
			nextSend = Time.unscaledTime + 1.5f;
			List<string> list = new List<string>();
			foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in cfg)
			{
				if (!IsPersonal(item.Key))
				{
					list.Add(item.Key.Section + "\u001f" + item.Key.Key + "\u001f" + item.Value.GetSerializedValue());
				}
			}
			string text = string.Join("\u001e", list);
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(text.Length * 2 + 64, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
				nm.CustomMessagingManager.SendNamedMessageToAll(messageName, val, (NetworkDelivery)4);
			}
			finally
			{
				((FastBufferWriter)(ref val)).Dispose();
			}
			if (text != lastSent)
			{
				lastSent = text;
				Plugin.Log.LogInfo((object)"Sending this game's settings to all players.");
			}
		}

		private static void ClientTick(NetworkManager nm)
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			CustomMessagingManager customMessagingManager = nm.CustomMessagingManager;
			if (customMessagingManager != null && registeredOn != ((Il2CppObjectBase)customMessagingManager).Pointer)
			{
				if (handler == null)
				{
					handler = DelegateSupport.ConvertDelegate<HandleNamedMessageDelegate>((Delegate)new Action<ulong, FastBufferReader>(OnReceived));
				}
				customMessagingManager.RegisterNamedMessageHandler(messageName, handler);
				registeredOn = ((Il2CppObjectBase)customMessagingManager).Pointer;
			}
			if (!overriding)
			{
				Begin();
				joinedAt = Time.unscaledTime;
				foreach (KeyValuePair<string, string> item in whenHostLacksMod)
				{
					Set(item.Key, item.Value);
				}
			}
			if (!heardFromHost && !warnedMissing && Time.unscaledTime - joinedAt > 15f)
			{
				warnedMissing = true;
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(88, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("No settings from the host: the host doesn't seem to have ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("BiggerMap");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", so it stays off in this game.");
				}
				log.LogWarning(val);
			}
		}

		private static void OnReceived(ulong sender, FastBufferReader reader)
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				string text = default(string);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false);
				if (!overriding)
				{
					Begin();
				}
				heardFromHost = true;
				if (text == lastApplied)
				{
					return;
				}
				lastApplied = text;
				int num = 0;
				string[] array = text.Split('\u001e');
				for (int i = 0; i < array.Length; i++)
				{
					string[] array2 = array[i].Split('\u001f');
					if (array2.Length == 3)
					{
						ConfigDefinition d = new ConfigDefinition(array2[0], array2[1]);
						if (!IsPersonal(d) && Set(Id(d), array2[2]))
						{
							num++;
						}
					}
				}
				ManualLogSource log = Plugin.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Using the host's settings (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" values).");
				}
				log.LogInfo(val);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Host settings (receive): ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				log2.LogError(val2);
			}
		}

		private static void Begin()
		{
			overriding = true;
			heardFromHost = false;
			warnedMissing = false;
			lastApplied = null;
			savedFlag = cfg.SaveOnConfigSet;
			cfg.SaveOnConfigSet = false;
		}

		private static bool Set(string id, string value)
		{
			foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in cfg)
			{
				if (!(Id(item.Key) != id))
				{
					ConfigEntryBase value2 = item.Value;
					if (!originals.ContainsKey(value2))
					{
						originals[value2] = value2.GetSerializedValue();
					}
					if (value2.GetSerializedValue() != value)
					{
						value2.SetSerializedValue(value);
					}
					return true;
				}
			}
			return false;
		}

		private static void SavePersonal()
		{
			savingPersonal = true;
			Dictionary<ConfigEntryBase, string> dictionary = new Dictionary<ConfigEntryBase, string>();
			try
			{
				foreach (KeyValuePair<ConfigEntryBase, string> original in originals)
				{
					dictionary[original.Key] = original.Key.GetSerializedValue();
					original.Key.SetSerializedValue(original.Value);
				}
				cfg.Save();
			}
			finally
			{
				foreach (KeyValuePair<ConfigEntryBase, string> item in dictionary)
				{
					try
					{
						item.Key.SetSerializedValue(item.Value);
					}
					catch
					{
					}
				}
				savingPersonal = false;
			}
		}

		private static void Restore()
		{
			foreach (KeyValuePair<ConfigEntryBase, string> original in originals)
			{
				try
				{
					original.Key.SetSerializedValue(original.Value);
				}
				catch
				{
				}
			}
			originals.Clear();
			overriding = false;
			heardFromHost = false;
			lastApplied = null;
			cfg.SaveOnConfigSet = savedFlag;
			try
			{
				cfg.Save();
			}
			catch
			{
			}
			Plugin.Log.LogInfo((object)"Left the game; back to this computer's own settings.");
		}
	}
	public class HostConfigRunner : MonoBehaviour
	{
		public HostConfigRunner(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			HostConfig.Tick();
		}
	}
	[HarmonyPatch]
	internal static class MapScaler
	{
		private const float RingMinRadius = 30f;

		private const int DenseCount = 100;

		private static readonly Dictionary<string, (Mesh mesh, Material[] mats)> donors = new Dictionary<string, (Mesh, Material[])>();

		private static int standIns;

		private static int missingDonors;

		private static readonly string[] NotScenery = new string[12]
		{
			"Spawn", "Point", "Portal", "Breakable", "Objective", "Artifact", "Zone", "Hole", "Geyser", "Tornado",
			"Shooter", "Dead"
		};

		private static readonly Dictionary<IntPtr, Vector3> confinerOriginal = new Dictionary<IntPtr, Vector3>();

		[HarmonyPatch(typeof(WorldVariantManager), "ActivateCorrectVariant")]
		[HarmonyPostfix]
		private static void Activated(WorldVariantManager __instance)
		{
			if (Sync.WaitingForHost)
			{
				Runner.WaitForHost(__instance);
				Plugin.Log.LogInfo((object)"Waiting for the host's map size before changing the layout.");
			}
			else
			{
				Apply(__instance);
			}
		}

		internal static void Apply(WorldVariantManager __instance)
		{
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Expected O, but got Unknown
			try
			{
				float scale = Sync.Scale;
				GameObject activeVariant = __instance.GetActiveVariant();
				if ((Object)(object)activeVariant == (Object)null)
				{
					Plugin.Log.LogWarning((object)"No active map layout found.");
					return;
				}
				if (!Sync.Enabled || scale <= 1.01f)
				{
					TerrainStretch.Restore(activeVariant.transform);
					return;
				}
				Stopwatch stopwatch = Stopwatch.StartNew();
				standIns = (missingDonors = 0);
				CollectDonors(((Component)__instance).transform);
				Wall.Reset();
				int value = Spread(activeVariant.transform, scale);
				GridMap.Root = activeVariant.transform;
				if (Plugin.RemoveInvisibleBlockers.Value)
				{
					HashSet<int> hashSet = new HashSet<int>();
					for (int i = 0; i < 32; i++)
					{
						try
						{
							if (LayerMask.LayerToName(i) == "Obstacles")
							{
								hashSet.Add(i);
							}
						}
						catch
						{
						}
					}
					int num = Wall.BorderLayer();
					if (num >= 0)
					{
						hashSet.Add(num);
					}
					Blockers.Clean(((Component)__instance).transform, activeVariant.transform, hashSet);
				}
				if (Plugin.InvisibleEdge.Value)
				{
					Wall.Build(activeVariant.transform);
				}
				TerrainStretch.Apply(activeVariant.transform, scale);
				ScaleConfiners(activeVariant.transform, scale);
				ScaleSpawnAreas(activeVariant, scale);
				Sync.AppliedScale = scale;
				Plugin.Log.LogInfo((object)($"{((Object)activeVariant).name}: map scaled x{scale:0.##} ({value} objects moved, {standIns} batched meshes replaced" + ((missingDonors > 0) ? $", {missingDonors} hidden without a replacement" : "") + $") in {stopwatch.ElapsedMilliseconds} ms."));
				if (Plugin.RebuildNavMesh.Value)
				{
					Runner.RequestNavMesh(activeVariant.transform, scale);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(17, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Scaling the map: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}

		private static int Spread(Transform root, float k)
		{
			int num = 0;
			List<Transform> list = new List<Transform>();
			for (int i = 0; i < root.childCount; i++)
			{
				list.Add(root.GetChild(i));
			}
			foreach (Transform item in list)
			{
				if (!((Object)(object)((Component)item).GetComponent<Terrain>() != (Object)null))
				{
					if (((Object)item).name == "FloorCollider")
					{
						WidenFloor(item, k);
						continue;
					}
					if (IsContainer(item))
					{
						num += Walk(root, item, k);
						continue;
					}
					Place(root, item, k);
					num++;
				}
			}
			return num;
		}

		private static void WidenFloor(Transform floor, float k)
		{
			//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_0016: 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_0024: 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_0049: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((Component)floor).GetComponent<Renderer>() != (Object)null)
			{
				Vector3 localScale = floor.localScale;
				floor.localScale = new Vector3(localScale.x * k, localScale.y, localScale.z * k);
				return;
			}
			BoxCollider component = ((Component)floor).GetComponent<BoxCollider>();
			if ((Object)(object)component != (Object)null)
			{
				component.size = new Vector3(component.size.x * k, component.size.y, component.size.z * k);
			}
		}

		private static void ScaleSpawnAreas(GameObject variant, float k)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0029: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				WorldVariantSpawnableArea component = variant.GetComponent<WorldVariantSpawnableArea>();
				List<SpawnableArea> val = ((component != null) ? component.spawnableAreas : null);
				if (val == null)
				{
					return;
				}
				for (int i = 0; i < val.Count; i++)
				{
					SpawnableArea val2 = val[i];
					if (val2 != null)
					{
						val2.Center *= k;
						val2.Size *= k;
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Spawn areas: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val3);
			}
		}

		private static bool IsContainer(Transform t)
		{
			//IL_0057: 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_0064: 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)
			int childCount = t.childCount;
			if (childCount == 0)
			{
				return false;
			}
			if ((Object)(object)((Component)t).GetComponent<Renderer>() != (Object)null || (Object)(object)((Component)t).GetComponent<Collider>() != (Object)null || (Object)(object)((Component)t).GetComponent<NetworkObject>() != (Object)null || (Object)(object)((Component)t).GetComponent<LODGroup>() != (Object)null)
			{
				return false;
			}
			float num = 0f;
			for (int i = 0; i < childCount; i++)
			{
				Vector3 localPosition = t.GetChild(i).localPosition;
				float num2 = num;
				Vector2 val = new Vector2(localPosition.x, localPosition.z);
				num = Mathf.Max(num2, ((Vector2)(ref val)).magnitude);
			}
			return num > 8f;
		}

		private static int Walk(Transform root, Transform container, float k)
		{
			int num = 0;
			List<Transform> list = new List<Transform>();
			List<Transform> list2 = new List<Transform>();
			for (int i = 0; i < container.childCount; i++)
			{
				list2.Add(container.GetChild(i));
			}
			foreach (Transform item in list2)
			{
				if (((Component)item).gameObject.activeSelf)
				{
					if (IsContainer(item))
					{
						num += Walk(root, item, k);
						continue;
					}
					Place(root, item, k);
					list.Add(item);
					num++;
				}
			}
			if (list.Count == 0)
			{
				return num;
			}
			List<Transform> list3 = list.FindAll((Transform l) => Radius(root, l) / k >= 30f);
			bool flag = list3.Count >= 8 && (float)list3.Count >= (float)list.Count * 0.7f;
			if (flag)
			{
				Wall.Offer(root, container, list3);
			}
			if (!IsScenery(container, list))
			{
				return num;
			}
			if (Plugin.FillGaps.Value && flag)
			{
				num += FillRing(root, list3, k);
			}
			else if (Plugin.FillGrass.Value && list.Count >= 100 && !HasColliders(list))
			{
				num += Thicken(root, list, k);
			}
			return num;
		}

		private static bool IsScenery(Transform container, List<Transform> leaves)
		{
			string[] notScenery = NotScenery;
			foreach (string value in notScenery)
			{
				if (((Object)container).name.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return false;
				}
			}
			for (int j = 0; j < leaves.Count && j < 30; j++)
			{
				Transform val = leaves[j];
				if ((Object)(object)((Component)val).GetComponentInChildren<Renderer>(true) == (Object)null)
				{
					return false;
				}
				foreach (MonoBehaviour componentsInChild in ((Component)val).GetComponentsInChildren<MonoBehaviour>(true))
				{
					if ((Object)(object)componentsInChild != (Object)null && !((Object)componentsInChild).GetIl2CppType().FullName.StartsWith("UnityEngine.", StringComparison.Ordinal))
					{
						return false;
					}
				}
			}
			return true;
		}

		private static float Radius(Transform root, Transform t)
		{
			//IL_0002: 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_000c: 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_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)
			Vector3 val = root.InverseTransformPoint(t.position);
			Vector2 val2 = new Vector2(val.x, val.z);
			return ((Vector2)(ref val2)).magnitude;
		}

		private static void Place(Transform root, Transform t, float k)
		{
			//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_001f: 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)
			//IL_002c: 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)
			//IL_0079: 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_0087: 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_0094: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			if (!(((Object)t).name == "SkyboxRotator"))
			{
				Vector3 val = root.InverseTransformPoint(t.position);
				Vector2 val2 = new Vector2(val.x, val.z);
				if (((Vector2)(ref val2)).magnitude < 3f && Extent(t) > 25f)
				{
					Vector3 localScale = t.localScale;
					t.localScale = new Vector3(localScale.x * k, localScale.y, localScale.z * k);
				}
				else
				{
					t.position = root.TransformPoint(new Vector3(val.x * k, val.y, val.z * k));
				}
				ReplaceBatched(t);
			}
		}

		private static float Extent(Transform t)
		{
			//IL_001b: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			foreach (Renderer componentsInChild in ((Component)t).GetComponentsInChildren<Renderer>(true))
			{
				Bounds bounds = componentsInChild.bounds;
				Vector3 extents = ((Bounds)(ref bounds)).extents;
				num = Mathf.Max(num, Mathf.Max(extents.x, extents.z));
			}
			return num;
		}

		private static bool HasColliders(List<Transform> leaves)
		{
			for (int i = 0; i < leaves.Count && i < 30; i++)
			{
				if ((Object)(object)((Component)leaves[i]).GetComponentInChildren<Collider>(true) != (Object)null)
				{
					return true;
				}
			}
			return false;
		}

		private static int FillRing(Transform root, List<Transform> leaves, float k)
		{
			int num = Mathf.CeilToInt(k) - 1;
			if (num <= 0)
			{
				num = 1;
			}
			float num2 = 360f / (float)leaves.Count;
			int num3 = 0;
			for (int i = 1; i <= num; i++)
			{
				float angleDeg = num2 * (float)i / (float)(num + 1);
				foreach (Transform leaf in leaves)
				{
					Copy(root, leaf, angleDeg);
					num3++;
				}
			}
			return num3;
		}

		private static int Thicken(Transform root, List<Transform> leaves, float k)
		{
			int num = Mathf.Clamp(Mathf.RoundToInt(k * k) - 1, 0, Plugin.MaxGrassCopies.Value);
			int num2 = 0;
			for (int i = 1; i <= num; i++)
			{
				float angleDeg = 137.5f * (float)i;
				foreach (Transform leaf in leaves)
				{
					Copy(root, leaf, angleDeg);
					num2++;
				}
			}
			return num2;
		}

		private static void Copy(Transform root, Transform src, float angleDeg)
		{
			//IL_004b: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0064: 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_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_007e: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)((Component)src).GetComponent<NetworkObject>() != (Object)null) && !((Object)(object)((Component)src).GetComponentInChildren<NetworkObject>(true) != (Object)null))
			{
				GameObject obj = Object.Instantiate<GameObject>(((Component)src).gameObject, src.parent);
				((Object)obj).name = ((Object)src).name + " (BiggerMap)";
				Transform transform = obj.transform;
				Vector3 up = root.up;
				Vector3 position = root.position;
				Quaternion val = Quaternion.AngleAxis(angleDeg, up);
				transform.position = position + val * (src.position - position);
				transform.rotation = val * src.rotation;
			}
		}

		private static string Stem(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				return "";
			}
			name = name.Replace("(Clone)", "").Trim();
			int num = name.LastIndexOf(" (", StringComparison.Ordinal);
			if (num > 0 && name.EndsWith(")"))
			{
				name = name.Substring(0, num);
			}
			return name.Trim();
		}

		private static string Key(Transform t)
		{
			return Stem(((Object)t).name) + "|" + (((Object)(object)t.parent != (Object)null) ? Stem(((Object)t.parent).name) : "");
		}

		private static bool IsBatched(MeshFilter mf)
		{
			try
			{
				Mesh sharedMesh = mf.sharedMesh;
				return (Object)(object)sharedMesh != (Object)null && ((Object)sharedMesh).name.Contains("Combined Mesh");
			}
			catch
			{
				return false;
			}
		}

		private static bool IsLod0(Renderer r)
		{
			string name = ((Object)r).name;
			int num = name.LastIndexOf("LOD", StringComparison.OrdinalIgnoreCase);
			if (num < 0 || num + 3 >= name.Length || !char.IsDigit(name[num + 3]))
			{
				return true;
			}
			return name[num + 3] == '0';
		}

		private static void CollectDonors(Transform managerRoot)
		{
			donors.Clear();
			foreach (MeshFilter componentsInChild in ((Component)managerRoot).GetComponentsInChildren<MeshFilter>(true))
			{
				if ((Object)(object)componentsInChild == (Object)null || IsBatched(componentsInChild) || (Object)(object)componentsInChild.sharedMesh == (Object)null)
				{
					continue;
				}
				MeshRenderer component = ((Component)componentsInChild).GetComponent<MeshRenderer>();
				if (!((Object)(object)component == (Object)null))
				{
					string key = Key(((Component)componentsInChild).transform);
					if (!donors.ContainsKey(key))
					{
						donors[key] = (componentsInChild.sharedMesh, Il2CppArrayBase<Material>.op_Implicit((Il2CppArrayBase<Material>)(object)((Renderer)component).sharedMaterials));
					}
				}
			}
		}

		private static void ReplaceBatched(Transform t)
		{
			//IL_009a: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00e3: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			foreach (MeshFilter componentsInChild in ((Component)t).GetComponentsInChildren<MeshFilter>(true))
			{
				if ((Object)(object)componentsInChild == (Object)null || !IsBatched(componentsInChild))
				{
					continue;
				}
				MeshRenderer component = ((Component)componentsInChild).GetComponent<MeshRenderer>();
				if ((Object)(object)component == (Object)null || !((Renderer)component).enabled)
				{
					continue;
				}
				((Renderer)component).enabled = false;
				if (!IsLod0((Renderer)(object)component))
				{
					continue;
				}
				if (!donors.TryGetValue(Key(((Component)componentsInChild).transform), out (Mesh, Material[]) value))
				{
					missingDonors++;
					continue;
				}
				GameObject val = new GameObject(((Object)componentsInChild).name + " (BiggerMap mesh)")
				{
					layer = ((Component)componentsInChild).gameObject.layer
				};
				Transform transform = val.transform;
				transform.SetParent(((Component)componentsInChild).transform, false);
				transform.localPosition = Vector3.zero;
				transform.localRotation = Quaternion.identity;
				transform.localScale = Vector3.one;
				val.AddComponent<MeshFilter>().sharedMesh = value.Item1;
				MeshRenderer val2 = val.AddComponent<MeshRenderer>();
				((Renderer)val2).sharedMaterials = Il2CppReferenceArray<Material>.op_Implicit(value.Item2);
				((Renderer)val2).shadowCastingMode = ((Renderer)component).shadowCastingMode;
				try
				{
					((Renderer)val2).lightmapIndex = ((Renderer)component).lightmapIndex;
					((Renderer)val2).lightmapScaleOffset = ((Renderer)component).lightmapScaleOffset;
				}
				catch
				{
				}
				((Renderer)val2).receiveShadows = ((Renderer)component).receiveShadows;
				standIns++;
			}
		}

		private static void ScaleConfiners(Transform root, float k)
		{
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_0046: 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_004b: 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_0080: 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_0060: 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_006e: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				Vector3 val3 = default(Vector3);
				foreach (CinemachineConfiner item in Object.FindObjectsOfType<CinemachineConfiner>())
				{
					Collider boundingVolume = item.m_BoundingVolume;
					if (!((Object)(object)boundingVolume == (Object)null))
					{
						BoxCollider val = ((Il2CppObjectBase)boundingVolume).TryCast<BoxCollider>();
						Vector3 val2 = (((Object)(object)val != (Object)null) ? val.size : ((Component)boundingVolume).transform.localScale);
						if (!confinerOriginal.TryGetValue(((Il2CppObjectBase)boundingVolume).Pointer, out var value))
						{
							value = val2;
							confinerOriginal[((Il2CppObjectBase)boundingVolume).Pointer] = value;
						}
						((Vector3)(ref val3))..ctor(value.x * k, value.y, value.z * k);
						if ((Object)(object)val != (Object)null)
						{
							val.size = val3;
						}
						else
						{
							((Component)boundingVolume).transform.localScale = val3;
						}
						ManualLogSource log = Plugin.Log;
						BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(23, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Widened camera bounds ");
							((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(((Object)boundingVolume).name);
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(".");
						}
						log.LogInfo(val4);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(15, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Camera bounds: ");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
				}
				log2.LogWarning(val5);
			}
		}

		internal static void BuildNavMesh(Transform variant, float k)
		{
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Expected O, but got Unknown
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Invalid comparison between Unknown and I4
			//IL_00f1: 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_010b: 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_0115: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Expected O, but got Unknown
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: 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_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			bool flag = default(bool);
			try
			{
				Physics.SyncTransforms();
				List<NavMeshSurface> list = new List<NavMeshSurface>();
				foreach (NavMeshSurface item in Object.FindObjectsOfType<NavMeshSurface>())
				{
					if ((Object)(object)item != (Object)null)
					{
						list.Add(item);
					}
				}
				foreach (NavMeshSurface s in ((Component)variant).GetComponentsInChildren<NavMeshSurface>(true))
				{
					if ((Object)(object)s != (Object)null && !list.Exists((NavMeshSurface x) => ((Il2CppObjectBase)x).Pointer == ((Il2CppObjectBase)s).Pointer))
					{
						list.Add(s);
					}
				}
				if (list.Count == 0)
				{
					Plugin.Log.LogWarning((object)"No navigation surfaces found: enemies may not reach the new outer area.");
					return;
				}
				foreach (NavMeshSurface item2 in list)
				{
					Stopwatch stopwatch = Stopwatch.StartNew();
					if (Wall.Built)
					{
						Transform transform = ((Component)item2).transform;
						Vector3 lossyScale = transform.lossyScale;
						float num = 2f * Wall.Radius + 12f;
						Vector3 val = transform.InverseTransformPoint(Wall.Centre);
						item2.collectObjects = (CollectObjects)1;
						item2.center = new Vector3(val.x, 0f, val.z);
						item2.size = new Vector3(num / Mathf.Max(0.01f, Mathf.Abs(lossyScale.x)), 80f / Mathf.Max(0.01f, Mathf.Abs(lossyScale.y)), num / Mathf.Max(0.01f, Mathf.Abs(lossyScale.z)));
					}
					else if ((int)item2.collectObjects == 1)
					{
						Vector3 size = item2.size;
						Vector3 center = item2.center;
						item2.size = new Vector3(size.x * k + 10f, size.y, size.z * k + 10f);
						item2.center = new Vector3(center.x * k, center.y, center.z * k);
					}
					item2.useGeometry = (NavMeshCollectGeometry)1;
					item2.BuildNavMesh();
					ManualLogSource log = Plugin.Log;
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(34, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Rebuilt navigation for ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)item2).name);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<CollectObjects>(item2.collectObjects);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(") in ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<long>(stopwatch.ElapsedMilliseconds);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ms.");
					}
					log.LogInfo(val2);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(23, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Rebuilding navigation: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val3);
			}
		}
	}
	public class Runner : MonoBehaviour
	{
		private static WorldVariantManager waiting;

		private static Transform pendingVariant;

		private static float pendingScale;

		private static int frames;

		public Runner(IntPtr ptr)
			: base(ptr)
		{
		}

		internal static void WaitForHost(WorldVariantManager m)
		{
			waiting = m;
		}

		internal static void RequestNavMesh(Transform variant, float k)
		{
			pendingVariant = variant;
			pendingScale = k;
			frames = 1;
		}

		private void Update()
		{
			Sync.Tick();
			if (waiting != null)
			{
				if (((Il2CppObjectBase)waiting).WasCollected || (Object)(object)waiting == (Object)null)
				{
					waiting = null;
				}
				else if (!Sync.WaitingForHost)
				{
					WorldVariantManager _instance = waiting;
					waiting = null;
					MapScaler.Apply(_instance);
				}
			}
			if (pendingVariant != null && frames-- <= 0)
			{
				Transform val = pendingVariant;
				pendingVariant = null;
				if (!((Il2CppObjectBase)val).WasCollected && !((Object)(object)val == (Object)null))
				{
					MapScaler.BuildNavMesh(val, pendingScale);
				}
			}
		}
	}
	[BepInPlugin("girthy_mods.BiggerMap", "BiggerMap", "0.9.8")]
	public class Plugin : BasePlugin
	{
		public const string Guid = "girthy_mods.BiggerMap";

		public const string Name = "BiggerMap";

		public const string Version = "0.9.8";

		internal const float MaxScale = 1.8f;

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<float> Scale;

		internal static ConfigEntry<bool> FillGaps;

		internal static ConfigEntry<bool> FillGrass;

		internal static ConfigEntry<int> MaxGrassCopies;

		internal static ConfigEntry<bool> RebuildNavMesh;

		internal static ConfigEntry<bool> InvisibleEdge;

		internal static ConfigEntry<bool> RemoveInvisibleBlockers;

		public override void Load()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			HostConfig.Init((BasePlugin)(object)this, "girthy_mods.BiggerMap", Array.Empty<string>(), null);
			Enabled = ((BasePlugin)this).Config.Bind<bool>("Map", "Enabled", true, "Make the arena bigger.");
			Scale = ((BasePlugin)this).Config.Bind<float>("Map", "Scale", 1.5f, new ConfigDescription("How much wider the arena is (1.5 = 1.5x as wide, about 2.25x the area).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 1.8f), Array.Empty<object>()));
			FillGaps = ((BasePlugin)this).Config.Bind<bool>("Map", "FillBorderGaps", true, "Add copies of the border ring's pieces so the bigger ring has no gaps.");
			FillGrass = ((BasePlugin)this).Config.Bind<bool>("Map", "FillGrass", true, "Add copies of grass and flowers so the bigger ground isn't bare.");
			MaxGrassCopies = ((BasePlugin)this).Config.Bind<int>("Map", "MaxGrassCopies", 2, new ConfigDescription("Most extra copies of each grass field (more copies = more objects to draw).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 3), Array.Empty<object>()));
			RebuildNavMesh = ((BasePlugin)this).Config.Bind<bool>("Map", "RebuildNavigation", true, "Rebuild the enemies' navigation for the new layout (needed for enemies to reach the outer area).");
			RemoveInvisibleBlockers = ((BasePlugin)this).Config.Bind<bool>("Map", "RemoveInvisibleBlockers", true, "Switch off solid pieces left with nothing visible on them after spreading (they'd be invisible walls).");
			InvisibleEdge = ((BasePlugin)this).Config.Bind<bool>("Map", "InvisibleEdge", true, "Add an invisible wall just inside the moved border so players and enemies can't slip out through gaps.");
			Harmony val = new Harmony("girthy_mods.BiggerMap");
			val.PatchAll(typeof(MapScaler));
			val.PatchAll(typeof(GridMap));
			((BasePlugin)this).AddComponent<Runner>();
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(8, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("BiggerMap");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("0.9.8");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ready.");
			}
			log.LogInfo(val2);
		}
	}
	internal static class Sync
	{
		private const string MessageName = "girthy_mods.BiggerMap.Settings";

		private static HandleNamedMessageDelegate handler;

		private static IntPtr registeredOn;

		private static float nextSend;

		private static bool? hostEnabled;

		private static float? hostScale;

		internal static float AppliedScale;

		internal static bool Enabled => hostEnabled ?? Plugin.Enabled.Value;

		internal static bool WaitingForHost
		{
			get
			{
				try
				{
					NetworkManager singleton = NetworkManager.Singleton;
					return (Object)(object)singleton != (Object)null && singleton.IsListening && !singleton.IsServer && !hostScale.HasValue;
				}
				catch
				{
					return false;
				}
			}
		}

		internal static float Scale => Mathf.Clamp(hostScale ?? Plugin.Scale.Value, 1f, 1.8f);

		internal static void Tick()
		{
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			bool value = default(bool);
			try
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null)
				{
					if ((Object)(object)singleton == (Object)null || !singleton.IsListening)
					{
						hostEnabled = null;
						hostScale = null;
						registeredOn = IntPtr.Zero;
					}
					return;
				}
				CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
				if (!singleton.IsServer)
				{
					if (registeredOn != ((Il2CppObjectBase)customMessagingManager).Pointer)
					{
						if (handler == null)
						{
							handler = DelegateSupport.ConvertDelegate<HandleNamedMessageDelegate>((Delegate)new Action<ulong, FastBufferReader>(OnReceived));
						}
						customMessagingManager.RegisterNamedMessageHandler("girthy_mods.BiggerMap.Settings", handler);
						registeredOn = ((Il2CppObjectBase)customMessagingManager).Pointer;
					}
				}
				else if (!(Time.unscaledTime < nextSend))
				{
					nextSend = Time.unscaledTime + 1f;
					string[] array = new string[2];
					value = Plugin.Enabled.Value;
					array[0] = "Enabled=" + value;
					array[1] = "Scale=" + Plugin.Scale.Value.ToString(CultureInfo.InvariantCulture);
					string text = string.Join(";", array);
					FastBufferWriter val = default(FastBufferWriter);
					((FastBufferWriter)(ref val))..ctor(Encoding.UTF8.GetByteCount(text) * 2 + 64, (Allocator)2, -1);
					try
					{
						((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
						customMessagingManager.SendNamedMessageToAll("girthy_mods.BiggerMap.Settings", val, (NetworkDelivery)2);
						return;
					}
					finally
					{
						((FastBufferWriter)(ref val)).Dispose();
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(15, 1, ref value);
				if (value)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Settings sync: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				log.LogError(val2);
				nextSend = Time.unscaledTime + 30f;
			}
		}

		private static void OnReceived(ulong sender, FastBufferReader reader)
		{
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			bool flag2 = default(bool);
			try
			{
				string text = default(string);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false);
				bool? flag = null;
				float? num = null;
				string[] array = text.Split(';');
				foreach (string text2 in array)
				{
					int num2 = text2.IndexOf('=');
					if (num2 > 0)
					{
						string text3 = text2.Substring(0, num2);
						string text4 = text2.Substring(num2 + 1);
						if (text3 == "Enabled" && bool.TryParse(text4, out var result))
						{
							flag = result;
						}
						if (text3 == "Scale" && float.TryParse(text4, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
						{
							num = result2;
						}
					}
				}
				bool num3 = flag != hostEnabled || num != hostScale;
				hostEnabled = flag;
				hostScale = num;
				if (num3)
				{
					ManualLogSource log = Plugin.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Using the host's map size: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>((flag == false) ? "off" : $"x{num:0.##}");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
					}
					log.LogInfo(val);
				}
				if (num3 && AppliedScale > 0f && num != AppliedScale)
				{
					Plugin.Log.LogWarning((object)"The host's map size changed after this realm was laid out; it applies from the next realm.");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Settings sync (receive): ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				log2.LogError(val2);
			}
		}
	}
	internal static class TerrainStretch
	{
		private static readonly Dictionary<string, Vector3> originalSize = new Dictionary<string, Vector3>();

		private static string Key(TerrainData td)
		{
			return ((Object)td).name + "#" + td.heightmapResolution;
		}

		internal static void Apply(Transform variantRoot, float k)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			bool flag = default(bool);
			foreach (Terrain componentsInChild in ((Component)variantRoot).GetComponentsInChildren<Terrain>(true))
			{
				if ((Object)(object)componentsInChild == (Object)null)
				{
					continue;
				}
				try
				{
					Stretch(componentsInChild, variantRoot.position, k);
				}
				catch (Exception ex)
				{
					ManualLogSource log = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(32, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Couldn't stretch the ground (");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)componentsInChild).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val);
				}
			}
		}

		private static void Stretch(Terrain terrain, Vector3 centre, float k)
		{
			//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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0036: 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)
			//IL_0084: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_0072: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			TerrainData terrainData = terrain.terrainData;
			if (!((Object)(object)terrainData == (Object)null))
			{
				string key = Key(terrainData);
				Vector3 size = terrainData.size;
				if (!originalSize.TryGetValue(key, out var value))
				{
					value = size;
					originalSize[key] = value;
				}
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(value.x * k, value.y, value.z * k);
				Vector3 val2 = size - val;
				if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f)
				{
					terrainData.size = val;
				}
				Vector3 position = ((Component)terrain).transform.position;
				((Component)terrain).transform.position = new Vector3(centre.x + (position.x - centre.x) * k, position.y, centre.z + (position.z - centre.z) * k);
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(33, 6, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Stretched the ground ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((Object)terrain).name);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" x");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(k, "0.##");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" (");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(value.x, "0");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("x");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(value.z, "0");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" -> ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(val.x, "0");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("x");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(val.z, "0");
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(").");
				}
				log.LogInfo(val3);
			}
		}

		internal static void Restore(Transform variantRoot)
		{
			//IL_0043: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			foreach (Terrain componentsInChild in ((Component)variantRoot).GetComponentsInChildren<Terrain>(true))
			{
				try
				{
					TerrainData val = ((componentsInChild != null) ? componentsInChild.terrainData : null);
					if (!((Object)(object)val == (Object)null) && originalSize.TryGetValue(Key(val), out var value))
					{
						Vector3 val2 = val.size - value;
						if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f)
						{
							val.size = value;
						}
					}
				}
				catch
				{
				}
			}
		}
	}
	internal static class Wall
	{
		private sealed class Candidate
		{
			public string Name;

			public List<Transform> Leaves;

			public float Spread;
		}

		private static readonly List<Candidate> candidates = new List<Candidate>();

		internal static bool Built;

		internal static Vector3 Centre;

		internal static float Radius;

		private const int Slices = 120;

		internal static void Reset()
		{
			candidates.Clear();
			Built = false;
			Radius = 0f;
		}

		internal static void Offer(Transform root, Transform container, List<Transform> outerLeaves)
		{
			//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_0077: 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_0085: 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)
			try
			{
				int num = 0;
				foreach (Transform outerLeaf in outerLeaves)
				{
					if ((Object)(object)((Component)outerLeaf).GetComponentInChildren<Collider>(true) != (Object)null)
					{
						num++;
					}
				}
				if (num < outerLeaves.Count / 2)
				{
					return;
				}
				List<float> list = new List<float>();
				foreach (Transform outerLeaf2 in outerLeaves)
				{
					Vector3 val = root.InverseTransformPoint(outerLeaf2.position);
					Vector2 val2 = new Vector2(val.x, val.z);
					list.Add(((Vector2)(ref val2)).magnitude);
				}
				list.Sort();
				float num2 = list[list.Count / 2];
				float spread = ((num2 > 0f) ? ((list[list.Count - 1] - list[list.Count / 7]) / num2) : 9f);
				candidates.Add(new Candidate
				{
					Name = ((Object)container).name,
					Leaves = new List<Transform>(outerLeaves),
					Spread = spread
				});
			}
			catch
			{
			}
		}

		private static Candidate PickBorder()
		{
			Candidate candidate = null;
			foreach (Candidate candidate2 in candidates)
			{
				if (candidate2.Name.IndexOf("Border", StringComparison.OrdinalIgnoreCase) >= 0 && (candidate == null || candidate2.Leaves.Count > candidate.Leaves.Count))
				{
					candidate = candidate2;
				}
			}
			if (candidate != null)
			{
				return candidate;
			}
			foreach (Candidate candidate3 in candidates)
			{
				if (candidate == null || candidate3.Spread < candidate.Spread)
				{
					candidate = candidate3;
				}
			}
			return candidate;
		}

		internal static int BorderLayer()
		{
			Candidate candidate = PickBorder();
			if (candidate == null)
			{
				return -1;
			}
			foreach (Transform leaf in candidate.Leaves)
			{
				Collider componentInChildren = ((Component)leaf).GetComponentInChildren<Collider>(true);
				if ((Object)(object)componentInChildren != (Object)null && !componentInChildren.isTrigger)
				{
					return ((Component)componentInChildren).gameObject.layer;
				}
			}
			return -1;
		}

		internal static void Build(Transform root)
		{
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: 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_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: 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_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Expected O, but got Unknown
			//IL_00d3: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ef: Expected O, but got Unknown
			//IL_060d: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06de: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0704: Unknown result type (might be due to invalid IL or missing references)
			//IL_071f: Unknown result type (might be due to invalid IL or missing references)
			//IL_073e: Unknown result type (might be due to invalid IL or missing references)
			//IL_073f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0756: Unknown result type (might be due to invalid IL or missing references)
			//IL_075d: Expected O, but got Unknown
			//IL_07bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_07dd: Unknown result type (might be due to invalid IL or missing references)
			Built = false;
			Candidate candidate = PickBorder();
			if (candidate == null)
			{
				Plugin.Log.LogWarning((object)"No border ring found; no invisible wall added.");
				return;
			}
			List<Collider> list = new List<Collider>();
			foreach (Transform leaf in candidate.Leaves)
			{
				foreach (Collider componentsInChild in ((Component)leaf).GetComponentsInChildren<Collider>(true))
				{
					if ((Object)(object)componentsInChild != (Object)null && componentsInChild.enabled && !componentsInChild.isTrigger)
					{
						list.Add(componentsInChild);
					}
				}
			}
			if (list.Count == 0)
			{
				return;
			}
			Physics.SyncTransforms();
			Vector3 val = Vector3.zero;
			foreach (Transform leaf2 in candidate.Leaves)
			{
				val += leaf2.position;
			}
			val /= (float)candidate.Leaves.Count;
			val.y = root.position.y;
			float[] array = new float[120];
			List<Collider>[] array2 = new List<Collider>[120];
			for (int i = 0; i < 120; i++)
			{
				array[i] = float.MaxValue;
				array2[i] = new List<Collider>();
			}
			foreach (Collider item in list)
			{
				Bounds bounds;
				try
				{
					bounds = item.bounds;
				}
				catch
				{
					continue;
				}
				float num = Mathf.Sqrt(((Bounds)(ref bounds)).SqrDistance(new Vector3(val.x, ((Bounds)(ref bounds)).center.y, val.z)));
				if (!(num < 5f))
				{
					float num2 = float.MaxValue;
					float num3 = float.MinValue;
					float num4 = Angle(((Bounds)(ref bounds)).center - val);
					Vector3[] array3 = (Vector3[])(object)new Vector3[4]
					{
						new Vector3(((Bounds)(ref bounds)).min.x, 0f, ((Bounds)(ref bounds)).min.z),
						new Vector3(((Bounds)(ref bounds)).min.x, 0f, ((Bounds)(ref bounds)).max.z),
						new Vector3(((Bounds)(ref bounds)).max.x, 0f, ((Bounds)(ref bounds)).min.z),
						new Vector3(((Bounds)(ref bounds)).max.x, 0f, ((Bounds)(ref bounds)).max.z)
					};
					for (int j = 0; j < array3.Length; j++)
					{
						float num5 = Angle(array3[j] - new Vector3(val.x, 0f, val.z));
						float num6 = Mathf.DeltaAngle(num4, num5);
						num2 = Mathf.Min(num2, num6);
						num3 = Mathf.Max(num3, num6);
					}
					int num7 = Mathf.FloorToInt((num4 + num2) / 360f * 120f);
					int num8 = Mathf.CeilToInt((num4 + num3) / 360f * 120f);
					for (int k = num7; k <= num8; k++)
					{
						int num9 = (k % 120 + 120) % 120;
						array[num9] = Mathf.Min(array[num9], num);
						array2[num9].Add(item);
					}
				}
			}
			int num10 = 0;
			float[] array4 = new float[3] { 1f, 2.5f, 4f };
			Vector3 val2 = default(Vector3);
			Ray val3 = default(Ray);
			RaycastHit val4 = default(RaycastHit);
			for (int l = 0; l < 120; l++)
			{
				if (array2[l].Count == 0)
				{
					continue;
				}
				float num11 = float.MaxValue;
				for (int m = 0; m < 3; m++)
				{
					float num12 = ((float)l + 0.2f + 0.3f * (float)m) * (float)Math.PI * 2f / 120f;
					((Vector3)(ref val2))..ctor(Mathf.Cos(num12), 0f, Mathf.Sin(num12));
					float[] array5 = array4;
					foreach (float num13 in array5)
					{
						((Ray)(ref val3))..ctor(val + Vector3.up * num13, val2);
						foreach (Collider item2 in array2[l])
						{
							try
							{
								if (item2.Raycast(val3, ref val4, 400f) && ((RaycastHit)(ref val4)).distance > 5f)
								{
									num11 = Mathf.Min(num11, ((RaycastHit)(ref val4)).distance);
								}
							}
							catch
							{
							}
						}
					}
				}
				if (num11 < float.MaxValue)
				{
					array[l] = num11;
					num10++;
				}
			}
			int num14 = 0;
			for (int n = 0; n < 120; n++)
			{
				if (array[n] < float.MaxValue)
				{
					num14++;
				}
			}
			bool flag = default(bool);
			if (num14 < 30)
			{
				ManualLogSource log = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(75, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Border colliders cover too little of the ring (");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(num14);
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("/");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(120);
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("); no invisible wall added.");
				}
				log.LogWarning(val5);
				return;
			}
			float[] array6 = (float[])array.Clone();
			for (int num15 = 0; num15 < 120; num15++)
			{
				if (array[num15] < float.MaxValue)
				{
					continue;
				}
				float num16 = float.MaxValue;
				float num17 = float.MaxValue;
				for (int num18 = 1; num18 < 120; num18++)
				{
					if (num16 != float.MaxValue)
					{
						break;
					}
					num16 = array[((num15 - num18) % 120 + 120) % 120];
				}
				for (int num19 = 1; num19 < 120; num19++)
				{
					if (num17 != float.MaxValue)
					{
						break;
					}
					num17 = array[(num15 + num19) % 120];
				}
				array6[num15] = Mathf.Min(num16, num17);
			}
			int layer = ((Component)list[0]).gameObject.layer;
			GameObject val6 = new GameObject("BiggerMap_Wall");
			val6.layer = layer;
			val6.transform.SetParent(root, false);
			val6.transform.position = val;
			float num20 = float.MaxValue;
			float num21 = 0f;
			Vector3 val7 = default(Vector3);
			for (int num22 = 0; num22 < 120; num22++)
			{
				float num23 = array6[num22] + 0.5f;
				num20 = Mathf.Min(num20, num23);
				num21 = Mathf.Max(num21, num23);
				float num24 = ((float)num22 + 0.5f) * (float)Math.PI * 2f / 120f;
				((Vector3)(ref val7))..ctor(Mathf.Cos(num24), 0f, Mathf.Sin(num24));
				float num25 = 2f * num23 * Mathf.Sin((float)Math.PI / 120f) * 1.3f;
				GameObject val8 = new GameObject("Wall")
				{
					layer = layer
				};
				val8.transform.SetParent(val6.transform, false);
				val8.transform.position = val + val7 * (num23 + 1.5f) + Vector3.up * 15f;
				val8.transform.rotation = Quaternion.LookRotation(val7, Vector3.up);
				val8.AddComponent<BoxCollider>().size = new Vector3(num25, 40f, 3f);
			}
			Built = true;
			Centre = val;
			Radius = num21;
			ManualLogSource log2 = Plugin.Log;
			BepInExInfoLogInterpolatedStringHandler val9 = new BepInExInfoLogInterpolatedStringHandler(102, 9, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val9).AppendLiteral("Invisible edge along '");
				((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<string>(candidate.Name);
				((BepInExLogInterpolatedStringHandler)val9).AppendLiteral("': ");
				((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<float>(num20, "0.#");
				((BepInExLogInterpolatedStringHandler)val9).AppendLiteral("-");
				((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<float>(num21, "0.#");
				((BepInExLogInterpolatedStringHandler)val9).AppendLiteral(" m from (");
				((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<float>(val.x, "0.#");
				((BepInExLogInterpolatedStringHandler)val9).AppendLiteral(", ");
				((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<float>(val.z, "0.#");
				((BepInExLogInterpolatedStringHandler)val9).AppendLiteral("), ");
				((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<int>(num14);
				((BepInExLogInterpolatedStringHandler)val9).AppendLiteral("/");
				((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<int>(120);
				((BepInExLogInterpolatedStringHandler)val9).AppendLiteral(" slices on border rocks (");
				((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<int>(num10);
				((BepInExLogInterpolatedStringHandler)val9).AppendLiteral(" measured at the rock face), layer ");
				((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<string>(LayerMask.LayerToName(layer));
				((BepInExLogInterpolatedStringHandler)val9).AppendLiteral(".");
			}
			log2.LogInfo(val9);
		}

		private static float Angle(Vector3 v)
		{
			//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)
			return Mathf.Repeat(Mathf.Atan2(v.z, v.x) * 57.29578f, 360f);
		}
	}
	[HarmonyPatch]
	internal static class GridMap
	{
		internal static Transform Root;

		private static bool Active(out float k)
		{
			k = Sync.AppliedScale;
			if (k <= 1.01f)
			{
				return false;
			}
			try
			{
				return Root != null && !((Il2CppObjectBase)Root).WasCollected && (Object)(object)Root != (Object)null;
			}
			catch
			{
				return false;
			}
		}

		private static Vector3 ToGrid(Vector3 p, float k)
		{
			//IL_0005: 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_000b: 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_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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0038: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Root.InverseTransformPoint(p);
			Vector3 val2 = Root.TransformPoint(new Vector3(val.x / k, val.y, val.z / k));
			return new Vector3(val2.x, p.y, val2.z);
		}

		private static Vector3 FromGrid(Vector3 p, float k)
		{
			//IL_0005: 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_000b: 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_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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0038: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Root.InverseTransformPoint(p);
			Vector3 val2 = Root.TransformPoint(new Vector3(val.x * k, val.y, val.z * k));
			return new Vector3(val2.x, p.y, val2.z);
		}

		[HarmonyPatch(typeof(MapPositionProvider), "GetRandomPosition", new Type[]
		{
			typeof(Vector3),
			typeof(float),
			typeof(float)
		})]
		[HarmonyPrefix]
		private static void Around_Prefix(MapPositionProvider __instance, ref Vector3 aroundWorldPosition, ref float minDistance, ref float maxDistance)
		{
			//IL_000c: 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_002a: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0064: 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_0075: 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_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_00ab: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			if (!Active(out var k))
			{
				return;
			}
			aroundWorldPosition = ToGrid(aroundWorldPosition, k);
			minDistance /= k;
			maxDistance /= k;
			try
			{
				if (Count(__instance, aroundWorldPosition, minDistance, maxDistance) > 0)
				{
					return;
				}
				Vector3 val = (Wall.Built ? ToGrid(Wall.Centre, k) : Root.position);
				for (int i = 1; i <= 4; i++)
				{
					Vector3 val2 = Vector3.Lerp(aroundWorldPosition, new Vector3(val.x, aroundWorldPosition.y, val.z), 0.15f * (float)i);
					float num = maxDistance * (1f + 0.5f * (float)i) + 2f * (float)i;
					if (Count(__instance, val2, minDistance, num) != 0)
					{
						aroundWorldPosition = val2;
						maxDistance = num;
						break;
					}
				}
			}
			catch
			{
			}
		}

		private static int Count(MapPositionProvider m, Vector3 around, float min, float max)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return m.FindAvailablePositions(around, min, max)?.Count ?? 0;
		}

		[HarmonyPatch(typeof(MapPositionProvider), "GetRandomPosition", new Type[]
		{
			typeof(Vector3),
			typeof(float),
			typeof(float)
		})]
		[HarmonyPostfix]
		private static void Around_Postfix(ref Vector3 __result)
		{
			//IL_000b: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			if (Active(out var k))
			{
				__result = FromGrid(__result, k);
			}
		}

		[HarmonyPatch(typeof(MapPositionProvider), "GetRandomPosition", new Type[] { })]
		[HarmonyPostfix]
		private static void Anywhere_Postfix(ref Vector3 __result)
		{
			//IL_000b: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			if (Active(out var k))
			{
				__result = FromGrid(__result, k);
			}
		}

		[HarmonyPatch(typeof(MapPositionProvider), "TryGetFurthestAvailablePosition")]
		[HarmonyPrefix]
		private static void Furthest_Prefix(ref Vector3 origin, ref float maxDistance)
		{
			//IL_000c: 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)
			if (Active(out var k))
			{
				origin = ToGrid(origin, k);
				maxDistance /= k;
			}
		}

		[HarmonyPatch(typeof(MapPositionProvider), "TryGetFurthestAvailablePosition")]
		[HarmonyPostfix]
		private static void Furthest_Postfix(bool __result, ref Vector3 position)
		{
			//IL_000e: 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)
			if (__result && Active(out var k))
			{
				position = FromGrid(position, k);
			}
		}

		[HarmonyPatch(typeof(MapPositionProvider), "IsPositionAvailable", new Type[] { typeof(Vector3) })]
		[HarmonyPrefix]
		private static void Available_Prefix(ref Vector3 position)
		{
			//IL_000b: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			if (Active(out var k))
			{
				position = ToGrid(position, k);
			}
		}
	}
}