Decompiled source of MarvelPrototype v3.5.0

BepInEx/plugins/MarvelPrototype/MarvelPrototype.Core.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using DM;
using Landfall.TABS;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Marvel Prototype Core")]
[assembly: AssemblyDescription("Lightweight replacement for the ModdingForDummies subset used by Marvel Prototype.")]
[assembly: AssemblyFileVersion("3.5.0.0")]
[assembly: AssemblyVersion("3.5.0.0")]
namespace ModdingForDummies.TABSSimp
{
	internal static class Db
	{
		private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly string[] Filter = new string[33]
		{
			"Icon_Legacy_", "Icons_128x128_", "Icons_", "Icon_", "CP_", "P_", "E_", " Prefabs_VB", " Effects_VB", "_1",
			"_2", "_3", " (1)", " (2)", " (3)", " (4)", " (5)", " (6)", "B_", "Move_",
			"Leg_", "1_", "12_", "15_", "6__", "7_", "14_", "2_", "8_", "10_",
			"16_", "5_", "3_"
		};

		private static Dictionary<string, string> language;

		private static bool languageTried;

		internal static ContentDatabase Full => ContentDatabase.Instance();

		internal static LandfallContentDatabase Land => Full.LandfallContentDatabase;

		internal static string ProperName(string key)
		{
			if (string.IsNullOrEmpty(key))
			{
				return key ?? "";
			}
			if (!languageTried)
			{
				languageTried = true;
				try
				{
					language = Localizer.GetLanguage((Language)0);
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("[Marvel Core] English names unavailable: " + ex.Message));
				}
			}
			if (language != null && language.TryGetValue(key, out var value) && !string.IsNullOrEmpty(value))
			{
				return value;
			}
			value = key;
			for (int i = 0; i < Filter.Length; i++)
			{
				value = value.Replace(Filter[i], "");
			}
			return value;
		}

		private static T Find<T>(IEnumerable<T> all, string name, Func<T, string> key, Func<T, string> objectName) where T : class
		{
			if (all == null || string.IsNullOrEmpty(name))
			{
				return null;
			}
			List<T> source = all.Where((T x) => x != null).ToList();
			return source.FirstOrDefault((T x) => ProperName(key(x)) == name) ?? source.FirstOrDefault((T x) => string.Equals(ProperName(key(x)), name, StringComparison.OrdinalIgnoreCase)) ?? source.FirstOrDefault((T x) => string.Equals(ProperName(objectName(x)), name, StringComparison.OrdinalIgnoreCase));
		}

		internal static UnitBlueprint VanillaUnit(string name)
		{
			return Find(Full.GetAllUnitBlueprints(), name, (UnitBlueprint b) => b.Entity.Name, (UnitBlueprint b) => ((Object)b).name);
		}

		internal static Faction VanillaFaction(string name)
		{
			return Find(Full.GetAllFactions(), name, (Faction f) => f.Entity.Name, (Faction f) => ((Object)f).name);
		}

		private static void AddAsset(DatabaseID id, Object asset)
		{
			//IL_003d: 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)
			FieldInfo field = typeof(AssetLoader).GetField("m_nonStreamableAssets", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			Dictionary<DatabaseID, Object> dictionary = ((field != null) ? (field.GetValue(Full.AssetLoader) as Dictionary<DatabaseID, Object>) : null);
			if (dictionary != null && !dictionary.ContainsKey(id))
			{
				dictionary.Add(id, asset);
			}
		}

		internal static void AddUnit(UnitBlueprint bp)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			FieldInfo field = typeof(LandfallContentDatabase).GetField("m_unitBlueprints", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			Dictionary<DatabaseID, UnitBlueprint> dictionary = ((field != null) ? (field.GetValue(Land) as Dictionary<DatabaseID, UnitBlueprint>) : null);
			if (dictionary == null)
			{
				throw new InvalidOperationException("TABS unit database field m_unitBlueprints not found.");
			}
			DatabaseID gUID = bp.Entity.GUID;
			if (!dictionary.ContainsKey(gUID))
			{
				dictionary.Add(gUID, bp);
			}
			AddAsset(gUID, (Object)(object)bp);
		}

		internal static void AddFaction(Faction f)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			FieldInfo field = typeof(LandfallContentDatabase).GetField("m_factions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			Dictionary<DatabaseID, Faction> dictionary = ((field != null) ? (field.GetValue(Land) as Dictionary<DatabaseID, Faction>) : null);
			if (dictionary == null)
			{
				throw new InvalidOperationException("TABS faction database field m_factions not found.");
			}
			DatabaseID gUID = f.Entity.GUID;
			if (!dictionary.ContainsKey(gUID))
			{
				dictionary.Add(gUID, f);
			}
			AddAsset(gUID, (Object)(object)f);
		}
	}
	public class Mod
	{
		private static readonly Dictionary<string, ModUnit> units = new Dictionary<string, ModUnit>();

		private static readonly Dictionary<string, ModFaction> factions = new Dictionary<string, ModFaction>();

		public static ModUnit GetUnit(string name)
		{
			if (name == null)
			{
				return null;
			}
			if (units.TryGetValue(name, out var value))
			{
				return value;
			}
			UnitBlueprint val = Db.VanillaUnit(name);
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)("[Marvel Core] Could not find unit '" + name + "'."));
				return null;
			}
			return units[name] = new ModUnit(val);
		}

		public static ModUnit CreateUnit(string name)
		{
			return CreateUnit(name, null);
		}

		public static ModUnit CreateUnit(string name, string originalName)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			UnitBlueprint val = Db.VanillaUnit(string.IsNullOrEmpty(originalName) ? "Peasant" : originalName);
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)("[Marvel Core] Could not find unit template '" + originalName + "'."));
				return null;
			}
			uint unitCost = val.GetUnitCost(true);
			UnitBlueprint obj = Object.Instantiate<UnitBlueprint>(val);
			((Object)obj).name = name;
			obj.Entity.GUID = DatabaseID.NewID();
			obj.Entity.Name = name;
			obj.m_props = (GameObject[])(object)new GameObject[0];
			obj.useCustomCost = true;
			obj.customCost = (int)unitCost;
			Db.AddUnit(obj);
			ModUnit modUnit = new ModUnit(obj);
			units[name] = modUnit;
			return modUnit;
		}

		public static ModFaction GetFaction(string name)
		{
			if (name == null)
			{
				return null;
			}
			if (factions.TryGetValue(name, out var value))
			{
				return value;
			}
			Faction val = Db.VanillaFaction(name);
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)("[Marvel Core] Could not find faction '" + name + "'."));
				return null;
			}
			return factions[name] = new ModFaction(val);
		}

		public static ModFaction CreateFaction(string name)
		{
			return CreateFaction(name, null);
		}

		public static ModFaction CreateFaction(string name, string originalName)
		{
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			Faction val = ((!string.IsNullOrEmpty(originalName)) ? Db.VanillaFaction(originalName) : null);
			if ((Object)(object)val == (Object)null)
			{
				val = Db.VanillaFaction("Medieval");
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Db.Full.GetAllFactions().FirstOrDefault((Func<Faction, bool>)((Faction x) => (Object)(object)x != (Object)null));
			}
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)("[Marvel Core] No vanilla faction to copy for '" + name + "'."));
				return null;
			}
			Faction val2 = Object.Instantiate<Faction>(val);
			((Object)val2).name = name;
			val2.Entity.GenerateNewID();
			val2.Entity.Name = name;
			val2.Units = (UnitBlueprint[])(object)new UnitBlueprint[0];
			val2.index = Db.Land.GetFactions().Count();
			if (string.IsNullOrEmpty(originalName))
			{
				val2.m_FactionColor = new Color(8f / 15f, 8f / 15f, 8f / 15f, 1f);
			}
			val2.m_displayFaction = false;
			Db.AddFaction(val2);
			ModFaction modFaction = new ModFaction(val2);
			factions[name] = modFaction;
			return modFaction;
		}
	}
	public class WrapperDelineation<T> : IEnumerable<T>, IEnumerable
	{
		private readonly Action<List<T>> update;

		private List<T> list;

		public List<T> List
		{
			get
			{
				return list;
			}
			set
			{
				list = value ?? new List<T>();
				Push();
			}
		}

		public int Count => list.Count;

		public WrapperDelineation(List<T> initial, Action<List<T>> onUpdate)
		{
			list = initial ?? new List<T>();
			update = onUpdate;
		}

		public void Add(T item)
		{
			list.Add(item);
			Push();
		}

		public void Add(IEnumerable<T> items)
		{
			list.AddRange(items);
			Push();
		}

		public bool Remove(T item)
		{
			bool result = list.Remove(item);
			Push();
			return result;
		}

		public void Clear()
		{
			list.Clear();
			Push();
		}

		private void Push()
		{
			if (update != null)
			{
				update(list);
			}
		}

		public IEnumerator<T> GetEnumerator()
		{
			return list.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return list.GetEnumerator();
		}
	}
	public class ModFaction
	{
		private Sprite icon;

		public Faction internalObject { get; set; }

		public WrapperDelineation<ModUnit> Units { get; set; }

		public UnitBlueprint[] Blueprints => (from u in Units.List
			where u != null
			select u.internalObject).ToArray();

		public string Name
		{
			get
			{
				return internalObject.Entity.Name;
			}
			set
			{
				internalObject.Entity.Name = value;
			}
		}

		public bool Visible
		{
			get
			{
				return internalObject.m_displayFaction;
			}
			set
			{
				internalObject.m_displayFaction = value;
			}
		}

		public Sprite Icon
		{
			get
			{
				return icon;
			}
			set
			{
				icon = value;
				internalObject.Entity.SetSpriteIcon(value);
			}
		}

		public ModFaction(Faction faction)
		{
			internalObject = faction;
			Units = new WrapperDelineation<ModUnit>((from b in (IEnumerable<UnitBlueprint>)(((Object)(object)faction != (Object)null && faction.Units != null) ? ((Array)faction.Units) : ((Array)new UnitBlueprint[0]))
				where (Object)(object)b != (Object)null
				select new ModUnit(b)).ToList(), UpdateBlueprints);
		}

		private void UpdateBlueprints(List<ModUnit> list)
		{
			if (Object.op_Implicit((Object)(object)internalObject))
			{
				internalObject.Units = (from u in list
					where u != null && Object.op_Implicit((Object)(object)u.internalObject)
					select u.internalObject).ToArray();
			}
		}

		public ModUnit NewUnit(string name)
		{
			return NewUnit(name, null);
		}

		public ModUnit NewUnit(string name, string originalName)
		{
			ModUnit modUnit = Mod.CreateUnit(name, originalName);
			if (modUnit != null)
			{
				Units.Add(modUnit);
			}
			return modUnit;
		}
	}
	public class ModUnit
	{
		public UnitBlueprint internalObject;

		private Sprite icon;

		public string Name
		{
			get
			{
				return internalObject.Entity.Name;
			}
			set
			{
				internalObject.Entity.Name = value;
			}
		}

		public Sprite Icon
		{
			get
			{
				return icon;
			}
			set
			{
				icon = value;
				internalObject.Entity.SetSpriteIcon(value);
			}
		}

		public float Health
		{
			get
			{
				return internalObject.health;
			}
			set
			{
				internalObject.health = value;
			}
		}

		public float Speed
		{
			get
			{
				return internalObject.movementSpeedMuiltiplier;
			}
			set
			{
				internalObject.movementSpeedMuiltiplier = value;
			}
		}

		public float Mass
		{
			get
			{
				return internalObject.massMultiplier;
			}
			set
			{
				internalObject.massMultiplier = value;
			}
		}

		public float Balance
		{
			get
			{
				return internalObject.balanceMultiplier;
			}
			set
			{
				internalObject.balanceMultiplier = value;
			}
		}

		public float Size
		{
			get
			{
				return internalObject.sizeMultiplier;
			}
			set
			{
				internalObject.sizeMultiplier = value;
			}
		}

		public int Cost
		{
			get
			{
				return (int)internalObject.GetUnitCost(true);
			}
			set
			{
				internalObject.useCustomCost = true;
				internalObject.customCost = value;
			}
		}

		public ModUnit(UnitBlueprint blueprint)
		{
			internalObject = blueprint;
		}
	}
}
namespace MarvelPrototype.Core
{
	[BepInPlugin("myname.myfirstmod", "Marvel Prototype Core (ModdingForDummies replacement)", "0.9.0")]
	public class CorePlugin : BaseUnityPlugin
	{
		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Marvel Prototype Core 3.5.0 loaded (ModdingForDummies is no longer required; nothing is scanned at startup).");
		}
	}
}

BepInEx/plugins/MarvelPrototype/MarvelPrototype.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

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

internal sealed class AgileMotor
{
	private readonly UnitRef self;

	internal readonly IronManMotor Native;

	private bool begun;

	private readonly Quaternion hipOffset;

	private readonly Quaternion torsoOffset;

	private readonly Quaternion headOffset;

	internal float MaxSpeed = 10f;

	internal float MaxUp = 7f;

	internal float Reach = 0.75f;

	internal float Leg = 1.04f;

	internal Rigidbody Left => Native.Left;

	internal Rigidbody Right => Native.Right;

	internal Rigidbody FootL => Native.FootL;

	internal Rigidbody FootR => Native.FootR;

	internal Rigidbody Torso => Native.Torso;

	internal Rigidbody Head => Native.Head;

	internal bool Grounded => Native.Grounded;

	internal AgileMotor(UnitRef u)
	{
		//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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: 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_00d1: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		self = u;
		Native = new IronManMotor(u, physicalSkin: true);
		Vector3 forward = u.Forward;
		Quaternion val = Quaternion.LookRotation((((Vector3)(ref forward)).sqrMagnitude > 0.01f) ? u.Forward : Vector3.forward);
		hipOffset = Quaternion.Inverse(val) * u.Main.rotation;
		torsoOffset = (Object.op_Implicit((Object)(object)Torso) ? (Quaternion.Inverse(val) * Torso.rotation) : hipOffset);
		headOffset = (Object.op_Implicit((Object)(object)Head) ? (Quaternion.Inverse(val) * Head.rotation) : hipOffset);
	}

	internal Vector3 Point(Rigidbody body)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return Native.Point(body);
	}

	internal Vector3 Hand(bool left)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return Native.Hand(left);
	}

	internal void Begin()
	{
		if (!begun)
		{
			begun = true;
			Native.Begin();
		}
	}

	internal void Hold(Vector3 facing, float crouch = 1f, bool support = true, float lean = 0f)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		Native.EnsureAuthority();
		Native.Stabilize(facing, crouch, lean, support, 0.75f);
	}

	internal void Gait(Vector3 direction, float speed, float crouch = 1f, bool air = false)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Native.Gait(direction, speed, crouch, air);
	}

	internal void Drive(Vector3 direction, float speed, UnitRef target = null)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Native.Drive(direction, Mathf.Min(MaxSpeed, speed), target);
	}

	internal void Pose(Rigidbody limb, Vector3 goal, float force = 140f)
	{
		//IL_003c: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: 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_0155: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)limb) && !((Object)(object)limb == (Object)(object)self.Main))
		{
			Vector3 val = (Object.op_Implicit((Object)(object)Torso) ? Torso.position : self.Position);
			if ((Object)(object)limb == (Object)(object)Left || (Object)(object)limb == (Object)(object)Right)
			{
				Vector3 val2 = val + Vector3.Cross(Vector3.up, self.Forward) * (((Object)(object)limb == (Object)(object)Left) ? (-0.25f) : 0.25f) * self.Scale + Vector3.up * 0.12f * self.Scale;
				goal = val2 + Vector3.ClampMagnitude(goal - val2, Reach * self.Scale);
			}
			else if ((Object)(object)limb == (Object)(object)FootL || (Object)(object)limb == (Object)(object)FootR)
			{
				goal = self.Position + Vector3.ClampMagnitude(goal - self.Position, Leg * self.Scale);
			}
			Native.Pose(limb, goal, Mathf.Min(200f, force));
		}
	}

	internal void Turn(Vector3 direction)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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)
		Transform val = R.Get<Transform>(self.Data, "characterForwardObject");
		if (Object.op_Implicit((Object)(object)val) && ((Vector3)(ref direction)).sqrMagnitude > 0.01f)
		{
			Vector3 val2 = UnitRef.Flat(direction);
			val.rotation = Quaternion.LookRotation(((Vector3)(ref val2)).normalized, Vector3.up);
		}
	}

	internal bool Jump(Vector3 velocity)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		if (!Native.FindFloor())
		{
			return false;
		}
		self.AddVelocity(Vector3.ClampMagnitude(velocity, Mathf.Max(MaxSpeed, MaxUp) * 1.3f), 16f);
		return true;
	}

	internal void Accelerate(Vector3 a)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Native.Accelerate(a);
	}

	internal void Roll(Vector3 facing, float phase, float axisSign)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		Native.EnsureAuthority();
		Quaternion val = Quaternion.LookRotation(facing, Vector3.up) * Quaternion.Euler(0f, 0f, axisSign * phase * 360f);
		Rotate(self.Main, val * hipOffset);
		Rotate(Torso, val * torsoOffset);
		Rotate(Head, val * headOffset);
	}

	private static void Rotate(Rigidbody body, Quaternion goal)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: 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_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)body) && !body.isKinematic)
		{
			Quaternion val = goal * Quaternion.Inverse(body.rotation);
			float num = default(float);
			Vector3 val2 = default(Vector3);
			((Quaternion)(ref val)).ToAngleAxis(ref num, ref val2);
			if (num > 180f)
			{
				num -= 360f;
			}
			if (HulkRules.Finite(num) && HulkCombat.Finite(val2))
			{
				body.AddTorque(Vector3.ClampMagnitude(val2 * num * ((float)Math.PI / 180f) * 135f - body.angularVelocity * 8f, 190f), (ForceMode)5);
			}
		}
	}

	internal void Limit()
	{
		HulkCombat.Cap(self, MaxSpeed * 1.6f);
		self.CapOwnMotion(MaxSpeed * 1.6f, MaxUp * 1.5f);
	}

	internal void Dispose(bool restore)
	{
		Native.Dispose(restore);
		begun = false;
	}
}
public static class ArgumentBridge
{
	private sealed class Entry
	{
		public MethodInfo Target;

		public Action<object, MethodBase, object[]> Handler;
	}

	private static readonly List<Entry> Entries = new List<Entry>();

	private static ModuleBuilder module;

	public static MethodInfo Create(MethodInfo target, Action<object, MethodBase, object[]> handler)
	{
		if (module == null)
		{
			module = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("MarvelPrototype.StatusBridges"), AssemblyBuilderAccess.Run).DefineDynamicModule("StatusBridges");
		}
		int count = Entries.Count;
		Entries.Add(new Entry
		{
			Target = target,
			Handler = handler
		});
		ParameterInfo[] parameters = target.GetParameters();
		Type[] array = new Type[parameters.Length + 1];
		array[0] = typeof(object);
		for (int i = 0; i < parameters.Length; i++)
		{
			array[i + 1] = (parameters[i].ParameterType.IsByRef ? parameters[i].ParameterType : parameters[i].ParameterType.MakeByRefType());
		}
		TypeBuilder typeBuilder = module.DefineType("Prefix" + count, TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Sealed);
		MethodBuilder methodBuilder = typeBuilder.DefineMethod("Before", MethodAttributes.Public | MethodAttributes.Static, typeof(void), array);
		methodBuilder.DefineParameter(1, ParameterAttributes.None, "__instance");
		for (int j = 0; j < parameters.Length; j++)
		{
			methodBuilder.DefineParameter(j + 2, ParameterAttributes.None, parameters[j].Name);
		}
		ILGenerator iLGenerator = methodBuilder.GetILGenerator();
		LocalBuilder local = iLGenerator.DeclareLocal(typeof(object[]));
		iLGenerator.Emit(OpCodes.Ldc_I4, parameters.Length);
		iLGenerator.Emit(OpCodes.Newarr, typeof(object));
		iLGenerator.Emit(OpCodes.Stloc, local);
		for (int k = 0; k < parameters.Length; k++)
		{
			Type elementType = array[k + 1].GetElementType();
			iLGenerator.Emit(OpCodes.Ldloc, local);
			iLGenerator.Emit(OpCodes.Ldc_I4, k);
			iLGenerator.Emit(OpCodes.Ldarg, (short)(k + 1));
			iLGenerator.Emit(OpCodes.Ldobj, elementType);
			if (elementType.IsValueType)
			{
				iLGenerator.Emit(OpCodes.Box, elementType);
			}
			iLGenerator.Emit(OpCodes.Stelem_Ref);
		}
		iLGenerator.Emit(OpCodes.Ldc_I4, count);
		iLGenerator.Emit(OpCodes.Ldarg_0);
		iLGenerator.Emit(OpCodes.Ldloc, local);
		iLGenerator.Emit(OpCodes.Call, typeof(ArgumentBridge).GetMethod("Dispatch"));
		for (int l = 0; l < parameters.Length; l++)
		{
			Type elementType2 = array[l + 1].GetElementType();
			iLGenerator.Emit(OpCodes.Ldarg, (short)(l + 1));
			iLGenerator.Emit(OpCodes.Ldloc, local);
			iLGenerator.Emit(OpCodes.Ldc_I4, l);
			iLGenerator.Emit(OpCodes.Ldelem_Ref);
			iLGenerator.Emit(elementType2.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass, elementType2);
			iLGenerator.Emit(OpCodes.Stobj, elementType2);
		}
		iLGenerator.Emit(OpCodes.Ret);
		return typeBuilder.CreateType().GetMethod("Before");
	}

	public static void Dispatch(int id, object instance, object[] args)
	{
		Entry entry = Entries[id];
		entry.Handler(instance, entry.Target, args);
	}
}
[DefaultExecutionOrder(24)]
public sealed class BlackWidowCombatAI : MonoBehaviour
{
	internal UnitRef Self;

	internal UnitRef Target;

	internal BlackWidowVisual Visual;

	internal BlackWidowMotor Motor;

	internal WidowsBiteSystem Bite;

	internal readonly WidowCombatClock Clock = new WidowCombatClock();

	private BlackWidowMeleeSystem melee;

	private WidowTakedown takedown;

	private WidowGrapplingLine grapple;

	internal MarvelInteractionScene Interaction;

	internal float CalmReady;

	internal float TeamReady;

	private SpiderAbilityControl control;

	private WebStatus status;

	private bool locked;

	private bool overridden;

	private bool initialized;

	private bool cleaned;

	private float think;

	private float lastHP;

	private float staggerUntil;

	private float nextShot;

	private int shots;

	private int moves;

	private Vector3 facing;

	private Vector3 travel;

	private bool fired;

	internal Vector3 Facing
	{
		get
		{
			//IL_002d: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			if (!(((Vector3)(ref facing)).sqrMagnitude > 0.01f))
			{
				if (Self == null)
				{
					return Vector3.forward;
				}
				return Self.Forward;
			}
			return facing;
		}
	}

	internal bool Ready
	{
		get
		{
			if (initialized && !cleaned && Self != null && Self.Alive && Self.Active && Clock.Free && !Object.op_Implicit((Object)(object)Interaction) && !Disabled && Upright)
			{
				return !R.Get(Self.API, "IsRemotelyControlled", fallback: false);
			}
			return false;
		}
	}

	internal bool Upright
	{
		get
		{
			//IL_0045: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (Self != null && Motor != null && Object.op_Implicit((Object)(object)Self.Main) && Object.op_Implicit((Object)(object)Motor.Head) && Motor.Head.position.y > Self.Main.position.y + 0.25f * Self.Scale)
			{
				Vector3 velocity = Self.Main.velocity;
				return ((Vector3)(ref velocity)).magnitude < 11f;
			}
			return false;
		}
	}

	private bool Disabled
	{
		get
		{
			if ((!Object.op_Implicit((Object)(object)status) || (!status.Held && !status.Shock && !status.Blind)) && !(Time.time < staggerUntil))
			{
				if (Self != null && Object.op_Implicit((Object)(object)Self.Main))
				{
					return Self.Main.isKinematic;
				}
				return false;
			}
			return true;
		}
	}

	internal void Initialize(UnitRef u, BlackWidowVisual v, BlackWidowMotor m)
	{
		//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)
		Self = u;
		Visual = v;
		Motor = m;
		facing = u.Forward;
		control = SpiderAbilityControl.For(u);
		status = WebStatus.For(u);
		Bite = ((Component)this).gameObject.AddComponent<WidowsBiteSystem>();
		Bite.Widow = this;
		melee = new BlackWidowMeleeSystem(this);
		lastHP = R.Get(u.Data, "health", 720f);
		CalmReady = Time.time + 2f;
		TeamReady = Time.time + 3f;
		initialized = true;
	}

	private void Acquire()
	{
		if (!locked)
		{
			control.Acquire(actor: true);
			locked = true;
		}
		if (!overridden)
		{
			status.PhysicsOverrides++;
			overridden = true;
		}
		Motor.Begin();
	}

	private void Unlock()
	{
		if (locked && Object.op_Implicit((Object)(object)control))
		{
			control.Release(actor: true);
		}
		locked = false;
		if (overridden && Object.op_Implicit((Object)(object)status))
		{
			status.PhysicsOverrides = Math.Max(0, status.PhysicsOverrides - 1);
		}
		overridden = false;
	}

	private void Update()
	{
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: 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_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_037a: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0380: Unknown result type (might be due to invalid IL or missing references)
		//IL_0399: Unknown result type (might be due to invalid IL or missing references)
		//IL_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		if (!initialized || cleaned)
		{
			return;
		}
		try
		{
			if (Self == null || !Object.op_Implicit((Object)(object)Self.Unit) || !Self.Alive)
			{
				if (Object.op_Implicit((Object)(object)Interaction))
				{
					Interaction.Cancel();
				}
				FinishAction();
				Clock.Die();
				Unlock();
				Motor.Dispose(restore: false);
				return;
			}
			if (!World.InBattle || !Self.Active || R.Get(Self.API, "IsRemotelyControlled", fallback: false))
			{
				if (Object.op_Implicit((Object)(object)Interaction))
				{
					Interaction.Cancel();
				}
				FinishAction();
				Unlock();
				return;
			}
			Acquire();
			float num = R.Get(Self.Data, "health", lastHP);
			float num2 = Mathf.Max(0f, lastHP - num);
			lastHP = num;
			if (num2 >= 100f)
			{
				staggerUntil = Time.time + 0.32f;
				if (Object.op_Implicit((Object)(object)Interaction))
				{
					Interaction.Cancel();
				}
				FinishAction();
			}
			if (Disabled)
			{
				if (Object.op_Implicit((Object)(object)Interaction))
				{
					Interaction.Cancel();
				}
				FinishAction();
			}
			else
			{
				if (Object.op_Implicit((Object)(object)Interaction))
				{
					return;
				}
				if (Clock.Expired(Time.time))
				{
					FinishAction();
				}
				if (Time.time < think)
				{
					return;
				}
				think = Time.time + 0.065f;
				Target = Resolve();
				if (Target == null)
				{
					FinishAction();
					return;
				}
				Vector3 val = UnitRef.Flat(Target.Position - Self.Position);
				if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
				{
					facing = ((Vector3)(ref val)).normalized;
				}
				BlackWidowVisual visual = Visual;
				Vector3 val2 = Aim(Target) - Visual.Hand(left: false);
				visual.Aim = ((Vector3)(ref val2)).normalized;
				if (!Clock.Free)
				{
					return;
				}
				Vector3 incoming;
				bool heavy;
				bool flag = Threat(out incoming, out heavy);
				WidowSituation s = Situation(flag, heavy);
				if (flag && s.Distance < 3.2f && Clock.Available(WidowAttack.Counter, Time.time) && StartAttack(WidowAttack.Counter))
				{
					travel = Vector3.Cross(Vector3.up, incoming) * (float)((Self.Id % 2 == 0) ? 1 : (-1));
				}
				else if (flag && !Clock.AttackRequired && Time.time - Clock.LastAttack <= 1.6f && Clock.Evade(Time.time, heavy && s.Distance < 4f))
				{
					moves++;
					int num3 = moves % 4;
					Clock.End = Time.time + ((num3 == 0 || num3 == 3) ? 0.68f : 0.45f);
					Vector3 normalized;
					if (num3 != 3 || heavy || !(s.Distance < 3.5f))
					{
						val2 = Vector3.Cross(Vector3.up, incoming) * (float)((Self.Id % 2 == 0) ? 1 : (-1)) - incoming * 0.18f;
						normalized = ((Vector3)(ref val2)).normalized;
					}
					else
					{
						normalized = Facing;
					}
					travel = normalized;
					Motor.Jump(travel, (num3 == 3) ? 5.7f : (heavy ? 3.5f : 1.5f), num3 switch
					{
						2 => 0f, 
						3 => 4.2f, 
						0 => 1.9f, 
						_ => 1.3f, 
					});
				}
				else
				{
					WidowAttack? widowAttack = Clock.Select(s, Time.time);
					if (widowAttack.HasValue)
					{
						StartAttack(widowAttack.Value);
					}
				}
			}
		}
		catch (Exception ex)
		{
			Launcher.WarnOnce("widow_update_" + Self.Id, "Black Widow action canceled: " + ex);
			if (Object.op_Implicit((Object)(object)Interaction))
			{
				Interaction.Cancel();
			}
			FinishAction();
		}
	}

