Decompiled source of DimensionMaps v1.1.0

plugins/DimensionMaps.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using Agents;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CellMenu;
using DimensionMaps.Compat;
using DimensionMaps.Core;
using DimensionMaps.Core.NavMeshProcessor;
using DimensionMaps.Data;
using DimensionMaps.Extensions;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using Player;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace DimensionMaps
{
	public static class CompatibilityManager
	{
		internal static void Init()
		{
			if (((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.TryGetValue("BetterMaps", out var value))
			{
				BetterMapsCompat.Init(value.Instance);
			}
		}
	}
	public static class ConfigManager
	{
		private static Config _globalFallback;

		public const string FILE_PREFIX = "DimensionMaps_";

		public const string GLOBAL_FALLBACK_FILENAME = "DimensionMaps_GlobalFallback.json";

		private static readonly Dictionary<string, Config> _expeditionSettings = new Dictionary<string, Config>();

		public static bool TryGetCurrentConfig(out Config config)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			pActiveExpedition activeExpeditionData = RundownManager.GetActiveExpeditionData();
			if (activeExpeditionData == null || !uint.TryParse(activeExpeditionData.rundownKey.data.Replace("Local_", string.Empty), out var result))
			{
				config = null;
				return false;
			}
			string uniqueExpeditionString = GetUniqueExpeditionString(result, activeExpeditionData.tier, (uint)activeExpeditionData.expeditionIndex);
			if (_expeditionSettings.TryGetValue(uniqueExpeditionString, out config))
			{
				return true;
			}
			config = _globalFallback;
			return config != null;
		}

		public static string GetUniqueExpeditionString(uint rundownID, eRundownTier tier, uint expeditionIndex)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			return $"{rundownID}_{tier}_{expeditionIndex}";
		}

		internal static void Init()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Expected O, but got Unknown
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Expected O, but got Unknown
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Expected O, but got Unknown
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(56, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ConfigManager init running, discovering config files ...");
			}
			l.LogInfo(val);
			_globalFallback = null;
			_expeditionSettings.Clear();
			string configPath = Paths.ConfigPath;
			foreach (string item in Directory.EnumerateFiles(configPath, "DimensionMaps_*.json"))
			{
				try
				{
					AttemptLoadFile(item);
				}
				catch (Exception ex)
				{
					ManualLogSource l2 = Plugin.L;
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(28, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load config file: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item);
					}
					l2.LogError(val2);
					ManualLogSource l3 = Plugin.L;
					val2 = new BepInExErrorLogInterpolatedStringHandler(2, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.GetType().FullName);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					l3.LogError(val2);
					ManualLogSource l4 = Plugin.L;
					BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(12, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("StackTrace:\n");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.StackTrace);
					}
					l4.LogWarning(val3);
				}
			}
			string text = Path.Combine(configPath, "DimensionMaps_GlobalFallback.json");
			try
			{
				if (File.Exists(text))
				{
					_globalFallback = JsonSerializer.Deserialize<Config>(File.ReadAllText(text));
					ManualLogSource l5 = Plugin.L;
					val = new BepInExInfoLogInterpolatedStringHandler(36, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded global FALLBACK config file: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					}
					l5.LogInfo(val);
				}
			}
			catch (Exception ex2)
			{
				ManualLogSource l6 = Plugin.L;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(28, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load config file: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
				}
				l6.LogError(val2);
				ManualLogSource l7 = Plugin.L;
				val2 = new BepInExErrorLogInterpolatedStringHandler(2, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.GetType().FullName);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
				}
				l7.LogError(val2);
				ManualLogSource l8 = Plugin.L;
				BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(12, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("StackTrace:\n");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex2.StackTrace);
				}
				l8.LogWarning(val3);
			}
		}

		private static void AttemptLoadFile(string filePath)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);
			if (ParseFilename(fileNameWithoutExtension, out var rundownID, out var tier, out var expeditionIndex))
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(50, 4, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Config found for RundownID:");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(rundownID);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Tier:");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<eRundownTier>(tier);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Expedition:");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(expeditionIndex);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(fileNameWithoutExtension);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
				}
				l.LogInfo(val);
				Config value = JsonSerializer.Deserialize<Config>(File.ReadAllText(filePath));
				_expeditionSettings.Add(GetUniqueExpeditionString(rundownID, tier, expeditionIndex), value);
			}
		}

		private static bool ParseFilename(string fileName, out uint rundownID, out eRundownTier tier, out uint expeditionIndex)
		{
			rundownID = 0u;
			tier = (eRundownTier)0;
			expeditionIndex = 0u;
			if (!fileName.StartsWith("DimensionMaps_"))
			{
				return false;
			}
			fileName = fileName.Substring("DimensionMaps_".Length);
			string[] array = fileName.Split('_');
			if (array.Length != 3)
			{
				return false;
			}
			if (!uint.TryParse(array[0], out rundownID))
			{
				return false;
			}
			if (!Enum.TryParse<eRundownTier>(array[1], out tier) && !Enum.TryParse<eRundownTier>("Tier" + array[1].ToUpper(), out tier))
			{
				return false;
			}
			if (!uint.TryParse(array[2], out expeditionIndex))
			{
				return false;
			}
			return true;
		}
	}
	[BepInPlugin("dev.aurirex.gtfo.dimensionmaps", "Dimension Maps", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string BETTER_MAPS_GUID = "BetterMaps";

		public const string GUID = "dev.aurirex.gtfo.dimensionmaps";

		public const string NAME = "Dimension Maps";

		public const string VERSION = "1.1.0";

		internal static ManualLogSource L;

		private Harmony _harmonyInstance;

		public override void Load()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			L = ((BasePlugin)this).Log;
			_harmonyInstance = new Harmony("dev.aurirex.gtfo.dimensionmaps");
			_harmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
			CompatibilityManager.Init();
		}
	}
}
namespace DimensionMaps.Patches
{
	[HarmonyPatch(typeof(CM_PageMap), "UpdatePlayerData")]
	public static class CM_PageMap__UpdatePlayerData__Patch
	{
		private static GameObject _mapDisconnected;

		private static PlayerAgentDimensionOverrideJank _jank;

		private static bool _doDisconnectDimension;

		private static bool _hasConfig;

		private static Config _config;

		public static void Prefix(CM_PageMap __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected I4, but got Unknown
			if (__instance == null || !((CM_PageBase)__instance).m_isSetup)
			{
				return;
			}
			PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
			if ((Object)(object)localPlayerAgent == (Object)null)
			{
				return;
			}
			_hasConfig = ConfigManager.TryGetCurrentConfig(out _config);
			if ((int)((Agent)localPlayerAgent).DimensionIndex < 17 || (_hasConfig && _config.EnableDimensionSeventeenToTwenty))
			{
				_doDisconnectDimension = false;
				if (_hasConfig)
				{
					bool flag = _config.DimensionsToDisconnect.Contains((uint)(int)((Agent)localPlayerAgent).DimensionIndex);
					_doDisconnectDimension = (_config.InvertDimensionsToDisconnect ? (!flag) : flag);
				}
				GameObject mapDisconnected = __instance.m_mapDisconnected;
				if (mapDisconnected != null)
				{
					mapDisconnected.SetActive(_doDisconnectDimension);
				}
				_mapDisconnected = __instance.m_mapDisconnected;
				__instance.m_mapDisconnected = null;
				_jank = new PlayerAgentDimensionOverrideJank(_doDisconnectDimension);
			}
		}

