Decompiled source of NavMeshLib v1.0.0

plugins/NavMeshLib/NavMeshLib.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using DunGen.Adapters;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NavMeshLib.Enums;
using NavMeshLib.Patches;
using Unity.AI.Navigation;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("DunGen")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.ASPP")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.UnityNav")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.CoreUtils")]
[assembly: IgnoresAccessChecksTo("Unity.XR.Management")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.ConformanceAutomation")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MetaQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MockRuntime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.OculusQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.RuntimeDebugger")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SpatialTracking")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("UnityEngine.XR.LegacyInputHelpers")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NavMeshLib")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+085ed5a06313c584a0652ac7b4f47bc066c38e4e")]
[assembly: AssemblyProduct("NavMeshLib")]
[assembly: AssemblyTitle("NavMeshLib")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: TypeForwardedTo(typeof(AllowNullAttribute))]
[assembly: TypeForwardedTo(typeof(DisallowNullAttribute))]
[assembly: TypeForwardedTo(typeof(MaybeNullAttribute))]
[assembly: TypeForwardedTo(typeof(MaybeNullWhenAttribute))]
[assembly: TypeForwardedTo(typeof(NotNullAttribute))]
[assembly: TypeForwardedTo(typeof(NotNullIfNotNullAttribute))]
[assembly: TypeForwardedTo(typeof(NotNullWhenAttribute))]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 NavMeshLib
{
	public static class CustomAgentManager
	{
		public const int DEFAULT_AGENT_ID = 0;

		public const string DEFAULT_AGENT_NAME = "Humanoid";

		public const int INVALID_AGENT_ID = -1;

		private static readonly Dictionary<int, NavMeshBuildSettings> registeredAgents = new Dictionary<int, NavMeshBuildSettings>();

		private static readonly Dictionary<int, string> agentNamesByID = new Dictionary<int, string>();

		private static readonly Dictionary<string, int> agentIDsByName = new Dictionary<string, int>();

		public static IReadOnlyCollection<string> RegisteredAgentNames => agentIDsByName.Keys;

		public static int RegisterCustomAgent(string agentName, in NavMeshBuildSettings agentSettings)
		{
			//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_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_0076: 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_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_00a0: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			if (agentName == "Humanoid")
			{
				throw new ArgumentException("Cannot register custom NavMesh agent '" + agentName + "': that name is reserved for the default agent.", "agentName");
			}
			if (agentIDsByName.ContainsKey(agentName))
			{
				throw new ArgumentException("A custom NavMesh agent named '" + agentName + "' is already registered.", "agentName");
			}
			NavMeshBuildSettings value = NavMesh.CreateSettings();
			int agentTypeID = ((NavMeshBuildSettings)(ref value)).agentTypeID;
			NavMeshBuildSettings val = agentSettings;
			((NavMeshBuildSettings)(ref value)).agentSlope = ((NavMeshBuildSettings)(ref val)).agentSlope;
			val = agentSettings;
			((NavMeshBuildSettings)(ref value)).agentClimb = ((NavMeshBuildSettings)(ref val)).agentClimb;
			val = agentSettings;
			((NavMeshBuildSettings)(ref value)).agentHeight = ((NavMeshBuildSettings)(ref val)).agentHeight;
			val = agentSettings;
			((NavMeshBuildSettings)(ref value)).agentRadius = ((NavMeshBuildSettings)(ref val)).agentRadius;
			val = agentSettings;
			((NavMeshBuildSettings)(ref value)).minRegionArea = ((NavMeshBuildSettings)(ref val)).minRegionArea;
			val = agentSettings;
			((NavMeshBuildSettings)(ref value)).overrideTileSize = ((NavMeshBuildSettings)(ref val)).overrideTileSize;
			val = agentSettings;
			((NavMeshBuildSettings)(ref value)).tileSize = ((NavMeshBuildSettings)(ref val)).tileSize;
			val = agentSettings;
			((NavMeshBuildSettings)(ref value)).overrideVoxelSize = ((NavMeshBuildSettings)(ref val)).overrideVoxelSize;
			val = agentSettings;
			((NavMeshBuildSettings)(ref value)).voxelSize = ((NavMeshBuildSettings)(ref val)).voxelSize;
			registeredAgents.Add(agentTypeID, value);
			agentNamesByID.Add(agentTypeID, agentName);
			agentIDsByName.Add(agentName, agentTypeID);
			return agentTypeID;
		}

		public static void UpdateCustomAgentSettings(int agentTypeID, NavMeshBuildSettings newSettings)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (registeredAgents.ContainsKey(agentTypeID))
			{
				((NavMeshBuildSettings)(ref newSettings)).agentTypeID = agentTypeID;
				registeredAgents[agentTypeID] = newSettings;
			}
		}

		public static void RemoveCustomAgent(int agentTypeID)
		{
			if (registeredAgents.ContainsKey(agentTypeID) || agentNamesByID.ContainsKey(agentTypeID))
			{
				registeredAgents.Remove(agentTypeID);
				if (agentNamesByID.TryGetValue(agentTypeID, out string value))
				{
					agentIDsByName.Remove(value);
				}
				agentNamesByID.Remove(agentTypeID);
				NavMesh.RemoveSettings(agentTypeID);
			}
		}

		public static int GetAgentIDFromSettingsName(string agentName)
		{
			if (agentName == "Humanoid")
			{
				return 0;
			}
			if (!agentIDsByName.TryGetValue(agentName, out var value))
			{
				return -1;
			}
			return value;
		}

		internal static void OverrideNavMeshSettings(ref NavMeshBuildSettings buildSettings)
		{
			//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)
			int agentTypeID = ((NavMeshBuildSettings)(ref buildSettings)).agentTypeID;
			if (registeredAgents.ContainsKey(agentTypeID))
			{
				Plugin.LogDebug($"Overriding NavMeshBuildSettings for custom agent with ID: {agentTypeID}");
				NavMeshBuildSettings val = registeredAgents[agentTypeID];
				((NavMeshBuildSettings)(ref buildSettings)).agentSlope = ((NavMeshBuildSettings)(ref val)).agentSlope;
				((NavMeshBuildSettings)(ref buildSettings)).agentClimb = ((NavMeshBuildSettings)(ref val)).agentClimb;
				((NavMeshBuildSettings)(ref buildSettings)).agentHeight = ((NavMeshBuildSettings)(ref val)).agentHeight;
				((NavMeshBuildSettings)(ref buildSettings)).agentRadius = ((NavMeshBuildSettings)(ref val)).agentRadius;
				((NavMeshBuildSettings)(ref buildSettings)).minRegionArea = ((NavMeshBuildSettings)(ref val)).minRegionArea;
				((NavMeshBuildSettings)(ref buildSettings)).overrideTileSize = ((NavMeshBuildSettings)(ref val)).overrideTileSize;
				((NavMeshBuildSettings)(ref buildSettings)).tileSize = ((NavMeshBuildSettings)(ref val)).tileSize;
				((NavMeshBuildSettings)(ref buildSettings)).overrideVoxelSize = ((NavMeshBuildSettings)(ref val)).overrideVoxelSize;
				((NavMeshBuildSettings)(ref buildSettings)).voxelSize = ((NavMeshBuildSettings)(ref val)).voxelSize;
			}
		}

		internal static void GetSettingsNameFromID(int agentTypeID, ref string agentName)
		{
			if (agentNamesByID.TryGetValue(agentTypeID, out string value))
			{
				agentName = value;
			}
		}
	}
	public static class NavMeshUtil
	{
		public static bool IsValidPathToTarget(Vector3 startPosition, Vector3 endPosition, int areaMask, ref NavMeshPath path, out float pathDistance, bool calculatePathDistance = false, float nearestNavAreaRange = 2.7f, float maxRangeToEnd = 1.5f)
		{
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_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_006e: 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)
			pathDistance = 0f;
			if (!NavMesh.CalculatePath(startPosition, endPosition, areaMask, path))
			{
				return false;
			}
			Vector3[] corners = path.corners;
			if (corners.Length == 0)
			{
				return false;
			}
			Vector3 val = corners[^1] - RoundManager.Instance.GetNavMeshPosition(endPosition, RoundManager.Instance.navHit, nearestNavAreaRange, -1);
			if (((Vector3)(ref val)).sqrMagnitude > maxRangeToEnd * maxRangeToEnd)
			{
				return false;
			}
			if (calculatePathDistance)
			{
				for (int i = 1; i < corners.Length; i++)
				{
					pathDistance += Vector3.Distance(corners[i - 1], corners[i]);
				}
			}
			return true;
		}

		public static bool IsValidPathToTarget(Vector3 startPosition, Vector3 endPosition, NavMeshQueryFilter queryFilter, ref NavMeshPath path, out float pathDistance, bool calculatePathDistance = false, float nearestNavAreaRange = 2.7f, float maxRangeToEnd = 1.5f)
		{
			//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_000a: 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_0034: 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_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_006e: 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)
			pathDistance = 0f;
			if (!NavMesh.CalculatePath(startPosition, endPosition, queryFilter, path))
			{
				return false;
			}
			Vector3[] corners = path.corners;
			if (corners.Length == 0)
			{
				return false;
			}
			Vector3 val = corners[^1] - RoundManager.Instance.GetNavMeshPosition(endPosition, RoundManager.Instance.navHit, nearestNavAreaRange, -1);
			if (((Vector3)(ref val)).sqrMagnitude > maxRangeToEnd * maxRangeToEnd)
			{
				return false;
			}
			if (calculatePathDistance)
			{
				for (int i = 1; i < corners.Length; i++)
				{
					pathDistance += Vector3.Distance(corners[i - 1], corners[i]);
				}
			}
			return true;
		}

		public static bool IsValidPathToTarget(this NavMeshAgent navMeshAgent, Vector3 startPosition, Vector3 endPosition, ref NavMeshPath path, out float pathDistance, bool calculatePathDistance = false, float nearestNavAreaRange = 2.7f, float maxRangeToEnd = 1.5f)
		{
			//IL_0043: 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_006d: 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)
			float[] array = new float[32];
			if (((Behaviour)navMeshAgent).enabled)
			{
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = navMeshAgent.GetAreaCost(i);
				}
			}
			else
			{
				for (int j = 0; j < array.Length; j++)
				{
					array[j] = NavMesh.GetAreaCost(j);
				}
			}
			NavMeshQueryFilter val = default(NavMeshQueryFilter);
			((NavMeshQueryFilter)(ref val)).agentTypeID = navMeshAgent.agentTypeID;
			((NavMeshQueryFilter)(ref val)).areaMask = navMeshAgent.areaMask;
			((NavMeshQueryFilter)(ref val)).costs = array;
			NavMeshQueryFilter queryFilter = val;
			return IsValidPathToTarget(startPosition, endPosition, queryFilter, ref path, out pathDistance, calculatePathDistance, nearestNavAreaRange, maxRangeToEnd);
		}

		public static Vector3 GetNavMeshPosition(this RoundManager roundManager, Vector3 pos, NavMeshQueryFilter queryFilter, NavMeshHit navMeshHit = default(NavMeshHit), float sampleRadius = 5f)
		{
			//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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (NavMesh.SamplePosition(pos, ref navMeshHit, sampleRadius, queryFilter))
			{
				roundManager.GotNavMeshPositionResult = true;
				return ((NavMeshHit)(ref navMeshHit)).position;
			}
			roundManager.GotNavMeshPositionResult = false;
			return pos;
		}

		public static Vector3 GetRandomNavMeshPositionInRadius(this RoundManager roundManager, Vector3 pos, NavMeshQueryFilter queryFilter, float radius = 10f, NavMeshHit navHit = default(NavMeshHit))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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 y = pos.y;
			pos = Random.insideUnitSphere * radius + pos;
			pos.y = y;
			if (NavMesh.SamplePosition(pos, ref navHit, radius, queryFilter))
			{
				return ((NavMeshHit)(ref navHit)).position;
			}
			return pos;
		}

		public static Vector3 GetRandomNavMeshPositionInBoxPredictable(this RoundManager roundManager, Vector3 pos, NavMeshQueryFilter queryFilter, float radius = 10f, NavMeshHit navHit = default(NavMeshHit), Random randomSeed = null, float verticalScale = 1f)
		{
			//IL_0006: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0050: 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_005a: 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_0084: 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)
			RoundManager instance = RoundManager.Instance;
			float y = pos.y;
			float num = instance.RandomNumberInRadius(radius, randomSeed);
			float num2 = instance.RandomNumberInRadius(radius * verticalScale, randomSeed);
			float num3 = instance.RandomNumberInRadius(radius, randomSeed);
			Vector3 val = new Vector3(num, num2, num3) + pos;
			val.y = y;
			roundManager.randomPositionInBoxRadius = val;
			float num4 = Vector3.Distance(pos, val);
			if (NavMesh.SamplePosition(val, ref navHit, num4 + 2f, queryFilter))
			{
				roundManager.GotNavMeshPositionResult = true;
				return ((NavMeshHit)(ref navHit)).position;
			}
			roundManager.GotNavMeshPositionResult = false;
			return pos;
		}

		public static Vector3 GetRandomNavMeshPositionInBoxWithLimits(this RoundManager roundManager, Vector3 pos, NavMeshQueryFilter queryFilter, float minX, float maxX, float minZ, float maxZ, float minY, float maxY, float radius = 10f, NavMeshHit navHit = default(NavMeshHit), Random randomSeed = null, float verticalRange = 3f)
		{
			//IL_0001: 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_0025: 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_0049: 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_00bf: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			minX = Mathf.Max(minX, pos.x - radius);
			minY = Mathf.Max(minY, pos.y - radius);
			minZ = Mathf.Max(minZ, pos.z - radius);
			maxX = Mathf.Min(maxX, pos.x + radius);
			maxY = Mathf.Min(maxY, pos.y + radius);
			maxZ = Mathf.Min(maxZ, pos.z + radius);
			float num = math.remap(0f, 1f, minX, maxX, (float)randomSeed.NextDouble());
			float num2 = math.remap(0f, 1f, minZ, maxZ, (float)randomSeed.NextDouble());
			float num3 = math.remap(0f, 1f, minY, maxY, (float)randomSeed.NextDouble());
			num3 = Mathf.Clamp(num3, pos.y - verticalRange, pos.y + verticalRange);
			Vector3 point = default(Vector3);
			((Vector3)(ref point))..ctor(num, num3, num2);
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(point, Vector3.down, ref val, 5f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				point = ((RaycastHit)(ref val)).point;
			}
			float num4 = Vector3.Distance(pos, point);
			if (NavMesh.SamplePosition(point, ref navHit, num4 + 2f, queryFilter))
			{
				return ((NavMeshHit)(ref navHit)).position;
			}
			return pos;
		}

		public static Vector3 GetRandomNavMeshPositionInBoxPredictable(this RoundManager roundManager, Vector3 center, NavMeshQueryFilter queryFilter, float radiusX = 10f, float radiusY = 10f, float radiusZ = 10f, NavMeshHit navHit = default(NavMeshHit), Random randomSeed = null)
		{
			//IL_0000: 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_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_003f: 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_0058: 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)
			float y = center.y;
			float num = roundManager.RandomNumberInRadius(radiusX, randomSeed);
			float num2 = roundManager.RandomNumberInRadius(radiusY, randomSeed);
			float num3 = roundManager.RandomNumberInRadius(radiusZ, randomSeed);
			Vector3 val = new Vector3(num, num2, num3) + center;
			val.y = y;
			if (NavMesh.SamplePosition(val, ref navHit, 8f, queryFilter))
			{
				return ((NavMeshHit)(ref navHit)).position;
			}
			return Vector3.zero;
		}

		public static Vector3 GetRandomNavMeshPositionInRadiusSpherical(this RoundManager roundManager, Vector3 pos, NavMeshQueryFilter queryFilter, float radius = 10f, NavMeshHit navHit = default(NavMeshHit))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_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_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_007f: 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_0025: 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_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_0044: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			pos = Random.insideUnitSphere * radius + pos;
			if (NavMesh.SamplePosition(pos, ref navHit, radius + 2f, queryFilter))
			{
				Debug.DrawRay(pos + Vector3.forward * 0.01f, Vector3.up * 2f, Color.blue);
				return ((NavMeshHit)(ref navHit)).position;
			}
			Debug.DrawRay(pos + Vector3.forward * 0.01f, Vector3.up * 2f, Color.yellow);
			return pos;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static bool IsValidPathToTarget(this EnemyAI enemyAI, Vector3 startPosition, Vector3 endPosition, ref NavMeshPath path, out float pathDistance, bool calculatePathDistance = false, float nearestNavAreaRange = 2.7f, float maxRangeToEnd = 1.5f)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return enemyAI.agent.IsValidPathToTarget(startPosition, endPosition, ref path, out pathDistance, calculatePathDistance, nearestNavAreaRange, maxRangeToEnd);
		}

		public static void RebakeExteriorNavMesh(GameObject? environmentObject = null, bool generateNewSurfaces = false)
		{
			//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_00e2: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Invalid comparison between Unknown and I4
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: 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)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: 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_0184: Expected O, but got Unknown
			if ((Object)(object)environmentObject == (Object)null)
			{
				environmentObject = GameObject.FindGameObjectWithTag("OutsideLevelNavMesh");
			}
			if ((Object)(object)environmentObject != (Object)null)
			{
				HashSet<NavMeshSurface> hashSet = new HashSet<NavMeshSurface>();
				if (generateNewSurfaces)
				{
					NavMeshSurface component = environmentObject.GetComponent<NavMeshSurface>();
					int settingsCount = NavMesh.GetSettingsCount();
					for (int i = 0; i < settingsCount; i++)
					{
						NavMeshBuildSettings settings = NavMesh.GetSettingsByIndex(i);
						NavMeshSurface val = (from s in environmentObject.GetComponents<NavMeshSurface>()
							where s.agentTypeID == ((NavMeshBuildSettings)(ref settings)).agentTypeID
							select s).FirstOrDefault();
						Plugin.LogDebug($"Checking NavMeshSurface for agent ID {((NavMeshBuildSettings)(ref settings)).agentTypeID} at index {i}. Exterior surface null? {(Object)(object)val == (Object)null}");
						if ((Object)(object)val == (Object)null)
						{
							val = environmentObject.AddComponent<NavMeshSurface>();
							val.agentTypeID = ((NavMeshBuildSettings)(ref settings)).agentTypeID;
							val.defaultArea = component.defaultArea;
							val.useGeometry = component.useGeometry;
							val.collectObjects = component.collectObjects;
							if ((int)component.collectObjects == 1)
							{
								val.center = component.center;
								val.size = component.size;
							}
							val.layerMask = component.layerMask;
							val.minRegionArea = component.minRegionArea;
							NavMeshData navMeshData = val.navMeshData;
							if ((Object)(object)navMeshData == (Object)null)
							{
								NavMeshBuildSettings buildSettings = val.GetBuildSettings();
								navMeshData = new NavMeshData(((NavMeshBuildSettings)(ref buildSettings)).agentTypeID)
								{
									position = ((Component)val).transform.position,
									rotation = ((Component)val).transform.rotation
								};
								val.navMeshData = navMeshData;
							}
							else
							{
								navMeshData.position = ((Component)val).transform.position;
								navMeshData.rotation = ((Component)val).transform.rotation;
							}
						}
						hashSet.Add(val);
					}
				}
				NavMeshSurface[] array = ((hashSet.Count > 0) ? hashSet.ToArray() : environmentObject.GetComponents<NavMeshSurface>());
				Plugin.LogInfo($"[RebakeExteriorNavMesh] Rebaking {array.Length} surface(s)");
				((MonoBehaviour)RoundManager.Instance).StartCoroutine(UpdateNavMeshDelayed(array));
			}
			else
			{
				Plugin.LogFatal("[RebakeExteriorNavMesh] Failed to find environment object.......this should NEVER happen.");
			}
		}

		public static void RebakeDunGenNavMesh()
		{
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				NavMeshSurface[] array = instance.fullBakeSurfaces.ToArray();
				Plugin.LogInfo($"[RebakeDunGenNavMesh] Rebaking {array.Length} surface(s)");
				((MonoBehaviour)instance).StartCoroutine(UpdateNavMeshDelayed(array));
			}
		}

		public static void BuildNavMeshAsync(this NavMeshSurface navMeshSurface, Action? onBuildCompleted = null, Action<NavMeshSurface>? onSurfaceBuilt = null)
		{
			//IL_0056: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0046: Expected O, but got Unknown
			NavMeshData navMeshData = navMeshSurface.navMeshData;
			if ((Object)(object)navMeshData == (Object)null)
			{
				NavMeshBuildSettings buildSettings = navMeshSurface.GetBuildSettings();
				navMeshData = new NavMeshData(((NavMeshBuildSettings)(ref buildSettings)).agentTypeID)
				{
					position = ((Component)navMeshSurface).transform.position,
					rotation = ((Component)navMeshSurface).transform.rotation
				};
				navMeshSurface.navMeshData = navMeshData;
			}
			else
			{
				navMeshData.position = ((Component)navMeshSurface).transform.position;
				navMeshData.rotation = ((Component)navMeshSurface).transform.rotation;
			}
			((MonoBehaviour)navMeshSurface).StartCoroutine(UpdateNavMeshDelayed(navMeshSurface, onBuildCompleted, onSurfaceBuilt));
		}

		public static IEnumerator UpdateNavMeshDelayed(NavMeshSurface[] surfacesToUpdate, Action? onBuildCompleted = null, Action<NavMeshSurface>? onSurfaceBuilt = null)
		{
			yield return null;
			AdjacentRoomCullingModified roomCullingModified = StartOfRound.Instance.occlusionCuller;
			bool wasEnabled = ((Behaviour)roomCullingModified).enabled;
			foreach (NavMeshSurface navMeshSurface in surfacesToUpdate)
			{
				if ((Object)(object)navMeshSurface != (Object)null)
				{
					Plugin.LogInfo($"Updating NavMesh for surface {navMeshSurface}.");
					if ((Object)(object)roomCullingModified != (Object)null && ((Behaviour)roomCullingModified).enabled)
					{
						wasEnabled = true;
						((Behaviour)roomCullingModified).enabled = false;
					}
					AsyncOperation asyncOperation = navMeshSurface.UpdateNavMesh(navMeshSurface.navMeshData);
					while (asyncOperation != null && !asyncOperation.isDone)
					{
						Plugin.LogDebug($"{navMeshSurface} Rebuild Progress {asyncOperation.progress * 100f}%");
						yield return null;
					}
					Plugin.LogInfo($"{navMeshSurface} UpdateNavMesh finished, refreshing surface data.");
					((Object)navMeshSurface.navMeshData).name = ((Object)((Component)navMeshSurface).gameObject).name;
					navMeshSurface.RemoveData();
					Plugin.LogDebug("Removed existing data.");
					if (((Behaviour)navMeshSurface).isActiveAndEnabled)
					{
						navMeshSurface.AddData();
						Plugin.LogDebug("Added updated data.");
					}
					onSurfaceBuilt?.Invoke(navMeshSurface);
				}
			}
			if (roomCullingModified == null)
			{
				roomCullingModified = StartOfRound.Instance.occlusionCuller;
			}
			if ((Object)(object)roomCullingModified != (Object)null && ((Behaviour)roomCullingModified).enabled != wasEnabled)
			{
				((Behaviour)roomCullingModified).enabled = wasEnabled;
			}
			onBuildCompleted?.Invoke();
			Plugin.LogInfo($"Updated {surfacesToUpdate.Length} NavMeshe(s).");
		}

		private static IEnumerator UpdateNavMeshDelayed(NavMeshSurface surfaceToUpdate, Action? onBuildCompleted = null, Action<NavMeshSurface>? onSurfaceBuilt = null)
		{
			yield return null;
			AdjacentRoomCullingModified roomCullingModified = StartOfRound.Instance.occlusionCuller;
			bool wasEnabled = ((Behaviour)roomCullingModified).enabled;
			if ((Object)(object)surfaceToUpdate != (Object)null)
			{
				Plugin.LogInfo($"Updating NavMesh for surface {surfaceToUpdate}.");
				if ((Object)(object)roomCullingModified != (Object)null && ((Behaviour)roomCullingModified).enabled)
				{
					wasEnabled = true;
					((Behaviour)roomCullingModified).enabled = false;
				}
				AsyncOperation asyncOperation = surfaceToUpdate.UpdateNavMesh(surfaceToUpdate.navMeshData);
				while (asyncOperation != null && !asyncOperation.isDone)
				{
					Plugin.LogDebug($"{surfaceToUpdate} Rebuild Progress {asyncOperation.progress * 100f}%");
					yield return null;
				}
				Plugin.LogInfo($"{surfaceToUpdate} UpdateNavMesh finished, refreshing surface data.");
				((Object)surfaceToUpdate.navMeshData).name = ((Object)((Component)surfaceToUpdate).gameObject).name;
				surfaceToUpdate.RemoveData();
				Plugin.LogDebug("Removed existing data.");
				if (((Behaviour)surfaceToUpdate).isActiveAndEnabled)
				{
					surfaceToUpdate.AddData();
					Plugin.LogDebug("Added updated data.");
				}
				onSurfaceBuilt?.Invoke(surfaceToUpdate);
			}
			if (roomCullingModified == null)
			{
				roomCullingModified = StartOfRound.Instance.occlusionCuller;
			}
			if ((Object)(object)roomCullingModified != (Object)null && ((Behaviour)roomCullingModified).enabled != wasEnabled)
			{
				((Behaviour)roomCullingModified).enabled = wasEnabled;
			}
			onBuildCompleted?.Invoke();
			Plugin.LogInfo($"Finished updating {surfaceToUpdate}.");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "T-Rizzle.NavMeshLib";

		public const string PLUGIN_NAME = "NavMeshLib";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("T-Rizzle.NavMeshLib", "NavMeshLib", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private readonly Harmony _harmony = new Harmony("T-Rizzle.NavMeshLib");

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			LogInfo("Loading Required Patches");
			PatchClass<NavMeshPatch>();
			PatchClass<RoundManagerPatch>();
			PatchClass<UnityNavMeshAdapterPatch>();
			LogInfo("Plugin T-Rizzle.NavMeshLib is loaded!");
		}

		private void PatchClass<T>() where T : class
		{
			try
			{
				LogDebug($"Patching {typeof(T)}");
				_harmony.PatchAll(typeof(T));
			}
			catch (Exception arg)
			{
				LogError($"An error occured while patching {typeof(T)}: {arg}");
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogDebug(string debugLog)
		{
			Logger.LogDebug((object)debugLog);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogInfo(string infoLog)
		{
			Logger.LogInfo((object)infoLog);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogWarning(string warningLog)
		{
			Logger.LogWarning((object)warningLog);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogError(string errorLog)
		{
			Logger.LogError((object)errorLog);
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogFatal(string fatalLog)
		{
			Logger.LogFatal((object)fatalLog);
		}
	}
}
namespace NavMeshLib.Patches
{
	[HarmonyPatch(typeof(NavMesh))]
	public class NavMeshPatch
	{
		[HarmonyPatch("GetSettingsByID")]
		[HarmonyPostfix]
		public static void GetSettingsByID_Postfix(ref NavMeshBuildSettings __result)
		{
			Plugin.LogDebug($"GetSettingsByID returned settings with ID: {((NavMeshBuildSettings)(ref __result)).agentTypeID}");
			CustomAgentManager.OverrideNavMeshSettings(ref __result);
		}

		[HarmonyPatch("GetSettingsByIndex")]
		[HarmonyPostfix]
		public static void GetSettingsByIndex_Postfix(ref NavMeshBuildSettings __result)
		{
			Plugin.LogDebug($"GetSettingsByIndex returned settings with ID: {((NavMeshBuildSettings)(ref __result)).agentTypeID}");
			CustomAgentManager.OverrideNavMeshSettings(ref __result);
		}

		[HarmonyPatch("GetSettingsNameFromID")]
		[HarmonyPostfix]
		public static void GetSettingsNameFromID_Postfix(int agentTypeID, ref string __result)
		{
			Plugin.LogDebug("GetSettingsNameFromID returned name for agent with ID: " + __result);
			CustomAgentManager.GetSettingsNameFromID(agentTypeID, ref __result);
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	public class RoundManagerPatch
	{
		[HarmonyPatch("BakeDunGenNavMesh")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> BakeDunGenNavMesh_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			int num = -1;
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(NavMeshSurface), "BuildNavMesh", (Type[])null, (Type[])null);
			for (int i = 0; i < list.Count - 1; i++)
			{
				if ((list[i].opcode == OpCodes.Ldloc || list[i].opcode == OpCodes.Ldloc_S) && list[i].operand is LocalBuilder { LocalIndex: 6 } && CodeInstructionExtensions.Calls(list[i + 1], methodInfo))
				{
					num = i;
					break;
				}
			}
			if (num > -1)
			{
				list[num + 1].opcode = OpCodes.Call;
				list[num + 1].operand = AccessTools.Method(typeof(RoundManagerPatch), "BuildInteriorNavMesh", (Type[])null, (Type[])null);
				num = -1;
			}
			else
			{
				Plugin.LogError("NavMeshLib.Patches.RoundManagerPatch.BakeDunGenNavMesh_Transpiler could not change interior NavMesh generation to be asynchronous!");
			}
			return list.AsEnumerable();
		}

		[HarmonyPatch("SpawnOutsideHazards")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> SpawnOutsideHazards_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			int num = -1;
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(NavMeshSurface), "BuildNavMesh", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(GameObject), "GetComponent", (Type[])null, new Type[1] { typeof(NavMeshSurface) });
			for (int i = 0; i < list.Count - 2; i++)
			{
				if ((list[i].opcode == OpCodes.Ldloc || list[i].opcode == OpCodes.Ldloc_S) && list[i].operand is LocalBuilder { LocalIndex: 26 } && CodeInstructionExtensions.Calls(list[i + 1], methodInfo2) && CodeInstructionExtensions.Calls(list[i + 2], methodInfo))
				{
					num = i;
					break;
				}
			}
			if (num > -1)
			{
				for (int j = 0; j <= 2; j++)
				{
					list[num + j].opcode = OpCodes.Nop;
					list[num + j].operand = null;
				}
				num = -1;
			}
			else
			{
				Plugin.LogError("NavMeshLib.Patches.RoundManagerPatch.SpawnOutsideHazards_Transpiler could not change exterior NavMesh generation to be asynchronous!");
			}
			return list.AsEnumerable();
		}

		[HarmonyPatch("SpawnOutsideHazards")]
		[HarmonyPostfix]
		private static void SpawnOutsideHazards_Postfix()
		{
			Plugin.LogInfo("[SpawnOutsideHazards] Starting Async NavMesh Generation for exterior.");
			NavMeshUtil.RebakeExteriorNavMesh(null, generateNewSurfaces: true);
		}

		internal static void BuildInteriorNavMesh(NavMeshSurface navMeshSurface)
		{
			Plugin.LogInfo($"[BuildInteriorNavMesh] Starting Async NavMesh Generation for interior surface {navMeshSurface} with agent ID {navMeshSurface.agentTypeID}");
			navMeshSurface.BuildNavMeshAsync();
		}
	}
	[HarmonyPatch(typeof(UnityNavMeshAdapter))]
	public class UnityNavMeshAdapterPatch
	{
		[HarmonyPatch("BakeFullDungeon")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> BakeFullDungeon_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			int num = -1;
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(NavMeshSurface), "BuildNavMesh", (Type[])null, (Type[])null);
			for (int i = 0; i < list.Count - 1; i++)
			{
				if ((list[i].opcode == OpCodes.Ldloc || list[i].opcode == OpCodes.Ldloc_S) && list[i].operand is LocalBuilder { LocalIndex: 5 } && CodeInstructionExtensions.Calls(list[i + 1], methodInfo))
				{
					num = i;
					break;
				}
			}
			if (num > -1)
			{
				list[num + 1].opcode = OpCodes.Call;
				list[num + 1].operand = AccessTools.Method(typeof(RoundManagerPatch), "BuildInteriorNavMesh", (Type[])null, (Type[])null);
				num = -1;
			}
			else
			{
				Plugin.LogError("NavMeshLib.Patches.UnityNavMeshAdapterPatch.BakeFullDungeon_Transpiler could not change interior NavMesh generation to be asynchronous!");
			}
			return list.AsEnumerable();
		}

		[HarmonyPatch("Generate")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Generate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			int num = -1;
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(NavMeshSurface), "BuildNavMesh", (Type[])null, (Type[])null);
			for (int i = 0; i < list.Count - 2; i++)
			{
				if ((list[i].opcode == OpCodes.Ldloc || list[i].opcode == OpCodes.Ldloc_S) && list[i].operand is LocalBuilder { LocalIndex: 5 } && CodeInstructionExtensions.Calls(list[i + 2], methodInfo))
				{
					num = i;
					break;
				}
			}
			if (num > -1)
			{
				list[num + 2].opcode = OpCodes.Call;
				list[num + 2].operand = AccessTools.Method(typeof(RoundManagerPatch), "BuildInteriorNavMesh", (Type[])null, (Type[])null);
				num = -1;
			}
			else
			{
				Plugin.LogError("NavMeshLib.Patches.UnityNavMeshAdapterPatch.Generate_Transpiler could not change interior NavMesh generation to be asynchronous!");
			}
			return list.AsEnumerable();
		}
	}
}
namespace NavMeshLib.Enums
{
	public enum RebuildType
	{
		AllSurfaces,
		ActiveSurfaces,
		OutsideSurfaces,
		InsideSurfaces,
		Custom
	}
}
namespace NavMeshLib.Editor
{
	public class CustomNavMeshAgentHelper : MonoBehaviour
	{
		[Tooltip("The custom agents' names to use")]
		public string[] agentNames = new string[1] { "Humanoid" };

		[Tooltip("Should this affect child objects as well?")]
		public bool includesChildren;

		[Tooltip("For NavMeshModifier and NavMeshModifierVolume only! Should this override the previously set agent types?")]
		public bool overridePreviousAgentTypes;

		[Tooltip("Should we affect attached NavMeshSurfaces?")]
		public bool updateNavMeshSurfaces = true;

		[Tooltip("Should we affect attached NavMeshModifiers?")]
		public bool updateNavMeshModifiers = true;

		[Tooltip("Should we affect attached NavMeshModifierVolumes?")]
		public bool updateNavMeshModifierVolumes = true;

		[Tooltip("Should we affect attached NavMeshLinks?")]
		public bool updateNavMeshLinks = true;

		private void Awake()
		{
			if (agentNames == null || agentNames.Length == 0)
			{
				Plugin.LogWarning("No custom NavMesh agents were specified for " + ((Object)((Component)this).gameObject).name + ".");
				return;
			}
			List<int> list = new List<int>();
			for (int i = 0; i < agentNames.Length; i++)
			{
				int agentIDFromSettingsName = CustomAgentManager.GetAgentIDFromSettingsName(agentNames[i]);
				if (agentIDFromSettingsName == -1)
				{
					Plugin.LogWarning("Unable to find custom NavMesh agent '" + agentNames[i] + "' for " + ((Object)((Component)this).gameObject).name + ".");
				}
				else
				{
					list.Add(agentIDFromSettingsName);
				}
			}
			if (list.Count == 0)
			{
				Plugin.LogWarning("Unable to find any custom NavMesh agent in 'agentNames' for " + ((Object)((Component)this).gameObject).name + ".");
				return;
			}
			UpdateIfSingleAgent(list);
			NavMeshModifier[] navMeshComponents = GetNavMeshComponents<NavMeshModifier>(updateNavMeshModifiers);
			NavMeshModifierVolume[] navMeshComponents2 = GetNavMeshComponents<NavMeshModifierVolume>(updateNavMeshModifierVolumes);
			foreach (NavMeshModifier val in navMeshComponents)
			{
				if ((Object)(object)val != (Object)null)
				{
					if (overridePreviousAgentTypes)
					{
						List<int> affectedAgents = val.m_AffectedAgents;
						affectedAgents.Clear();
						affectedAgents.AddRange(list);
					}
					else
					{
						HashSet<int> hashSet = val.m_AffectedAgents.ToHashSet();
						hashSet.UnionWith(list);
						val.m_AffectedAgents = hashSet.ToList();
					}
				}
			}
			foreach (NavMeshModifierVolume val2 in navMeshComponents2)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					if (overridePreviousAgentTypes)
					{
						List<int> affectedAgents2 = val2.m_AffectedAgents;
						affectedAgents2.Clear();
						affectedAgents2.AddRange(list);
					}
					else
					{
						HashSet<int> hashSet2 = val2.m_AffectedAgents.ToHashSet();
						hashSet2.UnionWith(list);
						val2.m_AffectedAgents = hashSet2.ToList();
					}
				}
			}
		}

		private void UpdateIfSingleAgent(List<int> agentIDs)
		{
			if (agentIDs.Count != 1)
			{
				if (agentIDs.Count > 1 && (updateNavMeshSurfaces || updateNavMeshLinks))
				{
					Plugin.LogWarning("Multiple custom agents were specified for " + ((Object)((Component)this).gameObject).name + ". \n NavMeshSurface and NavMeshLink components require a single agent type and will not be modified.");
				}
				return;
			}
			int agentTypeID = agentIDs[0];
			NavMeshSurface[] navMeshComponents = GetNavMeshComponents<NavMeshSurface>(updateNavMeshSurfaces);
			NavMeshLink[] navMeshComponents2 = GetNavMeshComponents<NavMeshLink>(updateNavMeshLinks);
			foreach (NavMeshSurface val in navMeshComponents)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.agentTypeID = agentTypeID;
				}
			}
			foreach (NavMeshLink val2 in navMeshComponents2)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					val2.agentTypeID = agentTypeID;
				}
			}
		}

		private T[] GetNavMeshComponents<T>(bool enabled) where T : Component
		{
			if (!enabled)
			{
				return Array.Empty<T>();
			}
			if (!includesChildren)
			{
				return ((Component)this).GetComponents<T>();
			}
			return ((Component)this).GetComponentsInChildren<T>();
		}
	}
	public class NavMeshUpdater : MonoBehaviour
	{
		[Tooltip("What surfaces should be rebuild when UpdateNavMesh is called?")]
		public RebuildType rebuildType;

		[Tooltip("NavMesh surfaces to update when using SelectedSurfaces.")]
		public NavMeshSurface[]? surfacesToUpdate;

		public void UpdateNavMesh()
		{
			//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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			NavMeshSurface[] array;
			switch (rebuildType)
			{
			case RebuildType.OutsideSurfaces:
				NavMeshUtil.RebakeExteriorNavMesh();
				return;
			case RebuildType.InsideSurfaces:
				NavMeshUtil.RebakeDunGenNavMesh();
				return;
			case RebuildType.Custom:
				array = surfacesToUpdate ?? Array.Empty<NavMeshSurface>();
				if (array.Length == 0)
				{
					Plugin.LogWarning("NavMeshUpdater on '" + ((Object)((Component)this).gameObject).name + "' is configured for Custom but has no NavMesh surfaces assigned.");
					return;
				}
				break;
			default:
			{
				FindObjectsInactive val = (FindObjectsInactive)(rebuildType != RebuildType.ActiveSurfaces);
				array = Object.FindObjectsByType<NavMeshSurface>(val, (FindObjectsSortMode)0);
				break;
			}
			}
			foreach (NavMeshSurface val2 in array)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					NavMeshData navMeshData = val2.navMeshData;
					if ((Object)(object)navMeshData == (Object)null)
					{
						NavMeshBuildSettings buildSettings = val2.GetBuildSettings();
						navMeshData = new NavMeshData(((NavMeshBuildSettings)(ref buildSettings)).agentTypeID)
						{
							position = ((Component)val2).transform.position,
							rotation = ((Component)val2).transform.rotation
						};
						val2.navMeshData = navMeshData;
					}
					else
					{
						navMeshData.position = ((Component)val2).transform.position;
						navMeshData.rotation = ((Component)val2).transform.rotation;
					}
				}
			}
			((MonoBehaviour)this).StartCoroutine(NavMeshUtil.UpdateNavMeshDelayed(array));
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
}