	private UnitRef Resolve()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		return World.Enemies(Self, Self.Position, 10000f).OrderBy(delegate(UnitRef u)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			float num = Vector3.Distance(u.Position, Self.Position);
			return (!(num < 4f)) ? (num + (float)((!World.ClearPath(Self, Self.Position, Aim(u), u, terrainOnly: true)) ? 10 : 0) - (float)((u.WeaponReach > 5f) ? 3 : 0) + (float)((u.Health > 3000f) ? 2 : 0)) : (num - 50f);
		}).FirstOrDefault();
	}

	internal static Vector3 Aim(UnitRef u)
	{
		//IL_001a: 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)
		if (!Object.op_Implicit((Object)(object)u.Torso))
		{
			return u.Position;
		}
		return u.Torso.position;
	}

	private WidowSituation Situation(bool threat, bool heavy)
	{
		//IL_0022: 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_0063: 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_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: 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)
		Motor.Native.FindFloor();
		UnitRef[] source = World.Enemies(Self, Self.Position, 25f).ToArray();
		WebStatus component = Target.Unit.GetComponent<WebStatus>();
		WidowSituation result = new WidowSituation
		{
			Distance = Vector3.Distance(Self.Position, Target.Position) / Self.Scale,
			MassRatio = HulkCombat.Mass(Target) / Mathf.Max(1f, HulkCombat.Mass(Self)),
			HeightRatio = Target.Scale / Self.Scale,
			EnemyHP = Target.Health
		};
		float enemySpeed;
		if (!Object.op_Implicit((Object)(object)Target.Main))
		{
			enemySpeed = 0f;
		}
		else
		{
			Vector3 val = UnitRef.Flat(Target.Main.velocity);
			enemySpeed = ((Vector3)(ref val)).magnitude;
		}
		result.EnemySpeed = enemySpeed;
		result.Crowd = source.Count((UnitRef u) => Vector3.Distance(u.Position, Self.Position) < 6f * Self.Scale);
		result.Ranged = source.Count((UnitRef u) => u.WeaponReach > 5f);
		result.Threat = threat;
		result.HeavyThreat = heavy;
		result.CanGrapple = WidowTakedown.Can(this, Target);
		result.Clear = World.ClearPath(Self, Visual.Hand(left: false), Aim(Target), Target, terrainOnly: true);
		result.Grounded = Motor.Grounded;
		result.Staggered = Object.op_Implicit((Object)(object)component) && (component.Shock || component.Snared);
		return result;
	}

	private bool Threat(out Vector3 incoming, out bool heavy)
	{
		//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_003e: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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_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_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: 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_010f: 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_01e4: 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)
		//IL_01fa: 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_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: Unknown result type (might be due to invalid IL or missing references)
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Unknown result type (might be due to invalid IL or missing references)
		//IL_037c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0381: Unknown result type (might be due to invalid IL or missing references)
		incoming = Facing;
		heavy = false;
		ProjectileTracker.Refresh();
		Vector3 val = (Object.op_Implicit((Object)(object)Motor.Torso) ? Motor.Torso.position : Self.Position);
		float num = 0.61f;
		bool flag = false;
		Vector3 val4;
		foreach (FlightRef flight in ProjectileTracker.Flights)
		{
			if (!Object.op_Implicit((Object)(object)flight.Transform) || (flight.Owner != null && flight.Owner.Team == Self.Team))
			{
				continue;
			}
			Vector3 val2 = flight.Velocity - (Object.op_Implicit((Object)(object)Self.Main) ? Self.Main.velocity : Vector3.zero);
			float magnitude = ((Vector3)(ref val2)).magnitude;
			if (!(magnitude < 3f))
			{
				Vector3 val3 = val - flight.Transform.position;
				float num2 = Vector3.Dot(val3, val2) / ((Vector3)(ref val2)).sqrMagnitude;
				val4 = val3 - val2 * num2;
				float magnitude2 = ((Vector3)(ref val4)).magnitude;
				if (num2 < num && WidowRules.ProjectileThreat(num2, magnitude2, magnitude, Self.Scale))
				{
					num = num2;
					val4 = flight.Transform.position - val;
					incoming = ((Vector3)(ref val4)).normalized;
					heavy = Object.op_Implicit((Object)(object)flight.Body) && flight.Body.mass > 3f;
					flag = true;
				}
			}
		}
		if (flag)
		{
			return true;
		}
		foreach (UnitRef item in World.Enemies(Self, Self.Position, 26f))
		{
			Vector3 val5 = UnitRef.Flat(Self.Position - item.Position);
			if (item.WeaponReach > 5f && ((Vector3)(ref val5)).magnitude > 4f && Vector3.Dot(item.Forward, ((Vector3)(ref val5)).normalized) > 0.94f && (Object)(object)R.Get<Rigidbody>(item.Data, "targetMainRig") == (Object)(object)Self.TargetBody)
			{
				incoming = -((Vector3)(ref val5)).normalized;
				return true;
			}
			if (((Vector3)(ref val5)).magnitude > 3.3f * Self.Scale)
			{
				continue;
			}
			float num3 = HulkCombat.Mass(item) / Mathf.Max(1f, HulkCombat.Mass(Self));
			if (Object.op_Implicit((Object)(object)item.Main) && Vector3.Dot(item.Main.velocity, ((Vector3)(ref val5)).normalized) > 3.5f)
			{
				incoming = -((Vector3)(ref val5)).normalized;
				heavy = num3 > 2.15f;
				return true;
			}
			Transform[] array = (Transform[])(object)new Transform[2] { item.LeftHand, item.RightHand };
			foreach (Transform val6 in array)
			{
				Rigidbody val7 = item.LimbBody(val6);
				if (Object.op_Implicit((Object)(object)val7))
				{
					Vector3 pointVelocity = val7.GetPointVelocity(val6.position);
					val4 = val - val6.position;
					if (Vector3.Dot(pointVelocity, ((Vector3)(ref val4)).normalized) > 2.8f)
					{
						val4 = val6.position - val;
						incoming = ((Vector3)(ref val4)).normalized;
						heavy = num3 > 2.15f;
						return true;
					}
				}
			}
		}
		return false;
	}

	private bool StartAttack(WidowAttack attack)
	{
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		if (!Clock.Enter(attack, Time.time))
		{
			return false;
		}
		fired = false;
		shots = 0;
		nextShot = Time.time + 0.18f;
		Visual.Switch(WidowRules.Weapon(attack));
		if (attack == WidowAttack.Takedown || attack == WidowAttack.BiteGrapple || attack == WidowAttack.ArmLock)
		{
			goto IL_009b;
		}
		if (attack == WidowAttack.Counter && WidowTakedown.Can(this, Target) && Object.op_Implicit((Object)(object)Target.Main))
		{
			Vector3 velocity = Target.Main.velocity;
			if (((Vector3)(ref velocity)).magnitude > 3.5f)
			{
				goto IL_009b;
			}
		}
		switch (attack)
		{
		case WidowAttack.Grapple:
			grapple = ((Component)this).gameObject.AddComponent<WidowGrapplingLine>();
			if (!grapple.Begin(this, WidowTakedown.Can(this, Target) ? Target : null))
			{
				grapple.Stop();
				grapple = null;
				Clock.Finish();
				return false;
			}
			Clock.RetreatReady = Time.time + 7f;
			break;
		case WidowAttack.Smoke:
			travel = SafeSide(away: true);
			break;
		default:
			melee.Begin(attack, Target);
			break;
		case WidowAttack.Bite:
		case WidowAttack.Pistols:
			break;
		}
		goto IL_0185;
		IL_0185:
		return true;
		IL_009b:
		takedown = ((Component)this).gameObject.AddComponent<WidowTakedown>();
		if (!takedown.Begin(this, Target, attack))
		{
			takedown.Stop();
			takedown = null;
			Clock.Finish();
			return false;
		}
		goto IL_0185;
	}

	private Vector3 SafeSide(bool away)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: 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_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//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)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: 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_011a: 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_012f: 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)
		Vector3 val = Vector3.Cross(Vector3.up, Facing) * (float)((Self.Id % 2 == 0) ? 1 : (-1));
		Vector3[] array = new Vector3[3];
		Vector3 val2 = val - Facing * (away ? 0.25f : 0f);
		array[0] = ((Vector3)(ref val2)).normalized;
		val2 = -val - Facing * (away ? 0.25f : 0f);
		array[1] = ((Vector3)(ref val2)).normalized;
		array[2] = Facing;
		Vector3[] array2 = (Vector3[])(object)array;
		foreach (Vector3 val3 in array2)
		{
			if (World.GroundBelow(Self.Position + val3 * 1.3f * Self.Scale, 3.3f * Self.Scale, out var _) && World.ClearPath(Self, Self.Position, Self.Position + val3 * 1.3f * Self.Scale, Target, terrainOnly: true))
			{
				return val3;
			}
		}
		return Facing;
	}

	private void FixedUpdate()
	{
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: 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_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: 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_0327: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: Unknown result type (might be due to invalid IL or missing references)
		//IL_033b: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_06af: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		//IL_0422: Unknown result type (might be due to invalid IL or missing references)
		//IL_0629: Unknown result type (might be due to invalid IL or missing references)
		//IL_0634: Unknown result type (might be due to invalid IL or missing references)
		//IL_0439: Unknown result type (might be due to invalid IL or missing references)
		//IL_043a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0440: Unknown result type (might be due to invalid IL or missing references)
		//IL_0445: Unknown result type (might be due to invalid IL or missing references)
		//IL_044a: Unknown result type (might be due to invalid IL or missing references)
		//IL_045d: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0464: Unknown result type (might be due to invalid IL or missing references)
		//IL_0474: Unknown result type (might be due to invalid IL or missing references)
		//IL_0479: Unknown result type (might be due to invalid IL or missing references)
		//IL_047e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0485: Unknown result type (might be due to invalid IL or missing references)
		//IL_0495: Unknown result type (might be due to invalid IL or missing references)
		//IL_049a: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04db: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0582: Unknown result type (might be due to invalid IL or missing references)
		//IL_058d: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0671: Unknown result type (might be due to invalid IL or missing references)
		//IL_0669: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0676: Unknown result type (might be due to invalid IL or missing references)
		//IL_067e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0694: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ee: Unknown result type (might be due to invalid IL or missing references)
		if (!initialized || cleaned || Self == null || !Self.Alive || !World.InBattle || !Object.op_Implicit((Object)(object)Self.Main) || !locked)
		{
			return;
		}
		try
		{
			if (Disabled)
			{
				if (Object.op_Implicit((Object)(object)Interaction))
				{
					Interaction.Cancel();
				}
				FinishAction();
				Motor.Limit();
			}
			else
			{
				if (Object.op_Implicit((Object)(object)Interaction))
				{
					return;
				}
				Motor.Turn(Facing);
				bool flag = Object.op_Implicit((Object)(object)takedown) || (Clock.Attack == WidowAttack.JumpKick && Clock.State == WidowState.MeleeCombat);
				float crouch = ((Clock.State != WidowState.Dodge) ? 1f : ((moves % 3 == 0) ? 0.38f : 0.73f));
				if (Clock.State == WidowState.Dodge)
				{
					Motor.Acrobatics(Facing, moves % 4, Mathf.Clamp01((Time.time - Clock.Start) / Mathf.Max(0.1f, Clock.End - Clock.Start)));
				}
				else
				{
					Motor.Hold(Facing, crouch, !flag);
				}
				Motor.Hands(Facing);
				if (Object.op_Implicit((Object)(object)takedown))
				{
					takedown.Step();
				}
				else if (Object.op_Implicit((Object)(object)grapple))
				{
					grapple.Step();
				}
				else if (melee.Running)
				{
					if (Target != null && Target.Alive && Vector3.Distance(Self.Position, Target.Position) > 1.55f * Self.Scale)
					{
						Motor.Drive(Facing, 4.8f, Target);
					}
					if (Clock.State == WidowState.Counter)
					{
						Motor.Drive(travel, 4.5f, Target);
					}
					Motor.Gait(Facing, 0f);
					melee.Step();
				}
				else if (Clock.State == WidowState.Dodge)
				{
					Motor.Drive(travel, 6f);
					if (moves % 4 == 2)
					{
						Motor.Gait(Facing, 6f, 0.42f);
					}
				}
				else if (Clock.State == WidowState.SmokeReposition)
				{
					if (!fired)
					{
						fired = true;
						Bite.Launch(WidowProjectileKind.Smoke, Visual.Hand(left: true), Self.Position + Facing * 1.2f - Vector3.up * 0.65f * Self.Scale);
					}
					Motor.Drive(travel, 5.7f, Target);
					Motor.Gait(Facing, 5.7f, 0.72f);
				}
				else if (Clock.State == WidowState.PistolCombat || Clock.State == WidowState.WidowsBite)
				{
					if (Target == null || !Target.Alive)
					{
						FinishAction();
						return;
					}
					Vector3 val = Aim(Target) - Visual.Hand(left: false);
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					Visual.Aim = normalized;
					Vector3 val2 = (Object.op_Implicit((Object)(object)Motor.Torso) ? Motor.Torso.position : Self.Position);
					Vector3 val3 = Vector3.Cross(Vector3.up, Facing);
					Motor.Pose(Motor.Left, val2 + normalized * 0.58f * Self.Scale - val3 * 0.2f * Self.Scale);
					Motor.Pose(Motor.Right, val2 + normalized * 0.59f * Self.Scale + val3 * 0.2f * Self.Scale);
					Visual.Align();
					if (Time.time >= nextShot)
					{
						nextShot = Time.time + 0.19f;
						bool flag2 = Clock.State == WidowState.WidowsBite;
						if (shots < (flag2 ? 1 : 4))
						{
							Bite.Fire(shots % 2 == 0, Target, flag2);
							shots++;
						}
					}
					float num = Vector3.Distance(Self.Position, Target.Position) / Self.Scale;
					Vector3 direction = ((num > 16f) ? Facing : SafeSide(away: false));
					Motor.Drive(direction, (num > 16f) ? 5.5f : 2.5f, Target);
					Motor.Gait(Facing, 2.5f);
				}
				else if (Target != null && Target.Alive)
				{
					float num2 = Vector3.Distance(Self.Position, Target.Position) / Self.Scale;
					float speed = ((num2 > 2.2f) ? 6.4f : 1.8f);
					Vector3 direction2 = ((num2 > 2.2f) ? Facing : SafeSide(away: false));
					Motor.Drive(direction2, speed, Target);
					Motor.Gait(Facing, speed);
				}
				else
				{
					Motor.Gait(Facing, 0f);
				}
				Visual.Align();
				Motor.Limit();
			}
		}
		catch (Exception ex)
		{
			Launcher.WarnOnce("widow_fixed_" + Self.Id, "Black Widow physical action canceled: " + ex);
			if (Object.op_Implicit((Object)(object)Interaction))
			{
				Interaction.Cancel();
			}
			FinishAction();
			Motor.Limit();
		}
	}

	internal bool Reserve(MarvelInteractionScene scene, WidowState state, float seconds)
	{
		if (!Ready || !Object.op_Implicit((Object)(object)scene))
		{
			return false;
		}
		FinishAction();
		Interaction = scene;
		Clock.State = state;
		Clock.Start = Time.time;
		Clock.End = Time.time + seconds;
		return true;
	}

	internal void Release(MarvelInteractionScene scene)
	{
		if (!((Object)(object)Interaction != (Object)(object)scene))
		{
			Interaction = null;
			Clock.Finish();
			Clock.AttackRequired = true;
		}
	}

	internal void Face(Vector3 point)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		Vector3 val = UnitRef.Flat(point - Self.Position);
		if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
		{
			facing = ((Vector3)(ref val)).normalized;
		}
		BlackWidowVisual visual = Visual;
		Vector3 val2 = point - Visual.Hand(left: false);
		visual.Aim = ((Vector3)(ref val2)).normalized;
	}

	internal void TakedownFinished(WidowTakedown a)
	{
		if (!((Object)(object)takedown != (Object)(object)a))
		{
			takedown = null;
			Clock.Finish();
			Clock.AttackRequired = true;
		}
	}

	internal void GrappleFinished(WidowGrapplingLine a)
	{
		if (!((Object)(object)grapple != (Object)(object)a))
		{
			grapple = null;
			Clock.Finish();
			Clock.AttackRequired = true;
		}
	}

	internal void FinishAction()
	{
		if (Object.op_Implicit((Object)(object)takedown))
		{
			WidowTakedown widowTakedown = takedown;
			takedown = null;
			widowTakedown.Stop();
		}
		if (Object.op_Implicit((Object)(object)grapple))
		{
			WidowGrapplingLine widowGrapplingLine = grapple;
			grapple = null;
			widowGrapplingLine.Stop();
		}
		if (melee != null)
		{
			melee.Stop();
		}
		Clock.Finish();
	}

	private void Cleanup()
	{
		if (!cleaned)
		{
			cleaned = true;
			if (Object.op_Implicit((Object)(object)Interaction))
			{
				Interaction.Cancel();
			}
			FinishAction();
			if (Object.op_Implicit((Object)(object)Bite))
			{
				Bite.Clear();
			}
			Unlock();
			if (Motor != null)
			{
				Motor.Dispose(Self != null && Self.Alive);
			}
			initialized = false;
		}
	}

	private void OnDisable()
	{
		Cleanup();
	}

	private void OnDestroy()
	{
		Cleanup();
	}
}
internal static class WidowEffects
{
	internal static void Arc(Vector3 from, Vector3 to, float seconds = 0.13f, float width = 0.018f)
	{
		//IL_0005: 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_0010: Unknown result type (might be due to invalid IL or missing references)
		new GameObject("Marvel_Widow_ElectricArc").AddComponent<WidowElectricArc>().Begin(from, to, seconds, width);
	}

	internal static void Shock(UnitRef enemy)
	{
		//IL_0031: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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_0071: 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_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: 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)
		if (enemy != null && Object.op_Implicit((Object)(object)enemy.Unit))
		{
			Vector3 val = (Object.op_Implicit((Object)(object)enemy.Torso) ? enemy.Torso.position : enemy.Position);
			for (int i = 0; i < 3; i++)
			{
				Arc(val + Vector3.up * 0.3f * enemy.Scale + Vector3.right * (float)(i - 1) * 0.17f * enemy.Scale, val + Vector3.down * 0.35f * enemy.Scale - Vector3.right * (float)(i - 1) * 0.12f * enemy.Scale, 0.22f);
			}
		}
	}

	internal static void Impact(Vector3 point)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		HawkeyeEffects.Puff(point, new Color(0.7f, 0.77f, 0.8f, 0.24f), 0.16f, 0.12f);
	}
}
public sealed class WidowElectricArc : MonoBehaviour
{
	private LineRenderer line;

	private Vector3 a;

	private Vector3 b;

	private float end;

	private float width;

	internal void Begin(Vector3 from, Vector3 to, float seconds, float thick)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		BlackWidowAssets.Ensure();
		a = from;
		b = to;
		end = Time.time + Mathf.Clamp(seconds, 0.03f, 0.5f);
		width = thick;
		line = ((Component)this).gameObject.AddComponent<LineRenderer>();
		((Renderer)line).sharedMaterial = BlackWidowAssets.Electric;
		line.positionCount = 9;
		line.widthMultiplier = width;
	}

	private void Update()
	{
		//IL_0021: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: 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)
		if (!World.InBattle || Time.time >= end)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		Vector3 val = b - a;
		val = Vector3.Cross(((Vector3)(ref val)).normalized, Vector3.up);
		Vector3 normalized = ((Vector3)(ref val)).normalized;
		for (int i = 0; i < 9; i++)
		{
			float num = (float)i / 8f;
			line.SetPosition(i, Vector3.Lerp(a, b, num) + normalized * Mathf.Sin((float)i * 3.1f + Time.time * 80f) * Mathf.Sin(num * (float)Math.PI) * 0.055f);
		}
		LineRenderer obj = line;
		LineRenderer obj2 = line;
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0.55f, 0.9f, 1f, Mathf.Clamp01((end - Time.time) * 8f));
		obj2.endColor = val2;
		obj.startColor = val2;
	}
}
public sealed class WidowSmoke : MonoBehaviour
{
	internal static readonly HashSet<WidowSmoke> Clouds = new HashSet<WidowSmoke>();

	private UnitRef source;

	private float end;

	internal static void Spawn(UnitRef owner, Vector3 point)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Marvel_Widow_SmokeCloud");
		val.transform.position = point + Vector3.up * 0.3f;
		WidowSmoke widowSmoke = val.AddComponent<WidowSmoke>();
		widowSmoke.source = owner;
		widowSmoke.end = Time.time + 3.8f;
		Clouds.Add(widowSmoke);
		val.AddComponent<HawkeyePuffs>().Build(new Color(0.43f, 0.47f, 0.5f, 0.38f), 2.7f, 3.8f, 11, cloud: true);
	}

	internal static bool Obscured(UnitRef observer, Vector3 from, Vector3 to)
	{
		//IL_004e: 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_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		if (observer == null)
		{
			return false;
		}
		if (Object.op_Implicit((Object)(object)observer.Unit.GetComponent<BlackWidowCombatAI>()))
		{
			return false;
		}
		foreach (WidowSmoke cloud in Clouds)
		{
			if (Object.op_Implicit((Object)(object)cloud) && cloud.source != null && Time.time < cloud.end && HawkeyeRules.SmokeIntersects(from.x, from.y, from.z, to.x, to.y, to.z, ((Component)cloud).transform.position.x, ((Component)cloud).transform.position.y + 0.5f, ((Component)cloud).transform.position.z, 2.16f))
			{
				return true;
			}
		}
		return false;
	}

	internal static void Install(Harmony h)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		MethodInfo methodInfo = R.Method(World.ApiType, "SetAttackTarget");
		if (methodInfo != null)
		{
			h.Patch((MethodBase)methodInfo, new HarmonyMethod(ArgumentBridge.Create(methodInfo, Sight))
			{
				priority = 620
			}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static void Sight(object instance, MethodBase method, object[] args)
	{
		//IL_0083: 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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		if (Clouds.Count == 0 || !World.InBattle)
		{
			return;
		}
		Component val = (Component)((instance is Component) ? instance : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		UnitRef unitRef = World.Get(val);
		if (unitRef == null)
		{
			return;
		}
		ParameterInfo[] parameters = method.GetParameters();
		int num = -1;
		for (int i = 0; i < parameters.Length; i++)
		{
			if (parameters[i].Name == "targetPos")
			{
				num = i;
			}
		}
		if (num < 0 || !Obscured(unitRef, Object.op_Implicit((Object)(object)unitRef.Head) ? unitRef.Head.position : unitRef.Position, R.Vector(args[num], unitRef.Position)))
		{
			return;
		}
		for (int j = 0; j < parameters.Length; j++)
		{
			if (parameters[j].Name == "canSeeTarget" || parameters[j].Name == "startAttack")
			{
				args[j] = false;
			}
		}
	}

	private void Update()
	{
		if (!World.InBattle || source == null || !Object.op_Implicit((Object)(object)source.Unit) || Time.time >= end)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}

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

	private void OnDestroy()
	{
		Clouds.Remove(this);
	}
}
public sealed class WidowShock : MonoBehaviour
{
	private UnitRef self;

	private SpiderAbilityControl control;

	private WebStatus status;

	private float end;

	private float immune;

	private bool locked;

	internal static void Apply(UnitRef victim, UnitRef source, float seconds)
	{
		if (victim == null || !victim.Alive)
		{
			return;
		}
		WidowShock widowShock = victim.Unit.GetComponent<WidowShock>();
		if (!Object.op_Implicit((Object)(object)widowShock))
		{
			widowShock = victim.Unit.gameObject.AddComponent<WidowShock>();
		}
		if (!(Time.time < widowShock.immune))
		{
			HulkController component = victim.Unit.GetComponent<HulkController>();
			IronSpiderController component2 = victim.Unit.GetComponent<IronSpiderController>();
			bool flag = (Object.op_Implicit((Object)(object)component) && component.Clock.Hulk) || (Object.op_Implicit((Object)(object)component2) && component2.BlockNormal) || HulkCombat.Mass(victim) > HulkCombat.Mass(source) * 3f;
			widowShock.self = victim;
			widowShock.end = Time.time + Mathf.Min(flag ? 0.24f : 1.25f, seconds);
			widowShock.immune = widowShock.end + 3.5f;
			widowShock.control = SpiderAbilityControl.For(victim);
			widowShock.status = WebStatus.For(victim);
			widowShock.status.ShockUntil = Mathf.Max(widowShock.status.ShockUntil, widowShock.end);
			if (!widowShock.locked)
			{
				widowShock.control.Acquire();
				widowShock.locked = true;
			}
			widowShock.status.SuspendBalance(widowShock.end - Time.time);
			WidowEffects.Shock(victim);
		}
	}

	private void FixedUpdate()
	{
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		if (self == null || !self.Alive || !World.InBattle)
		{
			Release();
			Object.Destroy((Object)(object)this);
		}
		else if (Time.time >= end)
		{
			Release();
			if (Time.time >= immune)
			{
				Object.Destroy((Object)(object)this);
			}
		}
		else
		{
			Rigidbody main = self.Main;
			if (Object.op_Implicit((Object)(object)main) && !main.isKinematic)
			{
				main.AddTorque(new Vector3(Mathf.Sin(Time.time * 43f), 0f, Mathf.Cos(Time.time * 37f)) * 8f, (ForceMode)5);
			}
		}
	}

	private void Release()
	{
		if (locked)
		{
			if (Object.op_Implicit((Object)(object)control))
			{
				control.Release();
			}
			locked = false;
			if (Object.op_Implicit((Object)(object)status))
			{
				status.ResumeBalance();
			}
		}
	}

	private void OnDisable()
	{
		Release();
	}

	private void OnDestroy()
	{
		Release();
	}
}
internal sealed class BlackWidowMeleeSystem
{
	private readonly BlackWidowCombatAI widow;

	private WidowAttack attack;

	private UnitRef target;

	private float start;

	private float end;

	private bool active;

	private bool jumped;

	private int stage = -1;

	private readonly HashSet<int> hit = new HashSet<int>();

	private Vector3 previousA;

	private Vector3 previousB;

	private Rigidbody limb;

	internal bool Running => active;

	internal BlackWidowMeleeSystem(BlackWidowCombatAI owner)
	{
		widow = owner;
	}

	internal void Begin(WidowAttack a, UnitRef enemy)
	{
		Stop();
		attack = a;
		target = enemy;
		start = Time.time;
		end = start + WidowRules.Duration(a);
		active = true;
		widow.Visual.Switch(WidowRules.Weapon(a));
	}

	internal void Step()
	{
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//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_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: 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_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0353: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_0399: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_0415: Unknown result type (might be due to invalid IL or missing references)
		//IL_042a: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_04af: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_044e: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0526: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0541: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_07aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0636: Unknown result type (might be due to invalid IL or missing references)
		//IL_063b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0640: Unknown result type (might be due to invalid IL or missing references)
		//IL_0653: Unknown result type (might be due to invalid IL or missing references)
		//IL_0658: Unknown result type (might be due to invalid IL or missing references)
		//IL_065d: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_074b: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_06cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06da: Unknown result type (might be due to invalid IL or missing references)
		//IL_0769: Unknown result type (might be due to invalid IL or missing references)
		//IL_076b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0770: Unknown result type (might be due to invalid IL or missing references)
		//IL_0773: Unknown result type (might be due to invalid IL or missing references)
		//IL_0778: Unknown result type (might be due to invalid IL or missing references)
		//IL_077d: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0702: Unknown result type (might be due to invalid IL or missing references)
		//IL_0707: Unknown result type (might be due to invalid IL or missing references)
		//IL_070c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0715: Unknown result type (might be due to invalid IL or missing references)
		//IL_0718: Unknown result type (might be due to invalid IL or missing references)
		//IL_071d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0722: Unknown result type (might be due to invalid IL or missing references)
		if (!active)
		{
			return;
		}
		if (Time.time >= end || target == null || !target.Alive || !widow.Self.Alive)
		{
			Stop();
			return;
		}
		float num = Time.time - start;
		int num2 = ((attack == WidowAttack.DoubleBaton && num >= 0.35f) ? 1 : 0);
		bool flag = attack == WidowAttack.BatonLeft || attack == WidowAttack.Punch || (attack == WidowAttack.DoubleBaton && num2 == 0);
		bool flag2 = WidowRules.Kick(attack);
		BlackWidowVisual visual = widow.Visual;
		Vector3 facing = widow.Facing;
		Vector3 val = Vector3.Cross(Vector3.up, facing);
		Vector3 val2 = (Object.op_Implicit((Object)(object)widow.Motor.Torso) ? widow.Motor.Torso.position : widow.Self.Position);
		Vector3 val3;
		if (stage != num2)
		{
			stage = num2;
			hit.Clear();
			limb = ((!flag2) ? (flag ? widow.Motor.Left : widow.Motor.Right) : (flag ? widow.Motor.FootL : widow.Motor.FootR));
			val3 = (previousA = (previousB = (Object.op_Implicit((Object)(object)limb) ? widow.Motor.Point(limb) : val2)));
		}
		float num3 = num - ((num2 == 1) ? 0.35f : 0f);
		float num4 = Mathf.Clamp01((num3 - 0.075f) / 0.22f);
		bool flag3 = WidowRules.Weapon(attack) == WidowWeapon.Batons || attack == WidowAttack.StaffSweep;
		Vector3 val4 = ((!WidowRules.Low(attack)) ? ((attack != WidowAttack.Elbow) ? (Object.op_Implicit((Object)(object)target.Torso) ? target.Torso.position : target.Position) : (Object.op_Implicit((Object)(object)target.Head) ? target.Head.position : target.Position)) : (Object.op_Implicit((Object)(object)target.LeftFoot) ? target.LeftFoot.position : (target.Position - Vector3.up * 0.65f * target.Scale)));
		Vector3 val5 = val2 - facing * 0.17f * widow.Self.Scale + val * (flag ? (-0.31f) : 0.31f) * widow.Self.Scale;
		if (flag2)
		{
			val5 = widow.Self.Position + Vector3.up * 0.03f * widow.Self.Scale - facing * 0.19f * widow.Self.Scale;
		}
		if (attack == WidowAttack.Knee)
		{
			val4 = target.Position + Vector3.up * 0.05f * target.Scale;
		}
		if (attack == WidowAttack.StaffSweep || attack == WidowAttack.SpinningKick || attack == WidowAttack.BackKick)
		{
			float num5 = Mathf.Lerp(-65f, 80f, num4);
			val4 = val2 + Quaternion.AngleAxis(num5, Vector3.up) * facing * (flag2 ? 0.85f : 0.65f) * widow.Self.Scale;
			if (flag2)
			{
				val4.y = (WidowRules.Low(attack) ? (target.Position.y - 0.5f * target.Scale) : (target.Position.y + 0.2f * target.Scale));
			}
		}
		widow.Motor.Pose(limb, (num3 < 0.08f) ? val5 : Vector3.Lerp(val5, val4, num4), (num3 < 0.08f) ? 100 : 165);
		if (attack == WidowAttack.JumpKick && !jumped)
		{
			jumped = true;
			widow.Motor.Jump(facing, 3f, 2.4f);
		}
		if (attack == WidowAttack.Counter && num3 < 0.16f)
		{
			widow.Motor.Drive(val * (float)((widow.Self.Id % 2 == 0) ? 1 : (-1)), 3f, target);
		}
		if (flag3)
		{
			visual.BatonYaw = ((attack == WidowAttack.StaffSweep) ? Mathf.Lerp(-95f, 85f, num4) : Mathf.Lerp(-50f, 28f, num4));
			visual.BatonPitch = Mathf.Lerp(-30f, 32f, num4);
		}
		visual.Align();
		Vector3 val6 = (Object.op_Implicit((Object)(object)limb) ? widow.Motor.Point(limb) : val2);
		Vector3 val7 = val6;
		float num6 = (flag2 ? 0.105f : 0.08f) * widow.Self.Scale;
		if (flag3)
		{
			Transform val8 = visual.Baton(flag);
			if (Object.op_Implicit((Object)(object)val8))
			{
				val6 = val8.TransformPoint(new Vector3(0f, 0f, (attack == WidowAttack.StaffSweep) ? (-0.62f) : 0.05f));
				val7 = val8.TransformPoint(new Vector3(0f, 0f, 0.59f));
				num6 = 0.048f * widow.Self.Scale;
			}
		}
		if (num3 >= ((attack == WidowAttack.StaffSweep) ? 0.18f : 0.1f) && num3 <= ((attack == WidowAttack.StaffSweep) ? 0.4f : 0.32f))
		{
			Sweep(previousA, val6, num6);
			if (flag3)
			{
				Sweep(previousB, val7, num6);
				Collider[] array = Physics.OverlapCapsule(val6, val7, num6, -1, (QueryTriggerInteraction)1);
				foreach (Collider val9 in array)
				{
					Vector3 point = val9.ClosestPoint(val7);
					val3 = val6 - previousA;
					float magnitude = ((Vector3)(ref val3)).magnitude;
					val3 = val7 - previousB;
					Contact(val9, point, Mathf.Max(magnitude, ((Vector3)(ref val3)).magnitude) / Time.fixedDeltaTime);
				}
			}
			else
			{
				Collider[] array = Physics.OverlapSphere(val6, num6, -1, (QueryTriggerInteraction)1);
				foreach (Collider val10 in array)
				{
					Vector3 point2 = val10.ClosestPoint(val6);
					val3 = val6 - previousA;
					Contact(val10, point2, ((Vector3)(ref val3)).magnitude / Time.fixedDeltaTime);
				}
			}
		}
		previousA = val6;
		previousB = val7;
	}

	private void Sweep(Vector3 from, Vector3 to, float radius)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = to - from;
		if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
		{
			return;
		}
		foreach (RaycastHit item in from h in Physics.SphereCastAll(@from, radius, ((Vector3)(ref val)).normalized, ((Vector3)(ref val)).magnitude, -1, (QueryTriggerInteraction)1)
			orderby ((RaycastHit)(ref h)).distance
			select h)
		{
			RaycastHit current = item;
			if (World.Get((Component)(object)((RaycastHit)(ref current)).collider) != widow.Self)
			{
				if (World.Get((Component)(object)((RaycastHit)(ref current)).collider) == null)
				{
					break;
				}
				Contact(((RaycastHit)(ref current)).collider, ((RaycastHit)(ref current)).point, ((Vector3)(ref val)).magnitude / Time.fixedDeltaTime);
			}
		}
	}

	private void Contact(Collider c, Vector3 point, float speed)
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: 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_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: 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_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: 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_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: 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)
		if (!active || speed < 1.1f || !Object.op_Implicit((Object)(object)c))
		{
			return;
		}
		UnitRef unitRef = World.Get((Component)(object)c);
		if (unitRef == null || !unitRef.Alive || unitRef.Team == widow.Self.Team || hit.Contains(unitRef.Id) || !World.ClearPath(widow.Self, Object.op_Implicit((Object)(object)limb) ? widow.Motor.Point(limb) : widow.Self.Position, point, unitRef, terrainOnly: true))
		{
			return;
		}
		hit.Add(unitRef.Id);
		float num = HulkCombat.Mass(unitRef) / Mathf.Max(1f, HulkCombat.Mass(widow.Self));
		float num2 = WidowRules.ForceScale(num);
		Vector3 val = UnitRef.Flat(unitRef.Position - widow.Self.Position);
		Vector3 val2 = ((Vector3)(ref val)).normalized;
		if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
		{
			val2 = widow.Facing;
		}
		unitRef.Damage(WidowRules.Damage(attack), val2, widow.Self);
		unitRef.AddVelocity(val2 * (WidowRules.Kick(attack) ? 2.8f : 1.45f) * num2 + Vector3.up * 0.22f * num2, 3.3f);
		if (unitRef.Alive)
		{
			if (num <= 2.15f)
			{
				WebStatus.For(unitRef).SuspendBalance(WidowRules.Low(attack) ? 0.65f : 0.24f);
			}
			if (WidowRules.Weapon(attack) == WidowWeapon.Batons || attack == WidowAttack.StaffSweep)
			{
				WidowShock.Apply(unitRef, widow.Self, 0.42f);
			}
		}
		WidowEffects.Impact(point);
		if (WidowRules.Weapon(attack) != WidowWeapon.Unarmed)
		{
			WidowEffects.Arc(point, point + Vector3.up * 0.2f, 0.12f);
		}
	}

	internal void Stop()
	{
		active = false;
		jumped = false;
		target = null;
		limb = null;
		hit.Clear();
		stage = -1;
		if (Object.op_Implicit((Object)(object)widow.Visual))
		{
			widow.Visual.BatonYaw = (widow.Visual.BatonPitch = 0f);
		}
	}
}
internal sealed class BlackWidowMotor
{
	private readonly UnitRef self;