		public static void Postfix(CM_PageMap __instance)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (__instance == null || !((CM_PageBase)__instance).m_isSetup || _jank == null)
			{
				return;
			}
			_jank.Dispose();
			_jank = null;
			if ((Object)(object)__instance.m_mapHolder == (Object)null)
			{
				return;
			}
			if (!_doDisconnectDimension)
			{
				PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
				if ((Object)(object)localPlayerAgent == (Object)null)
				{
					return;
				}
				__instance.m_mapHolder.SetActive(true);
				CMapDataManager.ShowDimension(((Agent)localPlayerAgent).DimensionIndex);
			}
			__instance.m_mapDisconnected = _mapDisconnected;
			GameObject mapDisconnected = __instance.m_mapDisconnected;
			if (mapDisconnected != null)
			{
				mapDisconnected.SetActive(_doDisconnectDimension);
			}
		}
	}
	[HarmonyPatch(typeof(LG_MapLookatRevealerBase), "OnReveal")]
	public static class LG_MapLookatRevealerBase__OnReveal__Patch
	{
		private static bool _inSecondIteration;

		internal static bool RevealCalled;

		public static void Prefix()
		{
			RevealCalled = false;
		}

		public static void Postfix(LG_MapLookatRevealerBase __instance)
		{
			if (RevealCalled)
			{
				_inSecondIteration = false;
			}
			else if (!_inSecondIteration)
			{
				_inSecondIteration = true;
				Action actionOnReveal = __instance.ActionOnReveal;
				__instance.ActionOnReveal = null;
				__instance.IsRevealed = false;
				__instance.OnReveal((PlayerAgent)null);
				__instance.ActionOnReveal = actionOnReveal;
			}
			else
			{
				_inSecondIteration = false;
			}
		}
	}
	[HarmonyPatch(typeof(MapDataManager), "WantToSetGUIObjVisible")]
	public class MapDataManager__WantToSetGUIObjVisible__Patch
	{
		public static void Postfix()
		{
			LG_MapLookatRevealerBase__OnReveal__Patch.RevealCalled = true;
		}
	}
	[HarmonyPatch(typeof(GameDataInit), "Initialize")]
	public class GameDataInit__Initialize__Patch
	{
		public static void Postfix()
		{
			ConfigManager.Init();
		}
	}
	[HarmonyPatch(typeof(LG_Factory), "NextBatch")]
	public static class LG_Factory__NextBatch__Patch
	{
		private static BatchName _lastBatch;

		public static void Postfix(LG_Factory __instance, ref bool __result)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_0022: 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)
			if (__result)
			{
				if ((int)_lastBatch == 25)
				{
					NavMeshMeshCache.NavMeshBuildDone();
				}
				if ((int)_lastBatch == 38)
				{
					NavMeshMeshCache.DeferredMapConstruction();
				}
				_lastBatch = __instance.m_currentBatchName;
			}
		}
	}
	[HarmonyPatch(typeof(LG_BuildUnityGraphJob), "Build")]
	public static class LG_BuildUnityGraphJob__NavmeshDone__Patch
	{
		public static bool Prefix(LG_BuildUnityGraphJob __instance, ref bool __result)
		{
			__instance.Setup();
			if (__instance.m_dimension.NavmeshOperation.isDone)
			{
				NavmeshDone(__instance);
				__result = true;
				return false;
			}
			__result = false;
			return false;
		}

		private static void NavmeshDone(LG_BuildUnityGraphJob __instance)
		{
			__instance.m_timeCost = Time.realtimeSinceStartup - __instance.m_timeCost;
			Debug.Log(Object.op_Implicit("---------------------------------------------------------"));
			Debug.Log(Object.op_Implicit("Navmesh done! time: " + __instance.m_timeCost));
			Debug.Log(Object.op_Implicit("---------------------------------------------------------"));
			NavMeshMeshCache.Process(__instance);
		}
	}
	[HarmonyPatch(typeof(LG_GenerateNavigationInfoJob), "Build")]
	public static class LG_GenerateNavigationInfoJob__Build__Patch
	{
		public static bool Prefix(LG_GenerateNavigationInfoJob __instance, ref bool __result)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			LG_Factory.DEBUG_LOG(10, ((LG_FactoryJob)__instance).GetName(), false);
			if ((Object)(object)__instance.m_dimension.m_exitPlugArea != (Object)null)
			{
				LG_Factory.InjectJob((LG_FactoryJob)new LG_PropagateNavigationInfoJob(new LG_NavigationData(new LG_NavInfo("Node Exit", false), true)
				{
					ShowPassageTo = true
				}, __instance.m_dimension.m_exitPlugArea.m_courseNode, __instance.m_dimension.m_exitPlugGO.transform.position, -1f, true), (BatchName)62);
			}
			for (int i = 0; i < __instance.m_dimension.Layers.Count; i++)
			{
				LG_Layer val = __instance.m_dimension.Layers[i];
				for (int j = 0; j < val.m_zones.Count; j++)
				{
					__instance.InjectZoneNavInfoJob(val.m_zones[j]);
					CMapDataManager.AddZoneData(__instance.m_dimension.DimensionIndex, __instance.CreateMapZoneData(val.m_zones[j]));
				}
			}
			CMapDataManager.GenerateMap(__instance.m_dimension.DimensionIndex);
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(MapDetails), "StoreSnapshot")]
	public static class MapDetails__StoreSnapshot__Patch
	{
		public static bool Prefix()
		{
			NavMeshMeshCache.SaveSnapshot();
			return false;
		}
	}
	[HarmonyPatch(typeof(MapDetails), "RestoreSnapshot")]
	public static class MapDetails__RestoreSnapshot__Patch
	{
		public static bool Prefix()
		{
			NavMeshMeshCache.LoadSnapshot();
			return false;
		}
	}
	[HarmonyPatch(typeof(MapDetails), "OnLevelCleanup")]
	public static class MapDetails__OnLevelCleanup__Patch
	{
		public static bool Prefix()
		{
			NavMeshMeshCache.OnLevelCleanup();
			MapDetails current = MapDetails.Current;
			if (current != null)
			{
				current.Cleanup();
			}
			MapDetails.Current = null;
			MapDetails.s_isSetup = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(MapDetails), "CollectCommands")]
	public static class MapDetails__CollectCommands__Patch
	{
		public static bool Prefix(MapDetails __instance, CommandBuffer cmd)
		{
			if (!NavMeshMeshCache.IsSetup)
			{
				return false;
			}
			foreach (KeyValuePair<eDimensionIndex, CMapDetails.MapData> allMapLayer in NavMeshMeshCache.Details.AllMapLayers)
			{
				DrawMapRevealerCones(cmd, allMapLayer.Value);
			}
			return false;
		}

		private static void DrawMapRevealerCones(CommandBuffer cmd, CMapDetails.MapData mapData)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			bool num = mapData.coneMtx.Count > 0;
			bool flag = mapData.coneMtx_Other.Count > 0;
			bool flag2 = mapData.coneMtx_Mapper.Count > 0;
			if (!num && !flag && !flag2)
			{
				return;
			}
			cmd.SetProjectionMatrix(mapData.Camera.projectionMatrix);
			cmd.SetViewMatrix(mapData.Camera.worldToCameraMatrix);
			cmd.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)(object)mapData.MapTexture));
			foreach (Matrix4x4 item in mapData.coneMtx)
			{
				cmd.DrawMesh(MapDetails.Current.m_cone, item, MapDetails.Current.m_visiblityMaterial_Cone);
			}
			foreach (Matrix4x4 item2 in mapData.coneMtx_Other)
			{
				cmd.DrawMesh(MapDetails.Current.m_cone, item2, MapDetails.Current.m_visiblityMaterial_ConeOtherPlayer);
			}
			foreach (Matrix4x4 item3 in mapData.coneMtx_Mapper)
			{
				cmd.DrawMesh(MapDetails.Current.m_cone, item3, MapDetails.Current.m_visiblityMaterial_ConeMapper);
			}
			mapData.coneMtx.Clear();
			mapData.coneMtx_Other.Clear();
			mapData.coneMtx_Mapper.Clear();
		}
	}
	[HarmonyPatch(typeof(MapDetails), "OnNavMeshGenerationDone")]
	public static class MapDetails__OnNavMeshGenerationDone__Patch
	{
		public static bool Prefix(MapDetails __instance)
		{
			__instance.m_mapResolution = Mathf.Min(__instance.m_mapResolution, __instance.m_mapRenderResolution);
			return false;
		}
	}
	[HarmonyPatch(typeof(MapDetails), "AddVisiblityCone")]
	public static class MapDetails__AddVisiblityCone__Patch
	{
		public static bool Prefix(Transform transform, VisibilityLayer visibilityLayer)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if ((int)visibilityLayer == 0 && transform.localScale.x == 128f)
			{
				NavMeshMeshCache.Details?.AddVisibilityConeCConsole(transform, visibilityLayer);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(PlayerAgent), "Update")]
	public class PlayerAgent__Update__Patch
	{
		public static void Postfix(PlayerAgent __instance)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			VisibilityLayer visibilityLayer = (VisibilityLayer)((!((Agent)__instance).IsLocallyOwned) ? 1 : 0);
			NavMeshMeshCache.Details?.AddVisibilityCone(((Agent)__instance).DimensionIndex, __instance.m_mapVisibilityTrans, visibilityLayer);
		}
	}
}
namespace DimensionMaps.Extensions
{
	public static class GameObjectExtensions
	{
		public static T GetOrAddComponent<T>(this GameObject gameObject) where T : MonoBehaviour
		{
			T component = gameObject.GetComponent<T>();
			if ((Object)(object)component != (Object)null)
			{
				return component;
			}
			return gameObject.AddComponent<T>();
		}

