Decompiled source of Gungeon Online v0.122.0

plugins/GungeonOnline.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dungeonator;
using HarmonyLib;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;
using InControl;
using Pathfinding;
using Steamworks;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace GungeonOnline;

public static class AllocProfiler
{
	public static bool Enabled;

	private static readonly Dictionary<string, long> totals = new Dictionary<string, long>();

	private static float nextReportAt;

	private static long startTotal = -1L;

	public static void Init()
	{
		string[] commandLineArgs = Environment.GetCommandLineArgs();
		foreach (string text in commandLineArgs)
		{
			if (text == "--gungeon-online-allocprof")
			{
				Enabled = true;
			}
		}
		if (Enabled)
		{
			Plugin.Log.LogInfo((object)"Allocation profiler on.");
		}
	}

	public static long Begin()
	{
		if (!Enabled)
		{
			return 0L;
		}
		return GC.GetTotalMemory(forceFullCollection: false);
	}

	public static void End(string name, long before)
	{
		FreezeWatch.Done(name);
		if (Enabled)
		{
			long num = GC.GetTotalMemory(forceFullCollection: false) - before;
			if (num > 0)
			{
				totals.TryGetValue(name, out var value);
				totals[name] = value + num;
			}
		}
	}

	public static void Report()
	{
		if (!Enabled)
		{
			return;
		}
		long totalMemory = GC.GetTotalMemory(forceFullCollection: false);
		if (startTotal < 0)
		{
			startTotal = totalMemory;
			nextReportAt = Time.realtimeSinceStartup + 30f;
		}
		else if (!(Time.realtimeSinceStartup < nextReportAt))
		{
			nextReportAt = Time.realtimeSinceStartup + 30f;
			List<KeyValuePair<string, long>> list = new List<KeyValuePair<string, long>>(totals);
			list.Sort((KeyValuePair<string, long> a, KeyValuePair<string, long> b) => b.Value.CompareTo(a.Value));
			string text = "Alloc report (last 30 s): heap " + totalMemory / 1048576 + " MB (+" + (totalMemory - startTotal) / 1024 + " KB);";
			for (int num = 0; num < list.Count && num < 12; num++)
			{
				object obj = text;
				text = string.Concat(obj, " ", list[num].Key, "=", list[num].Value / 1024, "KB");
			}
			Plugin.Log.LogInfo((object)text);
			totals.Clear();
			startTotal = totalMemory;
		}
	}
}
public static class AttackSync
{
	private static NetSession session;

	private static readonly FieldInfo actorField = AccessTools.Field(typeof(BehaviorBase), "m_aiActor");

	private static readonly FieldInfo activeField = AccessTools.Field(typeof(BehaviorSpeculator), "m_activeContinuousBehavior");

	private static readonly FieldInfo classActiveField = AccessTools.Field(typeof(BehaviorSpeculator), "m_classSpecificContinuousBehavior");

	private static readonly MethodInfo endContinuous = AccessTools.Method(typeof(BehaviorSpeculator), "EndContinuousBehavior", (Type[])null, (Type[])null);

	private static readonly MethodInfo endClassContinuous = AccessTools.Method(typeof(BehaviorSpeculator), "EndClassSpecificContinuousBehavior", (Type[])null, (Type[])null);

	private static readonly Dictionary<AIActor, List<AttackBehaviorBase>> attacksOf = new Dictionary<AIActor, List<AttackBehaviorBase>>();

	private static int depth;

	private static bool replaying;

	private static bool seeded;

	private static int seed;

	private static int lastFrame;

	public static int Started;

	public static int Replayed;

	public static int Missed;

	private static bool Connected
	{
		get
		{
			if (session != null)
			{
				return session.Status == NetSession.State.Connected;
			}
			return false;
		}
	}

	public static void Init(NetSession netSession, Harmony harmony)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		session = netSession;
		HarmonyMethod val = new HarmonyMethod(typeof(AttackSync), "BeforeAttackUpdate", (Type[])null);
		HarmonyMethod val2 = new HarmonyMethod(typeof(AttackSync), "AfterAttackUpdate", (Type[])null);
		HarmonyMethod val3 = new HarmonyMethod(typeof(AttackSync), "BeforeIsReady", (Type[])null);
		BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
		Type[] types;
		try
		{
			types = typeof(AttackBehaviorBase).Assembly.GetTypes();
		}
		catch (ReflectionTypeLoadException ex)
		{
			types = ex.Types;
		}
		int num = 0;
		int num2 = 0;
		Type[] array = types;
		foreach (Type type in array)
		{
			if ((object)type == null || !typeof(AttackBehaviorBase).IsAssignableFrom(type) || typeof(IAttackBehaviorGroup).IsAssignableFrom(type))
			{
				continue;
			}
			MethodInfo method = type.GetMethod("Update", bindingAttr, null, Type.EmptyTypes, null);
			if ((object)method != null && !method.IsAbstract)
			{
				try
				{
					harmony.Patch((MethodBase)method, val, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
				}
				catch (Exception ex2)
				{
					Plugin.Log.LogWarning((object)("AttackSync: couldn't patch " + type.Name + ".Update: " + ex2.Message));
				}
			}
			MethodInfo method2 = type.GetMethod("IsReady", bindingAttr, null, Type.EmptyTypes, null);
			if ((object)method2 != null && !method2.IsAbstract)
			{
				try
				{
					harmony.Patch((MethodBase)method2, val3, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					num2++;
				}
				catch (Exception ex3)
				{
					Plugin.Log.LogWarning((object)("AttackSync: couldn't patch " + type.Name + ".IsReady: " + ex3.Message));
				}
			}
		}
		Plugin.Log.LogInfo((object)("AttackSync: watching " + num + " kinds of enemy attack."));
	}

	private static AIActor ActorOf(BehaviorBase b)
	{
		if ((object)actorField == null)
		{
			return null;
		}
		object? value = actorField.GetValue(b);
		return (AIActor)((value is AIActor) ? value : null);
	}

	private static List<AttackBehaviorBase> AttacksOf(AIActor a)
	{
		if (attacksOf.TryGetValue(a, out var value))
		{
			return value;
		}
		value = new List<AttackBehaviorBase>();
		BehaviorSpeculator behaviorSpeculator = ((BraveBehaviour)a).behaviorSpeculator;
		if ((Object)(object)behaviorSpeculator != (Object)null && behaviorSpeculator.AttackBehaviors != null)
		{
			foreach (AttackBehaviorBase attackBehavior in behaviorSpeculator.AttackBehaviors)
			{
				Collect(attackBehavior, value);
			}
		}
		attacksOf[a] = value;
		return value;
	}

	private static void Collect(AttackBehaviorBase b, List<AttackBehaviorBase> list)
	{
		if (b == null)
		{
			return;
		}
		IAttackBehaviorGroup val = (IAttackBehaviorGroup)(object)((b is IAttackBehaviorGroup) ? b : null);
		if (val == null)
		{
			list.Add(b);
			return;
		}
		for (int i = 0; i < val.Count; i++)
		{
			Collect(val.GetAttackBehavior(i), list);
		}
	}

	private static bool BeforeAttackUpdate(BehaviorBase __instance, ref BehaviorResult __result, out bool __state)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		__state = false;
		if (Time.frameCount != lastFrame)
		{
			lastFrame = Time.frameCount;
			depth = 0;
		}
		depth++;
		__state = true;
		if (depth > 1 || replaying || !Connected)
		{
			return true;
		}
		AIActor val = ActorOf(__instance);
		if ((Object)(object)val == (Object)null || !EnemySync.TryGetId(val, out var _) || AttacksOf(val).IndexOf((AttackBehaviorBase)__instance) < 0)
		{
			return true;
		}
		if (!EnemySync.LeadsEnemy(val))
		{
			__result = (BehaviorResult)0;
			return false;
		}
		seed = Random.Range(int.MinValue, int.MaxValue);
		Random.InitState(seed);
		seeded = true;
		return true;
	}

	private static void AfterAttackUpdate(BehaviorBase __instance, BehaviorResult __result, bool __state)
	{
		//IL_002d: 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_005d: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		if (!__state)
		{
			return;
		}
		depth--;
		if (depth > 0 || replaying || !seeded)
		{
			return;
		}
		seeded = false;
		if ((int)__result == 0)
		{
			return;
		}
		AIActor val = ActorOf(__instance);
		if (!((Object)(object)val == (Object)null) && EnemySync.TryGetId(val, out var id))
		{
			int num = AttacksOf(val).IndexOf((AttackBehaviorBase)__instance);
			if (num >= 0)
			{
				Started++;
				Send(val, id, num, (byte)__result, seed);
			}
		}
	}

	private static bool BeforeIsReady(ref bool __result)
	{
		if (!replaying)
		{
			return true;
		}
		__result = true;
		return false;
	}

	private static void Send(AIActor a, int id, int index, byte result, int diceSeed)
	{
		//IL_0064: 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_0069: Unknown result type (might be due to invalid IL or missing references)
		int level = LevelSync.CurrentLevelCode();
		Vector2 pos = (((Object)(object)((BraveBehaviour)a).specRigidbody != (Object)null) ? ((BraveBehaviour)a).specRigidbody.UnitCenter : Vector2.op_Implicit(((BraveBehaviour)a).transform.position));
		byte target = (byte)TargetSync.SlotOfTarget(a);
		session.SendReliable(MsgType.AttackStart, delegate(BinaryWriter w)
		{
			w.Write(level);
			w.Write(id);
			w.Write(a.EnemyGuid ?? "");
			w.Write((ushort)index);
			w.Write(target);
			w.Write(pos.x);
			w.Write(pos.y);
			w.Write(diceSeed);
		});
	}