	internal readonly IronManMotor Native;

	private bool begun;

	private readonly Quaternion hipOffset;

	private readonly Quaternion torsoOffset;

	private readonly Quaternion headOffset;

	internal Rigidbody Left => Native.Left;

	internal Rigidbody Right => Native.Right;

	internal Rigidbody FootL => Native.FootL;

	internal Rigidbody FootR => Native.FootR;

	internal Rigidbody Torso => Native.Torso;

	internal Rigidbody Head => Native.Head;

	internal bool Grounded => Native.Grounded;

	internal BlackWidowMotor(UnitRef u)
	{
		//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_0037: 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_003c: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		self = u;
		Native = new IronManMotor(u, physicalSkin: true);
		Vector3 forward = u.Forward;
		Quaternion val = Quaternion.LookRotation((((Vector3)(ref forward)).sqrMagnitude > 0.01f) ? u.Forward : Vector3.forward);
		hipOffset = Quaternion.Inverse(val) * u.Main.rotation;
		torsoOffset = (Object.op_Implicit((Object)(object)Torso) ? (Quaternion.Inverse(val) * Torso.rotation) : hipOffset);
		headOffset = (Object.op_Implicit((Object)(object)Head) ? (Quaternion.Inverse(val) * Head.rotation) : hipOffset);
	}

	internal Vector3 Point(Rigidbody body)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return Native.Point(body);
	}

	internal Vector3 Hand(bool left)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return Native.Hand(left);
	}

	internal Vector3 Foot(bool left)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return Native.Foot(left);
	}

	internal void Begin()
	{
		if (!begun)
		{
			begun = true;
			Native.Begin();
		}
	}

	internal void Hold(Vector3 facing, float crouch = 1f, bool support = true, float roll = 0f)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		Native.EnsureAuthority();
		Native.Stabilize(facing, crouch, 0f, support, 0.7f);
		if (Mathf.Abs(roll) > 0.1f && Object.op_Implicit((Object)(object)self.Main) && !self.Main.isKinematic)
		{
			self.Main.AddTorque(facing * roll, (ForceMode)5);
		}
	}

	internal void Gait(Vector3 direction, float speed, float crouch = 1f, bool air = false)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Native.Gait(direction, speed, crouch, air);
	}

	internal void Drive(Vector3 direction, float speed, UnitRef target = null)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Native.Drive(direction, Mathf.Min(7.8f, speed), target);
	}

	internal void Hands(Vector3 facing)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Vector3.Cross(Vector3.up, facing);
		Vector3 val2 = (Object.op_Implicit((Object)(object)Torso) ? Torso.position : self.Position);
		Pose(Left, val2 - val * 0.34f * self.Scale + facing * 0.3f * self.Scale, 75f);
		Pose(Right, val2 + val * 0.34f * self.Scale + facing * 0.28f * self.Scale, 75f);
	}

	internal void Pose(Rigidbody limb, Vector3 goal, float force = 130f)
	{
		//IL_003c: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: 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_00f3: 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_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: 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_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)limb) && !((Object)(object)limb == (Object)(object)self.Main))
		{
			Vector3 val = (Object.op_Implicit((Object)(object)Torso) ? Torso.position : self.Position);
			if ((Object)(object)limb == (Object)(object)Left || (Object)(object)limb == (Object)(object)Right)
			{
				Vector3 val2 = val + Vector3.Cross(Vector3.up, self.Forward) * (((Object)(object)limb == (Object)(object)Left) ? (-0.25f) : 0.25f) * self.Scale + Vector3.up * 0.12f * self.Scale;
				goal = val2 + Vector3.ClampMagnitude(goal - val2, 0.73f * self.Scale);
			}
			else if ((Object)(object)limb == (Object)(object)FootL || (Object)(object)limb == (Object)(object)FootR)
			{
				goal = self.Position + Vector3.ClampMagnitude(goal - self.Position, 1.04f * self.Scale);
			}
			Native.Pose(limb, goal, Mathf.Min(180f, force));
		}
	}

	internal void Turn(Vector3 direction)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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)
		Transform val = R.Get<Transform>(self.Data, "characterForwardObject");
		if (Object.op_Implicit((Object)(object)val) && ((Vector3)(ref direction)).sqrMagnitude > 0.01f)
		{
			Vector3 val2 = UnitRef.Flat(direction);
			val.rotation = Quaternion.LookRotation(((Vector3)(ref val2)).normalized, Vector3.up);
		}
	}

	internal void Jump(Vector3 direction, float speed, float up)
	{
		//IL_0019: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		if (Native.FindFloor())
		{
			UnitRef unitRef = self;
			Vector3 val = UnitRef.Flat(direction);
			unitRef.AddVelocity(((Vector3)(ref val)).normalized * Mathf.Min(7f, speed) + Vector3.up * Mathf.Min(6f, up), 9f);
		}
	}

	internal void Acrobatics(Vector3 facing, int kind, float phase)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might

BepInEx/plugins/MarvelPrototype/MarvelPrototype.Donate.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Marvel Prototype Donate")]
[assembly: AssemblyFileVersion("3.5.0.0")]
[assembly: AssemblyVersion("3.5.0.0")]
namespace MarvelPrototype.Donate;

[BepInPlugin("darkx.marvelprototype.donate", "Marvel Prototype: DonationAlerts", "3.5.0")]
public class DonatePlugin : BaseUnityPlugin
{
	internal const string DefaultUrl = "https://www.donationalerts.com/r/lilzalupaa";

	internal static ConfigEntry<string> Url;

	internal static ConfigEntry<bool> Show;

	internal static ConfigEntry<bool> DontShow;

	internal static ConfigEntry<bool> OpenNow;

	internal static DonatePlugin Instance;

	private static bool shownThisLaunch;

	private static DonateWindow window;

	private float next;

	private float stableSince = -1f;

	private Type menuType;

	private MethodInfo inMainMenu;

	private void Awake()
	{
		Instance = this;
		Url = ((BaseUnityPlugin)this).Config.Bind<string>("DonationAlerts", "Url", "https://www.donationalerts.com/r/lilzalupaa", "DonationAlerts page opened by the Donate button.");
		Show = ((BaseUnityPlugin)this).Config.Bind<bool>("DonationAlerts", "ShowOnStartup", true, "Show the small DonationAlerts card once per game launch in the main menu.");
		DontShow = ((BaseUnityPlugin)this).Config.Bind<bool>("DonationAlerts", "DontShowAgain", false, "Set by the card's \"Don't show again\" checkbox.");
		OpenNow = ((BaseUnityPlugin)this).Config.Bind<bool>("DonationAlerts", "OpenNow", false, "Set to true (e.g. in a BepInEx configuration manager) to show the card again right now; it resets itself.");
		OpenNow.SettingChanged += delegate
		{
			if (OpenNow.Value)
			{
				OpenNow.Value = false;
				Open(manual: true);
			}
		};
		if (OpenNow.Value)
		{
			OpenNow.Value = false;
		}
	}

	internal static bool ValidUrl(string u)
	{
		if (!string.IsNullOrEmpty(u) && Uri.TryCreate(u.Trim(), UriKind.Absolute, out Uri result))
		{
			return result.Scheme == Uri.UriSchemeHttps;
		}
		return false;
	}

	internal bool InMainMenu()
	{
		if (inMainMenu == null)
		{
			Type type = Type("TABSSceneManager");
			inMainMenu = ((type != null) ? type.GetMethod("IsInMainMenuScene", BindingFlags.Static | BindingFlags.Public) : null);
		}
		try
		{
			return inMainMenu != null && (bool)inMainMenu.Invoke(null, null);
		}
		catch
		{
			return false;
		}
	}

	internal static Type Type(string name)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		for (int i = 0; i < assemblies.Length; i++)
		{
			Type type = assemblies[i].GetType(name, throwOnError: false);
			if (type != null)
			{
				return type;
			}
		}
		return null;
	}

	private void Update()
	{
		if (shownThisLaunch || !Show.Value || DontShow.Value || Time.unscaledTime < next)
		{
			return;
		}
		next = Time.unscaledTime + 0.25f;
		if (!InMainMenu())
		{
			stableSince = -1f;
			return;
		}
		if (menuType == null)
		{
			menuType = Type("MainMenuButtons");
		}
		if (menuType == null)
		{
			return;
		}
		Object obj = Object.FindObjectOfType(menuType);
		Behaviour val = (Behaviour)(object)((obj is Behaviour) ? obj : null);
		bool flag = (Object)(object)GameObject.Find("Marvel Prototype Discord invite") != (Object)null;
		if (!Object.op_Implicit((Object)(object)val) || !val.isActiveAndEnabled || flag)
		{
			stableSince = -1f;
			return;
		}
		if (stableSince < 0f)
		{
			stableSince = Time.unscaledTime;
		}
		if (!(Time.unscaledTime - stableSince < 1.5f))
		{
			Open(manual: false);
		}
	}

	internal static void Open(bool manual)
	{
		shownThisLaunch = true;
		if (Object.op_Implicit((Object)(object)window))
		{
			return;
		}
		try
		{
			window = DonateWindow.Create(Url.Value, DontShow.Value);
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)("DonationAlerts card shown (" + (manual ? "opened from settings" : "main menu, once per launch") + ")."));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)Instance).Logger.LogError((object)("DonationAlerts card failed: " + ex));
		}
	}

	internal static void Closed(bool dontShowAgain)
	{
		if (DontShow.Value != dontShowAgain)
		{
			DontShow.Value = dontShowAgain;
			((ConfigEntryBase)DontShow).ConfigFile.Save();
		}
		window = null;
	}

	internal static void Log(string s)
	{
		if (Object.op_Implicit((Object)(object)Instance))
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)s);
		}
	}
}
internal sealed class Texts
{
	internal string Title;

	internal string Body;

	internal string Donate;

	internal string Close;

	internal string DontShow;

	internal static readonly Texts Ru = new Texts
	{
		Title = "Поддержать Marvel Prototype",
		Body = "Мод бесплатный. Если он тебе нравится, можно поддержать автора донатом на DonationAlerts — это помогает делать новых героев.",
		Donate = "Задонатить",
		Close = "Закрыть",
		DontShow = "Больше не показывать"
	};

	internal static readonly Texts En = new Texts
	{
		Title = "Support Marvel Prototype",
		Body = "The mod is free. If you enjoy it, you can support the author with a donation on DonationAlerts. It helps make new heroes.",
		Donate = "Donate",
		Close = "Close",
		DontShow = "Don't show again"
	};

	internal bool Fits(Func<char, bool> has)
	{
		string[] array = new string[5] { Title, Body, Donate, Close, DontShow };
		foreach (string text in array)
		{
			foreach (char c in text)
			{
				if (!char.IsWhiteSpace(c) && !has(c))
				{
					return false;
				}
			}
		}
		return true;
	}
}
internal sealed class DonateWindow : MonoBehaviour
{
	private static readonly Color32 Brand = new Color32((byte)245, (byte)106, (byte)0, byte.MaxValue);

	private static Sprite rounded;

	private static Sprite icon;

	private RectTransform panel;

	private Toggle toggle;

	private string url;

	private bool closing;

	private float nextCheck;