		public static bool TryGetComponentButDontCrash<T>(this GameObject gameObject, out T comp) where T : MonoBehaviour
		{
			comp = gameObject.GetComponent<T>();
			return (Object)(object)comp != (Object)null;
		}

		public static void SafeDestroy(this Object obj)
		{
			if (!(obj == (Object)null))
			{
				Object.Destroy(obj);
			}
		}

		public static void SafeDestroyGameObject(this Component component)
		{
			if (!((Object)(object)component == (Object)null))
			{
				Object.Destroy((Object)(object)component.gameObject);
			}
		}

		public static IEnumerable<Transform> Children(this GameObject gameObject)
		{
			return gameObject.transform.Children();
		}

		public static IEnumerable<Transform> Children(this Transform transform)
		{
			for (int i = 0; i < transform.childCount; i++)
			{
				yield return transform.GetChild(i);
			}
		}

		public static void DontDestroyAndSetHideFlags(this Object obj)
		{
			Object.DontDestroyOnLoad(obj);
			obj.hideFlags = (HideFlags)61;
		}
	}
}
namespace DimensionMaps.Data
{
	public class Config
	{
		public bool EnableDimensionSeventeenToTwenty { get; set; }

		public bool InvertDimensionsToDisconnect { get; set; }

		public List<uint> DimensionsToDisconnect { get; set; } = new List<uint>();


		public List<uint> DimensionsToForceDefaultMapRendering { get; set; } = new List<uint>();

	}
}
namespace DimensionMaps.Core
{
	public static class CMapDataManager
	{
		private static readonly Dictionary<eDimensionIndex, MapInfo> _dimensionMapInfo = new Dictionary<eDimensionIndex, MapInfo>();

		public static void Cleanup()
		{
			foreach (KeyValuePair<eDimensionIndex, MapInfo> item in _dimensionMapInfo)
			{
				item.Value.Cleanup();
			}
			_dimensionMapInfo.Clear();
		}

		public static void AddZoneData(eDimensionIndex dimensionIndex, CM_MapZoneData mapZoneData)
		{
			//IL_0005: 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)
			if (!_dimensionMapInfo.TryGetValue(dimensionIndex, out var value))
			{
				value = new MapInfo();
				_dimensionMapInfo.Add(dimensionIndex, value);
			}
			value.zoneDatas.Add(mapZoneData);
		}

