Decompiled source of FatedGates v1.0.0

plugins/FatedGates.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using FatedGates.Commands.Converters;
using FatedGates.Services;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using ProjectM.Shared;
using ProjectM.Shared.Systems;
using ProjectM.Terrain;
using Stunlock.Core;
using Stunlock.Localization;
using Stunlock.Network;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Scenes;
using Unity.Transforms;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FatedGates")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Server-side V Rising mod for persistent public waygates and public reveal zones.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6cc1dd7daf028ae1e39bb5e380493dffa817222f")]
[assembly: AssemblyProduct("FatedGates")]
[assembly: AssemblyTitle("FatedGates")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FatedGates
{
	internal static class Core
	{
		private static MonoBehaviour monoBehaviour;

		private static bool _hasInitialized = false;

		public static World Server { get; } = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");


		public static EntityManager EntityManager { get; } = Server.EntityManager;


		public static ChunkObjectManager ChunkObjectManager { get; } = Server.GetExistingSystemManaged<ChunkObjectManager>();


		public static PrefabCollectionSystem PrefabCollection { get; } = Server.GetExistingSystemManaged<PrefabCollectionSystem>();


		public static ServerGameSettingsSystem ServerGameSettingsSystem { get; internal set; }

		public static ServerScriptMapper ServerScriptMapper { get; internal set; }

		public static double ServerTime => ServerGameManager.ServerTime;

		public static ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();

		public static ManualLogSource Log { get; } = Plugin.LogInstance;


		public static LocalizationService LocalizationService { get; } = new LocalizationService();


		public static MapIconService MapIconService { get; internal set; }

		public static PortalService PortalService { get; } = new PortalService();


		public static WaygateService WaygateService { get; internal set; }

		public static RevealService RevealService { get; private set; }

		public static void LogException(Exception e, [CallerMemberName] string caller = null)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(51, 5, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failure in ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(caller);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nMessage: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.Message);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Inner:");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.InnerException?.Message);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n\nStack: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.StackTrace);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nInner Stack: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.InnerException?.StackTrace);
			}
			log.LogError(val);
		}

		internal static void InitializeAfterLoaded()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			if (!_hasInitialized)
			{
				ServerGameSettingsSystem = Server.GetExistingSystemManaged<ServerGameSettingsSystem>();
				ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
				FoundWaygatePrefabConverter.Initialize();
				MapIconService = new MapIconService();
				WaygateService = new WaygateService();
				RevealService = new RevealService();
				_hasInitialized = true;
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(26, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("KindredPortals initialized");
				}
				log.LogInfo(val);
			}
		}

		private static World GetWorld(string name)
		{
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.Name == name)
				{
					return current;
				}
			}
			return null;
		}

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			if ((Object)(object)monoBehaviour == (Object)null)
			{
				GameObject val = new GameObject("KindredExtract");
				monoBehaviour = (MonoBehaviour)(object)val.AddComponent<IgnorePhysicsDebugSystem>();
				Object.DontDestroyOnLoad((Object)val);
			}
			return monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
		}

		public static void StopCoroutine(Coroutine coroutine)
		{
			if (!((Object)(object)monoBehaviour == (Object)null))
			{
				monoBehaviour.StopCoroutine(coroutine);
			}
		}
	}
	public static class ECSExtensions
	{
		private static EntityManager EntityManager { get; } = Core.Server.EntityManager;


		public unsafe static void Write<T>(this Entity entity, T componentData) where T : struct
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			byte[] array = StructureToByteArray(componentData);
			int num = Marshal.SizeOf<T>();
			fixed (byte* ptr = array)
			{
				EntityManager entityManager = EntityManager;
				((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, val.TypeIndex, (void*)ptr, num);
			}
		}

		private static byte[] StructureToByteArray<T>(T structure) where T : struct
		{
			int num = Marshal.SizeOf(structure);
			byte[] array = new byte[num];
			IntPtr intPtr = Marshal.AllocHGlobal(num);
			Marshal.StructureToPtr(structure, intPtr, fDeleteOld: true);
			Marshal.Copy(intPtr, array, 0, num);
			Marshal.FreeHGlobal(intPtr);
			return array;
		}

		public unsafe static T Read<T>(this Entity entity) where T : struct
		{
			//IL_000d: 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_0015: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex)));
		}

		public static DynamicBuffer<T> ReadBuffer<T>(this Entity entity) where T : struct
		{
			//IL_0005: 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_000d: 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)
			EntityManager entityManager = Core.Server.EntityManager;
			return ((EntityManager)(ref entityManager)).GetBuffer<T>(entity, false);
		}

		public static bool Has<T>(this Entity entity)
		{
			//IL_000d: 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_0015: 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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
		}

		public static string LookupName(this PrefabGUID prefabGuid)
		{
			//IL_000a: 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_0012: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			PrefabLookupMap prefabLookupMap = Core.Server.GetExistingSystemManaged<PrefabCollectionSystem>()._PrefabLookupMap;
			string text = default(string);
			object obj;
			if (!((PrefabLookupMap)(ref prefabLookupMap)).TryGetName(prefabGuid, ref text))
			{
				obj = "GUID Not Found";
			}
			else
			{
				string text2 = text;
				PrefabGUID val = prefabGuid;
				obj = text2 + " " + ((object)(PrefabGUID)(ref val)).ToString();
			}
			return obj.ToString();
		}

		public static void Add<T>(this Entity entity)
		{
			//IL_000d: 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_0015: 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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			((EntityManager)(ref entityManager)).AddComponent(entity, val);
		}

		public static void Remove<T>(this Entity entity)
		{
			//IL_000d: 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_0015: 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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			((EntityManager)(ref entityManager)).RemoveComponent(entity, val);
		}

		public static TerrainChunk GetChunk(this Entity entity)
		{
			//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_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)
			return entity.Read<Translation>().Value.GetChunk();
		}

		public static TerrainChunk GetChunk(this float3 pos)
		{
			//IL_0002: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			TerrainChunk result = default(TerrainChunk);
			result.X = (sbyte)((pos.x + 3200f) / 160f);
			result.Y = (sbyte)((pos.z + 3200f) / 160f);
			return result;
		}
	}
	[BepInPlugin("FatedGates", "FatedGates", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static Harmony Harmony { get; private set; }

		public static ManualLogSource LogInstance { get; private set; }

		public override void Load()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("FatedGates");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			LogInstance = ((BasePlugin)this).Log;
			_harmony = new Harmony("FatedGates");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			Harmony = _harmony;
			CommandRegistry.RegisterAll();
		}

		public override bool Unload()
		{
			CommandRegistry.UnregisterAssembly();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "FatedGates";

		public const string PLUGIN_NAME = "FatedGates";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace FatedGates.Services
{
	internal class LocalizationService
	{
		private Dictionary<string, string> localization = new Dictionary<string, string>();

		public LocalizationService()
		{
			LoadLocalization();
		}

		private void LoadLocalization()
		{
			string name = "FatedGates.Localization.English.json";
			Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
			if (manifestResourceStream != null)
			{
				using (StreamReader streamReader = new StreamReader(manifestResourceStream))
				{
					string json = streamReader.ReadToEnd();
					localization = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
					return;
				}
			}
			Console.WriteLine("Resource not found!");
		}

		public string GetLocalization(string guid)
		{
			if (localization.TryGetValue(guid, out var value))
			{
				return value;
			}
			return "<Localization not found!>";
		}
	}
	internal class MapIconService
	{
		private PrefabGUID mapIconProxyPrefabGUID;

		private Entity mapIconProxyPrefab;

		private EntityQuery mapIconProxyQuery;

		public MapIconService()
		{
			//IL_0036: 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_003f: 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_0066: 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)
			//IL_006e: 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_0078: 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_0085: 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_0092: 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_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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			if (!Core.PrefabCollection._SpawnableNameToPrefabGuidDictionary.TryGetValue("MapIcon_ProxyObject_POI_Unknown", ref mapIconProxyPrefabGUID))
			{
				Core.Log.LogError((object)"Failed to find MapIcon_ProxyObject_POI_Unknown PrefabGUID");
			}
			if (!Core.PrefabCollection._PrefabGuidToEntityMap.TryGetValue(mapIconProxyPrefabGUID, ref mapIconProxyPrefab))
			{
				Core.Log.LogError((object)"Failed to find MapIcon_ProxyObject_POI_Unknown Prefab entity");
			}
			EntityQueryBuilder val = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
			val = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly<AttachMapIconsToEntity>());
			val = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly<SpawnedBy>());
			val = ((EntityQueryBuilder)(ref val)).AddNone(ComponentType.ReadOnly<ChunkPortal>());
			val = ((EntityQueryBuilder)(ref val)).AddNone(ComponentType.ReadOnly<ChunkWaypoint>());
			EntityQueryBuilder val2 = ((EntityQueryBuilder)(ref val)).WithOptions((EntityQueryOptions)2);
			EntityManager entityManager = Core.EntityManager;
			mapIconProxyQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val2);
			((EntityQueryBuilder)(ref val2)).Dispose();
		}

		public void CreateMapIcon(Entity characterEntity, PrefabGUID mapIcon)
		{
			//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_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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0023: 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_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_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_0041: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0062: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0077: 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_008b: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			float3 value = characterEntity.Read<Translation>().Value;
			EntityManager entityManager = Core.EntityManager;
			Entity val = ((EntityManager)(ref entityManager)).Instantiate(mapIconProxyPrefab);
			val.Write<Translation>(new Translation
			{
				Value = value
			});
			val.Add<SpawnedBy>();
			val.Write<SpawnedBy>(new SpawnedBy
			{
				Value = characterEntity
			});
			val.Remove<SyncToUserBitMask>();
			val.Remove<SyncToUserBuffer>();
			val.Remove<OnlySyncToUsersTag>();
			entityManager = Core.EntityManager;
			DynamicBuffer<AttachMapIconsToEntity> buffer = ((EntityManager)(ref entityManager)).GetBuffer<AttachMapIconsToEntity>(val, false);
			buffer.Clear();
			buffer.Add(new AttachMapIconsToEntity
			{
				Prefab = mapIcon
			});
		}

		public bool RemoveMapIcon(Entity characterEntity)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0072: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			float3 pos = characterEntity.Read<Translation>().Value;
			NativeArray<Entity> val = ((EntityQuery)(ref mapIconProxyQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			Entity val2 = ((IEnumerable<Entity>)(from x in ((IEnumerable<Entity>)val.ToArray()).Where(delegate(Entity x)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Unknown result type (might be due to invalid IL or missing references)
					//IL_0009: Unknown result type (might be due to invalid IL or missing references)
					//IL_000e: 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 (x.Has<PrefabGUID>())
					{
						PrefabGUID val3 = x.Read<PrefabGUID>();
						return ((PrefabGUID)(ref val3)).Equals(mapIconProxyPrefabGUID);
					}
					return false;
				})
				orderby math.distance(pos, x.Read<Translation>().Value)
				select x)).FirstOrDefault((Func<Entity, bool>)((Entity x) => math.distance(pos, x.Read<Translation>().Value) < 5f));
			val.Dispose();
			if (val2 == Entity.Null)
			{
				return false;
			}
			EntityManager entityManager;
			if (val2.Has<AttachedBuffer>())
			{
				entityManager = Core.EntityManager;
				DynamicBuffer<AttachedBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<AttachedBuffer>(val2, false);
				for (int i = 0; i < buffer.Length; i++)
				{
					Entity entity = buffer[i].Entity;
					if (!(entity == Entity.Null))
					{
						entityManager = Core.EntityManager;
						((EntityManager)(ref entityManager)).DestroyEntity(entity);
					}
				}
			}
			entityManager = Core.EntityManager;
			((EntityManager)(ref entityManager)).DestroyEntity(val2);
			return true;
		}
	}
	[HarmonyPatch(typeof(MapIconSpawnSystem), "OnUpdate")]
	internal static class MapIconSpawnSystemPatch
	{
		public static void Prefix(MapIconSpawnSystem __instance)
		{
			//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_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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0027: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_006e: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			EntityQuery _query_1050583545_ = __instance.__query_1050583545_0;
			NativeArray<Entity> val = ((EntityQuery)(ref _query_1050583545_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (current.Has<Attach>())
				{
					Entity parent = current.Read<Attach>().Parent;
					if (!((Entity)(ref parent)).Equals(Entity.Null) && parent.Has<SpawnedBy>())
					{
						MapIconData componentData = current.Read<MapIconData>();
						componentData.RequiresReveal = false;
						componentData.AllySetting = (MapIconShowSettings)2;
						componentData.EnemySetting = (MapIconShowSettings)2;
						current.Write<MapIconData>(componentData);
					}
				}
			}
			val.Dispose();
		}
	}
	internal class PortalService
	{
		private Entity portalPrefab;

		private EntityQuery spawnedPortalQuery;

		private Dictionary<Entity, (float3 pos, quaternion rot, TerrainChunk chunk, int index, PrefabGUID mapIcon)> portalStartPos = new Dictionary<Entity, (float3, quaternion, TerrainChunk, int, PrefabGUID)>();

		public PortalService()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_007a: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_009d: 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)
			PrefabGUID val = default(PrefabGUID);
			if (!Core.PrefabCollection._SpawnableNameToPrefabGuidDictionary.TryGetValue("TM_General_Entrance_Gate", ref val))
			{
				Core.Log.LogError((object)"Failed to find TM_General_Entrance_Gate PrefabGUID");
			}
			if (!Core.PrefabCollection._PrefabGuidToEntityMap.TryGetValue(val, ref portalPrefab))
			{
				Core.Log.LogError((object)"Failed to find TM_General_Entrance_Gate Prefab entity");
			}
			EntityQueryBuilder val2 = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
			val2 = ((EntityQueryBuilder)(ref val2)).AddAll(ComponentType.ReadOnly<ChunkPortal>());
			val2 = ((EntityQueryBuilder)(ref val2)).AddAll(ComponentType.ReadOnly<SpawnedBy>());
			EntityQueryBuilder val3 = ((EntityQueryBuilder)(ref val2)).WithOptions((EntityQueryOptions)2);
			EntityManager entityManager = Core.EntityManager;
			spawnedPortalQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val3);
			((EntityQueryBuilder)(ref val3)).Dispose();
		}

		public bool StartPortal(Entity playerEntity, PrefabGUID mapIcon)
		{
			//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_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_000e: 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_0030: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			float3 value = playerEntity.Read<Translation>().Value;
			TerrainChunk val = default(TerrainChunk);
			val.X = (sbyte)((value.x + 3200f) / 160f);
			val.Y = (sbyte)((value.z + 3200f) / 160f);
			TerrainChunk val2 = val;
			int nextAvailableIndex = GetNextAvailableIndex(val2);
			if (nextAvailableIndex >= 9)
			{
				return false;
			}
			portalStartPos[playerEntity] = (value, playerEntity.Read<Rotation>().Value, val2, nextAvailableIndex, mapIcon);
			return true;
		}

		public string EndPortal(Entity playerEntity, PrefabGUID endMapIcon)
		{
			//IL_0006: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0046: 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_0060: 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_0069: 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)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			if (!portalStartPos.TryGetValue(playerEntity, out (float3, quaternion, TerrainChunk, int, PrefabGUID) value))
			{
				return "Start portal hasn't been specified";
			}
			float3 value2 = playerEntity.Read<Translation>().Value;
			TerrainChunk val = default(TerrainChunk);
			val.X = (sbyte)((value2.x + 3200f) / 160f);
			val.Y = (sbyte)((value2.z + 3200f) / 160f);
			TerrainChunk val2 = val;
			int num = GetNextAvailableIndex(val2);
			if (val2 == value.Item3)
			{
				num++;
			}
			if (num >= 9)
			{
				return "Can't have more than 9 portals in a chunk";
			}
			CreatePortal(playerEntity, value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, val2, num);
			quaternion value3 = playerEntity.Read<Rotation>().Value;
			CreatePortal(playerEntity, value2, value3, val2, num, endMapIcon, value.Item3, value.Item4);
			portalStartPos.Remove(playerEntity);
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(15, 4, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Start: ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<TerrainChunk>(value.Item3);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(value.Item4);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" End: ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<TerrainChunk>(val2);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(num);
			}
			log.LogInfo(val3);
			return null;
		}

		private void CreatePortal(Entity creator, float3 pos, quaternion rot, TerrainChunk chunk, int index, PrefabGUID mapIcon, TerrainChunk toChunk, int toIndex)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0014: 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_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_0025: 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_002e: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0069: 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)
			//IL_0070: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			EntityManager entityManager = Core.EntityManager;
			Entity val = ((EntityManager)(ref entityManager)).Instantiate(portalPrefab);
			val.Write<Translation>(new Translation
			{
				Value = pos
			});
			val.Write<Rotation>(new Rotation
			{
				Value = rot
			});
			val.Add<SpawnedBy>();
			val.Write<SpawnedBy>(new SpawnedBy
			{
				Value = creator
			});
			entityManager = Core.EntityManager;
			DynamicBuffer<AttachMapIconsToEntity> buffer = ((EntityManager)(ref entityManager)).GetBuffer<AttachMapIconsToEntity>(val, false);
			buffer.Clear();
			if (!((PrefabGUID)(ref mapIcon)).Equals(PrefabGUID.Empty))
			{
				buffer.Add(new AttachMapIconsToEntity
				{
					Prefab = mapIcon
				});
			}
			val.Write<ChunkPortal>(new ChunkPortal
			{
				FromChunk = chunk,
				FromChunkPortalIndex = index,
				ToChunk = toChunk,
				ToChunkPortalIndex = toIndex
			});
		}

		private int GetNextAvailableIndex(TerrainChunk chunk)
		{
			//IL_0005: 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_000d: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			FixedList512Bytes<ChunkPortalData> val = default(FixedList512Bytes<ChunkPortalData>);
			if (!Core.ChunkObjectManager._ChunkPortals.TryGetValue(chunk, ref val))
			{
				return 0;
			}
			for (int i = 0; i < val.Length; i++)
			{
				if (val[i].PortalEntity == Entity.Null)
				{
					return i;
				}
			}
			return val.Length;
		}

		public bool TeleportToClosestPortal(Entity playerEntity)
		{
			//IL_000d: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0076: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> val = ((EntityQuery)(ref spawnedPortalQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			float3 pos = playerEntity.Read<Translation>().Value;
			Entity val2 = ((IEnumerable<Entity>)val.ToArray()).OrderBy((Entity x) => math.distance(pos, x.Read<Translation>().Value)).FirstOrDefault();
			val.Dispose();
			if (val2 == Entity.Null)
			{
				return false;
			}
			float3 value = val2.Read<Translation>().Value;
			quaternion value2 = val2.Read<Rotation>().Value;
			playerEntity.Write<Translation>(new Translation
			{
				Value = value
			});
			playerEntity.Write<LastTranslation>(new LastTranslation
			{
				Value = value
			});
			playerEntity.Write<Rotation>(new Rotation
			{
				Value = value2
			});
			return true;
		}

		private Entity GetConnectedPortal(ChunkPortal chunkPortal)
		{
			//IL_0005: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			FixedList512Bytes<ChunkPortalData> val = default(FixedList512Bytes<ChunkPortalData>);
			if (!Core.ChunkObjectManager._ChunkPortals.TryGetValue(chunkPortal.ToChunk, ref val))
			{
				return Entity.Null;
			}
			return val[chunkPortal.ToChunkPortalIndex].PortalEntity;
		}

		private void RemovePortalEntry(ChunkPortal chunkPortal)
		{
			//IL_0005: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002d: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_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)
			FixedList512Bytes<ChunkPortalData> val = default(FixedList512Bytes<ChunkPortalData>);
			if (Core.ChunkObjectManager._ChunkPortals.TryGetValue(chunkPortal.FromChunk, ref val))
			{
				val[chunkPortal.FromChunkPortalIndex] = default(ChunkPortalData);
				Core.ChunkObjectManager._ChunkPortals.Remove(chunkPortal.FromChunk);
				Core.ChunkObjectManager._ChunkPortals.Add(chunkPortal.FromChunk, val);
			}
		}

		public bool DestroyPortal(Entity senderCharacterEntity)
		{
			//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)
			//IL_000d: 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_001e: 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_004d: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0071: 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_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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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_016d: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00c6: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			float3 pos = senderCharacterEntity.Read<Translation>().Value;
			NativeArray<Entity> val = ((EntityQuery)(ref spawnedPortalQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			Entity val2 = ((IEnumerable<Entity>)((IEnumerable<Entity>)val.ToArray()).OrderBy((Entity x) => math.distance(pos, x.Read<Translation>().Value))).FirstOrDefault((Func<Entity, bool>)((Entity x) => math.distance(pos, x.Read<Translation>().Value) < 5f));
			val.Dispose();
			if (val2 == Entity.Null)
			{
				return false;
			}
			ChunkPortal chunkPortal = val2.Read<ChunkPortal>();
			Entity connectedPortal = GetConnectedPortal(chunkPortal);
			RemovePortalEntry(chunkPortal);
			EntityManager entityManager;
			if (val2.Has<AttachedBuffer>())
			{
				entityManager = Core.EntityManager;
				DynamicBuffer<AttachedBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<AttachedBuffer>(val2, false);
				for (int i = 0; i < buffer.Length; i++)
				{
					Entity entity = buffer[i].Entity;
					if (!(entity == Entity.Null))
					{
						entityManager = Core.EntityManager;
						((EntityManager)(ref entityManager)).DestroyEntity(entity);
					}
				}
			}
			entityManager = Core.EntityManager;
			((EntityManager)(ref entityManager)).DestroyEntity(val2);
			if (connectedPortal != Entity.Null)
			{
				RemovePortalEntry(connectedPortal.Read<ChunkPortal>());
				if (connectedPortal.Has<AttachedBuffer>())
				{
					entityManager = Core.EntityManager;
					DynamicBuffer<AttachedBuffer> buffer2 = ((EntityManager)(ref entityManager)).GetBuffer<AttachedBuffer>(connectedPortal, false);
					for (int j = 0; j < buffer2.Length; j++)
					{
						Entity entity2 = buffer2[j].Entity;
						if (!(entity2 == Entity.Null))
						{
							entityManager = Core.EntityManager;
							((EntityManager)(ref entityManager)).DestroyEntity(entity2);
						}
					}
				}
				entityManager = Core.EntityManager;
				((EntityManager)(ref entityManager)).DestroyEntity(connectedPortal);
			}
			return true;
		}
	}
	internal class RevealService
	{
		public class PublicRevealZone
		{
			public string Name { get; set; } = "Public Reveal Zone";


			public int X { get; set; }

			public int Y { get; set; }

			public int Radius { get; set; } = 1;

		}

		private readonly List<PublicRevealZone> publicRevealZones = new List<PublicRevealZone>();

		private readonly string currentSaveName;

		private readonly string saveScopedConfigDir;

		private readonly string publicRevealZonesPath;

		public RevealService()
		{
			currentSaveName = GetCurrentSaveName();
			saveScopedConfigDir = Path.Combine(Paths.ConfigPath, "FatedGates", currentSaveName);
			publicRevealZonesPath = Path.Combine(saveScopedConfigDir, "PublicRevealZones.json");
			Directory.CreateDirectory(saveScopedConfigDir);
			LoadPublicRevealZones();
		}

		private void LoadPublicRevealZones()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				if (!File.Exists(publicRevealZonesPath))
				{
					SavePublicRevealZones();
					return;
				}
				List<PublicRevealZone> list = JsonSerializer.Deserialize<List<PublicRevealZone>>(File.ReadAllText(publicRevealZonesPath));
				publicRevealZones.Clear();
				if (list != null)
				{
					publicRevealZones.AddRange(list);
				}
				ManualLogSource log = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(publicRevealZones.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" public reveal zones.");
				}
				log.LogInfo(val);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Core.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load public reveal zones: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val2);
			}
		}

		private void SavePublicRevealZones()
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				string directoryName = Path.GetDirectoryName(publicRevealZonesPath);
				if (!string.IsNullOrEmpty(directoryName))
				{
					Directory.CreateDirectory(directoryName);
				}
				CompactPublicRevealZones();
				string contents = JsonSerializer.Serialize(publicRevealZones, new JsonSerializerOptions
				{
					WriteIndented = true
				});
				File.WriteAllText(publicRevealZonesPath, contents);
				ManualLogSource log = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Saved ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(publicRevealZones.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" public reveal zones.");
				}
				log.LogInfo(val);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Core.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to save public reveal zones: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val2);
			}
		}

		private void CompactPublicRevealZones()
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			if (publicRevealZones.Count <= 1)
			{
				return;
			}
			List<PublicRevealZone> list = (from zone in publicRevealZones
				group zone by new { zone.X, zone.Y }).Select(group =>
			{
				int radius = group.Max((PublicRevealZone zone) => zone.Radius);
				PublicRevealZone publicRevealZone = group.OrderByDescending((PublicRevealZone zone) => zone.Radius).First();
				return new PublicRevealZone
				{
					Name = publicRevealZone.Name,
					X = publicRevealZone.X,
					Y = publicRevealZone.Y,
					Radius = radius
				};
			}).ToList();
			int num = publicRevealZones.Count - list.Count;
			if (num > 0)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(55, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Compacted public reveal zones: removed ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" duplicate entr");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>((num == 1) ? "y" : "ies");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
				}
				log.LogInfo(val);
			}
			publicRevealZones.Clear();
			publicRevealZones.AddRange(list);
		}

		public bool RemovePublicRevealZone(Entity characterEntity, int index, out string message)
		{
			//IL_012a: 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_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			if (publicRevealZones.Count == 0)
			{
				message = "No saved public reveal zones to remove.";
				return false;
			}
			if (index > 0)
			{
				int num = index - 1;
				if (num < 0 || num >= publicRevealZones.Count)
				{
					message = $"Invalid reveal zone index {index}. Use .waygate listrevealzones to see valid indexes.";
					return false;
				}
				PublicRevealZone publicRevealZone = publicRevealZones[num];
				publicRevealZones.RemoveAt(num);
				SavePublicRevealZones();
				message = $"Removed public reveal zone #{index}: {publicRevealZone.Name} at bitmap ({publicRevealZone.X}, {publicRevealZone.Y}), radius {publicRevealZone.Radius}.";
				return true;
			}
			if (!(characterEntity == Entity.Null))
			{
				EntityManager entityManager = Core.EntityManager;
				if (((EntityManager)(ref entityManager)).Exists(characterEntity))
				{
					float3 value = characterEntity.Read<Translation>().Value;
					(int x, int y) tuple = WorldPositionToRevealBitmap(value);
					int item = tuple.x;
					int item2 = tuple.y;
					int num2 = -1;
					float num3 = float.MaxValue;
					for (int i = 0; i < publicRevealZones.Count; i++)
					{
						PublicRevealZone publicRevealZone2 = publicRevealZones[i];
						int num4 = publicRevealZone2.X - item;
						int num5 = publicRevealZone2.Y - item2;
						int num6 = num4 * num4 + num5 * num5;
						if ((float)num6 < num3)
						{
							num3 = num6;
							num2 = i;
						}
					}
					if (num2 < 0)
					{
						message = "Could not find a closest public reveal zone.";
						return false;
					}
					float num7 = math.sqrt(num3);
					if (num7 > 10f)
					{
						message = $"Closest public reveal zone is {num7:F1} bitmap pixels away. Move closer or provide an index.";
						return false;
					}
					PublicRevealZone publicRevealZone3 = publicRevealZones[num2];
					publicRevealZones.RemoveAt(num2);
					SavePublicRevealZones();
					message = $"Removed closest public reveal zone #{num2 + 1}: {publicRevealZone3.Name} at bitmap ({publicRevealZone3.X}, {publicRevealZone3.Y}), radius {publicRevealZone3.Radius}.";
					return true;
				}
			}
			message = "Could not remove closest reveal zone; character entity is invalid.";
			return false;
		}

		public bool RevealMainMapPixelsForUser(Entity userEntity, int centerX, int centerY, int radius)
		{
			//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_000d: 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_0015: 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_0033: 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_004f: 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_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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Invalid comparison between Unknown and I4
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_009f: 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)
			//IL_00be: 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_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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_01d9: Expected O, but got Unknown
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: 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_018c: 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)
			if (!(userEntity == Entity.Null))
			{
				EntityManager entityManager = Core.EntityManager;
				if (((EntityManager)(ref entityManager)).Exists(userEntity))
				{
					entityManager = Core.EntityManager;
					if (!((EntityManager)(ref entityManager)).HasBuffer<UserMapZoneElement>(userEntity))
					{
						Core.Log.LogWarning((object)"Reveal failed; user has no UserMapZoneElement buffer.");
						return false;
					}
					entityManager = Core.EntityManager;
					DynamicBuffer<UserMapZoneElement> buffer = ((EntityManager)(ref entityManager)).GetBuffer<UserMapZoneElement>(userEntity, false);
					bool flag = default(bool);
					for (int i = 0; i < buffer.Length; i++)
					{
						UserMapZoneElement val = buffer[i];
						if ((int)val.MapType != 1)
						{
							continue;
						}
						Entity entityOnServer = ((NetworkedEntity)(ref val.UserZoneEntity)).GetEntityOnServer();
						if (!(entityOnServer == Entity.Null))
						{
							entityManager = Core.EntityManager;
							if (((EntityManager)(ref entityManager)).Exists(entityOnServer))
							{
								entityManager = Core.EntityManager;
								if (!((EntityManager)(ref entityManager)).HasBuffer<UserMapZonePackedRevealElement>(entityOnServer))
								{
									Core.Log.LogWarning((object)"Reveal failed; MainMap zone entity has no reveal buffer.");
									return false;
								}
								entityManager = Core.EntityManager;
								DynamicBuffer<UserMapZonePackedRevealElement> buffer2 = ((EntityManager)(ref entityManager)).GetBuffer<UserMapZonePackedRevealElement>(entityOnServer, false);
								HashSet<int> hashSet = new HashSet<int>();
								for (int j = centerY - radius; j <= centerY + radius; j++)
								{
									for (int k = centerX - radius; k <= centerX + radius; k++)
									{
										if (k < 0 || k >= 256 || j < 0 || j >= 256)
										{
											continue;
										}
										int num = k - centerX;
										int num2 = j - centerY;
										if (num * num + num2 * num2 <= radius * radius)
										{
											int num3 = j * 32 + k / 8;
											int num4 = k % 8;
											byte b = (byte)(1 << num4);
											UserMapZonePackedRevealElement val2 = buffer2[num3];
											byte packedPixel = val2.PackedPixel;
											val2.PackedPixel |= b;
											buffer2[num3] = val2;
											if (packedPixel != val2.PackedPixel)
											{
												hashSet.Add(num3);
											}
										}
									}
								}
								ManualLogSource log = Core.Log;
								BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(65, 5, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Revealed MainMap pixels around (");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(centerX);
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(", ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(centerY);
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(") radius ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(radius);
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" for ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<FixedString64Bytes>(userEntity.Read<User>().CharacterName);
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(". Changed bytes: ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(hashSet.Count);
								}
								log.LogInfo(val3);
								return true;
							}
						}
						Core.Log.LogWarning((object)"Reveal failed; MainMap UserZoneEntity is invalid.");
						return false;
					}
					Core.Log.LogWarning((object)"Reveal failed; no MainMap zone found.");
					return false;
				}
			}
			Core.Log.LogWarning((object)"Reveal failed; user entity is invalid.");
			return false;
		}

		public void AddPublicRevealZone(int x, int y, int radius = 1, string name = "Public Reveal Zone")
		{
			PublicRevealZone item = new PublicRevealZone
			{
				Name = name,
				X = x,
				Y = y,
				Radius = radius
			};
			publicRevealZones.Add(item);
			SavePublicRevealZones();
		}

		public void RevealPublicZoneForUser(Entity userEntity, PublicRevealZone zone)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			RevealMainMapPixelsForUser(userEntity, zone.X, zone.Y, zone.Radius);
		}

		public void RevealAllPublicZonesForUser(Entity userEntity)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			foreach (PublicRevealZone publicRevealZone in publicRevealZones)
			{
				RevealPublicZoneForUser(userEntity, publicRevealZone);
			}
		}

		public (int x, int y) WorldPositionToRevealBitmap(float3 worldPos)
		{
			//IL_0005: 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_0024: 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 = 0.08424167f * worldPos.x + 1.898E-05f * worldPos.z + 242.16705f;
			return new ValueTuple<int, int>(item2: Mathf.RoundToInt(1.13E-05f * worldPos.x + 0.08437769f * worldPos.z + 201.91725f), item1: Mathf.RoundToInt(num));
		}

		public bool AddRevealZoneAtClosestWaygate(Entity characterEntity, int radius = 1)
		{
			//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_000d: 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_0016: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_0103: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			if (!(characterEntity == Entity.Null))
			{
				EntityManager entityManager = Core.EntityManager;
				if (((EntityManager)(ref entityManager)).Exists(characterEntity))
				{
					float3 value = characterEntity.Read<Translation>().Value;
					if (!Core.WaygateService.GetClosestSpawnedWaygate(value, out var closestWaygate, out var distance))
					{
						Core.Log.LogWarning((object)"Could not add reveal zone at closest waygate; no nearby spawned waygate found.");
						return false;
					}
					float3 value2 = closestWaygate.Read<Translation>().Value;
					var (num, num2) = WorldPositionToRevealBitmap(value2);
					AddPublicRevealZone(num, num2, radius, $"Reveal Zone {num},{num2} for a spawned waygate");
					ManualLogSource log = Core.Log;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(111, 7, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Added reveal zone at closest waygate. ");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Waygate world pos X=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(value2.x, "F4");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Y=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(value2.y, "F4");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Z=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(value2.z, "F4");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; ");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("bitmap (");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") radius ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(radius);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; ");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("distance from player ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(distance, "F2");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
					}
					log.LogInfo(val);
					return true;
				}
			}
			Core.Log.LogWarning((object)"Could not add reveal zone at closest waygate; character entity is invalid.");
			return false;
		}

		public string GetPublicRevealZoneListText()
		{
			if (publicRevealZones.Count == 0)
			{
				return "No saved public reveal zones.";
			}
			List<string> list = new List<string> { $"Saved public reveal zones ({publicRevealZones.Count}):" };
			for (int i = 0; i < publicRevealZones.Count; i++)
			{
				PublicRevealZone publicRevealZone = publicRevealZones[i];
				list.Add($"{i + 1}. {publicRevealZone.Name} at bitmap ({publicRevealZone.X}, {publicRevealZone.Y}), radius {publicRevealZone.Radius}");
			}
			return string.Join("\n", list);
		}

		private string GetCurrentSaveName()
		{
			string[] commandLineArgs = Environment.GetCommandLineArgs();
			for (int i = 0; i < commandLineArgs.Length - 1; i++)
			{
				if (string.Equals(commandLineArgs[i], "-saveName", StringComparison.OrdinalIgnoreCase) || string.Equals(commandLineArgs[i], "-serverSaveName", StringComparison.OrdinalIgnoreCase))
				{
					return SanitizeSaveName(commandLineArgs[i + 1]);
				}
			}
			string environmentVariable = Environment.GetEnvironmentVariable("VR_SAVE_NAME");
			if (!string.IsNullOrWhiteSpace(environmentVariable))
			{
				return SanitizeSaveName(environmentVariable);
			}
			Core.Log.LogWarning((object)"Could not determine active save name from command line or VR_SAVE_NAME. Using 'default'.");
			return "default";
		}

		private string SanitizeSaveName(string saveName)
		{
			char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
			foreach (char oldChar in invalidFileNameChars)
			{
				saveName = saveName.Replace(oldChar, '_');
			}
			saveName = saveName.Trim();
			if (!string.IsNullOrWhiteSpace(saveName))
			{
				return saveName;
			}
			return "default";
		}
	}
	internal class WaygateService
	{
		public class PublicWaygate
		{
			public string Name { get; set; } = "Public Waygate";


			public float WorldX { get; set; }

			public float WorldY { get; set; }

			public float WorldZ { get; set; }
		}

		private const float UnlockDistance = 25f;

		private readonly EntityQuery connectedUserQuery;

		private readonly EntityQuery waypointQuery;

		private readonly EntityQuery spawnedWaypointQuery;

		private readonly Dictionary<Entity, List<NetworkId>> unlockedSpawnedWaypoints = new Dictionary<Entity, List<NetworkId>>();

		private readonly HashSet<NetworkId> autoUnlockWaypoints = new HashSet<NetworkId>();

		private readonly string currentSaveName;

		private readonly string saveScopedConfigDir;

		private readonly string publicWaygatesPath;

		private readonly List<PublicWaygate> publicWaygates = new List<PublicWaygate>();

		public WaygateService()
		{
			//IL_0028: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0055: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a5: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00c9: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_00de: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			EntityQueryBuilder val = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
			val = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly<ChunkWaypoint>());
			val = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly<SpawnedBy>());
			EntityQueryBuilder val2 = ((EntityQueryBuilder)(ref val)).WithOptions((EntityQueryOptions)2);
			EntityManager entityManager = Core.EntityManager;
			spawnedWaypointQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val2);
			((EntityQueryBuilder)(ref val2)).Dispose();
			val = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
			val = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly<IsConnected>());
			EntityQueryBuilder val3 = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly<User>());
			entityManager = Core.EntityManager;
			connectedUserQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val3);
			((EntityQueryBuilder)(ref val3)).Dispose();
			val = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
			val = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly<ChunkWaypoint>());
			EntityQueryBuilder val4 = ((EntityQueryBuilder)(ref val)).WithOptions((EntityQueryOptions)2);
			entityManager = Core.EntityManager;
			waypointQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val4);
			((EntityQueryBuilder)(ref val4)).Dispose();
			currentSaveName = GetCurrentSaveName();
			saveScopedConfigDir = Path.Combine(Paths.ConfigPath, "FatedGates", currentSaveName);
			publicWaygatesPath = Path.Combine(saveScopedConfigDir, "PublicWaygates.json");
			Directory.CreateDirectory(saveScopedConfigDir);
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(47, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Using save-scoped FatedGates config directory: ");
				((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(saveScopedConfigDir);
			}
			log.LogInfo(val5);
			LoadPublicWaygates();
			if (!Core.ServerGameSettingsSystem.Settings.AllWaypointsUnlocked)
			{
				Core.StartCoroutine(ResolvePublicWaygatesWhenReady());
				Core.StartCoroutine(CheckForWaypointUnlocks());
			}
		}

		private void LoadPublicWaygates()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				if (!File.Exists(publicWaygatesPath))
				{
					SavePublicWaygates();
					return;
				}
				List<PublicWaygate> list = JsonSerializer.Deserialize<List<PublicWaygate>>(File.ReadAllText(publicWaygatesPath));
				publicWaygates.Clear();
				if (list != null)
				{
					publicWaygates.AddRange(list);
				}
				ManualLogSource log = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(publicWaygates.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" public waygates.");
				}
				log.LogInfo(val);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Core.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(32, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load public waygates: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val2);
			}
		}

		private void SavePublicWaygates()
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				string directoryName = Path.GetDirectoryName(publicWaygatesPath);
				if (!string.IsNullOrEmpty(directoryName))
				{
					Directory.CreateDirectory(directoryName);
				}
				string contents = JsonSerializer.Serialize(publicWaygates, new JsonSerializerOptions
				{
					WriteIndented = true
				});
				File.WriteAllText(publicWaygatesPath, contents);
				ManualLogSource log = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(23, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Saved ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(publicWaygates.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" public waygates.");
				}
				log.LogInfo(val);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Core.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(32, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to save public waygates: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val2);
			}
		}

		public void SavePublicWaygate(Entity waygateEntity, string name = "Public Waygate")
		{
			//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)
			//IL_000d: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			float3 pos = waygateEntity.Read<Translation>().Value;
			bool flag = default(bool);
			if (publicWaygates.Any((PublicWaygate existing) => math.distance(new float3(existing.WorldX, existing.WorldY, existing.WorldZ), pos) < 2f))
			{
				ManualLogSource log = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(48, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Public waygate near X=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(pos.x, "F2");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Y=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(pos.y, "F2");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Z=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(pos.z, "F2");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is already saved.");
				}
				log.LogInfo(val);
			}
			else
			{
				publicWaygates.Add(new PublicWaygate
				{
					Name = name,
					WorldX = pos.x,
					WorldY = pos.y,
					WorldZ = pos.z
				});
				SavePublicWaygates();
				ManualLogSource log2 = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(38, 4, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Saved public waygate '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' at X=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(pos.x, "F2");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Y=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(pos.y, "F2");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Z=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(pos.z, "F2");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
				}
				log2.LogInfo(val);
			}
			NetworkId val2 = waygateEntity.Read<NetworkId>();
			if (val2 != NetworkId.Empty)
			{
				autoUnlockWaypoints.Add(val2);
				UnlockWaypointForAllConnectedUsers(val2);
			}
		}

		private IEnumerator ResolvePublicWaygatesWhenReady()
		{
			if (publicWaygates.Count == 0)
			{
				Core.Log.LogInfo((object)"No saved public waygates to resolve.");
				yield break;
			}
			WaitForSeconds wait = new WaitForSeconds(1f);
			bool flag = default(bool);
			for (int attempt = 1; attempt <= 10; attempt++)
			{
				EntityQuery val = spawnedWaypointQuery;
				NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
				int length = val2.Length;
				val2.Dispose();
				BepInExInfoLogInterpolatedStringHandler val3;
				if (length > 0)
				{
					ManualLogSource log = Core.Log;
					val3 = new BepInExInfoLogInterpolatedStringHandler(68, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Resolving public waygates after ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(attempt);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" attempt(s); spawned waygate count=");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(length);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(".");
					}
					log.LogInfo(val3);
					ResolvePublicWaygates();
					yield break;
				}
				ManualLogSource log2 = Core.Log;
				val3 = new BepInExInfoLogInterpolatedStringHandler(63, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Public waygate resolve attempt ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(attempt);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(": no spawned waygates found yet.");
				}
				log2.LogInfo(val3);
				yield return wait;
			}
			Core.Log.LogWarning((object)"Failed to resolve public waygates: no spawned waygates found after waiting.");
		}

		public void ResolvePublicWaygates()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_008b: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_015b: 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_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Expected O, but got Unknown
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Expected O, but got Unknown
			autoUnlockWaypoints.Clear();
			EntityQuery val = spawnedWaypointQuery;
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			Il2CppArrayBase<Entity> source = val2.ToArray();
			List<PublicWaygate> list = new List<PublicWaygate>();
			bool flag = default(bool);
			try
			{
				foreach (PublicWaygate publicWaygate in publicWaygates)
				{
					float3 savedPos = new float3(publicWaygate.WorldX, publicWaygate.WorldY, publicWaygate.WorldZ);
					Entity val3 = ((IEnumerable<Entity>)source).OrderBy((Entity x) => math.distance(savedPos, x.Read<Translation>().Value)).FirstOrDefault();
					if (val3 == Entity.Null)
					{
						Core.Log.LogWarning((object)("Could not resolve public waygate '" + publicWaygate.Name + "'; no spawned waygates found. Removing stale public waygate entry."));
						list.Add(publicWaygate);
						continue;
					}
					float num = math.distance(savedPos, val3.Read<Translation>().Value);
					if (num > 10f)
					{
						Core.Log.LogWarning((object)($"Could not resolve public waygate '{publicWaygate.Name}'; closest spawned waygate was {num:F2} units away. " + "Removing stale public waygate entry."));
						list.