Decompiled source of BotsAI v0.5.2

RoundsBots.dll

Decompiled 16 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using InControl;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using RoundsBots.Logic;
using TMPro;
using UnboundLib;
using UnboundLib.GameModes;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("RoundsBots")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.5.2.0")]
[assembly: AssemblyInformationalVersion("0.5.2+1725606c31a7515997730fbd09d53e098c185c0d")]
[assembly: AssemblyProduct("RoundsBots")]
[assembly: AssemblyTitle("RoundsBots")]
[assembly: AssemblyVersion("0.5.2.0")]
[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 RoundsBots
{
	internal sealed class BotAiming
	{
		private const float DefaultBulletGravity = 30f;

		private const float MinBulletSpeed = 5f;

		private const int TrajectorySamples = 14;

		private const float MaxFlightTime = 3f;

		private const float DragSearchDegrees = 45f;

		private const float DragAimTolerance = 0.5f;

		private const float BankSearchInterval = 0.25f;

		private const int BankSamples = 36;

		private const float BankMaxTime = 1f;

		private const float BankHitRadius = 0.9f;

		private static readonly RaycastHit2D[] BankHits = (RaycastHit2D[])(object)new RaycastHit2D[8];

		private static readonly SegmentCast WallCast = BankShot.WithArenaBounds(CastWall, 35.56f, 20f);

		private const float HomingLaunchDistance = 4f;

		private const float HomingMaxAngle = 65f;

		private static readonly float[] HomingAngles = new float[5] { 0f, 25f, -25f, 50f, -50f };

		private float nextBankSearchAt;

		private Vector2? bankDirection;

		private readonly CharacterData data;

		private Player trackedTarget;

		private Vector2 trackedPosition;

		private float trackedTime;

		private Vector2 targetVelocity;

		private Vector2 bulletBoost;

		private float bulletDrag;

		private float bulletDragMinSpeed = 1f;

		private float bulletSimulationSpeed = 1f;

		private const float BulletRadius = 0.3f;

		private const float MaxMuzzleOffset = 2f;

		private int drillCacheCount = -1;

		private float drillCacheMeters;

		private bool UsesDragSim => BulletSim.Needed(bulletDrag, bulletSimulationSpeed);

		public bool HasClearShot { get; private set; }

		public float LastBulletSpeed { get; private set; }

		public float LastBulletGravity { get; private set; }

		public bool LastHomingShot { get; private set; }

		public bool LastBankShot { get; private set; }

		public BotAiming(CharacterData data)
		{
			this.data = data;
		}

		public Vector2 Aim(Vector2 from, Player target, float aimErrorDegrees)
		{
			//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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_0040: 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_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)
			//IL_0081: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_00c1: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_00cb: 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_012c: 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_012f: 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)
			UpdateTargetVelocity(target);
			GetBulletPhysics(out var speed, out var gravity);
			LastBulletSpeed = speed;
			LastBulletGravity = gravity;
			Vector2 position = target.data.playerVel.position;
			Vector2 val = position - from;
			Vector2 val2 = ((Vector2)(ref val)).normalized;
			HasClearShot = false;
			bool[] array = new bool[2] { false, true };
			foreach (bool flag in array)
			{
				if (TrySolve(from, position, speed, gravity, flag, out var direction, out var flightTime))
				{
					if (IsTrajectoryClear(from, direction, speed, gravity, flightTime))
					{
						val2 = direction;
						HasClearShot = true;
						break;
					}
					if (!flag)
					{
						val2 = direction;
					}
				}
			}
			LastBankShot = false;
			LastHomingShot = false;
			if (!HasClearShot && HasHoming() && TryHomingShot(from, position, out var direction2))
			{
				val2 = direction2;
				HasClearShot = true;
				LastHomingShot = true;
			}
			if (!HasClearShot && TryBankShot(from, position, speed, gravity, out var direction3))
			{
				val2 = direction3;
				HasClearShot = true;
				LastBankShot = true;
			}
			Vector2 val3 = Rotate(val2, Random.Range(0f - aimErrorDegrees, aimErrorDegrees));
			if (HasClearShot && !LastBankShot && !LastHomingShot && !IsDirectionClear(from, val3, position, speed, gravity))
			{
				return val2;
			}
			return val3;
		}

		private bool IsDirectionClear(Vector2 from, Vector2 direction, Vector2 targetPosition, float speed, float gravity)
		{
			//IL_002f: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			float flightTime = (UsesDragSim ? BulletSim.ClosestApproach(SimPath(direction, speed, gravity), targetPosition.x - from.x, targetPosition.y - from.y).time : Mathf.Min(BotMath.FlightTime(targetPosition.x - from.x, direction.x, speed), 3f));
			return IsTrajectoryClear(from, direction, speed, gravity, flightTime);
		}

		private bool HasHoming()
		{
			Gun val = (((Object)(object)data.weaponHandler != (Object)null) ? data.weaponHandler.gun : null);
			if ((Object)(object)val == (Object)null || val.objectsToSpawn == null)
			{
				return false;
			}
			ObjectsToSpawn[] objectsToSpawn = val.objectsToSpawn;
			foreach (ObjectsToSpawn val2 in objectsToSpawn)
			{
				if (val2 != null && (Object)(object)val2.AddToProjectile != (Object)null && (Object)(object)val2.AddToProjectile.GetComponentInChildren<Homing>(true) != (Object)null)
				{
					return true;
				}
			}
			return false;
		}

		private static bool TryHomingShot(Vector2 from, Vector2 target, out Vector2 direction)
		{
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0037: 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_0041: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//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_0070: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			direction = Vector2.zero;
			LayerMask canSeePlayerMask = PlayerManager.instance.canSeePlayerMask;
			Vector2 val = target - from;
			Vector2 normalized = ((Vector2)(ref val)).normalized;
			float[] homingAngles = HomingAngles;
			foreach (float degrees in homingAngles)
			{
				Vector2 val2 = Rotate(normalized, degrees);
				Vector2 val3 = from + val2 * 4f;
				if (!IsBlocked(from, val3, canSeePlayerMask) && !IsBlocked(val3, target, canSeePlayerMask) && !(Vector2.Angle(val2, target - val3) > 65f))
				{
					direction = val2;
					return true;
				}
			}
			return false;
		}

		private bool TryBankShot(Vector2 from, Vector2 target, float speed, float gravity, out Vector2 direction)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			direction = Vector2.zero;
			Gun val = (((Object)(object)data.weaponHandler != (Object)null) ? data.weaponHandler.gun : null);
			if ((Object)(object)val == (Object)null || val.reflects <= 0)
			{
				bankDirection = null;
				return false;
			}
			if (Time.time >= nextBankSearchAt)
			{
				nextBankSearchAt = Time.time + 0.25f;
				bankDirection = (BankShot.TryFind(from.x, from.y, speed, gravity, bulletBoost.x, bulletBoost.y, val.reflects, target.x, target.y, 0.9f, 1f, 36, WallCast, out var dirX, out var dirY) ? new Vector2?(new Vector2(dirX, dirY)) : ((Vector2?)null));
			}
			direction = (Vector2)(((??)bankDirection) ?? Vector2.zero);
			return bankDirection.HasValue;
		}

		private static bool CastWall(float ax, float ay, float bx, float by, out float hitX, out float hitY, out float normalX, out float normalY)
		{
			//IL_001c: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00dc: 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)
			hitX = (hitY = (normalX = (normalY = 0f)));
			int num = Physics2D.LinecastNonAlloc(new Vector2(ax, ay), new Vector2(bx, by), BankHits, LayerMask.op_Implicit(PlayerManager.instance.canSeePlayerMask));
			float num2 = float.PositiveInfinity;
			for (int i = 0; i < num; i++)
			{
				RaycastHit2D val = BankHits[i];
				if (!((Object)(object)((RaycastHit2D)(ref val)).collider == (Object)null) && !((RaycastHit2D)(ref val)).collider.isTrigger && !(((RaycastHit2D)(ref val)).distance >= num2))
				{
					Transform root = ((RaycastHit2D)(ref val)).transform.root;
					if (!((Object)(object)((Component)root).GetComponent<Player>() != (Object)null) && !((Object)(object)((Component)root).GetComponent<SpawnedAttack>() != (Object)null))
					{
						num2 = ((RaycastHit2D)(ref val)).distance;
						hitX = ((RaycastHit2D)(ref val)).point.x;
						hitY = ((RaycastHit2D)(ref val)).point.y;
						normalX = ((RaycastHit2D)(ref val)).normal.x;
						normalY = ((RaycastHit2D)(ref val)).normal.y;
					}
				}
			}
			return num2 < float.PositiveInfinity;
		}

		private bool TrySolve(Vector2 from, Vector2 targetPosition, float speed, float gravity, bool highArc, out Vector2 direction, out float flightTime)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_001b: 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_0022: 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_0045: 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_0051: 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_0071: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			direction = Vector2.zero;
			flightTime = 0f;
			Vector2 val = targetPosition;
			for (int i = 0; i < 3; i++)
			{
				Vector2 val2 = val - from;
				if (!BotMath.TryBallisticAim(val2.x, val2.y, speed, gravity, highArc, out var dirX, out var dirY))
				{
					return false;
				}
				direction = new Vector2(dirX, dirY);
				flightTime = Mathf.Min(BotMath.FlightTime(val2.x, dirX, speed), 3f);
				val = targetPosition + (targetVelocity - bulletBoost) * flightTime;
			}
			if (UsesDragSim)
			{
				Vector2 val3 = val - from;
				float baseAngleDeg = Mathf.Atan2(direction.y, direction.x) * 57.29578f;
				if (!BulletSim.TryAim(val3.x, val3.y, speed, gravity, bulletDrag, bulletDragMinSpeed, bulletSimulationSpeed, bulletBoost.x, bulletBoost.y, baseAngleDeg, 45f, 3f, 0.5f, out var dirX2, out var dirY2, out var flightTime2))
				{
					return false;
				}
				direction = new Vector2(dirX2, dirY2);
				flightTime = flightTime2;
			}
			return true;
		}

		private bool IsTrajectoryClear(Vector2 from, Vector2 direction, float speed, float gravity, float flightTime)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: 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_0018: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_003f: 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_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_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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Vector2 val = from + ((Vector2)(ref direction)).normalized * MuzzleOffset();
			Vector2 val2 = new Vector2(0f - direction.y, direction.x);
			Vector2 val3 = ((Vector2)(ref val2)).normalized * 0.3f;
			if (IsSingleTrajectoryClear(val, direction, speed, gravity, flightTime) && IsSingleTrajectoryClear(val + val3, direction, speed, gravity, flightTime))
			{
				return IsSingleTrajectoryClear(val - val3, direction, speed, gravity, flightTime);
			}
			return false;
		}

		private float MuzzleOffset()
		{
			//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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			Gun val = (((Object)(object)data.weaponHandler != (Object)null) ? data.weaponHandler.gun : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val.shootPosition == (Object)null)
			{
				return 0f;
			}
			return Mathf.Min(Vector2.Distance(Vector2.op_Implicit(val.shootPosition.position), Vector2.op_Implicit(((Component)data).transform.position)), 2f);
		}

		private bool IsSingleTrajectoryClear(Vector2 from, Vector2 direction, float speed, float gravity, float flightTime)
		{
			//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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_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_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_005b: 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_008c: 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_0075: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			LayerMask canSeePlayerMask = PlayerManager.instance.canSeePlayerMask;
			float num = DrillMeters();
			float num2 = 0f;
			List<(float, float, float)> path = (UsesDragSim ? SimPath(direction, speed, gravity) : null);
			Vector2 a = from;
			for (int i = 1; i <= 14; i++)
			{
				float t = flightTime * (float)i / 14f;
				Vector2 val = from + Offset(path, direction, speed, gravity, t);
				if (IsBlocked(a, val, canSeePlayerMask))
				{
					num2 += ((num > 0f) ? WallThickness(a, val, canSeePlayerMask) : float.PositiveInfinity);
					if (!BotMath.DrillPierces(num2, num))
					{
						return false;
					}
				}
				a = val;
			}
			return true;
		}

		private List<(float t, float x, float y)> SimPath(Vector2 direction, float speed, float gravity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return BulletSim.Path(direction.x, direction.y, speed, gravity, bulletDrag, bulletDragMinSpeed, bulletSimulationSpeed, bulletBoost.x, bulletBoost.y, 3f);
		}

		private Vector2 Offset(List<(float t, float x, float y)> path, Vector2 direction, float speed, float gravity, float t)
		{
			//IL_0048: 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_006d: 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_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_0042: Unknown result type (might be due to invalid IL or missing references)
			if (path != null && path.Count > 0)
			{
				int index = Mathf.Clamp(Mathf.RoundToInt(t / 0.02f) - 1, 0, path.Count - 1);
				return new Vector2(path[index].x, path[index].y);
			}
			var (num, num2) = BotMath.BulletPosition(direction.x, direction.y, speed, gravity, t);
			return new Vector2(num, num2) + bulletBoost * t;
		}

		private float DrillMeters()
		{
			Gun val = (((Object)(object)data.weaponHandler != (Object)null) ? data.weaponHandler.gun : null);
			if ((Object)(object)val == (Object)null || val.objectsToSpawn == null)
			{
				return 0f;
			}
			if (val.objectsToSpawn.Length != drillCacheCount)
			{
				drillCacheCount = val.objectsToSpawn.Length;
				drillCacheMeters = 0f;
				ObjectsToSpawn[] objectsToSpawn = val.objectsToSpawn;
				foreach (ObjectsToSpawn val2 in objectsToSpawn)
				{
					if (!((Object)(object)val2?.AddToProjectile == (Object)null))
					{
						RayHitDrill[] componentsInChildren = val2.AddToProjectile.GetComponentsInChildren<RayHitDrill>(true);
						foreach (RayHitDrill val3 in componentsInChildren)
						{
							drillCacheMeters += val3.metersOfDrilling;
						}
					}
				}
			}
			return drillCacheMeters;
		}

		private static float WallThickness(Vector2 a, Vector2 b, LayerMask mask)
		{
			//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_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_0011: 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)
			float num = Vector2.Distance(a, b);
			float num2 = FirstSolidDistance(a, b, mask);
			float num3 = FirstSolidDistance(b, a, mask);
			return Mathf.Clamp(num - (float.IsInfinity(num2) ? 0f : num2) - (float.IsInfinity(num3) ? 0f : num3), 0f, num);
		}

		private static float FirstSolidDistance(Vector2 a, Vector2 b, LayerMask mask)
		{
			//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)
			//IL_0008: 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)
			float num = float.PositiveInfinity;
			RaycastHit2D[] array = Physics2D.LinecastAll(a, b, LayerMask.op_Implicit(mask));
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit2D hit = array[i];
				if (IsSolidHit(hit) && ((RaycastHit2D)(ref hit)).distance < num)
				{
					num = ((RaycastHit2D)(ref hit)).distance;
				}
			}
			return num;
		}

		private static bool IsSolidHit(RaycastHit2D hit)
		{
			if ((Object)(object)((RaycastHit2D)(ref hit)).collider == (Object)null || ((RaycastHit2D)(ref hit)).collider.isTrigger)
			{
				return false;
			}
			Transform val = (((Object)(object)((RaycastHit2D)(ref hit)).transform != (Object)null) ? ((RaycastHit2D)(ref hit)).transform.root : null);
			if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).GetComponent<Player>() == (Object)null && (Object)(object)((Component)val).GetComponent<SpawnedAttack>() == (Object)null)
			{
				return !Destructibles.IsDestructible(((RaycastHit2D)(ref hit)).collider);
			}
			return false;
		}

		private static bool IsBlocked(Vector2 a, Vector2 b, LayerMask mask)
		{
			//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_0002: 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)
			RaycastHit2D[] array = Physics2D.LinecastAll(a, b, LayerMask.op_Implicit(mask));
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit2D val = array[i];
				if (!((Object)(object)((RaycastHit2D)(ref val)).collider != (Object)null) || !((RaycastHit2D)(ref val)).collider.isTrigger)
				{
					Transform val2 = (((Object)(object)((RaycastHit2D)(ref val)).transform != (Object)null) ? ((RaycastHit2D)(ref val)).transform.root : null);
					if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).GetComponent<Player>() == (Object)null && (Object)(object)((Component)val2).GetComponent<SpawnedAttack>() == (Object)null && !Destructibles.IsDestructible(((RaycastHit2D)(ref val)).collider))
					{
						return true;
					}
				}
			}
			return false;
		}

		private void GetBulletPhysics(out float speed, out float gravity)
		{
			//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_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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			speed = 0f;
			gravity = 30f;
			bulletBoost = Vector2.zero;
			Gun val = (((Object)(object)data.weaponHandler != (Object)null) ? data.weaponHandler.gun : null);
			MoveTransform val2 = (((Object)(object)val != (Object)null && val.projectiles != null && val.projectiles.Length != 0 && (Object)(object)val.projectiles[0].objectToSpawn != (Object)null) ? val.projectiles[0].objectToSpawn.GetComponent<MoveTransform>() : null);
			if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null)
			{
				speed = ((Vector3)(ref val2.localForce)).magnitude * val.projectileSpeed;
				gravity = val2.gravity * val.gravity;
				bulletBoost = Vector2.op_Implicit(val2.worldForce) * val.gravity;
				bulletDrag = Mathf.Clamp(val.drag, 0f, 45f);
				bulletDragMinSpeed = val.dragMinSpeed;
				bulletSimulationSpeed = val.projectielSimulatonSpeed;
			}
			else
			{
				bulletDrag = 0f;
				bulletDragMinSpeed = 1f;
				bulletSimulationSpeed = 1f;
			}
			if (speed < 5f)
			{
				speed = 5f;
			}
		}

		private void UpdateTargetVelocity(Player target)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007d: 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_0052: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			Vector2 position = target.data.playerVel.position;
			float time = Time.time;
			if ((Object)(object)target != (Object)(object)trackedTarget)
			{
				trackedTarget = target;
				targetVelocity = Vector2.zero;
			}
			else
			{
				float num = time - trackedTime;
				if (num > 0.01f && num < 1f)
				{
					Vector2 val = (position - trackedPosition) / num;
					targetVelocity = Vector2.Lerp(targetVelocity, val, 0.5f);
				}
			}
			trackedPosition = position;
			trackedTime = time;
		}

		private static Vector2 Rotate(Vector2 v, float degrees)
		{
			//IL_0014: 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_0025: 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_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_003e: Unknown result type (might be due to invalid IL or missing references)
			float num = degrees * ((float)Math.PI / 180f);
			float num2 = Mathf.Cos(num);
			float num3 = Mathf.Sin(num);
			Vector2 val = new Vector2(v.x * num2 - v.y * num3, v.x * num3 + v.y * num2);
			return ((Vector2)(ref val)).normalized;
		}
	}
	public sealed class BotBrain : MonoBehaviour
	{
		private const float BulletHitRadius = 2f;

		private const float HomingBulletHitRadius = 4f;

		private const float BlockReactionWindow = 0.3f;

		private const float JumpHoldSeconds = 0.25f;

		private const float CeilingGravityEstimate = 40f;

		private float lastVerticalSpeed;

		private const float BoundsBlockLookAhead = 0.08f;

		private const float DebugLogInterval = 3f;

		private const float ArenaMargin = 10f;

		private const float MinReloadToHide = 0.5f;

		private const float HideFromDistance = 30f;

		private const float RetreatDistance = 30f;

		private const float BreakableProbeDistance = 3f;

		private const float CloseBlockDistance = 4f;

		private const float LoadoutRefreshSeconds = 1f;

		private const float CloseBlockInterval = 2.5f;

		private const int MaxShotsPerObstacle = 6;

		private const float MovableJumpDistance = 1.5f;

		private static readonly string[] VanillaAiTypes = new string[6] { "PlayerAI", "PlayerAIPhilip", "PlayerAIDavid", "PlayerAIPetter", "PlayerAIWilhelm", "PlayerAIZorro" };

		private CharacterData data;

		private BotAiming aiming;

		private BotNavigation navigation;

		private BotLoadout loadout;

		private readonly BotCover cover = new BotCover();

		private int closeRangeEffects;

		private float loadoutRefreshAt;

		private bool wasDead;

		private float lastClearShotAt;

		private float? clearShotSince;

		private bool approaching;

		private string stalemateReason;

		private Player routeOverride;

		private float? noRouteSince;

		private float nextRouteCheckAt;

		private float aliveSince;

		private float nextCloseBlockAt;

		private Vector2 obstaclePoint;

		private int obstacleShots;

		private float thinkTimer;

		private float jumpHoldTimer;

		private Vector2 moveDirection;

		private Vector2 aimDirection = Vector2.right;

		private bool shooting;

		private bool wasShooting;

		private bool pendingJump;

		private bool pendingBlock;

		private Vector2 lastFramePosition;

		private float nextDebugLogAt;

		private bool couldActLastFrame;

		private readonly LoopDetector loopDetector = new LoopDetector();

		private float nextLoopSampleAt;

		private const float LoopSampleSeconds = 0.5f;

		private const float LoopMinTargetDistance = 10f;

		private const float StuckBeforeDeathSeconds = 2f;

		private const float RouteCheckInterval = 2f;

		private bool IsVariantB => DeathCause.IsVariantB(data.player.playerID, DamageTracker.MatchIndex);

		private string Variant
		{
			get
			{
				if (Plugin.Experiment.Value != BotExperiment.None)
				{
					if (!IsVariantB)
					{
						return "A";
					}
					return "B";
				}
				return "-";
			}
		}

		public bool LastCanSee { get; private set; }

		public bool LastClearShot { get; private set; }

		public static bool IsBot(Player player)
		{
			if ((Object)(object)player != (Object)null)
			{
				return (Object)(object)((Component)player).GetComponent<BotBrain>() != (Object)null;
			}
			return false;
		}

		private void Awake()
		{
			data = ((Component)this).GetComponent<CharacterData>();
			aiming = new BotAiming(data);
			navigation = new BotNavigation(data);
		}

		private void Start()
		{
			//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)
			DisableVanillaAi();
			loadout = new BotLoadout(data);
			lastFramePosition = Vector2.op_Implicit(((Component)this).transform.position);
			Plugin.Log.LogInfo((object)$"Bot brain attached to player {data.player.playerID} (team {data.player.teamID}).");
		}

		private void Update()
		{
			//IL_004c: 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_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_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_0079: 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_0086: 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_0158: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)data == (Object)null || (Object)(object)data.view == (Object)null || !data.view.IsMine)
			{
				return;
			}
			GeneralInput input = data.input;
			input.ResetInput();
			Vector2 val = Vector2.op_Implicit(((Component)this).transform.position);
			Vector2 val2 = (val - lastFramePosition) / Mathf.Max(Time.deltaTime, 0.0001f);
			lastVerticalSpeed = val2.y;
			lastFramePosition = val;
			ReportDeath();
			bool flag = CanAct();
			if (flag && !couldActLastFrame)
			{
				aliveSince = Time.time;
				lastClearShotAt = Time.time;
				approaching = false;
				routeOverride = null;
				noRouteSince = null;
				NavMap.Invalidate();
			}
			couldActLastFrame = flag;
			if (!flag)
			{
				navigation.Reset();
				shooting = false;
				wasShooting = false;
				jumpHoldTimer = 0f;
				return;
			}
			BotSettings settings = Plugin.Settings;
			thinkTimer -= Time.deltaTime;
			if (thinkTimer <= 0f)
			{
				thinkTimer = settings.ThinkInterval * Random.Range(0.8f, 1.2f);
				Think(settings);
			}
			if (BotMath.WillHitArenaBounds(val.x, val.y, val2.x, val2.y, 0.08f) && (Object)(object)data.block != (Object)null && !data.block.IsOnCD())
			{
				pendingBlock = true;
			}
			ApplyInput(input);
		}

		private void OnDisable()
		{
			if ((Object)(object)data != (Object)null && data.dead && !wasDead)
			{
				ReportDeath();
			}
		}

		private void ApplyInput(GeneralInput input)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			input.direction = Vector2.op_Implicit(moveDirection);
			input.aimDirection = Vector2.op_Implicit(aimDirection);
			bool flag = (input.shootWasPressed = (input.shootIsPressed = shooting && !input.silencedInput));
			input.shootWasReleased = wasShooting && !flag;
			wasShooting = flag;
			bool flag2 = false;
			if (pendingJump && BotMath.JumpWouldHitCeiling(((Component)this).transform.position.y))
			{
				flag2 = true;
				pendingJump = !BotMath.JumpWouldHitCeiling(((Component)this).transform.position.y, 3f);
			}
			if (jumpHoldTimer > 0f && BotMath.ShouldReleaseJump(((Component)this).transform.position.y, lastVerticalSpeed, 40f))
			{
				jumpHoldTimer = 0f;
			}
			if (pendingJump)
			{
				input.jumpWasPressed = true;
				jumpHoldTimer = (flag2 ? 0f : 0.25f);
				pendingJump = false;
			}
			if (jumpHoldTimer > 0f)
			{
				input.jumpIsPressed = true;
				jumpHoldTimer -= Time.deltaTime;
			}
			if (pendingBlock && !input.silencedInput)
			{
				input.shieldWasPressed = true;
			}
			pendingBlock = false;
		}

		private bool CanAct()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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)
			Vector2 val = Vector2.op_Implicit(((Component)this).transform.position);
			if (Mathf.Abs(val.x) < 45.56f && Mathf.Abs(val.y) < 30f && data.isPlaying && !data.dead && !data.isStunned && !data.input.stunnedInput)
			{
				return !GameManager.lockInput;
			}
			return false;
		}

		private void Think(BotSettings settings)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0045: 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_004b: 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_0065: 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_0072: 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_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_0131: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = Vector2.op_Implicit(((Component)this).transform.position);
			Player val2 = FindTarget(val);
			if ((Object)(object)val2 == (Object)null)
			{
				moveDirection = Vector2.zero;
				shooting = false;
				return;
			}
			Vector2 val3 = val2.data.playerVel.position - val;
			bool canSee = PlayerManager.instance.CanSeePlayer(val, val2).canSee;
			aimDirection = aiming.Aim(val, val2, settings.AimErrorDegrees);
			shooting = aiming.HasClearShot && Random.value < settings.ShootChance;
			canSee |= aiming.HasClearShot && !aiming.LastBankShot && !aiming.LastHomingShot;
			settings = AdaptToLoadout(settings);
			settings = BreakStalemate(settings, ref canSee);
			float num = loadout.ReloadRemaining();
			bool flag = !IsDisabled(BotExperiment.NoHide) && num > 0.5f && (canSee || cover.Current.HasValue) && ((Vector2)(ref val3)).magnitude < 30f;
			int num2;
			bool flag2;
			if (flag)
			{
				(num2, flag2) = Hide(val, val3, val2, settings);
			}
			else
			{
				(num2, flag2) = navigation.Decide(val, val3, canSee, settings);
			}
			if (!flag)
			{
				cover.Clear();
			}
			moveDirection = new Vector2((float)num2, 0f);
			pendingJump |= flag2;
			if (!IsDisabled(BotExperiment.NoBreakObstacles))
			{
				HandleObstacleAhead(val, num2, !aiming.HasClearShot && num <= 0f);
			}
			UpdateBlock(val, settings);
			if (closeRangeEffects > 0 && !IsDisabled(BotExperiment.NoCloseBlock) && canSee && ((Vector2)(ref val3)).magnitude < 4f && Time.time >= nextCloseBlockAt && !pendingBlock && Random.value < settings.BlockChance && (Object)(object)data.block != (Object)null && !data.block.IsOnCD())
			{
				pendingBlock = true;
				nextCloseBlockAt = Time.time + 2.5f;
			}
			LastCanSee = canSee;
			LastClearShot = aiming.HasClearShot;
			TrackRouteLoop(val, val3);
			if (Time.time >= nextDebugLogAt)
			{
				nextDebugLogAt = Time.time + 3f;
				string text = $"Bot {data.player.playerID}: pos={val:F1} toTarget={val3:F1} canSee={canSee} clearShot={aiming.HasClearShot} ";
				string text2 = $"bullet(speed={aiming.LastBulletSpeed:F0}, g={aiming.LastBulletGravity:F0}) bank={aiming.LastBankShot} homing={aiming.LastHomingShot} move={num2} path={navigation.LastPathLength} grounded={data.isGrounded} wall={data.isWallGrab} ";
				object[] obj = new object[5] { settings.PreferredDistance, closeRangeEffects, num, flag, null };
				Vector2? current = cover.Current;
				object obj2;
				if (!current.HasValue)
				{
					obj2 = null;
				}
				else
				{
					Vector2 valueOrDefault = current.GetValueOrDefault();
					obj2 = ((Vector2)(ref valueOrDefault)).ToString("F1");
				}
				if (obj2 == null)
				{
					obj2 = "-";
				}
				obj[4] = obj2;
				BotLog.Write(text + text2 + string.Format("dist={0:F0} close={1} reload={2:F1} hide={3} cover={4}", obj));
			}
		}

		private void TrackRouteLoop(Vector2 myPosition, Vector2 toTarget)
		{
			//IL_0051: 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_0099: 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)
			if (aiming.HasClearShot || ((Vector2)(ref toTarget)).magnitude < 10f)
			{
				loopDetector.Clear();
			}
			else if (!(Time.time < nextLoopSampleAt))
			{
				nextLoopSampleAt = Time.time + 0.5f;
				loopDetector.Add(Time.time, myPosition.x, myPosition.y);
				if (loopDetector.IsLooping(Time.time))
				{
					BotLog.Write($"ROUTE_LOOP bot={data.player.playerID} pos={myPosition:F1} toTarget={toTarget:F1} {navigation.DescribePlan()}");
					loopDetector.Clear();
				}
			}
		}

		private BotSettings BreakStalemate(BotSettings settings, ref bool canSee)
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			float time = Time.time;
			if (aiming.HasClearShot)
			{
				lastClearShotAt = time;
				clearShotSince = clearShotSince ?? time;
			}
			else
			{
				clearShotSince = null;
			}
			if (Stalemate.ShouldApproach(canSee, time - lastClearShotAt))
			{
				approaching = true;
			}
			else if (approaching && clearShotSince.HasValue && time - clearShotSince.Value >= 0.5f)
			{
				approaching = false;
			}
			float num = time - DamageTracker.LastDamageAt;
			string text = (((Object)(object)routeOverride != (Object)null) ? "noPath" : ((!approaching) ? null : ((num > 5f) ? "quiet" : "noShot")));
			if (text != stalemateReason)
			{
				Vector2 val = Vector2.op_Implicit(((Component)this).transform.position);
				string text2 = ((text != null) ? ("enter=" + text) : ("exit=" + stalemateReason));
				BotLog.Write(FormattableString.Invariant($"STALEMATE bot={data.player.playerID} {text2} quiet={num:F0} pos=({val.x:F1},{val.y:F1})"));
				stalemateReason = text;
			}
			float num2 = Stalemate.PreferredDistance(settings.PreferredDistance, num);
			if (!approaching)
			{
				if (!Mathf.Approximately(num2, settings.PreferredDistance))
				{
					return settings.WithPreferredDistance(num2);
				}
				return settings;
			}
			canSee = false;
			if (!Mathf.Approximately(num2, settings.PreferredDistance))
			{
				return settings.WithPreferredDistance(num2);
			}
			return settings;
		}

		private BotSettings AdaptToLoadout(BotSettings settings)
		{
			if (IsDisabled(BotExperiment.NoLoadoutDistance))
			{
				return settings;
			}
			if (Time.time >= loadoutRefreshAt)
			{
				loadoutRefreshAt = Time.time + 1f;
				closeRangeEffects = loadout.CloseRangeEffects;
			}
			float num = BotMath.PreferredDistance(settings.PreferredDistance, loadout.BulletRange(aiming.LastBulletSpeed), closeRangeEffects);
			if (!Mathf.Approximately(num, settings.PreferredDistance))
			{
				return settings.WithPreferredDistance(num);
			}
			return settings;
		}

		private (int horizontal, bool jump) Hide(Vector2 myPosition, Vector2 toTarget, Player target, BotSettings settings)
		{
			//IL_0006: 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_001d: 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_0026: 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)
			Vector2? val = cover.Find(myPosition, target);
			if (val.HasValue)
			{
				var (num, flag) = navigation.MoveTo(myPosition, val.Value - myPosition);
				if (num != 0 || flag || Vector2.Distance(val.Value, myPosition) < 1f)
				{
					return (horizontal: num, jump: flag);
				}
				return (horizontal: 0, jump: false);
			}
			return navigation.Decide(myPosition, toTarget, canSee: true, settings.WithPreferredDistance(30f));
		}

		private void HandleObstacleAhead(Vector2 myPosition, int horizontal, bool canShoot)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0019: 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_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_0032: 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_0034: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00ab: 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_00b1: 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)
			Vector2 direction = (Vector2)((horizontal != 0) ? new Vector2((float)horizontal, 0f) : aimDirection);
			Vector2 point;
			Vector2 val;
			switch (Destructibles.FindAhead(myPosition, direction, 3f, out point))
			{
			case ObstacleKind.None:
				return;
			case ObstacleKind.Movable:
				if (horizontal != 0)
				{
					val = point - myPosition;
					if (((Vector2)(ref val)).magnitude < 1.5f && (data.isGrounded || data.isWallGrab))
					{
						pendingJump = true;
					}
				}
				break;
			}
			if (canShoot)
			{
				val = point - obstaclePoint;
				obstacleShots = ((!(((Vector2)(ref val)).sqrMagnitude < 1f)) ? 1 : (obstacleShots + 1));
				obstaclePoint = point;
				if (obstacleShots <= 6)
				{
					val = point - myPosition;
					aimDirection = ((Vector2)(ref val)).normalized;
					shooting = true;
				}
			}
		}

		private bool IsDisabled(BotExperiment feature)
		{
			if (Plugin.Experiment.Value == feature)
			{
				return IsVariantB;
			}
			return false;
		}

		private void ReportDeath()
		{
			bool dead = data.dead;
			if (dead && !wasDead)
			{
				BotLog.Write(DescribeDeath());
			}
			wasDead = dead;
		}

		private string DescribeDeath()
		{
			//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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			int playerID = data.player.playerID;
			string text = "unknown";
			string text2 = "-";
			string text3 = "-";
			if (DamageTracker.TryGetLastHit(playerID, out var hit))
			{
				text = hit.Cause.ToString().ToLowerInvariant();
				text2 = ((hit.SourceId >= 0) ? hit.SourceId.ToString() : "-");
				text3 = hit.Weapon;
			}
			Vector2 val = Vector2.op_Implicit(((Component)this).transform.position);
			bool flag = Time.time - navigation.LastStuckAt <= 2f;
			float num = Time.time - aliveSince;
			return FormattableString.Invariant($"RESULT died bot={playerID} variant={Variant} experiment={Plugin.Experiment.Value} match={DamageTracker.MatchIndex} map={NavMap.CurrentMapName()} t={Time.time:F0} cause={text} killer={text2} weapon={text3} life={num:F1} stuck2s={flag} pos=({val.x:F1},{val.y:F1})");
		}

		private Player FindTarget(Vector2 myPosition)
		{
			//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_00a5: Unknown result type (might be due to invalid IL or missing references)
			Player me = data.player;
			List<Player> list = PlayerManager.instance.players.Where((Player p) => (Object)(object)p != (Object)null && (Object)(object)p != (Object)(object)me && p.teamID != me.teamID && (Object)(object)p.data != (Object)null && !p.data.dead).OrderBy(delegate(Player p)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				Vector2 val2 = Vector2.op_Implicit(((Component)p).transform.position) - myPosition;
				return ((Vector2)(ref val2)).sqrMagnitude;
			}).ToList();
			Player val = list.FirstOrDefault();
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			if ((Object)(object)routeOverride != (Object)null && !list.Contains(routeOverride))
			{
				routeOverride = null;
			}
			if (Time.time >= nextRouteCheckAt)
			{
				nextRouteCheckAt = Time.time + 2f;
				UpdateRouteOverride(myPosition, val, list);
			}
			return routeOverride ?? val;
		}

		private void UpdateRouteOverride(Vector2 myPosition, Player nearest, List<Player> enemies)
		{
			//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_0028: 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_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_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (aiming.HasClearShot || navigation.HasRouteTo(myPosition, Vector2.op_Implicit(((Component)nearest).transform.position)))
			{
				noRouteSince = null;
				routeOverride = null;
				return;
			}
			noRouteSince = noRouteSince ?? Time.time;
			if (!(Time.time - noRouteSince.Value < 3f) && (!((Object)(object)routeOverride != (Object)null) || !navigation.HasRouteTo(myPosition, Vector2.op_Implicit(((Component)routeOverride).transform.position))))
			{
				routeOverride = enemies.Skip(1).FirstOrDefault((Func<Player, bool>)((Player p) => navigation.HasRouteTo(myPosition, Vector2.op_Implicit(((Component)p).transform.position))));
			}
		}

		private void UpdateBlock(Vector2 myPosition, BotSettings settings)
		{
			//IL_0093: 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_00a4: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)data.block == (Object)null || data.block.IsOnCD())
			{
				return;
			}
			float timeWindow = 0.3f + settings.ThinkInterval;
			ProjectileHit[] array = BulletCache.Get();
			foreach (ProjectileHit val in array)
			{
				if ((Object)(object)val == (Object)null || (Object)(object)val.ownPlayer == (Object)null || val.ownPlayer.teamID == data.player.teamID)
				{
					continue;
				}
				MoveTransform component = ((Component)val).GetComponent<MoveTransform>();
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				Vector2 val2 = myPosition - Vector2.op_Implicit(((Component)val).transform.position);
				Vector2 val3 = Vector2.op_Implicit(component.velocity);
				float hitRadius = (((Object)(object)((Component)val).GetComponentInChildren<Homing>() != (Object)null) ? 4f : 2f);
				if (BotMath.IsIncomingThreat(val2.x, val2.y, val3.x, val3.y, hitRadius, timeWindow))
				{
					if (Random.value < settings.BlockChance)
					{
						pendingBlock = true;
					}
					break;
				}
			}
		}

		private void DisableVanillaAi()
		{
			MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && VanillaAiTypes.Contains(((object)val).GetType().Name))
				{
					((Behaviour)val).enabled = false;
				}
			}
			PlayerAPI component = ((Component)this).GetComponent<PlayerAPI>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
		}
	}
	internal sealed class BotCover
	{
		private const float SearchBudget = 18f;

		private const float CacheSeconds = 0.6f;

		private const int MaxCandidates = 40;

		private static readonly Vector2[] BodyPoints = (Vector2[])(object)new Vector2[5]
		{
			Vector2.zero,
			new Vector2(0f, 0.6f),
			new Vector2(0f, -0.5f),
			new Vector2(-0.5f, 0f),
			new Vector2(0.5f, 0f)
		};

		private static readonly RaycastHit2D[] Hits = (RaycastHit2D[])(object)new RaycastHit2D[16];

		private Vector2? cover;

		private float foundAt = float.NegativeInfinity;

		public Vector2? Current => cover;

		public void Clear()
		{
			cover = null;
			foundAt = float.NegativeInfinity;
		}

		public Vector2? Find(Vector2 myPosition, Player enemy)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (cover.HasValue ? (!IsBodyVisible(enemy, cover.Value)) : (Time.time - foundAt < 0.6f))
			{
				return cover;
			}
			foundAt = Time.time;
			cover = Search(myPosition, enemy);
			return cover;
		}

		private static Vector2? Search(Vector2 myPosition, Player enemy)
		{
			//IL_0006: 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_0042: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ac: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			NavGrid navGrid = NavMap.Get();
			var (x, y) = NavMap.ToCell(myPosition);
			if (!navGrid.TryFindStandable(x, y, out var sx, out var sy))
			{
				return null;
			}
			Vector2 position = enemy.data.playerVel.position;
			float num = Vector2.Distance(myPosition, position);
			int num2 = 0;
			foreach (var (x2, y2, _) in navGrid.ReachableWithin(sx, sy, 18f))
			{
				if (++num2 > 40)
				{
					break;
				}
				Vector2 val = NavMap.ToWorld(x2, y2) + Vector2.up * 0.5f;
				if (!(Vector2.Distance(val, position) < num * 0.8f) && !HazardCache.IsDangerous(val) && !IsBodyVisible(enemy, val))
				{
					return val;
				}
			}
			return null;
		}

		private static bool IsBodyVisible(Player enemy, Vector2 center)
		{
			//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_0014: 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)
			Vector2[] bodyPoints = BodyPoints;
			foreach (Vector2 val in bodyPoints)
			{
				if (IsVisibleFrom(enemy, center + val))
				{
					return true;
				}
			}
			return false;
		}

		private static bool IsVisibleFrom(Player enemy, Vector2 point)
		{
			//IL_000b: 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_001b: 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_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)
			Vector2 position = enemy.data.playerVel.position;
			LayerMask canSeePlayerMask = PlayerManager.instance.canSeePlayerMask;
			int num = Physics2D.LinecastNonAlloc(position, point, Hits, LayerMask.op_Implicit(canSeePlayerMask));
			for (int i = 0; i < num; i++)
			{
				RaycastHit2D val = Hits[i];
				if (!((Object)(object)((RaycastHit2D)(ref val)).collider == (Object)null) && !((RaycastHit2D)(ref val)).collider.isTrigger)
				{
					Transform val2 = (((Object)(object)((RaycastHit2D)(ref val)).transform != (Object)null) ? ((RaycastHit2D)(ref val)).transform.root : null);
					if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).GetComponent<Player>() == (Object)null && (Object)(object)((Component)val2).GetComponent<SpawnedAttack>() == (Object)null && !Destructibles.IsDestructible(((RaycastHit2D)(ref val)).collider))
					{
						return false;
					}
				}
			}
			return true;
		}
	}
	internal sealed class BotLoadout
	{
		private static readonly FieldInfo CurrentAmmoField = AccessTools.Field(typeof(GunAmmo), "currentAmmo");

		private static readonly FieldInfo ReloadCounterField = AccessTools.Field(typeof(GunAmmo), "reloadCounter");

		private readonly CharacterData data;

		private readonly int baseBlockSpawns;

		private readonly int baseTriggers;

		private GunAmmo ammo;

		private Gun Gun
		{
			get
			{
				if (!((Object)(object)data.weaponHandler != (Object)null))
				{
					return null;
				}
				return data.weaponHandler.gun;
			}
		}

		public int CloseRangeEffects => Mathf.Max(0, CountBlockSpawns() - baseBlockSpawns) + Mathf.Max(0, CountTriggers() - baseTriggers);

		public BotLoadout(CharacterData data)
		{
			this.data = data;
			baseBlockSpawns = CountBlockSpawns();
			baseTriggers = CountTriggers();
		}

		public float BulletRange(float bulletSpeed)
		{
			Gun gun = Gun;
			if (!((Object)(object)gun != (Object)null) || !(gun.destroyBulletAfter > 0f))
			{
				return 0f;
			}
			return gun.destroyBulletAfter * bulletSpeed;
		}

		public float ReloadRemaining()
		{
			Gun gun = Gun;
			if ((Object)(object)gun == (Object)null || !gun.isReloading)
			{
				return 0f;
			}
			if ((Object)(object)ammo == (Object)null)
			{
				ammo = ((Component)gun).GetComponentInChildren<GunAmmo>();
			}
			if ((Object)(object)ammo == (Object)null || CurrentAmmoField == null || ReloadCounterField == null)
			{
				if (!gun.isReloading)
				{
					return 0f;
				}
				return 1f;
			}
			if ((int)CurrentAmmoField.GetValue(ammo) <= 0)
			{
				return Mathf.Max(0f, (float)ReloadCounterField.GetValue(ammo));
			}
			return 0f;
		}

		private int CountBlockSpawns()
		{
			if (!((Object)(object)data.block != (Object)null))
			{
				return 0;
			}
			return data.block.objectsToSpawn.Count;
		}

		private int CountTriggers()
		{
			return ((Component)data).GetComponentsInChildren<BlockTrigger>(true).Length + ((Component)data).GetComponentsInChildren<PlayerInRangeTrigger>(true).Length;
		}
	}
	internal static class BotLog
	{
		public static void Write(string line)
		{
			Plugin.Log.LogInfo((object)line);
			try
			{
				Directory.CreateDirectory(InputRecorder.Folder);
				File.AppendAllText(Path.Combine(InputRecorder.Folder, "botlog.txt"), $"{DateTime.Now:HH:mm:ss} map={NavMap.CurrentMapName()} {line}{Environment.NewLine}");
			}
			catch (IOException ex)
			{
				Plugin.Log.LogWarning((object)("botlog write failed: " + ex.Message));
			}
		}
	}
	internal static class BotLook
	{
		public const string BotsKey = "rbBots";

		private static readonly MethodInfo AdditionalDataMethod = AccessTools.Method(AccessTools.TypeByName("RWF.PlayerExtensions"), "GetAdditionalData", (Type[])null, (Type[])null);

		private static readonly FieldInfo LocalIdField = AccessTools.Field(AccessTools.TypeByName("RWF.PlayerAdditionalData"), "localID");

		private static readonly Type SelectorType = AccessTools.TypeByName("RWF.UI.PrivateRoomCharacterSelectionInstance");

		private static readonly HashSet<int> VanillaApplied = new HashSet<int>();

		private static PlayerFace VanillaFace => new PlayerFace();

		public static void Apply(Harmony harmony)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Player), "RPCA_SetFace", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(BotLook), "VanillaFaceForBots", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(CharacterCreatorItemEquipper), "RPCA_SetFace", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(BotLook), "VanillaPortraitForBots", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(CardChoiceVisuals), "Show", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(BotLook), "VanillaFaceWhenBotPicks", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo = AccessTools.PropertyGetter(AccessTools.TypeByName("RWF.LobbyCharacter"), "NickName");
			if (methodInfo != null)
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(BotLook), "BotName", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		public static int[] AnnouncedBots(Player owner)
		{
			if (owner != null && owner.IsLocal)
			{
				return OnlineBots.LocalBots;
			}
			if (owner == null || !(owner.CustomProperties[(object)"rbBots"] is int[] result))
			{
				return Array.Empty<int>();
			}
			return result;
		}

		public static bool IsBot(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Component)player).GetComponent<BotBrain>() != (Object)null)
			{
				return true;
			}
			if (PhotonNetwork.OfflineMode || AdditionalDataMethod == null || LocalIdField == null || (Object)(object)player.data?.view == (Object)null)
			{
				return false;
			}
			object obj = AdditionalDataMethod.Invoke(null, new object[1] { player });
			if (obj != null)
			{
				return AnnouncedBots(player.data.view.Owner).Contains((int)LocalIdField.GetValue(obj));
			}
			return false;
		}

		public static void ApplyVanillaFace(CharacterCreatorItemEquipper equipper)
		{
			if ((Object)(object)equipper != (Object)null)
			{
				equipper.EquipFace(VanillaFace);
			}
		}

		private static bool IsLobbyBot(object lobbyCharacter)
		{
			if (lobbyCharacter == null)
			{
				return false;
			}
			Traverse val = Traverse.Create(lobbyCharacter);
			return AnnouncedBots(val.Field("networkPlayer").GetValue<Player>()).Contains(val.Field("localID").GetValue<int>());
		}

		private static object LobbyCharacterOf(Component selector)
		{
			if (!((Object)(object)selector == (Object)null))
			{
				return Traverse.Create((object)selector).Property("currentPlayer", (object[])null).GetValue();
			}
			return null;
		}

		public static void RefreshLobbyFaces()
		{
			if (SelectorType == null)
			{
				return;
			}
			foreach (Component item in Object.FindObjectsOfType(SelectorType).OfType<Component>())
			{
				if (!IsLobbyBot(LobbyCharacterOf(item)))
				{
					continue;
				}
				CharacterCreatorItemEquipper[] componentsInChildren = item.GetComponentsInChildren<CharacterCreatorItemEquipper>(true);
				foreach (CharacterCreatorItemEquipper val in componentsInChildren)
				{
					if (VanillaApplied.Add(((Object)val).GetInstanceID()))
					{
						ApplyVanillaFace(val);
					}
				}
			}
		}

		private static void MakeVanilla(ref int eyeID, ref Vector2 eyeOffset, ref int mouthID, ref Vector2 mouthOffset, ref int detailID, ref Vector2 detailOffset, ref int detail2ID, ref Vector2 detail2Offset)
		{
			//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_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_0028: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_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)
			eyeID = (mouthID = (detailID = (detail2ID = 0)));
			eyeOffset = (mouthOffset = (detailOffset = (detail2Offset = Vector2.zero)));
		}

		private static void VanillaFaceForBots(Player __instance, ref int eyeID, ref Vector2 eyeOffset, ref int mouthID, ref Vector2 mouthOffset, ref int detailID, ref Vector2 detailOffset, ref int detail2ID, ref Vector2 detail2Offset)
		{
			if (IsBot(__instance))
			{
				MakeVanilla(ref eyeID, ref eyeOffset, ref mouthID, ref mouthOffset, ref detailID, ref detailOffset, ref detail2ID, ref detail2Offset);
			}
		}

		private static void VanillaPortraitForBots(CharacterCreatorItemEquipper __instance, ref int eyeID, ref Vector2 eyeOffset, ref int mouthID, ref Vector2 mouthOffset, ref int detailID, ref Vector2 detailOffset, ref int detail2ID, ref Vector2 detail2Offset)
		{
			Component val = ((SelectorType == null) ? null : ((Component)__instance).GetComponentInParent(SelectorType));
			if ((Object)(object)val != (Object)null && IsLobbyBot(LobbyCharacterOf(val)))
			{
				MakeVanilla(ref eyeID, ref eyeOffset, ref mouthID, ref mouthOffset, ref detailID, ref detailOffset, ref detail2ID, ref detail2Offset);
			}
		}

		private static void VanillaFaceWhenBotPicks(CardChoiceVisuals __instance, int pickerID)
		{
			if (IsBot(PlayerManager.instance?.players?.FirstOrDefault((Func<Player, bool>)((Player p) => (Object)(object)p != (Object)null && p.playerID == pickerID))))
			{
				ApplyVanillaFace(((Component)__instance).GetComponentInChildren<CharacterCreatorItemEquipper>());
			}
		}

		public static string BotNameFor(Player player)
		{
			if ((Object)(object)player == (Object)null || PhotonNetwork.OfflineMode || AdditionalDataMethod == null || LocalIdField == null || (Object)(object)player.data?.view == (Object)null)
			{
				return null;
			}
			object obj = AdditionalDataMethod.Invoke(null, new object[1] { player });
			if (obj == null)
			{
				return null;
			}
			Player owner = player.data.view.Owner;
			int num = Array.IndexOf((from id in AnnouncedBots(owner)
				orderby id
				select id).ToArray(), (int)LocalIdField.GetValue(obj));
			if (num < 0)
			{
				return null;
			}
			if (!owner.IsLocal)
			{
				return $"Bot {num + 1} ({owner.NickName})";
			}
			return $"Bot {num + 1}";
		}

		public static void RefreshNameTags()
		{
			if ((Object)(object)PlayerManager.instance == (Object)null)
			{
				return;
			}
			foreach (Player player in PlayerManager.instance.players)
			{
				string text = BotNameFor(player);
				if (text == null)
				{
					continue;
				}
				PlayerName[] componentsInChildren = ((Component)player).GetComponentsInChildren<PlayerName>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					TextMeshProUGUI componentInParent = ((Component)componentsInChildren[i]).GetComponentInParent<TextMeshProUGUI>();
					if ((Object)(object)componentInParent != (Object)null && ((TMP_Text)componentInParent).text != text)
					{
						((TMP_Text)componentInParent).text = text;
					}
				}
			}
		}

		private static void BotName(object __instance, ref string __result)
		{
			Traverse obj = Traverse.Create(__instance);
			Player value = obj.Field("networkPlayer").GetValue<Player>();
			int value2 = obj.Field("localID").GetValue<int>();
			int[] array = (from id in AnnouncedBots(value)
				orderby id
				select id).ToArray();
			int num = Array.IndexOf(array, value2);
			if (num < 0)
			{
				string text = $"{value.NickName} {value2 + 1}";
				if (array.Length != 0 && __result == text)
				{
					__result = value.NickName;
				}
			}
			else
			{
				__result = (value.IsLocal ? $"Bot {num + 1}" : $"Bot {num + 1} ({value.NickName})");
			}
		}
	}
	internal sealed class BotNavigation
	{
		private const float FlatGroundCheck = 3f;

		private const float SafeDropDepth = 45f;

		private const float LookAhead = 1.5f;

		private const float DetourHeight = 3f;

		private const float ClimbHeight = 2.5f;

		private const int EdgeSearchSteps = 30;

		private const float StuckSeconds = 1f;

		private const float StuckSpeed = 0.5f;

		private const float MaxStuckElapsed = 1f;

		private const float AirJumpAfter = 0.35f;

		private const float RouteExtraDistance = 4f;

		private const float MaxCommitSeconds = 1.5f;

		private const float MaxClimbSeconds = 3f;

		private const float MaxBounceSeconds = 4.5f;

		private const float BouncedBelowY = -16f;

		private int bounceColumn = -1;

		private bool voidFallLogged;

		private float voidSampleY;

		private float voidSampleAt;

		private bool bounced;

		private const float RepeatedStuckWindow = 3f;

		private const float ReverseSeconds = 2.5f;

		private const float FlipHoldSeconds = 0.35f;

		private const float EmergencyFallY = -14f;

		private const float StandingOffset = 0.5f;

		private const float WallProbeDistance = 1.2f;

		private const float HazardEscapeMargin = 1f;

		private const float HazardLookAhead = 2.5f;

		private static readonly float[] GapLandingDistances = new float[6] { 4f, 7f, 10f, 13f, 16f, 20f };

		private static readonly (int x, int y)[] StartCellOffsets = new(int, int)[6]
		{
			(0, 0),
			(0, -1),
			(-1, 0),
			(1, 0),
			(-1, -1),
			(1, -1)
		};

		private readonly CharacterData data;

		private float stuckTimer;

		private float lastX;

		private float lastThinkTime;

		private int lastHorizontal = 1;

		private NavStep? plannedStep;

		private float plannedAt;

		private bool airJumpUsed;

		private bool airborneNow;

		private float lastStuckAt = float.NegativeInfinity;

		private float reverseUntil;

		private int reverseDirection;

		private float lastAirY;

		private static readonly FieldRef<HealthHandler, float> LastDamaged = AccessTools.FieldRefAccess<HealthHandler, float>("lastDamaged");

		private const float AttemptTimeout = 2.5f;

		private const float FellBelow = 2.5f;

		private (int fx, int fy, int tx, int ty, NavMove move, float at, float lowY)? attempt;

		private int lastOutput;

		private float lastFlipAt = float.NegativeInfinity;

		private float bounceApexY = float.NegativeInfinity;

		private const float BounceSpentDrop = 2f;

		private const int VoidSearchRadius = 12;

		private List<NavStep> LastPath;

		private const float NearestReachableBudget = 200f;

		private const float NearestReachableCacheSeconds = 1f;

		private (int sx, int sy, int gx, int gy) nearestKey;

		private (int x, int y) nearestCell;

		private float nearestAt = float.NegativeInfinity;

		private bool BounceStillSafe
		{
			get
			{
				if (plannedStep.HasValue && plannedStep.Value.Move == NavMove.Bounce)
				{
					if (!bounced)
					{
						if ((Object)(object)data.block != (Object)null)
						{
							return !data.block.IsOnCD();
						}
						return false;
					}
					return true;
				}
				return false;
			}
		}

		private bool CanJumpInAir
		{
			get
			{
				if (!data.isWallGrab)
				{
					return data.currentJumps > 0;
				}
				return true;
			}
		}

		private bool FallingToBounce
		{
			get
			{
				if (plannedStep.HasValue && plannedStep.Value.Move == NavMove.Bounce)
				{
					return !bounced;
				}
				return false;
			}
		}

		public int LastPathLength { get; private set; }

		public float LastStuckAt => lastStuckAt;

		public BotNavigation(CharacterData data)
		{
			this.data = data;
			Reset();
		}

		public void Reset()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			lastX = ((Component)data).transform.position.x;
			lastThinkTime = Time.time;
			stuckTimer = 0f;
		}

		public (int horizontal, bool jump) Decide(Vector2 myPosition, Vector2 toTarget, bool canSee, BotSettings settings)
		{
			//IL_0001: 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_0020: 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_005a: 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_0034: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			ForgetSpentBounce(myPosition);
			(int horizontal, bool jump) tuple = DecideRaw(myPosition, toTarget, canSee, settings);
			int item = tuple.horizontal;
			bool item2 = tuple.jump;
			int num = VoidEscapeDirection(myPosition);
			if (num != 0)
			{
				lastOutput = num;
				TrackVoidFall(myPosition, canSee, toTarget, num);
				return (horizontal: num, jump: item2 || EmergencyJump(myPosition));
			}
			int num2 = Smooth(item);
			TrackVoidFall(myPosition, canSee, toTarget, num2);
			return (horizontal: num2, jump: item2 || EmergencyJump(myPosition));
		}

		private void TrackVoidFall(Vector2 myPosition, bool canSee, Vector2 toTarget, int horizontal)
		{
			//IL_0016: 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_0078: 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_0162: 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)
			float time = Time.time;
			float num = ((time > voidSampleAt) ? ((myPosition.y - voidSampleY) / (time - voidSampleAt)) : 0f);
			voidSampleY = myPosition.y;
			voidSampleAt = time;
			if (data.isGrounded || data.isWallGrab)
			{
				voidFallLogged = false;
			}
			else if (!voidFallLogged && !(num > 0f) && !data.ThereIsGroundBelow(Vector2.op_Implicit(myPosition), 45f))
			{
				voidFallLogged = true;
				string text = (plannedStep.HasValue ? plannedStep.Value.Move.ToString() : "-");
				bool flag = (Object)(object)data.block == (Object)null || data.block.IsOnCD();
				BotLog.Write(FormattableString.Invariant($"VOID_FALL bot={data.player.playerID} blockCD={flag} planned={text} jumps={data.currentJumps} vy={num:F1} move={horizontal} canSee={canSee} dist={((Vector2)(ref toTarget)).magnitude:F1} pos=({myPosition.x:F1},{myPosition.y:F1})"));
			}
		}

		private int Smooth(int horizontal)
		{
			if (horizontal != 0 && lastOutput != 0 && horizontal != lastOutput)
			{
				if (Time.time - lastFlipAt < 0.35f)
				{
					return 0;
				}
				lastFlipAt = Time.time;
			}
			if (horizontal != 0)
			{
				lastOutput = horizontal;
			}
			return horizontal;
		}

		private void ForgetSpentBounce(Vector2 myPosition)
		{
			//IL_003e: 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)
			if (!plannedStep.HasValue || plannedStep.Value.Move != NavMove.Bounce || !bounced)
			{
				bounceApexY = float.NegativeInfinity;
				return;
			}
			bounceApexY = Mathf.Max(bounceApexY, myPosition.y);
			if (BotMath.BounceSpent(bounceApexY, myPosition.y, -16f, 2f))
			{
				plannedStep = null;
				bounced = false;
				bounceApexY = float.NegativeInfinity;
			}
		}

		private int VoidEscapeDirection(Vector2 myPosition)
		{
			//IL_0020: 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_0075: 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_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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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)
			if (data.isGrounded || data.isWallGrab || data.ThereIsGroundBelow(Vector2.op_Implicit(myPosition), 45f) || BounceStillSafe)
			{
				return 0;
			}
			if (plannedStep.HasValue && plannedStep.Value.Move == NavMove.Bounce)
			{
				plannedStep = null;
			}
			for (int i = 1; i <= 12; i++)
			{
				bool flag = data.ThereIsGroundBelow(Vector2.op_Implicit(myPosition + Vector2.right * (float)i), 45f);
				bool flag2 = data.ThereIsGroundBelow(Vector2.op_Implicit(myPosition + Vector2.left * (float)i), 45f);
				if (!(flag || flag2))
				{
					continue;
				}
				if (!(flag && flag2))
				{
					if (!flag)
					{
						return -1;
					}
					return 1;
				}
				if (lastOutput == 0)
				{
					return 1;
				}
				return lastOutput;
			}
			return 0;
		}

		private bool EmergencyJump(Vector2 myPosition)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!BounceStillSafe && !data.isGrounded && myPosition.y < -14f && data.currentJumps > 0)
			{
				return data.sinceGrounded > 0.35f;
			}
			return false;
		}

		private (int horizontal, bool jump) DecideRaw(Vector2 myPosition, Vector2 toTarget, bool canSee, BotSettings settings)
		{
			//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_000d: 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_0034: 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_0107: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_00c1: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = HazardCache.EscapeDirection(myPosition, 1f);
			if (val != Vector2.zero)
			{
				return (horizontal: lastHorizontal = ((!(Mathf.Abs(val.x) > 0.1f)) ? (-lastHorizontal) : ((val.x > 0f) ? 1 : (-1))), jump: val.y > 0.3f);
			}
			if (Time.time < reverseUntil)
			{
				return (horizontal: reverseDirection, jump: false);
			}
			if ((!canSee || ((Vector2)(ref toTarget)).magnitude > settings.PreferredDistance + 4f) && TryFollowPath(myPosition, toTarget, out var horizontal, out var jump))
			{
				if (horizontal != 0)
				{
					lastHorizontal = horizontal;
				}
				if (data.isWallGrab && toTarget.y > 2.5f)
				{
					jump = true;
				}
				bool flag = UpdateStuck(horizontal);
				if (FallingToBounce)
				{
					return (horizontal: horizontal, jump: false);
				}
				return (horizontal: horizontal, jump: jump || (flag && !airborneNow));
			}
			int num = ChooseDirection(myPosition, toTarget, canSee, settings);
			bool flag2 = false;
			if (num != 0 && HazardCache.IsDangerous(myPosition + new Vector2((float)num * 2.5f, 0f)))
			{
				num = 0;
			}
			if (num != 0 && IsEdgeAhead(myPosition, num) && !HasGroundFarBelow(myPosition, num))
			{
				if (HasLandingAhead(myPosition, num))
				{
					flag2 = true;
				}
				else
				{
					num = 0;
				}
			}
			if (num != 0)
			{
				lastHorizontal = num;
			}
			if (!data.isGrounded && !data.isWallGrab && data.sinceGrounded > 0.35f && data.currentJumps > 0 && !data.ThereIsGroundBelow(Vector2.op_Implicit(myPosition), 45f))
			{
				flag2 = true;
			}
			bool flag3 = toTarget.y > 2.5f;
			if (data.isWallGrab)
			{
				num = lastHorizontal;
				flag2 = flag2 || flag3;
			}
			if (UpdateStuck(num))
			{
				flag2 = true;
			}
			return (horizontal: num, jump: flag2);
		}

		public (int horizontal, bool jump) MoveTo(Vector2 myPosition, Vector2 toGoal)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (HazardCache.EscapeDirection(myPosition, 1f) != Vector2.zero || !TryFollowPath(myPosition, toGoal, out var horizontal, out var jump))
			{
				return (horizontal: 0, jump: false);
			}
			if (horizontal != 0)
			{
				lastHorizontal = horizontal;
			}
			bool flag = UpdateStuck(horizontal);
			return (horizontal: horizontal, jump: jump || (flag && !airborneNow));
		}

		private int ChooseDirection(Vector2 myPosition, Vector2 toTarget, bool canSee, BotSettings settings)
		{
			//IL_0003: 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_0026: 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_0012: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			if (!canSee && toTarget.y < -3f)
			{
				int num = FindDropEdge(myPosition, toTarget.x);
				if (num != 0)
				{
					return num;
				}
			}
			if (!canSee && toTarget.y > 2.5f)
			{
				int num2 = FindOpenSky(myPosition, toTarget);
				if (num2 != 0)
				{
					return num2;
				}
			}
			return BotMath.Horizontal(toTarget.x, ((Vector2)(ref toTarget)).magnitude, settings.PreferredDistance, canSee);
		}

		private int FindOpenSky(Vector2 myPosition, Vector2 toTarget)
		{
			//IL_0000: 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_0022: 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_002e: 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_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_008c: Unknown result type (might be due to invalid IL or missing references)
			float height = Mathf.Min(toTarget.y + 2f, 25f);
			LayerMask canSeePlayerMask = PlayerManager.instance.canSeePlayerMask;
			if (!IsCeilingAbove(myPosition, height, canSeePlayerMask))
			{
				return 0;
			}
			int num = ((toTarget.x >= 0f) ? 1 : (-1));
			foreach (int item in Enumerable.Range(1, 30))
			{
				int[] array = new int[2]
				{
					num,
					-num
				};
				foreach (int num2 in array)
				{
					if (!IsCeilingAbove(myPosition + new Vector2((float)(num2 * item), 0f), height, canSeePlayerMask))
					{
						return num2;
					}
				}
			}
			return 0;
		}

		private static bool IsCeilingAbove(Vector2 from, float height, LayerMask mask)
		{
			//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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit2D[] array = Physics2D.RaycastAll(from, Vector2.up, height, LayerMask.op_Implicit(mask));
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit2D val = array[i];
				Transform val2 = (((Object)(object)((RaycastHit2D)(ref val)).transform != (Object)null) ? ((RaycastHit2D)(ref val)).transform.root : null);
				if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).GetComponent<Player>() == (Object)null && (Object)(object)((Component)val2).GetComponent<SpawnedAttack>() == (Object)null)
				{
					return true;
				}
			}
			return false;
		}

		private int FindDropEdge(Vector2 myPosition, float targetDx)
		{
			//IL_0035: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			int num