		public static void GenerateMap(eDimensionIndex dimensionIndex)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (_dimensionMapInfo.TryGetValue(dimensionIndex, out var value))
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(43, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Generating map icons for ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(value.zoneDatas.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" zones in dim ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<eDimensionIndex>(dimensionIndex);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ...");
				}
				l.LogWarning(val);
				BuildMap(dimensionIndex, value.zoneDatas.ToArray());
			}
		}

		private static GameObject GetDimensionMapRoot(eDimensionIndex dimensionIndex)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0072: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			CM_PageMap current = CM_PageMap.Current;
			Transform val = current.m_mapMover.transform.FindChild($"{dimensionIndex}");
			if ((Object)(object)val != (Object)null)
			{
				return ((Component)val).gameObject;
			}
			GameObject val2 = new GameObject($"{dimensionIndex}");
			val2.transform.SetParent(current.m_mapMover.transform);
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one;
			return val2;
		}

		private static bool GetZoneGUIList(eDimensionIndex dimensionIndex, out List<CM_MapZoneGUIItem> zoneGUIs)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (_dimensionMapInfo.TryGetValue(dimensionIndex, out var value))
			{
				zoneGUIs = value.zoneGUIs;
				return true;
			}
			zoneGUIs = null;
			return false;
		}

		private static void BuildMap(eDimensionIndex dimensionIndex, CM_MapZoneData[] zones)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: 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_010e: Expected O, but got Unknown
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			CM_PageMap current = CM_PageMap.Current;
			GameObject dimensionMapRoot = GetDimensionMapRoot(dimensionIndex);
			if (!GetZoneGUIList(dimensionIndex, out var zoneGUIs))
			{
				Plugin.L.LogError((object)"Could not get `zoneGUIs`, this should not happen.");
				return;
			}
			foreach (CM_MapZoneData val in zones)
			{
				CM_MapZoneGUIItem val2 = GOUtil.SpawnChildAndGetComp<CM_MapZoneGUIItem>(current.m_zoneGUIPrefab, dimensionMapRoot.transform);
				((Component)val2).transform.localPosition = Vector3.zero;
				val2.Setup(val, current.m_root);
				zoneGUIs.Add(val2);
			}
			if (current.m_zoneGUI == null)
			{
				current.m_zoneGUI = Il2CppReferenceArray<CM_MapZoneGUIItem>.op_Implicit((CM_MapZoneGUIItem[])(object)new CM_MapZoneGUIItem[0]);
			}
			List<CM_MapZoneGUIItem> list = ((IEnumerable<CM_MapZoneGUIItem>)current.m_zoneGUI).ToList();
			foreach (CM_MapZoneGUIItem item in zoneGUIs)
			{
				list.Add(item);
			}
			current.m_zoneGUI = Il2CppReferenceArray<CM_MapZoneGUIItem>.op_Implicit(list.ToArray());
			Bounds bounds;
			GameObject uI = CMapDetails.GetUI(dimensionIndex, out bounds);
			if ((Object)(object)uI == (Object)null)
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(42, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Oh no, Map UI creation for dim ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<eDimensionIndex>(dimensionIndex);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" failed! :c");
				}
				l.LogError(val3);
				return;
			}
			uI.transform.SetParent(current.m_mapMover.transform);
			uI.transform.localScale = Vector3.one;
			Vector3 localGUIPos = CM_PageMap.GetLocalGUIPos(CM_PageMap.WorldRef, ((Bounds)(ref bounds)).min);
			Vector3 localGUIPos2 = CM_PageMap.GetLocalGUIPos(CM_PageMap.WorldRef, ((Bounds)(ref bounds)).max);
			Bounds val4 = default(Bounds);
			((Bounds)(ref val4)).SetMinMax(localGUIPos, localGUIPos2);
			uI.transform.localPosition = new Vector3(((Bounds)(ref val4)).center.x, ((Bounds)(ref val4)).center.y, -0.1f);
			current.m_mapDetails.SetScale(new Vector3(((Bounds)(ref val4)).size.x, ((Bounds)(ref val4)).size.y, 1f));
			uI.transform.localRotation = Quaternion.identity;
			uI.transform.SetAsFirstSibling();
			uI.SetActive(false);
			dimensionMapRoot.SetActive(false);
			if ((int)dimensionIndex == 0)
			{
				GOUtil.SpawnChildAndGetComp<CM_MapGUIItemBase>(current.m_elevatorGUIPrefab, CM_PageMap.m_mapMoverElementsRoot.transform).PlaceInGUI(ElevatorRide.MapPosition, CM_PageMap.WorldNorth, Vector3.up, false);
				uI.SetActive(true);
				dimensionMapRoot.SetActive(true);
			}
			if (_dimensionMapInfo.TryGetValue(dimensionIndex, out var value))
			{
				value.SetGameObjects(uI, dimensionMapRoot);
			}
			((Component)((CM_PageBase)current).m_cursor).transform.SetAsLastSibling();
			current.m_mapHolder.transform.localScale = new Vector3(current.m_scaleCurrent, current.m_scaleCurrent, 1f);
			current.m_mapBuilt = true;
		}

		public static void ShowDimension(eDimensionIndex dimensionIndex)
		{
			//IL_0005: 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)
			if (!_dimensionMapInfo.TryGetValue(dimensionIndex, out var value))
			{
				return;
			}
			foreach (KeyValuePair<eDimensionIndex, MapInfo> item in _dimensionMapInfo)
			{
				item.Value.SetActive(active: false);
			}
			value.SetActive(active: true);
			if (NavMeshMeshCache.Details.GetMapLayer(dimensionIndex, out var mapData))
			{
				mapData.resolutionSetter?.Invoke();
			}
		}
	}
	public class CMapDetails
	{
		public class MapData
		{
			private readonly GameObject _gameObject;

			public readonly Bounds bounds;

			public readonly Vector3 boundsCenter;

			public readonly float boundsExtendsX;

			public readonly float boundsExtendsY;

			internal Action resolutionSetter;

			internal readonly List<Matrix4x4> coneMtx = new List<Matrix4x4>();

			internal readonly List<Matrix4x4> coneMtx_Other = new List<Matrix4x4>();

			internal readonly List<Matrix4x4> coneMtx_Mapper = new List<Matrix4x4>();

			public string Name
			{
				get
				{
					GameObject gameObject = _gameObject;
					if (gameObject == null)
					{
						return null;
					}
					return ((Object)gameObject).name;
				}
			}

			public Renderer Renderer { get; private set; }

			public RenderTexture MapTexture { get; private set; }

			private GameObject CameraGameObject { get; set; }

			public Camera Camera { get; private set; }

			public SnapShot SnapShot { get; set; }

			public MapData(GameObject go, MeshRenderer renderer, Bounds bounds)
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				_gameObject = go;
				Renderer = (Renderer)(object)renderer;
				this.bounds = bounds;
				boundsCenter = ((Bounds)(ref bounds)).center;
				boundsExtendsX = ((Bounds)(ref bounds)).extents.x;
				boundsExtendsY = ((Bounds)(ref bounds)).extents.y;
			}

			public void Cleanup()
			{
				((Object)(object)Renderer).SafeDestroy();
				((Object)(object)Camera).SafeDestroy();
				CleanupRT(MapTexture);
				SnapShot?.Cleanup();
				((Object)(object)MapTexture).SafeDestroy();
				((Object)(object)_gameObject).SafeDestroy();
				((Object)(object)CameraGameObject).SafeDestroy();
			}

			internal void DisposeRenderer()
			{
				((Object)(object)Renderer)?.SafeDestroy();
				Renderer = null;
			}

			internal void AssignCamera(Camera camera, RenderTexture renderTexture)
			{
				Camera = camera;
				MapTexture = renderTexture;
				SnapShot = new SnapShot(MapTexture);
				CameraGameObject = ((Component)camera).gameObject;
			}
		}

		private readonly Dictionary<eDimensionIndex, MapData> _mapLayers = new Dictionary<eDimensionIndex, MapData>();

		private static eDimensionIndex _currentDimension;

		public static bool RevealMapTexture { get; set; }

		public static Material NavMeshMaterial => MapDetails.Current.m_navmeshMaterial;

		public static Material Mat_FindMapOutline => MapDetails.Current.m_findMapOutline_Material;

		public static Material Mat_SDF => MapDetails.Current.m_SDF_Material;

		public static Material Mat_BlurX => MapDetails.Current.m_blurX;

		public static Material Mat_BlurY => MapDetails.Current.m_blurY;

		public static int MapResolution => MapDetails.Current.m_mapResolution;

		public static int MapRenderResolution => MapDetails.Current.m_mapRenderResolution;

		internal static float? MapOutlineFactor => NavMeshMeshCache.GetProcessor(_currentDimension).MapOutlineFactor;

		internal static float? MapBlurFactor => NavMeshMeshCache.GetProcessor(_currentDimension).MapBlurFactor;

		public IEnumerable<KeyValuePair<eDimensionIndex, MapData>> AllMapLayers
		{
			get
			{
				foreach (KeyValuePair<eDimensionIndex, MapData> mapLayer in _mapLayers)
				{
					yield return mapLayer;
				}
			}
		}

		public void SaveSnapshot()
		{
			Plugin.L.LogWarning((object)"Saving map snapshots ...");
			foreach (KeyValuePair<eDimensionIndex, MapData> mapLayer in _mapLayers)
			{
				mapLayer.Value.SnapShot.Capture();
			}
		}

		public void RestoreSnapshot()
		{
			Plugin.L.LogWarning((object)"Restoring map snapshots ...");
			foreach (KeyValuePair<eDimensionIndex, MapData> allMapLayer in AllMapLayers)
			{
				allMapLayer.Value.SnapShot.Restore();
			}
		}

		public void OnLevelCleanup()
		{
			foreach (KeyValuePair<eDimensionIndex, MapData> mapLayer in _mapLayers)
			{
				mapLayer.Value?.Cleanup();
			}
			_mapLayers.Clear();
		}

		private static void CleanupRT(RenderTexture rt)
		{
			if (rt != null)
			{
				rt.Release();
			}
		}

		public void SetupAllMapLayers(IEnumerable<NavMeshInfo> allInfos)
		{
			//IL_0017: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_0088: Expected O, but got Unknown
			MapDataManager.PrepareMapNavmesh();
			foreach (NavMeshInfo allInfo in allInfos)
			{
				SetupMapLayer(allInfo.dimensionIndex, allInfo.mesh);
			}
			MapData mapData = _mapLayers[(eDimensionIndex)0];
			if (mapData != null)
			{
				MapDetails.Current.m_mapTexture = mapData.MapTexture;
				MapDetails.Current.m_camera = mapData.Camera;
				MapDetails current2 = MapDetails.Current;
				if (current2.m_cmd == null)
				{
					CommandBuffer val = new CommandBuffer();
					CommandBuffer val2 = val;
					current2.m_cmd = val;
				}
				MapDetails.s_isSetup = true;
			}
		}

		public bool GetMapLayer(eDimensionIndex index, out MapData mapData)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return _mapLayers.TryGetValue(index, out mapData);
		}

		private void SetupMapLayer(eDimensionIndex index, Mesh mesh)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			_currentDimension = index;
			GameObject val = new GameObject($"MapNavmesh_{index}");
			MeshFilter val2 = val.AddComponent<MeshFilter>();
			MeshRenderer val3 = val.AddComponent<MeshRenderer>();
			val2.mesh = mesh;
			((Renderer)val3).material = NavMeshMaterial;
			Bounds bounds = ((Renderer)val3).bounds;
			((Bounds)(ref bounds)).Expand(new Vector3(64f, 0f, 64f));
			MapData mapData = new MapData(val, val3, bounds);
			SetupCamera(mapData);
			DrawMapBasis(mapData);
			_mapLayers[index] = mapData;
		}

		private void SetupCamera(MapData mapData)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0052: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			Camera val = new GameObject("CAMERA_" + mapData.Name).AddComponent<Camera>();
			val.orthographic = true;
			Bounds bounds = mapData.bounds;
			val.orthographicSize = ((Bounds)(ref bounds)).size.z * 0.5f;
			Transform transform = ((Component)val).transform;
			bounds = mapData.bounds;
			Vector3 center = ((Bounds)(ref bounds)).center;
			bounds = mapData.bounds;
			transform.position = center + new Vector3(0f, ((Bounds)(ref bounds)).size.y + 20f, 0f);
			val.nearClipPlane = 1f;
			bounds = mapData.bounds;
			val.farClipPlane = ((Bounds)(ref bounds)).size.y * 2f + 5f + 20f;
			val.cullingMask = 0;
			((Component)val).transform.rotation = Quaternion.LookRotation(Vector3.down, Vector3.forward);
			val.allowMSAA = false;
			val.allowHDR = false;
			val.useOcclusionCulling = false;
			val.renderingPath = (RenderingPath)1;
			val.clearFlags = (CameraClearFlags)4;
			bounds = mapData.bounds;
			int x = (int)((Bounds)(ref bounds)).size.x * MapResolution;
			bounds = mapData.bounds;
			int y = (int)((Bounds)(ref bounds)).size.z * MapResolution;
			GetClampedRes(2048, ref x, ref y, out var _, out var _, out var _);
			RenderTexture val2 = new RenderTexture(x, y, 0, (RenderTextureFormat)11, (RenderTextureReadWrite)1)
			{
				name = "mapRT_" + mapData.Name,
				filterMode = (FilterMode)2,
				wrapMode = (TextureWrapMode)1
			};
			val2.Create();
			val.targetTexture = val2;
			mapData.AssignCamera(val, val2);
			((Behaviour)mapData.Camera).enabled = false;
			mapData.Renderer.enabled = false;
		}

		private void DrawMapBasis(MapData mapData)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Expected O, but got Unknown
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: 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_0211: 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_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Expected O, but got Unknown
			Bounds bounds = mapData.bounds;
			int x = (int)((Bounds)(ref bounds)).size.x * MapRenderResolution;
			bounds = mapData.bounds;
			int y = (int)((Bounds)(ref bounds)).size.z * MapRenderResolution;
			GetClampedRes(1024, ref x, ref y, out var _, out var _, out var downscale);
			float num = 0.005f * downscale;
			int num2 = Shader.PropertyToID("_SamplingScale");
			Mat_FindMapOutline.SetFloat(num2, MapOutlineFactor ?? num);
			Mat_SDF.SetFloat(num2, MapOutlineFactor ?? num);
			Mat_BlurX.SetFloat(num2, MapBlurFactor ?? num);
			Mat_BlurY.SetFloat(num2, MapBlurFactor ?? num);
			RenderTexture val = new RenderTexture(x, y, 16, (RenderTextureFormat)0, (RenderTextureReadWrite)1);
			RenderTexture val2 = new RenderTexture(x, y, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)1);
			RenderTexture val3 = new RenderTexture(((Texture)mapData.MapTexture).width, ((Texture)mapData.MapTexture).height, 0, (RenderTextureFormat)11, (RenderTextureReadWrite)1);
			((Texture)val).filterMode = (FilterMode)2;
			((Texture)val2).filterMode = (FilterMode)2;
			((Texture)val3).filterMode = (FilterMode)2;
			val.Create();
			val2.Create();
			val3.Create();
			CommandBuffer val4 = new CommandBuffer();
			val4.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)(object)val));
			val4.ClearRenderTarget(true, true, Color.black);
			val4.SetProjectionMatrix(mapData.Camera.projectionMatrix);
			val4.SetViewMatrix(mapData.Camera.worldToCameraMatrix);
			val4.DrawRenderer(mapData.Renderer, NavMeshMaterial);
			val4.Blit((Texture)(object)val, RenderTargetIdentifier.op_Implicit((Texture)(object)val2), Mat_FindMapOutline);
			val4.Blit((Texture)(object)val2, RenderTargetIdentifier.op_Implicit((Texture)(object)mapData.MapTexture), Mat_SDF);
			val4.Blit((Texture)(object)mapData.MapTexture, RenderTargetIdentifier.op_Implicit((Texture)(object)val3), Mat_BlurX);
			val4.Blit((Texture)(object)val3, RenderTargetIdentifier.op_Implicit((Texture)(object)mapData.MapTexture), Mat_BlurY);
			val4.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)(object)mapData.MapTexture));
			mapData.Renderer.enabled = true;
			Graphics.ExecuteCommandBuffer(val4);
			val4.Dispose();
			mapData.Renderer.enabled = false;
			mapData.DisposeRenderer();
			val.Release();
			val2.Release();
			val3.Release();
		}

		private void GetClampedRes(int maxRes, ref int x, ref int y, out float ratio, out bool overX, out float downscale)
		{
			downscale = 1f;
			overX = x > y;
			if (overX)
			{
				ratio = y / x;
				if (x > maxRes)
				{
					y = (int)((float)y * ((float)maxRes / (float)x));
					x = maxRes;
					downscale = (float)maxRes / (float)x;
				}
			}
			else
			{
				ratio = y / x;
				if (y > maxRes)
				{
					x = (int)((float)x * ((float)maxRes / (float)y));
					y = maxRes;
					downscale = (float)maxRes / (float)y;
				}
			}
		}

		public static GameObject GetUI(eDimensionIndex dimensionIndex, out Bounds bounds)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0021: 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_005c: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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)
			MapDetails current = MapDetails.Current;
			if (!NavMeshMeshCache.Details._mapLayers.TryGetValue(dimensionIndex, out var value))
			{
				bounds = default(Bounds);
				return null;
			}
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(32, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Custom MapDetails.GetUI running!");
			}
			l.LogError(val);
			GameObject val2 = Object.Instantiate<GameObject>(current.m_mapDetailsUI, Vector3.zero, Quaternion.identity);
			((Object)val2).name = $"{((Object)val2).name}_{dimensionIndex}";
			current.m_UIObject = val2;
			SpriteRenderer componentInChildren = val2.GetComponentInChildren<SpriteRenderer>();
			RenderTexture mapTexture = value.MapTexture;
			Material material = ((Renderer)componentInChildren).material;
			material.SetTexture("_MapTexture", (Texture)(object)mapTexture);
			current.m_mapTexture = mapTexture;
			bounds = value.bounds;
			current.s_aspectX = (float)((Texture)mapTexture).width / 1024f;
			current.s_aspectY = (float)((Texture)mapTexture).height / 1024f;
			current.s_uvScaleCompensation = 10f;
			float num = (RevealMapTexture ? 1f : 0f);
			material.SetVector(current.s_SID_Settings, new Vector4(current.s_aspectX, current.s_aspectY, current.s_uvScaleCompensation, num));
			(value.resolutionSetter = delegate
			{
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				Shader.SetGlobalVector("_MAP_ResolutionData", new Vector4(1f / (float)((Texture)mapTexture).width, 1f / (float)((Texture)mapTexture).height, 0f, 0f));
			})();
			current.m_UIMaterial = material;
			((Renderer)componentInChildren).material = material;
			return val2;
		}

		public void AddVisibilityCone(eDimensionIndex dimensionIndex, Transform transform, VisibilityLayer visibilityLayer)
		{
			//IL_000e: 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_002b: Expected I4, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (MapDetails.s_isSetup && _mapLayers.TryGetValue(dimensionIndex, out var value))
			{
				switch ((int)visibilityLayer)
				{
				case 0:
					value.coneMtx.Add(transform.localToWorldMatrix);
					break;
				case 1:
					value.coneMtx_Other.Add(transform.localToWorldMatrix);
					break;
				case 2:
					value.coneMtx_Mapper.Add(transform.localToWorldMatrix);
					break;
				}
			}
		}

		public void AddVisibilityConeCConsole(Transform transform, VisibilityLayer visibilityLayer)
		{
			//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)
			foreach (KeyValuePair<eDimensionIndex, MapData> mapLayer in _mapLayers)
			{
				AddVisibilityCone(mapLayer.Key, transform, visibilityLayer);
			}
		}
	}
	public class DeferredNavMeshData
	{
		public readonly eDimensionIndex dimensionIndex;

		public readonly NavMeshTriangulation navMeshTriangulation;

		public DeferredNavMeshData(eDimensionIndex dimensionIndex, NavMeshTriangulation navMeshTriangulation)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			this.dimensionIndex = dimensionIndex;
			this.navMeshTriangulation = navMeshTriangulation;
		}
	}
	public class MapInfo
	{
		public readonly List<CM_MapZoneData> zoneDatas = new List<CM_MapZoneData>();

		public readonly List<CM_MapZoneGUIItem> zoneGUIs = new List<CM_MapZoneGUIItem>();

		private GameObject _uiRoot;

		private GameObject _itemRoot;

		public void Cleanup()
		{
			((Object)(object)_uiRoot)?.SafeDestroy();
			((Object)(object)_itemRoot)?.SafeDestroy();
		}

		public void SetActive(bool active)
		{
			GameObject uiRoot = _uiRoot;
			if (uiRoot != null)
			{
				uiRoot.SetActive(active);
			}
			GameObject itemRoot = _itemRoot;
			if (itemRoot != null)
			{
				itemRoot.SetActive(active);
			}
		}

		internal void SetGameObjects(GameObject uiRoot, GameObject itemRoot)
		{
			_uiRoot = uiRoot;
			_itemRoot = itemRoot;
		}
	}
	public class NavMeshInfo
	{
		public readonly eDimensionIndex dimensionIndex;

		public Mesh mesh;

		public readonly Dimension dimension;

		public NavMeshInfo(eDimensionIndex dimensionIndex, Mesh mesh, Dimension dimension)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			this.dimensionIndex = dimensionIndex;
			this.mesh = mesh;
			this.dimension = dimension;
		}
	}
	public static class NavMeshMeshCache
	{
		internal static CMapDetails Details;

		public static HashSet<NavMeshInfo> All { get; } = new HashSet<NavMeshInfo>();


		public static bool IsSetup { get; private set; }

		public static INavMeshProcessor DefaultProcessor { get; } = new DefaultNavMeshProcessor();


		public static INavMeshProcessor Processor { get; set; } = DefaultProcessor;


		private static void Clear()
		{
			foreach (NavMeshInfo item in All)
			{
				((Object)(object)item.mesh).SafeDestroy();
			}
			All.Clear();
		}

		private static void AddNavMeshData(Dimension dimension)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			dimension.NavmeshInstance = NavMesh.AddNavMeshData(dimension.NavmeshData);
		}

		internal static void NavMeshBuildDone()
		{
			InjectAllNavMeshes();
			if (!Processor.IsDeferred)
			{
				SetupMapLayers(All);
			}
		}

		public static void InjectDeferredMesh(eDimensionIndex key, Mesh mesh)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			NavMeshInfo navMeshInfo = All.FirstOrDefault((NavMeshInfo i) => i.dimensionIndex == key);
			if (navMeshInfo != null)
			{
				navMeshInfo.mesh = mesh;
			}
		}

		public static void SetupAllMapLayers()
		{
			SetupMapLayers(All);
		}

		private static void SetupMapLayers(IEnumerable<NavMeshInfo> mapLayers)
		{
			if (Details == null)
			{
				Details = new CMapDetails();
			}
			Details.SetupAllMapLayers(mapLayers);
		}

		private static void InjectAllNavMeshes()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			Plugin.L.LogWarning((object)"Re-Injecting all nav meshes");
			NavMesh.RemoveAllNavMeshData();
			bool flag = default(bool);
			foreach (NavMeshInfo item in All)
			{
				Dimension dimension = item.dimension;
				if (dimension != null)
				{
					ManualLogSource l = Plugin.L;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(22, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Injecting NavMesh for ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<eDimensionIndex>(dimension.DimensionIndex);
					}
					l.LogWarning(val);
					AddNavMeshData(dimension);
				}
			}
			IsSetup = true;
		}

		public static void Process(LG_BuildUnityGraphJob job)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0072: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(14, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Processing ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((LG_FactoryJob)job).GetName());
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<eDimensionIndex>(job.m_dimension.DimensionIndex);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
			}
			l.LogWarning(val);
			NavMesh.RemoveAllNavMeshData();
			Dimension dimension = job.m_dimension;
			AddNavMeshData(dimension);
			eDimensionIndex dimensionIndex = dimension.DimensionIndex;
			Mesh mesh = null;
			INavMeshProcessor processor = GetProcessor(dimensionIndex);
			if (processor.IsDeferred)
			{
				if (processor.DeferredData == null)
				{
					ManualLogSource l2 = Plugin.L;
					val = new BepInExWarningLogInterpolatedStringHandler(68, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Current ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("INavMeshProcessor");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ('");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(processor.GetType().FullName);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("') says it's deferred, but no ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("DeferredData");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" queue exists. (= Not good)");
					}
					l2.LogWarning(val);
				}
				processor.DeferredData?.Enqueue(new DeferredNavMeshData(dimensionIndex, NavMesh.CalculateTriangulation()));
			}
			else
			{
				mesh = processor.CalculateNavMeshMesh(dimensionIndex);
			}
			NavMeshInfo item = new NavMeshInfo(dimensionIndex, mesh, dimension);
			All.Add(item);
		}

		public static void DeferredMapConstruction()
		{
			if (Processor.IsDeferred)
			{
				Processor.DeferredMapConstruction();
			}
		}

		public static void OnLevelCleanup()
		{
			Details?.OnLevelCleanup();
			CMapDataManager.Cleanup();
			Clear();
			IsSetup = false;
		}

		public static void SaveSnapshot()
		{
			Details?.SaveSnapshot();
		}

		public static void LoadSnapshot()
		{
			Details?.RestoreSnapshot();
		}

		public static INavMeshProcessor GetProcessor(eDimensionIndex dimensionIndex)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected I4, but got Unknown
			if (ConfigManager.TryGetCurrentConfig(out var config) && config.DimensionsToForceDefaultMapRendering != null && config.DimensionsToForceDefaultMapRendering.Contains((uint)(int)dimensionIndex))
			{
				return DefaultProcessor;
			}
			return Processor;
		}
	}
	public class PlayerAgentDimensionOverrideJank : IDisposable
	{
		private Dictionary<IntPtr, eDimensionIndex> _jank = new Dictionary<IntPtr, eDimensionIndex>();

		public PlayerAgentDimensionOverrideJank(bool doDisconnect = false)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0076: 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)
			PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
			eDimensionIndex val = (eDimensionIndex)((localPlayerAgent != null) ? ((int)((Agent)localPlayerAgent).m_dimensionIndex) : 0);
			Enumerator<PlayerAgent> enumerator = PlayerManager.PlayerAgentsInLevel.GetEnumerator();
			while (enumerator.MoveNext())
			{
				PlayerAgent current = enumerator.Current;
				if (!((Object)(object)current == (Object)null))
				{
					_jank.Add(((Il2CppObjectBase)current).Pointer, ((Agent)current).m_dimensionIndex);
					if (doDisconnect)
					{
						((Agent)current).m_dimensionIndex = (eDimensionIndex)20;
						break;
					}
					if (((Agent)current).m_dimensionIndex == val)
					{
						((Agent)current).m_dimensionIndex = (eDimensionIndex)0;
					}
					else
					{
						((Agent)current).m_dimensionIndex = (eDimensionIndex)(val + 1);
					}
				}
			}
		}

		public void Dispose()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<PlayerAgent> enumerator = PlayerManager.PlayerAgentsInLevel.GetEnumerator();
			while (enumerator.MoveNext())
			{
				PlayerAgent current = enumerator.Current;
				if (!((Object)(object)current == (Object)null) && _jank.TryGetValue(((Il2CppObjectBase)current).Pointer, out var value))
				{
					((Agent)current).m_dimensionIndex = value;
				}
			}
		}
	}
	public class SnapShot : IDisposable
	{
		private bool _hasSnapshot;

		private readonly RenderTexture _mapTexture;

		private RenderTexture _snapshotTexture;

		public SnapShot(RenderTexture mapTexture)
		{
			//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_001e: Expected O, but got Unknown
			_mapTexture = mapTexture;
			_snapshotTexture = new RenderTexture(mapTexture.descriptor);
		}

		public void Capture()
		{
			if (!((Object)(object)_snapshotTexture == (Object)null))
			{
				Graphics.Blit((Texture)(object)_mapTexture, _snapshotTexture);
				_hasSnapshot = true;
			}
		}

		public void Restore()
		{
			if (!((Object)(object)_snapshotTexture == (Object)null) && _hasSnapshot)
			{
				Graphics.Blit((Texture)(object)_snapshotTexture, _mapTexture);
			}
		}

		public void Cleanup()
		{
			RenderTexture snapshotTexture = _snapshotTexture;
			if (snapshotTexture != null)
			{
				snapshotTexture.Release();
			}
			_snapshotTexture = null;
		}

		public void Dispose()
		{
			Cleanup();
		}
	}
}
namespace DimensionMaps.Core.NavMeshProcessor
{
	public class DefaultNavMeshProcessor : INavMeshProcessor
	{
		public float? MapBlurFactor { get; set; }

