Decompiled source of ArenaRoyalePvP v1.0.1

BepInEx\plugins\ArenaRoyale\ArenaRoyale.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ArenaRoyaleLocal;
using BepInEx;
using BepInEx.Logging;
using DM;
using Dummiesman;
using GamepadUI.StateManager.Core;
using HarmonyLib;
using InControl;
using Landfall.TABC;
using Landfall.TABS;
using Landfall.TABS.AI;
using Landfall.TABS.AI.Components;
using Landfall.TABS.AI.Components.Modifiers;
using Landfall.TABS.AI.Components.Tags;
using Landfall.TABS.AI.Systems;
using Landfall.TABS.AI.Systems.Modifiers;
using Landfall.TABS.GameMode;
using Landfall.TABS.GameState;
using Landfall.TABS.RuntimeCleanup;
using Landfall.TABS.Services;
using Landfall.TABS.TeamEdge;
using Landfall.TABS.UnitEditor;
using Landfall.TABS.UnitPlacement;
using Landfall.TABS.WinConditions;
using Landfall.TABS.Workshop;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pathfinding;
using TFBGames;
using TMPro;
using Tabs.PersistentHealth.Mod;
using ToyBox;
using UIStateManager;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("ArenaRoyale")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ArenaRoyale")]
[assembly: AssemblyTitle("ArenaRoyale")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[HarmonyPatch(typeof(Explosion), "Explode")]
internal static class ArenaAbilityStun
{
	private static readonly HashSet<Unit> struck = new HashSet<Unit>();

	private static void Postfix(Explosion __instance)
	{
		//IL_0015: 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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		if (!ArenaRoyale.Selected || !Object.op_Implicit((Object)(object)__instance) || !ArenaSpellSimulation.Active(((Component)__instance).gameObject.scene))
		{
			return;
		}
		TeamHolder componentInParent = ((Component)__instance).GetComponentInParent<TeamHolder>();
		Unit val = ((Object.op_Implicit((Object)(object)componentInParent) && Object.op_Implicit((Object)(object)componentInParent.spawner)) ? componentInParent.spawner.GetComponentInParent<Unit>() : ((Component)__instance).GetComponentInParent<Unit>());
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		float abilityStun = RoyaleUnitSettings.For(val.unitBlueprint).AbilityStun;
		if (!(abilityStun > 0f))
		{
			return;
		}
		struck.Clear();
		Collider[] array = Physics.OverlapSphere(((Component)__instance).transform.position, __instance.radius, LayerMask.op_Implicit(__instance.layerMask));
		for (int i = 0; i < array.Length; i++)
		{
			Unit componentInParent2 = ((Component)array[i]).GetComponentInParent<Unit>();
			if (!Object.op_Implicit((Object)(object)componentInParent2) || componentInParent2.Team == val.Team || !struck.Add(componentInParent2) || !Object.op_Implicit((Object)(object)componentInParent2.data) || componentInParent2.data.Dead || !Object.op_Implicit((Object)(object)componentInParent2.data.mainRig) || ArenaHealingTargets.IsBuilding(componentInParent2) || ArenaTowerDefender.Is(componentInParent2) || ArenaMummyCaptive.Is(componentInParent2) || ArenaPreviewNative.IsSample((Component)(object)componentInParent2) || Object.op_Implicit((Object)(object)((Component)componentInParent2).GetComponent<ArenaSpellBody>()))
			{
				continue;
			}
			List<Rigidbody> list = new List<Rigidbody>();
			Rigidbody[] componentsInChildren = ((Component)componentInParent2).GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody val2 in componentsInChildren)
			{
				if ((Object)(object)((Component)val2).GetComponentInParent<Unit>() == (Object)(object)componentInParent2)
				{
					list.Add(val2);
				}
			}
			ArenaBoulderStatus.Get(componentInParent2, list.ToArray()).Stun(abilityStun);
		}
		struck.Clear();
	}
}
[HarmonyPatch(typeof(DodgeMove), "GetDirection")]
internal static class ArenaBarrelBridgeSteering
{
	private static void Postfix(DodgeMove __instance, CombatMoveDataInstance move, Rigidbody ownRig, DataHandler ___data, ref Vector3 __result)
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Invalid comparison between Unknown and I4
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Invalid comparison between Unknown and I4
		//IL_0093: 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_00aa: Invalid comparison between Unknown and I4
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: 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_00e1: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		if (!ArenaRoyale.Selected || !Object.op_Implicit((Object)(object)ArenaSession.Current) || !ArenaSession.Current.Ready || !Object.op_Implicit((Object)(object)__instance) || __instance.IsRemotelyControlled || !Object.op_Implicit((Object)(object)ownRig) || !Object.op_Implicit((Object)(object)___data) || ___data.Dead || !Object.op_Implicit((Object)(object)___data.mainRig) || !Object.op_Implicit((Object)(object)___data.targetMainRig) || move == null || ((int)move.forceDirection != 12 && (int)move.forceDirection != 13))
		{
			return;
		}
		Unit unit = ___data.unit;
		if (ArenaBarrelRoller.Scoped(unit) && ArenaBarrelDamage.IsBarrel((Component)(object)__instance) && ArenaBarrelNavigation.Direction(unit, ___data.lookDirectionIntent, out var direction))
		{
			if ((int)move.forceDirection == 12)
			{
				__result = direction;
				return;
			}
			Vector3 val = Vector3.Cross(((Component)ownRig).transform.forward, direction);
			__result = ((Vector3)(ref val)).normalized * Vector3.Angle(((Component)ownRig).transform.forward, direction);
		}
	}
}
internal static class ArenaBarrelDamage
{
	internal struct Scope
	{
		internal Unit Previous;

		internal Team? PreviousTeam;

		internal Explosion Explosion;

		internal bool IgnoreRoot;

		internal bool IgnoreTeamMates;

		internal Explosion PreviousExplosion;
	}

	[ThreadStatic]
	private static Unit owner;

	[ThreadStatic]
	private static Team? team;

	[ThreadStatic]
	private static Explosion activeExplosion;

	internal static Unit Owner
	{
		get
		{
			if (!ArenaRoyale.Selected)
			{
				return null;
			}
			return owner;
		}
	}

	internal static bool IsBarrel(Component source)
	{
		if (!Object.op_Implicit((Object)(object)source))
		{
			return false;
		}
		Transform val = source.transform;
		while (Object.op_Implicit((Object)(object)val))
		{
			string name = ((Object)val).name;
			if (name.IndexOf("ExplosionBombBarrel", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("BarrelE_Explosion", StringComparison.OrdinalIgnoreCase) >= 0 || name.StartsWith("BarrelArmor_", StringComparison.OrdinalIgnoreCase) || name.StartsWith("Wings_Leg_BarrelRoller", StringComparison.OrdinalIgnoreCase) || name.StartsWith("StayCombatFix_BarrelExplosion", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	internal static Unit SourceUnit(Component source)
	{
		TeamHolder val = (Object.op_Implicit((Object)(object)source) ? source.GetComponentInParent<TeamHolder>() : null);
		Unit val2 = ((Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.spawner)) ? val.spawner.GetComponentInParent<Unit>() : null);
		ArenaTowerProjectile arenaTowerProjectile = (Object.op_Implicit((Object)(object)source) ? source.GetComponentInParent<ArenaTowerProjectile>() : null);
		if (!Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)arenaTowerProjectile))
		{
			val2 = arenaTowerProjectile.Shot.Shooter;
		}
		if (!Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)source))
		{
			val2 = source.GetComponentInParent<Unit>();
		}
		return val2;
	}

	internal static GameObject Spawn(GameObject original, Vector3 position, Quaternion rotation, Component source)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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)
		if (!ArenaBarrelRoller.AllowSpawn(source, original))
		{
			return null;
		}
		GameObject val = Object.Instantiate<GameObject>(original, position, rotation);
		if (!ArenaRoyale.Selected || !Object.op_Implicit((Object)(object)original) || !IsBarrel((Component)(object)original.transform))
		{
			return val;
		}
		Unit val2 = SourceUnit(source);
		if (!Object.op_Implicit((Object)(object)val2))
		{
			return val;
		}
		TeamHolder val3 = val.GetComponent<TeamHolder>();
		if (!Object.op_Implicit((Object)(object)val3))
		{
			val3 = val.AddComponent<TeamHolder>();
		}
		val3.team = val2.Team;
		val3.spawner = ((Component)val2).gameObject;
		ArenaTowerShot.Capture(val, source);
		return val;
	}

	internal static Scope Begin(Explosion source)
	{
		//IL_0079: 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_00a4: 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_00a1: Invalid comparison between Unknown and I4
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		Scope result = new Scope
		{
			Previous = owner,
			PreviousTeam = team,
			PreviousExplosion = activeExplosion
		};
		owner = null;
		team = null;
		activeExplosion = null;
		if (!ArenaRoyale.Selected || !IsBarrel((Component)(object)source))
		{
			return result;
		}
		owner = SourceUnit((Component)(object)source);
		TeamHolder componentInParent = ((Component)source).GetComponentInParent<TeamHolder>();
		if (Object.op_Implicit((Object)(object)owner))
		{
			team = owner.Team;
		}
		else if (Object.op_Implicit((Object)(object)componentInParent) && ((int)componentInParent.team == 0 || (int)componentInParent.team == 1))
		{
			team = componentInParent.team;
		}
		else
		{
			ArenaTowerProjectile componentInParent2 = ((Component)source).GetComponentInParent<ArenaTowerProjectile>();
			if (Object.op_Implicit((Object)(object)componentInParent2) && componentInParent2.Shot.HasTeam)
			{
				team = componentInParent2.Shot.SourceTeam;
			}
		}
		if (!team.HasValue)
		{
			return result;
		}
		result.Explosion = source;
		result.IgnoreRoot = source.ignoreRoot;
		result.IgnoreTeamMates = source.ignoreTeamMates;
		activeExplosion = source;
		IncludeCaster();
		return result;
	}

	internal static void End(Scope state)
	{
		if (Object.op_Implicit((Object)(object)state.Explosion))
		{
			state.Explosion.ignoreRoot = state.IgnoreRoot;
			state.Explosion.ignoreTeamMates = state.IgnoreTeamMates;
		}
		owner = state.Previous;
		team = state.PreviousTeam;
		activeExplosion = state.PreviousExplosion;
	}

	internal static bool SelfHit(Unit victim, Unit damager)
	{
		if (Object.op_Implicit((Object)(object)Owner) && (Object)(object)victim == (Object)(object)owner)
		{
			if (Object.op_Implicit((Object)(object)damager))
			{
				return (Object)(object)damager == (Object)(object)owner;
			}
			return true;
		}
		return false;
	}

	internal static bool SelfHit(Damagable victim, Unit damager, Explosion source)
	{
		if (ArenaRoyale.Selected && Object.op_Implicit((Object)(object)source) && (Object)(object)source == (Object)(object)activeExplosion && Object.op_Implicit((Object)(object)victim))
		{
			return SelfHit(((Component)victim).GetComponentInParent<Unit>(), damager);
		}
		return false;
	}

	private static void IncludeCaster()
	{
		if (ArenaRoyale.Selected && Object.op_Implicit((Object)(object)activeExplosion) && team.HasValue)
		{
			activeExplosion.ignoreRoot = false;
			activeExplosion.ignoreTeamMates = false;
		}
	}

	internal static Collider[] Filter(Collider[] hits)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		Unit source = Owner;
		if (!ArenaRoyale.Selected || !team.HasValue)
		{
			return hits;
		}
		IncludeCaster();
		ArenaBarrelRoller.Queried(activeExplosion);
		Team sourceTeam = team.Value;
		return Array.FindAll(hits, delegate(Collider collider)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)collider))
			{
				return true;
			}
			ArenaTower arenaTower = ArenaFriendlyTowerCombat.TowerOf(collider);
			Unit val = (Object.op_Implicit((Object)(object)arenaTower) ? arenaTower.Unit : ((Component)collider).GetComponentInParent<Unit>());
			return !Object.op_Implicit((Object)(object)val) || (Object)(object)val == (Object)(object)source || val.Team != sourceTeam;
		});
	}
}
[HarmonyPatch(typeof(Explosion), "Explode")]
internal static class ArenaBarrelExplosionPatch
{
	[HarmonyPriority(0)]
	private static bool Prefix(Explosion __instance, out ArenaBarrelDamage.Scope __state)
	{
		__state = ArenaBarrelDamage.Begin(__instance);
		return ArenaBarrelRoller.AllowExplosion(__instance);
	}

	private static Exception Finalizer(Exception __exception, ArenaBarrelDamage.Scope __state)
	{
		try
		{
			if (__exception == null)
			{
				ArenaBarrelRoller.Complete(__state.Explosion);
			}
		}
		finally
		{
			ArenaBarrelDamage.End(__state);
		}
		return __exception;
	}
}
[HarmonyPatch(typeof(RemoveAfterSeconds), "TriggerRemoval")]
internal static class ArenaBarrelRemovalSpawnPatch
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		return Rewrite(instructions);
	}

	internal static IEnumerable<CodeInstruction> Rewrite(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo replacement = AccessTools.Method(typeof(ArenaBarrelDamage), "Spawn", (Type[])null, (Type[])null);
		int found = 0;
		foreach (CodeInstruction instruction in instructions)
		{
			if (instruction.operand is MethodInfo methodInfo && methodInfo.DeclaringType == typeof(Object) && methodInfo.Name == "Instantiate" && methodInfo.ReturnType == typeof(GameObject) && methodInfo.GetParameters().Length == 3 && methodInfo.GetParameters()[1].ParameterType == typeof(Vector3) && methodInfo.GetParameters()[2].ParameterType == typeof(Quaternion))
			{
				yield return new CodeInstruction(instruction)
				{
					opcode = OpCodes.Ldarg_0,
					operand = null
				};
				yield return new CodeInstruction(OpCodes.Call, (object)replacement);
				found++;
			}
			else
			{
				yield return instruction;
			}
		}
		if (found != 2)
		{
			throw new InvalidOperationException("Arena Royale: native barrel removal spawn changed; ownership hook could not be installed safely.");
		}
	}
}
[HarmonyPatch(typeof(KillAfterSeconds), "Spawn")]
internal static class ArenaBarrelTimedSpawnPatch
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		return ArenaBarrelRemovalSpawnPatch.Rewrite(instructions);
	}
}
internal static class ArenaBarrelDetonation
{
	internal static bool Consume(bool allowed, bool queried, bool consumed, bool validCaster)
	{
		return allowed && queried && !consumed && validCaster;
	}
}
[HarmonyPatch]
internal static class ArenaBarrelDetonationCompatibility
{
	private static Type Kind => AccessTools.TypeByName("StayCombatFix.BarrelRollerDeathLogic");

	private static MethodBase Find()
	{
		return Kind?.GetMethod("TryBlockDuplicateBarrelExplosion", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[1] { typeof(Explosion) }, null);
	}

	private static bool Prepare()
	{
		return Find() != null;
	}

	private static MethodBase TargetMethod()
	{
		return Find();
	}

	private static bool Prefix(Explosion explosion, ref bool __result)
	{
		if (!ArenaRoyale.Selected || !Object.op_Implicit((Object)(object)explosion) || !ArenaBarrelDamage.IsBarrel((Component)(object)explosion))
		{
			return true;
		}
		Unit val = ArenaBarrelDamage.SourceUnit((Component)(object)explosion);
		if (!ArenaBarrelRoller.Scoped(val))
		{
			return true;
		}
		ArenaBarrelBlastPermit arenaBarrelBlastPermit = ((Component)explosion).GetComponent<ArenaBarrelBlastPermit>();
		if (!Object.op_Implicit((Object)(object)arenaBarrelBlastPermit))
		{
			arenaBarrelBlastPermit = ((Component)explosion).gameObject.AddComponent<ArenaBarrelBlastPermit>();
		}
		__result = arenaBarrelBlastPermit.DedupSeen;
		arenaBarrelBlastPermit.DedupSeen = true;
		if (!__result)
		{
			AccessTools.Method(Kind, "MarkRecentBarrelExplosion", new Type[1] { typeof(Transform) }, (Type[])null)?.Invoke(null, new object[1] { ((Component)val).transform });
		}
		return false;
	}
}
internal static class ArenaBarrelNavigation
{
	private sealed class Route
	{
		internal Unit Target;

		internal Vector3 From;

		internal Vector3 Goal;

		internal float NextCheck;

		internal bool Clear;
	}

	private static readonly ConditionalWeakTable<Unit, Route> routes = new ConditionalWeakTable<Unit, Route>();

	internal static bool Direction(Unit actor, Vector3 native, out Vector3 direction)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: 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_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: 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_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: 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_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: 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_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		direction = Vector3.zero;
		if (!ArenaBarrelRoller.Scoped(actor) || !Object.op_Implicit((Object)(object)actor.data) || actor.data.Dead || !Object.op_Implicit((Object)(object)actor.data.mainRig) || !Object.op_Implicit((Object)(object)actor.api) || !actor.api.Active || actor.api.IsRemotelyControlled || ArenaBoulderStatus.Blocks(actor))
		{
			return false;
		}
		ArenaUnitDeployment component = ((Component)actor).GetComponent<ArenaUnitDeployment>();
		if (Object.op_Implicit((Object)(object)component) && component.Waiting)
		{
			return false;
		}
		Unit val = (Object.op_Implicit((Object)(object)actor.data.targetData) ? ((Component)actor.data.targetData).GetComponentInParent<Unit>() : null);
		if (!ArenaBarrelRoller.Approaching(actor, val))
		{
			return false;
		}
		if (ArenaBuildingNavigation.Direction(actor.api, out var _, out direction))
		{
			return ((Vector3)(ref direction)).sqrMagnitude > 0.001f;
		}
		Vector3 position = actor.data.mainRig.position;
		Vector3 val2 = ArenaBarrelRoller.Aim(val, position);
		GameObjectEntity component2 = ((Component)actor).GetComponent<GameObjectEntity>();
		Vector3 waypoint;
		bool flag = ArenaBridgeGuidance.TryWaypoint(Object.op_Implicit((Object)(object)component2) ? component2.Entity : Entity.Null, position, val2, out waypoint);
		if (flag)
		{
			val2 = waypoint;
		}
		Vector3 val3 = val2 - position;
		val3.y = 0f;
		Route value = routes.GetValue(actor, (Unit key) => new Route());
		if (!((Object)(object)value.Target != (Object)(object)val) && !(Time.time >= value.NextCheck))
		{
			Vector3 val4 = position - value.From;
			if (!(((Vector3)(ref val4)).sqrMagnitude > 0.1225f))
			{
				val4 = val2 - value.Goal;
				if (!(((Vector3)(ref val4)).sqrMagnitude > 0.04f))
				{
					goto IL_0226;
				}
			}
		}
		value.Target = val;
		value.From = position;
		value.Goal = val2;
		value.NextCheck = Time.time + 0.12f;
		Vector3 val5 = val2;
		if (!flag)
		{
			val5 -= ((Vector3)(ref val3)).normalized * Mathf.Min(1.2f, ((Vector3)(ref val3)).magnitude * 0.5f);
		}
		value.Clear = Clear(position, val5);
		goto IL_0226;
		IL_0226:
		native.y = 0f;
		direction = (value.Clear ? val3 : native);
		if (((Vector3)(ref direction)).sqrMagnitude < 0.001f)
		{
			return false;
		}
		((Vector3)(ref direction)).Normalize();
		return true;
	}

	private static bool Clear(Vector3 from, Vector3 to)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		AstarPath active = AstarPath.active;
		if (!Object.op_Implicit((Object)(object)active))
		{
			return false;
		}
		from.y = (to.y = 12.088128f);
		GraphNode node = active.GetNearest(from).node;
		if (node == null || !node.Walkable || node.GraphIndex >= active.graphs.Length)
		{
			return false;
		}
		NavGraph obj = active.graphs[node.GraphIndex];
		IRaycastableGraph val = (IRaycastableGraph)(object)((obj is IRaycastableGraph) ? obj : null);
		if (val != null)
		{
			return !val.Linecast(from, to, node);
		}
		return false;
	}
}
[HarmonyPatch(typeof(UnitAPI), "SetLookDirection")]
internal static class ArenaBarrelHeadingPatch
{
	[HarmonyPriority(0)]
	private static void Prefix(UnitAPI __instance, ref Vector3 localDirection)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		if (ArenaRoyale.Selected && Object.op_Implicit((Object)(object)__instance) && ArenaBarrelNavigation.Direction(ArenaUnitAccess.Actor(__instance), localDirection, out var direction))
		{
			localDirection = direction;
		}
	}
}
[HarmonyPatch(typeof(UnitAPI), "SetMovementSpeed")]
internal static class ArenaBarrelAdvancePatch
{
	[HarmonyPriority(0)]
	private static void Prefix(UnitAPI __instance, ref float __0)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		if (ArenaRoyale.Selected && Object.op_Implicit((Object)(object)__instance))
		{
			Unit val = ArenaUnitAccess.Actor(__instance);
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.data) && ArenaBarrelNavigation.Direction(val, val.data.lookDirectionIntent, out var _))
			{
				__0 = 1f;
			}
		}
	}
}
internal static class ArenaBarrelRoller
{
	private sealed class Kind
	{
		internal UnitBlueprint Blueprint;