	internal static DonateWindow Create(string url, bool dontShowAgain)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Marvel Prototype DonationAlerts", new Type[1] { typeof(RectTransform) });
		Object.DontDestroyOnLoad((Object)(object)val);
		Canvas obj = val.AddComponent<Canvas>();
		obj.renderMode = (RenderMode)0;
		obj.sortingOrder = 30002;
		CanvasScaler obj2 = val.AddComponent<CanvasScaler>();
		obj2.uiScaleMode = (ScaleMode)1;
		obj2.referenceResolution = new Vector2(1920f, 1080f);
		obj2.matchWidthOrHeight = 0.5f;
		val.AddComponent<GraphicRaycaster>();
		if (!Object.op_Implicit((Object)(object)EventSystem.current))
		{
			GameObject val2 = new GameObject("Marvel donate events");
			val2.transform.SetParent(val.transform, false);
			val2.AddComponent<EventSystem>();
			val2.AddComponent<StandaloneInputModule>();
		}
		DonateWindow donateWindow = val.AddComponent<DonateWindow>();
		donateWindow.url = url;
		donateWindow.Build(dontShowAgain);
		return donateWindow;
	}

	private static Sprite Rounded()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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_0038: Expected O, but got Unknown
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)rounded))
		{
			return rounded;
		}
		Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
		{
			name = "Marvel_Donate_Rounded",
			hideFlags = (HideFlags)52,
			wrapMode = (TextureWrapMode)1
		};
		Color32[] array = (Color32[])(object)new Color32[1024];
		for (int i = 0; i < 32; i++)
		{
			for (int j = 0; j < 32; j++)
			{
				float num = Mathf.Max(new float[3]
				{
					(float)(10 - j) - 0.5f,
					(float)j + 0.5f - 22f,
					0f
				});
				float num2 = Mathf.Max(new float[3]
				{
					(float)(10 - i) - 0.5f,
					(float)i + 0.5f - 22f,
					0f
				});
				float num3 = Mathf.Clamp01(10f - Mathf.Sqrt(num * num + num2 * num2) + 0.5f);
				array[i * 32 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num3 * 255f));
			}
		}
		val.SetPixels32(array);
		val.Apply(false, true);
		rounded = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(10f, 10f, 10f, 10f));
		((Object)rounded).hideFlags = (HideFlags)52;
		return rounded;
	}

	private static Sprite Icon()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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_0038: Expected O, but got Unknown
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)icon))
		{
			return icon;
		}
		Texture2D val = new Texture2D(96, 96, (TextureFormat)4, false)
		{
			name = "Marvel_Donate_Icon",
			hideFlags = (HideFlags)52,
			wrapMode = (TextureWrapMode)1
		};
		Color32[] array = (Color32[])(object)new Color32[9216];
		for (int i = 0; i < 96; i++)
		{
			for (int j = 0; j < 96; j++)
			{
				float num = Mathf.Max(new int[3]
				{
					22 - j,
					j - 73,
					0
				});
				float num2 = Mathf.Max(new int[3]
				{
					22 - i,
					i - 73,
					0
				});
				float num3 = Mathf.Clamp01(22f - Mathf.Sqrt(num * num + num2 * num2) + 0.5f);
				Color32 brand = Brand;
				brand.a = (byte)(num3 * 255f);
				float num4 = (float)(j - 48) / 26f;
				float num5 = (float)(i - 44) / 26f;
				float num6 = Mathf.Pow(num4 * num4 + num5 * num5 - 1f, 3f) - num4 * num4 * num5 * num5 * num5;
				if (num3 > 0f && num6 <= 0f)
				{
					((Color32)(ref brand))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, brand.a);
				}
				array[i * 96 + j] = brand;
			}
		}
		val.SetPixels32(array);
		val.Apply(false, true);
		icon = Sprite.Create(val, new Rect(0f, 0f, 96f, 96f), new Vector2(0.5f, 0.5f), 100f);
		((Object)icon).hideFlags = (HideFlags)52;
		return icon;
	}

	private static RectTransform Child(string name, Transform parent)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
		val.transform.SetParent(parent, false);
		return (RectTransform)val.transform;
	}

	private static Image Box(RectTransform t, Color c)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		Image obj = ((Component)t).gameObject.AddComponent<Image>();
		obj.sprite = Rounded();
		obj.type = (Type)1;
		((Graphic)obj).color = c;
		return obj;
	}

	private static TextMeshProUGUI Label(string name, Transform parent, float size, Color c, FontStyles style, TextAlignmentOptions align, TMP_FontAsset font)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		TextMeshProUGUI val = ((Component)Child(name, parent)).gameObject.AddComponent<TextMeshProUGUI>();
		if (Object.op_Implicit((Object)(object)font))
		{
			((TMP_Text)val).font = font;
		}
		((TMP_Text)val).fontSize = size;
		((Graphic)val).color = c;
		((TMP_Text)val).fontStyle = style;
		((TMP_Text)val).alignment = align;
		((TMP_Text)val).enableWordWrapping = true;
		((TMP_Text)val).overflowMode = (TextOverflowModes)0;
		((Graphic)val).raycastTarget = false;
		return val;
	}

	private static Button MakeButton(string name, Transform parent, Color colour, string text, TMP_FontAsset font, Action click)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Expected O, but got Unknown
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Expected O, but got Unknown
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = Child(name, parent);
		Image targetGraphic = Box(val, colour);
		Button obj = ((Component)val).gameObject.AddComponent<Button>();
		((Selectable)obj).targetGraphic = (Graphic)(object)targetGraphic;
		ColorBlock colors = ((Selectable)obj).colors;
		((ColorBlock)(ref colors)).normalColor = new Color(0.92f, 0.92f, 0.92f);
		((ColorBlock)(ref colors)).highlightedColor = Color.white;
		((ColorBlock)(ref colors)).pressedColor = new Color(0.75f, 0.75f, 0.75f);
		((ColorBlock)(ref colors)).selectedColor = ((ColorBlock)(ref colors)).highlightedColor;
		((ColorBlock)(ref colors)).disabledColor = new Color(0.45f, 0.45f, 0.45f, 0.6f);
		((ColorBlock)(ref colors)).fadeDuration = 0.08f;
		((Selectable)obj).colors = colors;
		((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
		{
			click();
		});
		VerticalLayoutGroup obj2 = ((Component)val).gameObject.AddComponent<VerticalLayoutGroup>();
		((LayoutGroup)obj2).padding = new RectOffset(14, 14, 10, 10);
		((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
		bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true);
		((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = childControlWidth;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
		LayoutElement obj3 = ((Component)val).gameObject.AddComponent<LayoutElement>();
		obj3.minHeight = 46f;
		obj3.preferredWidth = 10f;
		obj3.flexibleWidth = 1f;
		((TMP_Text)Label("Label", (Transform)(object)val, 20f, Color.white, (FontStyles)1, (TextAlignmentOptions)514, font)).text = text;
		return obj;
	}

	private static TMP_FontAsset Font()
	{
		TMP_FontAsset val = null;
		try
		{
			Type type = DonatePlugin.Type("Localizer");
			MethodInfo methodInfo = ((type != null) ? type.GetMethods(BindingFlags.Static | BindingFlags.Public).FirstOrDefault((MethodInfo x) => x.Name == "GetCurrentFont") : null);
			if (methodInfo != null)
			{
				ParameterInfo[] parameters = methodInfo.GetParameters();
				object? obj = methodInfo.Invoke(null, (parameters.Length != 1) ? new object[0] : new object[1] { 0 });
				val = (TMP_FontAsset)((obj is TMP_FontAsset) ? obj : null);
			}
		}
		catch
		{
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			val = TMP_Settings.defaultFontAsset ?? Resources.FindObjectsOfTypeAll<TMP_FontAsset>().FirstOrDefault();
		}
		return val;
	}

	private static bool Russian()
	{
		try
		{
			Type type = DonatePlugin.Type("Localizer");
			FieldInfo fieldInfo = ((type != null) ? type.GetField("m_locale", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) : null);
			object obj = ((fieldInfo != null) ? fieldInfo.GetValue(null) : null);
			return ((obj != null) ? obj.ToString().ToUpperInvariant() : "").Contains("RU");
		}
		catch
		{
			return false;
		}
	}

	private void Build(bool dontShowAgain)
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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_0089: 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_00ba: 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_010e: 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_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Expected O, but got Unknown
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Expected O, but got Unknown
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0429: Unknown result type (might be due to invalid IL or missing references)
		//IL_043e: Unknown result type (might be due to invalid IL or missing references)
		//IL_044a: Unknown result type (might be due to invalid IL or missing references)
		//IL_044f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0450: Unknown result type (might be due to invalid IL or missing references)
		//IL_0457: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0463: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0511: Unknown result type (might be due to invalid IL or missing references)
		//IL_051b: Expected O, but got Unknown
		//IL_0545: Unknown result type (might be due to invalid IL or missing references)
		//IL_054a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0582: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0601: Unknown result type (might be due to invalid IL or missing references)
		//IL_0614: Unknown result type (might be due to invalid IL or missing references)
		//IL_062a: Unknown result type (might be due to invalid IL or missing references)
		//IL_064a: Unknown result type (might be due to invalid IL or missing references)
		//IL_066b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0670: Unknown result type (might be due to invalid IL or missing references)
		//IL_0688: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fe: Expected O, but got Unknown
		//IL_0739: Unknown result type (might be due to invalid IL or missing references)
		//IL_0750: Unknown result type (might be due to invalid IL or missing references)
		//IL_0774: Unknown result type (might be due to invalid IL or missing references)
		TMP_FontAsset font = Font();
		Func<char, bool> has = (char c) => !Object.op_Implicit((Object)(object)font) || font.HasCharacter(c, true, true);
		Texts texts = ((Russian() && Texts.Ru.Fits(has)) ? Texts.Ru : Texts.En);
		panel = Child("Card", ((Component)this).transform);
		RectTransform obj = panel;
		RectTransform obj2 = panel;
		RectTransform obj3 = panel;
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(0.5f, 0.5f);
		obj3.pivot = val;
		Vector2 anchorMin = (obj2.anchorMax = val);
		obj.anchorMin = anchorMin;
		panel.anchoredPosition = new Vector2(0f, -40f);
		panel.sizeDelta = new Vector2(560f, 200f);
		Box(panel, new Color(0.1f, 0.11f, 0.13f, 0.97f));
		Outline obj4 = ((Component)panel).gameObject.AddComponent<Outline>();
		((Shadow)obj4).effectColor = new Color(1f, 1f, 1f, 0.14f);
		((Shadow)obj4).effectDistance = new Vector2(1.5f, -1.5f);
		Shadow obj5 = ((Component)panel).gameObject.AddComponent<Shadow>();
		obj5.effectColor = new Color(0f, 0f, 0f, 0.5f);
		obj5.effectDistance = new Vector2(0f, -6f);
		VerticalLayoutGroup obj6 = ((Component)panel).gameObject.AddComponent<VerticalLayoutGroup>();
		((LayoutGroup)obj6).padding = new RectOffset(26, 26, 22, 20);
		((HorizontalOrVerticalLayoutGroup)obj6).spacing = 10f;
		((LayoutGroup)obj6).childAlignment = (TextAnchor)1;
		bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj6).childControlHeight = true);
		((HorizontalOrVerticalLayoutGroup)obj6).childControlWidth = childControlWidth;
		((HorizontalOrVerticalLayoutGroup)obj6).childForceExpandWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj6).childForceExpandHeight = false;
		((Component)panel).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
		RectTransform val3 = Child("Header", (Transform)(object)panel);
		HorizontalLayoutGroup obj7 = ((Component)val3).gameObject.AddComponent<HorizontalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj7).spacing = 14f;
		((LayoutGroup)obj7).childAlignment = (TextAnchor)3;
		childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj7).childControlHeight = true);
		((HorizontalOrVerticalLayoutGroup)obj7).childControlWidth = childControlWidth;
		((HorizontalOrVerticalLayoutGroup)obj7).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj7).childForceExpandHeight = false;
		((LayoutGroup)obj7).padding = new RectOffset(0, 34, 0, 0);
		RectTransform obj8 = Child("Icon", (Transform)(object)val3);
		Image obj9 = ((Component)obj8).gameObject.AddComponent<Image>();
		obj9.sprite = Icon();
		obj9.preserveAspect = true;
		LayoutElement obj10 = ((Component)obj8).gameObject.AddComponent<LayoutElement>();
		float num = (obj10.minHeight = 48f);
		float num3 = (obj10.minWidth = num);
		float preferredWidth = (obj10.preferredHeight = num3);
		obj10.preferredWidth = preferredWidth;
		TextMeshProUGUI obj11 = Label("Title", (Transform)(object)val3, 26f, Color.white, (FontStyles)1, (TextAlignmentOptions)513, font);
		((Component)obj11).gameObject.AddComponent<LayoutElement>().flexibleWidth = 1f;
		((TMP_Text)obj11).text = texts.Title;
		((TMP_Text)Label("Description", (Transform)(object)panel, 19f, new Color(0.86f, 0.88f, 0.92f), (FontStyles)0, (TextAlignmentOptions)513, font)).text = texts.Body;
		((TMP_Text)Label("Link", (Transform)(object)panel, 16f, new Color(1f, 0.72f, 0.45f), (FontStyles)0, (TextAlignmentOptions)513, font)).text = (url ?? "").Trim();
		RectTransform val4 = Child("DontShow", (Transform)(object)panel);
		HorizontalLayoutGroup obj12 = ((Component)val4).gameObject.AddComponent<HorizontalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj12).spacing = 10f;
		((LayoutGroup)obj12).childAlignment = (TextAnchor)3;
		childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj12).childControlHeight = true);
		((HorizontalOrVerticalLayoutGroup)obj12).childControlWidth = childControlWidth;
		((HorizontalOrVerticalLayoutGroup)obj12).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj12).childForceExpandHeight = false;
		RectTransform val5 = Child("Box", (Transform)(object)val4);
		Image targetGraphic = Box(val5, new Color(0.22f, 0.24f, 0.28f));
		LayoutElement obj13 = ((Component)val5).gameObject.AddComponent<LayoutElement>();
		num = (obj13.preferredHeight = 22f);
		num3 = (obj13.minHeight = num);
		preferredWidth = (obj13.preferredWidth = num3);
		obj13.minWidth = preferredWidth;
		RectTransform obj14 = Child("Check", (Transform)(object)val5);
		obj14.anchorMin = new Vector2(0.2f, 0.2f);
		obj14.anchorMax = new Vector2(0.8f, 0.8f);
		anchorMin = (obj14.offsetMax = Vector2.zero);
		obj14.offsetMin = anchorMin;
		Image graphic = Box(obj14, Color32.op_Implicit(Brand));
		toggle = ((Component)val4).gameObject.AddComponent<Toggle>();
		((Selectable)toggle).targetGraphic = (Graphic)(object)targetGraphic;
		toggle.graphic = (Graphic)(object)graphic;
		toggle.isOn = dontShowAgain;
		((TMP_Text)Label("Label", (Transform)(object)val4, 16f, new Color(0.74f, 0.77f, 0.82f), (FontStyles)0, (TextAlignmentOptions)513, font)).text = texts.DontShow;
		RectTransform val6 = Child("Buttons", (Transform)(object)panel);
		HorizontalLayoutGroup obj15 = ((Component)val6).gameObject.AddComponent<HorizontalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj15).spacing = 12f;
		((LayoutGroup)obj15).padding = new RectOffset(0, 0, 4, 0);
		childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj15).childControlHeight = true);
		((HorizontalOrVerticalLayoutGroup)obj15).childControlWidth = childControlWidth;
		childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj15).childForceExpandHeight = true);
		((HorizontalOrVerticalLayoutGroup)obj15).childForceExpandWidth = childControlWidth;
		Button obj16 = MakeButton("Donate", (Transform)(object)val6, Color32.op_Implicit(Brand), texts.Donate, font, OpenLink);
		MakeButton("Close", (Transform)(object)val6, new Color(0.26f, 0.28f, 0.32f), texts.Close, font, Close);
		((Selectable)obj16).interactable = DonatePlugin.ValidUrl(url);
		RectTransform val7 = Child("Close cross", (Transform)(object)panel);
		((Component)val7).gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
		((Vector2)(ref val))..ctor(1f, 1f);
		val7.pivot = val;
		anchorMin = (val7.anchorMax = val);
		val7.anchorMin = anchorMin;
		val7.anchoredPosition = new Vector2(-10f, -10f);
		val7.sizeDelta = new Vector2(34f, 34f);
		Image targetGraphic2 = Box(val7, new Color(1f, 1f, 1f, 0f));
		Button obj17 = ((Component)val7).gameObject.AddComponent<Button>();
		((Selectable)obj17).targetGraphic = (Graphic)(object)targetGraphic2;
		ColorBlock colors = ((Selectable)obj17).colors;
		((ColorBlock)(ref colors)).normalColor = new Color(1f, 1f, 1f, 0f);
		((ColorBlock)(ref colors)).highlightedColor = new Color(1f, 1f, 1f, 0.14f);
		((ColorBlock)(ref colors)).pressedColor = new Color(1f, 1f, 1f, 0.24f);
		((ColorBlock)(ref colors)).selectedColor = ((ColorBlock)(ref colors)).normalColor;
		((Selectable)obj17).colors = colors;
		((UnityEvent)obj17.onClick).AddListener(new UnityAction(Close));
		float[] array = new float[2] { 45f, -45f };
		foreach (float num10 in array)
		{
			RectTransform obj18 = Child("Line", (Transform)(object)val7);
			obj18.sizeDelta = new Vector2(18f, 2.5f);
			((Transform)obj18).localRotation = Quaternion.Euler(0f, 0f, num10);
			Image obj19 = ((Component)obj18).gameObject.AddComponent<Image>();
			((Graphic)obj19).color = new Color(0.8f, 0.82f, 0.86f);
			((Graphic)obj19).raycastTarget = false;
		}
		LayoutRebuilder.ForceRebuildLayoutImmediate(panel);
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)27))
		{
			Close();
		}
		else if (Time.unscaledTime >= nextCheck)
		{
			nextCheck = Time.unscaledTime + 0.25f;
			if (Object.op_Implicit((Object)(object)DonatePlugin.Instance) && !DonatePlugin.Instance.InMainMenu())
			{
				Close();
			}
		}
	}

	private void OpenLink()
	{
		if (DonatePlugin.ValidUrl(url))
		{
			Application.OpenURL(url.Trim());
			DonatePlugin.Log("DonationAlerts page opened by the player.");
			Close();
		}
	}

	internal void Close()
	{
		if (!closing)
		{
			closing = true;
			DonatePlugin.Closed(Object.op_Implicit((Object)(object)toggle) && toggle.isOn);
			EventSystem current = EventSystem.current;
			if (Object.op_Implicit((Object)(object)current) && Object.op_Implicit((Object)(object)current.currentSelectedGameObject) && current.currentSelectedGameObject.transform.IsChildOf(((Component)this).transform))
			{
				current.SetSelectedGameObject((GameObject)null);
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
}

BepInEx/plugins/MarvelPrototype/MarvelPrototype.Ultron.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("3.1.4.0")]
[assembly: AssemblyVersion("3.1.4.0")]
namespace MarvelPrototype.Ultron;

internal static class R
{
	private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

	private static readonly Dictionary<Type, Dictionary<string, MemberInfo>> members = new Dictionary<Type, Dictionary<string, MemberInfo>>();

	private static readonly Dictionary<Type, Dictionary<string, MethodInfo[]>> methods = new Dictionary<Type, Dictionary<string, MethodInfo[]>>();

	private static readonly Dictionary<string, Type> types = new Dictionary<string, Type>();

	internal static Type Type(string name)
	{
		if (types.TryGetValue(name, out var value))
		{
			return value;
		}
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		for (int i = 0; i < assemblies.Length; i++)
		{
			value = assemblies[i].GetType(name, throwOnError: false);
			if (value != null)
			{
				types[name] = value;
				return value;
			}
		}
		return null;
	}

	private static MemberInfo Member(Type t, string name)
	{
		if (!members.TryGetValue(t, out var value))
		{
			value = (members[t] = new Dictionary<string, MemberInfo>());
		}
		if (value.TryGetValue(name, out var value2))
		{
			return value2;
		}
		Type type = t;
		while (type != null && value2 == null)
		{
			value2 = (MemberInfo)(((object)type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) ?? ((object)type.GetProperty(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)));
			type = type.BaseType;
		}
		value[name] = value2;
		return value2;
	}

	internal static object Get(object o, string name)
	{
		Prof.Reflect++;
		if (o == null)
		{
			return null;
		}
		MemberInfo memberInfo = Member((o as Type) ?? o.GetType(), name);
		FieldInfo fieldInfo = memberInfo as FieldInfo;
		if (fieldInfo != null)
		{
			return fieldInfo.GetValue((o is Type) ? null : o);
		}
		PropertyInfo propertyInfo = memberInfo as PropertyInfo;
		if (!(propertyInfo != null) || !propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length != 0)
		{
			return null;
		}
		return propertyInfo.GetValue((o is Type) ? null : o, null);
	}

	internal static T Get<T>(object o, string name, T fallback = default(T))
	{
		object obj = Get(o, name);
		if (!(obj is T))
		{
			return fallback;
		}
		return (T)obj;
	}

	internal static bool Set(object o, string name, object value)
	{
		if (o == null)
		{
			return false;
		}
		MemberInfo memberInfo = Member((o as Type) ?? o.GetType(), name);
		FieldInfo fieldInfo = memberInfo as FieldInfo;
		if (fieldInfo != null && !fieldInfo.IsInitOnly)
		{
			fieldInfo.SetValue((o is Type) ? null : o, value);
			return true;
		}
		PropertyInfo propertyInfo = memberInfo as PropertyInfo;
		if (propertyInfo != null && propertyInfo.CanWrite)
		{
			propertyInfo.SetValue((o is Type) ? null : o, value, null);
			return true;
		}
		return false;
	}

	internal static MethodInfo Method(Type type, string name, int count = -1)
	{
		if (type == null)
		{
			return null;
		}
		if (!methods.TryGetValue(type, out var value))
		{
			value = (methods[type] = new Dictionary<string, MethodInfo[]>());
		}
		if (!value.TryGetValue(name, out var value2))
		{
			value2 = (value[name] = (from m in type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
				where m.Name == name
				select m).ToArray());
		}
		for (int num = 0; num < value2.Length; num++)
		{
			if (count < 0 || value2[num].GetParameters().Length == count)
			{
				return value2[num];
			}
		}
		return null;
	}

	internal static object Call(object o, string name, params object[] args)
	{
		if (o == null)
		{
			return null;
		}
		MethodInfo methodInfo = Method((o as Type) ?? o.GetType(), name, args.Length);
		if (!(methodInfo == null))
		{
			return methodInfo.Invoke((o is Type) ? null : o, args);
		}
		return null;
	}

	internal static bool Any(object o)
	{
		if (!(o is IEnumerable enumerable))
		{
			return false;
		}
		IEnumerator enumerator = enumerable.GetEnumerator();
		try
		{
			return enumerator.MoveNext();
		}
		finally
		{
			IDisposable disposable = enumerator as IDisposable;
			if (disposable != null)
			{
				disposable.Dispose();
			}
		}
	}
}
internal static class Log
{
	private static readonly HashSet<string> warned = new HashSet<string>();

	private static readonly Dictionary<string, float> throttle = new Dictionary<string, float>();

	internal static ManualLogSource Source;

	internal static bool Verbose;

	internal static int Errors;

	internal static void Info(string s)
	{
		if (Source != null)
		{
			Source.LogInfo((object)s);
		}
	}

	internal static void Debug(string s)
	{
		if (Verbose && Source != null)
		{
			Source.LogInfo((object)s);
		}
	}

	internal static void Error(string s)
	{
		Errors++;
		if (Source != null)
		{
			Source.LogError((object)s);
		}
	}

	internal static void WarnOnce(string key, string s)
	{
		if (warned.Add(key) && Source != null)
		{
			Source.LogWarning((object)s);
		}
	}

	internal static void Throttled(string key, float interval, string s)
	{
		if (!throttle.TryGetValue(key, out var value) || !(Time.unscaledTime < value))
		{
			throttle[key] = Time.unscaledTime + interval;
			Info(s);
		}
	}
}
internal sealed class UUnit
{
	internal readonly Component Unit;

	internal readonly object Data;

	internal readonly object Health;

	internal readonly Rigidbody[] Bodies;

	internal readonly Rigidbody Main;

	internal UltronBody Body;

	private float massCache = -1f;

	private float heightCache = -1f;

	private Collider[] cols;

	private int aliveFrame = -1;

	private bool aliveCached;

	private float teamUntil;

	private int teamCached;

	private static MethodInfo takeDamage;

	private static object[] kinds;

	internal Collider[] Colliders
	{
		get
		{
			if (cols == null && Object.op_Implicit((Object)(object)Unit))
			{
				cols = Unit.GetComponentsInChildren<Collider>(true);
			}
			return (Collider[])(((object)cols) ?? ((object)new Collider[0]));
		}
	}

	internal int Id
	{
		get
		{
			if (!Object.op_Implicit((Object)(object)Unit))
			{
				return 0;
			}
			return ((Object)Unit).GetInstanceID();
		}
	}

	internal bool Alive
	{
		get
		{
			if (!Object.op_Implicit((Object)(object)Unit))
			{
				return false;
			}
			int frameCount = Time.frameCount;
			if (frameCount != aliveFrame)
			{
				aliveCached = Unit.gameObject.activeInHierarchy && !R.Get(Unit, "dead", fallback: false) && !R.Get(Data, "Dead", fallback: false);
				aliveFrame = frameCount;
			}
			return aliveCached;
		}
	}

	internal int Team
	{
		get
		{
			if (Time.time < teamUntil)
			{
				return teamCached;
			}
			object obj = R.Get(Unit, "Team");
			teamCached = ((obj == null) ? (-1) : Convert.ToInt32(obj));
			teamUntil = Time.time + 0.5f;
			return teamCached;
		}
	}

	internal object Blueprint => R.Get(Unit, "unitBlueprint");

	internal Vector3 Position
	{
		get
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Body) && Body.Built)
			{
				return Body.Center;
			}
			if (!Object.op_Implicit((Object)(object)Main))
			{
				return Unit.transform.position;
			}
			return Main.position;
		}
	}

	internal float HealthValue
	{
		get
		{
			return R.Get(Data, "health", 0f);
		}
		set
		{
			R.Set(Data, "health", value);
		}
	}

	internal float MaxHealth
	{
		get
		{
			return Mathf.Max(1f, R.Get(Data, "maxHealth", 100f));
		}
		set
		{
			R.Set(Data, "maxHealth", value);
		}
	}

	internal Transform HeadT => R.Get<Transform>(Data, "head");

	internal Transform TorsoT => R.Get<Transform>(Data, "torso");

	internal float Mass
	{
		get
		{
			if (Object.op_Implicit((Object)(object)Body) && Body.Built)
			{
				return Body.TotalMass;
			}
			if (massCache < 0f)
			{
				float num = 0f;
				Rigidbody[] bodies = Bodies;
				foreach (Rigidbody val in bodies)
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						num += val.mass;
					}
				}
				massCache = Mathf.Max(1f, num);
			}
			return massCache;
		}
	}

	internal float Height
	{
		get
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Body) && Body.Built)
			{
				return Body.Height;
			}
			if (heightCache < 0f)
			{
				Transform headT = HeadT;
				Transform val = R.Get<Transform>(Data, "footLeft");
				Transform val2 = R.Get<Transform>(Data, "footRight");
				if (Object.op_Implicit((Object)(object)headT) && (Object.op_Implicit((Object)(object)val) || Object.op_Implicit((Object)(object)val2)))
				{
					float num = Mathf.Min(Object.op_Implicit((Object)(object)val) ? val.position.y : float.MaxValue, Object.op_Implicit((Object)(object)val2) ? val2.position.y : float.MaxValue);
					heightCache = Mathf.Clamp(headT.position.y - num + 0.25f, 0.3f, 200f);
					return heightCache;
				}
				float num2 = float.MaxValue;
				float num3 = float.MinValue;
				Collider[] componentsInChildren = Unit.GetComponentsInChildren<Collider>(true);
				foreach (Collider val3 in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)val3) && val3.enabled)
					{
						Bounds bounds = val3.bounds;
						num2 = Mathf.Min(num2, ((Bounds)(ref bounds)).min.y);
						num3 = Mathf.Max(num3, ((Bounds)(ref bounds)).max.y);
					}
				}
				heightCache = ((num3 > num2) ? Mathf.Clamp(num3 - num2, 0.3f, 200f) : 1.7f);
			}
			return heightCache;
		}
	}

	internal Vector3 Chest
	{
		get
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Body) && Body.Built)
			{
				return Body.ChestPoint;
			}
			Transform torsoT = TorsoT;
			if (!Object.op_Implicit((Object)(object)torsoT))
			{
				return Position + Vector3.up * 0.4f;
			}
			return torsoT.position;
		}
	}

	internal bool Colossal
	{
		get
		{
			MonoBehaviour[] components = Unit.GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val in components)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					switch (((object)val).GetType().Name)
					{
					case "GalactusBody":
					case "GalactusController":
					case "GalactusSetup":
						return true;
					}
				}
			}
			return Height > 4.5f;
		}
	}

	internal UUnit(Component unit)
	{
		Unit = unit;
		Data = R.Get(unit, "data");
		Health = R.Get(Data, "healthHandler");
		Bodies = unit.GetComponentsInChildren<Rigidbody>(true);
		Main = R.Get<Rigidbody>(Data, "mainRig") ?? R.Get<Rigidbody>(Data, "hip");
	}

	internal void Invalidate()
	{
		aliveFrame = -1;
	}

	internal void Damage(float amount, Vector3 direction, UUnit source, int damageType, string tag = null)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		if (Alive && !(amount <= 0f) && Health != null)
		{
			if (tag != null)
			{
				float healthValue = HealthValue;
				Diag.Count("hits:" + tag);
				DamageTagged(amount, direction, source, damageType);
				Diag.Add("dmg:" + tag, Mathf.Max(0f, healthValue - HealthValue));
			}
			else
			{
				DamageTagged(amount, direction, source, damageType);
			}
		}
	}

	private void DamageTagged(float amount, Vector3 direction, UUnit source, int damageType)
	{
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		if (takeDamage == null)
		{
			takeDamage = R.Method(Health.GetType(), "TakeDamage", 4);
			if (takeDamage == null)
			{
				Log.WarnOnce("damage", "TABS HealthHandler.TakeDamage(float,Vector3,Unit,DamageType) not found.");
				return;
			}
			Type parameterType = takeDamage.GetParameters()[3].ParameterType;
			kinds = new object[4];
			for (int i = 0; i < 4; i++)
			{
				kinds[i] = Enum.ToObject(parameterType, i);
			}
		}
		try
		{
			takeDamage.Invoke(Health, new object[4]
			{
				amount,
				direction,
				source?.Unit,
				kinds[Mathf.Clamp(damageType, 0, 3)]
			});
			Invalidate();
		}
		catch (Exception ex)
		{
			Log.WarnOnce("damage_throw", "TakeDamage threw: " + ex.GetBaseException().Message);
		}
	}

	internal void Push(Vector3 velocity, float cap)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		velocity = Vector3.ClampMagnitude(velocity, cap);
		if (Object.op_Implicit((Object)(object)Body) && Body.Built)
		{
			Body.Knock(velocity);
			return;
		}
		Rigidbody[] bodies = Bodies;
		foreach (Rigidbody val in bodies)
		{
			if (Object.op_Implicit((Object)(object)val) && !val.isKinematic)
			{
				val.AddForce(velocity, (ForceMode)2);
			}
		}
	}
}
internal static class UWorld
{
	internal static Type UnitType;

	internal static readonly List<UUnit> Units = new List<UUnit>();

	private static readonly Dictionary<int, UUnit> cache = new Dictionary<int, UUnit>();

	private static MethodInfo service;

	private static float nextScan;

	private static float nextFull;

	private static int stateFrame = -1;

	private static int stateCached = -1;

	private static readonly List<int> dead = new List<int>();

	private static readonly RaycastHit[] buf = (RaycastHit[])(object)new RaycastHit[32];

	private static readonly Collider[] overlap = (Collider[])(object)new Collider[96];

	internal static int State
	{
		get
		{
			if (service == null)
			{
				return -1;
			}
			int frameCount = Time.frameCount;
			if (frameCount == stateFrame)
			{
				return stateCached;
			}
			try
			{
				object obj = R.Get(service.Invoke(null, null), "GameState");
				stateCached = ((obj == null) ? (-1) : Convert.ToInt32(obj));
			}
			catch
			{
				stateCached = -1;
			}
			stateFrame = frameCount;
			return stateCached;
		}
	}

	internal static bool InBattle => State == 1;

	internal static bool Ready()
	{
		UnitType = R.Type("Landfall.TABS.Unit");
		if (UnitType == null)
		{
			return false;
		}
		if (service == null)
		{
			Type type = R.Type("ServiceLocator");
			Type type2 = R.Type("Landfall.TABS.GameState.GameStateManager");
			if (type != null && type2 != null)
			{
				MethodInfo methodInfo = type.GetMethods(BindingFlags.Static | BindingFlags.Public).FirstOrDefault((MethodInfo x) => x.Name == "GetService" && x.IsGenericMethodDefinition && x.GetParameters().Length == 0);
				if (methodInfo != null)
				{
					service = methodInfo.MakeGenericMethod(type2);
				}
			}
		}
		return service != null;
	}

	internal static UUnit Get(Component c)
	{
		if (!Object.op_Implicit((Object)(object)c) || UnitType == null)
		{
			return null;
		}
		Component val = (UnitType.IsInstanceOfType(c) ? c : c.GetComponentInParent(UnitType));
		if (!Object.op_Implicit((Object)(object)val))
		{
			return null;
		}
		int instanceID = ((Object)val).GetInstanceID();
		if (cache.TryGetValue(instanceID, out var value) && Object.op_Implicit((Object)(object)value.Unit))
		{
			return value;
		}
		if (R.Get(val, "data") == null)
		{
			return null;
		}
		value = new UUnit(val);
		cache[instanceID] = value;
		return value;
	}

	internal static UUnit Register(Component unit)
	{
		UUnit uUnit = Get(unit);
		if (uUnit != null && uUnit.Alive && !Units.Contains(uUnit))
		{
			Units.Add(uUnit);
		}
		return uUnit;
	}

	internal static void Tick()
	{
		if (Time.unscaledTime < nextScan)
		{
			return;
		}
		nextScan = Time.unscaledTime + 0.25f;
		if (Time.unscaledTime >= nextFull)
		{
			nextFull = Time.unscaledTime + 2f;
			Object[] array = Object.FindObjectsOfType(UnitType);
			foreach (Object obj in array)
			{
				Get((Component)(object)((obj is Component) ? obj : null));
			}
		}
		Units.Clear();
		dead.Clear();
		foreach (KeyValuePair<int, UUnit> item in cache)
		{
			if (!Object.op_Implicit((Object)(object)item.Value.Unit))
			{
				dead.Add(item.Key);
			}
			else if (item.Value.Alive)
			{
				Units.Add(item.Value);
			}
		}
		foreach (int item2 in dead)
		{
			cache.Remove(item2);
		}
	}

	internal static void Clear()
	{
		Units.Clear();
		cache.Clear();
	}

	private static int Sorted(Vector3 o, Vector3 d, float dist, float radius)
	{
		//IL_0019: 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_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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_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)
		int num = ((radius > 0f) ? Physics.SphereCastNonAlloc(o, radius, d, buf, dist, -1, (QueryTriggerInteraction)1) : Physics.RaycastNonAlloc(o, d, buf, dist, -1, (QueryTriggerInteraction)1));
		for (int i = 1; i < num; i++)
		{
			RaycastHit val = buf[i];
			int num2 = i - 1;
			while (num2 >= 0 && ((RaycastHit)(ref buf[num2])).distance > ((RaycastHit)(ref val)).distance)
			{
				buf[num2 + 1] = buf[num2];
				num2--;
			}
			buf[num2 + 1] = val;
		}
		return num;
	}

	internal static bool IsScenery(Collider c)
	{
		if (!Object.op_Implicit((Object)(object)c) || c.isTrigger)
		{
			return false;
		}
		if ((Object)(object)((Component)c).GetComponentInParent(UnitType) != (Object)null)
		{
			return false;
		}
		if (Object.op_Implicit((Object)(object)((Component)c).GetComponentInParent<UltronFxTag>()))
		{
			return false;
		}
		Rigidbody attachedRigidbody = c.attachedRigidbody;
		if (!((Object)(object)attachedRigidbody == (Object)null))
		{
			if (attachedRigidbody.isKinematic && (Object)(object)((Component)attachedRigidbody).GetComponentInParent(UnitType) == (Object)null)
			{
				return attachedRigidbody.mass > 50f;
			}
			return false;
		}
		return true;
	}

	internal static bool Ground(Vector3 p, float up, float down, out RaycastHit hit)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: 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)
		int num = Sorted(p + Vector3.up * up, Vector3.down, up + down, 0f);
		for (int i = 0; i < num; i++)
		{
			if (IsScenery(((RaycastHit)(ref buf[i])).collider) && ((RaycastHit)(ref buf[i])).normal.y > 0.35f)
			{
				hit = buf[i];
				return true;
			}
		}
		hit = default(RaycastHit);
		return false;
	}

	internal static bool Blocked(Vector3 a, Vector3 b, float radius, out RaycastHit hit)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = b - a;
		float magnitude = ((Vector3)(ref val)).magnitude;
		hit = default(RaycastHit);
		if (magnitude < 0.01f)
		{
			return false;
		}
		int num = Sorted(a, val / magnitude, magnitude, radius);
		for (int i = 0; i < num; i++)
		{
			if (IsScenery(((RaycastHit)(ref buf[i])).collider) && ((RaycastHit)(ref buf[i])).distance > 0f)
			{
				hit = buf[i];
				return true;
			}
		}
		return false;
	}

	internal static bool Finite(Vector3 v)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0034: 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)
		if (!float.IsNaN(v.x) && !float.IsNaN(v.y) && !float.IsNaN(v.z) && !float.IsInfinity(v.x) && !float.IsInfinity(v.y))
		{
			return !float.IsInfinity(v.z);
		}
		return false;
	}

	internal static Vector3 Flat(Vector3 v)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		v.y = 0f;
		return v;
	}

	internal static int UnitsIn(Vector3 c, float r, List<UUnit> into)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		into.Clear();
		int num = Physics.OverlapSphereNonAlloc(c, r, overlap, -1, (QueryTriggerInteraction)1);
		for (int i = 0; i < num; i++)
		{
			UUnit uUnit = Get((Component)(object)overlap[i]);
			if (uUnit != null && !into.Contains(uUnit))
			{
				into.Add(uUnit);
			}
		}
		return into.Count;
	}

	internal static int UnitsAlong(Vector3 a, Vector3 b, float r, List<UUnit> into)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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)
		into.Clear();
		Vector3 val = b - a;
		float magnitude = ((Vector3)(ref val)).magnitude;
		if (magnitude < 0.01f)
		{
			return UnitsIn(a, r, into);
		}
		int num = Physics.SphereCastNonAlloc(a, r, val / magnitude, buf, magnitude, -1, (QueryTriggerInteraction)1);
		for (int i = 0; i < num; i++)
		{
			UUnit uUnit = Get((Component)(object)((RaycastHit)(ref buf[i])).collider);
			if (uUnit != null && !into.Contains(uUnit))
			{
				into.Add(uUnit);
			}
		}
		num = Physics.OverlapSphereNonAlloc(a, r, overlap, -1, (QueryTriggerInteraction)1);
		for (int j = 0; j < num; j++)
		{
			UUnit uUnit2 = Get((Component)(object)overlap[j]);
			if (uUnit2 != null && !into.Contains(uUnit2))
			{
				into.Add(uUnit2);
			}
		}
		return into.Count;
	}
}
internal static class Diag
{
	internal static readonly Dictionary<string, int> Counts = new Dictionary<string, int>();