		public float? MapOutlineFactor { get; set; }

		public Mesh CalculateNavMeshMesh(eDimensionIndex dimensionIndex)
		{
			//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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			NavMeshTriangulation val = NavMesh.CalculateTriangulation();
			Mesh val2 = new Mesh
			{
				name = "NavMeshMesh_" + ((object)(eDimensionIndex)(ref dimensionIndex)).ToString(),
				indexFormat = (IndexFormat)(Mathf.Max(((Il2CppArrayBase<Vector3>)(object)val.vertices).Length, ((Il2CppArrayBase<int>)(object)val.indices).Length) >= 65534),
				vertices = val.vertices,
				triangles = val.indices
			};
			Vector3[] array = (Vector3[])(object)new Vector3[((Il2CppArrayBase<Vector3>)(object)val2.vertices).Length];
			Vector3 up = Vector3.up;
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = up;
			}
			val2.normals = Il2CppStructArray<Vector3>.op_Implicit(array);
			return val2;
		}
	}
	public class DeferredNavMeshProcessor : INavMeshProcessor
	{
		public Action onDeferredMapConstruction;

		public bool IsDeferred => true;

		public float? MapBlurFactor { get; set; }

		public float? MapOutlineFactor { get; set; }

		public Queue<DeferredNavMeshData> DeferredData { get; } = new Queue<DeferredNavMeshData>();


		public Mesh CalculateNavMeshMesh(eDimensionIndex dimensionIndex)
		{
			return null;
		}

		public void DeferredMapConstruction()
		{
			onDeferredMapConstruction?.Invoke();
		}
	}
	public interface INavMeshProcessor
	{
		bool IsDeferred => false;

		float? MapOutlineFactor => null;

		float? MapBlurFactor => null;

		Queue<DeferredNavMeshData> DeferredData => null;

		Mesh CalculateNavMeshMesh(eDimensionIndex dimensionIndex);

		void DeferredMapConstruction()
		{
		}
	}
}
namespace DimensionMaps.Compat
{
	public static class BetterMapsCompat
	{
		private const string BUILD_METHOD_NAME = "OnBuildDone";