	public static void OnAttackStart(BinaryReader r)
	{
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Invalid comparison between Unknown and I4
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Invalid comparison between Unknown and I4
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		int num = r.ReadInt32();
		int id = r.ReadInt32();
		string text = r.ReadString();
		int num2 = r.ReadUInt16();
		int slot = r.ReadByte();
		Vector2 center = default(Vector2);
		((Vector2)(ref center))..ctor(r.ReadSingle(), r.ReadSingle());
		int num3 = r.ReadInt32();
		if (num != LevelSync.CurrentLevelCode())
		{
			return;
		}
		AIActor val = EnemySync.ById(id);
		if ((Object)(object)val == (Object)null || val.EnemyGuid != text || (Object)(object)((BraveBehaviour)val).healthHaver == (Object)null || ((BraveBehaviour)val).healthHaver.IsDead || EnemySync.LeadsEnemy(val))
		{
			return;
		}
		BehaviorSpeculator behaviorSpeculator = ((BraveBehaviour)val).behaviorSpeculator;
		List<AttackBehaviorBase> list = AttacksOf(val);
		if ((Object)(object)behaviorSpeculator == (Object)null || num2 >= list.Count)
		{
			Missed++;
			return;
		}
		AttackBehaviorBase val2 = list[num2];
		EnemySync.PlaceAt(val, center);
		TargetSync.Force(val, slot);
		try
		{
			if (activeField.GetValue(behaviorSpeculator) != null)
			{
				endContinuous.Invoke(behaviorSpeculator, null);
			}
			IDictionary dictionary = classActiveField.GetValue(behaviorSpeculator) as IDictionary;
			if (dictionary != null && dictionary.Contains(behaviorSpeculator.AttackBehaviors))
			{
				endClassContinuous.Invoke(behaviorSpeculator, new object[1] { behaviorSpeculator.AttackBehaviors });
			}
			State state = Random.state;
			Random.InitState(num3);
			replaying = true;
			BehaviorResult val3;
			try
			{
				val3 = ((BehaviorBase)val2).Update();
			}
			finally
			{
				replaying = false;
			}
			Random.state = state;
			if ((int)val3 == 4)
			{
				activeField.SetValue(behaviorSpeculator, val2);
			}
			else if ((int)val3 == 3 && dictionary != null)
			{
				dictionary[behaviorSpeculator.AttackBehaviors] = val2;
			}
			if ((int)val3 == 0)
			{
				Missed++;
			}
			else
			{
				Replayed++;
			}
		}
		catch (Exception ex)
		{
			Missed++;
			Plugin.Log.LogWarning((object)("Couldn't copy " + ((Object)val).name + "'s attack " + ((object)val2).GetType().Name + ": " + ex.Message));
		}
	}

	public static void Update()
	{
		if (attacksOf.Count <= 200)
		{
			return;
		}
		List<AIActor> list = new List<AIActor>();
		foreach (AIActor key in attacksOf.Keys)
		{
			if ((Object)(object)key == (Object)null)
			{
				list.Add(key);
			}
		}
		foreach (AIActor item in list)
		{
			attacksOf.Remove(item);
		}
	}
}
public class Brain
{
	private const float GraceAfterStart = 1f;

	private const float RepathInterval = 0.5f;

	private const float DodgeCooldown = 1.2f;

	private const float RealBonus = 10000f;

	private const float HostBonus = 5000f;

	private const float GhostPenalty = 50000f;

	private const int MaxGap = 2;

	private static NetSession session;

	private bool active;

	private bool forced;

	private float graceUntil;

	private Vector2 move;

	private bool shoot;

	private bool dodge;

	private bool reload;

	private bool interact;

	private static readonly List<Vector2> waypoints = new List<Vector2>();

	private IntVector2 pathGoal = new IntVector2(-1, -1);

	private float nextPathAt;

	private float strafeSign = 1f;

	private float nextStrafeFlipAt;

	private float nextDodgeAt;

	private static readonly List<AIActor> enemies = new List<AIActor>();

	private List<AIActor> enemiesOut = new List<AIActor>();

	public readonly int PlayerIndex;

	public readonly string Label;

	public bool Explore;

	private RoomHandler exploreRoom;

	private static readonly HashSet<RoomHandler> explored = new HashSet<RoomHandler>();

	private RoomHandler progressRoom;

	private Dungeon exploredFloor;

	private float bestDistance;

	private float progressAt;

	private float nextStatusAt;

	private Component blocker;

	private float blockedAt;

	private float nextBlockerLogAt;

	private Vector2 smoothMove;

	private float nextPathLogAt;

	private int inputTicks;

	private float lastRetryAt;

	private Vector2 exitAt;

	private float nextExitScanAt;

	private ElevatorDepartureController exit;

	private bool bossDone;

	private Component lootTarget;

	private float lootChosenAt;

	private float nextLootScanAt;

	private float nextInteractAt;

	private int lootPresses;

	private static readonly HashSet<Component> lootGivenUp = new HashSet<Component>();

	private static readonly Dictionary<string, FieldInfo> flagFields = new Dictionary<string, FieldInfo>();

	private float nextGunPickAt;

	private int tourIndex;

	private Vector2 pitRollDir;

	private float pitRollUntil;

	private float lastGapRollAt = -100f;

	private float noGapsUntil;

	private int gapRolls;

	private Vector2 lastPos;

	private float stuckSince = -1f;

	private float sidestepUntil;

	private float sidestepSign = 1f;

	private Vector2 sidestepDir;

	private int sidesteps;

	private static readonly float[] turns = new float[9] { 0f, 20f, -20f, 40f, -40f, 65f, -65f, 90f, -90f };

	private static readonly List<SpeculativeRigidbody> ignoreScratch = new List<SpeculativeRigidbody>();

	private float nextBumpLogAt;

	private static readonly FieldInfo actionsField = AccessTools.Field(typeof(PlayerActionSet), "actions");

	private static readonly FieldInfo oneAxisField = AccessTools.Field(typeof(PlayerActionSet), "oneAxisActions");

	private static readonly FieldInfo twoAxisField = AccessTools.Field(typeof(PlayerActionSet), "twoAxisActions");

	private static readonly MethodInfo oneAxisUpdate = AccessTools.Method(typeof(PlayerOneAxisAction), "Update", (Type[])null, (Type[])null);

	private static readonly MethodInfo twoAxisUpdate = AccessTools.Method(typeof(PlayerTwoAxisAction), "Update", (Type[])null, (Type[])null);

	private static readonly object[] tickArgs = new object[2];

	public bool Active => active;

	public PlayerController Player
	{
		get
		{
			if (!GameManager.HasInstance)
			{
				return null;
			}
			if (PlayerIndex != 0)
			{
				return GameManager.Instance.SecondaryPlayer;
			}
			return GameManager.Instance.PrimaryPlayer;
		}
	}

	public Brain(int playerIndex, string label)
	{
		//IL_0003: 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)
		PlayerIndex = playerIndex;
		Label = label;
	}

	public static void SetSession(NetSession netSession)
	{
		session = netSession;
	}