	internal static float MaxAltitude;

	internal static readonly Dictionary<string, float> Sums = new Dictionary<string, float>();

	internal static void Count(string k)
	{
		Counts.TryGetValue(k, out var value);
		Counts[k] = value + 1;
	}

	internal static void Add(string k, float v)
	{
		Sums.TryGetValue(k, out var value);
		Sums[k] = value + v;
	}

	internal static void Reset()
	{
		Counts.Clear();
		Sums.Clear();
		MaxAltitude = 0f;
	}
}
internal static class Prof
{
	internal static readonly string[] Names = new string[6] { "ai", "bodyPhysics", "bodyPose", "plugin", "bolts", "debrisFx" };

	internal static readonly long[] Ticks = new long[6];

	private static readonly long[] start = new long[6];

	internal static int Reflect;

	internal static bool PauseAI;

	internal static bool HideSkins;

	internal static bool NoHitboxes;

	internal static void B(int i)
	{
		start[i] = Stopwatch.GetTimestamp();
	}

	internal static void E(int i)
	{
		Ticks[i] += Stopwatch.GetTimestamp() - start[i];
	}

	internal static void Reset()
	{
		for (int i = 0; i < Ticks.Length; i++)
		{
			Ticks[i] = 0L;
		}
		Reflect = 0;
	}
}
internal sealed class UltronFxTag : MonoBehaviour
{
}
internal static class UltronAssets
{
	internal sealed class Clip
	{
		internal string Name;

		internal float Fps;

		internal Vector3[] Hips;

		internal Quaternion[][] Rot;

		internal float Length => (float)Rot.Length / Fps;
	}

	internal sealed class Fragment
	{
		internal string Name;

		internal int Bone;

		internal Mesh Mesh;

		internal Bounds Box;
	}

	internal static string[] Names;

	internal static int[] Parents;

	internal static Vector3[] RestPos;

	internal static Quaternion[] RestRot;

	internal static Vector3[] CapHead;

	internal static Vector3[] CapTail;

	internal static float[] CapRadius;

	internal static Quaternion[] Mean;

	internal static Mesh Mesh;

	internal static Material Primary;

	internal static Material Drone;

	internal static Clip Walk;

	internal static Clip Run;

	internal static int TipBone = -1;

	internal static Vector3 TipLocal;

	internal static Fragment[] Fragments;

	internal static Fragment[] DroneFragments;

	internal const float ModelHeight = 1.9f;

	private static Texture2D baseTex;

	private static Texture2D glowTex;

	private static bool failed;

	private static Sprite icon;

	internal static int Bone(string n)
	{
		for (int i = 0; i < Names.Length; i++)
		{
			if (Names[i] == n)
			{
				return i;
			}
		}
		return -1;
	}

	internal static bool Ensure()
	{
		if (Object.op_Implicit((Object)(object)Mesh))
		{
			return true;
		}
		if (failed)
		{
			return false;
		}
		try
		{
			Load();
			return true;
		}
		catch (Exception ex)
		{
			Log.Error("Ultron assets failed to load: " + ex);
			Release();
			failed = true;
			return false;
		}
	}

	internal static byte[] Bytes(string name)
	{
		using Stream stream = typeof(UltronAssets).Assembly.GetManifestResourceStream("MarvelPrototype.Ultron." + name);
		if (stream == null)
		{
			throw new FileNotFoundException("Embedded resource missing: " + name);
		}
		byte[] array = new byte[stream.Length];
		int num;
		for (int i = 0; i < array.Length; i += num)
		{
			num = stream.Read(array, i, array.Length - i);
			if (num <= 0)
			{
				break;
			}
		}
		return array;
	}

	private static string Str(BinaryReader r)
	{
		int num = r.ReadInt32();
		if (num < 0 || num > 256)
		{
			throw new InvalidDataException("ULT1 string");
		}
		return Encoding.UTF8.GetString(r.ReadBytes(num));
	}

	private static Vector3 V3(BinaryReader r)
	{
		//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)
		Vector3 val = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
		if (!UWorld.Finite(val))
		{
			throw new InvalidDataException("ULT1 nonfinite");
		}
		return val;
	}

	private static Quaternion Q(BinaryReader r)
	{
		//IL_001f: 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_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		Quaternion val = default(Quaternion);
		((Quaternion)(ref val))..ctor(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
		float num = Mathf.Sqrt(val.x * val.x + val.y * val.y + val.z * val.z + val.w * val.w);
		if (float.IsNaN(num) || num < 0.5f)
		{
			throw new InvalidDataException("ULT1 quaternion");
		}
		return new Quaternion(val.x / num, val.y / num, val.z / num, val.w / num);
	}

	private static void Load()
	{
		//IL_00e9: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0306: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Expected O, but got Unknown
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: Unknown result type (might be due to invalid IL or missing references)
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_0516: Unknown result type (might be due to invalid IL or missing references)
		//IL_051b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0452: Unknown result type (might be due to invalid IL or missing references)
		//IL_0457: Unknown result type (might be due to invalid IL or missing references)
		//IL_047e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0483: Unknown result type (might be due to invalid IL or missing references)
		//IL_0545: Unknown result type (might be due to invalid IL or missing references)
		//IL_0547: Unknown result type (might be due to invalid IL or missing references)
		//IL_060d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0612: Unknown result type (might be due to invalid IL or missing references)
		//IL_0615: Unknown result type (might be due to invalid IL or missing references)
		//IL_061a: Unknown result type (might be due to invalid IL or missing references)
		//IL_061e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0620: Unknown result type (might be due to invalid IL or missing references)
		//IL_0622: Unknown result type (might be due to invalid IL or missing references)
		//IL_062c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0631: Unknown result type (might be due to invalid IL or missing references)
		//IL_0633: Unknown result type (might be due to invalid IL or missing references)
		//IL_0635: Unknown result type (might be due to invalid IL or missing references)
		//IL_063a: Unknown result type (might be due to invalid IL or missing references)
		//IL_063f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0816: Unknown result type (might be due to invalid IL or missing references)
		//IL_081b: Unknown result type (might be due to invalid IL or missing references)
		//IL_082b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0830: Unknown result type (might be due to invalid IL or missing references)
		//IL_095a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0987: Unknown result type (might be due to invalid IL or missing references)
		//IL_084a: Unknown result type (might be due to invalid IL or missing references)
		//IL_084f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0851: Unknown result type (might be due to invalid IL or missing references)
		//IL_0853: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_08d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_08dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_08e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_068a: Unknown result type (might be due to invalid IL or missing references)
		//IL_068f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0699: Unknown result type (might be due to invalid IL or missing references)
		//IL_069e: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0888: Unknown result type (might be due to invalid IL or missing references)
		//IL_088a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0891: Unknown result type (might be due to invalid IL or missing references)
		//IL_0898: Unknown result type (might be due to invalid IL or missing references)
		//IL_089f: Unknown result type (might be due to invalid IL or missing references)
		//IL_08a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0863: Unknown result type (might be due to invalid IL or missing references)
		//IL_086b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0873: Unknown result type (might be due to invalid IL or missing references)
		//IL_087b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0722: Unknown result type (might be due to invalid IL or missing references)
		//IL_0727: Unknown result type (might be due to invalid IL or missing references)
		//IL_073e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0746: Unknown result type (might be due to invalid IL or missing references)
		//IL_074e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0756: Unknown result type (might be due to invalid IL or missing references)
		//IL_0763: Expected O, but got Unknown
		using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(Bytes("UltronRig.bin"))))
		{
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "ULT3")
			{
				throw new InvalidDataException("ULT3 header");
			}
			int num = binaryReader.ReadInt32();
			if (num < 18 || num > 64)
			{
				throw new InvalidDataException("ULT1 bones");
			}
			Names = new string[num];
			Parents = new int[num];
			RestPos = (Vector3[])(object)new Vector3[num];
			RestRot = (Quaternion[])(object)new Quaternion[num];
			CapHead = (Vector3[])(object)new Vector3[num];
			CapTail = (Vector3[])(object)new Vector3[num];
			CapRadius = new float[num];
			for (int i = 0; i < num; i++)
			{
				Names[i] = Str(binaryReader);
				Parents[i] = binaryReader.ReadInt32();
				if (Parents[i] >= i)
				{
					throw new InvalidDataException("ULT1 bone order");
				}
				RestPos[i] = V3(binaryReader);
				RestRot[i] = Q(binaryReader);
				CapHead[i] = V3(binaryReader);
				CapTail[i] = V3(binaryReader);
				CapRadius[i] = binaryReader.ReadSingle();
			}
			int num2 = binaryReader.ReadInt32();
			if (num2 < 3 || num2 > 65000)
			{
				throw new InvalidDataException("ULT1 vertices");
			}
			Vector3[] array = (Vector3[])(object)new Vector3[num2];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num2];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num2];
			BoneWeight[] array4 = (BoneWeight[])(object)new BoneWeight[num2];
			for (int j = 0; j < num2; j++)
			{
				array[j] = V3(binaryReader);
				array2[j] = V3(binaryReader);
				array3[j] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
				int num3 = binaryReader.ReadByte();
				int num4 = binaryReader.ReadByte();
				int num5 = binaryReader.ReadByte();
				int num6 = binaryReader.ReadByte();
				if (num3 >= num || num4 >= num || num5 >= num || num6 >= num)
				{
					throw new InvalidDataException("ULT1 bone index");
				}
				int num7 = j;
				BoneWeight val = default(BoneWeight);
				((BoneWeight)(ref val)).boneIndex0 = num3;
				((BoneWeight)(ref val)).boneIndex1 = num4;
				((BoneWeight)(ref val)).boneIndex2 = num5;
				((BoneWeight)(ref val)).boneIndex3 = num6;
				((BoneWeight)(ref val)).weight0 = binaryReader.ReadSingle();
				((BoneWeight)(ref val)).weight1 = binaryReader.ReadSingle();
				((BoneWeight)(ref val)).weight2 = binaryReader.ReadSingle();
				((BoneWeight)(ref val)).weight3 = binaryReader.ReadSingle();
				array4[num7] = val;
			}
			int num8 = binaryReader.ReadInt32();
			if (num8 < 3 || num8 % 3 != 0)
			{
				throw new InvalidDataException("ULT1 indices");
			}
			int[] array5 = new int[num8];
			for (int k = 0; k < num8; k++)
			{
				array5[k] = binaryReader.ReadUInt16();
				if (array5[k] >= num2)
				{
					throw new InvalidDataException("ULT1 index range");
				}
			}
			Matrix4x4[] array6 = (Matrix4x4[])(object)new Matrix4x4[num];
			Matrix4x4[] array7 = (Matrix4x4[])(object)new Matrix4x4[num];
			for (int l = 0; l < num; l++)
			{
				Matrix4x4 val2 = Matrix4x4.TRS(RestPos[l], RestRot[l], Vector3.one);
				array6[l] = ((Parents[l] < 0) ? val2 : (array6[Parents[l]] * val2));
				array7[l] = ((Matrix4x4)(ref array6[l])).inverse;
			}
			Mesh = new Mesh
			{
				name = "Marvel_Ultron"
			};
			Mesh.vertices = array;
			Mesh.normals = array2;
			Mesh.uv = array3;
			Mesh.triangles = array5;
			Mesh.boneWeights = array4;
			Mesh.bindposes = array7;
			Mesh.RecalculateTangents();
			Mesh.RecalculateBounds();
			int num9 = binaryReader.ReadInt32();
			for (int m = 0; m < num9; m++)
			{
				Clip clip = new Clip
				{
					Name = Str(binaryReader)
				};
				int num10 = binaryReader.ReadInt32();
				clip.Fps = binaryReader.ReadSingle();
				if (num10 < 2 || num10 > 2000 || clip.Fps <= 0f)
				{
					throw new InvalidDataException("ULT1 clip");
				}
				clip.Hips = (Vector3[])(object)new Vector3[num10];
				clip.Rot = new Quaternion[num10][];
				for (int n = 0; n < num10; n++)
				{
					clip.Hips[n] = V3(binaryReader);
					clip.Rot[n] = (Quaternion[])(object)new Quaternion[num];
					for (int num11 = 0; num11 < num; num11++)
					{
						clip.Rot[n][num11] = Q(binaryReader);
					}
				}
				if (clip.Name == "Walking")
				{
					Walk = clip;
				}
				else if (clip.Name == "Running")
				{
					Run = clip;
				}
			}
			int num12 = binaryReader.ReadInt32();
			if (num12 < 0 || num12 > 16)
			{
				throw new InvalidDataException("ULT2 anchors");
			}
			for (int num13 = 0; num13 < num12; num13++)
			{
				string text = Str(binaryReader);
				int num14 = binaryReader.ReadInt32();
				Vector3 tipLocal = V3(binaryReader);
				if (num14 < 0 || num14 >= num)
				{
					throw new InvalidDataException("ULT2 anchor bone");
				}
				if (text == "IndexTip")
				{
					TipBone = num14;
					TipLocal = tipLocal;
				}
			}
			int num15 = binaryReader.ReadInt32();
			if (num15 < 1 || num15 > 4)
			{
				throw new InvalidDataException("ULT3 piece sets");
			}
			for (int num16 = 0; num16 < num15; num16++)
			{
				string text2 = Str(binaryReader);
				int num17 = binaryReader.ReadInt32();
				if (num17 < 1 || num17 > 32)
				{
					throw new InvalidDataException("ULT3 fragments");
				}
				Fragment[] array8 = new Fragment[num17];
				if (text2 == "drone")
				{
					DroneFragments = array8;
				}
				else
				{
					Fragments = array8;
				}
				for (int num18 = 0; num18 < num17; num18++)
				{
					Fragment fragment = new Fragment
					{
						Name = Str(binaryReader),
						Bone = binaryReader.ReadInt32()
					};
					if (fragment.Bone < 0 || fragment.Bone >= num)
					{
						throw new InvalidDataException("ULT2 fragment bone");
					}
					Vector3 val3 = V3(binaryReader);
					Vector3 val4 = V3(binaryReader);
					fragment.Box = new Bounds((val3 + val4) * 0.5f, val4 - val3);
					int num19 = binaryReader.ReadInt32();
					if (num19 < 3 || num19 > 65000)
					{
						throw new InvalidDataException("ULT2 fragment vertices");
					}
					Vector3[] array9 = (Vector3[])(object)new Vector3[num19];
					Vector3[] array10 = (Vector3[])(object)new Vector3[num19];
					Vector2[] array11 = (Vector2[])(object)new Vector2[num19];
					for (int num20 = 0; num20 < num19; num20++)
					{
						array9[num20] = V3(binaryReader);
						array10[num20] = V3(binaryReader);
						array11[num20] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
					}
					int num21 = binaryReader.ReadInt32();
					if (num21 < 3 || num21 % 3 != 0)
					{
						throw new InvalidDataException("ULT2 fragment indices");
					}
					int[] array12 = new int[num21];
					for (int num22 = 0; num22 < num21; num22++)
					{
						array12[num22] = binaryReader.ReadUInt16();
						if (array12[num22] >= num19)
						{
							throw new InvalidDataException("ULT2 fragment index");
						}
					}
					fragment.Mesh = new Mesh
					{
						name = "Marvel_Ultron_Piece_" + fragment.Name,
						vertices = array9,
						normals = array10,
						uv = array11,
						triangles = array12
					};
					fragment.Mesh.RecalculateBounds();
					array8[num18] = fragment;
				}
			}
			if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
			{
				throw new InvalidDataException("ULT2 trailing bytes");
			}
			if (TipBone < 0 || Fragments == null || DroneFragments == null)
			{
				throw new InvalidDataException("ULT3 needs IndexTip and both piece sets");
			}
			if (Walk == null || Run == null)
			{
				throw new InvalidDataException("ULT1 needs Walking and Running");
			}
		}
		Mean = (Quaternion[])(object)new Quaternion[Names.Length];
		for (int num23 = 0; num23 < Names.Length; num23++)
		{
			Vector4 val5 = Vector4.zero;
			Quaternion val6 = Walk.Rot[0][num23];
			Quaternion[][] rot = Walk.Rot;
			for (int num24 = 0; num24 < rot.Length; num24++)
			{
				Quaternion val7 = rot[num24][num23];
				if (Quaternion.Dot(val7, val6) < 0f)
				{
					((Quaternion)(ref val7))..ctor(0f - val7.x, 0f - val7.y, 0f - val7.z, 0f - val7.w);
				}
				val5 += new Vector4(val7.x, val7.y, val7.z, val7.w);
			}
			((Vector4)(ref val5)).Normalize();
			Mean[num23] = new Quaternion(val5.x, val5.y, val5.z, val5.w);
		}
		Shader obj = Shader.Find("Standard");
		if (!Object.op_Implicit((Object)(object)obj))
		{
			throw new InvalidOperationException("Standard shader unavailable");
		}
		baseTex = Tex("UltronBase.jpg", linear: false);
		glowTex = Tex("UltronGlow.png", linear: false);
		Primary = Make(obj, "Marvel_Ultron_Primary", new Color(1.12f, 1.12f, 1.15f), 0.3f, 0.58f);
		Drone = Make(obj, "Marvel_Ultron_Drone", new Color(0.5f, 0.5f, 0.54f), 0.35f, 0.35f);
		Log.Info("Ultron assets: " + Mesh.vertexCount + " vertices, " + Mesh.triangles.Length / 3 + " triangles, " + Names.Length + " bones, Walking " + Walk.Length.ToString("0.000") + " s, Running " + Run.Length.ToString("0.000") + " s, base " + ((Texture)baseTex).width + " px, glow " + ((Texture)glowTex).width + " px; 2 shared materials; " + Fragments.Length + "/" + DroneFragments.Length + " break-apart pieces with closed joint caps; fingertip on " + Names[TipBone] + ".");
	}

	private static Material Make(Shader s, string name, Color c, float metallic, float gloss)
	{
		//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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: 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_004e: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Expected O, but got Unknown
		Material val = new Material(s)
		{
			name = name,
			mainTexture = (Texture)(object)baseTex,
			color = c
		};
		val.SetFloat("_Metallic", metallic);
		val.SetFloat("_Glossiness", gloss);
		val.SetTexture("_EmissionMap", (Texture)(object)glowTex);
		val.SetColor("_EmissionColor", Color.black);
		val.EnableKeyword("_EMISSION");
		val.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)0;
		return val;
	}

	private static Texture2D Tex(string name, bool linear)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		Texture2D val = new Texture2D(2, 2, (TextureFormat)3, true, linear)
		{
			name = "Marvel_" + name
		};
		if (!ImageConversion.LoadImage(val, Bytes(name), true))
		{
			throw new IOException("Invalid texture " + name);
		}
		((Texture)val).wrapMode = (TextureWrapMode)0;
		((Texture)val).filterMode = (FilterMode)2;
		((Texture)val).anisoLevel = 4;
		return val;
	}

	internal static Sprite Icon()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)icon))
		{
			return icon;
		}
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
		{
			name = "Marvel_UltronIcon"
		};
		if (!ImageConversion.LoadImage(val, Bytes("UltronIcon.png"), true))
		{
			return null;
		}
		icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
		((Object)icon).name = "Marvel_UltronIcon";
		return icon;
	}

	internal static void Release()
	{
		Object[] array = (Object[])(object)new Object[5]
		{
			(Object)Mesh,
			(Object)Primary,
			(Object)Drone,
			(Object)baseTex,
			(Object)glowTex
		};
		foreach (Object val in array)
		{
			if (Object.op_Implicit(val))
			{
				Object.Destroy(val);
			}
		}
		Fragment[][] array2 = new Fragment[2][] { Fragments, DroneFragments };
		foreach (Fragment[] array3 in array2)
		{
			if (array3 == null)
			{
				continue;
			}
			Fragment[] array4 = array3;
			foreach (Fragment fragment in array4)
			{
				if (fragment != null && Object.op_Implicit((Object)(object)fragment.Mesh))
				{
					Object.Destroy((Object)(object)fragment.Mesh);
				}
			}
		}
		Fragments = (DroneFragments = null);
		TipBone = -1;
		Mesh = null;
		Primary = (Drone = null);
		baseTex = (glowTex = null);
		Walk = (Run = null);
		failed = false;
	}
}
internal sealed class UltronBody : MonoBehaviour
{
	private sealed class Part
	{
		internal int Bone;

		internal Rigidbody Body;

		internal CapsuleCollider Shape;

		internal Vector3 PosOffset;

		internal Quaternion RotOffset;

		internal int Parent = -1;
	}

	private struct Pose3
	{
		internal Vector3 position;

		internal Quaternion rotation;
	}

	internal UUnit Self;

	internal bool Primary;

	internal float S;

	internal float Height;

	internal bool Built;

	internal Vector3 Position;

	internal float Heading;

	internal Vector3 Velocity;

	internal float VerticalSpeed;

	internal Vector3 DesiredVelocity;

	internal Vector3 DesiredFacing;

	internal float TurnRate = 300f;

	internal float Accel = 14f;

	internal float FlightAltitude;

	internal bool Frozen;

	private Vector3 knock;

	private bool airMode;

	private float groundY;

	private float fallSpeed;

	internal float ArmWL;

	internal float ArmWR;

	internal float KickW;

	internal float Twist;

	internal float Lean;

	internal float Crouch;

	internal float LegTuck;

	internal Vector3 ArmTL;

	internal Vector3 ArmTR;

	internal Vector3 PoleL;

	internal Vector3 PoleR;

	internal Vector3 KickT;

	internal Vector3? LookAt;

	internal float PointW;

	internal Vector3 PointAt;

	private Transform root;

	private Transform[] bones;

	private SkinnedMeshRenderer skin;

	private Quaternion[] local;

	private MaterialPropertyBlock mpb;

	private int hips;

	private int spine;

	private int spine1;

	private int spine2;

	private int neck;

	private int head;

	private int lSh;

	private int lArm;

	private int lFore;

	private int lHand;

	private int rSh;

	private int rArm;

	private int rFore;

	private int rHand;

	private int lUp;

	private int lLeg;

	private int lFoot;

	private int rUp;

	private int rLeg;

	private int rFoot;

	private int rIndex;

	private Quaternion indexStraight;

	private float phase;

	private float runMix;

	private float amp;

	private float meanHipsY;

	private readonly List<Part> parts = new List<Part>();

	private int[] partOfBone;

	private float totalMass;

	private readonly HashSet<Collider> own = new HashSet<Collider>();

	private Rigidbody[] native;

	private Vector3[] nativePos;

	private Quaternion[] nativeRot;

	private Rigidbody nativeAnchor;

	private bool captured;

	private readonly List<Renderer> hidden = new List<Renderer>();

	private readonly List<Behaviour> disabled = new List<Behaviour>();

	private float nextHide;

	private float glow;

	private float glowTarget;

	private float pulseUntil;

	private float pulseAmount;

	private Color glowColor = new Color(1f, 0.08f, 0.04f);

	private static readonly List<UltronBody> all = new List<UltronBody>();

	internal const float RefMass = 450f;

	private static readonly HashSet<string> nativeDrivers = new HashSet<string>
	{
		"Balance", "AnimationHandler", "StandingHandler", "GravityHandler", "MovementHandler", "RotationHandler", "StepHandler", "FootSupport", "SetAnimationByInput", "DodgeMove",
		"WeaponHandler", "CollisionWeapon", "Holdable", "ProjectileDodgeMove", "KeepUpright", "UnitSpawner", "ConditionalEvent"
	};

	private static readonly string[] partBones = new string[16]
	{
		"Hips", "Spine1", "Spine2", "Head", "LeftArm", "LeftForeArm", "LeftHand", "RightArm", "RightForeArm", "RightHand",
		"LeftUpLeg", "LeftLeg", "LeftFoot", "RightUpLeg", "RightLeg", "RightFoot"
	};

	private static readonly string[] dronePartBones = new string[11]
	{
		"Hips", "Spine2", "Head", "LeftArm", "LeftForeArm", "RightArm", "RightForeArm", "LeftUpLeg", "LeftLeg", "RightUpLeg",
		"RightLeg"
	};

	private readonly List<Joint> joints = new List<Joint>();

	private float limpUntil;

	private bool permanentLimp;

	private bool shatterPending;

	private static readonly RaycastHit[] wallHits = (RaycastHit[])(object)new RaycastHit[16];

	private bool partsOn = true;

	internal bool Flying => airMode;

	internal bool Limp { get; private set; }

	internal float Altitude => Position.y - groundY;

	internal float GroundY => groundY;

	internal static IList<UltronBody> All => all;

	internal float TotalMass => totalMass;