		private const string CUSTOM_CREATENAVMESH_METHOD_NAME = "CreateNavMesh";

		private const string FIELD_BLURFACTOR = "_BlurFactor";

		private const string FIELD_OUTLINEFACTOR = "_OutlineFactor";

		private static Harmony _harmony;

		private static MethodInfo _MI_CreateNavMesh;

		private static Func<bool, Mesh> _betterMapsMethod_CreateNavMesh;

		private static readonly DeferredNavMeshProcessor _processor = new DeferredNavMeshProcessor();

		private static NavMeshTriangulation _overrideTriangulationResult;

		private static BindingFlags All => AccessTools.all;

		private static bool OverrideCalculateTriangulation { get; set; }

		private static NavMeshTriangulation OverrideTriangulationResult
		{
			get
			{
				return _overrideTriangulationResult;
			}
			set
			{
				_overrideTriangulationResult = value;
				OverrideCalculateTriangulation = true;
			}
		}

		internal static void Init(object betterMapsPluginInstance)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Expected O, but got Unknown
			Type type = betterMapsPluginInstance.GetType();
			Log("PluginType: " + type.FullName);
			MethodInfo method = type.GetMethod("OnBuildDone", All);
			_harmony = new Harmony("dev.aurirex.gtfo.dimensionmaps.BetterMapsCompat");
			_harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(BetterMapsCompat).GetMethod("Prefix_OnBuildDone", All)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			_MI_CreateNavMesh = type.GetMethod("CreateNavMesh", All);
			_betterMapsMethod_CreateNavMesh = (bool b) => (Mesh)_MI_CreateNavMesh.Invoke(betterMapsPluginInstance, new object[1] { b });
			ConfigEntry<float> val = (ConfigEntry<float>)type.GetField("_BlurFactor", All).GetValue(betterMapsPluginInstance);
			ConfigEntry<float> val2 = (ConfigEntry<float>)type.GetField("_OutlineFactor", All).GetValue(betterMapsPluginInstance);
			_processor.MapBlurFactor = val?.Value;
			Log($"Gotten BlurFactor: {CMapDetails.MapBlurFactor}");
			_processor.MapOutlineFactor = val2?.Value;
			Log($"Gotten OutlineFactor: {CMapDetails.MapOutlineFactor}");
			MethodInfo method2 = typeof(NavMesh).GetMethod("CalculateTriangulation");
			_harmony.Patch((MethodBase)method2, new HarmonyMethod(typeof(BetterMapsCompat).GetMethod("Prefix_CalculateTriangulation", All)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			_processor.onDeferredMapConstruction = CreateMapMeshes;
			NavMeshMeshCache.Processor = _processor;
		}

		private static void Log(string msg)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(4, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("BetterMapsCompat");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("]: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(msg);
			}
			l.LogWarning(val);
		}

		private static bool Prefix_OnBuildDone()
		{
			return false;
		}

		private static void CreateMapMeshes()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			Log("Creating Deferred Meshes ...");
			while (_processor.DeferredData.Count > 0)
			{
				DeferredNavMeshData deferredNavMeshData = _processor.DeferredData.Dequeue();
				OverrideTriangulationResult = deferredNavMeshData.navMeshTriangulation;
				NavMeshMeshCache.InjectDeferredMesh(mesh: _betterMapsMethod_CreateNavMesh(arg: false), key: deferredNavMeshData.dimensionIndex);
			}
			NavMeshMeshCache.SetupAllMapLayers();
		}

		private static bool Prefix_CalculateTriangulation(ref NavMeshTriangulation __result)
		{
			if (!OverrideCalculateTriangulation)
			{
				return true;
			}
			__result = OverrideTriangulationResult;
			OverrideCalculateTriangulation = false;
			return false;
		}
	}
}