	public void Start(bool keepOn)
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		if (!active && PlayerIndex == 0)
		{
			Plugin.Log.LogInfo((object)("Take a Break: the bot plays for us" + (keepOn ? " (test copy: stays on)." : "; moving takes control back.")));
			if (!keepOn)
			{
				Toast.Show("Taking a break: the bot plays for you. Move to take control back.", 5f);
			}
		}
		active = true;
		forced |= keepOn;
		graceUntil = Time.realtimeSinceStartup + 1f;
		waypoints.Clear();
		pathGoal = new IntVector2(-1, -1);
	}

	public void Stop(string why)
	{
		//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)
		if (active)
		{
			active = false;
			forced = false;
			move = Vector2.zero;
			shoot = (dodge = (reload = false));
			PlayerController player = Player;
			if ((Object)(object)player != (Object)null)
			{
				player.forceAimPoint = null;
			}
			if (PlayerIndex == 0)
			{
				Plugin.Log.LogInfo((object)("Take a Break off (" + why + ")."));
				Toast.Show("You're back in control.", 3f);
			}
		}
	}

	public void Toggle()
	{
		if (active)
		{
			Stop("switched off");
		}
		else
		{
			Start(keepOn: false);
		}
	}

	public void Update()
	{
		//IL_0103: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		if (!active)
		{
			return;
		}
		GameManager val = (GameManager.HasInstance ? GameManager.Instance : null);
		PlayerController player = Player;
		if ((Object)(object)val == (Object)null || (Object)(object)player == (Object)null || val.IsLoadingLevel || val.IsPaused || (PlayerIndex == 0 && MultiplayerMenu.IsOpen) || (Object)(object)((BraveBehaviour)player).specRigidbody == (Object)null || (Object)(object)((BraveBehaviour)player).healthHaver == (Object)null || player.CurrentRoom == null)
		{
			graceUntil = realtimeSinceStartup + 0.75f;
			move = Vector2.zero;
			shoot = (dodge = (reload = false));
			return;
		}
		if (PlayerIndex == 0 && !forced && realtimeSinceStartup > graceUntil && PlayerTouchedControls())
		{
			Stop("the player moved");
			return;
		}
		try
		{
			Think(player);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Autopilot error: " + ex.Message));
			move = Vector2.zero;
			shoot = false;
		}
	}

	private bool PlayerTouchedControls()
	{
		//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_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)
		if (Input.anyKeyDown)
		{
			return true;
		}
		InputDevice activeDevice = InputManager.ActiveDevice;
		if (activeDevice != null)
		{
			if (!activeDevice.AnyButtonWasPressed)
			{
				Vector2 vector = activeDevice.LeftStick.Vector;
				if (!(((Vector2)(ref vector)).magnitude > 0.4f))
				{
					Vector2 vector2 = activeDevice.DPad.Vector;
					if (!(((Vector2)(ref vector2)).magnitude > 0.4f))
					{
						goto IL_0050;
					}
				}
			}
			return true;
		}
		goto IL_0050;
		IL_0050:
		return false;
	}

	private void Think(PlayerController me)
	{
		//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_002f: 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_0047: 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_0067: 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_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: 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_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: 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_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_05be: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_066c: Unknown result type (might be due to invalid IL or missing references)
		//IL_066f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0674: Unknown result type (might be due to invalid IL or missing references)
		//IL_0679: Unknown result type (might be due to invalid IL or missing references)
		//IL_0680: Unknown result type (might be due to invalid IL or missing references)
		//IL_0683: Unknown result type (might be due to invalid IL or missing references)
		//IL_0689: Unknown result type (might be due to invalid IL or missing references)
		//IL_068e: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0616: Unknown result type (might be due to invalid IL or missing references)
		//IL_0618: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_0701: Unknown result type (might be due to invalid IL or missing references)
		//IL_0706: Unknown result type (might be due to invalid IL or missing references)
		//IL_0505: Unknown result type (might be due to invalid IL or missing references)
		//IL_050a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06be: Unknown result type (might be due to invalid IL or missing references)
		//IL_051d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0520: Unknown result type (might be due to invalid IL or missing references)
		//IL_0518: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: 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_06d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_047a: Unknown result type (might be due to invalid IL or missing references)
		//IL_047c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0486: Unknown result type (might be due to invalid IL or missing references)
		//IL_048b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_041a: Unknown result type (might be due to invalid IL or missing references)
		//IL_041f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0424: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
		move = Vector2.zero;
		shoot = (dodge = (reload = false));
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		Vector2 centerPosition = ((GameActor)me).CenterPosition;
		PickGun(me, realtimeSinceStartup);
		AIActor val = (me.IsGhost ? null : ClosestEnemy(me, centerPosition));
		Vector2 stepDir = Vector2.zero;
		float timeToHit = float.MaxValue;
		bool flag = !me.IsGhost && IncomingBullet(centerPosition, out stepDir, out timeToHit);
		if ((Object)(object)val != (Object)null)
		{
			Vector2 centerPosition2 = ((GameActor)val).CenterPosition;
			Vector2 val2 = (((Object)(object)((BraveBehaviour)val).specRigidbody != (Object)null) ? (((BraveBehaviour)val).specRigidbody.Velocity * 0.15f) : Vector2.zero);
			me.forceAimPoint = centerPosition2 + val2;
			shoot = !WallBetween(centerPosition, centerPosition2);
			Gun currentGun = ((GameActor)me).CurrentGun;
			if ((Object)(object)currentGun != (Object)null && !currentGun.IsReloading && currentGun.ClipShotsRemaining == 0 && currentGun.ammo > 0)
			{
				reload = true;
			}
		}
		if (flag)
		{
			move = stepDir;
			if (timeToHit < 0.3f && realtimeSinceStartup >= nextDodgeAt && !me.IsDodgeRolling)
			{
				dodge = true;
				nextDodgeAt = realtimeSinceStartup + 1.2f;
			}
		}
		else if ((Object)(object)val != (Object)null)
		{
			Vector2 val3 = ((GameActor)val).CenterPosition - centerPosition;
			float magnitude = ((Vector2)(ref val3)).magnitude;
			Vector2 val4 = ((magnitude > 0.01f) ? (val3 / magnitude) : Vector2.right);
			if (realtimeSinceStartup >= nextStrafeFlipAt)
			{
				strafeSign = 0f - strafeSign;
				nextStrafeFlipAt = realtimeSinceStartup + Random.Range(1.2f, 2.5f);
			}
			Vector2 val5 = new Vector2(0f - val4.y, val4.x) * strafeSign;
			if (magnitude < 3.5f)
			{
				Vector2 val6 = -val4 + val5 * 0.5f;
				move = ((Vector2)(ref val6)).normalized;
			}
			else if (magnitude > 8f || WallBetween(centerPosition, ((GameActor)val).CenterPosition))
			{
				move = PathToward(me, ((GameActor)val).CenterPosition);
			}
			else
			{
				move = val5;
			}
		}
		else if (me.IsGhost || !EveryoneIsABot() || !LootStep(me, realtimeSinceStartup))
		{
			Vector2 at = Vector2.zero;
			bool flag2 = Explore && !me.IsGhost && !SomeoneElseLeads(me);
			if (!flag2 && ClosestTeammate(centerPosition, out at))
			{
				if (Vector2.Distance(centerPosition, at) > 3f)
				{
					move = PathToward(me, at);
				}
			}
			else if (flag2 && ExitPoint(out exitAt))
			{
				move = PathToward(me, exitAt);
			}
			else if (flag2)
			{
				RoomHandler val7 = NextRoomToExplore(me);
				if (val7 != null)
				{
					IntVector2 centerCell = val7.GetCenterCell();
					Vector2 val8 = default(Vector2);
					((Vector2)(ref val8))..ctor((float)centerCell.x + 0.5f, (float)centerCell.y + 0.5f);
					float num = Vector2.Distance(centerPosition, val8);
					if (val7 != progressRoom || num < bestDistance - 1f)
					{
						progressRoom = val7;
						bestDistance = num;
						progressAt = realtimeSinceStartup;
					}
					else if (realtimeSinceStartup - progressAt > 6f)
					{
						Plugin.Log.LogInfo((object)("Bot: can't get to " + val7.GetRoomName() + "; trying another room."));
						explored.Add(val7);
						exploreRoom = null;
						progressRoom = null;
					}
					move = PathToward(me, val8);
				}
				else
				{
					RoomHandler val9 = BossRoom();
					if (val9 != null && me.CurrentRoom != val9)
					{
						IntVector2 centerCell2 = val9.GetCenterCell();
						move = PathToward(me, new Vector2((float)centerCell2.x + 0.5f, (float)centerCell2.y + 0.5f));
					}
					if (realtimeSinceStartup - lastRetryAt > 30f)
					{
						lastRetryAt = realtimeSinceStartup;
						explored.RemoveWhere((RoomHandler r) => r != null && !r.hasEverBeenVisited);
					}
				}
			}
			if (((Vector2)(ref move)).sqrMagnitude > 0.01f)
			{
				me.forceAimPoint = centerPosition + move * 4f;
			}
		}
		if ((Object)(object)val == (Object)null && !me.IsGhost && (Object)(object)blocker != (Object)null && realtimeSinceStartup - blockedAt < 0.6f)
		{
			Component obj = blocker;
			BraveBehaviour val10 = (BraveBehaviour)(object)((obj is BraveBehaviour) ? obj : null);
			Vector2 value = (((Object)(object)val10 != (Object)null && (Object)(object)val10.specRigidbody != (Object)null) ? val10.specRigidbody.UnitCenter : Vector2.op_Implicit(blocker.transform.position));
			me.forceAimPoint = value;
			shoot = true;
			if (realtimeSinceStartup >= nextBlockerLogAt)
			{
				nextBlockerLogAt = realtimeSinceStartup + 5f;
				Plugin.Log.LogInfo((object)("Bot" + ((PlayerIndex == 0) ? "" : (" (" + Label + ")")) + ": " + ((Object)blocker).name + " is in the way; shooting it."));
			}
		}
		Vector2 val11 = move;
		Vector2 val12 = Feet(me);
		Vector2 dir;
		if (me.IsDodgeRolling && realtimeSinceStartup < pitRollUntil)
		{
			move = pitRollDir;
		}
		else if (!flag && PitJump(me, val12, realtimeSinceStartup, out dir))
		{
			move = dir;
			dodge = true;
			nextDodgeAt = realtimeSinceStartup + 1.2f;
			pitRollDir = dir;
			pitRollUntil = realtimeSinceStartup + 1.2f;
			Plugin.Log.LogInfo((object)("Bot" + ((PlayerIndex == 0) ? "" : (" (" + Label + ")")) + ": rolling over a gap."));
		}
		else
		{
			move = KeepSafe(me, val12, move);
			move = Unstick(val12, move, realtimeSinceStartup);
		}
		if (((Vector2)(ref move)).sqrMagnitude > 0.01f && ((Vector2)(ref smoothMove)).sqrMagnitude > 0.01f && Vector2.Dot(move, smoothMove) > 0f)
		{
			Vector2 val13 = Vector2.Lerp(smoothMove, move, Mathf.Clamp01(BraveTime.DeltaTime * 14f));
			move = ((Vector2)(ref val13)).normalized;
		}
		smoothMove = move;
		if (forced && realtimeSinceStartup >= nextStatusAt)
		{
			nextStatusAt = realtimeSinceStartup + 3f;
			Plugin.Log.LogInfo((object)("Bot" + ((PlayerIndex == 0) ? "" : (" (" + Label + ")")) + ": at " + ((Vector2)(ref centerPosition)).ToString("F1") + " want " + ((Vector2)(ref val11)).ToString("F2") + " move " + ((Vector2)(ref move)).ToString("F2") + (((Object)(object)val != (Object)null) ? (", fighting " + ((Object)val).name) : "") + (flag ? ", dodging" : "") + ", path " + waypoints.Count + ((exploreRoom != null) ? (", exploring " + exploreRoom.GetRoomName()) : "") + ", inputs seen " + inputTicks));
		}
	}

	private string CellKind(DungeonData data, IntVector2 c)
	{
		//IL_0004: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		if (data == null || !data.CheckInBoundsAndValid(c))
		{
			return "invalid";
		}
		CellData val = data[c];
		if (val != null)
		{
			return string.Concat(val.type, val.isOccupied ? " occupied" : "");
		}
		return "null";
	}

	private AIActor ClosestEnemy(PlayerController me, Vector2 pos)
	{
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: 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)
		enemies.Clear();
		RoomHandler currentRoom = me.CurrentRoom;
		if (currentRoom != null)
		{
			currentRoom.GetActiveEnemies((ActiveEnemyType)0, ref enemiesOut);
		}
		if (enemiesOut != null && currentRoom != null)
		{
			enemies.AddRange(enemiesOut);
		}
		AIActor result = null;
		float num = float.MaxValue;
		foreach (AIActor enemy in enemies)
		{
			if (!((Object)(object)enemy == (Object)null) && !((Object)(object)((BraveBehaviour)enemy).healthHaver == (Object)null) && !((BraveBehaviour)enemy).healthHaver.IsDead && enemy.IsNormalEnemy && !((Object)(object)enemy.CompanionOwner != (Object)null) && !((GameActor)enemy).IsGone && ((Component)enemy).gameObject.activeInHierarchy)
			{
				float num2 = Vector2.Distance(pos, ((GameActor)enemy).CenterPosition);
				if (WallBetween(pos, ((GameActor)enemy).CenterPosition))
				{
					num2 += 20f;
				}
				if (num2 < num)
				{
					result = enemy;
					num = num2;
				}
			}
		}
		return result;
	}

	private bool IncomingBullet(Vector2 pos, out Vector2 stepDir, out float timeToHit)
	{
		//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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: 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_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		stepDir = Vector2.zero;
		timeToHit = float.MaxValue;
		bool result = false;
		Vector2 val4 = default(Vector2);
		foreach (Projectile allProjectile in StaticReferenceManager.AllProjectiles)
		{
			if ((Object)(object)allProjectile == (Object)null || !((Behaviour)allProjectile).isActiveAndEnabled || !allProjectile.collidesWithPlayer || allProjectile.Owner is PlayerController)
			{
				continue;
			}
			Vector2 val = (((Object)(object)((BraveBehaviour)allProjectile).specRigidbody != (Object)null) ? ((BraveBehaviour)allProjectile).specRigidbody.UnitCenter : Vector2.op_Implicit(((BraveBehaviour)allProjectile).transform.position));
			Vector2 val2 = pos - val;
			float magnitude = ((Vector2)(ref val2)).magnitude;
			if (magnitude > 5f)
			{
				continue;
			}
			Vector2 lastVelocity = allProjectile.LastVelocity;
			float magnitude2 = ((Vector2)(ref lastVelocity)).magnitude;
			if (magnitude2 < 0.5f)
			{
				continue;
			}
			Vector2 val3 = lastVelocity / magnitude2;
			float num = Vector2.Dot(val2, val3);
			if (num <= 0f)
			{
				continue;
			}
			float num2 = Mathf.Abs(val2.x * val3.y - val2.y * val3.x);
			if (num2 > 1.1f)
			{
				continue;
			}
			float num3 = num / magnitude2;
			if (num3 < timeToHit)
			{
				timeToHit = num3;
				((Vector2)(ref val4))..ctor(0f - val3.y, val3.x);
				if (Vector2.Dot(val2, val4) < 0f)
				{
					val4 = -val4;
				}
				stepDir = val4;
				result = true;
			}
		}
		return result;
	}

	private RoomHandler NextRoomToExplore(PlayerController me)
	{
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Invalid comparison between Unknown and I4
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)GameManager.Instance.Dungeon != (Object)(object)exploredFloor)
		{
			exploredFloor = GameManager.Instance.Dungeon;
			explored.Clear();
			lootGivenUp.Clear();
			exploreRoom = null;
		}
		if (me.CurrentRoom != null)
		{
			explored.Add(me.CurrentRoom);
		}
		if (exploreRoom != null && !exploreRoom.hasEverBeenVisited && !explored.Contains(exploreRoom))
		{
			return exploreRoom;
		}
		exploreRoom = null;
		Dungeon dungeon = GameManager.Instance.Dungeon;
		if ((Object)(object)dungeon == (Object)null || dungeon.data == null)
		{
			return null;
		}
		Vector2 val = Feet(me);
		IntVector2 val2 = default(IntVector2);
		((IntVector2)(ref val2))..ctor(Mathf.FloorToInt(val.x), Mathf.FloorToInt(val.y));
		float num = float.MaxValue;
		foreach (RoomHandler room in dungeon.data.rooms)
		{
			if (room == null || room.area == null || !Seen(room, me))
			{
				continue;
			}
			foreach (RoomHandler connectedRoom in room.connectedRooms)
			{
				if (connectedRoom != null && connectedRoom.area != null && !Seen(connectedRoom, me) && (int)connectedRoom.area.PrototypeRoomCategory != 6)
				{
					IntVector2 centerCell = connectedRoom.GetCenterCell();
					Path val3 = null;
					float num2 = ((!Pathfinder.HasInstance || !Pathfinder.Instance.GetPath(val2, centerCell, ref val3, (IntVector2?)IntVector2.One, (CellTypes)2, (CellValidator)null, (ExtraWeightingFunction)null, true) || val3 == null) ? (1000f + Vector2.Distance(val, new Vector2((float)centerCell.x, (float)centerCell.y))) : ((float)val3.Count));
					if (num2 < num)
					{
						num = num2;
						exploreRoom = connectedRoom;
					}
				}
			}
		}
		return exploreRoom;
	}

	private bool SomeoneElseLeads(PlayerController me)
	{
		if (session == null || session.Status != NetSession.State.Connected)
		{
			return false;
		}
		int num = ((PlayerIndex == 0) ? session.LocalSlot : StandIn.Slot);
		if (PlayerIndex != 0)
		{
			PlayerController primaryPlayer = GameManager.Instance.PrimaryPlayer;
			if ((Object)(object)primaryPlayer != (Object)null && !primaryPlayer.IsGhost && !((BraveBehaviour)primaryPlayer).healthHaver.IsDead)
			{
				return true;
			}
		}
		string text = LevelSync.CurrentLevelKey();
		foreach (RemotePlayerState remote in session.Remotes)
		{
			if (remote.HasPlayer && !remote.IsDead && !(remote.Scene != text) && remote.Slot != num && (!remote.OnBreak || remote.Slot < num))
			{
				return true;
			}
		}
		return false;
	}

	private static RoomHandler BossRoom()
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Invalid comparison between Unknown and I4
		Dungeon dungeon = GameManager.Instance.Dungeon;
		if ((Object)(object)dungeon == (Object)null || dungeon.data == null)
		{
			return null;
		}
		foreach (RoomHandler room in dungeon.data.rooms)
		{
			if (room != null && room.area != null && (int)room.area.PrototypeRoomCategory == 3)
			{
				return room;
			}
		}
		return null;
	}

	private bool ExitPoint(out Vector2 at)
	{
		//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_013e: 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_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: 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_008d: Invalid comparison between Unknown and I4
		at = Vector2.zero;
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		if (realtimeSinceStartup >= nextExitScanAt)
		{
			nextExitScanAt = realtimeSinceStartup + 1f;
			bossDone = false;
			exit = null;
			Dungeon dungeon = GameManager.Instance.Dungeon;
			if ((Object)(object)dungeon != (Object)null && dungeon.data != null)
			{
				foreach (RoomHandler room in dungeon.data.rooms)
				{
					if (room != null && room.area != null && (int)room.area.PrototypeRoomCategory == 3 && room.hasEverBeenVisited && !room.IsSealed && room.GetActiveEnemiesCount((ActiveEnemyType)1) == 0)
					{
						bossDone = true;
					}
				}
				if (bossDone)
				{
					exit = Object.FindObjectOfType<ElevatorDepartureController>();
				}
			}
		}
		if (!bossDone || (Object)(object)exit == (Object)null || (Object)(object)exit.elevatorFloor == (Object)null)
		{
			return false;
		}
		SpeculativeRigidbody component = exit.elevatorFloor.GetComponent<SpeculativeRigidbody>();
		at = (((Object)(object)component != (Object)null) ? component.UnitCenter : Vector2.op_Implicit(exit.elevatorFloor.transform.position));
		return true;
	}

	private bool Seen(RoomHandler room, PlayerController me)
	{
		if (!room.hasEverBeenVisited && !explored.Contains(room))
		{
			return room == me.CurrentRoom;
		}
		return true;
	}

	private bool EveryoneIsABot()
	{
		if (!active || session == null || session.Status != NetSession.State.Connected)
		{
			return false;
		}
		foreach (RemotePlayerState remote in session.Remotes)
		{
			if (!remote.OnBreak)
			{
				return false;
			}
		}
		if (PlayerIndex != 0 && !Autopilot.Self.Active)
		{
			return false;
		}
		return true;
	}

	private bool LootStep(PlayerController me, float now)
	{
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		RoomHandler currentRoom = me.CurrentRoom;
		if (currentRoom != null && currentRoom.IsSealed)
		{
			return false;
		}
		if ((Object)(object)lootTarget == (Object)null || !StillLoot(lootTarget, me) || now >= nextLootScanAt)
		{
			Component val = lootTarget;
			nextLootScanAt = now + 1f;
			lootTarget = FindLoot(me);
			if ((Object)(object)lootTarget != (Object)(object)val)
			{
				lootChosenAt = now;
				lootPresses = 0;
			}
		}
		if ((Object)(object)lootTarget == (Object)null)
		{
			return false;
		}
		Vector2 val2 = LootPoint(lootTarget);
		Vector2 val3 = Feet(me);
		if (now - lootChosenAt > 15f || lootPresses >= 5)
		{
			Plugin.Log.LogInfo((object)("Bot: giving up on " + ((Object)lootTarget).name + "."));
			lootGivenUp.Add(lootTarget);
			lootTarget = null;
			return false;
		}
		if (Vector2.Distance(val3, val2) > 1.3f)
		{
			move = PathToward(me, val2);
			me.forceAimPoint = val2;
			return true;
		}
		me.forceAimPoint = val2;
		if (!(lootTarget is Chest) && Vector2.Distance(val3, val2) > 0.3f)
		{
			Vector2 val4 = val2 - val3;
			move = ((Vector2)(ref val4)).normalized;
		}
		if (now >= nextInteractAt)
		{
			nextInteractAt = now + 0.7f;
			interact = true;
			lootPresses++;
			if (lootPresses == 1 && !(lootTarget is CurrencyPickup))
			{
				Plugin.Log.LogInfo((object)("Bot: opening/picking up " + ((Object)lootTarget).name + "."));
			}
		}
		return true;
	}

	private Vector2 LootPoint(Component c)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		BraveBehaviour val = (BraveBehaviour)(object)((c is BraveBehaviour) ? c : null);
		if ((Object)(object)val != (Object)null && (Object)(object)val.sprite != (Object)null)
		{
			return val.sprite.WorldCenter;
		}
		return Vector2.op_Implicit(c.transform.position);
	}

	private bool StillLoot(Component c, PlayerController me)
	{
		if ((Object)(object)c == (Object)null || !c.gameObject.activeInHierarchy || lootGivenUp.Contains(c))
		{
			return false;
		}
		Chest val = (Chest)(object)((c is Chest) ? c : null);
		if ((Object)(object)val != (Object)null)
		{
			if (!val.IsOpen && !val.IsBroken && !val.pickedUp)
			{
				if (val.IsLocked)
				{
					return me.carriedConsumables.KeyBullets > 0;
				}
				return true;
			}
			return false;
		}
		PickupObject val2 = (PickupObject)(object)((c is PickupObject) ? c : null);
		if ((Object)(object)val2 == (Object)null || val2.IsBeingSold || (Object)(object)((Component)val2).GetComponentInParent<ShopItemController>() != (Object)null)
		{
			return false;
		}
		Gun val3 = (Gun)(object)((val2 is Gun) ? val2 : null);
		if ((Object)(object)val3 != (Object)null)
		{
			if ((Object)(object)val3.CurrentOwner == (Object)null && !val3.HasBeenPickedUp && !val3.HasEverBeenAcquiredByPlayer)
			{
				return !LootSync.IsPlayerDrop(val3);
			}
			return false;
		}
		PassiveItem val4 = (PassiveItem)(object)((val2 is PassiveItem) ? val2 : null);
		if ((Object)(object)val4 != (Object)null)
		{
			if (!val4.PickedUp && (Object)(object)val4.Owner == (Object)null)
			{
				return !Flag(val4, "m_pickedUpThisRun");
			}
			return false;
		}
		PlayerItem val5 = (PlayerItem)(object)((val2 is PlayerItem) ? val2 : null);
		if ((Object)(object)val5 != (Object)null)
		{
			if (!val5.PickedUp && (Object)(object)val5.LastOwner == (Object)null)
			{
				return !Flag(val5, "m_pickedUpThisRun");
			}
			return false;
		}
		HealthPickup val6 = (HealthPickup)(object)((val2 is HealthPickup) ? val2 : null);
		if ((Object)(object)val6 != (Object)null)
		{
			if (!Flag(val6, "m_pickedUp"))
			{
				if (!(val6.healAmount <= 0f))
				{
					if (((BraveBehaviour)me).healthHaver.GetMaxHealth() > 0f)
					{
						return ((BraveBehaviour)me).healthHaver.GetCurrentHealth() < ((BraveBehaviour)me).healthHaver.GetMaxHealth();
					}
					return false;
				}
				return true;
			}
			return false;
		}
		AmmoPickup val7 = (AmmoPickup)(object)((val2 is AmmoPickup) ? val2 : null);
		if ((Object)(object)val7 != (Object)null)
		{
			if (!val7.pickedUp)
			{
				return NeedsAmmo(me);
			}
			return false;
		}
		if (val2 is KeyBulletPickup)
		{
			return !Flag(val2, "m_hasBeenPickedUp");
		}
		CurrencyPickup val8 = (CurrencyPickup)(object)((val2 is CurrencyPickup) ? val2 : null);
		if ((Object)(object)val8 != (Object)null)
		{
			if (!val8.PreventPickup)
			{
				return !Flag(val8, "m_hasBeenPickedUp");
			}
			return false;
		}
		return false;
	}

	private static bool Flag(object o, string name)
	{
		string key = o.GetType().FullName + "." + name;
		if (!flagFields.TryGetValue(key, out var value))
		{
			value = AccessTools.Field(o.GetType(), name);
			flagFields[key] = value;
		}
		if ((object)value != null)
		{
			return (bool)value.GetValue(o);
		}
		return false;
	}

	private static bool NeedsAmmo(PlayerController me)
	{
		if (me.inventory == null)
		{
			return false;
		}
		foreach (Gun allGun in me.inventory.AllGuns)
		{
			if ((Object)(object)allGun != (Object)null && !allGun.InfiniteAmmo && allGun.ammo < allGun.AdjustedMaxAmmo)
			{
				return true;
			}
		}
		return false;
	}

	private void PickGun(PlayerController me, float now)
	{
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Expected I4, but got Unknown
		if (now < nextGunPickAt || me.inventory == null || me.IsGhost)
		{
			return;
		}
		nextGunPickAt = now + 2f;
		Gun currentGun = ((GameActor)me).CurrentGun;
		if ((Object)(object)currentGun != (Object)null && currentGun.IsReloading)
		{
			return;
		}
		List<Gun> allGuns = me.inventory.AllGuns;
		if (Autopilot.GunTour && allGuns.Count > 1)
		{
			nextGunPickAt = now + 15f;
			tourIndex = (tourIndex + 1) % allGuns.Count;
			Gun val = allGuns[tourIndex];
			if ((Object)(object)val != (Object)null)
			{
				val.ammo = val.AdjustedMaxAmmo;
				Plugin.Log.LogInfo((object)("Bot" + ((PlayerIndex == 0) ? "" : (" (" + Label + ")")) + ": gun tour - " + ((PickupObject)val).EncounterNameOrDisplayName + "."));
				me.ChangeToGunSlot(tourIndex, false);
			}
			return;
		}
		int num = -1;
		int num2 = int.MinValue;
		for (int i = 0; i < allGuns.Count; i++)
		{
			Gun val2 = allGuns[i];
			if (!((Object)(object)val2 == (Object)null) && (val2.InfiniteAmmo || val2.ammo > 0))
			{
				int num3 = (int)((PickupObject)val2).quality;
				int num4 = ((num3 >= 1 && num3 <= 5) ? (num3 * 10) : 0) + ((!val2.InfiniteAmmo) ? 1 : 0);
				if (num4 > num2)
				{
					num = i;
					num2 = num4;
				}
			}
		}
		if (num >= 0 && !((Object)(object)allGuns[num] == (Object)(object)currentGun))
		{
			Plugin.Log.LogInfo((object)("Bot" + ((PlayerIndex == 0) ? "" : (" (" + Label + ")")) + ": switching to " + ((PickupObject)allGuns[num]).DisplayName + "."));
			me.ChangeToGunSlot(num, false);
		}
	}

	private Component FindLoot(PlayerController me)
	{
		//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_0025: 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)
		Vector2 feet = Feet(me);
		Component best = null;
		float bestDist = 40f;
		Chest[] array = Object.FindObjectsOfType<Chest>();
		foreach (Chest c in array)
		{
			Consider((Component)(object)c, me, feet, ref best, ref bestDist);
		}
		PickupObject[] array2 = Object.FindObjectsOfType<PickupObject>();
		foreach (PickupObject c2 in array2)
		{
			Consider((Component)(object)c2, me, feet, ref best, ref bestDist);
		}
		return best;
	}

	private void Consider(Component c, PlayerController me, Vector2 feet, ref Component best, ref float bestDist)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		if (!StillLoot(c, me))
		{
			return;
		}
		Vector2 val = LootPoint(c);
		Dungeon dungeon = GameManager.Instance.Dungeon;
		RoomHandler val2 = (((Object)(object)dungeon != (Object)null) ? dungeon.data.GetAbsoluteRoomFromPosition(new IntVector2(Mathf.FloorToInt(val.x), Mathf.FloorToInt(val.y))) : null);
		if (val2 != null && Seen(val2, me) && !val2.HasActiveEnemies((ActiveEnemyType)1))
		{
			float num = Vector2.Distance(feet, val);
			if (num < bestDist)
			{
				best = c;
				bestDist = num;
			}
		}
	}

	private bool ClosestTeammate(Vector2 pos, out Vector2 at)
	{
		//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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		at = Vector2.zero;
		float num = float.MaxValue;
		if (PlayerIndex != 0 && GameManager.HasInstance && (Object)(object)GameManager.Instance.PrimaryPlayer != (Object)null)
		{
			PlayerController primaryPlayer = GameManager.Instance.PrimaryPlayer;
			at = ((GameActor)primaryPlayer).CenterPosition;
			num = Vector2.Distance(pos, at) - 5000f - (Autopilot.Self.Active ? 0f : 10000f) + ((primaryPlayer.IsGhost || ((BraveBehaviour)primaryPlayer).healthHaver.IsDead) ? 50000f : 0f);
		}
		if (session != null && session.Status == NetSession.State.Connected)
		{
			string text = LevelSync.CurrentLevelKey();
			foreach (RemotePlayerState remote in session.Remotes)
			{
				if (remote.HasPlayer && !(remote.Scene != text))
				{
					float num2 = Vector2.Distance(pos, remote.Position) - (remote.OnBreak ? 0f : 10000f) - ((remote.Slot == 0) ? 5000f : 0f) + (remote.IsDead ? 50000f : 0f);
					if (num2 < num)
					{
						at = remote.Position;
						num = num2;
					}
				}
			}
		}
		return num < float.MaxValue;
	}

	private Vector2 Feet(PlayerController me)
	{
		//IL_0025: 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)
		SpeculativeRigidbody specRigidbody = ((BraveBehaviour)me).specRigidbody;
		if ((Object)(object)specRigidbody != (Object)null && specRigidbody.PrimaryPixelCollider != null)
		{
			return specRigidbody.PrimaryPixelCollider.UnitCenter;
		}
		return ((GameActor)me).CenterPosition;
	}

	private static bool IsPit(Vector2 p)
	{
		Dungeon dungeon = GameManager.Instance.Dungeon;
		if ((Object)(object)dungeon == (Object)null || dungeon.data == null)
		{
			return false;
		}
		int num = Mathf.FloorToInt(p.x);
		int num2 = Mathf.FloorToInt(p.y);
		if (dungeon.data.CheckInBoundsAndValid(num, num2))
		{
			return dungeon.data.isPit(num, num2);
		}
		return false;
	}

	private static bool GapsRollable(List<Vector2> path)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		foreach (Vector2 item in path)
		{
			num = (IsPit(item) ? (num + 1) : 0);
			if (num > 2)
			{
				return false;
			}
		}
		return num == 0;
	}

	private bool PitJump(PlayerController me, Vector2 feet, float now, out Vector2 dir)
	{
		//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_0068: 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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		dir = Vector2.zero;
		if (me.IsGhost || me.IsDodgeRolling || now < nextDodgeAt || waypoints.Count == 0)
		{
			return false;
		}
		int num = -1;
		for (int i = 0; i < waypoints.Count && i < 4; i++)
		{
			if (IsPit(waypoints[i]))
			{
				num = i;
				break;
			}
		}
		if (num < 0 || Vector2.Distance(feet, waypoints[num]) > 1.6f)
		{
			return false;
		}
		int num2 = -1;
		for (int j = num + 1; j < waypoints.Count && j <= num + 2; j++)
		{
			if (!IsPit(waypoints[j]))
			{
				num2 = j;
				break;
			}
		}
		if (num2 < 0)
		{
			return false;
		}
		Vector2 val = ((num2 + 1 < waypoints.Count && !IsPit(waypoints[num2 + 1])) ? waypoints[num2 + 1] : waypoints[num2]);
		float num3 = Vector2.Distance(feet, val);
		if (num3 > 3.5f)
		{
			return false;
		}
		Vector2 val2 = (val - feet) / (float)Mathf.Max(1, Mathf.CeilToInt(num3 * 8f));
		float num4 = -1f;
		float num5 = 0f;
		Vector2 val3 = feet;
		while (Vector2.Distance(feet, val3) <= num3)
		{
			if (IsPit(val3))
			{
				if (num4 < 0f)
				{
					num4 = Vector2.Distance(feet, val3);
				}
				num5 += ((Vector2)(ref val2)).magnitude;
			}
			val3 += val2;
		}
		if (num4 < 0f || num4 > 0.9f || num5 > 2.2f)
		{
			return false;
		}
		gapRolls = ((!(now - lastGapRollAt < 8f)) ? 1 : (gapRolls + 1));
		lastGapRollAt = now;
		if (gapRolls > 2)
		{
			noGapsUntil = now + 30f;
			waypoints.Clear();
			Plugin.Log.LogInfo((object)"Bot: this gap keeps failing; walking round for a while.");
			return false;
		}
		Vector2 val4 = val - feet;
		dir = ((Vector2)(ref val4)).normalized;
		return true;
	}

	private Vector2 PathToward(PlayerController me, Vector2 goal)
	{
		//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_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_0036: 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_009e: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_037a: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0397: Unknown result type (might be due to invalid IL or missing references)
		//IL_038f: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = Feet(me);
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		IntVector2 val2 = default(IntVector2);
		((IntVector2)(ref val2))..ctor(Mathf.FloorToInt(goal.x), Mathf.FloorToInt(goal.y));
		if (realtimeSinceStartup >= nextPathAt || val2 != pathGoal || waypoints.Count == 0)
		{
			nextPathAt = realtimeSinceStartup + 0.5f;
			pathGoal = val2;
			waypoints.Clear();
			Path val3 = null;
			IntVector2 val4 = default(IntVector2);
			((IntVector2)(ref val4))..ctor(Mathf.FloorToInt(val.x), Mathf.FloorToInt(val.y));
			bool flag = Pathfinder.HasInstance && Pathfinder.Instance.GetPath(val4, val2, ref val3, (IntVector2?)IntVector2.One, (CellTypes)2, (CellValidator)null, (ExtraWeightingFunction)null, true);
			if (flag && val3 != null && val3.Positions != null)
			{
				foreach (IntVector2 position in val3.Positions)
				{
					waypoints.Add(new Vector2((float)position.x + 0.5f, (float)position.y + 0.5f));
				}
			}
			if (waypoints.Count == 0 && !me.IsGhost && realtimeSinceStartup >= noGapsUntil && Pathfinder.HasInstance && Pathfinder.Instance.GetPath(val4, val2, ref val3, (IntVector2?)IntVector2.One, (CellTypes)6, (CellValidator)null, (ExtraWeightingFunction)null, true) && val3 != null && val3.Positions != null)
			{
				foreach (IntVector2 position2 in val3.Positions)
				{
					waypoints.Add(new Vector2((float)position2.x + 0.5f, (float)position2.y + 0.5f));
				}
				if (!GapsRollable(waypoints))
				{
					waypoints.Clear();
				}
			}
			if (forced && waypoints.Count == 0 && realtimeSinceStartup >= nextPathLogAt)
			{
				nextPathLogAt = realtimeSinceStartup + 3f;
				DungeonData data = (((Object)(object)GameManager.Instance.Dungeon != (Object)null) ? GameManager.Instance.Dungeon.data : null);
				Plugin.Log.LogInfo((object)string.Concat("Bot path: ", val4, " -> ", val2, " found ", flag, ", start cell ", CellKind(data, val4), ", goal cell ", CellKind(data, val2), ", pathfinder ", Pathfinder.HasInstance));
			}
		}
		while (waypoints.Count > 0 && Vector2.Distance(val, waypoints[0]) < 0.45f)
		{
			waypoints.RemoveAt(0);
		}
		Vector2 val5 = ((waypoints.Count > 0) ? waypoints[0] : goal);
		for (int i = 1; i < waypoints.Count && i < 6 && ClearLine(val, waypoints[i]); i++)
		{
			val5 = waypoints[i];
		}
		Vector2 val6 = val5 - val;
		if (!(((Vector2)(ref val6)).sqrMagnitude > 0.01f))
		{
			return Vector2.zero;
		}
		return ((Vector2)(ref val6)).normalized;
	}

	private Vector2 Unstick(Vector2 pos, Vector2 want, float now)
	{
		//IL_000a: 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_007a: 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_0051: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: 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_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		if (now < sidestepUntil)
		{
			return sidestepDir;
		}
		bool flag = ((Vector2)(ref want)).sqrMagnitude > 0.01f;
		if (!flag || stuckSince < 0f || Vector2.Distance(pos, lastPos) > 0.5f)
		{
			if (stuckSince >= 0f && Vector2.Distance(pos, lastPos) > 0.5f && now > sidestepUntil + 1f)
			{
				sidesteps = 0;
			}
			lastPos = pos;
			stuckSince = (flag ? now : (-1f));
			return want;
		}
		if (now - stuckSince < 1.2f)
		{
			return want;
		}
		lastPos = pos;
		stuckSince = -1f;
		sidestepSign = 0f - sidestepSign;
		PlayerController player = Player;
		sidesteps++;
		if (sidesteps >= 3 && (Object)(object)player != (Object)null && player.CurrentRoom != null)
		{
			IntVector2 centerCell = player.CurrentRoom.GetCenterCell();
			Vector2 val = new Vector2((float)centerCell.x + 0.5f, (float)centerCell.y + 0.5f) - pos;
			sidestepDir = KeepSafe(player, pos, (((Vector2)(ref val)).sqrMagnitude > 0.01f) ? ((Vector2)(ref val)).normalized : (-want));
			sidestepUntil = now + 0.9f;
			sidesteps = 0;
			waypoints.Clear();
			return sidestepDir;
		}
		Vector2 val2 = new Vector2(0f - want.y, want.x) * sidestepSign;
		sidestepDir = KeepSafe(player, pos, val2);
		if (((Vector2)(ref sidestepDir)).sqrMagnitude < 0.01f)
		{
			sidestepDir = KeepSafe(player, pos, -val2);
		}
		sidestepUntil = now + 0.2f;
		waypoints.Clear();
		return sidestepDir;
	}

	private Vector2 KeepSafe(PlayerController me, Vector2 pos, Vector2 want)
	{
		//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)
		//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_000e: 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_004e: 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_0093: 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_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: 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_00a2: 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_007b: 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_00b0: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
		if (((Vector2)(ref want)).sqrMagnitude < 0.01f)
		{
			return Vector2.zero;
		}
		Vector2 normalized = ((Vector2)(ref want)).normalized;
		Vector2 val = Vector2.zero;
		bool flag = false;
		float[] array = turns;
		foreach (float num in array)
		{
			if (flag && Mathf.Abs(num) > 40f)
			{
				break;
			}
			Vector2 val2 = Rotate(normalized, num);
			if (me.IsGhost || (SafeStep(pos + val2 * 0.8f) && SafeStep(pos + val2 * 0.4f)))
			{
				if (val == Vector2.zero)
				{
					val = val2;
				}
				if (!Bumps(me, val2, out var wall))
				{
					return val2;
				}
				if (num == 0f && wall)
				{
					flag = true;
				}
			}
		}
		return val;
	}

	private bool Bumps(PlayerController me, Vector2 dir, out bool wall)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		wall = false;
		SpeculativeRigidbody specRigidbody = ((BraveBehaviour)me).specRigidbody;
		if ((Object)(object)specRigidbody == (Object)null || !PhysicsEngine.HasInstance)
		{
			return false;
		}
		IntVector2 val = default(IntVector2);
		((IntVector2)(ref val))..ctor(Mathf.RoundToInt(dir.x * 8f), Mathf.RoundToInt(dir.y * 8f));
		if (val == IntVector2.Zero)
		{
			return false;
		}
		CollisionData val2 = null;
		bool flag = false;
		try
		{
			flag = PhysicsEngine.Instance.RigidbodyCastWithIgnores(specRigidbody, val, ref val2, true, true, (int?)null, false, OnlineBodies());
			if (flag && val2 != null && (Object)(object)val2.OtherRigidbody != (Object)null && (Object)(object)((Component)val2.OtherRigidbody).GetComponentInParent<DungeonDoorController>() != (Object)null)
			{
				flag = false;
			}
			if (flag && val2 != null && (Object)(object)val2.OtherRigidbody != (Object)null && (Object)(object)((Component)val2.OtherRigidbody).GetComponent<Projectile>() != (Object)null)
			{
				flag = false;
			}
			if (flag && val2 != null && (Object)(object)val2.OtherRigidbody != (Object)null)
			{
				Component componentInParent = (Component)(object)((Component)val2.OtherRigidbody).GetComponentInParent<FlippableCover>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					componentInParent = (Component)(object)((Component)val2.OtherRigidbody).GetComponentInParent<MajorBreakable>();
				}
				if ((Object)(object)componentInParent != (Object)null)
				{
					blocker = componentInParent;
					blockedAt = Time.realtimeSinceStartup;
				}
			}
			wall = flag && (val2 == null || (Object)(object)val2.OtherRigidbody == (Object)null);
			if (flag && forced && Time.realtimeSinceStartup >= nextBumpLogAt)
			{
				nextBumpLogAt = Time.realtimeSinceStartup + 2f;
				Plugin.Log.LogInfo((object)("Bot bumps " + ((Vector2)(ref dir)).ToString("F2") + ": " + ((val2 == null) ? "nothing?" : string.Concat(val2.collisionType, " ", ((Object)(object)val2.OtherRigidbody != (Object)null) ? (((Object)val2.OtherRigidbody).name + " (parent " + (((Object)(object)((BraveBehaviour)val2.OtherRigidbody).transform.parent != (Object)null) ? ((Object)((BraveBehaviour)val2.OtherRigidbody).transform.parent).name : "-") + ")") : "tile"))));
			}
		}
		finally
		{
			if (val2 != null)
			{
				CollisionData.Pool.Free(ref val2);
			}
		}
		return flag;
	}

	private SpeculativeRigidbody[] OnlineBodies()
	{
		List<SpeculativeRigidbody> list = ignoreScratch;
		list.Clear();
		for (int i = 0; i < 4; i++)
		{
			SpeculativeRigidbody val = TargetSync.BodyOf(i);
			if ((Object)(object)val != (Object)null)
			{
				list.Add(val);
			}
			val = TablePush.BodyOf(i);
			if ((Object)(object)val != (Object)null)
			{
				list.Add(val);
			}
		}
		return list.ToArray();
	}

	private bool SafeStep(Vector2 p)
	{
		Dungeon dungeon = GameManager.Instance.Dungeon;
		if ((Object)(object)dungeon == (Object)null || dungeon.data == null)
		{
			return true;
		}
		int num = Mathf.FloorToInt(p.x);
		int num2 = Mathf.FloorToInt(p.y);
		if (!dungeon.data.CheckInBoundsAndValid(num, num2))
		{
			return false;
		}
		return !dungeon.data.isPit(num, num2);
	}

	private Vector2 Rotate(Vector2 v, float degrees)
	{
		//IL_003c: 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);
		return new Vector2(v.x * num2 - v.y * num3, v.x * num3 + v.y * num2);
	}

	private bool ClearLine(Vector2 from, Vector2 to)
	{
		//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_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = to - from;
		if (((Vector2)(ref val)).sqrMagnitude < 0.0001f)
		{
			return true;
		}
		Vector2 val2 = new Vector2(0f - val.y, val.x);
		Vector2 val3 = ((Vector2)(ref val2)).normalized * 0.4f;
		if (!WallOrPitBetween(from + val3, to + val3))
		{
			return !WallOrPitBetween(from - val3, to - val3);
		}
		return false;
	}

	private bool WallOrPitBetween(Vector2 from, Vector2 to)
	{
		//IL_001e: 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_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		Dungeon dungeon = GameManager.Instance.Dungeon;
		if ((Object)(object)dungeon == (Object)null || dungeon.data == null)
		{
			return false;
		}
		float num = Vector2.Distance(from, to);
		int num2 = Mathf.Max(1, Mathf.CeilToInt(num * 4f));
		for (int i = 1; i <= num2; i++)
		{
			Vector2 val = Vector2.Lerp(from, to, (float)i / (float)num2);
			int num3 = Mathf.FloorToInt(val.x);
			int num4 = Mathf.FloorToInt(val.y);
			if (!dungeon.data.CheckInBoundsAndValid(num3, num4) || dungeon.data.isWall(num3, num4) || dungeon.data.isPit(num3, num4))
			{
				return true;
			}
		}
		return false;
	}

	private bool WallBetween(Vector2 from, Vector2 to)
	{
		//IL_001e: 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_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		Dungeon dungeon = GameManager.Instance.Dungeon;
		if ((Object)(object)dungeon == (Object)null || dungeon.data == null)
		{
			return false;
		}
		float num = Vector2.Distance(from, to);
		int num2 = Mathf.Max(1, Mathf.CeilToInt(num * 3f));
		for (int i = 1; i < num2; i++)
		{
			Vector2 val = Vector2.Lerp(from, to, (float)i / (float)num2);
			int num3 = Mathf.FloorToInt(val.x);
			int num4 = Mathf.FloorToInt(val.y);
			if (!dungeon.data.CheckInBoundsAndValid(num3, num4) || dungeon.data.isWall(num3, num4))
			{
				return true;
			}
		}
		return false;
	}

	public bool FillActions(PlayerActionSet __instance, ulong updateTick, float deltaTime)
	{
		if (!active || !GameManager.HasInstance || GameManager.Instance.IsPaused || (PlayerIndex == 0 && MultiplayerMenu.IsOpen))
		{
			return false;
		}
		if (!BraveInput.HasInstanceForPlayer(PlayerIndex) || !object.ReferenceEquals(BraveInput.GetInstanceForPlayer(PlayerIndex).ActiveActions, __instance))
		{
			return false;
		}
		GungeonActions val = (GungeonActions)(object)((__instance is GungeonActions) ? __instance : null);
		if (val == null || (object)actionsField == null)
		{
			return false;
		}
		inputTicks++;
		Dictionary<PlayerAction, float> dictionary = new Dictionary<PlayerAction, float>();
		dictionary[val.Left] = Mathf.Max(0f, 0f - move.x);
		dictionary[val.Right] = Mathf.Max(0f, move.x);
		dictionary[val.Down] = Mathf.Max(0f, 0f - move.y);
		dictionary[val.Up] = Mathf.Max(0f, move.y);
		dictionary[val.ShootAction] = (shoot ? 1f : 0f);
		dictionary[val.DodgeRollAction] = (dodge ? 1f : 0f);
		dictionary[val.ReloadAction] = (reload ? 1f : 0f);
		dictionary[val.InteractAction] = (interact ? 1f : 0f);
		dodge = false;
		reload = false;
		interact = false;
		List<PlayerAction> list = (List<PlayerAction>)actionsField.GetValue(__instance);
		for (int i = 0; i < list.Count; i++)
		{
			dictionary.TryGetValue(list[i], out var value);
			((OneAxisInputControl)list[i]).CommitWithValue(value, updateTick, deltaTime);
		}
		tickArgs[0] = updateTick;
		tickArgs[1] = deltaTime;
		List<PlayerOneAxisAction> list2 = (((object)oneAxisField != null) ? ((List<PlayerOneAxisAction>)oneAxisField.GetValue(__instance)) : null);
		if (list2 != null && (object)oneAxisUpdate != null)
		{
			foreach (PlayerOneAxisAction item in list2)
			{
				oneAxisUpdate.Invoke(item, tickArgs);
			}
		}
		List<PlayerTwoAxisAction> list3 = (((object)twoAxisField != null) ? ((List<PlayerTwoAxisAction>)twoAxisField.GetValue(__instance)) : null);
		if (list3 != null && (object)twoAxisUpdate != null)
		{
			foreach (PlayerTwoAxisAction item2 in list3)
			{
				twoAxisUpdate.Invoke(item2, tickArgs);
			}
		}
		return true;
	}
}
public static class Autopilot
{
	public static readonly Brain Self = new Brain(0, "us");

	private static readonly List<Brain> brains = new List<Brain> { Self };

	public static bool GunTour;

	public static bool Active => Self.Active;

	public static bool Explore
	{
		get
		{
			return Self.Explore;
		}
		set
		{
			Self.Explore = value;
		}
	}

	public static void Init(NetSession netSession, Harmony harmony)
	{
		Brain.SetSession(netSession);
		harmony.PatchAll(typeof(Autopilot));
	}

	public static void Start(bool keepOn)
	{
		Self.Start(keepOn);
	}

	public static void Stop(string why)
	{
		Self.Stop(why);
	}

	public static void Toggle()
	{
		Self.Toggle();
	}

	public static void Add(Brain b)
	{
		if (!brains.Contains(b))
		{
			brains.Add(b);
		}
	}

	public static void Remove(Brain b)
	{
		if (b != Self)
		{
			brains.Remove(b);
		}
	}

	public static void Update()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.TakeABreakKey != null && Input.GetKeyDown(Plugin.TakeABreakKey.Value) && !Self.Active)
		{
			Self.Start(keepOn: false);
			return;
		}
		for (int i = 0; i < brains.Count; i++)
		{
			brains[i].Update();
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerActionSet), "Update", new Type[]
	{
		typeof(ulong),
		typeof(float)
	})]
	private static bool BeforeActionsUpdate(PlayerActionSet __instance, ulong updateTick, float deltaTime)
	{
		for (int i = 0; i < brains.Count; i++)
		{
			if (brains[i].FillActions(__instance, updateTick, deltaTime))
			{
				return false;
			}
		}
		return true;
	}
}
public static class BeamSync
{
	private class Shown
	{
		public string Prefab;

		public BeamController Beam;

		public Vector2 Origin;

		public Vector2 Direction;

		public float LastHeard;
	}

	private const float SendInterval = 1f / 15f;

	private static NetSession session;

	private static readonly FieldInfo moduleDataField = AccessTools.Field(typeof(Gun), "m_moduleData");

	private static float nextSendAt;

	private static int lastSentCount;

	private static readonly List<Shown>[] shownBy = NewLists();

	private static List<Shown>[] NewLists()
	{
		List<Shown>[] array = new List<Shown>[4];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = new List<Shown>();
		}
		return array;
	}

	public static void Init(NetSession netSession)
	{
		session = netSession;
	}

	private static List<BeamController> OurBeams(PlayerController me)
	{
		List<BeamController> list = new List<BeamController>();
		Gun currentGun = ((GameActor)me).CurrentGun;
		if ((Object)(object)currentGun == (Object)null || (object)moduleDataField == null)
		{
			return list;
		}
		if (!(moduleDataField.GetValue(currentGun) is IDictionary dictionary))
		{
			return list;
		}
		foreach (object value in dictionary.Values)
		{
			ModuleShootData val = (ModuleShootData)((value is ModuleShootData) ? value : null);
			if (val != null && (Object)(object)val.beam != (Object)null && ((Behaviour)val.beam).isActiveAndEnabled)
			{
				list.Add(val.beam);
			}
		}
		return list;
	}

	public static void Update()
	{
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		if (session == null || session.Status != NetSession.State.Connected)
		{
			List<Shown>[] array = shownBy;
			foreach (List<Shown> shown in array)
			{
				Clear(shown);
			}
			return;
		}
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		List<Shown>[] array2 = shownBy;
		foreach (List<Shown> list in array2)
		{
			for (int num = list.Count - 1; num >= 0; num--)
			{
				Shown shown2 = list[num];
				if ((Object)(object)shown2.Beam == (Object)null || realtimeSinceStartup - shown2.LastHeard > 0.3f)
				{
					Stop(shown2);
					list.RemoveAt(num);
				}
				else
				{
					shown2.Beam.Origin = shown2.Origin;
					shown2.Beam.Direction = shown2.Direction;
					shown2.Beam.LateUpdatePosition(new Vector3(shown2.Origin.x, shown2.Origin.y, 0f));
				}
			}
		}
		if (realtimeSinceStartup < nextSendAt)
		{
			return;
		}
		nextSendAt = realtimeSinceStartup + 1f / 15f;
		PlayerController val = (GameManager.HasInstance ? GameManager.Instance.PrimaryPlayer : null);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		List<BeamController> beams = OurBeams(val);
		if (beams.Count == 0 && lastSentCount == 0)
		{
			return;
		}
		lastSentCount = beams.Count;
		int level = LevelSync.CurrentLevelCode();
		session.SendUnreliable(MsgType.Beams, delegate(BinaryWriter w)
		{
			//IL_005c: 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_007e: 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)
			w.Write(level);
			w.Write((byte)Mathf.Min(beams.Count, 8));
			for (int k = 0; k < beams.Count && k < 8; k++)
			{
				BeamController val2 = beams[k];
				w.Write(((Object)((Component)val2).gameObject).name.Replace("(Clone)", "").Trim());
				w.Write(val2.Origin.x);
				w.Write(val2.Origin.y);
				w.Write(val2.Direction.x);
				w.Write(val2.Direction.y);
			}
		});
	}

	public static void OnBeams(BinaryReader r)
	{
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		int num = r.ReadInt32();
		int num2 = r.ReadByte();
		PlayerController val = (GameManager.HasInstance ? GameManager.Instance.PrimaryPlayer : null);
		bool flag = (Object)(object)val != (Object)null && num == LevelSync.CurrentLevelCode() && !GameManager.Instance.IsLoadingLevel;
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		List<Shown> list = shownBy[Mathf.Clamp(session.From, 0, shownBy.Length - 1)];
		Vector2 origin = default(Vector2);
		Vector2 val2 = default(Vector2);
		for (int i = 0; i < num2; i++)
		{
			string text = r.ReadString();
			((Vector2)(ref origin))..ctor(r.ReadSingle(), r.ReadSingle());
			((Vector2)(ref val2))..ctor(r.ReadSingle(), r.ReadSingle());
			if (!flag)
			{
				continue;
			}
			Shown shown = ((i < list.Count) ? list[i] : null);
			if (shown != null && shown.Prefab != text)
			{
				Stop(shown);
				list.RemoveAt(i);
				shown = null;
			}
			if (shown == null)
			{
				BeamController val3 = Start(text, origin, val2, val);
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				shown = new Shown();
				shown.Prefab = text;
				shown.Beam = val3;
				list.Insert(Mathf.Min(i, list.Count), shown);
			}
			shown.Origin = origin;
			shown.Direction = val2;
			shown.LastHeard = realtimeSinceStartup;
		}
		for (int num3 = list.Count - 1; num3 >= num2; num3--)
		{
			Stop(list[num3]);
			list.RemoveAt(num3);
		}
	}

	private static BeamController Start(string prefabName, Vector2 origin, Vector2 dir, PlayerController me)
	{
		//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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = BulletSync.FindPrefab(prefabName);
		if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<BeamController>() == (Object)null)
		{
			return null;
		}
		try
		{
			GameObject val2 = SpawnManager.SpawnProjectile(val, new Vector3(origin.x, origin.y, 0f), Quaternion.identity, true);
			Projectile val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponent<Projectile>() : null);
			BeamController val4 = (((Object)(object)val2 != (Object)null) ? val2.GetComponent<BeamController>() : null);
			if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null)
			{
				return null;
			}
			val3.Owner = (GameActor)(object)me;
			val3.baseData.damage = 0f;
			val3.collidesWithEnemies = false;
			val3.collidesWithPlayer = false;
			val4.Owner = (GameActor)(object)me;
			val4.HitsPlayers = false;
			val4.HitsEnemies = false;
			val4.DamageModifier = 0f;
			val4.Direction = dir;
			val4.Origin = origin;
			return val4;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Couldn't show the partner's beam " + prefabName + ": " + ex.Message));
			return null;
		}
	}

	private static void Stop(Shown s)
	{
		if (s == null || (Object)(object)s.Beam == (Object)null)
		{
			return;
		}
		try
		{
			s.Beam.CeaseAttack();
		}
		catch
		{
			Object.Destroy((Object)(object)((Component)s.Beam).gameObject);
		}
	}

	private static void Clear(List<Shown> shown)
	{
		foreach (Shown item in shown)
		{
			Stop(item);
		}
		shown.Clear();
	}
}
public static class BlankSync
{
	private static NetSession session;