	internal Vector3 Center
	{
		get
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (!Built || bones == null)
			{
				return Position + Vector3.up * S;
			}
			return bones[hips].position;
		}
	}

	internal Vector3 ChestPoint
	{
		get
		{
			//IL_003b: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!Built)
			{
				return Position + Vector3.up * 1.45f * S;
			}
			return bones[spine2].position;
		}
	}

	internal Vector3 HeadPoint
	{
		get
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_005a: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!Built)
			{
				return Position + Vector3.up * 1.7f * S;
			}
			return bones[head].position + Vector3.up * 0.08f * S;
		}
	}

	internal Vector3 Forward => Quaternion.Euler(0f, Heading, 0f) * Vector3.forward;

	internal Vector3 Right => Quaternion.Euler(0f, Heading, 0f) * Vector3.right;

	internal Quaternion Facing => Quaternion.Euler(0f, Heading, 0f);

	internal Vector3 FingerTip
	{
		get
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			if (!Built)
			{
				return Center;
			}
			return bones[UltronAssets.TipBone].TransformPoint(UltronAssets.TipLocal);
		}
	}

	internal Vector3 FingerDir
	{
		get
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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)
			Vector3 val = FingerTip - bones[rIndex].position;
			if (!(((Vector3)(ref val)).sqrMagnitude > 1E-06f))
			{
				return Forward;
			}
			return ((Vector3)(ref val)).normalized;
		}
	}

	internal float Reach => 0.78f * S;

	internal bool Recovered => !Limp;

	internal bool Shattered { get; private set; }

	internal Vector3 BreakVelocity => Velocity + knock + Vector3.up * VerticalSpeed;

	internal float KnockSpeed => ((Vector3)(ref knock)).magnitude;

	internal float GlowLevel => glow;

	internal event Action AfterPose;

	internal Vector3 Shoulder(bool left)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		return bones[left ? lArm : rArm].position;
	}

	internal Vector3 Fist(bool left)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = bones[left ? lHand : rHand].position;
		Vector3 position2 = bones[left ? lFore : rFore].position;
		Vector3 val = position - position2;
		return position + ((Vector3)(ref val)).normalized * 0.085f * S;
	}

	internal Vector3 FootPoint(bool right)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		return bones[right ? rFoot : lFoot].position;
	}

	internal Vector3 Local(Vector3 p)
	{
		//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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		return Position + Facing * (p * S);
	}

	internal void Build(UUnit u, bool primary, float height, Vector3? at = null, float? heading = null)
	{
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: 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_0211: 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_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0371: Unknown result type (might be due to invalid IL or missing references)
		//IL_0426: Unknown result type (might be due to invalid IL or missing references)
		//IL_043a: Unknown result type (might be due to invalid IL or missing references)
		//IL_043f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0477: Unknown result type (might be due to invalid IL or missing references)
		//IL_0481: Expected O, but got Unknown
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0533: Unknown result type (might be due to invalid IL or missing references)
		//IL_0538: Unknown result type (might be due to invalid IL or missing references)
		//IL_053b: Unknown result type (might be due to invalid IL or missing references)
		//IL_052a: Unknown result type (might be due to invalid IL or missing references)
		//IL_051d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0561: Unknown result type (might be due to invalid IL or missing references)
		//IL_0550: Unknown result type (might be due to invalid IL or missing references)
		//IL_0571: Unknown result type (might be due to invalid IL or missing references)
		//IL_057e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0585: Unknown result type (might be due to invalid IL or missing references)
		//IL_058a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0591: Unknown result type (might be due to invalid IL or missing references)
		//IL_0596: Unknown result type (might be due to invalid IL or missing references)
		if (!UltronAssets.Ensure())
		{
			throw new InvalidOperationException("Ultron assets unavailable");
		}
		Self = u;
		Primary = primary;
		Height = height;
		S = height / 1.9f;
		u.Body = this;
		string[] names = UltronAssets.Names;
		Func<string, int> func = delegate(string n)
		{
			int num4 = UltronAssets.Bone(n);
			if (num4 < 0)
			{
				throw new InvalidOperationException("Ultron rig bone missing: " + n);
			}
			return num4;
		};
		hips = func("Hips");
		spine = func("Spine");
		spine1 = func("Spine1");
		spine2 = func("Spine2");
		neck = func("Neck");
		head = func("Head");
		lSh = func("LeftShoulder");
		lArm = func("LeftArm");
		lFore = func("LeftForeArm");
		lHand = func("LeftHand");
		rSh = func("RightShoulder");
		rArm = func("RightArm");
		rFore = func("RightForeArm");
		rHand = func("RightHand");
		rIndex = func("RightIndex");
		lUp = func("LeftUpLeg");
		lLeg = func("LeftLeg");
		lFoot = func("LeftFoot");
		rUp = func("RightUpLeg");
		rLeg = func("RightLeg");
		rFoot = func("RightFoot");
		Pose3 pose = RestWorld(rHand);
		Pose3 pose2 = RestWorld(rFore);
		Quaternion val = Quaternion.Inverse(pose.rotation);
		Vector3 val2 = UltronAssets.RestRot[rIndex] * ((Vector3)(ref UltronAssets.TipLocal)).normalized;
		Vector3 val3 = pose.position - pose2.position;
		Vector3 val4 = val * ((Vector3)(ref val3)).normalized;
		indexStraight = Quaternion.FromToRotation(val2, val4) * UltronAssets.RestRot[rIndex];
		float num = 0f;
		Vector3[] array = UltronAssets.Walk.Hips;
		foreach (Vector3 val5 in array)
		{
			num += val5.y;
		}
		meanHipsY = num / (float)UltronAssets.Walk.Hips.Length;
		root = new GameObject("Marvel_Ultron_View_" + u.Id).transform;
		((Component)root).gameObject.AddComponent<UltronFxTag>();
		root.localScale = Vector3.one * S;
		bones = (Transform[])(object)new Transform[names.Length];
		local = (Quaternion[])(object)new Quaternion[names.Length];
		for (int num3 = 0; num3 < names.Length; num3++)
		{
			Transform transform = new GameObject(names[num3]).transform;
			transform.SetParent((UltronAssets.Parents[num3] < 0) ? root : bones[UltronAssets.Parents[num3]], false);
			transform.localPosition = UltronAssets.RestPos[num3];
			transform.localRotation = UltronAssets.RestRot[num3];
			bones[num3] = transform;
		}
		Transform transform2 = new GameObject("Marvel_Ultron_Skin").transform;
		transform2.SetParent(root, false);
		skin = ((Component)transform2).gameObject.AddComponent<SkinnedMeshRenderer>();
		skin.sharedMesh = UltronAssets.Mesh;
		skin.bones = bones;
		skin.rootBone = bones[hips];
		((Renderer)skin).sharedMaterial = (primary ? UltronAssets.Primary : UltronAssets.Drone);
		skin.updateWhenOffscreen = false;
		skin.localBounds = new Bounds(Vector3.zero, new Vector3(2.4f, 2.6f, 2.4f));
		skin.quality = (SkinQuality)(primary ? 4 : 2);
		if (!primary)
		{
			((Renderer)skin).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)skin).receiveShadows = false;
		}
		mpb = new MaterialPropertyBlock();
		glow = (glowTarget = (primary ? 2.3f : 0.85f));
		ApplyGlow();
		Heading = heading ?? (Mathf.Atan2(u.Unit.transform.forward.x, u.Unit.transform.forward.z) * 57.29578f);
		Vector3 val6 = (Vector3)(((??)at) ?? (Object.op_Implicit((Object)(object)u.Main) ? u.Main.position : u.Unit.transform.position));
		groundY = (UWorld.Ground(val6, 1.5f, 6f, out var hit) ? ((RaycastHit)(ref hit)).point.y : (val6.y - 1f));
		Position = new Vector3(val6.x, groundY, val6.z);
		DesiredFacing = Forward;
		HideNative();
		Capture();
		Pose(0f);
		BuildParts();
		FollowParts(snap: true);
		all.Add(this);
		Built = true;
	}

	private void HideNative()
	{
		Renderer[] componentsInChildren = Self.Unit.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			if (Object.op_Implicit((Object)(object)val) && !val.forceRenderingOff && !Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<UltronFxTag>()))
			{
				val.forceRenderingOff = true;
				hidden.Add(val);
			}
		}
	}

	private void Capture()
	{
		//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_0063: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: 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_00b3: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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)
		if (captured)
		{
			return;
		}
		captured = true;
		native = Self.Bodies;
		nativeAnchor = Self.Main;
		nativePos = (Vector3[])(object)new Vector3[native.Length];
		nativeRot = (Quaternion[])(object)new Quaternion[native.Length];
		Quaternion val = Quaternion.Inverse(Facing);
		for (int i = 0; i < native.Length; i++)
		{
			Rigidbody val2 = native[i];
			if (Object.op_Implicit((Object)(object)val2))
			{
				nativePos[i] = (Object.op_Implicit((Object)(object)nativeAnchor) ? (val * (val2.position - nativeAnchor.position)) : Vector3.zero);
				nativeRot[i] = val * val2.rotation;
				val2.isKinematic = true;
				val2.useGravity = false;
				val2.detectCollisions = false;
				val2.interpolation = (RigidbodyInterpolation)0;
			}
		}
		Behaviour[] componentsInChildren = Self.Unit.GetComponentsInChildren<Behaviour>(true);
		foreach (Behaviour val3 in componentsInChildren)
		{
			if (Object.op_Implicit((Object)(object)val3) && val3.enabled && nativeDrivers.Contains(((object)val3).GetType().Name))
			{
				val3.enabled = false;
				disabled.Add(val3);
			}
		}
	}

	private void CarryNative()
	{
		//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_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		if (!captured || !Object.op_Implicit((Object)(object)nativeAnchor))
		{
			return;
		}
		Quaternion facing = Facing;
		Vector3 val = ((Built && parts.Count > 0) ? parts[0].Body.position : (Position + Vector3.up * 1.05f * S));
		for (int i = 0; i < native.Length; i++)
		{
			Rigidbody val2 = native[i];
			if (Object.op_Implicit((Object)(object)val2))
			{
				if (!val2.isKinematic)
				{
					val2.isKinematic = true;
					val2.useGravity = false;
					val2.detectCollisions = false;
				}
				val2.MovePosition(val + facing * nativePos[i]);
				val2.MoveRotation(facing * nativeRot[i]);
			}
		}
		R.Set(Self.Data, "groundPosition", Position);
	}

	private void BuildParts()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: 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_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0352: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Unknown result type (might be due to invalid IL or missing references)
		//IL_037d: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = Self.Unit.transform;
		float num = Mathf.Max(0.01f, transform.lossyScale.x);
		int layer = (Object.op_Implicit((Object)(object)Self.Main) ? ((Component)Self.Main).gameObject.layer : Self.Unit.gameObject.layer);
		partOfBone = new int[bones.Length];
		for (int i = 0; i < partOfBone.Length; i++)
		{
			partOfBone[i] = -1;
		}
		float num2 = (Primary ? 900f : 380f);
		totalMass = 0f;
		string[] array = (Primary ? partBones : dronePartBones);
		foreach (string text in array)
		{
			int num3 = UltronAssets.Bone(text);
			Vector3 val = UltronAssets.CapHead[num3] * S;
			Vector3 val2 = UltronAssets.CapTail[num3] * S;
			float num4 = Mathf.Clamp(UltronAssets.CapRadius[num3], 0.04f, 0.2f) * S;
			if (text == "Hips")
			{
				num4 = 0.15f * S;
			}
			if (text == "Spine2")
			{
				num4 = 0.18f * S;
			}
			if (text == "Head")
			{
				num4 = 0.1f * S;
			}
			GameObject val3 = new GameObject("Marvel_Ultron_Hit_" + text)
			{
				layer = layer
			};
			val3.transform.SetParent(transform, false);
			Vector3 val4 = val2 - val;
			float num5 = Mathf.Max(((Vector3)(ref val4)).magnitude, 0.05f * S);
			Pose3 pose = RestWorld(num3);
			Vector3 val5 = (val + val2) * 0.5f;
			Quaternion val6 = Quaternion.FromToRotation(Vector3.up, val4 / num5);
			Rigidbody val7 = val3.AddComponent<Rigidbody>();
			val7.isKinematic = true;
			val7.useGravity = false;
			val7.interpolation = (RigidbodyInterpolation)0;
			val7.collisionDetectionMode = (CollisionDetectionMode)0;
			val7.drag = 0.3f;
			val7.angularDrag = 3f;
			val7.maxAngularVelocity = 20f;
			CapsuleCollider val8 = val3.AddComponent<CapsuleCollider>();
			val8.direction = 1;
			val8.radius = num4 / num;
			val8.height = Mathf.Max(num5 + 2f * num4, 2.05f * num4) / num;
			float num6;
			switch (text)
			{
			default:
				num6 = (text.Contains("UpLeg") ? 0.07f : (text.Contains("Leg") ? 0.055f : 0.035f));
				break;
			case "Head":
				num6 = 0.06f;
				break;
			case "Hips":
			case "Spine1":
			case "Spine2":
				num6 = 0.13f;
				break;
			}
			float num7 = num6;
			val7.mass = num2 * num7;
			totalMass += val7.mass;
			Part part = new Part
			{
				Bone = num3,
				Body = val7,
				Shape = val8
			};
			part.PosOffset = Quaternion.Inverse(pose.rotation) * (val5 - pose.position);
			part.RotOffset = Quaternion.Inverse(pose.rotation) * val6;
			partOfBone[num3] = parts.Count;
			parts.Add(part);
			own.Add((Collider)(object)val8);
			val3.AddComponent<UltronPartTag>().Body = this;
		}
		foreach (Part part2 in parts)
		{
			foreach (Part part3 in parts)
			{
				if (part2 != part3)
				{
					Physics.IgnoreCollision((Collider)(object)part2.Shape, (Collider)(object)part3.Shape, true);
				}
			}
		}
		Collider[] componentsInChildren = Self.Unit.GetComponentsInChildren<Collider>(true);
		foreach (Collider val9 in componentsInChildren)
		{
			if (!Object.op_Implicit((Object)(object)val9) || own.Contains(val9))
			{
				continue;
			}
			foreach (Part part4 in parts)
			{
				Physics.IgnoreCollision(val9, (Collider)(object)part4.Shape, true);
			}
		}
		foreach (Part part5 in parts)
		{
			int num8 = UltronAssets.Parents[part5.Bone];
			while (num8 >= 0 && partOfBone[num8] < 0)
			{
				num8 = UltronAssets.Parents[num8];
			}
			part5.Parent = ((num8 >= 0) ? partOfBone[num8] : (-1));
		}
	}

	private Pose3 RestWorld(int b)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Vector3.zero;
		Quaternion val2 = Quaternion.identity;
		List<int> list = new List<int>();
		for (int num = b; num >= 0; num = UltronAssets.Parents[num])
		{
			list.Add(num);
		}
		for (int num2 = list.Count - 1; num2 >= 0; num2--)
		{
			int num3 = list[num2];
			val += val2 * (UltronAssets.RestPos[num3] * S);
			val2 *= UltronAssets.RestRot[num3];
		}
		return new Pose3
		{
			position = val,
			rotation = val2
		};
	}

	private void FollowParts(bool snap)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: 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_006b: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < parts.Count; i++)
		{
			Part part = parts[i];
			if (Object.op_Implicit((Object)(object)part.Body))
			{
				Transform val = bones[part.Bone];
				Vector3 val2 = val.position + val.rotation * part.PosOffset;
				Quaternion val3 = val.rotation * part.RotOffset;
				if (snap)
				{
					part.Body.position = val2;
					part.Body.rotation = val3;
					((Component)part.Body).transform.SetPositionAndRotation(val2, val3);
				}
				else
				{
					part.Body.MovePosition(val2);
					part.Body.MoveRotation(val3);
				}
			}
		}
	}

	internal bool IsOwn(Collider c)
	{
		if (Object.op_Implicit((Object)(object)c))
		{
			return own.Contains(c);
		}
		return false;
	}

	internal void BecomeRagdoll(Vector3 velocity, float seconds)
	{
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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_0139: 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_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: 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_01b3: 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_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: 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)
		if (!Built)
		{
			return;
		}
		if (!Limp)
		{
			FollowParts(snap: true);
			foreach (Part part2 in parts)
			{
				part2.Body.isKinematic = false;
				part2.Body.useGravity = true;
				part2.Body.velocity = Vector3.ClampMagnitude(velocity + Velocity + Vector3.up * VerticalSpeed, 14f);
				part2.Body.angularVelocity = Vector3.zero;
				part2.Body.drag = 0.15f;
				part2.Body.angularDrag = 1.5f;
			}
			for (int i = 0; i < parts.Count; i++)
			{
				Part part = parts[i];
				if (part.Parent >= 0)
				{
					CharacterJoint val = ((Component)part.Body).gameObject.AddComponent<CharacterJoint>();
					((Joint)val).connectedBody = parts[part.Parent].Body;
					((Joint)val).autoConfigureConnectedAnchor = true;
					((Joint)val).anchor = ((Component)part.Body).transform.InverseTransformPoint(bones[part.Bone].position);
					((Joint)val).axis = Vector3.right;
					val.swingAxis = Vector3.forward;
					val.enableProjection = true;
					val.projectionDistance = 0.04f;
					val.projectionAngle = 25f;
					((Joint)val).enablePreprocessing = false;
					SoftJointLimit lowTwistLimit = val.lowTwistLimit;
					((SoftJointLimit)(ref lowTwistLimit)).limit = -40f;
					val.lowTwistLimit = lowTwistLimit;
					SoftJointLimit highTwistLimit = val.highTwistLimit;
					((SoftJointLimit)(ref highTwistLimit)).limit = 40f;
					val.highTwistLimit = highTwistLimit;
					SoftJointLimit swing1Limit = val.swing1Limit;
					((SoftJointLimit)(ref swing1Limit)).limit = 70f;
					val.swing1Limit = swing1Limit;
					SoftJointLimit swing2Limit = val.swing2Limit;
					((SoftJointLimit)(ref swing2Limit)).limit = 50f;
					val.swing2Limit = swing2Limit;
					joints.Add((Joint)(object)val);
				}
			}
			Limp = true;
		}
		else
		{
			foreach (Part part3 in parts)
			{
				part3.Body.AddForce(Vector3.ClampMagnitude(velocity, 10f), (ForceMode)2);
			}
		}
		if (seconds <= 0f)
		{
			permanentLimp = true;
		}
		else
		{
			limpUntil = Mathf.Max(limpUntil, Time.time + seconds);
		}
	}

	private void Recover()
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_011a: 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_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: 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)
		foreach (Joint joint in joints)
		{
			if (Object.op_Implicit((Object)(object)joint))
			{
				Object.Destroy((Object)(object)joint);
			}
		}
		joints.Clear();
		Vector3 position = parts[0].Body.position;
		groundY = (UWorld.Ground(position, 1f, 8f * S, out var hit) ? ((RaycastHit)(ref hit)).point.y : (position.y - S));
		Position = new Vector3(position.x, groundY, position.z);
		Vector3 val = UWorld.Flat(bones[hips].forward);
		if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
		{
			Heading = Mathf.Atan2(val.x, val.z) * 57.29578f;
		}
		foreach (Part part in parts)
		{
			part.Body.velocity = Vector3.zero;
			part.Body.angularVelocity = Vector3.zero;
			part.Body.isKinematic = true;
			part.Body.useGravity = false;
			part.Body.drag = 0.3f;
			part.Body.angularDrag = 3f;
		}
		Limp = false;
		Velocity = Vector3.zero;
		VerticalSpeed = 0f;
		knock = Vector3.zero;
		airMode = false;
		FlightAltitude = 0f;
		Pose(0f);
		FollowParts(snap: true);
	}

	internal void MarkShatterPending()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		shatterPending = true;
		DesiredVelocity = Vector3.zero;
		FlightAltitude = 0f;
		SetGlow(0f);
	}

	internal void BonePose(int bone, out Vector3 pos, out Quaternion rot)
	{
		//IL_0009: 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_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)
		pos = bones[bone].position;
		rot = bones[bone].rotation;
	}

	internal void HideBody()
	{
		if (Shattered)
		{
			return;
		}
		Shattered = true;
		shatterPending = false;
		foreach (Joint joint in joints)
		{
			if (Object.op_Implicit((Object)(object)joint))
			{
				Object.Destroy((Object)(object)joint);
			}
		}
		joints.Clear();
		foreach (Part part in parts)
		{
			if (Object.op_Implicit((Object)(object)part.Body))
			{
				Object.Destroy((Object)(object)((Component)part.Body).gameObject);
			}
		}
		parts.Clear();
		own.Clear();
		if (Object.op_Implicit((Object)(object)root))
		{
			((Component)root).gameObject.SetActive(false);
		}
	}

	internal void Knock(Vector3 v)
	{
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
		if (!Built || Limp)
		{
			if (!Limp)
			{
				return;
			}
			{
				foreach (Part part in parts)
				{
					if (Object.op_Implicit((Object)(object)part.Body))
					{
						part.Body.AddForce(Vector3.ClampMagnitude(v, 8f) * 0.5f, (ForceMode)2);
					}
				}
				return;
			}
		}
		v.y = Mathf.Max(0f, v.y);
		knock += UWorld.Flat(v) * (Primary ? 0.55f : 0.85f);
		knock = Vector3.ClampMagnitude(knock, Primary ? 7f : 10f);
		if (v.y > 2f && airMode)
		{
			VerticalSpeed = Mathf.Min(VerticalSpeed + v.y * 0.4f, 4f);
		}
	}

	internal void StartAirborne(float altitude)
	{
		altitude = Mathf.Clamp(altitude, 0f, 9f);
		Position.y = groundY + altitude;
		airMode = altitude > 0.05f;
		FlightAltitude = altitude;
		VerticalSpeed = 0f;
		if (Built)
		{
			Pose(0f);
			FollowParts(snap: true);
		}
	}

	private bool Wall(Vector3 from, Vector3 dir, float dist)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		int num = Physics.SphereCastNonAlloc(from, 0.32f * S, dir, wallHits, dist, -1, (QueryTriggerInteraction)1);
		for (int i = 0; i < num; i++)
		{
			Collider collider = ((RaycastHit)(ref wallHits[i])).collider;
			if (((RaycastHit)(ref wallHits[i])).distance > 0f && UWorld.IsScenery(collider) && ((RaycastHit)(ref wallHits[i])).normal.y < 0.6f)
			{
				return true;
			}
		}
		return false;
	}

	private void FixedUpdate()
	{
		Prof.B(1);
		try
		{
			if (partsOn == Prof.NoHitboxes)
			{
				partsOn = !Prof.NoHitboxes;
				foreach (Part part in parts)
				{
					if (Object.op_Implicit((Object)(object)part.Shape))
					{
						((Collider)part.Shape).enabled = partsOn;
					}
				}
			}
			FixedStep();
		}
		finally
		{
			Prof.E(1);
		}
	}

	private void FixedStep()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: 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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: 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_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: 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_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: 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_01a6: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: 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)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to 

BepInEx/plugins/MarvelPrototype/MarvelPrototype.Villains.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("3.0.0.0")]
[assembly: AssemblyVersion("3.0.0.0")]
namespace MarvelPrototype.GreenGoblin;

internal sealed class CostumeProfile
{
	internal sealed class Piece
	{
		internal string Name;

		internal float Grow = 1f;

		internal Vector3 Shift;
	}

	internal string Pack;

	internal Color[] Colors;

	internal Func<string, int> Region;

	internal float HeadScale = 1.06f;

	internal string[] Head = new string[0];

	internal Piece[] Torso = new Piece[0];

	internal Piece[] Hip = new Piece[0];

	internal string Foot;

	internal string[] SkinParts = new string[0];

	internal static readonly CostumeProfile Goblin = new CostumeProfile
	{
		Pack = "GoblinProps.bin",
		Colors = (Color[])(object)new Color[3]
		{
			new Color(0.24f, 0.5f, 0.1f),
			new Color(0.4f, 0.13f, 0.58f),
			new Color(0.31f, 0.09f, 0.46f)
		},
		Region = null,
		Head = new string[2] { "Mask", "Hat" },
		Torso = new Piece[1]
		{
			new Piece
			{
				Name = "Tunic",
				Grow = 1.45f
			}
		},
		Hip = new Piece[1]
		{
			new Piece
			{
				Name = "Belt",
				Grow = 1.25f
			}
		},
		Foot = "Boot"
	};

	internal static readonly CostumeProfile Octopus = new CostumeProfile
	{
		Pack = "OckProps.bin",
		Colors = (Color[])(object)new Color[3]
		{
			new Color(0.2f, 0.42f, 0.18f),
			new Color(0.42f, 0.26f, 0.13f),
			new Color(0.17f, 0.36f, 0.15f)
		},
		Region = delegate(string bone)
		{
			string text = bone.ToLowerInvariant();
			if (text.Contains("head") || text.Contains("neck"))
			{
				return 3;
			}
			return (text.Contains("arm") || text.Contains("elbow") || text.Contains("hand")) ? 1 : 0;
		},
		HeadScale = 1.4f,
		Head = new string[3] { "Head", "Hair", "Goggles" },
		Torso = new Piece[3]
		{
			new Piece
			{
				Name = "Belly",
				Grow = 2.1f
			},
			new Piece
			{
				Name = "Coat",
				Grow = 1.45f
			},
			new Piece
			{
				Name = "Frame",
				Grow = 1.45f
			}
		},
		Foot = "Shoe",
		SkinParts = new string[1] { "Head" }
	};
}
internal static class GalactusPrice
{
	internal const int OldDefault = 100000;

	internal const int NewDefault = 65535;

	internal const int TabsMax = 65535;

	private static ConfigEntry<int> migratedTo;

	internal static int Applied = -1;

	internal static string Report = "";

	internal static void Bind(ConfigFile c)
	{
		migratedTo = c.Bind<int>("Galactus", "CostMigration", 0, "Internal: set when MarvelPrototype's [Galactus] Cost default was moved from 100000 to 65535 (the TABS price maximum; do not edit).");
	}

	internal static void Apply(object launcher)
	{
		try
		{
			Type obj = R.Type("MarvelPrototype.GalactusConfig");
			if (!(R.Get(obj, "cost") is ConfigEntry<int> val))
			{
				GoblinPlugin.WarnOnce("galactus_cfg", "Galactus config entry not found; price unchanged.");
				return;
			}
			string text = "kept " + val.Value;
			if (migratedTo.Value != 65535)
			{
				if (val.Value == 100000)
				{
					val.Value = 65535;
					text = "migrated 100000 -> 65535";
				}
				else
				{
					text = "custom value " + val.Value + " kept";
				}
				migratedTo.Value = 65535;
			}
			int num = Mathf.Clamp(val.Value, 1, 65535);
			if (num != val.Value)
			{
				GoblinPlugin.WarnOnce("galactus_wrap", "Galactus Cost " + val.Value + " is above the TABS maximum 65535 (it would wrap); using 65535.");
			}
			R.Set(obj, "Cost", num);
			object obj2 = R.Get(launcher, "galactusBlueprint");
			if (obj2 == null)
			{
				GoblinPlugin.WarnOnce("galactus_bp", "Galactus blueprint not found; menu price unchanged.");
				return;
			}
			Type type = R.Type("ModdingForDummies.TABSSimp.ModUnit");
			object obj3 = null;
			if (type != null)
			{
				obj3 = FormatterServices.GetUninitializedObject(type);
				R.Set(obj3, "internalObject", obj2);
				R.Set(obj3, "Cost", num);
			}
			Applied = ((obj3 != null) ? Convert.ToInt32(R.Get(obj3, "Cost") ?? ((object)(-1))) : (-1));
			Report = "Galactus price: " + text + "; blueprint cost now " + Applied;
			GoblinPlugin.Log(Report);
		}
		catch (Exception ex)
		{
			GoblinPlugin.Error("Galactus price change failed: " + ex.GetBaseException());
		}
	}
}
internal static class GoblinAssets
{
	private static Sprite icon;

	private static readonly Dictionary<string, Sprite> icons = new Dictionary<string, Sprite>();

	private static Material glow;

	private static Texture2D soft;

	internal static byte[] Bytes(string name)
	{
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MarvelPrototype.GreenGoblin." + name);
		if (stream == null)
		{
			throw new FileNotFoundException("Embedded Goblin resource missing: " + name);
		}
		byte[] array = new byte[stream.Length];
		int i;
		int num;
		for (i = 0; i < array.Length; i += num)
		{
			num = stream.Read(array, i, array.Length - i);
			if (num <= 0)
			{
				break;
			}
		}
		if (i != array.Length)
		{
			throw new EndOfStreamException(name);
		}
		return array;
	}

	internal static Sprite Icon(string file)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_0069: 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)
		if (icons.TryGetValue(file, out var value) && Object.op_Implicit((Object)(object)value))
		{
			return value;
		}
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
		if (!ImageConversion.LoadImage(val, Bytes(file), true))
		{
			Object.Destroy((Object)(object)val);
			throw new IOException("Invalid icon " + file);
		}
		((Texture)val).wrapMode = (TextureWrapMode)1;
		value = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
		((Object)value).name = "Marvel_Menu_" + file;
		icons[file] = value;
		return value;
	}

	internal static Sprite Icon()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_006b: 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)
		if (Object.op_Implicit((Object)(object)icon))
		{
			return icon;
		}
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
		if (!ImageConversion.LoadImage(val, Bytes("GoblinIcon.png"), true))
		{
			Object.Destroy((Object)(object)val);
			throw new IOException("Invalid Goblin icon");
		}
		((Object)val).name = "Goblin_Menu_Icon";
		((Texture)val).wrapMode = (TextureWrapMode)1;
		icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
		((Object)icon).name = "Goblin_Menu_Icon";
		return icon;
	}

	internal static Material Glow()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)glow))
		{
			return glow;
		}
		glow = new Material(Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Particles/Additive") ?? Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Color"))
		{
			name = "Goblin_Glow"
		};
		Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
		{
			name = "Goblin_Soft",
			wrapMode = (TextureWrapMode)1
		};
		Color32[] array = (Color32[])(object)new Color32[4096];
		for (int i = 0; i < 64; i++)
		{
			for (int j = 0; j < 64; j++)
			{
				Vector2 val2 = new Vector2((float)j - 31.5f, (float)i - 31.5f);
				float num = Mathf.Clamp01(((Vector2)(ref val2)).magnitude / 31.5f);
				byte b = (byte)(255f * Mathf.Pow(1f - num, 2.2f));
				array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, b);
			}
		}
		val.SetPixels32(array);
		val.Apply(false, true);
		soft = val;
		glow.mainTexture = (Texture)(object)val;
		return glow;
	}

	internal static void Release()
	{
		GoblinPack.Release();
		TexturedPack.Release();
		foreach (Sprite value in icons.Values)
		{
			if (Object.op_Implicit((Object)(object)value))
			{
				Texture2D texture = value.texture;
				Object.Destroy((Object)(object)value);
				if (Object.op_Implicit((Object)(object)texture))
				{
					Object.Destroy((Object)(object)texture);
				}
			}
		}
		icons.Clear();
		if (Object.op_Implicit((Object)(object)icon))
		{
			Texture2D texture2 = icon.texture;
			Object.Destroy((Object)(object)icon);
			if (Object.op_Implicit((Object)(object)texture2))
			{
				Object.Destroy((Object)(object)texture2);
			}
			icon = null;
		}
		if (Object.op_Implicit((Object)(object)glow))
		{
			Object.Destroy((Object)(object)glow);
			glow = null;
		}
		if (Object.op_Implicit((Object)(object)soft))
		{
			Object.Destroy((Object)(object)soft);
			soft = null;
		}
	}
}
internal sealed class TexturedPack
{
	private static readonly Dictionary<string, TexturedPack> packs = new Dictionary<string, TexturedPack>();

	private readonly Dictionary<string, Mesh> meshes = new Dictionary<string, Mesh>();

	internal Material Material;

	private readonly List<Texture2D> textures = new List<Texture2D>();

	internal IEnumerable<string> Names => meshes.Keys;

	internal static TexturedPack Get(string resource, string baseTexture, string metalTexture)
	{
		if (packs.TryGetValue(resource, out var value))
		{
			return value;
		}
		value = new TexturedPack();
		value.Load(resource, baseTexture, metalTexture);
		packs[resource] = value;
		return value;
	}