		internal bool Roller;
	}

	private static readonly ConditionalWeakTable<Unit, Kind> kinds = new ConditionalWeakTable<Unit, Kind>();

	private static readonly List<Unit> objectives = new List<Unit>();

	private const float RetargetMargin = 1.5f;

	internal static bool IsRoller(Unit unit)
	{
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)unit))
		{
			return false;
		}
		Kind value = kinds.GetValue(unit, (Unit key) => new Kind());
		if ((Object)(object)value.Blueprint == (Object)(object)unit.unitBlueprint && Object.op_Implicit((Object)(object)value.Blueprint))
		{
			return value.Roller;
		}
		value.Blueprint = unit.unitBlueprint;
		value.Roller = false;
		if (Object.op_Implicit((Object)(object)unit.unitBlueprint) && unit.unitBlueprint.Entity.GUID.m_ID == 846602731)
		{
			value.Roller = true;
		}
		else
		{
			DodgeMove[] componentsInChildren = ((Component)unit).GetComponentsInChildren<DodgeMove>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				if (ArenaBarrelDamage.IsBarrel((Component)(object)componentsInChildren[num]))
				{
					value.Roller = true;
					break;
				}
			}
		}
		return value.Roller;
	}

	internal static bool Scoped(Unit unit)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		if (ArenaRoyale.Selected && Object.op_Implicit((Object)(object)ArenaSession.Current) && ArenaSession.Current.Ready && Object.op_Implicit((Object)(object)unit) && ((Component)unit).gameObject.scene == ((Component)ArenaSession.Current).gameObject.scene && IsRoller(unit))
		{
			return !ArenaPreviewNative.IsSample((Component)(object)unit);
		}
		return false;
	}

	internal static bool Building(Unit unit)
	{
		if (Object.op_Implicit((Object)(object)unit))
		{
			if (!Object.op_Implicit((Object)(object)((Component)unit).GetComponent<ArenaTower>()) && !Object.op_Implicit((Object)(object)((Component)unit).GetComponent<ArenaPlaceableBuilding>()))
			{
				return BuildingKinds.Stationary(unit);
			}
			return true;
		}
		return false;
	}

	internal static bool Eligible(Unit actor, Unit target)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)actor) || !Object.op_Implicit((Object)(object)target) || (Object)(object)actor == (Object)(object)target || actor.Team == target.Team || !Object.op_Implicit((Object)(object)target.data) || target.data.Dead || !Object.op_Implicit((Object)(object)target.data.mainRig) || !((Component)target).gameObject.activeInHierarchy || ((Component)actor).gameObject.scene != ((Component)target).gameObject.scene || ArenaPreviewNative.IsSample((Component)(object)target) || ArenaTowerDefender.Is(target) || !Building(target))
		{
			return false;
		}
		ArenaTower component = ((Component)target).GetComponent<ArenaTower>();
		if (Object.op_Implicit((Object)(object)component) && component.Destroyed)
		{
			return false;
		}
		ArenaPlaceableBuilding component2 = ((Component)target).GetComponent<ArenaPlaceableBuilding>();
		if (Object.op_Implicit((Object)(object)component2))
		{
			return component2.Alive;
		}
		return true;
	}

	internal static Vector3 Aim(Unit target, Vector3 from)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0037: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		ArenaTower component = ((Component)target).GetComponent<ArenaTower>();
		if (Object.op_Implicit((Object)(object)component))
		{
			return component.AimPoint(from);
		}
		ArenaPlaceableBuilding component2 = ((Component)target).GetComponent<ArenaPlaceableBuilding>();
		if (Object.op_Implicit((Object)(object)component2))
		{
			return component2.AimPoint(from);
		}
		Bounds val = ArenaLargeUnitBody.Bounds(target);
		return ((Bounds)(ref val)).ClosestPoint(from);
	}

	internal static float Distance(Unit actor, Unit target)
	{
		//IL_000b: 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)
		return Vector3.Distance(actor.data.mainRig.position, Aim(target, actor.data.mainRig.position));
	}

	private static bool Attackable(Unit actor, Unit target)
	{
		ArenaTower component = ((Component)target).GetComponent<ArenaTower>();
		if (Object.op_Implicit((Object)(object)component) && !component.CanBeAttackedBy(actor))
		{
			return false;
		}
		ArenaPlaceableBuilding component2 = ((Component)target).GetComponent<ArenaPlaceableBuilding>();
		if (Object.op_Implicit((Object)(object)component2))
		{
			return component2.CanBeAttackedBy(actor);
		}
		return true;
	}

	internal static void Arm(Unit actor, Unit target)
	{
		if (!Scoped(actor) || !Object.op_Implicit((Object)(object)actor.data) || actor.data.Dead || !Object.op_Implicit((Object)(object)actor.data.mainRig) || !Eligible(actor, target) || !Attackable(actor, target))
		{
			return;
		}
		ArenaUnitDeployment component = ((Component)actor).GetComponent<ArenaUnitDeployment>();
		if ((!Object.op_Implicit((Object)(object)component) || !component.Waiting) && !(Distance(actor, target) > Mathf.Max(0f, actor.m_AttackDistance) + 0.05f))
		{
			ArenaBarrelFuse arenaBarrelFuse = ((Component)actor).GetComponent<ArenaBarrelFuse>();
			if (!Object.op_Implicit((Object)(object)arenaBarrelFuse))
			{
				arenaBarrelFuse = ((Component)actor).gameObject.AddComponent<ArenaBarrelFuse>();
			}
			arenaBarrelFuse.ArmedUntil = Time.time + 2f;
			arenaBarrelFuse.Target = target;
		}
	}

	internal static bool Armed(Unit actor)
	{
		ArenaBarrelFuse arenaBarrelFuse = (Object.op_Implicit((Object)(object)actor) ? ((Component)actor).GetComponent<ArenaBarrelFuse>() : null);
		if (Scoped(actor) && Object.op_Implicit((Object)(object)arenaBarrelFuse) && Object.op_Implicit((Object)(object)arenaBarrelFuse.Target))
		{
			return arenaBarrelFuse.ArmedUntil >= Time.time;
		}
		return false;
	}

	internal static bool AllowSpawn(Component source, GameObject prefab)
	{
		if (!ArenaRoyale.Selected || !Object.op_Implicit((Object)(object)prefab) || !ArenaBarrelDamage.IsBarrel((Component)(object)prefab.transform))
		{
			return true;
		}
		Unit val = ArenaBarrelDamage.SourceUnit(source);
		if (Scoped(val))
		{
			return Armed(val);
		}
		return true;
	}

	internal static bool AllowExplosion(Explosion explosion)
	{
		if (!ArenaRoyale.Selected || !ArenaBarrelDamage.IsBarrel((Component)(object)explosion))
		{
			return true;
		}
		Unit val = ArenaBarrelDamage.SourceUnit((Component)(object)explosion);
		if (!Scoped(val))
		{
			return true;
		}
		ArenaBarrelBlastPermit arenaBarrelBlastPermit = ((Component)explosion).GetComponent<ArenaBarrelBlastPermit>();
		if (Object.op_Implicit((Object)(object)arenaBarrelBlastPermit) && arenaBarrelBlastPermit.Evaluated)
		{
			return arenaBarrelBlastPermit.Allowed;
		}
		if (!Object.op_Implicit((Object)(object)arenaBarrelBlastPermit))
		{
			arenaBarrelBlastPermit = ((Component)explosion).gameObject.AddComponent<ArenaBarrelBlastPermit>();
		}
		arenaBarrelBlastPermit.Evaluated = true;
		arenaBarrelBlastPermit.Allowed = Armed(val);
		if (arenaBarrelBlastPermit.Allowed)
		{
			arenaBarrelBlastPermit.Caster = val;
			((Component)val).GetComponent<ArenaBarrelFuse>().ArmedUntil = float.NegativeInfinity;
		}
		return arenaBarrelBlastPermit.Allowed;
	}

	internal static IEnumerator GuardSpawn(SpawnObject source, IEnumerator native)
	{
		try
		{
			while (Object.op_Implicit((Object)(object)source) && AllowSpawn((Component)(object)source, source.objectToSpawn) && native.MoveNext())
			{
				yield return native.Current;
			}
		}
		finally
		{
			(native as IDisposable)?.Dispose();
		}
	}

	private static bool Link(Unit unit, EntityManager manager, out Entity entity)
	{
		//IL_0023: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		GameObjectEntity val = (Object.op_Implicit((Object)(object)unit) ? ((Component)unit).GetComponent<GameObjectEntity>() : null);
		entity = (Object.op_Implicit((Object)(object)val) ? val.Entity : Entity.Null);
		if (Object.op_Implicit((Object)(object)val) && manager.Exists(entity))
		{
			return !manager.HasComponent<IsInPool>(entity);
		}
		return false;
	}

	internal static void Refresh(JobHandle dependency)
	{
		//IL_019d: 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_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: 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)
		//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0402: Unknown result type (might be due to invalid IL or missing references)
		//IL_0406: Unknown result type (might be due to invalid IL or missing references)
		//IL_0418: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_036b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0385: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0469: 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_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
		if (!ArenaRoyale.Selected || !Object.op_Implicit((Object)(object)ArenaSession.Current) || !ArenaSession.Current.Ready || World.Active == null)
		{
			return;
		}
		TeamSystem existingManager = World.Active.GetExistingManager<TeamSystem>();
		EntityManager existingManager2 = World.Active.GetExistingManager<EntityManager>();
		if (existingManager == null || existingManager2 == null)
		{
			return;
		}
		List<Unit> allUnits = existingManager.GetAllUnits();
		bool flag = false;
		foreach (Unit item in allUnits)
		{
			if (Scoped(item) && Object.op_Implicit((Object)(object)item.data) && !item.data.Dead)
			{
				flag = true;
				break;
			}
		}
		if (!flag)
		{
			return;
		}
		((JobHandle)(ref dependency)).Complete();
		objectives.Clear();
		Entity entity;
		foreach (Unit item2 in allUnits)
		{
			if (Building(item2) && Object.op_Implicit((Object)(object)item2.data) && !item2.data.Dead && Object.op_Implicit((Object)(object)item2.data.mainRig) && Link(item2, existingManager2, out entity))
			{
				objectives.Add(item2);
			}
		}
		foreach (Unit item3 in allUnits)
		{
			if (!Scoped(item3) || !Object.op_Implicit((Object)(object)item3.data) || item3.data.Dead || !Object.op_Implicit((Object)(object)item3.data.mainRig) || !Link(item3, existingManager2, out var entity2) || !existingManager2.HasComponent<HasTargetTag>(entity2) || !existingManager2.HasComponent<TargetData>(entity2) || !existingManager2.HasComponent<Range>(entity2))
			{
				continue;
			}
			if (ArenaUnitDeployment.Deploying(item3))
			{
				ArenaSightRange.Blind(item3);
				ArenaBarrelFuse component = ((Component)item3).GetComponent<ArenaBarrelFuse>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.Objective = null;
				}
				continue;
			}
			ArenaBarrelFuse arenaBarrelFuse = ((Component)item3).GetComponent<ArenaBarrelFuse>();
			if (!Object.op_Implicit((Object)(object)arenaBarrelFuse))
			{
				arenaBarrelFuse = ((Component)item3).gameObject.AddComponent<ArenaBarrelFuse>();
			}
			Unit val = arenaBarrelFuse.Objective;
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = (Object.op_Implicit((Object)(object)item3.data.targetData) ? ((Component)item3.data.targetData).GetComponentInParent<Unit>() : null);
			}
			if (!Eligible(item3, val) || !Link(val, existingManager2, out entity))
			{
				val = null;
			}
			Unit val2 = null;
			float num = float.PositiveInfinity;
			float attackRange = existingManager2.GetComponentData<Range>(entity2).AttackRange;
			foreach (Unit objective in objectives)
			{
				if (Eligible(item3, objective))
				{
					float num2 = Distance(item3, objective);
					if ((!((Object)(object)objective != (Object)(object)val) || ArenaBridgeGuidance.Seen(objective, item3.data.mainRig.position, attackRange)) && num2 < num)
					{
						num = num2;
						val2 = objective;
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)val) || (Object.op_Implicit((Object)(object)val2) && (Object)(object)val2 != (Object)(object)val && num < Distance(item3, val) - 1.5f))
			{
				val = val2;
			}
			arenaBarrelFuse.Objective = val;
			Entity entity3 = Entity.Null;
			TargetData val3 = TargetData.Null;
			if (Object.op_Implicit((Object)(object)val) && Link(val, existingManager2, out entity3))
			{
				Range componentData = existingManager2.GetComponentData<Range>(entity2);
				float num3 = Distance(item3, val);
				bool flag2 = Attackable(item3, val);
				val3 = new TargetData
				{
					DistanceToTarget = num3,
					TargetInAttackRange = ((flag2 && num3 <= componentData.AttackRange) ? 1 : 0),
					TargetInPreferredRange = ((flag2 && num3 + 0.3f <= componentData.PreferredRange) ? 1 : 0)
				};
			}
			existingManager2.SetComponentData<HasTargetTag>(entity2, new HasTargetTag
			{
				Target = entity3
			});
			existingManager2.SetComponentData<TargetData>(entity2, val3);
			if (existingManager2.HasComponent<AttackThickness>(entity2))
			{
				existingManager2.SetComponentData<AttackThickness>(entity2, new AttackThickness
				{
					Value = 0f
				});
			}
			item3.data.targetData = (Object.op_Implicit((Object)(object)val) ? val.data : null);
			item3.data.targetMainRig = (Object.op_Implicit((Object)(object)val) ? val.data.mainRig : null);
			item3.data.distanceToTarget = val3.DistanceToTarget;
			item3.data.inRange = val3.TargetInAttackRange == 1;
			if (!Object.op_Implicit((Object)(object)val))
			{
				item3.data.CanSeeTarget = false;
				if (Object.op_Implicit((Object)(object)item3.Input))
				{
					item3.Input.inputDirection = Vector3.zero;
				}
			}
		}
	}

	internal static bool Approaching(Unit actor, Unit target)
	{
		if (Eligible(actor, target))
		{
			if (Attackable(actor, target))
			{
				return Distance(actor, target) > Mathf.Max(0f, actor.m_AttackDistance) + 0.05f;
			}
			return true;
		}
		return false;
	}

	internal static void Queried(Explosion explosion)
	{
		if (ArenaRoyale.Selected && Object.op_Implicit((Object)(object)explosion))
		{
			ArenaBarrelBlastPermit component = ((Component)explosion).GetComponent<ArenaBarrelBlastPermit>();
			if (Object.op_Implicit((Object)(object)component) && component.Allowed)
			{
				component.Queried = true;
			}
		}
	}

	internal static void Complete(Explosion explosion)
	{
		if (!ArenaRoyale.Selected || !Object.op_Implicit((Object)(object)explosion))
		{
			return;
		}
		ArenaBarrelBlastPermit component = ((Component)explosion).GetComponent<ArenaBarrelBlastPermit>();
		if (!Object.op_Implicit((Object)(object)component))
		{
			return;
		}
		Unit caster = component.Caster;
		bool validCaster = Scoped(caster) && Object.op_Implicit((Object)(object)caster.data);
		if (ArenaBarrelDetonation.Consume(component.Allowed, component.Queried, component.Consumed, validCaster))
		{
			component.Consumed = true;
			if (!caster.data.Dead)
			{
				caster.data.healthHandler.Die(caster);
			}
		}
	}
}
internal sealed class ArenaBarrelFuse : MonoBehaviour
{
	internal float ArmedUntil = float.NegativeInfinity;

	internal Unit Target;

	internal Unit Objective;

	private void OnDisable()
	{
		ArmedUntil = float.NegativeInfinity;
		Target = null;
		Objective = null;
	}
}
internal sealed class ArenaBarrelBlastPermit : MonoBehaviour
{
	internal bool Evaluated;

	internal bool Allowed;

	internal bool Queried;

	internal bool Consumed;

	internal bool DedupSeen;

	internal Unit Caster;

	private void OnDisable()
	{
		Evaluated = (Allowed = (Queried = (Consumed = (DedupSeen = false))));
		Caster = null;
	}
}
[HarmonyPatch(typeof(CanSeeSystem), "OnUpdate")]
internal static class ArenaBarrelBuildingTargetPatch
{
	[HarmonyPriority(600)]
	private static void Prefix(JobHandle inputDeps)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		ArenaBarrelRoller.Refresh(inputDeps);
	}
}
[HarmonyPatch(typeof(UnitAPI), "SetAttackTarget")]
internal static class ArenaBarrelTargetGuardPatch
{
	[HarmonyPriority(800)]
	private static bool Prefix(UnitAPI __instance, DataHandler unitData)
	{
		Unit val = ArenaUnitAccess.Actor(__instance);
		if (ArenaBarrelRoller.Scoped(val))
		{
			return ArenaBarrelRoller.Eligible(val, Object.op_Implicit((Object)(object)unitData) ? ((Component)unitData).GetComponentInParent<Unit>() : null);
		}
		return true;
	}
}
[HarmonyPatch(typeof(Unit), "Attack")]
internal static class ArenaBarrelBuildingAttackPatch
{
	[HarmonyPriority(0)]
	private static bool Prefix(Unit __instance, Rigidbody targetRig, float ___attackCounter, float ___lowestAttackTimeOfWeapons)
	{
		if (!ArenaBarrelRoller.Scoped(__instance))
		{
			return true;
		}
		Unit target = (Object.op_Implicit((Object)(object)targetRig) ? ((Component)targetRig).GetComponentInParent<Unit>() : null);
		if (!ArenaBarrelRoller.Eligible(__instance, target))
		{
			return false;
		}
		if (Object.op_Implicit((Object)(object)__instance.WeaponHandler) && !(___attackCounter * __instance.WeaponHandler.attackSpeedMultiplier < ___lowestAttackTimeOfWeapons / 2f))
		{
			ArenaBarrelRoller.Arm(__instance, target);
		}
		return true;
	}
}
[HarmonyPatch(typeof(SpawnObject), "SpawnUnit")]
internal static class ArenaBarrelAbilitySpawnPatch
{
	private static void Postfix(SpawnObject __instance, ref IEnumerator __result)
	{
		if (__result != null && ArenaRoyale.Selected && Object.op_Implicit((Object)(object)__instance.objectToSpawn) && ArenaBarrelDamage.IsBarrel((Component)(object)__instance.objectToSpawn.transform))
		{
			__result = ArenaBarrelRoller.GuardSpawn(__instance, __result);
		}
	}
}
[HarmonyPatch(typeof(ConditionalEvent), "CheckConditions")]
internal static class ArenaBarrelDeathConditionPatch
{
	[HarmonyPriority(800)]
	private static void Prefix(ConditionalEvent __instance, ConditionalEventInstance eventToCheck, ref bool forceFail)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Invalid comparison between Unknown and I4
		if (eventToCheck?.conditions == null || !ArenaBarrelRoller.Scoped(((Component)__instance).GetComponentInParent<Unit>()) || !ArenaBarrelDamage.IsBarrel((Component)(object)__instance))
		{
			return;
		}
		EventCondition[] conditions = eventToCheck.conditions;
		for (int i = 0; i < conditions.Length; i++)
		{
			if ((int)conditions[i].conditionType == 5)
			{
				forceFail = true;
				return;
			}
		}
		SpawnObject component = ((Component)__instance).GetComponent<SpawnObject>();
		if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.objectToSpawn) && ArenaBarrelDamage.IsBarrel((Component)(object)component.objectToSpawn.transform) && !ArenaBarrelRoller.Armed(((Component)__instance).GetComponentInParent<Unit>()))
		{
			forceFail = true;
		}
	}
}
[HarmonyPatch]
internal static class ArenaBarrelDeathQueuePatch
{
	private static MethodBase Find()
	{
		return AccessTools.TypeByName("StayCombatFix.BarrelRollerDeathLogic")?.GetMethod("TryScheduleFromScope", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[2]
		{
			typeof(Transform),
			typeof(string)
		}, null);
	}