	private static bool triggeringRemote;

	public static void Init(NetSession netSession, Harmony harmony)
	{
		session = netSession;
		harmony.PatchAll(typeof(BlankSync));
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(SilencerInstance), "TriggerSilencer")]
	private static void AfterTriggerSilencer(Vector2 centerPoint, float expandSpeed, float maxRadius, GameObject silencerVFX, float distIntensity, float distRadius, float pushForce, float pushRadius, float knockbackForce, float knockbackRadius, float additionalTimeAtMaxRadius, PlayerController user, bool breaksWalls, bool skipBreakables)
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		if (triggeringRemote || session == null || session.Status != NetSession.State.Connected || (Object)(object)user == (Object)null || !GameManager.HasInstance)
		{
			return;
		}
		bool flag = StandIn.Active && (Object)(object)user == (Object)(object)StandIn.Player;
		if ((Object)(object)user != (Object)(object)GameManager.Instance.PrimaryPlayer && !flag)
		{
			return;
		}
		if (flag)
		{
			Protocol.SendAs = StandIn.Slot;
		}
		try
		{
			SendBlank(centerPoint, expandSpeed, maxRadius, silencerVFX, distIntensity, distRadius, pushForce, pushRadius, knockbackForce, knockbackRadius, additionalTimeAtMaxRadius, breaksWalls, skipBreakables);
		}
		finally
		{
			Protocol.SendAs = -1;
		}
	}

	private static void SendBlank(Vector2 centerPoint, float expandSpeed, float maxRadius, GameObject silencerVFX, float distIntensity, float distRadius, float pushForce, float pushRadius, float knockbackForce, float knockbackRadius, float additionalTimeAtMaxRadius, bool breaksWalls, bool skipBreakables)
	{
		//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)
		bool ghostVfx = (Object)(object)silencerVFX != (Object)null && ((Object)silencerVFX).name.Contains("Ghost");
		bool anyVfx = (Object)(object)silencerVFX != (Object)null;
		string level = LevelSync.CurrentLevelKey();
		session.SendReliable(MsgType.Blank, delegate(BinaryWriter w)
		{
			w.Write(level);
			w.Write(centerPoint.x);
			w.Write(centerPoint.y);
			w.Write(expandSpeed);
			w.Write(maxRadius);
			w.Write(anyVfx);
			w.Write(ghostVfx);
			w.Write(distIntensity);
			w.Write(distRadius);
			w.Write(pushForce);
			w.Write(pushRadius);
			w.Write(knockbackForce);
			w.Write(knockbackRadius);
			w.Write(additionalTimeAtMaxRadius);
			w.Write(breaksWalls);
			w.Write(skipBreakables);
		});
	}

	public static void OnBlank(BinaryReader r)
	{
		//IL_00fe: 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)
		string text = r.ReadString();
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(r.ReadSingle(), r.ReadSingle());
		float num = r.ReadSingle();
		float num2 = r.ReadSingle();
		bool flag = r.ReadBoolean();
		bool flag2 = r.ReadBoolean();
		float num3 = r.ReadSingle();
		float num4 = r.ReadSingle();
		float num5 = r.ReadSingle();
		float num6 = r.ReadSingle();
		float num7 = r.ReadSingle();
		float num8 = r.ReadSingle();
		float num9 = r.ReadSingle();
		bool flag3 = r.ReadBoolean();
		bool flag4 = r.ReadBoolean();
		PlayerController val2 = (GameManager.HasInstance ? GameManager.Instance.Pr