	private Texture2D Tex(string name, bool linear)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear);
		if (!ImageConversion.LoadImage(val, GoblinAssets.Bytes(name), false))
		{
			Object.Destroy((Object)(object)val);
			throw new IOException("Invalid texture " + name);
		}
		((Object)val).name = "Ock_" + name;
		((Texture)val).wrapMode = (TextureWrapMode)0;
		val.Apply(true, true);
		textures.Add(val);
		return val;
	}

	private void Load(string resource, string baseTexture, string metalTexture)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_037a: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0380: Unknown result type (might be due to invalid IL or missing references)
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_0387: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_039f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Expected O, but got Unknown
		Shader val = Shader.Find("Standard") ?? Shader.Find("Legacy Shaders/Diffuse");
		if (!Object.op_Implicit((Object)(object)val))
		{
			throw new InvalidOperationException("Ock shader unavailable");
		}
		Material = new Material(val)
		{
			name = "Ock_Tentacle"
		};
		Material.mainTexture = (Texture)(object)Tex(baseTexture, linear: false);
		if (Material.HasProperty("_MetallicGlossMap"))
		{
			Material.SetTexture("_MetallicGlossMap", (Texture)(object)Tex(metalTexture, linear: true));
			Material.EnableKeyword("_METALLICGLOSSMAP");
		}
		if (Material.HasProperty("_GlossMapScale"))
		{
			Material.SetFloat("_GlossMapScale", 0.8f);
		}
		using BinaryReader binaryReader = new BinaryReader(new MemoryStream(GoblinAssets.Bytes(resource)));
		if (new string(binaryReader.ReadChars(4)) != "MPKT")
		{
			throw new InvalidDataException(resource + " header");
		}
		int num = binaryReader.ReadInt32();
		if (num < 1 || num > 64)
		{
			throw new InvalidDataException(resource + " parts");
		}
		for (int i = 0; i < num; i++)
		{
			int num2 = binaryReader.ReadInt32();
			if (num2 < 1 || num2 > 64)
			{
				throw new InvalidDataException(resource + " name");
			}
			string text = Encoding.UTF8.GetString(binaryReader.ReadBytes(num2));
			int num3 = binaryReader.ReadInt32();
			int num4 = binaryReader.ReadInt32();
			if (num3 < 3 || num3 > 65000 || num4 < 1 || num4 > 60000)
			{
				throw new InvalidDataException(resource + " size " + text);
			}
			Vector3[] array = (Vector3[])(object)new Vector3[num3];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num3];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num3];
			for (int j = 0; j < num3; j++)
			{
				array[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				array2[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				array3[j] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
				if (!GoblinRules.Finite(array[j]))
				{
					throw new InvalidDataException(resource + " nonfinite " + text);
				}
			}
			int[] array4 = new int[num4 * 6];
			for (int k = 0; k < num4; k++)
			{
				int num5 = binaryReader.ReadInt32();
				int num6 = binaryReader.ReadInt32();
				int num7 = binaryReader.ReadInt32();
				if (num5 < 0 || num6 < 0 || num7 < 0 || num5 >= num3 || num6 >= num3 || num7 >= num3)
				{
					throw new InvalidDataException(resource + " face " + text);
				}
				array4[k * 6] = num5;
				array4[k * 6 + 1] = num6;
				array4[k * 6 + 2] = num7;
				array4[k * 6 + 3] = num5 + num3;
				array4[k * 6 + 4] = num7 + num3;
				array4[k * 6 + 5] = num6 + num3;
			}
			Vector3[] array5 = (Vector3[])(object)new Vector3[num3 * 2];
			Vector3[] array6 = (Vector3[])(object)new Vector3[num3 * 2];
			Vector2[] array7 = (Vector2[])(object)new Vector2[num3 * 2];
			for (int l = 0; l < num3; l++)
			{
				array5[l] = (array5[l + num3] = array[l]);
				array6[l] = array2[l];
				array6[l + num3] = -array2[l];
				array7[l] = (array7[l + num3] = array3[l]);
			}
			Mesh val2 = new Mesh
			{
				name = "Ock_" + text,
				vertices = array5,
				normals = array6,
				uv = array7
			};
			val2.SetTriangles(array4, 0);
			val2.RecalculateBounds();
			meshes[text] = val2;
		}
		if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
		{
			throw new InvalidDataException(resource + " trailing bytes");
		}
	}

	internal Mesh Mesh(string part)
	{
		if (!meshes.TryGetValue(part, out var value))
		{
			throw new KeyNotFoundException("tentacle part " + part);
		}
		return value;
	}

	internal Transform Part(string part, Transform parent, string objectName)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		GameObject val = new GameObject(objectName);
		if (Object.op_Implicit((Object)(object)parent))
		{
			val.transform.SetParent(parent, false);
		}
		val.AddComponent<MeshFilter>().sharedMesh = Mesh(part);
		MeshRenderer obj = val.AddComponent<MeshRenderer>();
		((Renderer)obj).sharedMaterial = Material;
		((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1;
		return val.transform;
	}

	internal static void Release()
	{
		foreach (TexturedPack value in packs.Values)
		{
			foreach (Mesh value2 in value.meshes.Values)
			{
				if (Object.op_Implicit((Object)(object)value2))
				{
					Object.Destroy((Object)(object)value2);
				}
			}
			if (Object.op_Implicit((Object)(object)value.Material))
			{
				Object.Destroy((Object)(object)value.Material);
			}
			foreach (Texture2D texture in value.textures)
			{
				if (Object.op_Implicit((Object)(object)texture))
				{
					Object.Destroy((Object)(object)texture);
				}
			}
		}
		packs.Clear();
	}
}
internal sealed class GoblinPack
{
	private static readonly Dictionary<string, GoblinPack> packs = new Dictionary<string, GoblinPack>();

	private readonly Dictionary<string, Mesh> meshes = new Dictionary<string, Mesh>();

	internal Material[] Materials;

	private readonly string name;

	private GoblinPack(string n)
	{
		name = n;
	}

	internal static GoblinPack Get(string resource)
	{
		if (packs.TryGetValue(resource, out var value))
		{
			return value;
		}
		value = new GoblinPack(resource);
		value.Load(GoblinAssets.Bytes(resource));
		packs[resource] = value;
		return value;
	}

	private void Load(byte[] bytes)
	{
		//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_0130: 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_013a: Expected O, but got Unknown
		//IL_0198: 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_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d0: Expected O, but got Unknown
		//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0402: Unknown result type (might be due to invalid IL or missing references)
		//IL_0412: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Unknown result type (might be due to invalid IL or missing references)
		Shader val = Shader.Find("Standard") ?? Shader.Find("Legacy Shaders/Diffuse");
		if (!Object.op_Implicit((Object)(object)val))
		{
			throw new InvalidOperationException("Goblin prop shader unavailable");
		}
		using BinaryReader binaryReader = new BinaryReader(new MemoryStream(bytes));
		if (new string(binaryReader.ReadChars(4)) != "MPK1")
		{
			throw new InvalidDataException(name + " header");
		}
		int num = binaryReader.ReadInt32();
		int num2 = binaryReader.ReadInt32();
		if (num < 1 || num > 200 || num2 < 1 || num2 > 32)
		{
			throw new InvalidDataException(name + " counts");
		}
		Materials = (Material[])(object)new Material[num2];
		Color color = default(Color);
		Color val2 = default(Color);
		for (int i = 0; i < num2; i++)
		{
			((Color)(ref color))..ctor(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			float num3 = binaryReader.ReadSingle();
			float num4 = binaryReader.ReadSingle();
			((Color)(ref val2))..ctor(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			float num5 = binaryReader.ReadSingle();
			Material val3 = new Material(val)
			{
				name = "Goblin_" + Path.GetFileNameWithoutExtension(name) + "_" + i,
				color = color
			};
			if (val3.HasProperty("_Metallic"))
			{
				val3.SetFloat("_Metallic", Mathf.Clamp01(num3));
			}
			if (val3.HasProperty("_Glossiness"))
			{
				val3.SetFloat("_Glossiness", Mathf.Clamp01(num4));
			}
			if (num5 > 0f)
			{
				val3.EnableKeyword("_EMISSION");
				val3.SetColor("_EmissionColor", val2 * num5);
			}
			Materials[i] = val3;
		}
		for (int j = 0; j < num; j++)
		{
			int num6 = binaryReader.ReadInt32();
			if (num6 < 1 || num6 > 64)
			{
				throw new InvalidDataException(name + " part name");
			}
			string text = Encoding.UTF8.GetString(binaryReader.ReadBytes(num6));
			int num7 = binaryReader.ReadInt32();
			int num8 = binaryReader.ReadInt32();
			if (num7 < 3 || num7 > 65000 || num8 < 1 || num8 > 60000)
			{
				throw new InvalidDataException(name + " geometry size " + text);
			}
			Vector3[] array = (Vector3[])(object)new Vector3[num7];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num7];
			for (int k = 0; k < num7; k++)
			{
				array[k] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				array2[k] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				if (!GoblinRules.Finite(array[k]) || !GoblinRules.Finite(array2[k]))
				{
					throw new InvalidDataException(name + " nonfinite " + text);
				}
			}
			List<int>[] array3 = new List<int>[num2];
			for (int l = 0; l < num2; l++)
			{
				array3[l] = new List<int>();
			}
			for (int m = 0; m < num8; m++)
			{
				int num9 = binaryReader.ReadInt32();
				int num10 = binaryReader.ReadInt32();
				int num11 = binaryReader.ReadInt32();
				int num12 = binaryReader.ReadInt32();
				if (num9 < 0 || num10 < 0 || num11 < 0 || num9 >= num7 || num10 >= num7 || num11 >= num7 || num12 < 0 || num12 >= num2)
				{
					throw new InvalidDataException(name + " face " + text);
				}
				array3[num12].Add(num9);
				array3[num12].Add(num10);
				array3[num12].Add(num11);
			}
			if (!text.StartsWith("Anchor_"))
			{
				Vector3[] array4 = (Vector3[])(object)new Vector3[num7 * 2];
				Vector3[] array5 = (Vector3[])(object)new Vector3[num7 * 2];
				for (int n = 0; n < num7; n++)
				{
					array4[n] = (array4[n + num7] = array[n]);
					array5[n] = array2[n];
					array5[n + num7] = array2[n];
				}
				for (int num13 = 0; num13 < num2; num13++)
				{
					List<int> list = array3[num13];
					int count = list.Count;
					for (int num14 = 0; num14 + 2 < count; num14 += 3)
					{
						list.Add(list[num14] + num7);
						list.Add(list[num14 + 2] + num7);
						list.Add(list[num14 + 1] + num7);
					}
				}
				array = array4;
				array2 = array5;
			}
			Mesh val4 = new Mesh
			{
				name = "Goblin_" + text,
				vertices = array,
				normals = array2,
				subMeshCount = num2
			};
			for (int num15 = 0; num15 < num2; num15++)
			{
				val4.SetTriangles(array3[num15], num15);
			}
			val4.RecalculateBounds();
			if (meshes.ContainsKey(text))
			{
				throw new InvalidDataException(name + " duplicate part " + text);
			}
			meshes.Add(text, val4);
		}
		if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
		{
			throw new InvalidDataException(name + " trailing bytes");
		}
	}

	internal bool Has(string part)
	{
		return meshes.ContainsKey(part);
	}

	internal Mesh Mesh(string part)
	{
		if (!meshes.TryGetValue(part, out var value))
		{
			throw new KeyNotFoundException(name + " has no part " + part);
		}
		return value;
	}

	internal Vector3 Anchor(string part)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		Bounds bounds = Mesh(part).bounds;
		return ((Bounds)(ref bounds)).center;
	}

	internal GameObject Part(string part, Transform parent, string objectName)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		GameObject val = new GameObject(objectName);
		if (Object.op_Implicit((Object)(object)parent))
		{
			val.transform.SetParent(parent, false);
		}
		val.AddComponent<MeshFilter>().sharedMesh = Mesh(part);
		((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterials = Materials;
		return val;
	}

	internal static void Release()
	{
		foreach (GoblinPack value in packs.Values)
		{
			foreach (Mesh value2 in value.meshes.Values)
			{
				if (Object.op_Implicit((Object)(object)value2))
				{
					Object.Destroy((Object)(object)value2);
				}
			}
			if (value.Materials == null)
			{
				continue;
			}
			Material[] materials = value.Materials;
			foreach (Material val in materials)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}
		packs.Clear();
	}
}
internal enum GoblinPhase
{
	Placement,
	Flying,
	Falling,
	Ground,
	Dead
}
internal sealed class GoblinMotor
{
	private static readonly string[] Owned = new string[12]
	{
		"Balance", "AnimationHandler", "StandingHandler", "GravityHandler", "MovementHandler", "RotationHandler", "StepHandler", "FootSupport", "SetAnimationByInput", "DodgeMove",
		"WeaponHandler", "CollisionWeapon"
	};

	private static readonly string[] Muted = new string[0];

	private readonly List<KeyValuePair<KeyValuePair<object, FieldInfo>, float>> muted = new List<KeyValuePair<KeyValuePair<object, FieldInfo>, float>>();

	private readonly GUnit u;

	private readonly Dictionary<Behaviour, bool> behaviours = new Dictionary<Behaviour, bool>();

	private readonly Dictionary<Component, float> weapons = new Dictionary<Component, float>();

	private readonly Dictionary<Rigidbody, bool> gravity = new Dictionary<Rigidbody, bool>();

	private bool begun;

	private bool fallDamage;

	private bool fallDamageKnown;

	internal static int Unlocked;

	internal readonly Rigidbody Left;

	internal readonly Rigidbody Right;

	internal readonly Rigidbody Torso;

	internal string Taken = "";

	internal int MutedCount => muted.Count;

	private void Mute()
	{
		Behaviour[] componentsInChildren = u.Unit.GetComponentsInChildren<Behaviour>(true);
		foreach (Behaviour val in componentsInChildren)
		{
			if (!Object.op_Implicit((Object)(object)val) || !Muted.Contains(((object)val).GetType().Name))
			{
				continue;
			}
			Type type = ((object)val).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					if (!(fieldInfo.FieldType != typeof(float)))
					{
						string text = fieldInfo.Name.ToLowerInvariant();
						if (text.Contains("multiplier") || text.Contains("force"))
						{
							muted.Add(new KeyValuePair<KeyValuePair<object, FieldInfo>, float>(new KeyValuePair<object, FieldInfo>(val, fieldInfo), (float)fieldInfo.GetValue(val)));
							fieldInfo.SetValue(val, 0f);
						}
					}
				}
				type = type.BaseType;
			}
		}
	}

	internal void Unmute()
	{
		foreach (KeyValuePair<KeyValuePair<object, FieldInfo>, float> item in muted)
		{
			object key = item.Key.Key;
			if (Object.op_Implicit((Object)((key is Object) ? key : null)))
			{
				item.Key.Value.SetValue(item.Key.Key, item.Value);
			}
		}
		muted.Clear();
	}

	internal GoblinMotor(GUnit unit)
	{
		u = unit;
		Left = Body(u.LeftHand);
		Right = Body(u.RightHand);
		Torso = Body(u.Torso);
		Type type = R.Type("CollisionWeapon");
		if (type != null)
		{
			Component[] componentsInChildren = u.Unit.GetComponentsInChildren(type, true);
			foreach (Component val in componentsInChildren)
			{
				weapons[val] = R.Get(val, "damage", 0f);
			}
		}
	}

	private static Rigidbody Body(Transform t)
	{
		if (!Object.op_Implicit((Object)(object)t))
		{
			return null;
		}
		return ((Component)t).GetComponent<Rigidbody>() ?? ((Component)t).GetComponentInParent<Rigidbody>();
	}

	internal void Begin()
	{
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		if (begun)
		{
			return;
		}
		begun = true;
		List<string> list = new List<string>();
		Behaviour[] componentsInChildren = u.Unit.GetComponentsInChildren<Behaviour>(true);
		foreach (Behaviour val in componentsInChildren)
		{
			if (Object.op_Implicit((Object)(object)val) && Owned.Contains(((object)val).GetType().Name))
			{
				behaviours[val] = val.enabled;
				val.enabled = false;
				list.Add(((object)val).GetType().Name);
			}
		}
		Component[] array = weapons.Keys.ToArray();
		foreach (Component val2 in array)
		{
			if (Object.op_Implicit((Object)(object)val2))
			{
				R.Set(val2, "damage", 0f);
			}
		}
		Rigidbody[] bodies = u.Bodies;
		foreach (Rigidbody val3 in bodies)
		{
			if (Object.op_Implicit((Object)(object)val3))
			{
				gravity[val3] = val3.useGravity;
				val3.useGravity = false;
				if ((int)val3.constraints != 0)
				{
					val3.constraints = (RigidbodyConstraints)0;
					Unlocked++;
				}
			}
		}
		Taken = string.Join(",", list.Distinct().ToArray()) + " muted floats=" + muted.Count;
	}

	internal void Fall()
	{
		foreach (KeyValuePair<Rigidbody, bool> item in gravity)
		{
			if (Object.op_Implicit((Object)(object)item.Key))
			{
				item.Key.useGravity = item.Value;
			}
		}
		Unmute();
		object obj = R.Get(u.Data, "takeFallDamage");
		if (obj is bool)
		{
			fallDamage = (bool)obj;
			fallDamageKnown = true;
			R.Set(u.Data, "takeFallDamage", false);
		}
	}

	internal void Restore(float meleeMultiplier)
	{
		foreach (KeyValuePair<Rigidbody, bool> item in gravity)
		{
			if (Object.op_Implicit((Object)(object)item.Key))
			{
				item.Key.useGravity = item.Value;
			}
		}
		gravity.Clear();
		Unmute();
		foreach (KeyValuePair<Behaviour, bool> behaviour in behaviours)
		{
			if (Object.op_Implicit((Object)(object)behaviour.Key))
			{
				behaviour.Key.enabled = behaviour.Value;
			}
		}
		behaviours.Clear();
		foreach (KeyValuePair<Component, float> weapon in weapons)
		{
			if (Object.op_Implicit((Object)(object)weapon.Key))
			{
				R.Set(weapon.Key, "damage", weapon.Value * meleeMultiplier);
			}
		}
		begun = false;
	}

	internal void Regrip()
	{
		Rigidbody[] bodies = u.Bodies;
		foreach (Rigidbody val in bodies)
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				val.useGravity = false;
			}
		}
	}

	internal void RestoreFallDamage()
	{
		if (fallDamageKnown)
		{
			R.Set(u.Data, "takeFallDamage", fallDamage);
			fallDamageKnown = false;
		}
	}

	internal void Dead()
	{
		foreach (KeyValuePair<Rigidbody, bool> item in gravity)
		{
			if (Object.op_Implicit((Object)(object)item.Key))
			{
				item.Key.useGravity = item.Value;
			}
		}
		gravity.Clear();
		Unmute();
	}

	internal void Pose(Rigidbody limb, Vector3 point, Vector3 carrier, float power)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)limb) && !limb.isKinematic && GoblinRules.Finite(point))
		{
			Vector3 val = (point - limb.position) * 70f - (limb.velocity - carrier) * 11f;
			if (GoblinRules.Finite(val))
			{
				limb.AddForce(Vector3.ClampMagnitude(val, power), (ForceMode)5);
			}
		}
	}
}
public sealed class GoblinController : MonoBehaviour
{
	private enum Move
	{
		Climb,
		Orbit,
		Dive,
		PullUp
	}

	internal static readonly List<GoblinController> All = new List<GoblinController>();

	internal static int Dives;

	internal static int DiveHits;

	internal static int Pounces;

	internal static int GroundPhases;

	internal static int AirDeaths;

	internal GoblinPhase State;

	internal GUnit Self;

	internal GoblinGlider Glider;

	internal GUnit Target;

	internal int BombsThrown;

	internal int BladesThrown;

	internal int GunShots;

	private GoblinMotor motor;

	private Move move;

	private float moveStart;

	private float retarget;

	private float bombReady;

	private float bladeReady;

	private float gunReady;

	private float gunNext;

	private float diveReady;

	private float pounceReady;

	private float pounceUntil;

	private float groundBombReady;

	private float fallStart;

	private float landedAt;

	private float lastHealth;

	private float orbitAngle;

	private int gunLeft;

	private int orbitSign = 1;

	private int gunSide;

	private Vector3 diveDir;

	private Vector3 divePoint;

	private readonly HashSet<int> struck = new HashSet<int>();

	private float throwStart = -10f;

	private float throwRelease;

	private bool throwLeft;

	private bool released = true;

	private Action release;

	private bool ownedCleanup;

	private float stuckSince = -1f;

	private bool unpinned;

	internal static int AssistedSteps;

	private float landCheck = -1f;

	private float S => Self.Scale;

	internal void Initialize(GUnit u)
	{
		Self = u;
		motor = new GoblinMotor(u);
		Glider = GoblinGlider.Create(this, u);
		State = GoblinPhase.Placement;
		lastHealth = u.Health;
		All.Add(this);
		float num = Random.Range(0f, 1f);
		bombReady = 1.2f + num;
		bladeReady = 3.5f + num * 2f;
		gunReady = 2f + num;
		diveReady = 4f + num * 3f;
		orbitSign = ((!(Random.value < 0.5f)) ? 1 : (-1));
		orbitAngle = Random.Range(0f, (float)Math.PI * 2f);
	}

	private void FixedUpdate()
	{
		if (Self == null || !Object.op_Implicit((Object)(object)Self.Unit) || State == GoblinPhase.Dead)
		{
			return;
		}
		if (!Self.Alive)
		{
			Die();
			return;
		}
		bool inBattle = GoblinWorld.InBattle;
		if (State == GoblinPhase.Placement)
		{
			if (inBattle && !Self.Frozen)
			{
				TakeOff();
			}
		}
		else if (inBattle)
		{
			float health = Self.Health;
			if (health < lastHealth && State == GoblinPhase.Flying && Object.op_Implicit((Object)(object)Glider) && GoblinRules.GliderDamageShare > 0f)
			{
				Glider.Damage((lastHealth - health) * GoblinRules.GliderDamageShare, "hits on the rider");
			}
			lastHealth = health;
			Retarget();
			if (State == GoblinPhase.Flying)
			{
				Fly();
			}
			else if (State == GoblinPhase.Falling)
			{
				Fall();
			}
			else if (State == GoblinPhase.Ground)
			{
				GroundFight();
			}
			Throwing();
		}
	}

	private void TakeOff()
	{
		motor.Begin();
		Glider.Mount();
		State = GoblinPhase.Flying;
		move = Move.Climb;
		moveStart = Time.time;
		bombReady += Time.time;
		bladeReady += Time.time;
		gunReady += Time.time;
		diveReady += Time.time;
		GoblinPlugin.Log("Green Goblin airborne: unit=" + Self.Id + " team=" + Self.Team + " native behaviours held=" + motor.Taken + " glider hp=" + Glider.HP);
	}

	internal void OnGliderLost()
	{
		if (State == GoblinPhase.Flying)
		{
			State = GoblinPhase.Falling;
			fallStart = Time.time;
			motor.Fall();
			Glider = null;
			GoblinPlugin.Log("Green Goblin falls from the wrecked glider: unit=" + Self.Id + " hp=" + Self.Health.ToString("0"));
		}
	}