	private static bool Prepare()
	{
		return Find() != null;
	}

	private static MethodBase TargetMethod()
	{
		return Find();
	}

	private static bool Prefix(Transform scope)
	{
		return !ArenaBarrelRoller.Scoped(Object.op_Implicit((Object)(object)scope) ? ((Component)scope).GetComponentInParent<Unit>() : null);
	}
}
[HarmonyPatch]
internal static class ArenaBarrelSelfDamageCompatibility
{
	private static MethodBase Find()
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			if (ArenaBetterTracing.Is(assembly))
			{
				return assembly.GetType("Tabs.PersistentHealth.Mod.WeaponExplosionDamage", throwOnError: false)?.GetMethod("TakeDamage", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[7]
				{
					typeof(Damagable),
					typeof(float),
					typeof(Vector3),
					typeof(Unit),
					typeof(DamageType),
					typeof(Explosion),
					typeof(bool)
				}, null);
			}
		}
		return null;
	}

	private static bool Prepare()
	{
		return Find() != null;
	}

	private static MethodBase TargetMethod()
	{
		return Find();
	}

	private static bool Prefix(Damagable target, float damage, Vector3 direction, Unit source, DamageType damageType, Explosion explosion)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (!(damage > 0f) || !ArenaBarrelDamage.SelfHit(target, source, explosion))
		{
			return true;
		}
		target.TakeDamage(damage, direction, source, damageType);
		return false;
	}
}
[DefaultExecutionOrder(30000)]
internal sealed class ArenaBarrierContainment : MonoBehaviour
{
	private sealed class State
	{
		internal Vector3 Previous;

		internal Vector3 Offset;

		internal Vector3 PreviousCorpseCentre;

		internal bool CorpseTracked;

		internal float HalfX;

		internal float HalfZ;

		internal bool Initialized;

		internal bool ShapeKnown;

		internal Unit Carrier;

		internal float BuriedSince = -1f;

		internal bool MeasuredLarge;

		internal Vector3 MeasuredScale;

		internal int FarPasses;

		internal readonly List<Unit> Riders = new List<Unit>();

		internal ArenaBarrierPolicy LargePolicy;

		internal readonly List<ArenaBarrierPolicy.Rect> Obstacles = new List<ArenaBarrierPolicy.Rect>();

		internal Rigidbody Ccd;

		internal Rigidbody Main;

		internal CollisionDetectionMode PreviousCcd;

		internal readonly ArenaLargeUnitBridgeCollisions Bridge = new ArenaLargeUnitBridgeCollisions();

		internal readonly ArenaIceGiantTowerPassage Towers = new ArenaIceGiantTowerPassage();

		internal void RestoreCcd()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Ccd) && (int)Ccd.collisionDetectionMode == 2)
			{
				Ccd.collisionDetectionMode = PreviousCcd;
			}
			Ccd = null;
		}

		internal void Restore()
		{
			RestoreCcd();
			Bridge.Restore();
			Towers.Restore();
		}
	}

	private readonly Dictionary<Unit, State> states = new Dictionary<Unit, State>();

	private readonly HashSet<Unit> pending = new HashSet<Unit>();

	private readonly List<Unit> removed = new List<Unit>();

	private ArenaNativeWater environment;

	private ArenaBarrierPolicy policy;

	private const float FieldSurfaceY = 12f;

	private const float FloorRescueY = 11.6f;

	private const float FieldInnerX = 2.3f;

	private const float BuriedDepth = 0.3f;

	private const float FarPose = 1.5f;

	private const int FarMaxPasses = 3;

	internal static ArenaBarrierContainment Current { get; private set; }

	internal void Initialize(ArenaNativeWater owner)
	{
		environment = owner;
		policy = ArenaBarrierPolicy.Create(0.7344f);
		Current = this;
	}

	internal static bool Allows(Vector3 point, float halfX, float halfZ)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)Current) && Current.policy != null)
		{
			return Current.policy.Allows(new ArenaBarrierPolicy.Point(point.x, point.z), halfX, halfZ);
		}
		return true;
	}

	internal static bool Blocked(Unit unit, Vector3 position, Vector3 step, out bool blockX, out bool blockZ)
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		blockX = (blockZ = false);
		if (!Object.op_Implicit((Object)(object)Current) || Current.policy == null || !Object.op_Implicit((Object)(object)unit) || !Current.states.TryGetValue(unit, out var value) || !value.ShapeKnown)
		{
			return false;
		}
		bool flag = value.MeasuredLarge && value.LargePolicy != null;
		ArenaBarrierPolicy obj = (flag ? value.LargePolicy : Current.policy);
		Vector3 val = position + (flag ? Vector3.zero : value.Offset);
		Vector3 val2 = val + step;
		if (!obj.Constrain(Point(val), Point(val2), flag ? 0f : value.HalfX, flag ? 0f : value.HalfZ, out var safe))
		{
			return false;
		}
		blockX = Mathf.Abs(safe.X - val2.x) > 0.02f;
		blockZ = Mathf.Abs(safe.Z - val2.z) > 0.02f;
		return blockX | blockZ;
	}

	internal void Register(Unit unit)
	{
		if (Eligible(unit))
		{
			pending.Add(unit);
		}
	}

	private bool Eligible(Unit unit)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)unit) && ((Component)unit).gameObject.scene == ((Component)this).gameObject.scene && ((Component)unit).gameObject.activeInHierarchy && !Object.op_Implicit((Object)(object)((Component)unit).GetComponent<ArenaTower>()) && !ArenaPreviewNative.Spawning && !ArenaPreviewNative.IsSample((Component)(object)unit))
		{
			return !ArenaMummyCaptive.Is(unit);
		}
		return false;
	}

	private void FixedUpdate()
	{
		Enforce(predict: true);
	}

	private void LateUpdate()
	{
		Enforce(predict: false);
	}

	private void Enforce(bool predict)
	{
		//IL_02e6: 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_0369: Unknown result type (might be due to invalid IL or missing references)
		//IL_036e: Unknown result type (might be due to invalid IL or missing references)
		//IL_038b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0462: Unknown result type (might be due to invalid IL or missing references)
		//IL_0467: Unknown result type (might be due to invalid IL or missing references)
		//IL_0478: Unknown result type (might be due to invalid IL or missing references)
		//IL_047f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_0489: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0408: Unknown result type (might be due to invalid IL or missing references)
		//IL_0421: Unknown result type (might be due to invalid IL or missing references)
		//IL_0426: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0601: Unknown result type (might be due to invalid IL or missing references)
		//IL_0606: Unknown result type (might be due to invalid IL or missing references)
		//IL_0543: Unknown result type (might be due to invalid IL or missing references)
		//IL_0559: Unknown result type (might be due to invalid IL or missing references)
		//IL_0572: Unknown result type (might be due to invalid IL or missing references)
		//IL_0577: Unknown result type (might be due to invalid IL or missing references)
		//IL_0712: Unknown result type (might be due to invalid IL or missing references)
		//IL_071e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0722: Unknown result type (might be due to invalid IL or missing references)
		//IL_0727: Unknown result type (might be due to invalid IL or missing references)
		//IL_0729: Unknown result type (might be due to invalid IL or missing references)
		//IL_072e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0719: Unknown result type (might be due to invalid IL or missing references)
		//IL_073f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0744: Unknown result type (might be due to invalid IL or missing references)
		//IL_0746: Unknown result type (might be due to invalid IL or missing references)
		//IL_0754: Unknown result type (might be due to invalid IL or missing references)
		//IL_0756: Unknown result type (might be due to invalid IL or missing references)
		//IL_074f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0787: Unknown result type (might be due to invalid IL or missing references)
		//IL_078e: Unknown result type (might be due to invalid IL or missing references)
		//IL_076d: Unknown result type (might be due to invalid IL or missing references)
		//IL_07bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0819: Unknown result type (might be due to invalid IL or missing references)
		//IL_081e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0830: Unknown result type (might be due to invalid IL or missing references)
		//IL_0835: Unknown result type (might be due to invalid IL or missing references)
		//IL_0837: Unknown result type (might be due to invalid IL or missing references)
		//IL_083c: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_07fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_07fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0856: Unknown result type (might be due to invalid IL or missing references)
		//IL_085b: Unknown result type (might be due to invalid IL or missing references)
		//IL_085d: Unknown result type (might be due to invalid IL or missing references)
		//IL_08a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0903: Unknown result type (might be due to invalid IL or missing references)
		//IL_0908: Unknown result type (might be due to invalid IL or missing references)
		//IL_090a: Unknown result type (might be due to invalid IL or missing references)
		//IL_094a: Unknown result type (might be due to invalid IL or missing references)
		//IL_094f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0951: Unknown result type (might be due to invalid IL or missing references)
		//IL_0956: Unknown result type (might be due to invalid IL or missing references)
		//IL_095a: Unknown result type (might be due to invalid IL or missing references)
		//IL_095f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0961: Unknown result type (might be due to invalid IL or missing references)
		//IL_0963: Unknown result type (might be due to invalid IL or missing references)
		//IL_096a: Unknown result type (might be due to invalid IL or missing references)
		//IL_096f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0974: Unknown result type (might be due to invalid IL or missing references)
		//IL_0978: Unknown result type (might be due to invalid IL or missing references)
		//IL_097f: Unknown result type (might be due to invalid IL or missing references)
		//IL_099c: Unknown result type (might be due to invalid IL or missing references)
		//IL_09b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_09c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_09d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_09e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_09f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_09fa: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)environment) || !environment.Ready || !ArenaRoyale.Selected || !Object.op_Implicit((Object)(object)ArenaSession.Current) || !ArenaSession.Current.Ready)
		{
			foreach (State value3 in states.Values)
			{
				value3.Towers.Restore();
			}
			return;
		}
		World active = World.Active;
		TeamSystem val = ((active != null) ? active.GetExistingManager<TeamSystem>() : null);
		if (val != null)
		{
			foreach (Unit allUnit in val.GetAllUnits())
			{
				if (Object.op_Implicit((Object)(object)allUnit) && !states.ContainsKey(allUnit))
				{
					Register(allUnit);
				}
			}
		}
		foreach (Unit item in pending)
		{
			if (Eligible(item) && !states.ContainsKey(item))
			{
				states.Add(item, new State());
			}
		}
		pending.Clear();
		removed.Clear();
		bool flag = false;
		foreach (KeyValuePair<Unit, State> state in states)
		{
			state.Value.Carrier = ArenaMountedBody.Root(state.Key);
			state.Value.Riders.Clear();
		}
		foreach (KeyValuePair<Unit, State> state2 in states)
		{
			if (Object.op_Implicit((Object)(object)state2.Value.Carrier) && (Object)(object)state2.Value.Carrier != (Object)(object)state2.Key && states.TryGetValue(state2.Value.Carrier, out var value))
			{
				value.Riders.Add(state2.Key);
			}
		}
		Vector3 val5 = default(Vector3);
		Vector3 correction = default(Vector3);
		Vector3 allowed = default(Vector3);
		foreach (KeyValuePair<Unit, State> state3 in states)
		{
			Unit key = state3.Key;
			State value2 = state3.Value;
			if (!Eligible(key))
			{
				value2.Restore();
				removed.Add(key);
			}
			else
			{
				if (!Object.op_Implicit((Object)(object)key.data) || !Object.op_Implicit((Object)(object)key.data.mainRig))
				{
					continue;
				}
				Rigidbody mainRig = key.data.mainRig;
				if (value2.Main != mainRig)
				{
					value2.RestoreCcd();
					value2.Bridge.Restore();
					value2.Main = mainRig;
					value2.Previous = mainRig.position;
					value2.Initialized = false;
					value2.ShapeKnown = false;
					value2.CorpseTracked = false;
				}
				if (Object.op_Implicit((Object)(object)value2.Carrier) && (Object)(object)value2.Carrier != (Object)(object)key && states.ContainsKey(value2.Carrier))
				{
					value2.Restore();
					value2.Previous = mainRig.position;
					value2.Initialized = false;
					continue;
				}
				if (!value2.Initialized)
				{
					value2.Previous = mainRig.position;
					value2.Initialized = true;
				}
				bool flag2 = !key.data.Dead && Mathf.Abs(mainRig.position.x) > 2.3f && !BuildingKinds.IsBuilding(key);
				if (flag2 && mainRig.position.y < 11.6f)
				{
					Bounds bounds = ArenaBodyGeometry.Read(key, refresh: true).Bounds;
					float num = 12f - ((Bounds)(ref bounds)).min.y + 0.02f;
					if (num > 0f)
					{
						Move(key, new Vector3(0f, num, 0f));
						flag = true;
						StopSinking(key, value2);
						value2.Previous = mainRig.position;
					}
				}
				if (Far(key, value2, mainRig))
				{
					value2.FarPasses++;
					value2.Towers.Apply(key, enabled: true, value2.Riders);
					value2.Previous = mainRig.position;
					value2.CorpseTracked = false;
					value2.PreviousCorpseCentre = mainRig.position + value2.Offset;
					value2.Bridge.Apply(key, environment, passage: false);
					EnsureCcd(key, value2, mainRig, needed: false);
					continue;
				}
				value2.FarPasses = 0;
				ArenaBodyGeometry.Sample sample = Shape(key, value2, mainRig.position);
				if (flag2 && sample.Found && ((Bounds)(ref sample.Bounds)).min.y < 11.7f)
				{
					if (value2.BuriedSince < 0f)
					{
						value2.BuriedSince = Time.time;
					}
					else if (Time.time - value2.BuriedSince > 0.25f)
					{
						Move(key, new Vector3(0f, 12f - ((Bounds)(ref sample.Bounds)).min.y + 0.02f, 0f));
						flag = true;
						StopSinking(key, value2);
						value2.Previous = mainRig.position;
						value2.BuriedSince = -1f;
						sample = ArenaBodyGeometry.Read(key, refresh: true);
					}
				}
				else
				{
					value2.BuriedSince = -1f;
				}
				value2.Towers.Apply(key, enabled: true, value2.Riders);
				bool dead = key.data.Dead;
				bool flag3 = (value2.MeasuredLarge = (dead ? (Mathf.Max(value2.HalfX, value2.HalfZ) > 1f) : ArenaLargeUnitBody.IsLarge(key, sample)));
				value2.MeasuredScale = ((Component)key).transform.lossyScale;
				bool flag4 = flag3 && ArenaLargeUnitBody.IsVehicle(key);
				float support = (dead ? ArenaLargeUnitBody.Support(Mathf.Min(value2.HalfX, value2.HalfZ)) : ArenaLargeUnitBody.Support(sample.Clearance));
				ArenaBarrierPolicy arenaBarrierPolicy = policy;
				if (flag3)
				{
					arenaBarrierPolicy = (value2.LargePolicy = ArenaBarrierPolicy.RebuildLarge(value2.LargePolicy, policy, 0.7344f, value2.HalfX, value2.HalfZ, dead ? 0f : value2.Offset.x, dead ? 0f : value2.Offset.z, support));
				}
				if (flag3 && !flag4 && !dead)
				{
					ArenaLargeUnitNavigation.FillObstacles(key, value2.Obstacles, sample);
					arenaBarrierPolicy.AppendObstacles(value2.Obstacles);
				}
				float halfX = (flag3 ? 0f : value2.HalfX);
				float halfZ = (flag3 ? 0f : value2.HalfZ);
				Vector3 val2 = ((flag3 && !dead) ? Vector3.zero : value2.Offset);
				Vector3 val3 = mainRig.position + val2;
				Vector3 val4 = ((dead && value2.CorpseTracked) ? value2.PreviousCorpseCentre : (value2.Previous + val2));
				if (Mathf.Abs(val4.x) < 1E-05f)
				{
					val4.x = (((int)key.Team == 0) ? (-2E-05f) : 2E-05f);
				}
				if (!arenaBarrierPolicy.Constrain(Point(val4), Point(val3), halfX, halfZ, out var safe))
				{
					value2.Bridge.Restore();
					continue;
				}
				((Vector3)(ref val5))..ctor(safe.X - val3.x, 0f, safe.Z - val3.z);
				if (((Vector3)(ref val5)).sqrMagnitude > 1E-10f)
				{
					Move(key, val5);
					flag = true;
					LimitVelocity(key, val5, Vector3.zero, predicted: false);
					if (flag3)
					{
						sample = ArenaBodyGeometry.Read(key);
					}
				}
				value2.Previous = mainRig.position;
				value2.CorpseTracked = dead;
				value2.PreviousCorpseCentre = mainRig.position + val2;
				value2.Bridge.Apply(key, environment, flag3 && ArenaLargeUnitBody.InPassage(mainRig.position + val2, value2.HalfX + (dead ? 0f : Mathf.Abs(value2.Offset.x)), support));
				float margin = (float)(2 + (Object.op_Implicit((Object)(object)value2.Ccd) ? 1 : 0)) + Mathf.Max(Mathf.Abs(mainRig.velocity.x), Mathf.Abs(mainRig.velocity.z)) * Mathf.Max(0.02f, Time.fixedDeltaTime) * 2f;
				EnsureCcd(key, value2, mainRig, (flag4 && !key.data.Dead) || arenaBarrierPolicy.NearBarrier(Point(mainRig.position + val2), halfX, halfZ, margin));
				if (predict && !mainRig.isKinematic && !(Time.fixedDeltaTime <= 0f))
				{
					val3 = mainRig.position + val2;
					Vector3 velocity = mainRig.velocity;
					Vector3 val6 = val3 + velocity * Time.fixedDeltaTime;
					if (arenaBarrierPolicy.Constrain(Point(val3), Point(val6), halfX, halfZ, out var safe2))
					{
						((Vector3)(ref correction))..ctor(safe2.X - val6.x, 0f, safe2.Z - val6.z);
						((Vector3)(ref allowed))..ctor((safe2.X - val3.x) / Time.fixedDeltaTime, velocity.y, (safe2.Z - val3.z) / Time.fixedDeltaTime);
						LimitVelocity(key, correction, allowed, predicted: true);
					}
				}
			}
		}
		foreach (Unit item2 in removed)
		{
			states.Remove(item2);
		}
		if (flag)
		{
			Physics.SyncTransforms();
		}
	}

	private static ArenaBarrierPolicy.Point Point(Vector3 p)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		return new ArenaBarrierPolicy.Point(p.x, p.z);
	}

	private static void StopSinking(Unit unit, State state)
	{
		Stop(unit);
		foreach (Unit rider in state.Riders)
		{
			if (Object.op_Implicit((Object)(object)rider))
			{
				Stop(rider);
			}
		}
		static void Stop(Unit member)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody[] componentsInChildren = ((Component)member).GetComponentsInChildren<Rigidbody>();
			foreach (Rigidbody val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val) && !val.isKinematic && val.velocity.y < 0f)
				{
					Vector3 velocity = val.velocity;
					velocity.y = 0f;
					val.velocity = velocity;
				}
			}
		}
	}

	private bool Far(Unit unit, State state, Rigidbody main)
	{
		//IL_003c: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: 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_0102: Unknown result type (might be due to invalid IL or missing references)
		if (!state.ShapeKnown || state.MeasuredLarge || state.FarPasses >= 3 || state.Riders.Count != 0 || unit.data.Dead || main.isKinematic || state.MeasuredScale != ((Component)unit).transform.lossyScale)
		{
			return false;
		}
		Vector3 val = main.position - state.Previous;
		val.y = 0f;
		if (((Vector3)(ref val)).sqrMagnitude > 2.25f)
		{
			return false;
		}
		Vector3 velocity = main.velocity;
		float num = Mathf.Max(0.02f, Time.fixedDeltaTime);
		float margin = 4.5f + (Mathf.Abs(velocity.x) + Mathf.Abs(velocity.z)) * num * 2f;
		if (!policy.NearBarrier(Point(main.position + state.Offset), state.HalfX, state.HalfZ, margin))
		{
			return !policy.NearBarrier(Point(state.Previous + state.Offset), state.HalfX, state.HalfZ, margin);
		}
		return false;
	}

	private static ArenaBodyGeometry.Sample Shape(Unit unit, State state, Vector3 origin)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		ArenaBodyGeometry.Sample sample = ArenaBodyGeometry.Read(unit, refresh: true);
		if (sample.Found)
		{
			Bounds bounds = sample.Bounds;
			foreach (Unit rider in state.Riders)
			{
				if (Object.op_Implicit((Object)(object)rider) && Object.op_Implicit((Object)(object)rider.data) && Object.op_Implicit((Object)(object)rider.data.mainRig))
				{
					ArenaBodyGeometry.Sample sample2 = ArenaBodyGeometry.Read(rider, refresh: true);
					if (sample2.Found)
					{
						((Bounds)(ref bounds)).Encapsulate(sample2.Bounds);
					}
				}
			}
			state.Offset = ((Bounds)(ref bounds)).center - origin;
			state.Offset.y = 0f;
			state.HalfX = Mathf.Max(0.05f, ((Bounds)(ref bounds)).extents.x);
			state.HalfZ = Mathf.Max(0.05f, ((Bounds)(ref bounds)).extents.z);
			state.ShapeKnown = true;
		}
		else if (!state.ShapeKnown)
		{
			state.Offset = Vector3.zero;
			state.HalfX = (state.HalfZ = Mathf.Max(0.25f, unit.thickness));
		}
		return sample;
	}

	private void Move(Unit unit, Vector3 shift)
	{
		//IL_0010: 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_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		states.TryGetValue(unit, out var value);
		foreach (Unit item in ArenaMountedBody.Shift(unit, shift, value?.Riders))
		{
			((Component)item).GetComponent<ArenaUnitDeployment>()?.ShiftFloor(shift);
			((Component)item).GetComponent<BuildingRuntime>()?.ShiftAnchor(shift);
			if ((Object)(object)item != (Object)(object)unit && states.TryGetValue(item, out var value2) && value2.Initialized)
			{
				State state = value2;
				state.Previous += shift;
			}
		}
	}

	private void LimitVelocity(Unit unit, Vector3 correction, Vector3 allowed, bool predicted)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		if (Mathf.Abs(correction.x) + Mathf.Abs(correction.z) < 1E-05f)
		{
			return;
		}
		LimitBodyVelocity(unit, correction, allowed, predicted);
		if (!states.TryGetValue(unit, out var value))
		{
			return;
		}
		foreach (Unit rider in value.Riders)
		{
			if (Object.op_Implicit((Object)(object)rider))
			{
				LimitBodyVelocity(rider, correction, allowed, predicted);
			}
		}
	}

	private static void LimitBodyVelocity(Unit unit, Vector3 correction, Vector3 allowed, bool predicted)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: 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_00a8: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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_0121: 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)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		Rigidbody[] componentsInChildren = ((Component)unit).GetComponentsInChildren<Rigidbody>(true);
		foreach (Rigidbody val in componentsInChildren)
		{
			if (Object.op_Implicit((Object)(object)val) && !val.isKinematic)
			{
				Vector3 velocity = val.velocity;
				if (correction.x < -1E-05f && velocity.x > (predicted ? allowed.x : 0f))
				{
					velocity.x = (predicted ? allowed.x : 0f);
				}
				if (correction.x > 1E-05f && velocity.x < (predicted ? allowed.x : 0f))
				{
					velocity.x = (predicted ? allowed.x : 0f);
				}
				if (correction.z < -1E-05f && velocity.z > (predicted ? allowed.z : 0f))
				{
					velocity.z = (predicted ? allowed.z : 0f);
				}
				if (correction.z > 1E-05f && velocity.z < (predicted ? allowed.z : 0f))
				{
					velocity.z = (predicted ? allowed.z : 0f);
				}
				val.velocity = velocity;
			}
		}
	}

	private static void EnsureCcd(Unit unit, State state, Rigidbody main, bool needed)
	{
		//IL_005f: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)state.Ccd) && ((Object)(object)state.Ccd != (Object)(object)main || main.isKinematic || unit.data.Dead || !needed))
		{
			state.RestoreCcd();
		}
		if (needed && !Object.op_Implicit((Object)(object)state.Ccd) && !main.isKinematic && !unit.data.Dead && (int)main.collisionDetectionMode == 0 && (Object.op_Implicit((Object)(object)((Component)main).GetComponent<CapsuleCollider>()) || Object.op_Implicit((Object)(object)((Component)main).GetComponent<SphereCollider>()) || Object.op_Implicit((Object)(object)((Component)main).GetComponent<BoxCollider>())))
		{
			state.Ccd = main;
			state.PreviousCcd = main.collisionDetectionMode;
			main.collisionDetectionMode = (CollisionDetectionMode)2;
		}
	}

	private void OnDisable()
	{
		foreach (State value in states.Values)
		{
			value.Restore();
		}
		states.Clear();
		pending.Clear();
		if ((Object)(object)Current == (Object)(object)this)
		{
			Current = null;
		}
	}
}
[HarmonyPatch(typeof(Unit), "Awake")]
internal static class ArenaBarrierSpawnPatch
{
	private static void Postfix(Unit __instance)
	{
		ArenaBarrierContainment.Current?.Register(__instance);
	}
}
internal sealed class ArenaBarrierPolicy
{
	internal struct Point
	{
		internal float X;

		internal float Z;

		internal Point(float x, float z)
		{
			X = x;
			Z = z;
		}
	}

	internal struct Rect
	{
		internal float MinX;

		internal float MaxX;

		internal float MinZ;

		internal float MaxZ;

		internal Rect(float minX, float maxX, float minZ, float maxZ)
		{
			MinX = minX;
			MaxX = maxX;
			MinZ = minZ;
			MaxZ = maxZ;
		}

		internal Rect Expand(float x, float z)
		{
			return new Rect(MinX - x, MaxX + x, MinZ - z, MaxZ + z);
		}

		internal bool Contains(Point p)
		{
			if (p.X > MinX + 1E-05f && p.X < MaxX - 1E-05f && p.Z > MinZ + 1E-05f)
			{
				return p.Z < MaxZ - 1E-05f;
			}
			return false;
		}
	}

	internal const float Skin = 0.035f;

	internal const float PerimeterHalfX = 35.1f;

	internal const float PerimeterHalfZ = 18.855f;

	internal const float PerimeterThickness = 0.6f;

	private const float Epsilon = 1E-05f;

	private Rect interior;

	private Rect[] forbidden;

	private int forbiddenCount;

	private Rect[] subtractionA;

	private Rect[] subtractionB;

	private float[] recoveryX;

	private float[] recoveryZ;

	internal ArenaBarrierPolicy(Rect interior, Rect[] forbidden)
	{
		this.interior = interior;
		this.forbidden = forbidden;
		forbiddenCount = forbidden.Length;
	}

	internal static ArenaBarrierPolicy Create(float scale)
	{
		Rect rect = new Rect(-35.1f * scale, 35.1f * scale, -18.855f * scale, 18.855f * scale);
		float num = 2.6899998f * scale;
		float num2 = 1.61f * scale;
		float num3 = 7.1499996f;
		float num4 = 12.65f;
		float num5 = 0.11f;
		float num6 = 1.25f;
		return new ArenaBarrierPolicy(rect, new Rect[6]
		{
			new Rect(0f - num, num, (0f - (num3 - num6 + num5)) * scale, (num3 - num6 + num5) * scale),
			new Rect(0f - num2, num2, (0f - (num3 + num5)) * scale, (num3 + num5) * scale),
			new Rect(0f - num, num, (num4 + num6 - num5) * scale, rect.MaxZ + 1f),
			new Rect(0f - num, num, rect.MinZ - 1f, (0f - (num4 + num6 - num5)) * scale),
			new Rect(0f - num2, num2, (num4 - num5) * scale, rect.MaxZ + 1f),
			new Rect(0f - num2, num2, rect.MinZ - 1f, (0f - (num4 - num5)) * scale)
		});
	}

	internal static ArenaBarrierPolicy ForLargeBody(float scale, float halfX, float halfZ, float offsetX, float offsetZ, float support)
	{
		return RebuildLarge(null, Create(scale), scale, halfX, halfZ, offsetX, offsetZ, support);
	}

	internal static ArenaBarrierPolicy RebuildLarge(ArenaBarrierPolicy reuse, ArenaBarrierPolicy basis, float scale, float halfX, float halfZ, float offsetX, float offsetZ, float support)
	{
		if (reuse == basis)
		{
			throw new ArgumentException("A large-body workspace cannot overwrite its basis.");
		}
		Rect rect = new Rect(basis.interior.MinX + halfX - offsetX, basis.interior.MaxX - halfX - offsetX, basis.interior.MinZ + halfZ - offsetZ, basis.interior.MaxZ - halfZ - offsetZ);
		ArenaBarrierPolicy arenaBarrierPolicy = reuse ?? new ArenaBarrierPolicy(rect, new Rect[24]);
		arenaBarrierPolicy.interior = rect;
		arenaBarrierPolicy.forbiddenCount = 0;
		float num = 9.9f * scale;
		float num2 = 2.64f * scale - support;
		for (int i = 0; i < basis.forbiddenCount; i++)
		{
			Rect rect2 = basis.forbidden[i];
			Rect rect3 = rect2.Expand(halfX, halfZ);
			rect3 = new Rect(rect3.MinX - offsetX, rect3.MaxX - offsetX, rect3.MinZ - offsetZ, rect3.MaxZ - offsetZ);
			if (num2 > 0f && num >= num2 && rect3.MinZ < rect3.MaxZ)
			{
				float cursor = rect3.MinZ;
				arenaBarrierPolicy.AppendBeforeStrip(rect3, ref cursor, 0f - num - num2, 0f - num + num2);
				arenaBarrierPolicy.AppendBeforeStrip(rect3, ref cursor, num - num2, num + num2);
				if (cursor < rect3.MaxZ)
				{
					arenaBarrierPolicy.Add(new Rect(rect3.MinX, rect3.MaxX, cursor, rect3.MaxZ));
				}
				continue;
			}
			if (arenaBarrierPolicy.subtractionA == null)
			{
				arenaBarrierPolicy.subtractionA = new Rect[4];
				arenaBarrierPolicy.subtractionB = new Rect[4];
			}
			Rect[] array = arenaBarrierPolicy.subtractionA;
			Rect[] array2 = arenaBarrierPolicy.subtractionB;
			int num3 = 1;
			array[0] = rect3;
			for (int j = 0; j < 2; j++)
			{
				float num4 = ((j == 0) ? (-1f) : 1f);
				int num5 = 0;
				float num6 = num4 * num;
				for (int k = 0; k < num3; k++)
				{
					Rect rect4 = array[k];
					float num7 = num6 - num2;
					float num8 = num6 + num2;
					if (num8 <= rect4.MinZ || num7 >= rect4.MaxZ)
					{
						array2[num5++] = rect4;
						continue;
					}
					if (rect4.MinZ < num7)
					{
						array2[num5++] = new Rect(rect4.MinX, rect4.MaxX, rect4.MinZ, num7);
					}
					if (rect4.MaxZ > num8)
					{
						array2[num5++] = new Rect(rect4.MinX, rect4.MaxX, num8, rect4.MaxZ);
					}
				}
				Rect[] array3 = array;
				array = array2;
				array2 = array3;
				num3 = num5;
			}
			for (int l = 0; l < num3; l++)
			{
				arenaBarrierPolicy.Add(array[l]);
			}
		}
		return arenaBarrierPolicy;
	}

	private void Add(Rect box)
	{
		if (forbiddenCount == forbidden.Length)
		{
			Array.Resize(ref forbidden, Math.Max(4, forbidden.Length * 2));
		}
		forbidden[forbiddenCount++] = box;
	}

	private void AppendBeforeStrip(Rect full, ref float cursor, float low, float high)
	{
		if (!(high <= cursor) && !(low >= full.MaxZ))
		{
			if (cursor < low)
			{
				Add(new Rect(full.MinX, full.MaxX, cursor, low));
			}
			cursor = Math.Max(cursor, high);
		}
	}

	internal IEnumerable<Point> Corners()
	{
		for (int i = 0; i < forbiddenCount; i++)
		{
			Rect rect = forbidden[i];
			Rect padded = rect.Expand(0.055f, 0.055f);
			yield return new Point(padded.MinX, padded.MinZ);
			yield return new Point(padded.MinX, padded.MaxZ);
			yield return new Point(padded.MaxX, padded.MinZ);
			yield return new Point(padded.MaxX, padded.MaxZ);
		}
	}

	internal ArenaBarrierPolicy WithObstacles(IList<Rect> obstacles)
	{
		Rect[] array = new Rect[forbiddenCount + obstacles.Count];
		Array.Copy(forbidden, array, forbiddenCount);
		for (int i = 0; i < obstacles.Count; i++)
		{
			array[forbiddenCount + i] = obstacles[i];
		}
		return new ArenaBarrierPolicy(interior, array);
	}

	internal void AppendObstacles(IList<Rect> obstacles)
	{
		for (int i = 0; i < obstacles.Count; i++)
		{
			Add(obstacles[i]);
		}
	}

	internal bool Allows(Point p, float halfX, float halfZ)
	{
		float x = Math.Max(0f, halfX) + 0.035f;
		float z = Math.Max(0f, halfZ) + 0.035f;
		Rect rect = Interior(x, z);
		if (Finite(p.X) && Finite(p.Z) && rect.MinX <= rect.MaxX && rect.MinZ <= rect.MaxZ && p.X >= rect.MinX - 1E-05f && p.X <= rect.MaxX + 1E-05f && p.Z >= rect.MinZ - 1E-05f && p.Z <= rect.MaxZ + 1E-05f)
		{
			return Outside(p, x, z);
		}
		return false;
	}

	internal bool NearBarrier(Point p, float halfX, float halfZ, float margin)
	{
		float num = Math.Max(0f, halfX) + 0.035f + Math.Max(0f, margin);
		float num2 = Math.Max(0f, halfZ) + 0.035f + Math.Max(0f, margin);
		if (p.X <= interior.MinX + num || p.X >= interior.MaxX - num || p.Z <= interior.MinZ + num2 || p.Z >= interior.MaxZ - num2)
		{
			return true;
		}
		for (int i = 0; i < forbiddenCount; i++)
		{
			Rect rect = forbidden[i];
			Rect rect2 = rect.Expand(num, num2);
			if (p.X >= rect2.MinX && p.X <= rect2.MaxX && p.Z >= rect2.MinZ && p.Z <= rect2.MaxZ)
			{
				return true;
			}
		}
		return false;
	}

	private Rect Interior(float x, float z)
	{
		return new Rect(interior.MinX + x, interior.MaxX - x, interior.MinZ + z, interior.MaxZ - z);
	}

	private bool Outside(Point p, float x, float z)
	{
		for (int i = 0; i < forbiddenCount; i++)
		{
			if (forbidden[i].Expand(x, z).Contains(p))
			{
				return false;
			}
		}
		return true;
	}

	internal bool Constrain(Point previous, Point desired, float halfX, float halfZ, out Point safe)
	{
		float x = Math.Max(0f, halfX) + 0.035f;
		float z = Math.Max(0f, halfZ) + 0.035f;
		Rect bounds = Interior(x, z);
		safe = previous;
		if (bounds.MinX > bounds.MaxX || bounds.MinZ > bounds.MaxZ)
		{
			return false;
		}
		if (!Finite(previous.X) || !Finite(previous.Z))
		{
			previous = new Point(bounds.MinX, 0f);
		}
		if (!Finite(desired.X) || !Finite(desired.Z))
		{
			desired = previous;
		}
		Point point = Nearest(previous, previous, bounds, x, z);
		Point d = new Point(desired.X - point.X, desired.Z - point.Z);
		for (int i = 0; i < 8; i++)
		{
			float hit = 1f;
			bool blockX = false;
			bool blockZ = false;
			if (d.X < 0f && point.X + d.X < bounds.MinX)
			{
				Contact((bounds.MinX - point.X) / d.X, bx: true, bz: false);
			}
			if (d.X > 0f && point.X + d.X > bounds.MaxX)
			{
				Contact((bounds.MaxX - point.X) / d.X, bx: true, bz: false);
			}
			if (d.Z < 0f && point.Z + d.Z < bounds.MinZ)
			{
				Contact((bounds.MinZ - point.Z) / d.Z, bx: false, bz: true);
			}
			if (d.Z > 0f && point.Z + d.Z > bounds.MaxZ)
			{
				Contact((bounds.MaxZ - point.Z) / d.Z, bx: false, bz: true);
			}
			for (int j = 0; j < forbiddenCount; j++)
			{
				if (Sweep(point, d, forbidden[j].Expand(x, z), out var time, out var blockX2, out var blockZ2))
				{
					Contact(time, blockX2, blockZ2);
				}
			}
			point = new Point(point.X + d.X * hit, point.Z + d.Z * hit);
			if (!blockX && !blockZ)
			{
				break;
			}
			d = new Point(blockX ? 0f : (d.X * (1f - hit)), blockZ ? 0f : (d.Z * (1f - hit)));
			if (Math.Abs(d.X) + Math.Abs(d.Z) < 1E-05f)
			{
				break;
			}
			void Contact(float num, bool bx, bool bz)
			{
				if (!(num < 0f) && !(num > 1f))
				{
					if (num < hit - 1E-05f)
					{
						hit = num;
						blockX = bx;
						blockZ = bz;
					}
					else if (Math.Abs(num - hit) <= 1E-05f)
					{
						blockX |= bx;
						blockZ |= bz;
					}
				}
			}
		}
		safe = Nearest(point, previous, bounds, x, z);
		return Allows(safe, halfX, halfZ);
	}

	private Point Nearest(Point point, Point reference, Rect bounds, float x, float z)
	{
		Point point2 = new Point(Clamp(point.X, bounds.MinX, bounds.MaxX), Clamp(point.Z, bounds.MinZ, bounds.MaxZ));
		if (Outside(point2, x, z))
		{
			return point2;
		}
		int num = 3 + forbiddenCount * 2;
		if (recoveryX == null || recoveryX.Length < num)
		{
			int num2 = Math.Max(num, (recoveryX == null) ? 16 : (recoveryX.Length * 2));
			recoveryX = new float[num2];
			recoveryZ = new float[num2];
		}
		float[] array = recoveryX;
		float[] array2 = recoveryZ;
		array[0] = point2.X;
		array[1] = bounds.MinX;
		array[2] = bounds.MaxX;
		array2[0] = point2.Z;
		array2[1] = bounds.MinZ;
		array2[2] = bounds.MaxZ;
		for (int i = 0; i < forbiddenCount; i++)
		{
			Rect rect = forbidden[i].Expand(x, z);
			array[3 + i * 2] = Clamp(rect.MinX - 0.0001f, bounds.MinX, bounds.MaxX);
			array[4 + i * 2] = Clamp(rect.MaxX + 0.0001f, bounds.MinX, bounds.MaxX);
			array2[3 + i * 2] = Clamp(rect.MinZ - 0.0001f, bounds.MinZ, bounds.MaxZ);
			array2[4 + i * 2] = Clamp(rect.MaxZ + 0.0001f, bounds.MinZ, bounds.MaxZ);
		}
		float num3 = float.PositiveInfinity;
		float num4 = float.PositiveInfinity;
		Point result = point2;
		for (int j = 0; j < num; j++)
		{
			for (int k = 0; k < num; k++)
			{
				float x2 = array[j];
				float z2 = array2[k];
				Point point3 = new Point(x2, z2);
				if (Outside(point3, x, z))
				{
					float num5 = Squared(point3, point2);
					float num6 = Squared(point3, reference);
					if (num5 < num3 - 1E-05f || (Math.Abs(num5 - num3) <= 1E-05f && num6 < num4))
					{
						num3 = num5;
						num4 = num6;
						result = point3;
					}
				}
			}
		}
		return result;
	}

	private static bool Sweep(Point p, Point d, Rect box, out float time, out bool blockX, out bool blockZ)
	{
		time = 0f;
		blockX = (blockZ = false);
		if (!Interval(p.X, d.X, box.MinX, box.MaxX, out var entry, out var exit) || !Interval(p.Z, d.Z, box.MinZ, box.MaxZ, out var entry2, out var exit2))
		{
			return false;
		}
		float num = Math.Max(entry, entry2);
		float num2 = Math.Min(exit, exit2);
		if (num2 <= 1E-05f || num > num2 || num > 1f || num < -1E-05f)
		{
			return false;
		}
		time = Math.Max(0f, num);
		blockX = entry >= num - 1E-05f;
		blockZ = entry2 >= num - 1E-05f;
		return true;
	}

	private static bool Interval(float p, float d, float min, float max, out float entry, out float exit)
	{
		entry = float.NegativeInfinity;
		exit = float.PositiveInfinity;
		if (Math.Abs(d) < 1E-05f)
		{
			if (p > min + 1E-05f)
			{
				return p < max - 1E-05f;
			}
			return false;
		}
		float val = (min - p) / d;
		float val2 = (max - p) / d;
		entry = Math.Min(val, val2);
		exit = Math.Max(val, val2);
		return true;
	}

	private static float Squared(Point a, Point b)
	{
		float num = a.X - b.X;
		float num2 = a.Z - b.Z;
		return num * num + num2 * num2;
	}

	private static float Clamp(float value, float min, float max)
	{
		return Math.Max(min, Math.Min(max, value));
	}

	private static bool Finite(float value)
	{
		if (!float.IsNaN(value))
		{
			return !float.IsInfinity(value);
		}
		return false;
	}

	internal bool Traversable(Point from, Point to)
	{
		if (!Finite(from.X) || !Finite(from.Z) || !Finite(to.X) || !Finite(to.Z))
		{
			return false;
		}
		Rect rect = Interior(0.035f, 0.035f);
		if ((to.X < rect.MinX && (from.X >= rect.MinX || to.X <= from.X + 1E-05f)) || (to.X > rect.MaxX && (from.X <= rect.MaxX || to.X >= from.X - 1E-05f)) || (to.Z < rect.MinZ && (from.Z >= rect.MinZ || to.Z <= from.Z + 1E-05f)) || (to.Z > rect.MaxZ && (from.Z <= rect.MaxZ || to.Z >= from.Z - 1E-05f)))
		{
			return false;
		}
		Point d = new Point(to.X - from.X, to.Z - from.Z);
		for (int i = 0; i < forbiddenCount; i++)
		{
			Rect rect2 = forbidden[i];
			Rect box = rect2.Expand(0.035f, 0.035f);
			float time;
			bool blockX;
			bool blockZ;
			if (box.Contains(from))
			{
				if (box.Contains(to))
				{
					float num = Math.Min(Math.Min(from.X - box.MinX, box.MaxX - from.X), Math.Min(from.Z - box.MinZ, box.MaxZ - from.Z));
					if (Math.Min(Math.Min(to.X - box.MinX, box.MaxX - to.X), Math.Min(to.Z - box.MinZ, box.MaxZ - to.Z)) >= num - 1E-05f)
					{
						return false;
					}
				}
			}
			else if (box.Contains(to) || Sweep(from, d, box, out time, out blockX, out blockZ))
			{
				return false;
			}
		}
		return true;
	}

	internal static ArenaBarrierPolicy ForBody(float scale, float radius)
	{
		return ForBody(scale, radius, radius, 0f, 0f);
	}

	internal static ArenaBarrierPolicy ForBody(float scale, float halfX, float halfZ, float offsetX, float offsetZ)
	{
		ArenaBarrierPolicy arenaBarrierPolicy = Create(scale);
		halfX = Math.Max(0f, halfX);
		halfZ = Math.Max(0f, halfZ);
		Rect rect = arenaBarrierPolicy.interior;
		rect = new Rect(rect.MinX + halfX - offsetX, rect.MaxX - halfX - offsetX, rect.MinZ + halfZ - offsetZ, rect.MaxZ - halfZ - offsetZ);
		Rect[] array = new Rect[arenaBarrierPolicy.forbiddenCount];
		for (int i = 0; i < array.Length; i++)
		{
			Rect rect2 = arenaBarrierPolicy.forbidden[i].Expand(halfX, halfZ);
			array[i] = new Rect(rect2.MinX - offsetX, rect2.MaxX - offsetX, rect2.MinZ - offsetZ, rect2.MaxZ - offsetZ);
		}
		return new ArenaBarrierPolicy(rect, array);
	}
}
[DefaultExecutionOrder(11000)]
internal sealed class ArenaBastionAttack : MonoBehaviour
{
	private sealed class Binding
	{
		internal RangeWeapon Native;

		internal UnityAction Prepare;

		internal UnityAction Release;
	}

	public Transform Yaw;

	public Transform Pitch;

	public Transform Winch;

	public Transform Muzzle;

	public Transform LeftString;

	public Transform RightString;

	public GameObject LoadedBolt;

	public Vector3 BoltRestPosition;

	public Vector3 BoltDrawOffset;

	public Vector3 LeftStringDirection;

	public Vector3 RightStringDirection;

	public Quaternion WinchRestRotation;

	private Unit unit;

	private RangeWeapon weapon;

	private readonly List<Weapon> mounted = new List<Weapon>();

	private readonly List<Binding> bindings = new List<Binding>();

	private static readonly FieldRef<RangeWeapon, float> delayCounter = AccessTools.FieldRefAccess<RangeWeapon, float>("spawnDelayCounter");

	private bool winding;

	private bool unloaded;

	private float releaseElapsed;

	private float recoil;

	internal void BuildHierarchy(GameObject visual, ArenaBuildingUnits.BuildingAssetData data)
	{
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: 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_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		Yaw = Pivot("Bastion yaw", visual.transform, data.yawPosition);
		Pitch = Pivot("Bastion pitch", Yaw, data.pitchPosition);
		Winch = Pivot("Bastion windlass", Pitch, data.winchPosition);
		Muzzle = Pivot("Bastion muzzle", Pitch, data.muzzlePosition);
		BoltDrawOffset = ArenaBuildingUnits.BuildingAssetData.Vector(data.boltDrawOffset);
		LeftStringDirection = ArenaBuildingUnits.BuildingAssetData.Vector(data.stringLeftDirection);
		RightStringDirection = ArenaBuildingUnits.BuildingAssetData.Vector(data.stringRightDirection);
		LeftString = Pivot("Bastion left bowstring", Pitch, data.stringLeftTip);
		RightString = Pivot("Bastion right bowstring", Pitch, data.stringRightTip);
		LeftString.localRotation = Quaternion.LookRotation(LeftStringDirection, Vector3.up);
		RightString.localRotation = Quaternion.LookRotation(RightStringDirection, Vector3.up);
		WinchRestRotation = Winch.localRotation;
		MeshFilter[] componentsInChildren = visual.GetComponentsInChildren<MeshFilter>(true);
		foreach (MeshFilter val in componentsInChildren)
		{
			string text = ((Object)val).name.Split(new char[1] { '_' }).Last();
			Transform val2 = null;
			if (text == "Yaw")
			{
				val2 = Yaw;
			}
			if (text == "Pitch")
			{
				val2 = Pitch;
			}
			if (text == "Winch")
			{
				val2 = Winch;
			}
			if (text == "Bolt")
			{
				val2 = Pitch;
				LoadedBolt = ((Component)val).gameObject;
			}
			if (text == "StringLeft")
			{
				val2 = LeftString;
			}
			if (text == "StringRight")
			{
				val2 = RightString;
			}
			if (Object.op_Implicit((Object)(object)val2))
			{
				((Component)val).transform.SetParent(val2, true);
			}
		}
		BoltRestPosition = LoadedBolt.transform.localPosition;
		ApplyDraw(0f);
		Transform Pivot(string name, Transform parent, float[] position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing

BepInEx\plugins\ArenaRoyale\ArenaRoyale.UnitRuntime.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using DM;
using GamepadUI.StateManager.Core;
using HarmonyLib;
using Landfall.TABS;
using Landfall.TABS.AI;
using Landfall.TABS.AI.Components;
using Landfall.TABS.AI.Components.Modifiers;
using Landfall.TABS.AI.Components.Pathfinding;
using Landfall.TABS.AI.Components.Tags;
using Landfall.TABS.AI.Systems;
using Landfall.TABS.GameMode;
using Landfall.TABS.GameState;
using Landfall.TABS.RuntimeCleanup;
using Landfall.TABS.UnitEditor;
using Landfall.TABS.UnitPlacement;
using Landfall.TABS.WinConditions;
using Landfall.TABS.Workshop;
using Microsoft.CodeAnalysis;
using Pathfinding;
using TFBGames;
using TMPro;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ArenaRoyale.UnitRuntime")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ArenaRoyale.UnitRuntime")]
[assembly: AssemblyTitle("ArenaRoyale.UnitRuntime")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Tabs.PersistentHealth.Mod
{
	internal static class AssassinPoofCompatibility
	{
		internal static readonly DatabaseID LegacyAbilityId = new DatabaseID(-2, 1847012603);

		private static SpecialAbility s_nativeAbility;

		internal static bool PersonalOverrideEnabled => false;

		private static SpecialAbility ResolveNativeAbility(LandfallContentDatabase database = null)
		{
			if ((Object)(object)s_nativeAbility != (Object)null)
			{
				return s_nativeAbility;
			}
			if (database == null)
			{
				ContentDatabase obj = ContentDatabase.Instance();
				database = ((obj != null) ? obj.LandfallContentDatabase : null);
			}
			if (database == null)
			{
				return null;
			}
			s_nativeAbility = (from move in database.GetCombatMoves()
				where (Object)(object)move != (Object)null && (Object)(object)move.GetComponent<AssassinPoofEffect>() != (Object)null
				select move.GetComponent<SpecialAbility>() into ability
				where (Object)(object)ability != (Object)null && ((CharacterItem)ability).Entity != null && ((CharacterItem)ability).Entity.GUID.m_modID == DatabaseID._LANDFALL_CONTENT
				orderby (((CharacterItem)ability).DisplayName ?? string.Empty).IndexOf("Assassin", StringComparison.OrdinalIgnoreCase) >= 0 descending
				select ability).FirstOrDefault();
			return s_nativeAbility;
		}

		internal static bool IsNativeAssassinPoof(AssassinPoofEffect effect)
		{
			//IL_0048: 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)
			SpecialAbility val = (((Object)(object)effect != (Object)null) ? ((Component)effect).GetComponent<SpecialAbility>() : null);
			SpecialAbility val2 = (((Object)(object)val != (Object)null) ? ResolveNativeAbility() : null);
			if (((val != null) ? ((CharacterItem)val).Entity : null) != null && ((val2 != null) ? ((CharacterItem)val2).Entity : null) != null)
			{
				return ((CharacterItem)val).Entity.GUID == ((CharacterItem)val2).Entity.GUID;
			}
			return false;
		}

		internal static bool TryAttachToSpawnedUnit(AssassinPoofEffect effect)
		{
			if (!PersonalOverrideEnabled || (Object)(object)effect == (Object)null)
			{
				return false;
			}
			Unit component = ((Component)((Component)effect).transform.root).GetComponent<Unit>();
			if ((Object)(object)component == (Object)null || !IsNativeAssassinPoof(effect))
			{
				return false;
			}
			if ((Object)(object)((Component)component).GetComponentInChildren<ModAssassinPoofEffect>(true) == (Object)null)
			{
				((Component)effect).gameObject.AddComponent<ModAssassinPoofEffect>().CopyPresentationFrom(effect);
			}
			effect.automatic = false;
			((MonoBehaviour)effect).StopAllCoroutines();
			((Behaviour)effect).enabled = false;
			return true;
		}

		internal static void MigrateLegacyAbility(SerializedUnitBlueprint data, LandfallContentDatabase database = null)
		{
			//IL_0014: 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)
			if (data?.m_combatMoves != null && data.m_combatMoves.Contains(LegacyAbilityId))
			{
				SpecialAbility val = ResolveNativeAbility(database);
				if (((val != null) ? ((CharacterItem)val).Entity : null) == null)
				{
					BetterTracingPlugin.LogPluginWarning("Could not convert the old modded Assassin Poof: the vanilla ability is unavailable.");
				}
				else
				{
					ReplaceLegacyAbilityIds(data, ((CharacterItem)val).Entity.GUID);
				}
			}
		}

		internal static void ReplaceLegacyAbilityIds(SerializedUnitBlueprint data, DatabaseID nativeId)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (data?.m_combatMoves != null && !((DatabaseID)(ref nativeId)).IsDefaultID() && !(nativeId == LegacyAbilityId))
			{
				data.m_combatMoves = data.m_combatMoves.Select((DatabaseID id) => (!(id == LegacyAbilityId)) ? id : nativeId).ToArray();
			}
		}
	}
	public sealed class ModAssassinPoofEffect : MonoBehaviour
	{
		private readonly struct BodyShape
		{
			internal readonly float BottomY;

			internal readonly float LowerExtent;

			internal readonly float UpperExtent;

			internal readonly float Radius;

			internal BodyShape(float bottomY, float lowerExtent, float upperExtent, float radius)
			{
				BottomY = bottomY;
				LowerExtent = lowerExtent;
				UpperExtent = upperExtent;
				Radius = radius;
			}
		}

		private readonly struct RigidbodySnapshot
		{
			internal readonly Rigidbody Rigidbody;

			internal readonly bool WasKinematic;

			internal readonly bool DetectedCollisions;

			internal RigidbodySnapshot(Rigidbody rigidbody, bool wasKinematic, bool detectedCollisions)
			{
				Rigidbody = rigidbody;
				WasKinematic = wasKinematic;
				DetectedCollisions = detectedCollisions;
			}
		}

		private const int NormalCandidateAttempts = 40;

		private const int ExpandedCandidateAttempts = 72;

		private const float GoldenAngleDegrees = 137.50777f;

		private const float MaximumGroundDrop = 10f;

		private const float MinimumWalkableNormalY = 0.55f;

		private const float LandingClearance = 0.08f;

		private const float WallClearance = 0.14f;

		private Unit m_unit;

		private CanDoUnitEvents m_canDo;

		private ParticleSystem m_particles;

		private AssassinPoofEffect m_nativePresentation;

		private UnityEvent m_poofEvent;

		private float m_counter;

		private bool m_done;

		private bool m_initialized;

		private float TriggerDelaySeconds => UnitAbilityRuntime.Number((Component)(object)m_nativePresentation, "activationDelay", 0.28f);

		private float MoveDelaySeconds => UnitAbilityRuntime.Number((Component)(object)m_nativePresentation, "moveDelay", 0.015f);

		private float BacklineFraction => UnitAbilityRuntime.Number((Component)(object)m_nativePresentation, "backlinePercent", 40f) / 100f;

		private float MinimumTargetRadius => UnitAbilityRuntime.Number((Component)(object)m_nativePresentation, "distanceFromUnit", 2f);

		private float NormalSearchWidth => UnitAbilityRuntime.Number((Component)(object)m_nativePresentation, "searchWidth", 3.5f);

		private float ExpandedSearchWidth => NormalSearchWidth + 2.5f;

		internal void CopyPresentationFrom(AssassinPoofEffect nativeEffect)
		{
			m_nativePresentation = nativeEffect;
			m_poofEvent = (((Object)(object)nativeEffect != (Object)null) ? nativeEffect.poofEvent : null);
		}

		private void Start()
		{
			//IL_00cd: 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)
			m_unit = ((Component)((Component)this).transform.root).GetComponent<Unit>();
			if ((Object)(object)m_unit == (Object)null)
			{
				return;
			}
			ModAssassinPoofEffect[] componentsInChildren = ((Component)((Component)m_unit).transform.root).GetComponentsInChildren<ModAssassinPoofEffect>(true);
			if (componentsInChildren.Length != 0 && (Object)(object)componentsInChildren[0] != (Object)(object)this)
			{
				((Behaviour)this).enabled = false;
				return;
			}
			m_canDo = ((Component)this).GetComponent<CanDoUnitEvents>();
			m_nativePresentation = ((Component)this).GetComponent<AssassinPoofEffect>();
			if ((Object)(object)m_nativePresentation != (Object)null)
			{
				m_nativePresentation.automatic = false;
				((Behaviour)m_nativePresentation).enabled = false;
				m_poofEvent = m_nativePresentation.poofEvent;
			}
			DisableNativePoofEffectsOnUnit(m_unit);
			m_particles = ((Component)this).GetComponentInChildren<ParticleSystem>();
			if ((Object)(object)m_particles != (Object)null)
			{
				try
				{
					ShapeModule shape = m_particles.shape;
					((ShapeModule)(ref shape)).skinnedMeshRenderer = ((Component)((Component)this).transform.root).GetComponentInChildren<SkinnedMeshRenderer>();
				}
				catch
				{
				}
			}
			m_counter = Random.Range(0f, 0.08f);
			m_initialized = true;
		}

		private static void DisableNativePoofEffectsOnUnit(Unit owner)
		{
			if ((Object)(object)owner == (Object)null)
			{
				return;
			}
			AssassinPoofEffect[] componentsInChildren = ((Component)((Component)owner).transform.root).GetComponentsInChildren<AssassinPoofEffect>(true);
			foreach (AssassinPoofEffect val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && AssassinPoofCompatibility.IsNativeAssassinPoof(val))
				{
					val.automatic = false;
					((MonoBehaviour)val).StopAllCoroutines();
					((Behaviour)val).enabled = false;
				}
			}
		}

		private void Update()
		{
			if (m_initialized && !m_done && !((Object)(object)m_unit == (Object)null) && !m_unit.dead && !((Object)(object)m_unit.data == (Object)null) && !m_unit.data.Dead && (!((Object)(object)m_canDo != (Object)null) || m_canDo.canDoStuff))
			{
				m_counter += Time.deltaTime;
				if (!(m_counter <= TriggerDelaySeconds))
				{
					m_done = true;
					((MonoBehaviour)this).StartCoroutine(DoSafePoof());
				}
			}
		}

		private IEnumerator DoSafePoof()
		{
			if (!TryChooseSafeTeleportDestination(out var target, out var teleportDelta, out var groundPoint, out var groundNormal))
			{
				yield break;
			}
			if ((Object)(object)m_particles != (Object)null)
			{
				m_particles.Emit(25);
			}
			yield return (object)new WaitForSeconds(MoveDelaySeconds);
			if (IsLiveUnit(m_unit) && TryChooseSafeTeleportDestination(out target, out teleportDelta, out groundPoint, out groundNormal))
			{
				List<RigidbodySnapshot> snapshots = FreezeRagdollForTeleport(m_unit);
				MoveRagdollAsOne(m_unit, teleportDelta);
				SnapFeetToGround(m_unit, groundPoint.y);
				if ((Object)(object)m_unit.data != (Object)null)
				{
					m_unit.data.TouchGround(groundPoint, groundNormal, (Rigidbody)null);
				}
				UnityEvent poofEvent = m_poofEvent;
				if (poofEvent != null)
				{
					poofEvent.Invoke();
				}
				if ((Object)(object)m_particles != (Object)null)
				{
					m_particles.Play();
				}
				yield return (object)new WaitForFixedUpdate();
				RestoreRagdollAfterTeleport(m_unit, snapshots);
			}
		}

		private bool TryChooseSafeTeleportDestination(out Unit target, out Vector3 teleportDelta, out Vector3 groundPoint, out Vector3 groundNormal)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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)
			target = null;
			teleportDelta = Vector3.zero;
			groundPoint = Vector3.zero;
			groundNormal = Vector3.up;
			if (!IsLiveUnit(m_unit))
			{
				return false;
			}
			List<Unit> list = (from candidate in Object.FindObjectsOfType<Unit>()
				where IsLiveUnit(candidate) && (Object)(object)candidate != (Object)(object)m_unit && candidate.Team != m_unit.Team
				orderby Vector3.Distance(m_unit.data.mainRig.position, candidate.data.mainRig.position) descending
				select candidate).ToList();
			if (list.Count == 0)
			{
				return false;
			}
			int num = Mathf.Clamp(Mathf.CeilToInt((float)list.Count * BacklineFraction), 1, list.Count);
			ShuffleRange(list, 0, num);
			ShuffleRange(list, num, list.Count - num);
			foreach (Unit item in list)
			{
				if (TryFindSafeDestinationAroundTarget(m_unit, item, expandedSearch: false, out var groundedDelta, out var groundPoint2, out var groundNormal2))
				{
					target = item;
					teleportDelta = groundedDelta;
					groundPoint = groundPoint2;
					groundNormal = groundNormal2;
					return true;
				}
			}
			foreach (Unit item2 in list)
			{
				if (TryFindSafeDestinationAroundTarget(m_unit, item2, expandedSearch: true, out var groundedDelta2, out var groundPoint3, out var groundNormal3))
				{
					target = item2;
					teleportDelta = groundedDelta2;
					groundPoint = groundPoint3;
					groundNormal = groundNormal3;
					return true;
				}
			}
			return false;
		}

		private static void ShuffleRange(List<Unit> units, int start, int count)
		{
			for (int num = start + count - 1; num > start; num--)
			{
				int num2 = Random.Range(start, num + 1);
				int index = num;
				int index2 = num2;
				Unit value = units[num2];
				Unit value2 = units[num];
				units[index] = value;
				units[index2] = value2;
			}
		}

		private bool TryFindSafeDestinationAroundTarget(Unit caster, Unit target, bool expandedSearch, out Vector3 groundedDelta, out Vector3 groundPoint, out Vector3 groundNormal)
		{
			//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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
			groundedDelta = Vector3.zero;
			groundPoint = Vector3.zero;
			groundNormal = Vector3.up;
			if (!IsLiveUnit(caster) || !IsLiveUnit(target) || !TryGetBodyShape(caster, out var shape))
			{
				return false;
			}
			float num = 0.55f;
			if (TryGetBodyShape(target, out var shape2))
			{
				num = shape2.Radius;
			}
			float num2 = Mathf.Max(MinimumTargetRadius, shape.Radius + num + 0.5f);
			float num3 = (expandedSearch ? ExpandedSearchWidth : NormalSearchWidth);
			int num4 = (expandedSearch ? 72 : 40);
			float num5 = Random.Range(0f, 360f);
			for (int i = 0; i < num4; i++)
			{
				float num6 = num5 + (float)i * 137.50777f + Random.Range(-9f, 9f);
				float num7 = (float)(i % 6) / 5f;
				float num8 = num2 + num7 * num3 + Random.Range(-0.12f, 0.12f);
				Vector3 val = Quaternion.Euler(0f, num6, 0f) * Vector3.forward;
				Vector3 horizontalPoint = target.data.mainRig.position + val * num8;
				if (TryBuildSafeGroundedDestination(caster, target, shape, horizontalPoint, out groundedDelta, out groundPoint, out groundNormal))
				{
					return true;
				}
			}
			Vector3 val2 = caster.data.mainRig.position - target.data.mainRig.position;
			val2.y = 0f;
			if (((Vector3)(ref val2)).sqrMagnitude > 0.001f)
			{
				((Vector3)(ref val2)).Normalize();
				for (int j = 0; j < 4; j++)
				{
					Vector3 horizontalPoint2 = target.data.mainRig.position + val2 * (num2 + (float)j * 0.8f);
					if (TryBuildSafeGroundedDestination(caster, target, shape, horizontalPoint2, out groundedDelta, out groundPoint, out groundNormal))
					{
						return true;
					}
				}
			}
			return false;
		}

		private static bool TryBuildSafeGroundedDestination(Unit caster, Unit target, BodyShape casterShape, Vector3 horizontalPoint, out Vector3 groundedDelta, out Vector3 groundPoint, out Vector3 groundNormal)
		{
			//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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_00ec: 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)
			groundedDelta = Vector3.zero;
			groundPoint = Vector3.zero;
			groundNormal = Vector3.up;
			Vector3 position = caster.data.mainRig.position;
			if (!TryFindGroundBelow(new Vector3(horizontalPoint.x, Mathf.Max(position.y, target.data.mainRig.position.y) + 2f, horizontalPoint.z), out var ground))
			{
				return false;
			}
			float num = position.y - casterShape.BottomY;
			if (num < 0f)
			{
				return false;
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(horizontalPoint.x, ((RaycastHit)(ref ground)).point.y + num + 0.08f, horizontalPoint.z);
			if (!IsLandingVolumeClear(val, casterShape, caster))
			{
				return false;
			}
			if (HasEnvironmentBetweenTargetAndDestination(target, val))
			{
				return false;
			}
			groundedDelta = val - position;
			if (!AreTranslatedUnitCollidersClear(caster, groundedDelta))
			{
				groundedDelta = Vector3.zero;
				return false;
			}
			groundPoint = ((RaycastHit)(ref ground)).point;
			groundNormal = ((RaycastHit)(ref ground)).normal;
			return true;
		}

		private static bool TryFindGroundBelow(Vector3 destination, out RaycastHit ground)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			ground = default(RaycastHit);
			RaycastHit[] array = Physics.RaycastAll(destination + Vector3.up * 2f, Vector3.down, 12f, -1, (QueryTriggerInteraction)1);
			Array.Sort(array, (RaycastHit left, RaycastHit right) => ((RaycastHit)(ref left)).distance.CompareTo(((RaycastHit)(ref right)).distance));
			RaycastHit[] array2 = array;
			for (int num = 0; num < array2.Length; num++)
			{
				RaycastHit val = array2[num];
				Collider collider = ((RaycastHit)(ref val)).collider;
				if (!((Object)(object)collider == (Object)null) && !IsUnitCollider(collider) && !(((RaycastHit)(ref val)).normal.y < 0.55f) && !(destination.y - ((RaycastHit)(ref val)).point.y > 10f) && !(((RaycastHit)(ref val)).point.y > destination.y + 0.25f))
				{
					ground = val;
					return true;
				}
			}
			return false;
		}

		private static bool IsLandingVolumeClear(Vector3 mainRigPosition, BodyShape shape, Unit caster)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			float num = shape.Radius + 0.14f;
			Vector3 val = mainRigPosition + Vector3.down * Mathf.Max(0f, shape.LowerExtent - num);
			Vector3 val2 = mainRigPosition + Vector3.up * Mathf.Max(0f, shape.UpperExtent - num);
			Collider[] array = Physics.OverlapCapsule(val, val2, num, -1, (QueryTriggerInteraction)1);
			foreach (Collider val3 in array)
			{
				if (!((Object)(object)val3 == (Object)null) && !((Component)val3).transform.IsChildOf(((Component)caster).transform))
				{
					return false;
				}
			}
			float num2 = Mathf.Max(0.12f, (shape.LowerExtent + shape.UpperExtent) * 0.5f - 0.06f);
			Vector3 val4 = mainRigPosition + Vector3.up * ((shape.UpperExtent - shape.LowerExtent) * 0.5f + 0.06f);
			Vector3 val5 = default(Vector3);
			((Vector3)(ref val5))..ctor(num * 1.08f, num2, num * 1.08f);
			array = Physics.OverlapBox(val4, val5, Quaternion.identity, -1, (QueryTriggerInteraction)1);
			foreach (Collider val6 in array)
			{
				if (!((Object)(object)val6 == (Object)null) && !((Component)val6).transform.IsChildOf(((Component)caster).transform))
				{
					return false;
				}
			}
			return true;
		}

		private static bool HasEnvironmentBetweenTargetAndDestination(Unit target, Vector3 destination)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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)
			Vector3 val = target.data.mainRig.position + Vector3.up * 0.15f;
			Vector3 val2 = destination - val;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			if (magnitude < 0.25f)
			{
				return false;
			}
			RaycastHit[] array = Physics.RaycastAll(val, val2 / magnitude, magnitude, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val3 = array[i];
				if (!((Object)(object)((RaycastHit)(ref val3)).collider == (Object)null) && !IsUnitCollider(((RaycastHit)(ref val3)).collider) && ((RaycastHit)(ref val3)).distance > 0.15f && ((RaycastHit)(ref val3)).distance < magnitude - 0.1f)
				{
					return true;
				}
			}
			return false;
		}

		private static bool AreTranslatedUnitCollidersClear(Unit caster, Vector3 delta)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			Collider[] componentsInChildren = ((Component)((Component)caster).transform.root).GetComponentsInChildren<Collider>(true);
			Vector3 val3 = default(Vector3);
			foreach (Collider val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || !val.enabled || val.isTrigger)
				{
					continue;
				}
				Bounds bounds = val.bounds;
				float num = Mathf.Max(((Bounds)(ref bounds)).extents.x, ((Bounds)(ref bounds)).extents.z) + 0.14f;
				Vector3 val2 = ((Bounds)(ref bounds)).center + delta + Vector3.up * 0.04f;
				((Vector3)(ref val3))..ctor(num, Mathf.Max(0.02f, ((Bounds)(ref bounds)).extents.y - 0.04f), num);
				Collider[] array = Physics.OverlapBox(val2, val3, Quaternion.identity, -1, (QueryTriggerInteraction)1);
				foreach (Collider val4 in array)
				{
					if (!((Object)(object)val4 == (Object)null) && !((Component)val4).transform.IsChildOf(((Component)caster).transform))
					{
						return false;
					}
				}
			}
			return true;
		}

		private static bool TryGetBodyShape(Unit unit, out BodyShape shape)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_016d: 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_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			shape = default(BodyShape);
			if (!IsLiveUnit(unit))
			{
				return false;
			}
			Vector3 position = unit.data.mainRig.position;
			Bounds val = default(Bounds);
			bool flag = false;
			Rigidbody[] array = (((Object)(object)unit.data.allRigs != (Object)null) ? unit.data.allRigs.AllRigs : ((Component)unit).GetComponentsInChildren<Rigidbody>());
			foreach (Rigidbody val2 in array)
			{
				if ((Object)(object)val2 == (Object)null || (Object)(object)((Component)val2).GetComponentInParent<Weapon>() != (Object)null)
				{
					continue;
				}
				Collider[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Collider>();
				foreach (Collider val3 in componentsInChildren)
				{
					if (!((Object)(object)val3 == (Object)null) && val3.enabled && !val3.isTrigger)
					{
						if (!flag)
						{
							val = val3.bounds;
							flag = true;
						}
						else
						{
							((Bounds)(ref val)).Encapsulate(val3.bounds);
						}
					}
				}
			}
			float num = Mathf.Clamp(((Object)(object)unit.unitBlueprint != (Object)null) ? unit.unitBlueprint.sizeMultiplier : 1f, 0.5f, 3f);
			if (!flag)
			{
				shape = new BodyShape(position.y - 0.8f * num, 0.8f * num, 0.8f * num, 0.45f * num);
				return true;
			}
			float bottomY;
			float num2 = (TryGetActualFootBottomY(unit, out bottomY) ? bottomY : ((Bounds)(ref val)).min.y);
			float lowerExtent = Mathf.Clamp(position.y - num2, 0.35f * num, 2.5f * num);
			float upperExtent = Mathf.Clamp(((Bounds)(ref val)).max.y - position.y, 0.35f * num, 2.5f * num);
			float radius = Mathf.Clamp(Mathf.Max(((Bounds)(ref val)).extents.x, ((Bounds)(ref val)).extents.z) * 0.72f, 0.38f * num, 1.15f * num);
			shape = new BodyShape(num2, lowerExtent, upperExtent, radius);
			return true;
		}

		private static bool TryGetActualFootBottomY(Unit unit, out float bottomY)
		{
			//IL_0155: 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_00d0: 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)
			bottomY = float.PositiveInfinity;
			if ((Object)(object)unit?.data == (Object)null)
			{
				return false;
			}
			bool flag = false;
			Transform[] array = (Transform[])(object)new Transform[2]
			{
				unit.data.footLeft,
				unit.data.footRight
			};
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Rigidbody component = ((Component)val).GetComponent<Rigidbody>();
				Collider[] array3 = (((Object)(object)component != (Object)null) ? ((Component)component).GetComponentsInChildren<Collider>() : ((Component)val).GetComponentsInChildren<Collider>());
				foreach (Collider val2 in array3)
				{
					if (!((Object)(object)val2 == (Object)null) && val2.enabled && !val2.isTrigger && (!((Object)(object)component != (Object)null) || !((Object)(object)val2.attachedRigidbody != (Object)(object)component)))
					{
						float num = bottomY;
						Bounds bounds = val2.bounds;
						bottomY = Mathf.Min(num, ((Bounds)(ref bounds)).min.y);
						flag = true;
					}
				}
			}
			if (flag)
			{
				return true;
			}
			float num2 = Mathf.Clamp(((Object)(object)unit.unitBlueprint != (Object)null) ? unit.unitBlueprint.sizeMultiplier : 1f, 0.5f, 3f);
			array2 = array;
			foreach (Transform val3 in array2)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					bottomY = Mathf.Min(bottomY, val3.position.y - 0.12f * num2);
				}
			}
			return !float.IsPositiveInfinity(bottomY);
		}

		private static bool IsUnitCollider(Collider collider)
		{
			if ((Object)(object)collider != (Object)null)
			{
				return (Object)(object)((Component)collider).GetComponentInParent<Unit>() != (Object)null;
			}
			return false;
		}

		private static bool IsLiveUnit(Unit unit)
		{
			if ((Object)(object)unit != (Object)null && !unit.dead && (Object)(object)unit.data != (Object)null && !unit.data.Dead && (Object)(object)unit.data.mainRig != (Object)null)
			{
				return unit.data.health > 0f;
			}
			return false;
		}

		private static List<RigidbodySnapshot> FreezeRagdollForTeleport(Unit unit)
		{
			//IL_004a: 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)
			List<RigidbodySnapshot> list = new List<RigidbodySnapshot>();
			Rigidbody[] componentsInChildren = ((Component)((Component)unit).transform.root).GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null))
				{
					list.Add(new RigidbodySnapshot(val, val.isKinematic, val.detectCollisions));
					if (!val.isKinematic)
					{
						val.velocity = Vector3.zero;
						val.angularVelocity = Vector3.zero;
					}
					val.detectCollisions = false;
					val.isKinematic = true;
				}
			}
			return list;
		}

		private static void MoveRagdollAsOne(Unit unit, Vector3 delta)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			MoveRagdollAsOne(unit, delta, rotateBodyChildren: true);
		}

		private static void MoveRagdollAsOne(Unit unit, Vector3 delta, bool rotateBodyChildren)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_012c: 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)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: 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)
			Rigidbody[] componentsInChildren = ((Component)((Component)unit).transform.root).GetComponentsInChildren<Rigidbody>(true);
			HashSet<Transform> hashSet = new HashSet<Transform>();
			Rigidbody[] array = componentsInChildren;
			foreach (Rigidbody val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					val.position += delta;
					hashSet.Add(((Component)val).transform);
				}
			}
			if (rotateBodyChildren && (Object)(object)unit.data != (Object)null)
			{
				for (int j = 0; j < ((Component)unit.data).transform.childCount; j++)
				{
					((Component)unit.data).transform.GetChild(j).Rotate(Vector3.up * 180f);
				}
			}
			PhysicsFollowBodyPart[] componentsInChildren2 = ((Component)((Component)unit).transform.root).GetComponentsInChildren<PhysicsFollowBodyPart>(true);
			foreach (PhysicsFollowBodyPart val2 in componentsInChildren2)
			{
				if (!((Object)(object)val2 == (Object)null) && !HasMovedRigidbodyParent(((Component)val2).transform, hashSet))
				{
					Transform transform = ((Component)val2).transform;
					transform.position += delta;
				}
			}
			MoveNonRigidbodyWeapon(unit.WeaponHandler?.rightWeapon, delta, hashSet);
			MoveNonRigidbodyWeapon(unit.WeaponHandler?.leftWeapon, delta, hashSet);
			if ((Object)(object)unit.data != (Object)null)
			{
				unit.data.currentVelocity = Vector3.zero;
				unit.data.lastPos = (((Object)(object)unit.data.mainRig != (Object)null) ? unit.data.mainRig.position : Vector3.zero);
				DataHandler data = unit.data;
				data.groundPosition += delta;
				DataHandler data2 = unit.data;
				data2.groundMapPosition += delta;
				DataHandler data3 = unit.data;
				data3.centerOfMass += delta;
				DataHandler data4 = unit.data;
				data4.centerOfMassWithoutY += new Vector3(delta.x, 0f, delta.z);
			}
			Physics.SyncTransforms();
		}

		private static void SnapFeetToGround(Unit unit, float groundY)
		{
			//IL_0029: 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)
			Physics.SyncTransforms();
			if (TryGetActualFootBottomY(unit, out var bottomY))
			{
				float num = groundY + 0.08f - bottomY;
				if (!(Mathf.Abs(num) < 0.005f))
				{
					MoveRagdollAsOne(unit, Vector3.up * num, rotateBodyChildren: false);
				}
			}
		}

		private static bool HasMovedRigidbodyParent(Transform transform, HashSet<Transform> movedTransforms)
		{
			Transform val = transform;
			while ((Object)(object)val != (Object)null)
			{
				if (movedTransforms.Contains(val))
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		private static void MoveNonRigidbodyWeapon(Weapon weapon, Vector3 delta, HashSet<Transform> movedTransforms)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)weapon == (Object)null) && !HasMovedRigidbodyParent(((Component)weapon).transform, movedTransforms))
			{
				Transform transform = ((Component)weapon).transform;
				transform.position += delta;
			}
		}

		private static void RestoreRagdollAfterTeleport(Unit unit, List<RigidbodySnapshot> snapshots)
		{
			//IL_0036: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			foreach (RigidbodySnapshot snapshot in snapshots)
			{
				Rigidbody rigidbody = snapshot.Rigidbody;
				if (!((Object)(object)rigidbody == (Object)null))
				{
					rigidbody.isKinematic = snapshot.WasKinematic;
					if (!snapshot.WasKinematic)
					{
						rigidbody.velocity = Vector3.zero;
						rigidbody.angularVelocity = Vector3.zero;
					}
					rigidbody.detectCollisions = snapshot.DetectedCollisions;
				}
			}
			if ((Object)(object)unit != (Object)null && (Object)(object)unit.data != (Object)null && (Object)(object)unit.data.mainRig != (Object)null)
			{
				unit.data.currentVelocity = Vector3.zero;
				unit.data.lastPos = unit.data.mainRig.position;
			}
			Physics.SyncTransforms();
		}
	}
	[HarmonyPatch(typeof(UnitBlueprint), "DeserializedUnit", new Type[]
	{
		typeof(SerializedUnitBlueprint),
		typeof(AssetLoader),
		typeof(LandfallContentDatabase)
	})]
	internal static class AssassinPoofLegacyLoadPatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void Prefix(SerializedUnitBlueprint data, LandfallContentDatabase landfallContentDatabase)
		{
			AssassinPoofCompatibility.MigrateLegacyAbility(data, landfallContentDatabase);
		}
	}
	[HarmonyPatch(typeof(UnitBlueprint), "SerializedUnit", new Type[] { typeof(DatabaseID) })]
	internal static class AssassinPoofVanillaSavePatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void Postfix(SerializedUnitBlueprint __result)
		{
			AssassinPoofCompatibility.MigrateLegacyAbility(__result);
		}
	}
	[HarmonyPatch(typeof(AssassinPoofEffect), "Start")]
	internal static class NativeAssassinPoofStartOverridePatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool Prefix(AssassinPoofEffect __instance)
		{
			return !AssassinPoofCompatibility.TryAttachToSpawnedUnit(__instance);
		}
	}
	[HarmonyPatch(typeof(AssassinPoofEffect), "Update")]
	internal static class NativeAssassinPoofUpdateOverridePatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool Prefix(AssassinPoofEffect __instance)
		{
			return !AssassinPoofCompatibility.TryAttachToSpawnedUnit(__instance);
		}
	}
	[HarmonyPatch(typeof(AssassinPoofEffect), "DoThePoof")]
	internal static class NativeAssassinPoofManualOverridePatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool Prefix(AssassinPoofEffect __instance)
		{
			return !AssassinPoofCompatibility.TryAttachToSpawnedUnit(__instance);
		}
	}
	internal sealed class CarBodySupport : MonoBehaviour
	{
		private static readonly HashSet<CarBodySupport> Active = new HashSet<CarBodySupport>();

		private Collider[] _colliders;

		internal Unit Unit { get; private set; }

		internal Rigidbody Chassis => Unit?.data?.mainRig;

		internal static bool HasCars => Active.Count != 0;

		internal static bool IsCarBase(GameObject asset)
		{
			if ((Object)(object)asset != (Object)null)
			{
				if (!string.Equals(((Object)asset).name, "Car", StringComparison.OrdinalIgnoreCase))
				{
					return string.Equals(((Object)asset).name, "Volkswagen", StringComparison.OrdinalIgnoreCase);
				}
				return true;
			}
			return false;
		}

		internal static CarBodySupport Ensure(Unit unit)
		{
			if (!((Object)(object)unit == (Object)null))
			{
				UnitBlueprint unitBlueprint = unit.unitBlueprint;
				if (IsCarBase((unitBlueprint != null) ? unitBlueprint.UnitBase : null))
				{
					CarBodySupport carBodySupport = ((Component)unit).GetComponent<CarBodySupport>() ?? ((Component)unit).gameObject.AddComponent<CarBodySupport>();
					carBodySupport.Unit = unit;
					if (carBodySupport._colliders == null)
					{
						List<Collider> list = new List<Collider>();
						Collider[] componentsInChildren = ((Component)unit).GetComponentsInChildren<Collider>(true);
						foreach (Collider val in componentsInChildren)
						{
							if (!((Object)(object)((Component)val).GetComponentInParent<Unit>() == (Object)(object)unit) || !((Object)(object)((Component)val).GetComponentInParent<Holdable>() == (Object)null))
							{
								continue;
							}
							if (!(val is BoxCollider) && !(val is SphereCollider) && !(val is CapsuleCollider))
							{
								MeshCollider val2 = (MeshCollider)(object)((val is MeshCollider) ? val : null);
								if (val2 == null || !val2.convex)
								{
									continue;
								}
							}
							list.Add(val);
						}
						carBodySupport._colliders = list.ToArray();
					}
					if (((Behaviour)carBodySupport).isActiveAndEnabled)
					{
						Active.Add(carBodySupport);
					}
					return carBodySupport;
				}
			}
			return null;
		}

		internal bool TryDistance(Vector3 origin, out float distance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			Vector3 point;
			return TryClosestPoint(origin, out point, out distance);
		}

		internal bool TryClosestPoint(Vector3 origin, out Vector3 point, out float distance)
		{
			//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_000e: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			point = origin;
			distance = float.PositiveInfinity;
			if (TracingGeometry.IsFinite(origin) && !((Object)(object)Unit == (Object)null) && !Unit.dead)
			{
				DataHandler data = Unit.data;
				if (data != null && !data.Dead && _colliders != null)
				{
					Collider[] colliders = _colliders;
					foreach (Collider val in colliders)
					{
						if (!((Object)(object)val == (Object)null) && val.enabled && ((Component)val).gameObject.activeInHierarchy && !val.isTrigger)
						{
							Vector3 val2 = val.ClosestPoint(origin);
							Vector3 val3 = val2 - origin;
							float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
							if (!float.IsNaN(sqrMagnitude) && sqrMagnitude < distance)
							{
								distance = sqrMagnitude;
								point = val2;
							}
						}
					}
					if (float.IsInfinity(distance))
					{
						return false;
					}
					distance = Mathf.Sqrt(distance) - 0.3f;
					return true;
				}
			}
			return false;
		}

		private void OnEnable()
		{
			if ((Object)(object)Unit != (Object)null)
			{
				Active.Add(this);
			}
		}

		private void OnDisable()
		{
			Active.Remove(this);
		}

		private void OnDestroy()
		{
			Active.Remove(this);
		}

		internal static void RefreshTargets()
		{
			//IL_00b7: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: 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_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			World active = World.Active;
			TeamSystem val = ((active != null) ? active.GetExistingManager<TeamSystem>() : null);
			if (val == null)
			{
				return;
			}
			EntityManager existingManager = active.GetExistingManager<EntityManager>();
			if (existingManager == null || !existingManager.IsCreated)
			{
				return;
			}
			foreach (Unit allUnit in val.GetAllUnits())
			{
				if ((Object)(object)allUnit == (Object)null || allUnit.dead || (Object)(object)allUnit.api == (Object)null || allUnit.api.IsPossessed || allUnit.api.IsRemotelyControlled)
				{
					continue;
				}
				GameObjectEntity component = ((Component)allUnit).GetComponent<GameObjectEntity>();
				if ((Object)(object)component == (Object)null || component.EntityManager != existingManager || !existingManager.Exists(component.Entity) || !existingManager.HasComponent<HasTargetTag>(component.Entity) || !existingManager.HasComponent<TargetData>(component.Entity) || !existingManager.HasComponent<Range>(component.Entity))
				{
					continue;
				}
				HasTargetTag componentData = existingManager.GetComponentData<HasTargetTag>(component.Entity);
				if (!(componentData.Target == Entity.Null) && existingManager.Exists(componentData.Target))
				{
					Unit val2 = val.GetDataHandler(componentData.Target)?.unit;
					CarBodySupport carBodySupport = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<CarBodySupport>() : null);
					if (!((Object)(object)carBodySupport == (Object)null) && carBodySupport.TryDistance(allUnit.api.GetPredictedPosition(), out var distance))
					{
						TargetData componentData2 = existingManager.GetComponentData<TargetData>(component.Entity);
						Range componentData3 = existingManager.GetComponentData<Range>(component.Entity);
						componentData2.DistanceToTarget = distance;
						componentData2.TargetInAttackRange = ((distance <= componentData3.AttackRange) ? 1 : 0);
						componentData2.TargetInPreferredRange = ((distance + 0.3f <= componentData3.PreferredRange) ? 1 : 0);
						existingManager.SetComponentData<TargetData>(component.Entity, componentData2);
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(UnitAPI), "InitializeECSUnit")]
	internal static class CarBodyInitializePatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void Postfix(UnitAPI __instance)
		{
			CarBodySupport.Ensure(((Component)__instance).GetComponent<Unit>());
		}
	}
	[HarmonyPatch(typeof(CanSeeSystem), "OnUpdate")]
	internal static class CarTargetSurfacePatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void Prefix(JobHandle inputDeps)
		{
			if (CarBodySupport.HasCars)
			{
				((JobHandle)(ref inputDeps)).Complete();
				CarBodySupport.RefreshTargets();
			}
		}
	}
	[HarmonyPatch(typeof(MeleeWeapon), "Attack")]
	internal static class CarMeleeSurfaceAimPatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void Prefix(MeleeWeapon __instance, Rigidbody targetRig, Transform ___forcePoint, ref Vector3 position)
		{
			//IL_0034: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			CarBodySupport carBodySupport = (((Object)(object)targetRig != (Object)null) ? ((Component)targetRig).GetComponentInParent<CarBodySupport>() : null);
			if ((Object)(object)carBodySupport != (Object)null && carBodySupport.TryClosestPoint(((Object)(object)___forcePoint != (Object)null) ? ___forcePoint.position : ((Component)__instance).transform.position, out var point, out var _))
			{
				position = point;
			}
		}
	}
	internal sealed class CarRiderPhysics : MonoBehaviour
	{
		private sealed class Pair
		{
			internal Collider First;

			internal Collider Second;

			internal CarRiderPhysics Other;

			internal bool HasOther;
		}

		private sealed class Solver
		{
			internal Rigidbody Rig;

			internal int Iterations;

			internal int Velocity;
		}

		private static readonly HashSet<CarRiderPhysics> Riders = new HashSet<CarRiderPhysics>();

		private readonly List<Pair> _pairs = new List<Pair>();

		private readonly List<ConfigurableJoint> _joints = new List<ConfigurableJoint>();

		private readonly List<Solver> _solvers = new List<Solver>();

		private Mount _mount;

		private Collider[] _colliders;

		private bool _released;

		internal CarBodySupport Car { get; private set; }

		internal static void Bind(Mount mount)
		{
			CarBodySupport carBodySupport = CarBodySupport.Ensure((mount == null) ? null : mount.OtherData?.unit);
			if ((Object)(object)carBodySupport == (Object)null || !mount.IsMounted)
			{
				return;
			}
			CarRiderPhysics carRiderPhysics = ((Component)mount).GetComponent<CarRiderPhysics>() ?? ((Component)mount).gameObject.AddComponent<CarRiderPhysics>();
			carRiderPhysics.Release();
			carRiderPhysics._released = false;
			carRiderPhysics._mount = mount;
			carRiderPhysics.Car = carBodySupport;
			carRiderPhysics._colliders = ((Component)mount).GetComponentsInChildren<Collider>(true);
			Collider[] componentsInChildren = ((Component)carBodySupport).GetComponentsInChildren<Collider>(true);
			Collider[] colliders = carRiderPhysics._colliders;
			foreach (Collider first in colliders)
			{
				Collider[] array = componentsInChildren;
				foreach (Collider val in array)
				{
					if ((Object)(object)((Component)val).GetComponentInParent<Unit>() == (Object)(object)carBodySupport.Unit)
					{
						carRiderPhysics.Ignore(first, val, null);
					}
				}
			}
			foreach (CarRiderPhysics rider in Riders)
			{
				if (!((Object)(object)rider.Car == (Object)(object)carBodySupport) || !((Object)(object)rider._mount != (Object)null) || !rider._mount.IsMounted)
				{
					continue;
				}
				colliders = carRiderPhysics._colliders;
				foreach (Collider first2 in colliders)
				{
					Collider[] array = rider._colliders;
					foreach (Collider second in array)
					{
						carRiderPhysics.Ignore(first2, second, rider);
					}
				}
			}
			Rigidbody[] componentsInChildren2 = ((Component)mount).GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody val2 in componentsInChildren2)
			{
				if (!((Object)(object)((Component)val2).GetComponentInParent<Unit>() != (Object)(object)((Component)mount).GetComponent<Unit>()))
				{
					carRiderPhysics._solvers.Add(new Solver
					{
						Rig = val2,
						Iterations = val2.solverIterations,
						Velocity = val2.solverVelocityIterations
					});
					val2.solverIterations = Mathf.Max(val2.solverIterations, 12);
					val2.solverVelocityIterations = Mathf.Max(val2.solverVelocityIterations, 4);
				}
			}
			Riders.Add(carRiderPhysics);
		}

		private void Ignore(Collider first, Collider second, CarRiderPhysics other)
		{
			if (!((Object)(object)first == (Object)null) && !((Object)(object)second == (Object)null) && !((Object)(object)first == (Object)(object)second) && !Physics.GetIgnoreCollision(first, second))
			{
				Physics.IgnoreCollision(first, second, true);
				_pairs.Add(new Pair
				{
					First = first,
					Second = second,
					Other = other,
					HasOther = ((Object)(object)other != (Object)null)
				});
			}
		}

		internal static CarRiderPhysics For(Rigidbody rider, Rigidbody vehicle)
		{
			CarRiderPhysics carRiderPhysics = (((Object)(object)rider != (Object)null) ? ((Component)rider).GetComponentInParent<CarRiderPhysics>() : null);
			if (!((Object)(object)carRiderPhysics != (Object)null) || carRiderPhysics._released || !((Object)(object)carRiderPhysics._mount != (Object)null) || !carRiderPhysics._mount.IsMounted || !((Object)(object)carRiderPhysics.Car != (Object)null) || !((Object)(object)vehicle != (Object)null) || !((Object)(object)((Component)vehicle).GetComponentInParent<Unit>() == (Object)(object)carRiderPhysics.Car.Unit))
			{
				return null;
			}
			return carRiderPhysics;
		}

		internal void Track(ConfigurableJoint joint)
		{
			if (!((Object)(object)joint == (Object)null))
			{
				((Joint)joint).enableCollision = false;
				_joints.Add(joint);
			}
		}

		private void FixedUpdate()
		{
			if (_released)
			{
				return;
			}
			if ((Object)(object)_mount == (Object)null || !_mount.IsMounted || (Object)(object)Car == (Object)null || !((Behaviour)Car).isActiveAndEnabled)
			{
				Release();
				return;
			}
			for (int num = _pairs.Count - 1; num >= 0; num--)
			{
				Pair pair = _pairs[num];
				if (pair.HasOther && (!((Object)(object)pair.Other != (Object)null) || pair.Other._released))
				{
					Restore(pair);
					_pairs.RemoveAt(num);
				}
			}
		}

		private static void Restore(Pair pair)
		{
			if ((Object)(object)pair.First != (Object)null && (Object)(object)pair.Second != (Object)null)
			{
				Physics.IgnoreCollision(pair.First, pair.Second, false);
			}
		}

		private void Release()
		{
			_released = true;
			Riders.Remove(this);
			foreach (Pair pair in _pairs)
			{
				Restore(pair);
			}
			_pairs.Clear();
			foreach (ConfigurableJoint joint in _joints)
			{
				if ((Object)(object)joint != (Object)null)
				{
					Object.Destroy((Object)(object)joint);
				}
			}
			_joints.Clear();
			foreach (Solver solver in _solvers)
			{
				if (!((Object)(object)solver.Rig == (Object)null))
				{
					if (solver.Rig.solverIterations == Mathf.Max(solver.Iterations, 12))
					{
						solver.Rig.solverIterations = solver.Iterations;
					}
					if (solver.Rig.solverVelocityIterations == Mathf.Max(solver.Velocity, 4))
					{
						solver.Rig.solverVelocityIterations = solver.Velocity;
					}
				}
			}
			_solvers.Clear();
		}

		private void OnDisable()
		{
			Release();
		}

		private void OnDestroy()
		{
			Release();
		}
	}
	[HarmonyPatch(typeof(Mount), "EnterMount")]
	internal static class CarRiderMountedPatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void Postfix(Mount __instance)
		{
			CarRiderPhysics.Bind(__instance);
		}
	}
	[HarmonyPatch(typeof(JointActions), "AttachJoint", new Type[]
	{
		typeof(Rigidbody),
		typeof(Rigidbody),
		typeof(float),
		typeof(float),
		typeof(bool),
		typeof(bool),
		typeof(float)
	})]
	internal static class CarRiderSeatJointPatch
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void Prefix(Rigidbody __0, ref Rigidbody __1, out CarRiderPhysics __state)
		{
			__state = CarRiderPhysics.For(__0, __1);
			if ((Object)(object)__state?.Car.Chassis != (Object)null)
			{
				__1 = __state.Car.Chassis;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void Postfix(CarRiderPhysics __state, ConfigurableJoint __result)
		{
			__state?.Track(__result);
		}
	}
	internal sealed class CompanionUnitSession
	{
		internal readonly FormationMember Member;

		internal readonly UnitBlueprint Source;

		private readonly UnitFormation _formation;

		private readonly DatabaseID _parent;

		private readonly DatabaseID _unit;

		private string _copy;

		private string _stats;

		private string _abilities;

		private string _equipment;

		internal CompanionUnitSession(UnitFormation formation, int index, DatabaseID parent)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			if (formation?.units == null || index < 0 || index >= formation.units.Count || formation.units[index] == null)
			{
				throw new ArgumentException("This added unit is no longer available.");
			}
			_formation = formation;
			Member = formation.units[index];
			_parent = parent;
			_unit = Member.unit;
			Source = UnitFormationData.ResolveMember(Member);
			UnitBlueprint source = Source;
			if (((source != null) ? source.Entity : null) == null || (Object)(object)Source.UnitBase == (Object)null)
			{
				throw new InvalidOperationException("This added unit is unavailable.");
			}
			Remember();
		}

		internal bool Allows(UnitBlueprint unit)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (((unit != null) ? unit.Entity : null) != null && (Object)(object)unit.UnitBase != (Object)null)
			{
				return !UnitFormationData.WouldCreateCycle(unit, _parent);
			}
			return false;
		}

		internal bool Save(UnitFormation current, UnitBlueprint edited)
		{
			//IL_0032: 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)
			if (current == _formation)
			{
				List<FormationMember> units = current.units;
				if (units != null && units.Contains(Member) && !(Member.unit != _unit) && !(Member.copyJson != _copy) && !(Member.statsJson != _stats) && !(Member.abilitiesJson != _abilities) && !(Member.equipmentJson != _equipment) && Allows(edited))
				{
					string equipmentJson = JsonUtility.ToJson((object)new SerializedFormationEquipment
					{
						fullUnit = true,
						recipe = RiderRecipe.Capture(edited)
					});
					Member.equipmentJson = equipmentJson;
					Member.abilitiesJson = null;
					UnitFormationStats.Commit(Member, null);
					FormationEquipmentData.Invalidate(Member);
					Remember();
					return true;
				}
			}
			return false;
		}

		private void Remember()
		{
			_copy = Member.copyJson;
			_stats = Member.statsJson;
			_abilities = Member.abilitiesJson;
			_equipment = Member.equipmentJson;
		}
	}
	internal static class ConversionWeaponLoadout
	{
		internal static void Copy(UnitBlueprint target, UnitBlueprint source)
		{
			UnitDefaultsData.ReplaceWeapons(target, source);
			target.holdinigWithTwoHands = source.holdinigWithTwoHands;
			target.attackSpeedMultiplier = source.attackSpeedMultiplier;
			target.damageMultiplier = source.damageMultiplier;
			target.rangeMultiplier = source.rangeMultiplier;
			target.scaleWeapons = source.scaleWeapons;
			target.weaponSeparation = source.weaponSeparation;
			target.removeCloseRangeMiss = source.removeCloseRangeMiss;
			UnitWeaponData.Copy(target, source);
		}
	}
	[HarmonyPatch(typeof(UnitSpawner), "Spawn")]
	internal static class ConversionWeaponSpawn
	{
		internal sealed class State
		{
			internal UnitBlueprint Original;

			internal UnitBlueprint Ranged;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void Prefix(UnitSpawner __instance, Unit ___rootUnit, bool ___isHumanoid, out State __state)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			__state = null;
			if (!__instance.useRootWeapon || !__instance.spawnWithRootScaleAndMass || !___isHumanoid || (Object)(object)___rootUnit == (Object)null || (Object)(object)___rootUnit.unitBlueprint == (Object)null)
			{
				return;
			}
			State state = new State
			{
				Original = __instance.unitBlueprint,
				Ranged = __instance.rangedUnitBlueprint
			};
			GameObject val = null;
			ConversionWeaponRecipes conversionWeaponRecipes = null;
			try
			{
				val = new GameObject("Converted weapon recipes")
				{
					hideFlags = (HideFlags)61
				};
				conversionWeaponRecipes = val.AddComponent<ConversionWeaponRecipes>();
				conversionWeaponRecipes.Normal = Duplicate(state.Original, ___rootUnit.unitBlueprint);
				if (__instance.switchIfRanged)
				{
					conversionWeaponRecipes.Ranged = (((Object)(object)state.Ranged == (Object)(object)state.Original) ? conversionWeaponRecipes.Normal : Duplicate(state.Ranged, ___rootUnit.unitBlueprint));
				}
				ServiceLocator.GetService<RuntimeGarbageCollector>().AddGameObject(val);
				__state = state;
				__instance.unitBlueprint = conversionWeaponRecipes.Normal;
				if (__instance.switchIfRanged)
				{
					__instance.rangedUnitBlueprint = conversionWeaponRecipes.Ranged;
				}
			}
			catch (Exception ex)
			{
				conversionWeaponRecipes?.Release();
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				BetterTracingPlugin.LogPluginWarning("Could not preserve converted weapon settings: " + ex.Message);
			}
		}

		private static UnitBlueprint Duplicate(UnitBlueprint template, UnitBlueprint source)
		{
			if ((Object)(object)template == (Object)null)
			{
				return null;
			}
			UnitBlueprint val = Object.Instantiate<UnitBlueprint>(template);
			try
			{
				((Object)val).hideFlags = (HideFlags)61;
				ConversionWeaponLoadout.Copy(val, source);
				return val;
			}
			catch
			{
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static Exception Finalizer(UnitSpawner __instance, State __state, Exception __exception)
		{
			if (__state != null)
			{
				__instance.unitBlueprint = __state.Original;
				__instance.rangedUnitBlueprint = __state.Ranged;
			}
			return __exception;
		}
	}
	internal sealed class ConversionWeaponRecipes : MonoBehaviour
	{
		internal UnitBlueprint Normal;

		internal UnitBlueprint Ranged;

		internal void Release()
		{
			if ((Object)(object)Ranged != (Object)null && (Object)(object)Ranged != (Object)(object)Normal)
			{
				Object.Destroy((Object)(object)Ranged);
			}
			if ((Object)(object)Normal != (Object)null)
			{
				Object.Destroy((Object)(object)Normal);
			}
			Normal = (Ranged = null);
		}

		private void OnDestroy()
		{
			Release();
		}
	}
	internal static class EffectRadiusLines
	{
		internal sealed class State
		{
			internal Renderer Renderer;

			internal LineEffects Effect;

			internal float Inherited;

			internal float RootScale;
		}

		private static readonly FieldInfo Initialized = AccessTools.Field(typeof(LineEffects), "inited");

		private static readonly FieldInfo StartWidth = AccessTools.Field(typeof(LineEffects), "startWidth");

		private static readonly FieldInfo ScaleMultiplier = AccessTools.Field(typeof(LineEffects), "scaleMultiplier");

		internal static List<State> Capture(GameObject root)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			List<State> list = new List<State>();
			Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if ((val is LineRenderer || val is TrailRenderer) && EffectRadiusVisuals.Owned(root.transform, ((Component)val).transform))
				{
					LineEffects val2 = ((val is LineRenderer) ? ((Component)val).GetComponent<LineEffects>() : null);
					list.Add(new State
					{
						Renderer = val,
						Effect = val2,
						Inherited = (((Object)(object)val2 != (Object)null) ? Inherited(val2) : 1f),
						RootScale = ((Component)val).transform.root.localScale.x
					});
				}
			}
			return list;
		}

		private static float Inherited(LineEffects effect)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return 1f - effect.inheritScaleFactor + ((Component)effect).transform.lossyScale.x * effect.inheritScaleFactor;
		}

		internal static void Resize(List<State> lines, Vector3 center, float factor)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Invalid comparison between Unknown and I4
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			foreach (State line in lines)
			{
				if ((Object)(object)line.Renderer == (Object)null)
				{
					continue;
				}
				Renderer renderer = line.Renderer;
				TrailRenderer val = (TrailRenderer)(object)((renderer is TrailRenderer) ? renderer : null);
				if (val != null)
				{
					val.widthMultiplier *= factor;
					Vector3[] array = (Vector3[])(object)new Vector3[val.positionCount];
					val.GetPositions(array);
					for (int i = 0; i < array.Length; i++)
					{
						array[i] = center + (array[i] - center) * factor;
					}
					val.SetPositions(array);
					continue;
				}
				LineRenderer val2 = (LineRenderer)line.Renderer;
				LineEffects effect = line.Effect;
				if ((Object)(object)effect != (Object)null)
				{
					float num = Inherited(effect);
					float num2 = factor * line.Inherited / ((Mathf.Abs(num) > 1E-05f) ? num : 1f);
					if ((bool)Initialized.GetValue(effect))
					{
						StartWidth.SetValue(effect, (float)StartWidth.GetValue(effect) * num2);
						ScaleMultiplier.SetValue(effect, num);
						val2.widthMultiplier *= factor;
					}
					else
					{
						val2.widthMultiplier *= num2;
					}
					float x = ((Component)effect).transform.root.localScale.x;
					if ((int)effect.lineType == 1 && Mathf.Abs(x) > 1E-05f)
					{
						effect.radius *= factor * line.RootScale / x;
					}
					LineEffectInstance[] array2 = effect.effects ?? Array.Empty<LineEffectInstance>();
					foreach (LineEffectInstance val3 in array2)
					{
						if ((int)val3.curveType == 0)
						{
							val3.mainCurveMultiplier *= factor;
						}
					}
					continue;
				}
				val2.widthMultiplier *= factor;
				if (val2.useWorldSpace)
				{
					Vector3[] array3 = (Vector3[])(object)new Vector3[val2.positionCount];
					val2.GetPositions(array3);
					for (int k = 0; k < array3.Length; k++)
					{
						array3[k] = center + (array3[k] - center) * factor;
					}
					val2.SetPositions(array3);
				}
			}
		}
	}
	internal static class EffectRadiusParticles
	{
		internal sealed class State
		{
			internal ParticleSystem System;

			internal Matrix4x4 Space;

			internal Particle[] Particles;
		}

		internal static List<State> Capture(GameObject root)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			List<State> list = new List<State>();
			ParticleSystem[] componentsInChildren = root.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				if (EffectRadiusVisuals.Owned(root.transform, ((Component)val).transform))
				{
					Particle[] array = (Particle[])(object)new Particle[val.particleCount];
					val.GetParticles(array);
					list.Add(new State
					{
						System = val,
						Space = Space(val),
						Particles = array
					});
				}
			}
			return list;
		}

		private static Matrix4x4 Space(ParticleSystem system)
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0043: 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_0019: Invalid comparison between Unknown and I4
			//IL_0030: 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)
			MainModule main = system.main;
			if ((int)((MainModule)(ref main)).simulationSpace != 1)
			{
				if ((int)((MainModule)(ref main)).simulationSpace != 2 || !((Object)(object)((MainModule)(ref main)).customSimulationSpace != (Object)null))
				{
					return ((Component)system).transform.localToWorldMatrix;
				}
				return ((MainModule)(ref main)).customSimulationSpace.localToWorldMatrix;
			}
			return Matrix4x4.identity;
		}

		internal static void Resize(List<State> systems, Vector3 center, float factor)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0090: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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_014c: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: 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_01a4: 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_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: 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_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: 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_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: 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_0229: 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_0323: 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_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: 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_027f: Unknown result type (might be due to invalid IL or missing references)
			foreach (State system2 in systems)
			{
				ParticleSystem system = system2.System;
				if ((Object)(object)system == (Object)null)
				{
					continue;
				}
				MainModule main = system.main;
				bool flag = (int)((MainModule)(ref main)).scalingMode > 0;
				if (flag)
				{
					((MainModule)(ref main)).startSizeX = Scale(((MainModule)(ref main)).startSizeX, factor);
					if (((MainModule)(ref main)).startSize3D)
					{
						((MainModule)(ref main)).startSizeY = Scale(((MainModule)(ref main)).startSizeY, factor);
						((MainModule)(ref main)).startSizeZ = Scale(((MainModule)(ref main)).startSizeZ, factor);
					}
					((MainModule)(ref main)).startSpeed = Scale(((MainModule)(ref main)).startSpeed, factor);
					((MainModule)(ref main)).gravityModifier = Scale(((MainModule)(ref main)).gravityModifier, factor);
					ShapeModule shape = system.shape;
					((ShapeModule)(ref shape)).scale = ((ShapeModule)(ref shape)).scale * factor;
					((ShapeModule)(ref shape)).position = ((ShapeModule)(ref shape)).position * factor;
					VelocityOverLifetimeModule velocityOverLifetime = system.velocityOverLifetime;
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = Scale(((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x, factor);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = Scale(((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y, factor);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = Scale(((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z, factor);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).radial = Scale(((VelocityOverLifetimeModule)(ref velocityOverLifetime)).radial, factor);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalOffsetX = Scale(((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalOffsetX, factor);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalOffsetY = Scale(((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalOffsetY, factor);
					((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalOffsetZ = Scale(((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalOffsetZ, factor);
					ForceOverLifetimeModule forceOverLifetime = system.forceOverLifetime;
					((ForceOverLifetimeModule)(ref forceOverLifetime)).x = Scale(((ForceOverLifetimeModule)(ref forceOverLifetime)).x, factor);
					((ForceOverLifetimeModule)(ref forceOverLifetime)).y = Scale(((ForceOverLifetimeModule)(ref forceOverLifetime)).y, factor);
					((ForceOverLifetimeModule)(ref forceOverLifetime)).z = Scale(((ForceOverLifetimeModule)(ref forceOverLifetime)).z, factor);
					LimitVelocityOverLifetimeModule limitVelocityOverLifetime = system.limitVelocityOverLifetime;
					if (((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).separateAxes)
					{
						((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limitX = Scale(((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limitX, factor);
						((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limitY = Scale(((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limitY, factor);
						((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limitZ = Scale(((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limitZ, factor);
					}
					else
					{
						((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limit = Scale(((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limit, factor);
					}
					NoiseModule noise = system.noise;
					((NoiseModule)(ref noise)).strengthX = Scale(((NoiseModule)(ref noise)).strengthX, factor);
					if (((NoiseModule)(ref noise)).separateAxes)
					{
						((NoiseModule)(ref noise)).strengthY = Scale(((NoiseModule)(ref noise)).strengthY, factor);
						((NoiseModule)(ref noise)).strengthZ = Scale(((NoiseModule)(ref noise)).strengthZ, factor);
					}
					TrailModule trails = system.trails;
					if (!((TrailModule)(ref trails)).sizeAffectsWidth)
					{
						((TrailModule)(ref trails)).widthOverTrail = Scale(((TrailModule)(ref trails)).widthOverTrail, factor);
					}
				}
				Matrix4x4 val = Space(system);
				Matrix4x4 inverse = ((Matrix4x4)(ref val)).inverse;
				for (int i = 0; i < system2.Particles.Length; i++)
				{
					Particle val2 = system2.Particles[i];
					Vector3 val3 = ((Matrix4x4)(ref system2.Space)).MultiplyPoint3x4(((Particle)(ref val2)).position);
					((Particle)(ref val2)).position = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(center + (val3 - center) * factor);
					((Particle)(ref val2)).velocity = ((Matrix4x4)(ref inverse)).MultiplyVector(((Matrix4x4)(ref system2.Space)).MultiplyVector(((Particle)(ref val2)).velocity) * factor);
					if (flag)
					{
						if (((MainModule)(ref main)).startSize3D)
						{
							((Particle)(ref val2)).startSize3D = ((Particle)(ref val2)).startSize3D * factor;
						}
						else
						{
							((Particle)(ref val2)).startSize = ((Particle)(ref val2)).startSize * factor;
						}
					}
					system2.Particles[i] = val2;
				}
				system.SetParticles(system2.Particles, system2.Particles.Length);
			}
		}

		private static MinMaxCurve Scale(MinMaxCurve curve, float factor)
		{
			//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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystemCurveMode mode = ((MinMaxCurve)(ref curve)).mode;
			if ((int)mode != 0)
			{
				if ((int)mode == 3)
				{
					((MinMaxCurve)(ref curve)).constantMin = ((MinMaxCurve)(ref curve)).constantMin * factor;
					((MinMaxCurve)(ref curve)).constantMax = ((MinMaxCurve)(ref curve)).constantMax * factor;
				}
				else
				{
					((MinMaxCurve)(ref curve)).curveMultiplier = ((MinMaxCurve)(ref curve)).curveMultiplier * factor;
				}
			}
			else
			{
				((MinMaxCurve)(ref curve)).constant = ((MinMaxCurve)(ref curve)).constant * factor;
			}
			return curve;
		}
	}
	internal sealed class EffectRadiusVisuals : MonoBehaviour
	{
		public Explosion[] blasts;

		public float[] nativeRadii;

		public float[] targets;

		public float[] factors;

		public ExplosionRadiusCurve[] drivers;

		public AnimationCurve[] nativeCurves;

		public StormCloud[] clouds;

		public float[] cloudRadii;

		public float[] cloudFactors;

		public float[] cloudTargets;

		public float rendered = 1f;

		private static readonly FieldInfo CurveRadius = AccessTools.Field(typeof(ExplosionRadiusCurve), "originalRadius");

		private static readonly FieldInfo AnimationReady = AccessTools.Field(typeof(CodeAnimation), "inited");

		private static readonly FieldInfo AnimationScale = AccessTools.Field(typeof(CodeAnimation), "defaultScale");

		internal static void Configure(GameObject root, WeaponSlotSettings settings, string prefix)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			EffectRadiusVisuals state = root.GetComponent<EffectRadiusVisuals>();
			Dictionary<string, float> values = (settings?.values ?? new List<WeaponSettingValue>()).ToDictionary((WeaponSettingValue value) => value.key, (WeaponSettingValue value) => value.number);
			if ((Object)(object)state == (Object)null)
			{
				Explosion[] source = (from component in root.GetComponentsInChildren<Explosion>(true)
					where Owned(root.transform, ((Component)component).transform)
					select component).ToArray();
				StormCloud[] source2 = (from component in root.GetComponentsInChildren<StormCloud>(true)
					where Owned(root.transform, ((Component)component).transform)
					select component).ToArray();
				if (!source.Any((Explosion component) => values.ContainsKey(Key(root, (Component)(object)component, prefix, "radius"))) && !source2.Any((StormCloud component) => values.ContainsKey(Key(root, (Component)(object)component, prefix, "cloudRadius"))))
				{
					return;
				}
				state = root.AddComponent<EffectRadiusVisuals>();
				state.blasts = source;
				state.nativeRadii = source.Select((Explosion component) => component.radius).ToArray();
				state.drivers = source.Select((Explosion component) => ((Component)component).GetComponent<ExplosionRadiusCurve>()).ToArray();
				state.nativeCurves = state.drivers.Select((ExplosionRadiusCurve driver) => (!((Object)(object)driver != (Object)null)) ? null : UnitWeaponCatalog.RescaleCurve(driver.radiusCurve, 1f, 1f)).ToArray();
				state.clouds = source2;
				state.cloudRadii = source2.Select((StormCloud component) => component.cloudRadius).ToArray();
			}
			state.factors = state.blasts.Select((Explosion component, int index) => Ratio(values, Key(root, (Component)(object)component, prefix, "radius"), state.nativeRadii[index])).ToArray();
			state.targets = state.blasts.Select((Explosion component, int index) => (!values.TryGetValue(Key(root, (Component)(object)component, prefix, "radius"), out var value) || !FormationMember.Finite(value) || !(value >= 0f)) ? state.nativeRadii[index] : value).ToArray();
			state.cloudFactors = state.clouds.Select((StormCloud component, int index) => Ratio(values, Key(root, (Component)(object)component, prefix, "cloudRadius"), state.cloudRadii[index])).ToArray();
			state.cloudTargets = state.clouds.Select((StormCloud component, int index) => (!values.TryGetValue(Key(root, (Component)(object)component, prefix, "cloudRadius"), out value) || !FormationMember.Finite(value) || !(value >= 0f)) ? state.cloudRadii[index] : value).ToArray();
			if (root.activeInHierarchy)
			{
				state.Apply();
			}
		}

		private static string Key(GameObject root, Component component, string prefix, string member)
		{
			return prefix + ":" + UnitWeaponCatalog.ComponentPath(root.transform, component) + "/" + member;
		}

		private static float Ratio(Dictionary<string, float> values, string key, float original)
		{
			if (!values.TryGetValue(key, out var value) || !FormationMember.Finite(value) || !(value >= 0f) || value == original)
			{
				return 1f;
			}
			return value / ((original > 0f) ? original : 1f);
		}

		internal static void Reset(GameObject root)
		{
			EffectRadiusVisuals effectRadiusVisuals = (((Object)(object)root != (Object)null) ? root.GetComponent<EffectRadiusVisuals>() : null);
			if (effectRadiusVisuals?.nativeRadii != null)
			{
				effectRadiusVisuals.factors = effectRadiusVisuals.nativeRadii.Select((float _) => 1f).ToArray();
				effectRadiusVisuals.targets = effectRadiusVisuals.nativeRadii.ToArray();
				effectRadiusVisuals.cloudFactors = effectRadiusVisuals.cloudRadii.Select((float _) => 1f).ToArray();
				effectRadiusVisuals.cloudTargets = effectRadiusVisuals.cloudRadii.ToArray();
				if (root.activeInHierarchy)
				{
					effectRadiusVisuals.Apply();
				}
			}
		}

		internal static bool Owned(Transform root, Transform node)
		{
			while ((Object)(object)node != (Object)null && (Object)(object)node != (Object)(object)root)
			{
				if ((Object)(object)((Component)node).GetComponent<AbilityTemplateMarker>() != (Object)null || (Object)(object)((Component)node).GetComponent<UnitBaseTemplateMarker>() != (Object)null || ((Object)node).name == "BetterTracingWeaponEffects" || (Object)(object)((Component)node).GetComponent<Unit>() != (Object)null)
				{
					return false;
				}
				node = node.parent;
			}
			return true;
		}

		private void OnEnable()
		{
			if (nativeRadii != null)
			{
				Apply();
			}
		}

		private void Apply()
		{
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < blasts.Length; i++)
			{
				if (!((Object)(object)blasts[i] == (Object)null))
				{
					float value = factors[i];
					blasts[i].radius = targets[i];
					ExplosionRadiusCurve val = drivers[i];
					if (!((Object)(object)val == (Object)null) && nativeCurves[i] != null)
					{
						val.radiusCurve = UnitWeaponCatalog.RescaleCurve(nativeCurves[i], 1f, value);
						CurveRadius.SetValue(val, blasts[i].radius);
					}
				}
			}
			for (int j = 0; j < clouds.Length; j++)
			{
				if ((Object)(object)clouds[j] != (Object)null)
				{
					clouds[j].cloudRadius = cloudTargets[j];
				}
			}
			float num = factors.FirstOrDefault((float factor) => factor != 1f);
			if (num == 0f && !factors.Contains(0f))
			{
				num = cloudFactors.FirstOrDefault((float factor) => factor != 1f);
			}
			if (num == 0f && !factors.Contains(0f) && !cloudFactors.Contains(0f))
			{
				num = 1f;
			}
			if ((Object)(object)((Component)this).GetComponent<Unit>() != (Object)null || (Object)(object)((Component)this).GetComponent<Weapon>() != (Object)null)
			{
				return;
			}
			num = Mathf.Max(0.0001f, num);
			if (num != rendered)
			{
				float num2 = num / rendered;
				List<EffectRadiusParticles.State> systems = EffectRadiusParticles.Capture(((Component)this).gameObject);
				List<EffectRadiusLines.State> lines = EffectRadiusLines.Capture(((Component)this).gameObject);
				Transform transform = ((Component)this).transform;
				transform.localScale *= num2;
				CodeAnimation component = ((Component)this).GetComponent<CodeAnimation>();
				if ((Object)(object)component != (Object)null && (bool)AnimationReady.GetValue(component))
				{
					AnimationScale.SetValue(component, (Vector3)AnimationScale.GetValue(component) * num2);
				}
				EffectRadiusParticles.Resize(systems, ((Component)this).transform.position, num2);
				EffectRadiusLines.Resize(lines, ((Component)this).transform.position, num2);
				rendered = num;
			}
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct MeleeDistanceMovement : IMovementComponent, IComponentData
	{
	}
	internal static class ExtraStatsCompatibility
	{
		internal static string MovementTypeName(string savedTypeName)
		{
			if (string.IsNullOrWhit