Decompiled source of Better Tracing v1.1.6

BetterTracing.dll

Decompiled a week 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.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 System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using DM;
using GamepadUI.StateManager.Core;
using HarmonyLib;
using InControl;
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 Landfall.TABS_Input;
using Microsoft.CodeAnalysis;
using Pathfinding;
using TFBGames;
using TMPro;
using UIStateManager;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BetterTracing")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.6.0")]
[assembly: AssemblyInformationalVersion("1.1.6")]
[assembly: AssemblyProduct("BetterTracing")]
[assembly: AssemblyTitle("BetterTracing")]
[assembly: AssemblyVersion("1.1.6.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 AbilityPartSlots
	{
		internal const string SlotName = "BetterTracingPartSlot";

		internal static void Hold(Transform part)
		{
			//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_0036: 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)
			Transform val = (((Object)(object)part != (Object)null) ? part.parent : null);
			if (!((Object)(object)val == (Object)null) && InsideAbility(val))
			{
				GameObject val2 = new GameObject("BetterTracingPartSlot")
				{
					hideFlags = (HideFlags)1
				};
				val2.SetActive(false);
				val2.transform.SetParent(val, false);
				val2.transform.SetSiblingIndex(part.GetSiblingIndex());
			}
		}

		private static bool InsideAbility(Transform node)
		{
			while ((Object)(object)node != (Object)null)
			{
				if ((Object)(object)((Component)node).GetComponent<SpecialAbility>() != (Object)null)
				{
					return true;
				}
				node = node.parent;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(SetParent), "Doit")]
	internal static class AbilityPartSetParentPatch
	{
		private static void Prefix(SetParent __instance)
		{
			if ((Object)(object)__instance.targetParent != (Object)(object)((Component)__instance).transform.parent)
			{
				AbilityPartSlots.Hold(((Component)__instance).transform);
			}
		}
	}
	[HarmonyPatch(typeof(GoToBodyPart), "GoToPart")]
	internal static class AbilityPartBodyPatch
	{
		private static void Prefix(GoToBodyPart __instance, bool ___done)
		{
			if (!___done)
			{
				AbilityPartSlots.Hold(((Component)__instance).transform);
			}
		}
	}
	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
	{
		private static void Prefix(SerializedUnitBlueprint data, LandfallContentDatabase landfallContentDatabase)
		{
			AssassinPoofCompatibility.MigrateLegacyAbility(data, landfallContentDatabase);
		}
	}
	[HarmonyPatch(typeof(UnitBlueprint), "SerializedUnit", new Type[] { typeof(DatabaseID) })]
	internal static class AssassinPoofVanillaSavePatch
	{
		private static void Postfix(SerializedUnitBlueprint __result)
		{
			AssassinPoofCompatibility.MigrateLegacyAbility(__result);
		}
	}
	[HarmonyPatch(typeof(AssassinPoofEffect), "Start")]
	internal static class NativeAssassinPoofStartOverridePatch
	{
		private static bool Prefix(AssassinPoofEffect __instance)
		{
			return !AssassinPoofCompatibility.TryAttachToSpawnedUnit(__instance);
		}
	}
	[HarmonyPatch(typeof(AssassinPoofEffect), "Update")]
	internal static class NativeAssassinPoofUpdateOverridePatch
	{
		private static bool Prefix(AssassinPoofEffect __instance)
		{
			return !AssassinPoofCompatibility.TryAttachToSpawnedUnit(__instance);
		}
	}
	[HarmonyPatch(typeof(AssassinPoofEffect), "DoThePoof")]
	internal static class NativeAssassinPoofManualOverridePatch
	{
		private static bool Prefix(AssassinPoofEffect __instance)
		{
			return !AssassinPoofCompatibility.TryAttachToSpawnedUnit(__instance);
		}
	}
	[HarmonyPatch(typeof(UISubMenu), "Open")]
	internal static class BaseSettingsMenuOpen
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		internal static void Invoke(UISubMenu instance)
		{
			throw new InvalidOperationException("Native base settings menu open is not initialized.");
		}
	}
	[HarmonyPatch(typeof(UISubMenu), "Close")]
	internal static class BaseSettingsMenuClose
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		internal static void Invoke(UISubMenu instance)
		{
			throw new InvalidOperationException("Native base settings menu close is not initialized.");
		}
	}
	[BepInPlugin("fero.tabs.better_tracing", "Better Tracing", "1.1.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class BetterTracingPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "fero.tabs.better_tracing";

		private const string SettingKey = "Better Tracing";

		private ConfigEntry<bool> _enabled;

		private Harmony _harmony;

		private SettingsInstance _setting;

		internal static BetterTracingPlugin Instance { get; private set; }

		internal static bool IsEnabled()
		{
			if ((Object)(object)Instance != (Object)null)
			{
				return Instance._enabled?.Value ?? false;
			}
			return false;
		}

		internal static void LogPluginInfo(string message)
		{
			BetterTracingPlugin instance = Instance;
			if (instance != null)
			{
				((BaseUnityPlugin)instance).Logger.LogInfo((object)message);
			}
		}

		internal static void LogPluginWarning(string message)
		{
			BetterTracingPlugin instance = Instance;
			if (instance != null)
			{
				((BaseUnityPlugin)instance).Logger.LogWarning((object)message);
			}
		}

		private void Awake()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			Instance = this;
			_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "BetterTracing", true, "Help units navigate obstacles and protect fast-moving ragdolls from tunnelling through terrain.");
			_harmony = new Harmony("fero.tabs.better_tracing");
			int num = 0;
			Type[] types = typeof(BetterTracingPlugin).Assembly.GetTypes();
			foreach (Type type in types)
			{
				if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Any())
				{
					try
					{
						_harmony.CreateClassProcessor(type).Patch();
						num++;
					}
					catch (Exception ex)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not patch " + type.Name + ": " + ex.Message));
					}
				}
			}
			((MonoBehaviour)this).StartCoroutine(InjectSettingWhenReady());
			((MonoBehaviour)this).StartCoroutine(InstallRuntimeWhenReady());
			SpawnerAbilityRegistry.EnsureRegistered();
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Better Tracing loaded ({num} patch classes). Personal Assassin Poof: {AssassinPoofCompatibility.PersonalOverrideEnabled}.");
		}

		private IEnumerator InstallRuntimeWhenReady()
		{
			yield return null;
			try
			{
				TechnicalAbilityRuntime.Install(_harmony);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not enable optional Technical Items settings: " + ex.Message));
			}
			try
			{
				RunicSpellsSpawns.Install(_harmony);
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not enable Runic Spells spawn hooks: " + ex2.Message));
			}
			try
			{
				FleeDistanceRuntime.Install(_harmony);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Per-unit Flee Distance stats enabled.");
			}
			catch (Exception ex3)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not enable Flee Distance stats: " + ex3.Message));
			}
			try
			{
				UnitBehaviourRuntime.Install(_harmony);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Per-unit movement and targeting stats enabled.");
			}
			catch (Exception ex4)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not enable movement/targeting stats: " + ex4.Message));
			}
			try
			{
				foreach (UnitBlueprint userUnitBlueprint in ContentDatabase.Instance().GetUserUnitBlueprints())
				{
					SavedUnitSelection.RestoreWeaponFile(userUnitBlueprint);
				}
			}
			catch (Exception ex5)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not recover early-loaded weapon settings: " + ex5.Message));
			}
		}

		private IEnumerator InjectSettingWhenReady()
		{
			for (int i = 0; i < 1200; i++)
			{
				GlobalSettingsHandler service = ServiceLocator.GetService<GlobalSettingsHandler>();
				if ((Object)(object)service != (Object)null)
				{
					InjectSetting(service);
					break;
				}
				yield return null;
			}
		}

		internal static void InjectSetting(GlobalSettingsHandler handler)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Instance == (Object)null) && !((Object)(object)handler == (Object)null))
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(GlobalSettingsHandler), "m_gameplaySettings");
				List<SettingsInstance> list = (((SettingsInstance[])fieldInfo.GetValue(handler)) ?? Array.Empty<SettingsInstance>()).ToList();
				Instance._setting = ((IEnumerable<SettingsInstance>)list).FirstOrDefault((Func<SettingsInstance, bool>)((SettingsInstance s) => s?.m_settingsKey == "Better Tracing"));
				if (Instance._setting == null)
				{
					BetterTracingPlugin instance = Instance;
					SettingsInstance val = new SettingsInstance();
					val.settingsType = (SettingsType)0;
					val.options = new string[2] { "On", "Off" };
					val.defaultValue = 0;
					val.m_settingsKey = "Better Tracing";
					val.settingName = "Better Tracing";
					val.toolTip = "Helps units move around obstacles and prevents fast units from passing through terrain";
					instance._setting = val;
					list.Add(Instance._setting);
					fieldInfo.SetValue(handler, list.ToArray());
				}
				Instance._setting.currentValue = ((!IsEnabled()) ? 1 : 0);
				Instance._setting.OnValueChanged -= Instance.SetEnabled;
				Instance._setting.OnValueChanged += Instance.SetEnabled;
				if (AccessTools.Field(typeof(GlobalSettingsHandler), "m_settingsDict")?.GetValue(handler) is Dictionary<string, SettingsInstance> dictionary)
				{
					dictionary["Better Tracing"] = Instance._setting;
				}
			}
		}

		private void SetEnabled(int value)
		{
			_enabled.Value = value == 0;
			((BaseUnityPlugin)this).Config.Save();
		}

		internal static void OnSettingChanged(SettingsInstance setting)
		{
			if (setting?.m_settingsKey == "Better Tracing")
			{
				Instance?.SetEnabled(setting.currentValue);
			}
		}

		private void OnDestroy()
		{
			SpawnerAbilityEditor.CancelIfOpen();
			if (_setting != null)
			{
				_setting.OnValueChanged -= SetEnabled;
			}
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			TracingGeometry.ReleaseQueryCollider();
			FormationUI.ReleaseAssets();
			Instance = null;
		}
	}
	[HarmonyPatch(typeof(GlobalSettingsHandler), "Init", new Type[] { typeof(bool) })]
	internal static class BetterTracingSettingsInitPatch
	{
		private static void Postfix(GlobalSettingsHandler __instance)
		{
			BetterTracingPlugin.InjectSetting(__instance);
		}
	}
	[HarmonyPatch(typeof(MenuSettingsButton), "UpdateValue", new Type[] { typeof(int) })]
	internal static class BetterTracingSettingsValuePatch
	{
		private static void Postfix(MenuSettingsButton __instance)
		{
			BetterTracingPlugin.OnSettingChanged((__instance != null) ? __instance.settingsInstance : null);
		}
	}
	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
	{
		private static void Postfix(UnitAPI __instance)
		{
			CarBodySupport.Ensure(((Component)__instance).GetComponent<Unit>());
		}
	}
	[HarmonyPatch(typeof(CanSeeSystem), "OnUpdate")]
	internal static class CarTargetSurfacePatch
	{
		private static void Prefix(JobHandle inputDeps)
		{
			if (CarBodySupport.HasCars)
			{
				((JobHandle)(ref inputDeps)).Complete();
				CarBodySupport.RefreshTargets();
			}
		}
	}
	[HarmonyPatch(typeof(MeleeWeapon), "Attack")]
	internal static class CarMeleeSurfaceAimPatch
	{
		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
	{
		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
	{
		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;
			}
		}

		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;
		}

		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;
			}
		}

		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 CreatorClothingRig
	{
		internal static RigType Resolve(UnitRig target, RigType requested, TransformCatalog catalog, bool isUnitEditor)
		{
			//IL_0013: 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_0011: Invalid comparison between Unknown and I4
			//IL_0041: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!isUnitEditor || catalog != null || (Object)(object)target == (Object)null || (int)requested != 1)
			{
				return requested;
			}
			Unit val = ((Component)target).GetComponent<Unit>() ?? ((Component)target).GetComponentInParent<Unit>();
			if ((Object)(object)val == (Object)null || TransformCatalog.GetBoneNames(val.RigType).Count == 0)
			{
				return requested;
			}
			return val.RigType;
		}
	}
	[HarmonyPatch(typeof(UnitRig), "SpawnProp")]
	internal static class CreatorClothingRigPatch
	{
		private static void Prefix(UnitRig __instance, ref RigType rigType, TransformCatalog catalog, bool isUnitEditor)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected I4, but got Unknown
			rigType = (RigType)(int)CreatorClothingRig.Resolve(__instance, rigType, catalog, isUnitEditor);
		}
	}
	internal sealed class EditorTestCycle
	{
		private int _start = -10;

		private int _stop = -10;

		internal bool Start(bool testing, int frame)
		{
			if (testing || frame == _start || frame <= _stop + 1)
			{
				return false;
			}
			_start = frame;
			return true;
		}

		internal bool Stop(bool testing, int frame)
		{
			if (!testing || frame == _stop)
			{
				return false;
			}
			_stop = frame;
			return true;
		}
	}
	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);
						((LimitVelocityOverLifetimeMod