	private void Fall()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		if ((!GoblinWorld.Ground(Self.Position, 1.25f * S, out var _) || !(Time.time - fallStart > 0.45f)) && !(Time.time - fallStart > 2.6f))
		{
			return;
		}
		motor.Restore(GoblinRules.GroundMeleeMultiplier);
		State = GoblinPhase.Ground;
		landedAt = Time.time;
		GroundPhases++;
		Rigidbody[] bodies = Self.Bodies;
		foreach (Rigidbody val in bodies)
		{
			if (Object.op_Implicit((Object)(object)val) && (int)val.constraints != 0)
			{
				val.constraints = (RigidbodyConstraints)0;
			}
		}
		pounceReady = Time.time + 1.2f;
		bladeReady = Mathf.Max(bladeReady, Time.time + 2f);
		groundBombReady = Time.time + 2.5f;
		GoblinPlugin.Log("Green Goblin continues on foot: unit=" + Self.Id + " hp=" + Self.Health.ToString("0") + " melee x" + GoblinRules.GroundMeleeMultiplier);
		landCheck = Time.time + 1.5f;
	}

	private void Die()
	{
		GoblinPhase state = State;
		State = GoblinPhase.Dead;
		motor.Dead();
		if (Object.op_Implicit((Object)(object)Glider))
		{
			if (Glider.Mounted)
			{
				Glider.PilotLost();
				AirDeaths++;
			}
			Glider = null;
		}
		release = null;
		GoblinPlugin.Log("Green Goblin died (" + state.ToString() + "): unit=" + Self.Id + "; glider control released.");
	}

	private void Retarget()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: 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)
		if (Target != null && !Target.Alive)
		{
			Target = null;
		}
		if (Target != null && Time.time < retarget)
		{
			return;
		}
		retarget = Time.time + 0.5f;
		GUnit target = null;
		float num = float.MaxValue;
		Vector3 position = Self.Position;
		foreach (GUnit item in GoblinWorld.Enemies(Self.Team, position, 400f))
		{
			Vector3 val = item.Position - position;
			val.y *= 0.3f;
			float num2 = ((Vector3)(ref val)).magnitude * ((item == Target) ? 0.8f : 1f);
			if (num2 < num)
			{
				num = num2;
				target = item;
			}
		}
		Target = target;
	}

	private float Floor(Vector3 at)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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)
		if (!GoblinWorld.Ground(new Vector3(at.x, at.y + 25f, at.z), 80f, out var ground))
		{
			return Self.Position.y - 1f;
		}
		return ((RaycastHit)(ref ground)).point.y;
	}

	private void Fly()
	{
		//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_0021: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: 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_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)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: 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_012b: 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_056f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0576: Unknown result type (might be due to invalid IL or missing references)
		//IL_058a: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0516: Unknown result type (might be due to invalid IL or missing references)
		//IL_0517: Unknown result type (might be due to invalid IL or missing references)
		//IL_0521: Unknown result type (might be due to invalid IL or missing references)
		//IL_052c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0531: Unknown result type (might be due to invalid IL or missing references)
		//IL_0536: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: 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_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: 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_0542: Unknown result type (might be due to invalid IL or missing references)
		//IL_0421: Unknown result type (might be due to invalid IL or missing references)
		//IL_0423: Unknown result type (might be due to invalid IL or missing references)
		//IL_042d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0438: Unknown result type (might be due to invalid IL or missing references)
		//IL_043d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0442: Unknown result type (might be due to invalid IL or missing references)
		//IL_0462: Unknown result type (might be due to invalid IL or missing references)
		//IL_0467: Unknown result type (might be due to invalid IL or missing references)
		//IL_047c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: 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_0322: Unknown result type (might be due to invalid IL or missing references)
		//IL_0327: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_032d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: Unknown result type (might be due to invalid IL or missing references)
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_037c: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_038b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Unknown result type (might be due to invalid IL or missing references)
		//IL_0399: Unknown result type (might be due to invalid IL or missing references)
		//IL_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: 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_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: 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_027e: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: 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_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: 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_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)Glider))
		{
			OnGliderLost();
			return;
		}
		Vector3 deck = Glider.Deck;
		float num = Floor(deck);
		float num2 = GoblinRules.FlightHeight * S;
		Vector3 val = deck;
		float num3 = GoblinRules.FlightSpeed;
		float maxAccel = 16f;
		float pitch = 0f;
		Vector3 facing = ((Component)Glider).transform.forward;
		if (Target == null)
		{
			orbitAngle += Time.fixedDeltaTime * 0.35f;
			val = deck + new Vector3(Mathf.Cos(orbitAngle), 0f, Mathf.Sin(orbitAngle)) * 2f;
			val.y = num + num2;
			num3 = 3f;
			((Vector3)(ref facing))..ctor(0f - Mathf.Sin(orbitAngle), 0f, Mathf.Cos(orbitAngle));
		}
		else
		{
			Vector3 position = Target.Position;
			Vector3 val2 = position - deck;
			val2.y = 0f;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			Vector3 val3 = ((magnitude > 0.01f) ? (val2 / magnitude) : ((Component)Glider).transform.forward);
			if (move == Move.Climb)
			{
				val = deck + val3 * 2f;
				val.y = num + num2;
				facing = val3;
				if (deck.y > num + num2 * 0.8f || Time.time - moveStart > 3f)
				{
					Next(Move.Orbit);
				}
			}
			else if (move == Move.Orbit)
			{
				float num4 = 10f * Mathf.Sqrt(S);
				if (magnitude > num4 * 2.6f)
				{
					val = position - val3 * num4;
					val.y = Floor(val) + num2;
					facing = val3;
				}
				else
				{
					orbitAngle += (float)orbitSign * Time.fixedDeltaTime * GoblinRules.FlightSpeed * 0.75f / num4;
					Vector3 val4 = default(Vector3);
					((Vector3)(ref val4))..ctor(Mathf.Cos(orbitAngle), 0f, Mathf.Sin(orbitAngle));
					val = position + val4 * num4;
					val.y = Floor(val) + num2;
					facing = Vector3.Slerp(Vector3.Cross(Vector3.up, val4) * (float)orbitSign, val3, 0.45f);
				}
				if (Time.time >= diveReady && magnitude > 5f * S && magnitude < 22f * S && ClearDive(deck, position))
				{
					BeginDive(deck, position, val3);
				}
			}
			else if (move == Move.Dive)
			{
				divePoint = position;
				divePoint.y = Mathf.Max(Floor(position) + 0.45f * S, position.y - 0.75f * S);
				Vector3 val5 = divePoint - deck;
				val = divePoint + diveDir * 3f * S;
				val.y = divePoint.y;
				num3 = GoblinRules.DiveSpeed;
				maxAccel = 30f;
				facing = diveDir;
				float num5 = 0f - val5.y;
				Vector2 val6 = new Vector2(val5.x, val5.z);
				pitch = Mathf.Clamp(Mathf.Atan2(num5, Mathf.Max(1f, ((Vector2)(ref val6)).magnitude)) * 57.29578f, -10f, 35f);
				Strike(GoblinRules.DiveDamage, Glider.Velocity);
				if (Vector3.Dot(position - deck, diveDir) < -0.5f * S || Time.time - moveStart > 2.4f)
				{
					Next(Move.PullUp);
				}
			}
			else
			{
				val = deck + diveDir * 6f * S;
				val.y = num + num2;
				num3 = GoblinRules.DiveSpeed * 0.8f;
				maxAccel = 22f;
				facing = diveDir;
				pitch = -15f;
				Strike(GoblinRules.DiveDamage, Glider.Velocity);
				if (Time.time - moveStart > 1.1f)
				{
					diveReady = Time.time + GoblinRules.DiveCooldown * Random.Range(0.85f, 1.15f);
					orbitAngle = Mathf.Atan2(deck.z - position.z, deck.x - position.x);
					Next(Move.Orbit);
				}
			}
			if (move == Move.Orbit || move == Move.Climb)
			{
				Weapons(magnitude, position);
			}
			else
			{
				Guns(magnitude);
			}
		}
		if (move != Move.Dive && GoblinWorld.Blocked(deck + Vector3.up * 0.3f * S, val, out var _))
		{
			val.y = Mathf.Min(val.y + 3f * S, num + 9f * S);
		}
		val.y = Mathf.Clamp(val.y, Floor(val) + 0.45f * S, Floor(val) + 9f * S);
		Glider.Goal = val;
		Glider.Facing = facing;
		Glider.MaxSpeed = num3 * Mathf.Sqrt(S);
		Glider.MaxAccel = maxAccel;
		Glider.Pitch = pitch;
		Arms(Glider.Velocity);
	}

	private void Next(Move m)
	{
		move = m;
		moveStart = Time.time;
		if (m != Move.Dive && m != Move.PullUp)
		{
			struck.Clear();
		}
	}

	private bool ClearDive(Vector3 deck, Vector3 tp)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: 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)
		RaycastHit hit;
		return !GoblinWorld.Blocked(deck, tp + Vector3.up * 0.5f * S, out hit);
	}

	private void BeginDive(Vector3 deck, Vector3 tp, Vector3 toward)
	{
		//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)
		diveDir = toward;
		struck.Clear();
		Next(Move.Dive);
		Dives++;
	}

	private void Strike(float damage, Vector3 velocity)
	{
		//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_002d: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: 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_0109: 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_0118: 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_0121: 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)
		if (damage <= 0f)
		{
			return;
		}
		Vector3 chest = Self.Chest;
		float num = 1.25f * S;
		GUnit[] array = GoblinWorld.Enemies(Self.Team, chest, num + 1.2f * S).ToArray();
		foreach (GUnit gUnit in array)
		{
			if (!struck.Contains(gUnit.Id) && !(Mathf.Min(Vector3.Distance(gUnit.Chest, chest), Vector3.Distance(gUnit.Position, Object.op_Implicit((Object)(object)Glider) ? Glider.Deck : Self.Position)) > num))
			{
				struck.Add(gUnit.Id);
				Vector3 val;
				Vector3 normalized;
				if (!(((Vector3)(ref velocity)).sqrMagnitude > 0.1f))
				{
					val = gUnit.Position - chest;
					normalized = ((Vector3)(ref val)).normalized;
				}
				else
				{
					normalized = ((Vector3)(ref velocity)).normalized;
				}
				Vector3 val2 = normalized;
				gUnit.Damage(damage, val2, Self);
				val = val2 + Vector3.up * 0.4f;
				gUnit.Push(((Vector3)(ref val)).normalized * Mathf.Clamp(((Vector3)(ref velocity)).magnitude * 0.6f, 3f, 10f), 10f);
				DiveHits++;
			}
		}
	}

	private void Weapons(float dist, Vector3 tp)
	{
		//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_00ed: Unknown result type (might be due to invalid IL or missing references)
		if (Target == null)
		{
			return;
		}
		Vector3 chest = Target.Chest;
		if (Time.time >= bombReady && dist > 2.5f * S && dist < 24f * S && GoblinProjectile.CountOf(Self.Id) < GoblinRules.MaxBombs && released)
		{
			bombReady = Time.time + GoblinRules.BombCooldown * Random.Range(0.85f, 1.15f);
			GUnit t = Target;
			BeginThrow(left: false, 0.22f, delegate
			{
				ThrowBomb(t, air: true);
			});
		}
		else if (Time.time >= bladeReady && dist > 2.5f * S && dist < 26f * S && released && Sight(chest))
		{
			bladeReady = Time.time + GoblinRules.BladeCooldown;
			GUnit t2 = Target;
			BeginThrow(left: true, 0.18f, delegate
			{
				ThrowBlade(t2);
			});
		}
		Guns(dist);
	}

	private void Guns(float dist)
	{
		//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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: 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_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		if (Target == null)
		{
			return;
		}
		Vector3 chest = Target.Chest;
		if (Time.time >= gunReady && dist < GoblinRules.GunRange * S && Object.op_Implicit((Object)(object)Glider))
		{
			Vector3 val = chest - Glider.Nose;
			if (Vector3.Angle(((Component)Glider).transform.forward, val) < 60f && Sight(chest))
			{
				gunReady = Time.time + GoblinRules.GunBurstCooldown;
				gunLeft = GoblinRules.GunBurst;
				gunNext = Time.time;
			}
		}
		if (gunLeft > 0 && Time.time >= gunNext && Object.op_Implicit((Object)(object)Glider) && Target != null)
		{
			gunNext = Time.time + GoblinRules.GunInterval;
			gunLeft--;
			gunSide ^= 1;
			Vector3 val2 = ((gunSide == 0) ? Glider.GunL : Glider.GunR);
			Vector3 val3 = Target.Chest - val2;
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			normalized = Quaternion.Euler(Random.Range(-2.5f, 2.5f), Random.Range(-2.5f, 2.5f), 0f) * normalized;
			GoblinTracer.Fire(Self, val2, normalized, GoblinRules.GunRange * S);
			GunShots++;
		}
	}

	private bool Sight(Vector3 to)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		RaycastHit hit;
		return !GoblinWorld.Blocked(Self.Chest, to, out hit);
	}

	private void BeginThrow(bool left, float windup, Action act)
	{
		throwLeft = left;
		throwStart = Time.time;
		throwRelease = Time.time + windup;
		release = act;
		released = false;
	}

	private void Throwing()
	{
		if (!released && Time.time >= throwRelease)
		{
			released = true;
			Action action = release;
			release = null;
			if (action != null && Self.Alive)
			{
				action();
			}
		}
	}

	private Vector3 HandPoint(bool left)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		Rigidbody val = (left ? motor.Left : motor.Right);
		if (Object.op_Implicit((Object)(object)val))
		{
			return val.position;
		}
		Vector3 val2 = Vector3.Cross(Vector3.up, Self.Forward) * (float)((!left) ? 1 : (-1));
		return Self.Chest + val2 * 0.35f * S + Vector3.up * 0.2f * S;
	}

	private void ThrowBomb(GUnit t, bool air)
	{
		//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_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: 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_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		if (t != null && t.Alive)
		{
			Vector3 val = HandPoint(left: false) + Vector3.up * 0.08f * S;
			Vector3 val2 = t.Position - Vector3.up * 0.35f * S;
			float num = GoblinRules.LobTime(Vector3.Distance(val, val2), air);
			val2 += Vector3.ClampMagnitude(t.Velocity * num, 3f * S);
			Vector3 val3 = GoblinRules.Launch(val, val2, num, Physics.gravity.y);
			if (GoblinRules.Finite(val3))
			{
				PumpkinBomb.Throw(Self, val, val3, S);
				BombsThrown++;
			}
		}
	}

	private void ThrowBlade(GUnit t)
	{
		//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_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		if (t != null && t.Alive)
		{
			Vector3 val = HandPoint(left: true);
			Vector3 direction = t.Chest - val;
			if (!(((Vector3)(ref direction)).sqrMagnitude < 0.01f))
			{
				RazorBat.Throw(Self, val, direction, t, S);
				BladesThrown++;
			}
		}
	}

	private void Arms(Vector3 carrier)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: 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_00e8: 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_00f2: 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_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: 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_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: 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_01fc: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = (Object.op_Implicit((Object)(object)motor.Torso) ? motor.Torso.position : Self.Chest);
		Vector3 val2 = (Object.op_Implicit((Object)(object)Glider) ? ((Component)Glider).transform.forward : Self.Forward);
		val2.y = 0f;
		((Vector3)(ref val2)).Normalize();
		Vector3 val3 = Vector3.Cross(Vector3.up, val2);
		for (int i = 0; i < 2; i++)
		{
			bool flag = i == 0;
			Rigidbody limb = (flag ? motor.Left : motor.Right);
			float num = ((!flag) ? 1 : (-1));
			Vector3 point = val + val3 * num * 0.48f * S - Vector3.up * 0.18f * S + val2 * 0.12f * S;
			if (!released && flag == throwLeft)
			{
				point = val + val3 * num * 0.22f * S + Vector3.up * 0.55f * S - val2 * 0.32f * S;
			}
			else if (flag == throwLeft && Time.time - throwRelease < 0.25f)
			{
				point = val + val3 * num * 0.15f * S + Vector3.up * 0.18f * S + val2 * 0.62f * S;
			}
			motor.Pose(limb, point, carrier, 90f);
		}
	}

	private void Approach()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: 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_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Target.Position - Self.Position;
		val.y = 0f;
		float magnitude = ((Vector3)(ref val)).magnitude;
		Vector3 velocity = Self.Velocity;
		velocity.y = 0f;
		if (magnitude < 2.4f * S || Time.time < pounceUntil)
		{
			stuckSince = -1f;
			return;
		}
		Vector3 val2 = val / magnitude;
		if (Vector3.Dot(velocity, val2) > 0.6f * S)
		{
			stuckSince = -1f;
		}
		else if (stuckSince < 0f)
		{
			stuckSince = Time.time;
		}
		else
		{
			if (Time.time - stuckSince < 0.6f)
			{
				return;
			}
			Rigidbody[] bodies;
			if (!unpinned && Time.time - stuckSince > 2f)
			{
				unpinned = true;
				int num = 0;
				bodies = Self.Bodies;
				foreach (Rigidbody val3 in bodies)
				{
					if (Object.op_Implicit((Object)(object)val3) && (int)val3.constraints != 0)
					{
						val3.constraints = (RigidbodyConstraints)0;
						num++;
					}
				}
				int num2 = 0;
				Behaviour[] componentsInChildren = Self.Unit.GetComponentsInChildren<Behaviour>(true);
				foreach (Behaviour val4 in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)val4) && ((object)val4).GetType().Name == "SpawnFreezeBody" && val4.enabled)
					{
						val4.enabled = false;
						num2++;
					}
				}
				string[] obj = new string[8]
				{
					"GOBLIN_UNPIN unit=",
					Self.Id.ToString(),
					" constraintsCleared=",
					num.ToString(),
					" spawnFreezeDisabled=",
					num2.ToString(),
					" pos=",
					null
				};
				Vector3 position = Self.Position;
				obj[7] = ((Vector3)(ref position)).ToString("F2");
				GoblinPlugin.Log(string.Concat(obj));
			}
			Vector3 val5 = Vector3.ClampMagnitude(val2 * 3.4f * S * GoblinRules.Speed - velocity, 0.35f);
			bodies = Self.Bodies;
			foreach (Rigidbody val6 in bodies)
			{
				if (Object.op_Implicit((Object)(object)val6) && !val6.isKinematic)
				{
					val6.AddForce(val5, (ForceMode)2);
				}
			}
			if (Object.op_Implicit((Object)(object)motor.Torso))
			{
				Vector3 forward = ((Component)motor.Torso).transform.forward;
				forward.y = 0f;
				if (((Vector3)(ref forward)).sqrMagnitude > 0.01f)
				{
					Vector3 val7 = Vector3.Cross(((Vector3)(ref forward)).normalized, val2);
					motor.Torso.AddTorque(val7 * 6f, (ForceMode)5);
				}
			}
			AssistedSteps++;
		}
	}

	private void LandReport()
	{
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: 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_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		int num2 = 0;
		int num3 = 0;
		int num4 = 0;
		Rigidbody[] bodies = Self.Bodies;
		foreach (Rigidbody val in bodies)
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				if (val.isKinematic)
				{
					num3++;
				}
				if (val.useGravity)
				{
					num++;
				}
				else
				{
					num2++;
				}
				if ((int)val.constraints != 0)
				{
					num4++;
				}
			}
		}
		int num5 = (from b in Self.Unit.GetComponentsInChildren<Behaviour>(true)
			where Object.op_Implicit((Object)(object)b) && ((object)b).GetType().Name == "SpawnFreezeBody" && b.enabled
			select b).Count();
		string[] obj = new string[6]
		{
			"GOBLIN_LANDED_LOCKS constrainedBodies=",
			num4.ToString(),
			" activeSpawnFreeze=",
			num5.ToString(),
			" mainPos=",
			null
		};
		Vector3 val2 = Self.Position;
		obj[5] = ((Vector3)(ref val2)).ToString("F2");
		GoblinPlugin.Log(string.Concat(obj));
		string[] value = (from j in Self.Unit.GetComponentsInChildren<Joint>(true)
			where Object.op_Implicit((Object)(object)j) && (!Object.op_Implicit((Object)(object)j.connectedBody) || !((Component)j.connectedBody).transform.IsChildOf(Self.Unit.transform))
			select ((Object)j).name + "->" + (Object.op_Implicit((Object)(object)j.connectedBody) ? ((Object)j.connectedBody).name : "world")).ToArray();
		string[] value2 = (from b in Self.Unit.GetComponentsInChildren<Behaviour>(true)
			where Object.op_Implicit((Object)(object)b) && !b.enabled
			select ((object)b).GetType().Name).Distinct().ToArray();
		RaycastHit ground;
		float num6 = (GoblinWorld.Ground(Self.Position, 20f, out ground) ? (Self.Position.y - ((RaycastHit)(ref ground)).point.y) : (-1f));
		string[] obj2 = new string[16]
		{
			"GOBLIN_LANDED unit=",
			Self.Id.ToString(),
			" height=",
			num6.ToString("0.00"),
			" gravity on/off/kinematic=",
			num.ToString(),
			"/",
			num2.ToString(),
			"/",
			num3.ToString(),
			" foreignJoints=[",
			string.Join(",", value),
			"] disabled=[",
			string.Join(",", value2),
			"] vel=",
			null
		};
		val2 = Self.Velocity;
		obj2[15] = ((Vector3)(ref val2)).ToString("F1");
		GoblinPlugin.Log(string.Concat(obj2));
	}

	private void GroundFight()
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: 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_008e: 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_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		if (landCheck > 0f && Time.time >= landCheck)
		{
			landCheck = -1f;
			LandReport();
		}
		if (Time.time - landedAt > 1.5f)
		{
			motor.RestoreFallDamage();
		}
		if (Target == null)
		{
			return;
		}
		Approach();
		Vector3 val = Target.Position - Self.Position;
		val.y = 0f;
		float magnitude = ((Vector3)(ref val)).magnitude;
		RaycastHit ground;
		bool flag = GoblinWorld.Ground(Self.Position, 1.3f * S, out ground);
		if (Time.time < pounceUntil)
		{
			Strike(GoblinRules.PounceDamage, Self.Velocity);
		}
		else if (Time.time >= pounceReady && flag && magnitude > 2.2f * S && magnitude < 7.5f * S && Sight(Target.Chest))
		{
			pounceReady = Time.time + GoblinRules.PounceCooldown;
			pounceUntil = Time.time + 0.75f;
			struck.Clear();
			Pounces++;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Self.Push(normalized * Mathf.Clamp(magnitude * 1.6f, 5f, 10f) + Vector3.up * 3.6f, 11f);
		}
		if (Time.time >= bladeReady && magnitude > 2.5f * S && magnitude < 20f * S && released && Sight(Target.Chest))
		{
			bladeReady = Time.time + GoblinRules.BladeCooldown * 1.2f;
			GUnit t = Target;
			BeginThrow(left: true, 0.12f, delegate
			{
				ThrowBlade(t);
			});
		}
		else if (Time.time >= groundBombReady && magnitude > 4f * S && magnitude < 13f * S && released)
		{
			groundBombReady = Time.time + GoblinRules.GroundBombCooldown;
			GUnit t2 = Target;
			BeginThrow(left: false, 0.15f, delegate
			{
				ThrowBomb(t2, air: false);
			});
		}
	}

	private void OnDestroy()
	{
		All.Remove(this);
		if (Object.op_Implicit((Object)(object)Glider))
		{
			Object.Destroy((Object)(object)((Component)Glider).gameObject);
		}
		Glider = null;
		if (Self == null)
		{
			return;
		}
		GoblinProjectile[] array = GoblinProjectile.Live.ToArray();
		foreach (GoblinProjectile goblinProjectile in array)
		{
			if (Object.op_Implicit((Object)(object)goblinProjectile) && goblinProjectile.OwnerId == Self.Id)
			{
				Object.Destroy((Object)(object)((Component)goblinProjectile).gameObject);
			}
		}
	}

	internal string Describe()
	{
		//IL_0168: 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_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		string[] obj = new string[18]
		{
			"phase=",
			State.ToString(),
			" hp=",
			(Self != null) ? Self.Health.ToString("0") : "?",
			" glider=",
			Object.op_Implicit((Object)(object)Glider) ? (Glider.HP.ToString("0") + "/" + Glider.State) : "none",
			" target=",
			(Target != null) ? Target.Id.ToString() : "none",
			" bombs=",
			BombsThrown.ToString(),
			" blades=",
			BladesThrown.ToString(),
			" shots=",
			GunShots.ToString(),
			" move=",
			move.ToString(),
			null,
			null
		};
		object obj2;
		Vector3 val;
		if (!Object.op_Implicit((Object)(object)Glider))
		{
			obj2 = "";
		}
		else
		{
			string[] obj3 = new string[6] { " deck=", null, null, null, null, null };
			val = Glider.Deck;
			obj3[1] = ((Vector3)(ref val)).ToString("F1");
			obj3[2] = " goal=";
			obj3[3] = ((Vector3)(ref Glider.Goal)).ToString("F1");
			obj3[4] = " joints: ";
			obj3[5] = Glider.JointReport();
			obj2 = string.Concat(obj3);
		}
		obj[16] = (string)obj2;
		object obj4;
		if (Target == null)
		{
			obj4 = "";
		}
		else
		{
			val = Target.Position;
			obj4 = " targetPos=" + ((Vector3)(ref val)).ToString("F1");
		}
		obj[17] = (string)obj4;
		return string.Concat(obj);
	}
}
[DefaultExecutionOrder(920)]
public sealed class GoblinCostume : MonoBehaviour
{
	private sealed class Piece
	{
		internal Transform Bone;

		internal Transform View;

		internal Vector3 Offset;

		internal Quaternion Rotation;
	}

	private sealed class Painted
	{
		internal SkinnedMeshRenderer Renderer;

		internal Mesh Mesh;

		internal Material[] Materials;
	}

	private static readonly Color Skin = new Color(0.3f, 0.56f, 0.13f);

	private static readonly Color SkinDark = new Color(0.2f, 0.4f, 0.08f);

	private GUnit unit;

	private GameObject root;

	private readonly List<Piece> pieces = new List<Piece>();

	private readonly List<Renderer> tinted = new List<Renderer>();

	private readonly List<Renderer> hidden = new List<Renderer>();

	private MaterialPropertyBlock block;

	private float nextTint;

	internal bool Built;

	internal string Report = "";

	internal CostumeProfile Profile = CostumeProfile.Goblin;

	private readonly List<Painted> recoloured = new List<Painted>();

	private static readonly Color Green = new Color(0.24f, 0.5f, 0.1f);

	private static readonly Color Purple = new Color(0.4f, 0.13f, 0.58f);

	private static readonly Color Tunic = new Color(0.31f, 0.09f, 0.46f);

	private Quaternion facing;

	private bool headKnown;

	private Vector3 headCenter;

	private Vector3 headHalf;

	private readonly List<Transform> parented = new List<Transform>();

	private int skinFollowed;

	private string boneScales = "";

	private readonly List<Material> owned = new List<Material>();

	internal void Build(GUnit u, CostumeProfile profile = null)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: 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_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: 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_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0371: Unknown result type (might be due to invalid IL or missing references)
		//IL_0387: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0359: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
		if (Built)
		{
			return;
		}
		unit = u;
		if (profile != null)
		{
			Profile = profile;
		}
		block = new MaterialPropertyBlock();
		GoblinPack pack = GoblinPack.Get(Profile.Pack);
		root = new GameObject("Goblin_Costume_" + u.Id);
		Quaternion frame = Quaternion.LookRotation(u.Forward, Vector3.up);
		List<string> list = new List<string>();
		Rigidbody val = Socket(u.Head);
		Rigidbody val2 = Socket(u.Torso);
		Rigidbody val3 = Socket(u.Hip);
		facing = frame;
		Renderer[] componentsInChildren = u.Unit.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val4 in componentsInChildren)
		{
			if ((!(val4 is SkinnedMeshRenderer) && !(val4 is MeshRenderer)) || ((Object)val4).name.StartsWith("Goblin_"))
			{
				continue;
			}
			if (Weapon(val4))
			{
				if (val4.enabled)
				{
					val4.enabled = false;
					hidden.Add(val4);
				}
			}
			else
			{
				if (Ui(val4))
				{
					continue;
				}
				if (Eye(val4))
				{
					if (val4.enabled)
					{
						val4.enabled = false;
						hidden.Add(val4);
					}
				}
				else
				{
					SkinnedMeshRenderer val5 = (SkinnedMeshRenderer)(object)((val4 is SkinnedMeshRenderer) ? val4 : null);
					if (!Object.op_Implicit((Object)(object)val5) || !Recolor(val5, list))
					{
						tinted.Add(val4);
					}
				}
			}
		}
		if (Object.op_Implicit((Object)(object)val))
		{
			componentsInChildren = u.Unit.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val6 in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val6))
				{
					Bounds bounds = val6.bounds;
					if (((Bounds)(ref bounds)).Intersects(new Bounds(val.worldCenterOfMass, Vector3.one * 0.25f)))
					{
						list.Add("nearHead:" + ((object)val6).GetType().Name + "/" + ((Object)val6).name + "/en=" + val6.enabled + "/parent=" + (Object.op_Implicit((Object)(object)((Component)val6).transform.parent) ? ((Object)((Component)val6).transform.parent).name : "-"));
					}
				}
			}
		}
		string[] head = Profile.Head;
		foreach (string part in head)
		{
			if (headKnown)
			{
				FitHead(pack, part, val, list);
			}
			else
			{
				Fit(pack, part, val, frame, uniform: true, 1.3f, Vector3.zero, list);
			}
		}
		CostumeProfile.Piece[] torso = Profile.Torso;
		foreach (CostumeProfile.Piece piece in torso)
		{
			Fit(pack, piece.Name, val2, frame, uniform: false, piece.Grow, piece.Shift, list);
		}
		torso = Profile.Hip;
		foreach (CostumeProfile.Piece piece2 in torso)
		{
			if (Object.op_Implicit((Object)(object)val3) && (Object)(object)val3 != (Object)(object)val2)
			{
				Fit(pack, piece2.Name, val3, frame, uniform: false, piece2.Grow, piece2.Shift, list);
			}
			else
			{
				Fit(pack, piece2.Name, val2, frame, uniform: false, 1f, new Vector3(0f, -0.85f, 0f), list);
			}
		}
		if (Profile.Foot != null)
		{
			Transform[] array = (Transform[])(object)new Transform[2] { u.LeftFoot, u.RightFoot };
			for (int i = 0; i < array.Length; i++)
			{
				Rigidbody val7 = Socket(array[i]);
				if (Object.op_Implicit((Object)(object)val7))
				{
					FitLimb(pack, Profile.Foot, val7, frame, hand: false, list);
				}
			}
		}
		if (Profile.SkinParts.Length != 0)
		{
			TeamSkin(pack);
		}
		Tint();
		Built = true;
		Report = "pieces=" + pieces.Count + " followSkinBones=" + skinFollowed + " boneScale:" + boneScales + " recoloured=" + recoloured.Count + " tinted=" + tinted.Count + " hidden=" + hidden.Count + " " + string.Join(" ", list.ToArray());
		LateUpdate();
	}

	private int Region(string bone)
	{
		if (Profile.Region != null)
		{
			return Profile.Region(bone);
		}
		string text = bone.ToLowerInvariant();
		if (text.Contains("head") || text.Contains("neck"))
		{
			return 3;
		}
		if (text.Contains("elbow") || text.Contains("hand") || text.Contains("wrist") || text.Contains("finger") || text.Contains("knee") || text.Contains("foot") || text.Contains("ankle") || text.Contains("toe"))
		{
			return 1;
		}
		if (text.Contains("torso") || text.Contains("spine") || text.Contains("chest") || text.Contains("hip") || text.Contains("waist") || text.Contains("pelvis") || text.Contains("belly"))
		{
			return 2;
		}
		return 0;
	}

	private bool Recolor(SkinnedMeshRenderer smr, List<string> rep)
	{
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_0370: Expected O, but got Unknown
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		Mesh sharedMesh = smr.sharedMesh;
		if (!Object.op_Implicit((Object)(object)sharedMesh) || !sharedMesh.isReadable || smr.bones == null || smr.bones.Length == 0)
		{
			rep.Add("paint:" + (Object.op_Implicit((Object)(object)sharedMesh) ? (((Object)sharedMesh).name + (sharedMesh.isReadable ? "" : "(not readable)")) : "none"));
			return false;
		}
		BoneWeight[] boneWeights = sharedMesh.boneWeights;
		if (boneWeights == null || boneWeights.Length != sharedMesh.vertexCount)
		{
			rep.Add("paint:noweights");
			return false;
		}
		Transform[] bones = smr.bones;
		int[] array = new int[bones.Length];
		for (int i = 0; i < bones.Length; i++)
		{
			array[i] = (Object.op_Implicit((Object)(object)bones[i]) ? Region(((Object)bones[i]).name) : 0);
		}
		List<int>[] array2 = new List<int>[4]
		{
			new List<int>(),
			new List<int>(),
			new List<int>(),
			new List<int>()
		};
		for (int j = 0; j < sharedMesh.subMeshCount; j++)
		{
			int[] triangles = sharedMesh.GetTriangles(j);
			for (int k = 0; k + 2 < triangles.Length; k += 3)
			{
				int[] array3 = new int[4];
				for (int l = 0; l < 3; l++)
				{
					int boneIndex = ((BoneWeight)(ref boneWeights[triangles[k + l]])).boneIndex0;
					array3[(boneIndex >= 0 && boneIndex < array.Length) ? array[boneIndex] : 0]++;
				}
				int num = ((array3[3] >= 2) ? 3 : ((array3[1] >= 2) ? 1 : ((array3[2] >= 2) ? 2 : ((array3[0] < 2) ? array[Mathf.Clamp(((BoneWeight)(ref boneWeights[triangles[k]])).boneIndex0, 0, array.Length - 1)] : 0))));
				array2[num].Add(triangles[k]);
				array2[num].Add(triangles[k + 1]);
				array2[num].Add(triangles[k + 2]);
			}
		}
		if (!headKnown && array2[3].Count > 0)
		{
			MeasureHead(smr, sharedMesh, boneWeights, array2[3]);
		}
		if (recoloured.Count == 0)
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			BoneWeight[] array4 = boneWeights;
			for (int m = 0; m < array4.Length; m++)
			{
				BoneWeight val = array4[m];
				int boneIndex2 = ((BoneWeight)(ref val)).boneIndex0;
				string key = ((boneIndex2 >= 0 && boneIndex2 < bones.Length && Object.op_Implicit((Object)(object)bones[boneIndex2])) ? ((Object)bones[boneIndex2]).name : "?");
				dictionary.TryGetValue(key, out var value);
				dictionary[key] = value + 1;
			}
			rep.Add("vertsByBone:" + string.Join(",", dictionary.Select((KeyValuePair<string, int> p) => p.Key + "=" + p.Value).ToArray()));
		}
		Mesh val2 = Object.Instantiate<Mesh>(sharedMesh);
		((Object)val2).name = "Goblin_Painted_" + ((Object)sharedMesh).name;
		val2.subMeshCount = 3;
		for (int num2 = 0; num2 < 3; num2++)
		{
			val2.SetTriangles(array2[num2], num2, false);
		}
		Material sharedMaterial = ((Renderer)smr).sharedMaterial;
		Material[] array5 = (Material[])(object)new Material[3];
		Color[] colors = Profile.Colors;
		for (int num3 = 0; num3 < 3; num3++)
		{
			array5[num3] = (Object.op_Implicit((Object)(object)sharedMaterial) ? new Material(sharedMaterial) : new Material(Shader.Find("Standard")));
			((Object)array5[num3]).name = "Goblin_Suit_" + num3;
			array5[num3].color = colors[num3];
		}
		smr.sharedMesh = val2;
		((Renderer)smr).sharedMaterials = array5;
		recoloured.Add(new Painted
		{
			Renderer = smr,
			Mesh = val2,
			Materials = array5
		});
		rep.Add("paint:" + ((Object)sharedMesh).name + " tris g/p/t/headHidden=" + array2[0].Count / 3 + "/" + array2[1].Count / 3 + "/" + array2[2].Count / 3 + "/" + array2[3].Count / 3 + " bones=" + string.Join(",", (from b in bones
			where Object.op_Implicit((Object)(object)b)
			select ((Object)b).name).Distinct().Take(24).ToArray()));
		return true;
	}

	private void MeasureHead(SkinnedMeshRenderer smr, Mesh src, BoneWeight[] weights, List<int> tris)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: 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_012e: 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_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown res