Decompiled source of New Drones v1.0.0

BepInEx/plugins/StunDrone.dll

Decompiled 38 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Photon.Pun;
using UnityEngine;
using UnityEngine.UI;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace StunDroneMod;

[BepInPlugin("user.stundrone", "Stun Drone", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private float dumpTimer;

	private bool dumped;

	private float regTimer;

	private float adminTimer;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Stun Drone loaded. F8 = dump drone state");
		Registrar.Prefer = ((BaseUnityPlugin)this).Config.Bind<string>("General", "SourceDroneName", "Torque", "Часть имени ванильного дрона, который копируется (Zero Gravity, Feather, Indestructible, Battery, Torque...). Пусто = авто.").Value;
		Registrar.PriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceMin", 40000f, "Минимальная цена Stun Drone в магазине, $").Value;
		Registrar.PriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceMax", 75000f, "Максимальная цена Stun Drone в магазине, $").Value;
		StunDroneLogic.BarSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SecondsPerCharge", 10f, "Сколько секунд длится один заряд Stun Drone, пока он держит цель").Value;
		StunDroneLogic.StunCharges = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Charges", 6, "Сколько зарядов (полосок) у Stun Drone").Value;
		StunDroneLogic.ReleaseOnDetach = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ReleaseOnDetach", false, "false = цель остаётся в стане, пока дрон не выключен и есть заряд, даже если луч отцепился; true = стан снимается сразу при отцеплении луча").Value;
		StunDroneLogic.StrictBeam = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "StrictBeam", true, "true = цель считается прицепленной, только если конец луча дрона реально лежит на ней (защита от залипшей ссылки на старую цель)").Value;
		Registrar.PriceScale = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceScale", 0f, "Множитель цены: 0 = авто (по ванильному предмету), 0.001 = значение в тысячах, 1 = цена как есть").Value;
		Registrar.ShopMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "ShopMultiplier", 0f, "Множитель магазина игры: 0 = авто (ShopManager.itemValueMultiplier, обычно 4). Цена делится на него, чтобы в магазине было PriceMin..PriceMax").Value;
		Registrar.HealPriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "PriceMin", 25000f, "Минимальная цена Heal Drone в магазине, $").Value;
		Registrar.HealPriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "PriceMax", 50000f, "Максимальная цена Heal Drone в магазине, $").Value;
		StunDroneLogic.HealAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Heal Drone", "HealAmount", 5, "Сколько HP лечит за один тик").Value;
		StunDroneLogic.HealInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "HealInterval", 1f, "Пауза между тиками лечения, секунд").Value;
		StunDroneLogic.HealCharges = ((BaseUnityPlugin)this).Config.Bind<int>("Heal Drone", "Charges", 10, "Сколько зарядов (полосок) у Heal Drone. Один тик лечения (HealAmount HP) = 1 заряд").Value;
		Registrar.DefPriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "PriceMin", 30000f, "Минимальная цена Defense Drone в магазине, $").Value;
		Registrar.DefPriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "PriceMax", 60000f, "Максимальная цена Defense Drone в магазине, $").Value;
		StunDroneLogic.DefCharges = ((BaseUnityPlugin)this).Config.Bind<int>("Defense Drone", "Charges", 6, "Сколько зарядов (полосок) у Defense Drone").Value;
		StunDroneLogic.DefBarSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "SecondsPerCharge", 10f, "Сколько секунд длится 1 заряд Defense Drone").Value;
		StunDroneLogic.DefDamageScale = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "DamageMultiplier", 0.25f, "Множитель входящего урона под защитой (0.25 = -75% урона)").Value;
		DefenseHudOverlay.ShieldOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldOffsetX", 8f, "Смещение иконки щита по X от правого края HealthMax (в единицах HUD)").Value;
		DefenseHudOverlay.ShieldOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldOffsetY", 0f, "Смещение иконки щита по Y от центра HealthMax (в единицах HUD), + вверх").Value;
		DefenseHudOverlay.ShieldScale = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldScale", 0.7f, "Масштаб иконки щита").Value;
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)289))
		{
			StunDroneLogic[] array = Object.FindObjectsByType<StunDroneLogic>((FindObjectsSortMode)0);
			foreach (StunDroneLogic stunDroneLogic in array)
			{
				stunDroneLogic.DumpState(((BaseUnityPlugin)this).Logger);
			}
		}
		if (!Registrar.Done && Registrar.Tries < 300)
		{
			regTimer += Time.deltaTime;
			if (regTimer > 2f)
			{
				regTimer = 0f;
				Registrar.TryRegister(((BaseUnityPlugin)this).Logger);
			}
		}
		if (Registrar.AnyDone)
		{
			adminTimer += Time.deltaTime;
			if (adminTimer > 2f)
			{
				adminTimer = 0f;
				AdminSync.Run(((BaseUnityPlugin)this).Logger);
			}
		}
		if (!dumped)
		{
			dumpTimer += Time.deltaTime;
			if (dumpTimer > 10f)
			{
				dumped = true;
				Dumper.Run(((BaseUnityPlugin)this).Logger);
			}
		}
	}

	private void SpawnDrone(string itemName)
	{
		//IL_0111: 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_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: 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_0150: 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)
		StatsManager instance = StatsManager.instance;
		if ((Object)(object)instance == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"StatsManager not ready");
			return;
		}
		Item val = null;
		foreach (Item value in instance.itemDictionary.Values)
		{
			if ((Object)(object)value != (Object)null && value.itemName == itemName)
			{
				val = value;
				break;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)(itemName + " is not registered yet (wait for the log line DONE)"));
			return;
		}
		Type type = Registrar.FindType("REPOLib.Modules.Items");
		if (type == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"REPOLib not found");
			return;
		}
		Camera main = Camera.main;
		Vector3 val2 = (((Object)(object)main != (Object)null) ? (((Component)main).transform.position + ((Component)main).transform.forward * 2f) : Vector3.up);
		object obj = type.GetMethod("SpawnItem").Invoke(null, new object[3]
		{
			val,
			val2,
			Quaternion.identity
		});
		if (obj == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"SpawnItem returned null (are you the host? see REPOLib lines in the log)");
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)(itemName + " spawned"));
		}
	}
}
public class StunDroneLogic : MonoBehaviour
{
	public enum Mode
	{
		Player,
		Monster
	}

	private enum Part
	{
		Skip,
		Main,
		Other
	}

	private const float Range = 6f;

	private const float MonsterStunSeconds = 1.5f;

	private const float NormalGravity = 30f;

	private const float PlayerStunSeconds = 3f;

	private const float AutoCooldown = 6f;

	private const BindingFlags RB = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

	public Mode mode;

	public static int StunCharges = 6;

	public static int HealCharges = 10;

	public static int DefCharges = 6;

	public static float DefBarSeconds = 10f;

	public static float DefDamageScale = 0.25f;

	public int charge = 1;

	private object target;

	private float stickUntil;

	private ItemAttributes[] attrs;

	private float gravTimer;

	private bool gravLogged;

	private static readonly Color OrangeC = new Color(1f, 0.5f, 0.05f, 1f);

	private static readonly Color GreenC = new Color(0.15f, 1f, 0.3f, 1f);

	private static readonly Color DarkBlueC = new Color(0.08f, 0.28f, 1f, 1f);

	private bool batLogged;

	private bool torqueLogged;

	private bool scriptsDone;

	private Texture2D iconTex;

	private bool iconPending;

	private int bornFrame;

	private bool iconLogged;

	private static bool logged;

	private float nextAuto;

	private float reapplyTimer;

	private bool targetingDone;

	private ItemDrone droneComp;

	private bool wasAttached;

	private bool loggedScan;

	private float nextDiag;

	private float holdTimer;

	private object attachedObj;

	public static bool StrictBeam = true;

	public static bool ReleaseOnDetach = false;

	public static float BarSeconds = 3f;

	private float drainTimer;

	private object stunned;

	private float attachStart;

	private bool capped;

	private object relTarget;

	private float relUntil;

	private float relNext;

	private static bool stunLogged;

	private float nextBeamLog;

	private HashSet<Renderer> batRend = new HashSet<Renderer>();

	private List<Renderer> beamList = new List<Renderer>();

	private Dictionary<Renderer, int[]> beamProps = new Dictionary<Renderer, int[]>();

	private float nextBeamFind;

	private bool fieldColorLogged;

	private Component batteryComp;

	private float nextBatFind;

	private bool batteryLogged;

	private bool uiDumped;

	private float lifeVal = -1f;

	private int lastCharge;

	private float nextBatDump;

	private int dumpedCharge = -1;

	public static int HealAmount = 5;

	public static float HealInterval = 1f;

	private float nextHeal;

	private bool healWarned;

	private Component tumbleCache;

	private PlayerAvatar cachedFor;

	private bool tumbleWarned;

	private bool stunWarned;

	private bool stunWarned2;

	private bool stunOk;

	private static HashSet<string> noStunLogged = new HashSet<string>();

	private int lastDefHp = -1;

	private PlayerAvatar lastDefPlayer;

	private int Cap => Math.Max(1, Defense ? DefCharges : (Heal ? HealCharges : StunCharges));

	private string DisplayName => Defense ? "Defense Drone" : (Heal ? "Heal Drone" : "Stun Drone");

	private bool Heal => this is HealDroneLogic;

	private bool Defense => this is DefenseDroneLogic;

	private Color Orange => Defense ? DarkBlueC : (Heal ? GreenC : OrangeC);

	private void Awake()
	{
		charge = Cap;
		CollectBatteryRenderers();
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val != (Object)null && ((object)val).GetType().Name == "ItemBattery")
			{
				SetNum(val, "batteryBars", Cap);
			}
		}
		mode = ((!Heal && !Defense && !(Random.value < 0.5f)) ? Mode.Monster : Mode.Player);
		Retexture();
		ApplyIcon();
		bornFrame = Time.frameCount;
		ApplyTargeting();
		attrs = ((Component)this).GetComponentsInChildren<ItemAttributes>(true);
		ForceName();
		Debug.Log((object)string.Concat("[StunDrone] spawned, mode=", mode, ", name=", DumpName()));
	}

	private void ForceName()
	{
		if (attrs == null)
		{
			return;
		}
		ItemAttributes[] array = attrs;
		foreach (ItemAttributes val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				SetStr(val, "itemName", DisplayName);
				SetStr(val, "instanceName", DisplayName);
				SetStr(val, "cachedItemName", DisplayName);
			}
		}
	}

	private string DumpName()
	{
		if (attrs == null || attrs.Length == 0)
		{
			return "<no ItemAttributes>";
		}
		ItemAttributes o = attrs[0];
		return GetStr(o, "itemName") + " / " + GetStr(o, "cachedItemName");
	}

	private static void SetStr(object o, string name, string v)
	{
		FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null && field.FieldType == typeof(string))
		{
			field.SetValue(o, v);
		}
	}

	private static string GetStr(object o, string name)
	{
		FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		return (field != null) ? (field.GetValue(o) as string) : "?";
	}

	private void ApplyGravity()
	{
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				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)) && !(fieldInfo.Name.ToLower() != "customgravity"))
					{
						float num = (float)fieldInfo.GetValue(val);
						if (!gravLogged)
						{
							Debug.Log((object)("[StunDrone] " + type.Name + "." + fieldInfo.Name + ": " + num + " -> " + 30f));
						}
						if (num != 30f)
						{
							fieldInfo.SetValue(val, 30f);
						}
					}
				}
				type = type.BaseType;
			}
		}
		gravLogged = true;
	}

	private void ApplyColors()
	{
		//IL_00af: 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_00e6: 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_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			if (!(val is ParticleSystemRenderer) && Classify(((Component)val).transform) == Part.Other && !IsBatteryRenderer(val))
			{
				Material material = val.material;
				if (material.HasProperty("_EmissionColor"))
				{
					material.SetColor("_EmissionColor", Orange);
				}
			}
		}
		Light[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Light>(true);
		foreach (Light val2 in componentsInChildren2)
		{
			val2.color = Orange;
		}
		LineRenderer[] componentsInChildren3 = ((Component)this).GetComponentsInChildren<LineRenderer>(true);
		foreach (LineRenderer val3 in componentsInChildren3)
		{
			val3.startColor = Orange;
			val3.endColor = Orange;
		}
		ParticleSystem[] componentsInChildren4 = ((Component)this).GetComponentsInChildren<ParticleSystem>(true);
		foreach (ParticleSystem val4 in componentsInChildren4)
		{
			MainModule main = val4.main;
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Orange);
		}
	}

	private void ApplyBatteryColor()
	{
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] battery members: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null || ((object)val).GetType().Name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) < 0)
			{
				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 (!batLogged)
					{
						object value = null;
						try
						{
							value = fieldInfo.GetValue(val);
						}
						catch
						{
						}
						stringBuilder.Append(type.Name).Append('.').Append(fieldInfo.Name)
							.Append('=')
							.Append(value)
							.Append("; ");
					}
					if (fieldInfo.FieldType == typeof(Color) && (fieldInfo.Name.Equals("batteryColor", StringComparison.OrdinalIgnoreCase) || fieldInfo.Name.Equals("batteryColorMain", StringComparison.OrdinalIgnoreCase) || fieldInfo.Name.Equals("batteryColorMedium", StringComparison.OrdinalIgnoreCase)))
					{
						fieldInfo.SetValue(val, Orange);
					}
				}
				type = type.BaseType;
			}
		}
		if (!batLogged)
		{
			batLogged = true;
			Debug.Log((object)stringBuilder.ToString());
		}
	}

	private void RemoveTorque()
	{
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] torque members: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				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)
				{
					string text = fieldInfo.Name.ToLower();
					if (text.Contains("torque") || text.Contains("spin"))
					{
						object value = null;
						try
						{
							value = fieldInfo.GetValue(val);
						}
						catch
						{
						}
						if (!torqueLogged)
						{
							stringBuilder.Append(type.Name).Append('.').Append(fieldInfo.Name)
								.Append('=')
								.Append(value)
								.Append("; ");
						}
						if (fieldInfo.FieldType == typeof(float))
						{
							fieldInfo.SetValue(val, 0f);
						}
						else if (fieldInfo.FieldType == typeof(bool))
						{
							fieldInfo.SetValue(val, false);
						}
						else if (fieldInfo.FieldType == typeof(Vector3))
						{
							fieldInfo.SetValue(val, Vector3.zero);
						}
					}
				}
				type = type.BaseType;
			}
		}
		if (!torqueLogged)
		{
			torqueLogged = true;
			Debug.Log((object)stringBuilder.ToString());
		}
	}

	private void RemoveTorqueScripts()
	{
		if (scriptsDone)
		{
			return;
		}
		scriptsDone = true;
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] scripts on drone: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			string name = ((object)val).GetType().Name;
			stringBuilder.Append(((Object)((Component)val).gameObject).name).Append(':').Append(name)
				.Append("; ");
			if (!((Object)(object)val == (Object)(object)this) && !(name == "ItemDrone"))
			{
				string text = name.ToLower();
				if (text.Contains("torque") || text.Contains("spin"))
				{
					Debug.Log((object)("[StunDrone] removing script " + name + " on " + ((Object)((Component)val).gameObject).name));
					Object.Destroy((Object)(object)val);
				}
			}
		}
		Debug.Log((object)stringBuilder.ToString());
	}

	private void LateUpdate()
	{
		ForceName();
		SyncBattery();
		TintBeams();
		if (Time.frameCount > bornFrame + 5)
		{
			RemoveTorqueScripts();
		}
		if (Time.time > gravTimer)
		{
			gravTimer = Time.time + 0.5f;
			ApplyGravity();
			ApplyColors();
			ApplyBatteryColor();
			ApplyDroneFieldColors();
			RemoveTorque();
			if ((Object)(object)iconTex != (Object)null && Time.frameCount > bornFrame + 3)
			{
				ApplyIconMaterial();
			}
		}
	}

	private void ApplyTargeting()
	{
		ItemDrone componentInChildren = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		if (!((Object)(object)componentInChildren == (Object)null))
		{
			SetBool(componentInChildren, "targetValuables", v: false);
			SetBool(componentInChildren, "targetNonValuables", v: false);
			SetBool(componentInChildren, "targetPlayers", v: true);
			SetBool(componentInChildren, "targetEnemies", !Heal && !Defense);
		}
	}

	private static void SetBool(object o, string name, bool v)
	{
		FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null && field.FieldType == typeof(bool))
		{
			field.SetValue(o, v);
		}
		else
		{
			Debug.LogWarning((object)("[StunDrone] field " + name + " not found"));
		}
	}

	private void ApplyIcon()
	{
		iconTex = LoadEmbedded(Defense ? "def_icon.png" : (Heal ? "heal_icon.png" : "icon.png"));
		Debug.Log((object)("[StunDrone] icon.png embedded in DLL: " + ((Object)(object)iconTex != (Object)null) + (((Object)(object)iconTex == (Object)null) ? "  (put tex\\3.png next to build.bat and rebuild)" : "")));
		if ((Object)(object)iconTex == (Object)null)
		{
			return;
		}
		ItemDrone componentInChildren = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		if ((Object)(object)componentInChildren != (Object)null)
		{
			FieldInfo field = typeof(ItemDrone).GetField("droneIcon", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(componentInChildren, iconTex);
			}
			else
			{
				Debug.LogWarning((object)"[StunDrone] field droneIcon not found");
			}
		}
		else
		{
			Debug.LogWarning((object)"[StunDrone] ItemDrone not found on prefab");
		}
		iconPending = true;
		bornFrame = Time.frameCount;
	}

	private void ApplyIconMaterial()
	{
		//IL_0107: 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_0155: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			bool flag = false;
			Transform val2 = ((Component)val).transform;
			while ((Object)(object)val2 != (Object)null)
			{
				if (((Object)val2).name.Replace('_', ' ').Trim().StartsWith("Drone Icon"))
				{
					flag = true;
					break;
				}
				val2 = val2.parent;
			}
			if (flag)
			{
				Material material = val.material;
				material.EnableKeyword("_EMISSION");
				material.SetTexture("_EmissionMap", (Texture)(object)iconTex);
				if (material.HasProperty("_MainTex"))
				{
					material.SetTexture("_MainTex", (Texture)(object)iconTex);
				}
				if (material.HasProperty("_BaseMap"))
				{
					material.SetTexture("_BaseMap", (Texture)(object)iconTex);
				}
				if (material.HasProperty("_EmissionColor"))
				{
					material.SetColor("_EmissionColor", Color.white);
				}
				if (material.HasProperty("_Color"))
				{
					material.SetColor("_Color", Color.white);
				}
				if (material.HasProperty("_BaseColor"))
				{
					material.SetColor("_BaseColor", Color.white);
				}
				num++;
			}
		}
		if (!iconLogged)
		{
			iconLogged = true;
			Debug.Log((object)("[StunDrone] icon applied to " + num + " renderer(s) named 'Drone Icon'"));
		}
	}

	private void Retexture()
	{
		//IL_00ac: 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_007e: 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_0258: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = (Defense ? LoadEmbedded("def_albedo.png") : (Heal ? LoadEmbedded("heal_albedo.png") : null)) ?? LoadEmbedded("albedo.png") ?? Procedural(Defense ? new Color(0.08f, 0.25f, 0.95f) : (Heal ? new Color(0.2f, 0.8f, 0.3f) : ((mode == Mode.Player) ? new Color(0.9f, 0.55f, 0.1f) : new Color(0.1f, 0.6f, 0.8f))));
		Texture2D val2 = (Defense ? LoadEmbedded("def_emission.png") : (Heal ? LoadEmbedded("heal_emission.png") : null)) ?? LoadEmbedded("emission.png");
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val3 in componentsInChildren)
		{
			if (IsBatteryRenderer(val3))
			{
				continue;
			}
			Part part = Classify(((Component)val3).transform);
			if (!logged)
			{
				Debug.Log((object)("[StunDrone] renderer '" + ((Object)val3).name + "' -> " + part));
			}
			if (part == Part.Skip)
			{
				continue;
			}
			Material material = val3.material;
			if (material.HasProperty("_MainTex"))
			{
				material.SetTexture("_MainTex", (Texture)(object)val);
			}
			if (material.HasProperty("_BaseMap"))
			{
				material.SetTexture("_BaseMap", (Texture)(object)val);
			}
			if (part == Part.Main)
			{
				if (material.HasProperty("_EmissionMap"))
				{
					material.SetTexture("_EmissionMap", (Texture)null);
				}
				material.DisableKeyword("_EMISSION");
			}
			else if ((Object)(object)val2 != (Object)null && material.HasProperty("_EmissionMap"))
			{
				material.EnableKeyword("_EMISSION");
				material.SetTexture("_EmissionMap", (Texture)(object)val2);
				material.SetColor("_EmissionColor", Color.white);
			}
		}
		logged = true;
	}

	private static Part Classify(Transform t)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			string text = ((Object)val).name.Replace('_', ' ').Trim();
			if (text.StartsWith("Drone Icon"))
			{
				return Part.Skip;
			}
			if (text.Contains("Drone Triangle") || text.Contains("Drone Pyramid"))
			{
				return Part.Other;
			}
			if (text == "Drone")
			{
				return Part.Main;
			}
			val = val.parent;
		}
		return Part.Skip;
	}

	private static Texture2D LoadEmbedded(string name)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
		if (stream == null)
		{
			return null;
		}
		MemoryStream memoryStream = new MemoryStream();
		stream.CopyTo(memoryStream);
		Texture2D val = new Texture2D(2, 2);
		ImageConversion.LoadImage(val, memoryStream.ToArray());
		return val;
	}

	private static Texture2D Procedural(Color c)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_002e: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(64, 64);
		for (int i = 0; i < 64; i++)
		{
			for (int j = 0; j < 64; j++)
			{
				val.SetPixel(j, i, ((j / 8 + i / 8) % 2 == 0) ? c : (c * 0.6f));
			}
		}
		val.Apply();
		return val;
	}

	private void Update()
	{
		if (!targetingDone && Time.frameCount > bornFrame + 2)
		{
			targetingDone = true;
			ApplyTargeting();
		}
		if (iconPending && Time.frameCount >= bornFrame + 3)
		{
			iconPending = false;
			ApplyIconMaterial();
		}
		KeepReleasing();
		if ((Object)(object)droneComp == (Object)null)
		{
			droneComp = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		}
		object obj = ((charge > 0) ? DetectAttached() : null);
		if (stunned != null && !ReleaseOnDetach && !Heal && !Defense)
		{
			object obj2 = stunned;
			Component val = (Component)((obj2 is Component) ? obj2 : null);
			obj = (((Object)(object)val != (Object)null && (Object)(object)val.gameObject != (Object)null && charge > 0 && ToggleOn()) ? stunned : null);
		}
		if (capped && obj == null)
		{
			capped = false;
		}
		if (capped)
		{
			obj = null;
		}
		if (stunned != null && !object.ReferenceEquals(stunned, obj))
		{
			Release(stunned);
			stunned = null;
		}
		if (obj != null && stunned == null)
		{
			if (object.ReferenceEquals(relTarget, obj))
			{
				relTarget = null;
			}
			stunned = obj;
			attachStart = Time.time;
			holdTimer = 0f;
			drainTimer = 0f;
			Debug.Log((object)string.Concat("[StunDrone] attached to ", obj, ", charge=", charge));
		}
		attachedObj = stunned;
		if (stunned == null)
		{
			return;
		}
		float num = (Defense ? DefBarSeconds : BarSeconds);
		if (!Heal)
		{
			drainTimer += Time.deltaTime;
		}
		if (!Heal && drainTimer >= num)
		{
			drainTimer = 0f;
			charge--;
			Debug.Log((object)("[StunDrone] charge=" + charge));
			if (charge <= 0)
			{
				Debug.Log((object)("[StunDrone] charge empty, releasing " + stunned));
				Release(stunned);
				stunned = null;
				attachedObj = null;
				return;
			}
		}
		if (Heal)
		{
			HealTick();
			return;
		}
		if (Defense)
		{
			object obj3 = stunned;
			PlayerAvatar val2 = (PlayerAvatar)((obj3 is PlayerAvatar) ? obj3 : null);
			if ((Object)(object)val2 != (Object)null)
			{
				DefenseTick(val2);
			}
			return;
		}
		object obj4 = stunned;
		PlayerAvatar val3 = (PlayerAvatar)((obj4 is PlayerAvatar) ? obj4 : null);
		if ((Object)(object)val3 != (Object)null)
		{
			StunPlayer(val3);
			return;
		}
		holdTimer -= Time.deltaTime;
		if (!(holdTimer > 0f))
		{
			holdTimer = 0.2f;
			object obj5 = stunned;
			Enemy val4 = (Enemy)((obj5 is Enemy) ? obj5 : null);
			if ((Object)(object)val4 != (Object)null)
			{
				StunEnemy(val4);
			}
		}
	}

	public void DumpState(ManualLogSource log)
	{
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine(string.Concat("==== ", DateTime.Now.ToString("HH:mm:ss"), "  mode=", mode, " charge=", charge, " stunned=", stunned, " toggleOn=", ToggleOn()));
		if ((Object)(object)droneComp == (Object)null)
		{
			droneComp = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		}
		if ((Object)(object)droneComp != (Object)null)
		{
			Type type = ((object)droneComp).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object obj = null;
					try
					{
						obj = fieldInfo.GetValue(droneComp);
					}
					catch
					{
					}
					stringBuilder.AppendLine("  ItemDrone." + fieldInfo.Name + " (" + fieldInfo.FieldType.Name + ") = " + ((obj == null) ? "null" : obj.ToString()));
				}
				type = type.BaseType;
			}
		}
		LineRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<LineRenderer>(true);
		foreach (LineRenderer val in componentsInChildren)
		{
			stringBuilder.AppendLine("  LineRenderer " + ((Object)val).name + " enabled=" + ((Renderer)val).enabled + " active=" + ((Component)val).gameObject.activeInHierarchy + " points=" + val.positionCount + ((val.positionCount >= 2) ? string.Concat(" p0=", val.GetPosition(0), " pN=", val.GetPosition(val.positionCount - 1), " worldSpace=", val.useWorldSpace) : ""));
		}
		MonoBehaviour[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val2 in componentsInChildren2)
		{
			if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)this || (Object)(object)val2 == (Object)(object)droneComp)
			{
				continue;
			}
			string name = ((object)val2).GetType().Name;
			if (name.IndexOf("Line", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Magnet", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Drone", StringComparison.OrdinalIgnoreCase) < 0)
			{
				continue;
			}
			Type type = ((object)val2).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object obj = null;
					try
					{
						obj = fieldInfo.GetValue(val2);
					}
					catch
					{
					}
					stringBuilder.AppendLine("  " + name + "." + fieldInfo.Name + " (" + fieldInfo.FieldType.Name + ") = " + ((obj == null) ? "null" : obj.ToString()));
				}
				type = type.BaseType;
			}
		}
		try
		{
			string text = Path.Combine(Paths.BepInExRootPath, "StunDrone_state.txt");
			File.AppendAllText(text, stringBuilder.ToString());
			log.LogInfo((object)("State dumped: " + text));
		}
		catch (Exception ex)
		{
			log.LogError((object)("State dump failed: " + ex.Message));
		}
	}

	private void KeepReleasing()
	{
		if (relTarget == null)
		{
			return;
		}
		if (Time.time > relUntil)
		{
			relTarget = null;
		}
		else
		{
			if (Time.time < relNext)
			{
				return;
			}
			relNext = Time.time + 0.2f;
			object obj = relTarget;
			PlayerAvatar val = (PlayerAvatar)((obj is PlayerAvatar) ? obj : null);
			if (!((Object)(object)val == (Object)null))
			{
				Component val2 = FindTumble(val);
				if ((Object)(object)val2 != (Object)null)
				{
					CallMethod(val2, "TumbleOverrideTime", 0f);
					CallMethod(val2, "TumbleRequest", false, false);
				}
			}
		}
	}

	private void OnDisable()
	{
		if (stunned != null)
		{
			Release(stunned);
			stunned = null;
		}
	}

	private void OnDestroy()
	{
		if (stunned != null)
		{
			Release(stunned);
			stunned = null;
		}
	}

	private void Release(object target)
	{
		if (Heal)
		{
			return;
		}
		if (Defense)
		{
			ClearDefense(target);
			return;
		}
		relTarget = target;
		relUntil = Time.time + 1.2f;
		relNext = Time.time + 0.2f;
		try
		{
			PlayerAvatar val = (PlayerAvatar)((target is PlayerAvatar) ? target : null);
			if ((Object)(object)val != (Object)null)
			{
				Component val2 = FindTumble(val);
				if ((Object)(object)val2 != (Object)null)
				{
					CallMethod(val2, "TumbleOverrideTime", 0f);
					CallMethod(val2, "TumbleRequest", false, false);
				}
				Debug.Log((object)"[StunDrone] released player");
			}
			Enemy val3 = (Enemy)((target is Enemy) ? target : null);
			if (!((Object)(object)val3 != (Object)null))
			{
				return;
			}
			Component val4 = FindStun((Component)(object)val3);
			if ((Object)(object)val4 != (Object)null)
			{
				Type type = ((object)val4).GetType();
				while (type != null && type != typeof(MonoBehaviour))
				{
					FieldInfo field = type.GetField("stunTimer", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.FieldType == typeof(float))
					{
						field.SetValue(val4, 0.05f);
					}
					type = type.BaseType;
				}
			}
			MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)val3)).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val5 in componentsInChildren)
			{
				if ((Object)(object)val5 == (Object)null)
				{
					continue;
				}
				Type type = ((object)val5).GetType();
				while (type != null && type != typeof(MonoBehaviour))
				{
					FieldInfo field = type.GetField("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.FieldType == typeof(bool))
					{
						field.SetValue(val5, false);
					}
					PropertyInfo property = type.GetProperty("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null && property.PropertyType == typeof(bool) && property.CanWrite)
					{
						try
						{
							property.SetValue(val5, false, null);
						}
						catch
						{
						}
					}
					type = type.BaseType;
				}
			}
			Debug.Log((object)"[StunDrone] released enemy");
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[StunDrone] Release: " + ex.Message));
		}
	}

	private object DetectAttached()
	{
		object obj = null;
		if (!ToggleOn())
		{
			return null;
		}
		object obj2 = stunned;
		PlayerAvatar val = (PlayerAvatar)((obj2 is PlayerAvatar) ? obj2 : null);
		if ((Object)(object)val != (Object)null && IsHolder(val))
		{
			return val;
		}
		if ((Object)(object)droneComp != (Object)null)
		{
			Type type = ((object)droneComp).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object value;
					try
					{
						value = fieldInfo.GetValue(droneComp);
					}
					catch
					{
						continue;
					}
					Object val2 = (Object)((value is Object) ? value : null);
					IList list = value as IList;
					if (val2 == (Object)null && list != null)
					{
						foreach (object item in list)
						{
							val2 = (Object)((item is Object) ? item : null);
							if (val2 != (Object)null)
							{
								break;
							}
						}
					}
					if (val2 == (Object)null || val2 == (Object)(object)droneComp || val2 == (Object)(object)((Component)this).gameObject)
					{
						continue;
					}
					Component val3 = (Component)(object)((val2 is Component) ? val2 : null);
					GameObject val4 = (GameObject)(object)((val2 is GameObject) ? val2 : null);
					if ((Object)(object)val3 == (Object)null && (Object)(object)val4 != (Object)null)
					{
						val3 = (Component)(object)val4.transform;
					}
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					PlayerAvatar componentInParent = val3.GetComponentInParent<PlayerAvatar>();
					if ((Object)(object)componentInParent == (Object)null)
					{
						Component componentInParent2 = val3.GetComponentInParent(Registrar.FindType("PlayerTumble") ?? typeof(Transform));
						if ((Object)(object)componentInParent2 != (Object)null)
						{
							componentInParent = componentInParent2.GetComponentInParent<PlayerAvatar>();
						}
					}
					if ((Object)(object)componentInParent != (Object)null && !IsHolder(componentInParent))
					{
						obj = componentInParent;
						if (!loggedScan)
						{
							loggedScan = true;
							Debug.Log((object)("[StunDrone] target field (player): ItemDrone." + fieldInfo.Name));
						}
						break;
					}
					Enemy val5 = ((Heal || Defense) ? null : EnemyFrom(val3));
					if (!((Object)(object)val5 != (Object)null))
					{
						continue;
					}
					obj = val5;
					if (!loggedScan)
					{
						loggedScan = true;
						Debug.Log((object)("[StunDrone] target field (enemy): ItemDrone." + fieldInfo.Name));
					}
					break;
				}
				if (obj != null)
				{
					break;
				}
				type = type.BaseType;
			}
		}
		if (obj != null && StrictBeam && !BeamOnTarget(obj))
		{
			if (Time.time > nextBeamLog)
			{
				nextBeamLog = Time.time + 2f;
				Debug.Log((object)string.Concat("[StunDrone] ItemDrone still references ", obj, " but the beam is not on it -> not attached"));
			}
			obj = null;
		}
		if (obj != null)
		{
			return obj;
		}
		if ((Object)(object)droneComp != (Object)null && Time.time > nextDiag && LineOn() && ToggleOn())
		{
			nextDiag = Time.time + 3f;
			StringBuilder stringBuilder = new StringBuilder("[StunDrone] no target found; ItemDrone fields: ");
			Type type = ((object)droneComp).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object value = null;
					try
					{
						value = fieldInfo.GetValue(droneComp);
					}
					catch
					{
					}
					stringBuilder.Append(fieldInfo.Name).Append('=').Append((value == null) ? "null" : value.ToString())
						.Append("; ");
				}
				type = type.BaseType;
			}
			Debug.Log((object)stringBuilder.ToString());
		}
		return null;
	}

	private bool ToggleOn()
	{
		Type type = Registrar.FindType("ItemToggle");
		if (type == null)
		{
			return true;
		}
		Component val = ((Component)this).GetComponentInChildren(type, true);
		if ((Object)(object)val == (Object)null)
		{
			val = ((Component)this).GetComponentInParent(type);
		}
		if ((Object)(object)val == (Object)null)
		{
			return true;
		}
		Type type2 = ((object)val).GetType();
		while (type2 != null)
		{
			FieldInfo field = type2.GetField("toggleState", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(bool))
			{
				return (bool)field.GetValue(val);
			}
			type2 = type2.BaseType;
		}
		return true;
	}

	private bool IsHolder(PlayerAvatar p)
	{
		try
		{
			Type type = Registrar.FindType("PhysGrabObject");
			if (type == null)
			{
				return false;
			}
			Component val = ((Component)this).GetComponentInParent(type);
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)this).GetComponentInChildren(type, true);
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			FieldInfo field = ((object)val).GetType().GetField("playerGrabbing", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			IList list = ((field != null) ? (field.GetValue(val) as IList) : null);
			if (list == null)
			{
				return false;
			}
			foreach (object item in list)
			{
				if (item == null)
				{
					continue;
				}
				Component val2 = (Component)((item is Component) ? item : null);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				PlayerAvatar val3 = val2.GetComponentInParent<PlayerAvatar>();
				if ((Object)(object)val3 == (Object)null)
				{
					FieldInfo field2 = item.GetType().GetField("playerAvatar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field2 != null)
					{
						object? value = field2.GetValue(item);
						val3 = (PlayerAvatar)((value is PlayerAvatar) ? value : null);
					}
				}
				if (!((Object)(object)val3 == (Object)(object)p))
				{
					continue;
				}
				return true;
			}
		}
		catch
		{
		}
		return false;
	}

	private static Transform EnemyRoot(Component e)
	{
		Type type = Registrar.FindType("EnemyParent");
		if (type != null)
		{
			Component componentInParent = e.GetComponentInParent(type);
			if ((Object)(object)componentInParent != (Object)null)
			{
				return componentInParent.transform;
			}
		}
		Transform val = null;
		Transform val2 = e.transform;
		while ((Object)(object)val2 != (Object)null)
		{
			if (((Object)val2).name.StartsWith("Enemy"))
			{
				val = val2;
			}
			val2 = val2.parent;
		}
		return ((Object)(object)val != (Object)null) ? val : e.transform.root;
	}

	private static Transform TargetRoot(Component c)
	{
		return (c is Enemy) ? EnemyRoot(c) : c.transform.root;
	}

	private static Component FindStun(Component e)
	{
		Component val = null;
		StringBuilder stringBuilder = (stunLogged ? null : new StringBuilder("[StunDrone] enemy state components: "));
		MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot(e)).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val2 in componentsInChildren)
		{
			if (!((Object)(object)val2 == (Object)null))
			{
				string name = ((object)val2).GetType().Name;
				if (stringBuilder != null && name.StartsWith("EnemyState"))
				{
					stringBuilder.Append(name).Append("; ");
				}
				if ((Object)(object)val == (Object)null && name.StartsWith("EnemyState") && name.ToLower().Contains("stun"))
				{
					val = (Component)(object)val2;
				}
			}
		}
		if (stringBuilder != null)
		{
			stunLogged = true;
			Debug.Log((object)(stringBuilder.ToString() + " -> stun: " + (((Object)(object)val != (Object)null) ? ((object)val).GetType().Name : "NOT FOUND")));
		}
		return val;
	}

	private static Enemy EnemyFrom(Component c)
	{
		Enemy componentInParent = c.GetComponentInParent<Enemy>();
		if ((Object)(object)componentInParent != (Object)null)
		{
			return componentInParent;
		}
		Type type = Registrar.FindType("EnemyParent");
		if (type != null)
		{
			Component componentInParent2 = c.GetComponentInParent(type);
			if ((Object)(object)componentInParent2 != (Object)null)
			{
				componentInParent = componentInParent2.GetComponentInChildren<Enemy>(true);
				if ((Object)(object)componentInParent != (Object)null)
				{
					return componentInParent;
				}
			}
		}
		Transform val = c.transform;
		while ((Object)(object)val != (Object)null)
		{
			MonoBehaviour[] components = ((Component)val).GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val2 in components)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Type type2 = ((object)val2).GetType();
				while (type2 != null && type2 != typeof(MonoBehaviour))
				{
					FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo in fields)
					{
						if (fieldInfo.FieldType == typeof(Enemy))
						{
							object? value = fieldInfo.GetValue(val2);
							Enemy val3 = (Enemy)((value is Enemy) ? value : null);
							if ((Object)(object)val3 != (Object)null)
							{
								return val3;
							}
						}
					}
					type2 = type2.BaseType;
				}
			}
			val = val.parent;
		}
		return null;
	}

	private bool BeamOnTarget(object target)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_009b: 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_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_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_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: 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_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		Component val = (Component)((target is Component) ? target : null);
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		bool flag = false;
		Bounds bounds = default(Bounds);
		((Bounds)(ref bounds))..ctor(val.transform.position, Vector3.one * 0.5f);
		bool flag2 = true;
		Renderer[] componentsInChildren = ((Component)TargetRoot(val)).GetComponentsInChildren<Renderer>(false);
		foreach (Renderer val2 in componentsInChildren)
		{
			if (!((Object)(object)val2 == (Object)null) && !(val2 is ParticleSystemRenderer) && !(val2 is LineRenderer))
			{
				if (flag2)
				{
					bounds = val2.bounds;
					flag2 = false;
				}
				else
				{
					((Bounds)(ref bounds)).Encapsulate(val2.bounds);
				}
			}
		}
		LineRenderer[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<LineRenderer>(false);
		foreach (LineRenderer val3 in componentsInChildren2)
		{
			if (!((Object)(object)val3 == (Object)null) && ((Renderer)val3).enabled && ((Component)val3).gameObject.activeInHierarchy && val3.positionCount >= 2)
			{
				flag = true;
				Vector3 val4 = val3.GetPosition(0);
				Vector3 val5 = val3.GetPosition(val3.positionCount - 1);
				if (!val3.useWorldSpace)
				{
					val4 = ((Component)val3).transform.TransformPoint(val4);
					val5 = ((Component)val3).transform.TransformPoint(val5);
				}
				if (!(Vector3.Distance(val4, val5) < 0.3f) && (((Bounds)(ref bounds)).SqrDistance(val4) < 4f || ((Bounds)(ref bounds)).SqrDistance(val5) < 4f))
				{
					return true;
				}
			}
		}
		if (!flag && Time.time > nextBeamLog)
		{
			nextBeamLog = Time.time + 2f;
			Debug.Log((object)"[StunDrone] no active LineRenderer on drone");
		}
		return false;
	}

	private bool LineOn()
	{
		Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(false);
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name == "Line" && ((Component)val).gameObject.activeInHierarchy)
			{
				return true;
			}
		}
		return false;
	}

	private static bool BoolMember(object o, string name)
	{
		Type type = o.GetType();
		while (type != null)
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(bool))
			{
				return (bool)field.GetValue(o);
			}
			PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.PropertyType == typeof(bool) && property.CanRead && property.GetIndexParameters().Length == 0)
			{
				try
				{
					return (bool)property.GetValue(o, null);
				}
				catch
				{
					return false;
				}
			}
			type = type.BaseType;
		}
		return false;
	}

	private static Component FindComp(Component c, string typeName)
	{
		Type type = Registrar.FindType(typeName);
		if (type == null)
		{
			return null;
		}
		Component val = c.GetComponentInChildren(type, true);
		if ((Object)(object)val == (Object)null)
		{
			val = c.GetComponentInParent(type);
		}
		if ((Object)(object)val == (Object)null)
		{
			val = ((Component)c.transform.root).GetComponentInChildren(type, true);
		}
		return val;
	}

	private static bool CallMethod(object o, string name, params object[] args)
	{
		Type type = o.GetType();
		while (type != null)
		{
			MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name != name)
				{
					continue;
				}
				ParameterInfo[] parameters = methodInfo.GetParameters();
				if (parameters.Length >= args.Length)
				{
					object[] array = new object[parameters.Length];
					for (int j = 0; j < parameters.Length; j++)
					{
						array[j] = ((j < args.Length) ? args[j] : (parameters[j].IsOptional ? parameters[j].DefaultValue : null));
					}
					try
					{
						methodInfo.Invoke(o, array);
						return true;
					}
					catch (Exception ex)
					{
						Debug.LogWarning((object)("[StunDrone] " + name + " threw: " + ((ex.InnerException != null) ? ex.InnerException.Message : ex.Message)));
					}
				}
			}
			type = type.BaseType;
		}
		return false;
	}

	private static Component FindTumble(PlayerAvatar p)
	{
		Type type = ((object)p).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.Name == "PlayerTumble")
				{
					object? value = fieldInfo.GetValue(p);
					Component val = (Component)((value is Component) ? value : null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
			PropertyInfo[] properties = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (!(propertyInfo.PropertyType.Name == "PlayerTumble") || !propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length != 0)
				{
					continue;
				}
				try
				{
					object? value2 = propertyInfo.GetValue(p, null);
					Component val = (Component)((value2 is Component) ? value2 : null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				catch
				{
				}
			}
			type = type.BaseType;
		}
		Component val2 = FindComp((Component)(object)p, "PlayerTumble");
		if ((Object)(object)val2 != (Object)null)
		{
			return val2;
		}
		Type type2 = Registrar.FindType("PlayerTumble");
		if (type2 == null)
		{
			return null;
		}
		Object[] array = Object.FindObjectsByType(type2, (FindObjectsSortMode)0);
		foreach (Object val3 in array)
		{
			Component val4 = (Component)(object)((val3 is Component) ? val3 : null);
			if ((Object)(object)val4 == (Object)null)
			{
				continue;
			}
			Type type3 = ((object)val4).GetType();
			while (type3 != null && type3 != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type3.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo2 in fields)
				{
					if (fieldInfo2.FieldType == typeof(PlayerAvatar) && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)p)
					{
						return val4;
					}
				}
				type3 = type3.BaseType;
			}
		}
		return null;
	}

	private PlayerAvatar FindNearestPlayer()
	{
		//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)
		PlayerAvatar result = null;
		float num = 6f;
		PlayerAvatar[] array = Object.FindObjectsByType<PlayerAvatar>((FindObjectsSortMode)0);
		foreach (PlayerAvatar val in array)
		{
			if (!BoolMember(val, "isDisabled") && !BoolMember(val, "deadSet") && !((Object)(object)FindTumble(val) == (Object)null))
			{
				float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = val;
				}
			}
		}
		return result;
	}

	private Enemy FindNearestEnemy(bool skipStunned)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		Enemy result = null;
		float num = 6f;
		Enemy[] array = Object.FindObjectsByType<Enemy>((FindObjectsSortMode)0);
		foreach (Enemy val in array)
		{
			if (!skipStunned || !val.IsStunned())
			{
				float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = val;
				}
			}
		}
		return result;
	}

	private static bool IsDronePartName(string n)
	{
		n = n.Replace('_', ' ').Trim();
		return n == "Drone" || n.StartsWith("Drone Triangle") || n.StartsWith("Drone Pyramid") || n.StartsWith("Drone Icon");
	}

	private void AddBatteryRefs(object v)
	{
		if (v == null)
		{
			return;
		}
		if (v is IEnumerable enumerable && !(v is string) && !(v is Object))
		{
			foreach (object item2 in enumerable)
			{
				AddBatteryRefs(item2);
			}
			return;
		}
		Object val = (Object)((v is Object) ? v : null);
		if (val == (Object)null)
		{
			return;
		}
		Transform val2 = null;
		Renderer val3 = (Renderer)(object)((val is Renderer) ? val : null);
		if ((Object)(object)val3 != (Object)null)
		{
			batRend.Add(val3);
			return;
		}
		Component val4 = (Component)(object)((val is Component) ? val : null);
		if ((Object)(object)val4 != (Object)null)
		{
			val2 = val4.transform;
		}
		GameObject val5 = (GameObject)(object)((val is GameObject) ? val : null);
		if ((Object)(object)val5 != (Object)null)
		{
			val2 = val5.transform;
		}
		if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)((Component)this).transform) && !((Component)this).transform.IsChildOf(val2) && !IsDronePartName(((Object)val2).name))
		{
			Renderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer item in componentsInChildren)
			{
				batRend.Add(item);
			}
		}
	}

	private void CollectBatteryRenderers()
	{
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)this)
			{
				continue;
			}
			string name = ((object)val).GetType().Name;
			if (name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) < 0)
			{
				continue;
			}
			if (name.IndexOf("Visual", StringComparison.OrdinalIgnoreCase) >= 0 && (Object)(object)((Component)val).transform != (Object)(object)((Component)this).transform && !IsDronePartName(((Object)((Component)val).transform).name))
			{
				Renderer[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer item in componentsInChildren2)
				{
					batRend.Add(item);
				}
			}
			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.IsPrimitive && !(fieldInfo.FieldType == typeof(string)))
					{
						object v = null;
						try
						{
							v = fieldInfo.GetValue(val);
						}
						catch
						{
						}
						AddBatteryRefs(v);
					}
				}
				type = type.BaseType;
			}
		}
		Debug.Log((object)("[StunDrone] battery renderers excluded from retexture: " + batRend.Count));
	}

	private bool IsBatteryRenderer(Renderer r)
	{
		if (batRend.Contains(r) || IsUnder(((Component)r).transform, "Battery") || IsUnder(((Component)r).transform, "Bar"))
		{
			return true;
		}
		Transform val = ((Component)r).transform;
		while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)((Component)this).transform)
		{
			MonoBehaviour[] components = ((Component)val).GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val2 in components)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)this && ((object)val2).GetType().Name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					batRend.Add(r);
					return true;
				}
			}
			val = val.parent;
		}
		return false;
	}

	private static bool IsUnder(Transform t, string part)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name.IndexOf(part, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private static int[] ColorProps(Material m)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Invalid comparison between Unknown and I4
		List<int> list = new List<int>();
		Shader val = (((Object)(object)m != (Object)null) ? m.shader : null);
		if ((Object)(object)val == (Object)null)
		{
			return list.ToArray();
		}
		int propertyCount = val.GetPropertyCount();
		for (int i = 0; i < propertyCount; i++)
		{
			if ((int)val.GetPropertyType(i) == 0)
			{
				list.Add(Shader.PropertyToID(val.GetPropertyName(i)));
			}
		}
		return list.ToArray();
	}

	private static Gradient SolidGradient(Color c)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		Gradient val = new Gradient();
		val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
		{
			new GradientColorKey(c, 0f),
			new GradientColorKey(c, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
		{
			new GradientAlphaKey(1f, 0f),
			new GradientAlphaKey(1f, 1f)
		});
		return val;
	}

	private void TintBeams()
	{
		//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_013e: 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_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		if (Time.time > nextBeamFind)
		{
			nextBeamFind = Time.time + 1f;
			beamList.Clear();
			Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !IsUnder(((Component)val).transform, "Drone Icon") && !IsBatteryRenderer(val) && (val is LineRenderer || val is ParticleSystemRenderer || val is TrailRenderer || Classify(((Component)val).transform) == Part.Skip))
				{
					beamList.Add(val);
				}
			}
		}
		Color orange = Orange;
		foreach (Renderer beam in beamList)
		{
			if (!((Object)(object)beam == (Object)null))
			{
				LineRenderer val2 = (LineRenderer)(object)((beam is LineRenderer) ? beam : null);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.startColor = orange;
					val2.endColor = orange;
					val2.colorGradient = SolidGradient(orange);
				}
				Material material = beam.material;
				if (!beamProps.TryGetValue(beam, out var value))
				{
					value = ColorProps(material);
					beamProps[beam] = value;
				}
				int[] array = value;
				foreach (int num in array)
				{
					Color color = material.GetColor(num);
					material.SetColor(num, new Color(orange.r, orange.g, orange.b, color.a));
				}
			}
		}
	}

	private void ApplyDroneFieldColors()
	{
		//IL_0100: 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)
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] drone color fields: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)this)
			{
				continue;
			}
			string name = ((object)val).GetType().Name;
			if (name == "ItemAttributes" || name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) >= 0 || val is Graphic)
			{
				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)
				{
					string text = fieldInfo.Name.ToLower();
					if (fieldInfo.FieldType == typeof(Color) && text.Contains("color"))
					{
						fieldInfo.SetValue(val, Orange);
						if (!fieldColorLogged)
						{
							stringBuilder.Append(name).Append('.').Append(fieldInfo.Name)
								.Append("; ");
						}
					}
					else if (fieldInfo.FieldType == typeof(Gradient) && (text.Contains("color") || text.Contains("gradient")))
					{
						fieldInfo.SetValue(val, SolidGradient(Orange));
						if (!fieldColorLogged)
						{
							stringBuilder.Append(name).Append('.').Append(fieldInfo.Name)
								.Append("(gradient); ");
						}
					}
				}
				type = type.BaseType;
			}
		}
		if (!fieldColorLogged)
		{
			fieldColorLogged = true;
			Debug.Log((object)stringBuilder.ToString());
		}
	}

	private static void SetNum(object o, string name, float v)
	{
		Type type = o.GetType();
		while (type != null && type != typeof(MonoBehaviour))
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(field == null))
			{
				if (field.FieldType == typeof(float))
				{
					field.SetValue(o, v);
				}
				else if (field.FieldType == typeof(int))
				{
					field.SetValue(o, Mathf.RoundToInt(v));
				}
				break;
			}
			type = type.BaseType;
		}
	}

	private static bool GetNum(object o, string name, out float v)
	{
		v = 0f;
		Type type = o.GetType();
		while (type != null && type != typeof(MonoBehaviour))
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(field == null))
			{
				if (field.FieldType == typeof(float))
				{
					v = (float)field.GetValue(o);
					return true;
				}
				if (field.FieldType == typeof(int))
				{
					v = (int)field.GetValue(o);
					return true;
				}
				return false;
			}
			type = type.BaseType;
		}
		return false;
	}

	private void SyncBattery()
	{
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)batteryComp == (Object)null)
		{
			if (Time.time < nextBatFind)
			{
				return;
			}
			nextBatFind = Time.time + 1f;
			MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && ((object)val).GetType().Name == "ItemBattery")
				{
					batteryComp = (Component)(object)val;
					break;
				}
			}
			if ((Object)(object)batteryComp == (Object)null)
			{
				return;
			}
		}
		if (!batteryLogged)
		{
			batteryLogged = true;
			Debug.Log((object)("[StunDrone] ItemBattery found, bars=" + Cap));
		}
		SetNum(batteryComp, "batteryBars", Cap);
		if (!uiDumped && Time.time > nextBatFind + 3f && batteryLogged)
		{
			uiDumped = true;
			StringBuilder stringBuilder = new StringBuilder("[StunDrone] battery UI dump: ");
			Graphic[] componentsInChildren2 = batteryComp.GetComponentsInChildren<Graphic>(true);
			foreach (Graphic val2 in componentsInChildren2)
			{
				string text = ((Object)val2).name;
				Transform parent = ((Component)val2).transform.parent;
				while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)batteryComp.transform)
				{
					text = ((Object)parent).name + "/" + text;
					parent = parent.parent;
				}
				stringBuilder.Append(text).Append(" [").Append(((object)val2).GetType().Name)
					.Append(((Component)val2).gameObject.activeInHierarchy ? "" : ",off")
					.Append(", ")
					.Append(val2.color)
					.Append("]; ");
			}
			Debug.Log((object)stringBuilder.ToString());
		}
		float v;
		if (lifeVal < 0f)
		{
			if (GetNum(batteryComp, "batteryLife", out v) && v >= 0f && v <= 100f)
			{
				lifeVal = v;
				charge = Mathf.Clamp(Mathf.FloorToInt(v * (float)Cap / 100f + 0.001f), 0, Cap);
				Debug.Log((object)("[StunDrone] restored charge " + charge + "/" + Cap + " from batteryLife=" + v));
			}
			else
			{
				lifeVal = 100f * (float)charge / (float)Cap;
			}
			lastCharge = charge;
		}
		if (GetNum(batteryComp, "batteryLife", out v) && v > lifeVal + 0.01f)
		{
			lifeVal = Mathf.Min(100f, v);
			charge = Mathf.Clamp(Mathf.FloorToInt(lifeVal * (float)Cap / 100f + 0.001f), 0, Cap);
		}
		else if (charge < lastCharge)
		{
			lifeVal = 100f * (float)charge / (float)Cap;
		}
		else if (charge > lastCharge)
		{
			lifeVal = Mathf.Max(lifeVal, 100f * (float)charge / (float)Cap);
		}
		if (lifeVal >= 99.5f)
		{
			lifeVal = 100f;
			charge = Cap;
		}
		lastCharge = charge;
		SetNum(batteryComp, "batteryLife", lifeVal);
		if (charge >= Cap)
		{
			SetNum(batteryComp, "batteryLifeInt", Cap);
		}
		if (Time.time > nextBatDump && charge != dumpedCharge)
		{
			nextBatDump = Time.time + 2f;
			dumpedCharge = charge;
			StringBuilder stringBuilder2 = new StringBuilder("[StunDrone] ItemBattery dump (charge=" + charge + "/" + Cap + "): ");
			Type type = ((object)batteryComp).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) || fieldInfo.FieldType == typeof(int) || fieldInfo.FieldType == typeof(bool))
					{
						stringBuilder2.Append(string.Concat(fieldInfo.Name, "=", fieldInfo.GetValue(batteryComp), "; "));
					}
				}
				type = type.BaseType;
			}
			Debug.Log((object)stringBuilder2.ToString());
		}
		Type type2 = ((object)batteryComp).GetType();
		while (type2 != null && type2 != typeof(MonoBehaviour))
		{
			FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo2 in fields)
			{
				if (fieldInfo2.FieldType == typeof(float) && fieldInfo2.Name.ToLower().Contains("drain"))
				{
					fieldInfo2.SetValue(batteryComp, 0f);
				}
			}
			type2 = type2.BaseType;
		}
	}

	private static bool IsAuthority()
	{
		try
		{
			return !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient;
		}
		catch
		{
			return true;
		}
	}

	private static bool IntMember(object o, string name, out int v)
	{
		v = 0;
		Type type = o.GetType();
		while (type != null)
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(int))
			{
				v = (int)field.GetValue(o);
				return true;
			}
			PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.PropertyType == typeof(int) && property.CanRead && property.GetIndexParameters().Length == 0)
			{
				try
				{
					v = (int)property.GetValue(o, null);
					return true;
				}
				catch
				{
					return false;
				}
			}
			type = type.BaseType;
		}
		return false;
	}

	private static Component FindHealth(PlayerAvatar p)
	{
		Type type = ((object)p).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.Name == "PlayerHealth")
				{
					object? value = fieldInfo.GetValue(p);
					Component val = (Component)((value is Component) ? value : null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
			type = type.BaseType;
		}
		return FindComp((Component)(object)p, "PlayerHealth");
	}

	private bool NeedsHeal(PlayerAvatar p)
	{
		if ((Object)(object)p == (Object)null)
		{
			return false;
		}
		if (BoolMember(p, "isDisabled") || BoolMember(p, "deadSet"))
		{
			return false;
		}
		Component val = FindHealth(p);
		if ((Object)(object)val == (Object)null)
		{
			return true;
		}
		if (IntMember(val, "health", out var v) && IntMember(val, "maxHealth", out var v2))
		{
			return v < v2;
		}
		return true;
	}

	private void HealTick()
	{
		object obj = stunned;
		PlayerAvatar val = (PlayerAvatar)((obj is PlayerAvatar) ? obj : null);
		if ((Object)(object)val == (Object)null || Time.time < nextHeal)
		{
			return;
		}
		nextHeal = Time.time + HealInterval;
		if (!IsAuthority() || !NeedsHeal(val))
		{
			return;
		}
		Component val2 = FindHealth(val);
		if ((Object)(object)val2 == (Object)null)
		{
			if (!healWarned)
			{
				healWarned = true;
				Debug.LogWarning((object)"[HealDrone] PlayerHealth not found");
			}
		}
		else if (CallMethod(val2, "Heal", HealAmount, true) || CallMethod(val2, "Heal", HealAmount))
		{
			charge--;
			Debug.Log((object)("[HealDrone] healed " + HealAmount + " HP, charge=" + charge));
		}
		else if (!healWarned)
		{
			healWarned = true;
			Debug.LogWarning((object)"[HealDrone] PlayerHealth.Heal call failed");
		}
	}

	private void StunPlayer(PlayerAvatar p)
	{
		try
		{
			if ((Object)(object)tumbleCache == (Object)null || (Object)(object)cachedFor != (Object)(object)p)
			{
				tumbleCache = FindTumble(p);
				cachedFor = p;
			}
			Component val = tumbleCache;
			if ((Object)(object)val == (Object)null)
			{
				if (!tumbleWarned)
				{
					tumbleWarned = true;
					Debug.LogWarning((object)"[StunDrone] PlayerTumble not found");
				}
				return;
			}
			if (!CallMethod(val, "TumbleRequest", true, true) && !tumbleWarned)
			{
				tumbleWarned = true;
				Debug.LogWarning((object)"[StunDrone] TumbleRequest call failed");
			}
			CallMethod(val, "TumbleOverrideTime", 3f);
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[StunDrone] StunPlayer: " + ex.Message));
		}
	}

	private void StunEnemy(Enemy e)
	{
		try
		{
			Component val = FindStun((Component)(object)e);
			if ((Object)(object)val != (Object)null && CallMethod(val, "Set", 1.5f))
			{
				if (!stunOk)
				{
					stunOk = true;
					Debug.Log((object)("[StunDrone] enemy stunned via " + ((object)val).GetType().Name + ".Set on " + ((Object)e).name));
				}
				return;
			}
			if ((Object)(object)val != (Object)null && !stunWarned2)
			{
				stunWarned2 = true;
				StringBuilder stringBuilder = new StringBuilder("[StunDrone] " + ((object)val).GetType().Name + " methods: ");
				MethodInfo[] methods = ((object)val).GetType().GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					stringBuilder.Append(methodInfo.Name).Append('(');
					ParameterInfo[] parameters = methodInfo.GetParameters();
					foreach (ParameterInfo parameterInfo in parameters)
					{
						stringBuilder.Append(parameterInfo.ParameterType.Name).Append(' ');
					}
					stringBuilder.Append("); ");
				}
				Debug.LogWarning((object)stringBuilder.ToString());
			}
			if ((Object)(object)val == (Object)null && !noStunLogged.Contains(((Object)e).name))
			{
				noStunLogged.Add(((Object)e).name);
				Debug.LogWarning((object)("[StunDrone] enemy '" + ((Object)e).name + "' has no stun state -> freezing manually"));
			}
			FreezeEnemy(e);
			bool flag = false;
			MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val2 in componentsInChildren)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Type type = ((object)val2).GetType();
				while (type != null && type != typeof(MonoBehaviour))
				{
					FieldInfo field = type.GetField("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.FieldType == typeof(bool))
					{
						field.SetValue(val2, true);
						flag = true;
					}
					PropertyInfo property = type.GetProperty("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null && property.PropertyType == typeof(bool) && property.CanWrite)
					{
						try
						{
							property.SetValue(val2, true, null);
							flag = true;
						}
						catch
						{
						}
					}
					type = type.BaseType;
				}
			}
			if (!flag)
			{
				Debug.LogWarning((object)"[StunDrone] no way to stun enemy (no EnemyState*Stun*, no Stunned flag)");
			}
			else if (!stunWarned)
			{
				stunWarned = true;
				Debug.LogWarning((object)"[StunDrone] used Stunned flag fallback (state component not found) - may not actually stop the AI");
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[StunDrone] StunEnemy: " + ex.Message));
		}
	}

	private void FreezeEnemy(Enemy e)
	{
		//IL_00b9: 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)
		MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)null))
			{
				string name = ((object)val).GetType().Name;
				if (name == "EnemyNavMeshAgent")
				{
					CallMethod(val, "Disable", 0.3f);
				}
			}
		}
		Rigidbody[] componentsInChildren2 = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<Rigidbody>(true);
		foreach (Rigidbody val2 in componentsInChildren2)
		{
			if ((Object)(object)val2 != (Object)null && !val2.isKinematic)
			{
				val2.linearVelocity = Vector3.zero;
				val2.angularVelocity = Vector3.zero;
			}
		}
	}

	private void DefenseTick(PlayerAvatar p)
	{
		DefenseHighlight defenseHighlight = ((Component)p).GetComponent<DefenseHighlight>();
		if ((Object)(object)defenseHighlight == (Object)null)
		{
			defenseHighlight = ((Component)p).gameObject.AddComponent<DefenseHighlight>();
		}
		defenseHighlight.SetActive(active: true);
		DefenseHudOverlay.SetProtected(p, active: true);
		if (!IsAuthority())
		{
			return;
		}
		Component val = FindHealth(p);
		if ((Object)(object)val == (Object)null || !IntMember(val, "health", out var v))
		{
			return;
		}
		if ((Object)(object)lastDefPlayer != (Object)(object)p)
		{
			lastDefPlayer = p;
			lastDefHp = v;
			return;
		}
		if (v < lastDefHp && v > 0)
		{
			int num = lastDefHp - v;
			CallMethod(val, "Heal", num, false);
			IntMember(val, "health", out v);
		}
		lastDefHp = v;
	}

	private void ClearDefense(object target)
	{
		lastDefPlayer = null;
		lastDefHp = -1;
		PlayerAvatar val = (PlayerAvatar)((target is PlayerAvatar) ? target : null);
		if (!((Object)(object)val == (Object)null))
		{
			DefenseHighlight component = ((Component)val).GetComponent<DefenseHighlight>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetActive(active: false);
			}
			DefenseHudOverlay.SetProtected(val, active: false);
		}
	}
}
public class HealDroneLogic : StunDroneLogic
{
}
public class DefenseDroneLogic : StunDroneLogic
{
}
public class DefenseHudOverlay : MonoBehaviour
{
	private struct GraphicState
	{
		public Graphic graphic;

		public Color origColor;
	}

	private static DefenseHudOverlay instance;

	private static readonly Dictionary<int, float> protectedUntil = new Dictionary<int, float>();

	private static Texture2D shieldTex;

	public static float ShieldOffsetX = 8f;

	public static float ShieldOffsetY = 0f;

	public static float ShieldScale = 0.7f;

	private readonly List<GraphicState> tintedGraphics = new List<GraphicState>();

	private GameObject shieldBadgeGo;

	private RawImage shieldBadgeImg;

	private bool hudApplied;

	private float nextScan;

	public static void SetProtected(PlayerAvatar p, bool active)
	{
		if (!((Object)(object)p == (Object)null))
		{
			int instanceID = ((Object)p).GetInstanceID();
			if (active)
			{
				protectedUntil[instanceID] = Time.time + 1.5f;
			}
			else
			{
				protectedUntil.Remove(instanceID);
			}
			EnsureInstance();
		}
	}

	private static void EnsureInstance()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		if (!((Object)(object)instance != (Object)null))
		{
			GameObject val = new GameObject("DefenseDroneHudOverlay");
			Object.DontDestroyOnLoad((Object)(object)val);
			instance = val.AddComponent<DefenseHudOverlay>();
		}
	}

	private static bool IsLocalPlayerProtected()
	{
		if (protectedUntil.Count == 0)
		{
			return false;
		}
		float time = Time.time;
		List<int> list = new List<int>();
		bool flag = false;
		foreach (KeyValuePair<int, float> item in protectedUntil)
		{
			if (item.Value < time)
			{
				list.Add(item.Key);
			}
		}
		for (int i = 0; i < list.Count; i++)
		{
			protectedUntil.Remove(list[i]);
		}
		if (protectedUntil.Count == 0)
		{
			return false;
		}
		PlayerAvatar[] array = Object.FindObjectsByType<PlayerAvatar>((FindObjectsSortMode)0);
		foreach (PlayerAvatar val in array)
		{
			if (!((Object)(object)val == (Object)null) && protectedUntil.ContainsKey(((Object)val).GetInstanceID()) && IsLocalAvatar(val))
			{
				flag = true;
				break;
			}
		}
		if (!flag && protectedUntil.Count > 0)
		{
			flag = true;
		}
		return flag;
	}

	private static bool IsLocalAvatar(PlayerAvatar p)
	{
		if ((Object)(object)p == (Object)null)
		{
			return false;
		}
		try
		{
			PhotonView component = ((Component)p).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null)
			{
				return component.IsMine;
			}
		}
		catch
		{
		}
		try
		{
			FieldInfo field = ((object)p).GetType().GetField("photonView", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				object? value = field.GetValue(p);
				PhotonView val = (PhotonView)((value is PhotonView) ? value : null);
				if ((Object)(object)val != (Object)null)
				{
					return val.IsMine;
				}
			}
		}
		catch
		{
		}
		return false;
	}

	private static Texture2D GetShieldTexture()
	{
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)shieldTex != (Object)null)
		{
			return shieldTex;
		}
		try
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("def_shield.png");
			if (stream != null)
			{
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (ImageConversion.LoadImage(val, array))
				{
					shieldTex = val;
					return shieldTex;
				}
			}
		}
		catch
		{
		}
		Texture2D val2 = new Texture2D(32, 32, (TextureFormat)4, false);
		Color val3 = default(Color);
		((Color)(ref val3))..ctor(0f, 0f, 0f, 0f);
		for (int i = 0; i < 32; i++)
		{
			for (int j = 0; j < 32; j++)
			{
				val2.SetPixel(j, i, val3);
			}
		}
		val2.Apply();
		shieldTex = val2;
		return shieldTex;
	}

	private void Update()
	{
		if (!IsLocalPlayerProtected())
		{
			if (hudApplied)
			{
				RestoreHud();
			}
		}
		else if (!hudApplied || Time.time >= nextScan)
		{
			nextScan = Time.time + 0.1f;
			ApplyHud();
		}
	}

	private static bool IsInsideHealth(Transform t)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name == "Health")
			{
				return true;
			}
			if (((Object)val).name == "Game Hud")
			{
				break;
			}
			val = val.parent;
		}
		return false;
	}

	private static bool IsInsideNamed(Transform t, string name)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name == name)
			{
				return true;
			}
			if (((Object)val).name == "Health" || ((Object)val).name == "Game Hud")
			{
				break;
			}
			val = val.parent;
		}
		return false;
	}

	private static bool GetTextWorldBounds(Graphic g, RectTransform rt, out Vector3 a, out Vector3 b)
	{
		//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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0068: 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_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00bc: Unknown result type (might be due to invalid IL or missing references)
		a = Vector3.zero;
		b = Vector3.zero;
		try
		{
			PropertyInfo property = ((object)g).GetType().GetProperty("textBounds", BindingFlags.Instance | BindingFlags.Public);
			if (property == null || property.PropertyType != typeof(Bounds))
			{
				return false;
			}
			Bounds val = (Bounds)property.GetValue(g, null);
			if (((Bounds)(ref val)).size.x < 0.01f || ((Bounds)(ref val)).size.y < 0.01f)
			{
				return false;
			}
			a = ((Transform)rt).TransformPoint(((Bounds)(ref val)).min);
			b = ((Transform)rt).TransformPoint(((Bounds)(ref val)).max);
			return true;
		}
		catch
		{
			return false;
		}
	}

	private static RectTransform FindHealthRoot()
	{
		RectTransform val = null;
		RectTransform[] array = Object.FindObjectsByType<RectTransform>((FindObjectsSortMode)0);
		foreach (RectTransform val2 in array)
		{
			if (!((Object)(object)val2 == (Object)null) && !(((Object)((Component)val2).gameObject).name != "Health") && IsUnderGameHud((Transform)(object)val2) && ((Object)(object)val == (Object)null || (((Component)val2).gameObject.activeInHierarchy && !((Component)val).gameObject.activeInHierarchy)))
			{
				val = val2;
			}
		}
		return val;
	}

	private static bool IsUnderGameHud(Transform t)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name == "Game Hud")
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private void ApplyHud()
	{
		//IL_03c5: 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_0158: 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_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: 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_0268: 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_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_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: 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_025d: Unknown result type (might be due to invalid IL or missing references)
		hudApplied = true;
		Color val = default(Color);
		((Color)(ref val))..ctor(0.14f, 0.66f, 1f, 1f);
		RectTransform val2 = FindHealthRoot();
		bool flag = false;
		bool flag2 = false;
		float num = 0f;
		float num2 = 0f;
		float num3 = 0f;
		float num4 = 0f;
		Vector3[] array = (Vector3[])(object)new Vector3[4];
		Graphic[] array2 = Object.FindObjectsByType<Graphic>((FindObjectsSortMode)0);
		foreach (Graphic val3 in array2)
		{
			if ((Object)(object)val3 == (Object)null || ((Object)(object)shieldBadgeGo != (Object)null && ((Component)val3).transform.IsChildOf(shieldBadgeGo.transform)) || !IsInsideHealth(((Component)val3).transform))
			{
				continue;
			}
			bool flag3 = false;
			for (int j = 0; j < tintedGraphics.Count; j++)
			{
				if ((Object)(object)tintedGraphics[j].graphic == (Object)(object)val3)
				{
					flag3 = true;
					break;
				}
			}
			if (!flag3)
			{
				tintedGraphics.Add(new GraphicState
				{
					graphic = val3,
					origColor = val3.color
				});
			}
			Color color = val;
			color.a = ((val3.color.a > 0f) ? val3.color.a : 1f);
			val3.color = color;
			if ((Object)(object)val2 == (Object)null || !((Component)val3).gameObject.activeInHierarchy || !((Behaviour)val3).enabled)
			{
				continue;
			}
			bool flag4 = IsInsideNamed(((Component)val3).transform, "HealthMax");
			if (!flag4 && flag2)
			{
				continue;
			}
			if (flag4 && !flag2)
			{
				flag = false;
				flag2 = true;
			}
			RectTransform rectTransform = val3.rectTransform;
			if ((Object)(object)rectTransform == (Object)null)
			{
				continue;
			}
			if (!GetTextWorldBounds(val3, rectTransform, out var a, out var b))
			{
				rectTransform.GetWorldCorners(array);
				a = array[0];
				b = array[2];
			}
			Vector3 val4 = ((Transform)val2).InverseTransformPoint(a);
			Vector3 val5 = ((Transform)val2).InverseTransformPoint(b);
			float num5 = Mathf.Min(val4.x, val5.x);
			float num6 = Mathf.Max(val4.x, val5.x);
			float num7 = Mathf.Min(val4.y, val5.y);
			float num8 = Mathf.Max(val4.y, val5.y);
			if (num6 - num5 < 0.01f || num8 - num7 < 0.01f)
			{
				continue;
			}
			if (!flag)
			{
				num = num5;
				num2 = num6;
				num3 = num7;
				num4 = num8;
				flag = true;
				continue;
			}
			if (num5 < num)
			{
				num = num5;
			}
			if (num6 > num2)
			{
				num2 = num6;
			}
			if (num7 < num3)
			{
				num3 = num7;
			}
			if (num8 > num4)
			{
				num4 = num8;
			}
		}
		if (!((Object)(object)val2 == (Object)null))
		{
			Vector2 localPos = default(Vector2);
			if (flag)
			{
				((Vector2)(ref localPos))..ctor(num2 + ShieldOffsetX, (num3 + num4) * 0.5f + ShieldOffsetY);
			}
			else
			{
				((Vector2)(ref localPos))..ctor(ShieldOffsetX, ShieldOffsetY);
			}
			EnsureShieldBadge(val2, localPos, 64f * ShieldScale);
		}
	}

	private void EnsureShieldBadge(RectTransform healthRoot, Vector2 localPos, float size)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_00cb: 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_00f7: 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_0119: 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_0133: 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)
		if ((Object)(object)shieldBadgeGo == (Object)null)
		{
			shieldBadgeGo = new GameObject("DefenseDroneShieldIcon", new Type[1] { typeof(RectTransform) });
			shieldBadgeImg = shieldBadgeGo.AddComponent<RawImage>();
			((Graphic)shieldBadgeImg).raycastTarget = false;
		}
		RectTransform component = shieldBadgeGo.GetComponent<RectTransform>();
		if ((Object)(object)((Transform)component).parent != (Object)(object)healthRoot)
		{
			((Transform)component).SetParent((Transform)(object)healthRoot, false);
			shieldBadgeGo.layer = ((Component)healthRoot).gameObject.layer;
		}
		shieldBadgeGo.SetActive(true);
		((Behaviour)shieldBadgeImg).enabled = true;
		shieldBadgeImg.texture = (Texture)(object)GetShieldTexture();
		((Graphic)shieldBadgeImg).color = Color.white;
		component.anchorMin = new Vector2(0.5f, 0.5f);
		component.anchorMax = new Vector2(0.5f, 0.5f);
		component.pivot = new Vector2(0f, 0.5f);
		((Transform)component).localScale = Vector3.one;
		((Transform)component).localRotation = Quaternion.identity;
		component.sizeDelta = new Vector2(size, size);
		((Transform)component).localPosition = new Vector3(localPos.x, localPos.y, 0f);
		((Transform)component).SetAsLastSibling();
	}

	private void RestoreHud()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		hudApplied = false;
		for (int i = 0; i < tintedGraphics.Count; i++)
		{
			GraphicState graphicState = tintedGraphics[i];
			if ((Object)(object)graphicState.graphic != (Object)null)
			{
				graphicState.graphic.color = graphicState.origColor;
			}
		}
		tintedGraphics.Clear();
		if ((Object)(object)shieldBadgeGo != (Object)null)
		{
			shieldBadgeGo.SetActive(false);
		}
	}

	private void OnDisable()
	{
		RestoreHud();
	}

	private void OnDestroy()
	{
		RestoreHud();
	}
}
public class DefenseHighlight : MonoBehaviour
{
	private struct MatState
	{
		public Material mat;

		public bool hadEmission;

		public Color origColor;

		public bool hasColor;

		public Color origBaseColor;

		public bool hasBaseColor;

		public Color origEmission;

		public bool hasEmission;
	}

	private static readonly Color GlowColor = new Color(0.06f, 0.22f, 1f, 1f);

	private static readonly Color TintColor = new Color(0.28f, 0.48f, 1f, 1f);

	private readonly List<MatState> states = new List<MatState>();

	private Light auraLight;

	private bool isHighlighted;

	private float nextRefresh;

	public void SetActive(bool active)
	{
		if (active)
		{
			if (!isHighlighted || Time.time > nextRefresh)
			{
				nextRefresh = Time.time + 0.25f;
				Apply();
			}
			isHighlighted = true;
		}
		else if (isHighlighted)
		{
			Restore();
			isHighlighted = false;
		}
	}

	private void Apply()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_004d: 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_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: 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_0212: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)auraLight == (Object)null)
		{
			GameObject val = new GameObject("DefenseDroneAuraLight");
			val.transform.SetParent(((Component)this).transform, false);
			val.transform.localPosition = new Vector3(0f, 1f, 0f);
			auraLight = val.AddComponent<Light>();
			auraLight.type = (LightType)2;
			auraLight.color = GlowColor;
			auraLight.range = 4.5f;
			auraLight.intensity = 2.6f;
		}
		((Behaviour)auraLight).enabled = true;
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val2 in componentsInChildren)
		{
			if ((Object)(object)val2 == (Object)null || val2 is ParticleSystemRenderer || val2 is LineRenderer)
			{
				continue;
			}
			Material material = val2.material;
			if ((Object)(object)material == (Object)null)
			{
				continue;
			}
			bool flag = false;
			for (int j = 0; j < states.Count; j++)
			{
				if ((Object)(object)states[j].mat == (Object)(object)material)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				MatState item = new MatState
				{
					mat = material,
					hadEmission = material.IsKeywordEnabled("_EMISSION")
				};
				if (material.HasProperty("_Color"))
				{
					item.hasColor = true;
					item.origColor = material.GetColor("_Color");
				}
				if (material.HasProperty("_BaseColor"))
				{
					item.hasBaseColor = true;
					item.origBaseColor = material.GetColor("_BaseColor");
				}
				if (material.HasProperty("_EmissionColor"))
				{
					item.hasEmission = true;
					item.origEmission = material.GetColor("_EmissionColor");
				}
				states.Add(item);
			}
			material.EnableKeyword("_EMISSION");
			if (material.HasProperty("_EmissionColor"))
			{
				material.SetColor("_EmissionColor", GlowColor * 1.35f);
			}
			if (material.HasProperty("_Color"))
			{
				material.SetColor("_Color", TintColor);
			}
			if (material.HasProperty("_BaseColor"))
			{
				material.SetColor("_BaseColor", TintColor);
			}
		}
	}

	private void Restore()
	{
		//IL_006b: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)auraLight != (Object)null)
		{
			((Behaviour)auraLight).enabled = false;
		}
		for (int i = 0; i < states.Count; i++)
		{
			MatState matState = states[i];
			if (!((Object)(object)matState.mat == (Object)null))
			{
				if (matState.hasColor)
				{
					matState.mat.SetColor("_Color", matState.origColor);
				}
				if (matState.hasBaseColor)
				{
					matState.mat.SetColor("_BaseColor", matState.origBaseColor);
				}
				if (matState.hasEmission)
				{
					matState.mat.SetColor("_EmissionColor", matState.origEmission);
				}
				if (!matState.hadEmission)
				{
					matState.mat.DisableKeyword("_EMISSION");
				}
			}
		}
		states.Clear();
	}

	private void OnDisable()
	{
		if (isHighlighted)
		{
			Restore();
			isHighlighted = false;
		}
	}

	private void OnDestroy()
	{
		if (isHighlighted)
		{
			Restore();
			isHighlighted = false;
		}
	}
}
internal static class Registrar
{
	private const BindingFlags BF = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

	public static int Tries;

	public static string Prefer = "";

	public static float PriceMin = 40000f;

	public static float PriceMax = 75000f;

	public static float PriceScale = 0f;

	public static float ShopMultiplier = 0f;

	public static float HealPriceMin = 25000f;

	public static float HealPriceMax = 50000f;

	public static float DefPriceMin = 30000f;

	public static float DefPriceMax = 60000f;

	private static bool StunDone;

	private static bool HealDone = true;

	private static bool DefDone = true;

	private static string lastMsg;

	public static bool Done => StunDone && HealDone && DefDone;

	public static bool AnyDone => StunDone || HealDone || DefDone;

	private static void Say(ManualLogSource log, string m)
	{
		if (!(m == lastMsg))
		{
			lastMsg = m;
			log.LogInfo((object)("[Register] " + m));
		}
	}

	private static FieldInfo Fld(Type t, string name)
	{
		while (t != null)
		{
			FieldInfo field = t.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				return field;
			}
			t = t.BaseType;
		}
		return null;
	}

	private static string GetS(object o, string name)
	{
		FieldInfo fieldInfo = Fld(o.GetType(), name);
		return (fieldInfo != null) ? (fieldInfo.GetValue(o) as string) : null;
	}

	private static void SetS(object o, string name, string v)
	{
		FieldInfo fieldInfo = Fld(o.GetType(), name);
		if (fieldInfo != null && fieldInfo.FieldType == typeof(string))
		{
			fieldInfo.SetValue(o, v);
		}
	}

	internal static Type FindType(string full)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			try
			{
				Type type = assembly.GetType(full);
				if (type != null)
				{
					return type;
				}
			}
			catch
			{
			}
		}
		return null;
	}

	private static GameObject ExtractGO(object o)
	{
		if (o == null)
		{
			return null;
		}
		GameObject val = (GameObject)((o is GameObject) ? o : null);
		if ((Object)(object)val != (Obj

BepInEx/plugins/HealDrone.dll

Decompiled 38 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Photon.Pun;
using UnityEngine;
using UnityEngine.UI;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace HealDroneMod;

[BepInPlugin("user.healdrone", "Heal Drone", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private float dumpTimer;

	private bool dumped = true;

	private float regTimer;

	private float adminTimer;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Heal Drone loaded. F8 = dump drone state");
		Registrar.Prefer = ((BaseUnityPlugin)this).Config.Bind<string>("General", "SourceDroneName", "Torque", "Часть имени ванильного дрона, который копируется (Zero Gravity, Feather, Indestructible, Battery, Torque...). Пусто = авто.").Value;
		Registrar.PriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceMin", 40000f, "Минимальная цена Stun Drone в магазине, $").Value;
		Registrar.PriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceMax", 75000f, "Максимальная цена Stun Drone в магазине, $").Value;
		StunDroneLogic.BarSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SecondsPerCharge", 10f, "Сколько секунд длится один заряд Stun Drone, пока он держит цель").Value;
		StunDroneLogic.StunCharges = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Charges", 6, "Сколько зарядов (полосок) у Stun Drone").Value;
		StunDroneLogic.ReleaseOnDetach = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ReleaseOnDetach", false, "false = цель остаётся в стане, пока дрон не выключен и есть заряд, даже если луч отцепился; true = стан снимается сразу при отцеплении луча").Value;
		StunDroneLogic.StrictBeam = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "StrictBeam", true, "true = цель считается прицепленной, только если конец луча дрона реально лежит на ней (защита от залипшей ссылки на старую цель)").Value;
		Registrar.PriceScale = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceScale", 0f, "Множитель цены: 0 = авто (по ванильному предмету), 0.001 = значение в тысячах, 1 = цена как есть").Value;
		Registrar.ShopMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "ShopMultiplier", 0f, "Множитель магазина игры: 0 = авто (ShopManager.itemValueMultiplier, обычно 4). Цена делится на него, чтобы в магазине было PriceMin..PriceMax").Value;
		Registrar.HealPriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "PriceMin", 25000f, "Минимальная цена Heal Drone в магазине, $").Value;
		Registrar.HealPriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "PriceMax", 50000f, "Максимальная цена Heal Drone в магазине, $").Value;
		StunDroneLogic.HealAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Heal Drone", "HealAmount", 5, "Сколько HP лечит за один тик").Value;
		StunDroneLogic.HealInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "HealInterval", 1f, "Пауза между тиками лечения, секунд").Value;
		StunDroneLogic.HealCharges = ((BaseUnityPlugin)this).Config.Bind<int>("Heal Drone", "Charges", 10, "Сколько зарядов (полосок) у Heal Drone. Один тик лечения (HealAmount HP) = 1 заряд").Value;
		Registrar.DefPriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "PriceMin", 30000f, "Минимальная цена Defense Drone в магазине, $").Value;
		Registrar.DefPriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "PriceMax", 60000f, "Максимальная цена Defense Drone в магазине, $").Value;
		StunDroneLogic.DefCharges = ((BaseUnityPlugin)this).Config.Bind<int>("Defense Drone", "Charges", 6, "Сколько зарядов (полосок) у Defense Drone").Value;
		StunDroneLogic.DefBarSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "SecondsPerCharge", 10f, "Сколько секунд длится 1 заряд Defense Drone").Value;
		StunDroneLogic.DefDamageScale = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "DamageMultiplier", 0.25f, "Множитель входящего урона под защитой (0.25 = -75% урона)").Value;
		DefenseHudOverlay.ShieldOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldOffsetX", 8f, "Смещение иконки щита по X от правого края HealthMax (в единицах HUD)").Value;
		DefenseHudOverlay.ShieldOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldOffsetY", 0f, "Смещение иконки щита по Y от центра HealthMax (в единицах HUD), + вверх").Value;
		DefenseHudOverlay.ShieldScale = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldScale", 0.7f, "Масштаб иконки щита").Value;
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)289))
		{
			StunDroneLogic[] array = Object.FindObjectsByType<StunDroneLogic>((FindObjectsSortMode)0);
			foreach (StunDroneLogic stunDroneLogic in array)
			{
				stunDroneLogic.DumpState(((BaseUnityPlugin)this).Logger);
			}
		}
		if (!Registrar.Done && Registrar.Tries < 300)
		{
			regTimer += Time.deltaTime;
			if (regTimer > 2f)
			{
				regTimer = 0f;
				Registrar.TryRegister(((BaseUnityPlugin)this).Logger);
			}
		}
		if (Registrar.AnyDone)
		{
			adminTimer += Time.deltaTime;
			if (adminTimer > 2f)
			{
				adminTimer = 0f;
				AdminSync.Run(((BaseUnityPlugin)this).Logger);
			}
		}
		if (!dumped)
		{
			dumpTimer += Time.deltaTime;
			if (dumpTimer > 10f)
			{
				dumped = true;
				Dumper.Run(((BaseUnityPlugin)this).Logger);
			}
		}
	}

	private void SpawnDrone(string itemName)
	{
		//IL_0111: 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_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: 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_0150: 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)
		StatsManager instance = StatsManager.instance;
		if ((Object)(object)instance == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"StatsManager not ready");
			return;
		}
		Item val = null;
		foreach (Item value in instance.itemDictionary.Values)
		{
			if ((Object)(object)value != (Object)null && value.itemName == itemName)
			{
				val = value;
				break;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)(itemName + " is not registered yet (wait for the log line DONE)"));
			return;
		}
		Type type = Registrar.FindType("REPOLib.Modules.Items");
		if (type == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"REPOLib not found");
			return;
		}
		Camera main = Camera.main;
		Vector3 val2 = (((Object)(object)main != (Object)null) ? (((Component)main).transform.position + ((Component)main).transform.forward * 2f) : Vector3.up);
		object obj = type.GetMethod("SpawnItem").Invoke(null, new object[3]
		{
			val,
			val2,
			Quaternion.identity
		});
		if (obj == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"SpawnItem returned null (are you the host? see REPOLib lines in the log)");
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)(itemName + " spawned"));
		}
	}
}
public class StunDroneLogic : MonoBehaviour
{
	public enum Mode
	{
		Player,
		Monster
	}

	private enum Part
	{
		Skip,
		Main,
		Other
	}

	private const float Range = 6f;

	private const float MonsterStunSeconds = 1.5f;

	private const float NormalGravity = 30f;

	private const float PlayerStunSeconds = 3f;

	private const float AutoCooldown = 6f;

	private const BindingFlags RB = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

	public Mode mode;

	public static int StunCharges = 6;

	public static int HealCharges = 10;

	public static int DefCharges = 6;

	public static float DefBarSeconds = 10f;

	public static float DefDamageScale = 0.25f;

	public int charge = 1;

	private object target;

	private float stickUntil;

	private ItemAttributes[] attrs;

	private float gravTimer;

	private bool gravLogged;

	private static readonly Color OrangeC = new Color(1f, 0.5f, 0.05f, 1f);

	private static readonly Color GreenC = new Color(0.15f, 1f, 0.3f, 1f);

	private static readonly Color DarkBlueC = new Color(0.08f, 0.28f, 1f, 1f);

	private bool batLogged;

	private bool torqueLogged;

	private bool scriptsDone;

	private Texture2D iconTex;

	private bool iconPending;

	private int bornFrame;

	private bool iconLogged;

	private static bool logged;

	private float nextAuto;

	private float reapplyTimer;

	private bool targetingDone;

	private ItemDrone droneComp;

	private bool wasAttached;

	private bool loggedScan;

	private float nextDiag;

	private float holdTimer;

	private object attachedObj;

	public static bool StrictBeam = true;

	public static bool ReleaseOnDetach = false;

	public static float BarSeconds = 3f;

	private float drainTimer;

	private object stunned;

	private float attachStart;

	private bool capped;

	private object relTarget;

	private float relUntil;

	private float relNext;

	private static bool stunLogged;

	private float nextBeamLog;

	private HashSet<Renderer> batRend = new HashSet<Renderer>();

	private List<Renderer> beamList = new List<Renderer>();

	private Dictionary<Renderer, int[]> beamProps = new Dictionary<Renderer, int[]>();

	private float nextBeamFind;

	private bool fieldColorLogged;

	private Component batteryComp;

	private float nextBatFind;

	private bool batteryLogged;

	private bool uiDumped;

	private float lifeVal = -1f;

	private int lastCharge;

	private float nextBatDump;

	private int dumpedCharge = -1;

	public static int HealAmount = 5;

	public static float HealInterval = 1f;

	private float nextHeal;

	private bool healWarned;

	private Component tumbleCache;

	private PlayerAvatar cachedFor;

	private bool tumbleWarned;

	private bool stunWarned;

	private bool stunWarned2;

	private bool stunOk;

	private static HashSet<string> noStunLogged = new HashSet<string>();

	private int lastDefHp = -1;

	private PlayerAvatar lastDefPlayer;

	private int Cap => Math.Max(1, Defense ? DefCharges : (Heal ? HealCharges : StunCharges));

	private string DisplayName => Defense ? "Defense Drone" : (Heal ? "Heal Drone" : "Stun Drone");

	private bool Heal => this is HealDroneLogic;

	private bool Defense => this is DefenseDroneLogic;

	private Color Orange => Defense ? DarkBlueC : (Heal ? GreenC : OrangeC);

	private void Awake()
	{
		charge = Cap;
		CollectBatteryRenderers();
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val != (Object)null && ((object)val).GetType().Name == "ItemBattery")
			{
				SetNum(val, "batteryBars", Cap);
			}
		}
		mode = ((!Heal && !Defense && !(Random.value < 0.5f)) ? Mode.Monster : Mode.Player);
		Retexture();
		ApplyIcon();
		bornFrame = Time.frameCount;
		ApplyTargeting();
		attrs = ((Component)this).GetComponentsInChildren<ItemAttributes>(true);
		ForceName();
		Debug.Log((object)string.Concat("[StunDrone] spawned, mode=", mode, ", name=", DumpName()));
	}

	private void ForceName()
	{
		if (attrs == null)
		{
			return;
		}
		ItemAttributes[] array = attrs;
		foreach (ItemAttributes val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				SetStr(val, "itemName", DisplayName);
				SetStr(val, "instanceName", DisplayName);
				SetStr(val, "cachedItemName", DisplayName);
			}
		}
	}

	private string DumpName()
	{
		if (attrs == null || attrs.Length == 0)
		{
			return "<no ItemAttributes>";
		}
		ItemAttributes o = attrs[0];
		return GetStr(o, "itemName") + " / " + GetStr(o, "cachedItemName");
	}

	private static void SetStr(object o, string name, string v)
	{
		FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null && field.FieldType == typeof(string))
		{
			field.SetValue(o, v);
		}
	}

	private static string GetStr(object o, string name)
	{
		FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		return (field != null) ? (field.GetValue(o) as string) : "?";
	}

	private void ApplyGravity()
	{
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				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)) && !(fieldInfo.Name.ToLower() != "customgravity"))
					{
						float num = (float)fieldInfo.GetValue(val);
						if (!gravLogged)
						{
							Debug.Log((object)("[StunDrone] " + type.Name + "." + fieldInfo.Name + ": " + num + " -> " + 30f));
						}
						if (num != 30f)
						{
							fieldInfo.SetValue(val, 30f);
						}
					}
				}
				type = type.BaseType;
			}
		}
		gravLogged = true;
	}

	private void ApplyColors()
	{
		//IL_00af: 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_00e6: 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_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			if (!(val is ParticleSystemRenderer) && Classify(((Component)val).transform) == Part.Other && !IsBatteryRenderer(val))
			{
				Material material = val.material;
				if (material.HasProperty("_EmissionColor"))
				{
					material.SetColor("_EmissionColor", Orange);
				}
			}
		}
		Light[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Light>(true);
		foreach (Light val2 in componentsInChildren2)
		{
			val2.color = Orange;
		}
		LineRenderer[] componentsInChildren3 = ((Component)this).GetComponentsInChildren<LineRenderer>(true);
		foreach (LineRenderer val3 in componentsInChildren3)
		{
			val3.startColor = Orange;
			val3.endColor = Orange;
		}
		ParticleSystem[] componentsInChildren4 = ((Component)this).GetComponentsInChildren<ParticleSystem>(true);
		foreach (ParticleSystem val4 in componentsInChildren4)
		{
			MainModule main = val4.main;
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Orange);
		}
	}

	private void ApplyBatteryColor()
	{
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] battery members: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null || ((object)val).GetType().Name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) < 0)
			{
				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 (!batLogged)
					{
						object value = null;
						try
						{
							value = fieldInfo.GetValue(val);
						}
						catch
						{
						}
						stringBuilder.Append(type.Name).Append('.').Append(fieldInfo.Name)
							.Append('=')
							.Append(value)
							.Append("; ");
					}
					if (fieldInfo.FieldType == typeof(Color) && (fieldInfo.Name.Equals("batteryColor", StringComparison.OrdinalIgnoreCase) || fieldInfo.Name.Equals("batteryColorMain", StringComparison.OrdinalIgnoreCase) || fieldInfo.Name.Equals("batteryColorMedium", StringComparison.OrdinalIgnoreCase)))
					{
						fieldInfo.SetValue(val, Orange);
					}
				}
				type = type.BaseType;
			}
		}
		if (!batLogged)
		{
			batLogged = true;
			Debug.Log((object)stringBuilder.ToString());
		}
	}

	private void RemoveTorque()
	{
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] torque members: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				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)
				{
					string text = fieldInfo.Name.ToLower();
					if (text.Contains("torque") || text.Contains("spin"))
					{
						object value = null;
						try
						{
							value = fieldInfo.GetValue(val);
						}
						catch
						{
						}
						if (!torqueLogged)
						{
							stringBuilder.Append(type.Name).Append('.').Append(fieldInfo.Name)
								.Append('=')
								.Append(value)
								.Append("; ");
						}
						if (fieldInfo.FieldType == typeof(float))
						{
							fieldInfo.SetValue(val, 0f);
						}
						else if (fieldInfo.FieldType == typeof(bool))
						{
							fieldInfo.SetValue(val, false);
						}
						else if (fieldInfo.FieldType == typeof(Vector3))
						{
							fieldInfo.SetValue(val, Vector3.zero);
						}
					}
				}
				type = type.BaseType;
			}
		}
		if (!torqueLogged)
		{
			torqueLogged = true;
			Debug.Log((object)stringBuilder.ToString());
		}
	}

	private void RemoveTorqueScripts()
	{
		if (scriptsDone)
		{
			return;
		}
		scriptsDone = true;
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] scripts on drone: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			string name = ((object)val).GetType().Name;
			stringBuilder.Append(((Object)((Component)val).gameObject).name).Append(':').Append(name)
				.Append("; ");
			if (!((Object)(object)val == (Object)(object)this) && !(name == "ItemDrone"))
			{
				string text = name.ToLower();
				if (text.Contains("torque") || text.Contains("spin"))
				{
					Debug.Log((object)("[StunDrone] removing script " + name + " on " + ((Object)((Component)val).gameObject).name));
					Object.Destroy((Object)(object)val);
				}
			}
		}
		Debug.Log((object)stringBuilder.ToString());
	}

	private void LateUpdate()
	{
		ForceName();
		SyncBattery();
		TintBeams();
		if (Time.frameCount > bornFrame + 5)
		{
			RemoveTorqueScripts();
		}
		if (Time.time > gravTimer)
		{
			gravTimer = Time.time + 0.5f;
			ApplyGravity();
			ApplyColors();
			ApplyBatteryColor();
			ApplyDroneFieldColors();
			RemoveTorque();
			if ((Object)(object)iconTex != (Object)null && Time.frameCount > bornFrame + 3)
			{
				ApplyIconMaterial();
			}
		}
	}

	private void ApplyTargeting()
	{
		ItemDrone componentInChildren = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		if (!((Object)(object)componentInChildren == (Object)null))
		{
			SetBool(componentInChildren, "targetValuables", v: false);
			SetBool(componentInChildren, "targetNonValuables", v: false);
			SetBool(componentInChildren, "targetPlayers", v: true);
			SetBool(componentInChildren, "targetEnemies", !Heal && !Defense);
		}
	}

	private static void SetBool(object o, string name, bool v)
	{
		FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null && field.FieldType == typeof(bool))
		{
			field.SetValue(o, v);
		}
		else
		{
			Debug.LogWarning((object)("[StunDrone] field " + name + " not found"));
		}
	}

	private void ApplyIcon()
	{
		iconTex = LoadEmbedded(Defense ? "def_icon.png" : (Heal ? "heal_icon.png" : "icon.png"));
		Debug.Log((object)("[StunDrone] icon.png embedded in DLL: " + ((Object)(object)iconTex != (Object)null) + (((Object)(object)iconTex == (Object)null) ? "  (put tex\\3.png next to build.bat and rebuild)" : "")));
		if ((Object)(object)iconTex == (Object)null)
		{
			return;
		}
		ItemDrone componentInChildren = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		if ((Object)(object)componentInChildren != (Object)null)
		{
			FieldInfo field = typeof(ItemDrone).GetField("droneIcon", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(componentInChildren, iconTex);
			}
			else
			{
				Debug.LogWarning((object)"[StunDrone] field droneIcon not found");
			}
		}
		else
		{
			Debug.LogWarning((object)"[StunDrone] ItemDrone not found on prefab");
		}
		iconPending = true;
		bornFrame = Time.frameCount;
	}

	private void ApplyIconMaterial()
	{
		//IL_0107: 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_0155: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			bool flag = false;
			Transform val2 = ((Component)val).transform;
			while ((Object)(object)val2 != (Object)null)
			{
				if (((Object)val2).name.Replace('_', ' ').Trim().StartsWith("Drone Icon"))
				{
					flag = true;
					break;
				}
				val2 = val2.parent;
			}
			if (flag)
			{
				Material material = val.material;
				material.EnableKeyword("_EMISSION");
				material.SetTexture("_EmissionMap", (Texture)(object)iconTex);
				if (material.HasProperty("_MainTex"))
				{
					material.SetTexture("_MainTex", (Texture)(object)iconTex);
				}
				if (material.HasProperty("_BaseMap"))
				{
					material.SetTexture("_BaseMap", (Texture)(object)iconTex);
				}
				if (material.HasProperty("_EmissionColor"))
				{
					material.SetColor("_EmissionColor", Color.white);
				}
				if (material.HasProperty("_Color"))
				{
					material.SetColor("_Color", Color.white);
				}
				if (material.HasProperty("_BaseColor"))
				{
					material.SetColor("_BaseColor", Color.white);
				}
				num++;
			}
		}
		if (!iconLogged)
		{
			iconLogged = true;
			Debug.Log((object)("[StunDrone] icon applied to " + num + " renderer(s) named 'Drone Icon'"));
		}
	}

	private void Retexture()
	{
		//IL_00ac: 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_007e: 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_0258: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = (Defense ? LoadEmbedded("def_albedo.png") : (Heal ? LoadEmbedded("heal_albedo.png") : null)) ?? LoadEmbedded("albedo.png") ?? Procedural(Defense ? new Color(0.08f, 0.25f, 0.95f) : (Heal ? new Color(0.2f, 0.8f, 0.3f) : ((mode == Mode.Player) ? new Color(0.9f, 0.55f, 0.1f) : new Color(0.1f, 0.6f, 0.8f))));
		Texture2D val2 = (Defense ? LoadEmbedded("def_emission.png") : (Heal ? LoadEmbedded("heal_emission.png") : null)) ?? LoadEmbedded("emission.png");
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val3 in componentsInChildren)
		{
			if (IsBatteryRenderer(val3))
			{
				continue;
			}
			Part part = Classify(((Component)val3).transform);
			if (!logged)
			{
				Debug.Log((object)("[StunDrone] renderer '" + ((Object)val3).name + "' -> " + part));
			}
			if (part == Part.Skip)
			{
				continue;
			}
			Material material = val3.material;
			if (material.HasProperty("_MainTex"))
			{
				material.SetTexture("_MainTex", (Texture)(object)val);
			}
			if (material.HasProperty("_BaseMap"))
			{
				material.SetTexture("_BaseMap", (Texture)(object)val);
			}
			if (part == Part.Main)
			{
				if (material.HasProperty("_EmissionMap"))
				{
					material.SetTexture("_EmissionMap", (Texture)null);
				}
				material.DisableKeyword("_EMISSION");
			}
			else if ((Object)(object)val2 != (Object)null && material.HasProperty("_EmissionMap"))
			{
				material.EnableKeyword("_EMISSION");
				material.SetTexture("_EmissionMap", (Texture)(object)val2);
				material.SetColor("_EmissionColor", Color.white);
			}
		}
		logged = true;
	}

	private static Part Classify(Transform t)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			string text = ((Object)val).name.Replace('_', ' ').Trim();
			if (text.StartsWith("Drone Icon"))
			{
				return Part.Skip;
			}
			if (text.Contains("Drone Triangle") || text.Contains("Drone Pyramid"))
			{
				return Part.Other;
			}
			if (text == "Drone")
			{
				return Part.Main;
			}
			val = val.parent;
		}
		return Part.Skip;
	}

	private static Texture2D LoadEmbedded(string name)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
		if (stream == null)
		{
			return null;
		}
		MemoryStream memoryStream = new MemoryStream();
		stream.CopyTo(memoryStream);
		Texture2D val = new Texture2D(2, 2);
		ImageConversion.LoadImage(val, memoryStream.ToArray());
		return val;
	}

	private static Texture2D Procedural(Color c)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_002e: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(64, 64);
		for (int i = 0; i < 64; i++)
		{
			for (int j = 0; j < 64; j++)
			{
				val.SetPixel(j, i, ((j / 8 + i / 8) % 2 == 0) ? c : (c * 0.6f));
			}
		}
		val.Apply();
		return val;
	}

	private void Update()
	{
		if (!targetingDone && Time.frameCount > bornFrame + 2)
		{
			targetingDone = true;
			ApplyTargeting();
		}
		if (iconPending && Time.frameCount >= bornFrame + 3)
		{
			iconPending = false;
			ApplyIconMaterial();
		}
		KeepReleasing();
		if ((Object)(object)droneComp == (Object)null)
		{
			droneComp = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		}
		object obj = ((charge > 0) ? DetectAttached() : null);
		if (stunned != null && !ReleaseOnDetach && !Heal && !Defense)
		{
			object obj2 = stunned;
			Component val = (Component)((obj2 is Component) ? obj2 : null);
			obj = (((Object)(object)val != (Object)null && (Object)(object)val.gameObject != (Object)null && charge > 0 && ToggleOn()) ? stunned : null);
		}
		if (capped && obj == null)
		{
			capped = false;
		}
		if (capped)
		{
			obj = null;
		}
		if (stunned != null && !object.ReferenceEquals(stunned, obj))
		{
			Release(stunned);
			stunned = null;
		}
		if (obj != null && stunned == null)
		{
			if (object.ReferenceEquals(relTarget, obj))
			{
				relTarget = null;
			}
			stunned = obj;
			attachStart = Time.time;
			holdTimer = 0f;
			drainTimer = 0f;
			Debug.Log((object)string.Concat("[StunDrone] attached to ", obj, ", charge=", charge));
		}
		attachedObj = stunned;
		if (stunned == null)
		{
			return;
		}
		float num = (Defense ? DefBarSeconds : BarSeconds);
		if (!Heal)
		{
			drainTimer += Time.deltaTime;
		}
		if (!Heal && drainTimer >= num)
		{
			drainTimer = 0f;
			charge--;
			Debug.Log((object)("[StunDrone] charge=" + charge));
			if (charge <= 0)
			{
				Debug.Log((object)("[StunDrone] charge empty, releasing " + stunned));
				Release(stunned);
				stunned = null;
				attachedObj = null;
				return;
			}
		}
		if (Heal)
		{
			HealTick();
			return;
		}
		if (Defense)
		{
			object obj3 = stunned;
			PlayerAvatar val2 = (PlayerAvatar)((obj3 is PlayerAvatar) ? obj3 : null);
			if ((Object)(object)val2 != (Object)null)
			{
				DefenseTick(val2);
			}
			return;
		}
		object obj4 = stunned;
		PlayerAvatar val3 = (PlayerAvatar)((obj4 is PlayerAvatar) ? obj4 : null);
		if ((Object)(object)val3 != (Object)null)
		{
			StunPlayer(val3);
			return;
		}
		holdTimer -= Time.deltaTime;
		if (!(holdTimer > 0f))
		{
			holdTimer = 0.2f;
			object obj5 = stunned;
			Enemy val4 = (Enemy)((obj5 is Enemy) ? obj5 : null);
			if ((Object)(object)val4 != (Object)null)
			{
				StunEnemy(val4);
			}
		}
	}

	public void DumpState(ManualLogSource log)
	{
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine(string.Concat("==== ", DateTime.Now.ToString("HH:mm:ss"), "  mode=", mode, " charge=", charge, " stunned=", stunned, " toggleOn=", ToggleOn()));
		if ((Object)(object)droneComp == (Object)null)
		{
			droneComp = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		}
		if ((Object)(object)droneComp != (Object)null)
		{
			Type type = ((object)droneComp).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object obj = null;
					try
					{
						obj = fieldInfo.GetValue(droneComp);
					}
					catch
					{
					}
					stringBuilder.AppendLine("  ItemDrone." + fieldInfo.Name + " (" + fieldInfo.FieldType.Name + ") = " + ((obj == null) ? "null" : obj.ToString()));
				}
				type = type.BaseType;
			}
		}
		LineRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<LineRenderer>(true);
		foreach (LineRenderer val in componentsInChildren)
		{
			stringBuilder.AppendLine("  LineRenderer " + ((Object)val).name + " enabled=" + ((Renderer)val).enabled + " active=" + ((Component)val).gameObject.activeInHierarchy + " points=" + val.positionCount + ((val.positionCount >= 2) ? string.Concat(" p0=", val.GetPosition(0), " pN=", val.GetPosition(val.positionCount - 1), " worldSpace=", val.useWorldSpace) : ""));
		}
		MonoBehaviour[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val2 in componentsInChildren2)
		{
			if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)this || (Object)(object)val2 == (Object)(object)droneComp)
			{
				continue;
			}
			string name = ((object)val2).GetType().Name;
			if (name.IndexOf("Line", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Magnet", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Drone", StringComparison.OrdinalIgnoreCase) < 0)
			{
				continue;
			}
			Type type = ((object)val2).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object obj = null;
					try
					{
						obj = fieldInfo.GetValue(val2);
					}
					catch
					{
					}
					stringBuilder.AppendLine("  " + name + "." + fieldInfo.Name + " (" + fieldInfo.FieldType.Name + ") = " + ((obj == null) ? "null" : obj.ToString()));
				}
				type = type.BaseType;
			}
		}
		try
		{
			string text = Path.Combine(Paths.BepInExRootPath, "StunDrone_state.txt");
			File.AppendAllText(text, stringBuilder.ToString());
			log.LogInfo((object)("State dumped: " + text));
		}
		catch (Exception ex)
		{
			log.LogError((object)("State dump failed: " + ex.Message));
		}
	}

	private void KeepReleasing()
	{
		if (relTarget == null)
		{
			return;
		}
		if (Time.time > relUntil)
		{
			relTarget = null;
		}
		else
		{
			if (Time.time < relNext)
			{
				return;
			}
			relNext = Time.time + 0.2f;
			object obj = relTarget;
			PlayerAvatar val = (PlayerAvatar)((obj is PlayerAvatar) ? obj : null);
			if (!((Object)(object)val == (Object)null))
			{
				Component val2 = FindTumble(val);
				if ((Object)(object)val2 != (Object)null)
				{
					CallMethod(val2, "TumbleOverrideTime", 0f);
					CallMethod(val2, "TumbleRequest", false, false);
				}
			}
		}
	}

	private void OnDisable()
	{
		if (stunned != null)
		{
			Release(stunned);
			stunned = null;
		}
	}

	private void OnDestroy()
	{
		if (stunned != null)
		{
			Release(stunned);
			stunned = null;
		}
	}

	private void Release(object target)
	{
		if (Heal)
		{
			return;
		}
		if (Defense)
		{
			ClearDefense(target);
			return;
		}
		relTarget = target;
		relUntil = Time.time + 1.2f;
		relNext = Time.time + 0.2f;
		try
		{
			PlayerAvatar val = (PlayerAvatar)((target is PlayerAvatar) ? target : null);
			if ((Object)(object)val != (Object)null)
			{
				Component val2 = FindTumble(val);
				if ((Object)(object)val2 != (Object)null)
				{
					CallMethod(val2, "TumbleOverrideTime", 0f);
					CallMethod(val2, "TumbleRequest", false, false);
				}
				Debug.Log((object)"[StunDrone] released player");
			}
			Enemy val3 = (Enemy)((target is Enemy) ? target : null);
			if (!((Object)(object)val3 != (Object)null))
			{
				return;
			}
			Component val4 = FindStun((Component)(object)val3);
			if ((Object)(object)val4 != (Object)null)
			{
				Type type = ((object)val4).GetType();
				while (type != null && type != typeof(MonoBehaviour))
				{
					FieldInfo field = type.GetField("stunTimer", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.FieldType == typeof(float))
					{
						field.SetValue(val4, 0.05f);
					}
					type = type.BaseType;
				}
			}
			MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)val3)).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val5 in componentsInChildren)
			{
				if ((Object)(object)val5 == (Object)null)
				{
					continue;
				}
				Type type = ((object)val5).GetType();
				while (type != null && type != typeof(MonoBehaviour))
				{
					FieldInfo field = type.GetField("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.FieldType == typeof(bool))
					{
						field.SetValue(val5, false);
					}
					PropertyInfo property = type.GetProperty("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null && property.PropertyType == typeof(bool) && property.CanWrite)
					{
						try
						{
							property.SetValue(val5, false, null);
						}
						catch
						{
						}
					}
					type = type.BaseType;
				}
			}
			Debug.Log((object)"[StunDrone] released enemy");
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[StunDrone] Release: " + ex.Message));
		}
	}

	private object DetectAttached()
	{
		object obj = null;
		if (!ToggleOn())
		{
			return null;
		}
		object obj2 = stunned;
		PlayerAvatar val = (PlayerAvatar)((obj2 is PlayerAvatar) ? obj2 : null);
		if ((Object)(object)val != (Object)null && IsHolder(val))
		{
			return val;
		}
		if ((Object)(object)droneComp != (Object)null)
		{
			Type type = ((object)droneComp).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object value;
					try
					{
						value = fieldInfo.GetValue(droneComp);
					}
					catch
					{
						continue;
					}
					Object val2 = (Object)((value is Object) ? value : null);
					IList list = value as IList;
					if (val2 == (Object)null && list != null)
					{
						foreach (object item in list)
						{
							val2 = (Object)((item is Object) ? item : null);
							if (val2 != (Object)null)
							{
								break;
							}
						}
					}
					if (val2 == (Object)null || val2 == (Object)(object)droneComp || val2 == (Object)(object)((Component)this).gameObject)
					{
						continue;
					}
					Component val3 = (Component)(object)((val2 is Component) ? val2 : null);
					GameObject val4 = (GameObject)(object)((val2 is GameObject) ? val2 : null);
					if ((Object)(object)val3 == (Object)null && (Object)(object)val4 != (Object)null)
					{
						val3 = (Component)(object)val4.transform;
					}
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					PlayerAvatar componentInParent = val3.GetComponentInParent<PlayerAvatar>();
					if ((Object)(object)componentInParent == (Object)null)
					{
						Component componentInParent2 = val3.GetComponentInParent(Registrar.FindType("PlayerTumble") ?? typeof(Transform));
						if ((Object)(object)componentInParent2 != (Object)null)
						{
							componentInParent = componentInParent2.GetComponentInParent<PlayerAvatar>();
						}
					}
					if ((Object)(object)componentInParent != (Object)null && !IsHolder(componentInParent))
					{
						obj = componentInParent;
						if (!loggedScan)
						{
							loggedScan = true;
							Debug.Log((object)("[StunDrone] target field (player): ItemDrone." + fieldInfo.Name));
						}
						break;
					}
					Enemy val5 = ((Heal || Defense) ? null : EnemyFrom(val3));
					if (!((Object)(object)val5 != (Object)null))
					{
						continue;
					}
					obj = val5;
					if (!loggedScan)
					{
						loggedScan = true;
						Debug.Log((object)("[StunDrone] target field (enemy): ItemDrone." + fieldInfo.Name));
					}
					break;
				}
				if (obj != null)
				{
					break;
				}
				type = type.BaseType;
			}
		}
		if (obj != null && StrictBeam && !BeamOnTarget(obj))
		{
			if (Time.time > nextBeamLog)
			{
				nextBeamLog = Time.time + 2f;
				Debug.Log((object)string.Concat("[StunDrone] ItemDrone still references ", obj, " but the beam is not on it -> not attached"));
			}
			obj = null;
		}
		if (obj != null)
		{
			return obj;
		}
		if ((Object)(object)droneComp != (Object)null && Time.time > nextDiag && LineOn() && ToggleOn())
		{
			nextDiag = Time.time + 3f;
			StringBuilder stringBuilder = new StringBuilder("[StunDrone] no target found; ItemDrone fields: ");
			Type type = ((object)droneComp).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object value = null;
					try
					{
						value = fieldInfo.GetValue(droneComp);
					}
					catch
					{
					}
					stringBuilder.Append(fieldInfo.Name).Append('=').Append((value == null) ? "null" : value.ToString())
						.Append("; ");
				}
				type = type.BaseType;
			}
			Debug.Log((object)stringBuilder.ToString());
		}
		return null;
	}

	private bool ToggleOn()
	{
		Type type = Registrar.FindType("ItemToggle");
		if (type == null)
		{
			return true;
		}
		Component val = ((Component)this).GetComponentInChildren(type, true);
		if ((Object)(object)val == (Object)null)
		{
			val = ((Component)this).GetComponentInParent(type);
		}
		if ((Object)(object)val == (Object)null)
		{
			return true;
		}
		Type type2 = ((object)val).GetType();
		while (type2 != null)
		{
			FieldInfo field = type2.GetField("toggleState", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(bool))
			{
				return (bool)field.GetValue(val);
			}
			type2 = type2.BaseType;
		}
		return true;
	}

	private bool IsHolder(PlayerAvatar p)
	{
		try
		{
			Type type = Registrar.FindType("PhysGrabObject");
			if (type == null)
			{
				return false;
			}
			Component val = ((Component)this).GetComponentInParent(type);
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)this).GetComponentInChildren(type, true);
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			FieldInfo field = ((object)val).GetType().GetField("playerGrabbing", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			IList list = ((field != null) ? (field.GetValue(val) as IList) : null);
			if (list == null)
			{
				return false;
			}
			foreach (object item in list)
			{
				if (item == null)
				{
					continue;
				}
				Component val2 = (Component)((item is Component) ? item : null);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				PlayerAvatar val3 = val2.GetComponentInParent<PlayerAvatar>();
				if ((Object)(object)val3 == (Object)null)
				{
					FieldInfo field2 = item.GetType().GetField("playerAvatar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field2 != null)
					{
						object? value = field2.GetValue(item);
						val3 = (PlayerAvatar)((value is PlayerAvatar) ? value : null);
					}
				}
				if (!((Object)(object)val3 == (Object)(object)p))
				{
					continue;
				}
				return true;
			}
		}
		catch
		{
		}
		return false;
	}

	private static Transform EnemyRoot(Component e)
	{
		Type type = Registrar.FindType("EnemyParent");
		if (type != null)
		{
			Component componentInParent = e.GetComponentInParent(type);
			if ((Object)(object)componentInParent != (Object)null)
			{
				return componentInParent.transform;
			}
		}
		Transform val = null;
		Transform val2 = e.transform;
		while ((Object)(object)val2 != (Object)null)
		{
			if (((Object)val2).name.StartsWith("Enemy"))
			{
				val = val2;
			}
			val2 = val2.parent;
		}
		return ((Object)(object)val != (Object)null) ? val : e.transform.root;
	}

	private static Transform TargetRoot(Component c)
	{
		return (c is Enemy) ? EnemyRoot(c) : c.transform.root;
	}

	private static Component FindStun(Component e)
	{
		Component val = null;
		StringBuilder stringBuilder = (stunLogged ? null : new StringBuilder("[StunDrone] enemy state components: "));
		MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot(e)).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val2 in componentsInChildren)
		{
			if (!((Object)(object)val2 == (Object)null))
			{
				string name = ((object)val2).GetType().Name;
				if (stringBuilder != null && name.StartsWith("EnemyState"))
				{
					stringBuilder.Append(name).Append("; ");
				}
				if ((Object)(object)val == (Object)null && name.StartsWith("EnemyState") && name.ToLower().Contains("stun"))
				{
					val = (Component)(object)val2;
				}
			}
		}
		if (stringBuilder != null)
		{
			stunLogged = true;
			Debug.Log((object)(stringBuilder.ToString() + " -> stun: " + (((Object)(object)val != (Object)null) ? ((object)val).GetType().Name : "NOT FOUND")));
		}
		return val;
	}

	private static Enemy EnemyFrom(Component c)
	{
		Enemy componentInParent = c.GetComponentInParent<Enemy>();
		if ((Object)(object)componentInParent != (Object)null)
		{
			return componentInParent;
		}
		Type type = Registrar.FindType("EnemyParent");
		if (type != null)
		{
			Component componentInParent2 = c.GetComponentInParent(type);
			if ((Object)(object)componentInParent2 != (Object)null)
			{
				componentInParent = componentInParent2.GetComponentInChildren<Enemy>(true);
				if ((Object)(object)componentInParent != (Object)null)
				{
					return componentInParent;
				}
			}
		}
		Transform val = c.transform;
		while ((Object)(object)val != (Object)null)
		{
			MonoBehaviour[] components = ((Component)val).GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val2 in components)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Type type2 = ((object)val2).GetType();
				while (type2 != null && type2 != typeof(MonoBehaviour))
				{
					FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo in fields)
					{
						if (fieldInfo.FieldType == typeof(Enemy))
						{
							object? value = fieldInfo.GetValue(val2);
							Enemy val3 = (Enemy)((value is Enemy) ? value : null);
							if ((Object)(object)val3 != (Object)null)
							{
								return val3;
							}
						}
					}
					type2 = type2.BaseType;
				}
			}
			val = val.parent;
		}
		return null;
	}

	private bool BeamOnTarget(object target)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_009b: 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_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_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_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: 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_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		Component val = (Component)((target is Component) ? target : null);
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		bool flag = false;
		Bounds bounds = default(Bounds);
		((Bounds)(ref bounds))..ctor(val.transform.position, Vector3.one * 0.5f);
		bool flag2 = true;
		Renderer[] componentsInChildren = ((Component)TargetRoot(val)).GetComponentsInChildren<Renderer>(false);
		foreach (Renderer val2 in componentsInChildren)
		{
			if (!((Object)(object)val2 == (Object)null) && !(val2 is ParticleSystemRenderer) && !(val2 is LineRenderer))
			{
				if (flag2)
				{
					bounds = val2.bounds;
					flag2 = false;
				}
				else
				{
					((Bounds)(ref bounds)).Encapsulate(val2.bounds);
				}
			}
		}
		LineRenderer[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<LineRenderer>(false);
		foreach (LineRenderer val3 in componentsInChildren2)
		{
			if (!((Object)(object)val3 == (Object)null) && ((Renderer)val3).enabled && ((Component)val3).gameObject.activeInHierarchy && val3.positionCount >= 2)
			{
				flag = true;
				Vector3 val4 = val3.GetPosition(0);
				Vector3 val5 = val3.GetPosition(val3.positionCount - 1);
				if (!val3.useWorldSpace)
				{
					val4 = ((Component)val3).transform.TransformPoint(val4);
					val5 = ((Component)val3).transform.TransformPoint(val5);
				}
				if (!(Vector3.Distance(val4, val5) < 0.3f) && (((Bounds)(ref bounds)).SqrDistance(val4) < 4f || ((Bounds)(ref bounds)).SqrDistance(val5) < 4f))
				{
					return true;
				}
			}
		}
		if (!flag && Time.time > nextBeamLog)
		{
			nextBeamLog = Time.time + 2f;
			Debug.Log((object)"[StunDrone] no active LineRenderer on drone");
		}
		return false;
	}

	private bool LineOn()
	{
		Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(false);
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name == "Line" && ((Component)val).gameObject.activeInHierarchy)
			{
				return true;
			}
		}
		return false;
	}

	private static bool BoolMember(object o, string name)
	{
		Type type = o.GetType();
		while (type != null)
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(bool))
			{
				return (bool)field.GetValue(o);
			}
			PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.PropertyType == typeof(bool) && property.CanRead && property.GetIndexParameters().Length == 0)
			{
				try
				{
					return (bool)property.GetValue(o, null);
				}
				catch
				{
					return false;
				}
			}
			type = type.BaseType;
		}
		return false;
	}

	private static Component FindComp(Component c, string typeName)
	{
		Type type = Registrar.FindType(typeName);
		if (type == null)
		{
			return null;
		}
		Component val = c.GetComponentInChildren(type, true);
		if ((Object)(object)val == (Object)null)
		{
			val = c.GetComponentInParent(type);
		}
		if ((Object)(object)val == (Object)null)
		{
			val = ((Component)c.transform.root).GetComponentInChildren(type, true);
		}
		return val;
	}

	private static bool CallMethod(object o, string name, params object[] args)
	{
		Type type = o.GetType();
		while (type != null)
		{
			MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name != name)
				{
					continue;
				}
				ParameterInfo[] parameters = methodInfo.GetParameters();
				if (parameters.Length >= args.Length)
				{
					object[] array = new object[parameters.Length];
					for (int j = 0; j < parameters.Length; j++)
					{
						array[j] = ((j < args.Length) ? args[j] : (parameters[j].IsOptional ? parameters[j].DefaultValue : null));
					}
					try
					{
						methodInfo.Invoke(o, array);
						return true;
					}
					catch (Exception ex)
					{
						Debug.LogWarning((object)("[StunDrone] " + name + " threw: " + ((ex.InnerException != null) ? ex.InnerException.Message : ex.Message)));
					}
				}
			}
			type = type.BaseType;
		}
		return false;
	}

	private static Component FindTumble(PlayerAvatar p)
	{
		Type type = ((object)p).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.Name == "PlayerTumble")
				{
					object? value = fieldInfo.GetValue(p);
					Component val = (Component)((value is Component) ? value : null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
			PropertyInfo[] properties = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (!(propertyInfo.PropertyType.Name == "PlayerTumble") || !propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length != 0)
				{
					continue;
				}
				try
				{
					object? value2 = propertyInfo.GetValue(p, null);
					Component val = (Component)((value2 is Component) ? value2 : null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				catch
				{
				}
			}
			type = type.BaseType;
		}
		Component val2 = FindComp((Component)(object)p, "PlayerTumble");
		if ((Object)(object)val2 != (Object)null)
		{
			return val2;
		}
		Type type2 = Registrar.FindType("PlayerTumble");
		if (type2 == null)
		{
			return null;
		}
		Object[] array = Object.FindObjectsByType(type2, (FindObjectsSortMode)0);
		foreach (Object val3 in array)
		{
			Component val4 = (Component)(object)((val3 is Component) ? val3 : null);
			if ((Object)(object)val4 == (Object)null)
			{
				continue;
			}
			Type type3 = ((object)val4).GetType();
			while (type3 != null && type3 != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type3.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo2 in fields)
				{
					if (fieldInfo2.FieldType == typeof(PlayerAvatar) && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)p)
					{
						return val4;
					}
				}
				type3 = type3.BaseType;
			}
		}
		return null;
	}

	private PlayerAvatar FindNearestPlayer()
	{
		//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)
		PlayerAvatar result = null;
		float num = 6f;
		PlayerAvatar[] array = Object.FindObjectsByType<PlayerAvatar>((FindObjectsSortMode)0);
		foreach (PlayerAvatar val in array)
		{
			if (!BoolMember(val, "isDisabled") && !BoolMember(val, "deadSet") && !((Object)(object)FindTumble(val) == (Object)null))
			{
				float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = val;
				}
			}
		}
		return result;
	}

	private Enemy FindNearestEnemy(bool skipStunned)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		Enemy result = null;
		float num = 6f;
		Enemy[] array = Object.FindObjectsByType<Enemy>((FindObjectsSortMode)0);
		foreach (Enemy val in array)
		{
			if (!skipStunned || !val.IsStunned())
			{
				float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = val;
				}
			}
		}
		return result;
	}

	private static bool IsDronePartName(string n)
	{
		n = n.Replace('_', ' ').Trim();
		return n == "Drone" || n.StartsWith("Drone Triangle") || n.StartsWith("Drone Pyramid") || n.StartsWith("Drone Icon");
	}

	private void AddBatteryRefs(object v)
	{
		if (v == null)
		{
			return;
		}
		if (v is IEnumerable enumerable && !(v is string) && !(v is Object))
		{
			foreach (object item2 in enumerable)
			{
				AddBatteryRefs(item2);
			}
			return;
		}
		Object val = (Object)((v is Object) ? v : null);
		if (val == (Object)null)
		{
			return;
		}
		Transform val2 = null;
		Renderer val3 = (Renderer)(object)((val is Renderer) ? val : null);
		if ((Object)(object)val3 != (Object)null)
		{
			batRend.Add(val3);
			return;
		}
		Component val4 = (Component)(object)((val is Component) ? val : null);
		if ((Object)(object)val4 != (Object)null)
		{
			val2 = val4.transform;
		}
		GameObject val5 = (GameObject)(object)((val is GameObject) ? val : null);
		if ((Object)(object)val5 != (Object)null)
		{
			val2 = val5.transform;
		}
		if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)((Component)this).transform) && !((Component)this).transform.IsChildOf(val2) && !IsDronePartName(((Object)val2).name))
		{
			Renderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer item in componentsInChildren)
			{
				batRend.Add(item);
			}
		}
	}

	private void CollectBatteryRenderers()
	{
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)this)
			{
				continue;
			}
			string name = ((object)val).GetType().Name;
			if (name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) < 0)
			{
				continue;
			}
			if (name.IndexOf("Visual", StringComparison.OrdinalIgnoreCase) >= 0 && (Object)(object)((Component)val).transform != (Object)(object)((Component)this).transform && !IsDronePartName(((Object)((Component)val).transform).name))
			{
				Renderer[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer item in componentsInChildren2)
				{
					batRend.Add(item);
				}
			}
			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.IsPrimitive && !(fieldInfo.FieldType == typeof(string)))
					{
						object v = null;
						try
						{
							v = fieldInfo.GetValue(val);
						}
						catch
						{
						}
						AddBatteryRefs(v);
					}
				}
				type = type.BaseType;
			}
		}
		Debug.Log((object)("[StunDrone] battery renderers excluded from retexture: " + batRend.Count));
	}

	private bool IsBatteryRenderer(Renderer r)
	{
		if (batRend.Contains(r) || IsUnder(((Component)r).transform, "Battery") || IsUnder(((Component)r).transform, "Bar"))
		{
			return true;
		}
		Transform val = ((Component)r).transform;
		while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)((Component)this).transform)
		{
			MonoBehaviour[] components = ((Component)val).GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val2 in components)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)this && ((object)val2).GetType().Name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					batRend.Add(r);
					return true;
				}
			}
			val = val.parent;
		}
		return false;
	}

	private static bool IsUnder(Transform t, string part)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name.IndexOf(part, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private static int[] ColorProps(Material m)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Invalid comparison between Unknown and I4
		List<int> list = new List<int>();
		Shader val = (((Object)(object)m != (Object)null) ? m.shader : null);
		if ((Object)(object)val == (Object)null)
		{
			return list.ToArray();
		}
		int propertyCount = val.GetPropertyCount();
		for (int i = 0; i < propertyCount; i++)
		{
			if ((int)val.GetPropertyType(i) == 0)
			{
				list.Add(Shader.PropertyToID(val.GetPropertyName(i)));
			}
		}
		return list.ToArray();
	}

	private static Gradient SolidGradient(Color c)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		Gradient val = new Gradient();
		val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
		{
			new GradientColorKey(c, 0f),
			new GradientColorKey(c, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
		{
			new GradientAlphaKey(1f, 0f),
			new GradientAlphaKey(1f, 1f)
		});
		return val;
	}

	private void TintBeams()
	{
		//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_013e: 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_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		if (Time.time > nextBeamFind)
		{
			nextBeamFind = Time.time + 1f;
			beamList.Clear();
			Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !IsUnder(((Component)val).transform, "Drone Icon") && !IsBatteryRenderer(val) && (val is LineRenderer || val is ParticleSystemRenderer || val is TrailRenderer || Classify(((Component)val).transform) == Part.Skip))
				{
					beamList.Add(val);
				}
			}
		}
		Color orange = Orange;
		foreach (Renderer beam in beamList)
		{
			if (!((Object)(object)beam == (Object)null))
			{
				LineRenderer val2 = (LineRenderer)(object)((beam is LineRenderer) ? beam : null);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.startColor = orange;
					val2.endColor = orange;
					val2.colorGradient = SolidGradient(orange);
				}
				Material material = beam.material;
				if (!beamProps.TryGetValue(beam, out var value))
				{
					value = ColorProps(material);
					beamProps[beam] = value;
				}
				int[] array = value;
				foreach (int num in array)
				{
					Color color = material.GetColor(num);
					material.SetColor(num, new Color(orange.r, orange.g, orange.b, color.a));
				}
			}
		}
	}

	private void ApplyDroneFieldColors()
	{
		//IL_0100: 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)
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] drone color fields: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)this)
			{
				continue;
			}
			string name = ((object)val).GetType().Name;
			if (name == "ItemAttributes" || name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) >= 0 || val is Graphic)
			{
				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)
				{
					string text = fieldInfo.Name.ToLower();
					if (fieldInfo.FieldType == typeof(Color) && text.Contains("color"))
					{
						fieldInfo.SetValue(val, Orange);
						if (!fieldColorLogged)
						{
							stringBuilder.Append(name).Append('.').Append(fieldInfo.Name)
								.Append("; ");
						}
					}
					else if (fieldInfo.FieldType == typeof(Gradient) && (text.Contains("color") || text.Contains("gradient")))
					{
						fieldInfo.SetValue(val, SolidGradient(Orange));
						if (!fieldColorLogged)
						{
							stringBuilder.Append(name).Append('.').Append(fieldInfo.Name)
								.Append("(gradient); ");
						}
					}
				}
				type = type.BaseType;
			}
		}
		if (!fieldColorLogged)
		{
			fieldColorLogged = true;
			Debug.Log((object)stringBuilder.ToString());
		}
	}

	private static void SetNum(object o, string name, float v)
	{
		Type type = o.GetType();
		while (type != null && type != typeof(MonoBehaviour))
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(field == null))
			{
				if (field.FieldType == typeof(float))
				{
					field.SetValue(o, v);
				}
				else if (field.FieldType == typeof(int))
				{
					field.SetValue(o, Mathf.RoundToInt(v));
				}
				break;
			}
			type = type.BaseType;
		}
	}

	private static bool GetNum(object o, string name, out float v)
	{
		v = 0f;
		Type type = o.GetType();
		while (type != null && type != typeof(MonoBehaviour))
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(field == null))
			{
				if (field.FieldType == typeof(float))
				{
					v = (float)field.GetValue(o);
					return true;
				}
				if (field.FieldType == typeof(int))
				{
					v = (int)field.GetValue(o);
					return true;
				}
				return false;
			}
			type = type.BaseType;
		}
		return false;
	}

	private void SyncBattery()
	{
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)batteryComp == (Object)null)
		{
			if (Time.time < nextBatFind)
			{
				return;
			}
			nextBatFind = Time.time + 1f;
			MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && ((object)val).GetType().Name == "ItemBattery")
				{
					batteryComp = (Component)(object)val;
					break;
				}
			}
			if ((Object)(object)batteryComp == (Object)null)
			{
				return;
			}
		}
		if (!batteryLogged)
		{
			batteryLogged = true;
			Debug.Log((object)("[StunDrone] ItemBattery found, bars=" + Cap));
		}
		SetNum(batteryComp, "batteryBars", Cap);
		if (!uiDumped && Time.time > nextBatFind + 3f && batteryLogged)
		{
			uiDumped = true;
			StringBuilder stringBuilder = new StringBuilder("[StunDrone] battery UI dump: ");
			Graphic[] componentsInChildren2 = batteryComp.GetComponentsInChildren<Graphic>(true);
			foreach (Graphic val2 in componentsInChildren2)
			{
				string text = ((Object)val2).name;
				Transform parent = ((Component)val2).transform.parent;
				while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)batteryComp.transform)
				{
					text = ((Object)parent).name + "/" + text;
					parent = parent.parent;
				}
				stringBuilder.Append(text).Append(" [").Append(((object)val2).GetType().Name)
					.Append(((Component)val2).gameObject.activeInHierarchy ? "" : ",off")
					.Append(", ")
					.Append(val2.color)
					.Append("]; ");
			}
			Debug.Log((object)stringBuilder.ToString());
		}
		float v;
		if (lifeVal < 0f)
		{
			if (GetNum(batteryComp, "batteryLife", out v) && v >= 0f && v <= 100f)
			{
				lifeVal = v;
				charge = Mathf.Clamp(Mathf.FloorToInt(v * (float)Cap / 100f + 0.001f), 0, Cap);
				Debug.Log((object)("[StunDrone] restored charge " + charge + "/" + Cap + " from batteryLife=" + v));
			}
			else
			{
				lifeVal = 100f * (float)charge / (float)Cap;
			}
			lastCharge = charge;
		}
		if (GetNum(batteryComp, "batteryLife", out v) && v > lifeVal + 0.01f)
		{
			lifeVal = Mathf.Min(100f, v);
			charge = Mathf.Clamp(Mathf.FloorToInt(lifeVal * (float)Cap / 100f + 0.001f), 0, Cap);
		}
		else if (charge < lastCharge)
		{
			lifeVal = 100f * (float)charge / (float)Cap;
		}
		else if (charge > lastCharge)
		{
			lifeVal = Mathf.Max(lifeVal, 100f * (float)charge / (float)Cap);
		}
		if (lifeVal >= 99.5f)
		{
			lifeVal = 100f;
			charge = Cap;
		}
		lastCharge = charge;
		SetNum(batteryComp, "batteryLife", lifeVal);
		if (charge >= Cap)
		{
			SetNum(batteryComp, "batteryLifeInt", Cap);
		}
		if (Time.time > nextBatDump && charge != dumpedCharge)
		{
			nextBatDump = Time.time + 2f;
			dumpedCharge = charge;
			StringBuilder stringBuilder2 = new StringBuilder("[StunDrone] ItemBattery dump (charge=" + charge + "/" + Cap + "): ");
			Type type = ((object)batteryComp).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) || fieldInfo.FieldType == typeof(int) || fieldInfo.FieldType == typeof(bool))
					{
						stringBuilder2.Append(string.Concat(fieldInfo.Name, "=", fieldInfo.GetValue(batteryComp), "; "));
					}
				}
				type = type.BaseType;
			}
			Debug.Log((object)stringBuilder2.ToString());
		}
		Type type2 = ((object)batteryComp).GetType();
		while (type2 != null && type2 != typeof(MonoBehaviour))
		{
			FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo2 in fields)
			{
				if (fieldInfo2.FieldType == typeof(float) && fieldInfo2.Name.ToLower().Contains("drain"))
				{
					fieldInfo2.SetValue(batteryComp, 0f);
				}
			}
			type2 = type2.BaseType;
		}
	}

	private static bool IsAuthority()
	{
		try
		{
			return !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient;
		}
		catch
		{
			return true;
		}
	}

	private static bool IntMember(object o, string name, out int v)
	{
		v = 0;
		Type type = o.GetType();
		while (type != null)
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(int))
			{
				v = (int)field.GetValue(o);
				return true;
			}
			PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.PropertyType == typeof(int) && property.CanRead && property.GetIndexParameters().Length == 0)
			{
				try
				{
					v = (int)property.GetValue(o, null);
					return true;
				}
				catch
				{
					return false;
				}
			}
			type = type.BaseType;
		}
		return false;
	}

	private static Component FindHealth(PlayerAvatar p)
	{
		Type type = ((object)p).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.Name == "PlayerHealth")
				{
					object? value = fieldInfo.GetValue(p);
					Component val = (Component)((value is Component) ? value : null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
			type = type.BaseType;
		}
		return FindComp((Component)(object)p, "PlayerHealth");
	}

	private bool NeedsHeal(PlayerAvatar p)
	{
		if ((Object)(object)p == (Object)null)
		{
			return false;
		}
		if (BoolMember(p, "isDisabled") || BoolMember(p, "deadSet"))
		{
			return false;
		}
		Component val = FindHealth(p);
		if ((Object)(object)val == (Object)null)
		{
			return true;
		}
		if (IntMember(val, "health", out var v) && IntMember(val, "maxHealth", out var v2))
		{
			return v < v2;
		}
		return true;
	}

	private void HealTick()
	{
		object obj = stunned;
		PlayerAvatar val = (PlayerAvatar)((obj is PlayerAvatar) ? obj : null);
		if ((Object)(object)val == (Object)null || Time.time < nextHeal)
		{
			return;
		}
		nextHeal = Time.time + HealInterval;
		if (!IsAuthority() || !NeedsHeal(val))
		{
			return;
		}
		Component val2 = FindHealth(val);
		if ((Object)(object)val2 == (Object)null)
		{
			if (!healWarned)
			{
				healWarned = true;
				Debug.LogWarning((object)"[HealDrone] PlayerHealth not found");
			}
		}
		else if (CallMethod(val2, "Heal", HealAmount, true) || CallMethod(val2, "Heal", HealAmount))
		{
			charge--;
			Debug.Log((object)("[HealDrone] healed " + HealAmount + " HP, charge=" + charge));
		}
		else if (!healWarned)
		{
			healWarned = true;
			Debug.LogWarning((object)"[HealDrone] PlayerHealth.Heal call failed");
		}
	}

	private void StunPlayer(PlayerAvatar p)
	{
		try
		{
			if ((Object)(object)tumbleCache == (Object)null || (Object)(object)cachedFor != (Object)(object)p)
			{
				tumbleCache = FindTumble(p);
				cachedFor = p;
			}
			Component val = tumbleCache;
			if ((Object)(object)val == (Object)null)
			{
				if (!tumbleWarned)
				{
					tumbleWarned = true;
					Debug.LogWarning((object)"[StunDrone] PlayerTumble not found");
				}
				return;
			}
			if (!CallMethod(val, "TumbleRequest", true, true) && !tumbleWarned)
			{
				tumbleWarned = true;
				Debug.LogWarning((object)"[StunDrone] TumbleRequest call failed");
			}
			CallMethod(val, "TumbleOverrideTime", 3f);
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[StunDrone] StunPlayer: " + ex.Message));
		}
	}

	private void StunEnemy(Enemy e)
	{
		try
		{
			Component val = FindStun((Component)(object)e);
			if ((Object)(object)val != (Object)null && CallMethod(val, "Set", 1.5f))
			{
				if (!stunOk)
				{
					stunOk = true;
					Debug.Log((object)("[StunDrone] enemy stunned via " + ((object)val).GetType().Name + ".Set on " + ((Object)e).name));
				}
				return;
			}
			if ((Object)(object)val != (Object)null && !stunWarned2)
			{
				stunWarned2 = true;
				StringBuilder stringBuilder = new StringBuilder("[StunDrone] " + ((object)val).GetType().Name + " methods: ");
				MethodInfo[] methods = ((object)val).GetType().GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					stringBuilder.Append(methodInfo.Name).Append('(');
					ParameterInfo[] parameters = methodInfo.GetParameters();
					foreach (ParameterInfo parameterInfo in parameters)
					{
						stringBuilder.Append(parameterInfo.ParameterType.Name).Append(' ');
					}
					stringBuilder.Append("); ");
				}
				Debug.LogWarning((object)stringBuilder.ToString());
			}
			if ((Object)(object)val == (Object)null && !noStunLogged.Contains(((Object)e).name))
			{
				noStunLogged.Add(((Object)e).name);
				Debug.LogWarning((object)("[StunDrone] enemy '" + ((Object)e).name + "' has no stun state -> freezing manually"));
			}
			FreezeEnemy(e);
			bool flag = false;
			MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val2 in componentsInChildren)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Type type = ((object)val2).GetType();
				while (type != null && type != typeof(MonoBehaviour))
				{
					FieldInfo field = type.GetField("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.FieldType == typeof(bool))
					{
						field.SetValue(val2, true);
						flag = true;
					}
					PropertyInfo property = type.GetProperty("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null && property.PropertyType == typeof(bool) && property.CanWrite)
					{
						try
						{
							property.SetValue(val2, true, null);
							flag = true;
						}
						catch
						{
						}
					}
					type = type.BaseType;
				}
			}
			if (!flag)
			{
				Debug.LogWarning((object)"[StunDrone] no way to stun enemy (no EnemyState*Stun*, no Stunned flag)");
			}
			else if (!stunWarned)
			{
				stunWarned = true;
				Debug.LogWarning((object)"[StunDrone] used Stunned flag fallback (state component not found) - may not actually stop the AI");
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[StunDrone] StunEnemy: " + ex.Message));
		}
	}

	private void FreezeEnemy(Enemy e)
	{
		//IL_00b9: 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)
		MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)null))
			{
				string name = ((object)val).GetType().Name;
				if (name == "EnemyNavMeshAgent")
				{
					CallMethod(val, "Disable", 0.3f);
				}
			}
		}
		Rigidbody[] componentsInChildren2 = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<Rigidbody>(true);
		foreach (Rigidbody val2 in componentsInChildren2)
		{
			if ((Object)(object)val2 != (Object)null && !val2.isKinematic)
			{
				val2.linearVelocity = Vector3.zero;
				val2.angularVelocity = Vector3.zero;
			}
		}
	}

	private void DefenseTick(PlayerAvatar p)
	{
		DefenseHighlight defenseHighlight = ((Component)p).GetComponent<DefenseHighlight>();
		if ((Object)(object)defenseHighlight == (Object)null)
		{
			defenseHighlight = ((Component)p).gameObject.AddComponent<DefenseHighlight>();
		}
		defenseHighlight.SetActive(active: true);
		DefenseHudOverlay.SetProtected(p, active: true);
		if (!IsAuthority())
		{
			return;
		}
		Component val = FindHealth(p);
		if ((Object)(object)val == (Object)null || !IntMember(val, "health", out var v))
		{
			return;
		}
		if ((Object)(object)lastDefPlayer != (Object)(object)p)
		{
			lastDefPlayer = p;
			lastDefHp = v;
			return;
		}
		if (v < lastDefHp && v > 0)
		{
			int num = lastDefHp - v;
			CallMethod(val, "Heal", num, false);
			IntMember(val, "health", out v);
		}
		lastDefHp = v;
	}

	private void ClearDefense(object target)
	{
		lastDefPlayer = null;
		lastDefHp = -1;
		PlayerAvatar val = (PlayerAvatar)((target is PlayerAvatar) ? target : null);
		if (!((Object)(object)val == (Object)null))
		{
			DefenseHighlight component = ((Component)val).GetComponent<DefenseHighlight>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetActive(active: false);
			}
			DefenseHudOverlay.SetProtected(val, active: false);
		}
	}
}
public class HealDroneLogic : StunDroneLogic
{
}
public class DefenseDroneLogic : StunDroneLogic
{
}
public class DefenseHudOverlay : MonoBehaviour
{
	private struct GraphicState
	{
		public Graphic graphic;

		public Color origColor;
	}

	private static DefenseHudOverlay instance;

	private static readonly Dictionary<int, float> protectedUntil = new Dictionary<int, float>();

	private static Texture2D shieldTex;

	public static float ShieldOffsetX = 8f;

	public static float ShieldOffsetY = 0f;

	public static float ShieldScale = 0.7f;

	private readonly List<GraphicState> tintedGraphics = new List<GraphicState>();

	private GameObject shieldBadgeGo;

	private RawImage shieldBadgeImg;

	private bool hudApplied;

	private float nextScan;

	public static void SetProtected(PlayerAvatar p, bool active)
	{
		if (!((Object)(object)p == (Object)null))
		{
			int instanceID = ((Object)p).GetInstanceID();
			if (active)
			{
				protectedUntil[instanceID] = Time.time + 1.5f;
			}
			else
			{
				protectedUntil.Remove(instanceID);
			}
			EnsureInstance();
		}
	}

	private static void EnsureInstance()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		if (!((Object)(object)instance != (Object)null))
		{
			GameObject val = new GameObject("DefenseDroneHudOverlay");
			Object.DontDestroyOnLoad((Object)(object)val);
			instance = val.AddComponent<DefenseHudOverlay>();
		}
	}

	private static bool IsLocalPlayerProtected()
	{
		if (protectedUntil.Count == 0)
		{
			return false;
		}
		float time = Time.time;
		List<int> list = new List<int>();
		bool flag = false;
		foreach (KeyValuePair<int, float> item in protectedUntil)
		{
			if (item.Value < time)
			{
				list.Add(item.Key);
			}
		}
		for (int i = 0; i < list.Count; i++)
		{
			protectedUntil.Remove(list[i]);
		}
		if (protectedUntil.Count == 0)
		{
			return false;
		}
		PlayerAvatar[] array = Object.FindObjectsByType<PlayerAvatar>((FindObjectsSortMode)0);
		foreach (PlayerAvatar val in array)
		{
			if (!((Object)(object)val == (Object)null) && protectedUntil.ContainsKey(((Object)val).GetInstanceID()) && IsLocalAvatar(val))
			{
				flag = true;
				break;
			}
		}
		if (!flag && protectedUntil.Count > 0)
		{
			flag = true;
		}
		return flag;
	}

	private static bool IsLocalAvatar(PlayerAvatar p)
	{
		if ((Object)(object)p == (Object)null)
		{
			return false;
		}
		try
		{
			PhotonView component = ((Component)p).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null)
			{
				return component.IsMine;
			}
		}
		catch
		{
		}
		try
		{
			FieldInfo field = ((object)p).GetType().GetField("photonView", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				object? value = field.GetValue(p);
				PhotonView val = (PhotonView)((value is PhotonView) ? value : null);
				if ((Object)(object)val != (Object)null)
				{
					return val.IsMine;
				}
			}
		}
		catch
		{
		}
		return false;
	}

	private static Texture2D GetShieldTexture()
	{
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)shieldTex != (Object)null)
		{
			return shieldTex;
		}
		try
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("def_shield.png");
			if (stream != null)
			{
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (ImageConversion.LoadImage(val, array))
				{
					shieldTex = val;
					return shieldTex;
				}
			}
		}
		catch
		{
		}
		Texture2D val2 = new Texture2D(32, 32, (TextureFormat)4, false);
		Color val3 = default(Color);
		((Color)(ref val3))..ctor(0f, 0f, 0f, 0f);
		for (int i = 0; i < 32; i++)
		{
			for (int j = 0; j < 32; j++)
			{
				val2.SetPixel(j, i, val3);
			}
		}
		val2.Apply();
		shieldTex = val2;
		return shieldTex;
	}

	private void Update()
	{
		if (!IsLocalPlayerProtected())
		{
			if (hudApplied)
			{
				RestoreHud();
			}
		}
		else if (!hudApplied || Time.time >= nextScan)
		{
			nextScan = Time.time + 0.1f;
			ApplyHud();
		}
	}

	private static bool IsInsideHealth(Transform t)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name == "Health")
			{
				return true;
			}
			if (((Object)val).name == "Game Hud")
			{
				break;
			}
			val = val.parent;
		}
		return false;
	}

	private static bool IsInsideNamed(Transform t, string name)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name == name)
			{
				return true;
			}
			if (((Object)val).name == "Health" || ((Object)val).name == "Game Hud")
			{
				break;
			}
			val = val.parent;
		}
		return false;
	}

	private static bool GetTextWorldBounds(Graphic g, RectTransform rt, out Vector3 a, out Vector3 b)
	{
		//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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0068: 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_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00bc: Unknown result type (might be due to invalid IL or missing references)
		a = Vector3.zero;
		b = Vector3.zero;
		try
		{
			PropertyInfo property = ((object)g).GetType().GetProperty("textBounds", BindingFlags.Instance | BindingFlags.Public);
			if (property == null || property.PropertyType != typeof(Bounds))
			{
				return false;
			}
			Bounds val = (Bounds)property.GetValue(g, null);
			if (((Bounds)(ref val)).size.x < 0.01f || ((Bounds)(ref val)).size.y < 0.01f)
			{
				return false;
			}
			a = ((Transform)rt).TransformPoint(((Bounds)(ref val)).min);
			b = ((Transform)rt).TransformPoint(((Bounds)(ref val)).max);
			return true;
		}
		catch
		{
			return false;
		}
	}

	private static RectTransform FindHealthRoot()
	{
		RectTransform val = null;
		RectTransform[] array = Object.FindObjectsByType<RectTransform>((FindObjectsSortMode)0);
		foreach (RectTransform val2 in array)
		{
			if (!((Object)(object)val2 == (Object)null) && !(((Object)((Component)val2).gameObject).name != "Health") && IsUnderGameHud((Transform)(object)val2) && ((Object)(object)val == (Object)null || (((Component)val2).gameObject.activeInHierarchy && !((Component)val).gameObject.activeInHierarchy)))
			{
				val = val2;
			}
		}
		return val;
	}

	private static bool IsUnderGameHud(Transform t)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name == "Game Hud")
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private void ApplyHud()
	{
		//IL_03c5: 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_0158: 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_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: 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_0268: 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_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_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: 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_025d: Unknown result type (might be due to invalid IL or missing references)
		hudApplied = true;
		Color val = default(Color);
		((Color)(ref val))..ctor(0.14f, 0.66f, 1f, 1f);
		RectTransform val2 = FindHealthRoot();
		bool flag = false;
		bool flag2 = false;
		float num = 0f;
		float num2 = 0f;
		float num3 = 0f;
		float num4 = 0f;
		Vector3[] array = (Vector3[])(object)new Vector3[4];
		Graphic[] array2 = Object.FindObjectsByType<Graphic>((FindObjectsSortMode)0);
		foreach (Graphic val3 in array2)
		{
			if ((Object)(object)val3 == (Object)null || ((Object)(object)shieldBadgeGo != (Object)null && ((Component)val3).transform.IsChildOf(shieldBadgeGo.transform)) || !IsInsideHealth(((Component)val3).transform))
			{
				continue;
			}
			bool flag3 = false;
			for (int j = 0; j < tintedGraphics.Count; j++)
			{
				if ((Object)(object)tintedGraphics[j].graphic == (Object)(object)val3)
				{
					flag3 = true;
					break;
				}
			}
			if (!flag3)
			{
				tintedGraphics.Add(new GraphicState
				{
					graphic = val3,
					origColor = val3.color
				});
			}
			Color color = val;
			color.a = ((val3.color.a > 0f) ? val3.color.a : 1f);
			val3.color = color;
			if ((Object)(object)val2 == (Object)null || !((Component)val3).gameObject.activeInHierarchy || !((Behaviour)val3).enabled)
			{
				continue;
			}
			bool flag4 = IsInsideNamed(((Component)val3).transform, "HealthMax");
			if (!flag4 && flag2)
			{
				continue;
			}
			if (flag4 && !flag2)
			{
				flag = false;
				flag2 = true;
			}
			RectTransform rectTransform = val3.rectTransform;
			if ((Object)(object)rectTransform == (Object)null)
			{
				continue;
			}
			if (!GetTextWorldBounds(val3, rectTransform, out var a, out var b))
			{
				rectTransform.GetWorldCorners(array);
				a = array[0];
				b = array[2];
			}
			Vector3 val4 = ((Transform)val2).InverseTransformPoint(a);
			Vector3 val5 = ((Transform)val2).InverseTransformPoint(b);
			float num5 = Mathf.Min(val4.x, val5.x);
			float num6 = Mathf.Max(val4.x, val5.x);
			float num7 = Mathf.Min(val4.y, val5.y);
			float num8 = Mathf.Max(val4.y, val5.y);
			if (num6 - num5 < 0.01f || num8 - num7 < 0.01f)
			{
				continue;
			}
			if (!flag)
			{
				num = num5;
				num2 = num6;
				num3 = num7;
				num4 = num8;
				flag = true;
				continue;
			}
			if (num5 < num)
			{
				num = num5;
			}
			if (num6 > num2)
			{
				num2 = num6;
			}
			if (num7 < num3)
			{
				num3 = num7;
			}
			if (num8 > num4)
			{
				num4 = num8;
			}
		}
		if (!((Object)(object)val2 == (Object)null))
		{
			Vector2 localPos = default(Vector2);
			if (flag)
			{
				((Vector2)(ref localPos))..ctor(num2 + ShieldOffsetX, (num3 + num4) * 0.5f + ShieldOffsetY);
			}
			else
			{
				((Vector2)(ref localPos))..ctor(ShieldOffsetX, ShieldOffsetY);
			}
			EnsureShieldBadge(val2, localPos, 64f * ShieldScale);
		}
	}

	private void EnsureShieldBadge(RectTransform healthRoot, Vector2 localPos, float size)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_00cb: 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_00f7: 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_0119: 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_0133: 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)
		if ((Object)(object)shieldBadgeGo == (Object)null)
		{
			shieldBadgeGo = new GameObject("DefenseDroneShieldIcon", new Type[1] { typeof(RectTransform) });
			shieldBadgeImg = shieldBadgeGo.AddComponent<RawImage>();
			((Graphic)shieldBadgeImg).raycastTarget = false;
		}
		RectTransform component = shieldBadgeGo.GetComponent<RectTransform>();
		if ((Object)(object)((Transform)component).parent != (Object)(object)healthRoot)
		{
			((Transform)component).SetParent((Transform)(object)healthRoot, false);
			shieldBadgeGo.layer = ((Component)healthRoot).gameObject.layer;
		}
		shieldBadgeGo.SetActive(true);
		((Behaviour)shieldBadgeImg).enabled = true;
		shieldBadgeImg.texture = (Texture)(object)GetShieldTexture();
		((Graphic)shieldBadgeImg).color = Color.white;
		component.anchorMin = new Vector2(0.5f, 0.5f);
		component.anchorMax = new Vector2(0.5f, 0.5f);
		component.pivot = new Vector2(0f, 0.5f);
		((Transform)component).localScale = Vector3.one;
		((Transform)component).localRotation = Quaternion.identity;
		component.sizeDelta = new Vector2(size, size);
		((Transform)component).localPosition = new Vector3(localPos.x, localPos.y, 0f);
		((Transform)component).SetAsLastSibling();
	}

	private void RestoreHud()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		hudApplied = false;
		for (int i = 0; i < tintedGraphics.Count; i++)
		{
			GraphicState graphicState = tintedGraphics[i];
			if ((Object)(object)graphicState.graphic != (Object)null)
			{
				graphicState.graphic.color = graphicState.origColor;
			}
		}
		tintedGraphics.Clear();
		if ((Object)(object)shieldBadgeGo != (Object)null)
		{
			shieldBadgeGo.SetActive(false);
		}
	}

	private void OnDisable()
	{
		RestoreHud();
	}

	private void OnDestroy()
	{
		RestoreHud();
	}
}
public class DefenseHighlight : MonoBehaviour
{
	private struct MatState
	{
		public Material mat;

		public bool hadEmission;

		public Color origColor;

		public bool hasColor;

		public Color origBaseColor;

		public bool hasBaseColor;

		public Color origEmission;

		public bool hasEmission;
	}

	private static readonly Color GlowColor = new Color(0.06f, 0.22f, 1f, 1f);

	private static readonly Color TintColor = new Color(0.28f, 0.48f, 1f, 1f);

	private readonly List<MatState> states = new List<MatState>();

	private Light auraLight;

	private bool isHighlighted;

	private float nextRefresh;

	public void SetActive(bool active)
	{
		if (active)
		{
			if (!isHighlighted || Time.time > nextRefresh)
			{
				nextRefresh = Time.time + 0.25f;
				Apply();
			}
			isHighlighted = true;
		}
		else if (isHighlighted)
		{
			Restore();
			isHighlighted = false;
		}
	}

	private void Apply()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_004d: 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_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: 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_0212: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)auraLight == (Object)null)
		{
			GameObject val = new GameObject("DefenseDroneAuraLight");
			val.transform.SetParent(((Component)this).transform, false);
			val.transform.localPosition = new Vector3(0f, 1f, 0f);
			auraLight = val.AddComponent<Light>();
			auraLight.type = (LightType)2;
			auraLight.color = GlowColor;
			auraLight.range = 4.5f;
			auraLight.intensity = 2.6f;
		}
		((Behaviour)auraLight).enabled = true;
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val2 in componentsInChildren)
		{
			if ((Object)(object)val2 == (Object)null || val2 is ParticleSystemRenderer || val2 is LineRenderer)
			{
				continue;
			}
			Material material = val2.material;
			if ((Object)(object)material == (Object)null)
			{
				continue;
			}
			bool flag = false;
			for (int j = 0; j < states.Count; j++)
			{
				if ((Object)(object)states[j].mat == (Object)(object)material)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				MatState item = new MatState
				{
					mat = material,
					hadEmission = material.IsKeywordEnabled("_EMISSION")
				};
				if (material.HasProperty("_Color"))
				{
					item.hasColor = true;
					item.origColor = material.GetColor("_Color");
				}
				if (material.HasProperty("_BaseColor"))
				{
					item.hasBaseColor = true;
					item.origBaseColor = material.GetColor("_BaseColor");
				}
				if (material.HasProperty("_EmissionColor"))
				{
					item.hasEmission = true;
					item.origEmission = material.GetColor("_EmissionColor");
				}
				states.Add(item);
			}
			material.EnableKeyword("_EMISSION");
			if (material.HasProperty("_EmissionColor"))
			{
				material.SetColor("_EmissionColor", GlowColor * 1.35f);
			}
			if (material.HasProperty("_Color"))
			{
				material.SetColor("_Color", TintColor);
			}
			if (material.HasProperty("_BaseColor"))
			{
				material.SetColor("_BaseColor", TintColor);
			}
		}
	}

	private void Restore()
	{
		//IL_006b: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)auraLight != (Object)null)
		{
			((Behaviour)auraLight).enabled = false;
		}
		for (int i = 0; i < states.Count; i++)
		{
			MatState matState = states[i];
			if (!((Object)(object)matState.mat == (Object)null))
			{
				if (matState.hasColor)
				{
					matState.mat.SetColor("_Color", matState.origColor);
				}
				if (matState.hasBaseColor)
				{
					matState.mat.SetColor("_BaseColor", matState.origBaseColor);
				}
				if (matState.hasEmission)
				{
					matState.mat.SetColor("_EmissionColor", matState.origEmission);
				}
				if (!matState.hadEmission)
				{
					matState.mat.DisableKeyword("_EMISSION");
				}
			}
		}
		states.Clear();
	}

	private void OnDisable()
	{
		if (isHighlighted)
		{
			Restore();
			isHighlighted = false;
		}
	}

	private void OnDestroy()
	{
		if (isHighlighted)
		{
			Restore();
			isHighlighted = false;
		}
	}
}
internal static class Registrar
{
	private const BindingFlags BF = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

	public static int Tries;

	public static string Prefer = "";

	public static float PriceMin = 40000f;

	public static float PriceMax = 75000f;

	public static float PriceScale = 0f;

	public static float ShopMultiplier = 0f;

	public static float HealPriceMin = 25000f;

	public static float HealPriceMax = 50000f;

	public static float DefPriceMin = 30000f;

	public static float DefPriceMax = 60000f;

	private static bool StunDone = true;

	private static bool HealDone;

	private static bool DefDone = true;

	private static string lastMsg;

	public static bool Done => StunDone && HealDone && DefDone;

	public static bool AnyDone => StunDone || HealDone || DefDone;

	private static void Say(ManualLogSource log, string m)
	{
		if (!(m == lastMsg))
		{
			lastMsg = m;
			log.LogInfo((object)("[Register] " + m));
		}
	}

	private static FieldInfo Fld(Type t, string name)
	{
		while (t != null)
		{
			FieldInfo field = t.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				return field;
			}
			t = t.BaseType;
		}
		return null;
	}

	private static string GetS(object o, string name)
	{
		FieldInfo fieldInfo = Fld(o.GetType(), name);
		return (fieldInfo != null) ? (fieldInfo.GetValue(o) as string) : null;
	}

	private static void SetS(object o, string name, string v)
	{
		FieldInfo fieldInfo = Fld(o.GetType(), name);
		if (fieldInfo != null && fieldInfo.FieldType == typeof(string))
		{
			fieldInfo.SetValue(o, v);
		}
	}

	internal static Type FindType(string full)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			try
			{
				Type type = assembly.GetType(full);
				if (type != null)
				{
					return type;
				}
			}
			catch
			{
			}
		}
		return null;
	}

	private static GameObject ExtractGO(object o)
	{
		if (o == null)
		{
			return null;
		}
		GameObject val = (GameObject)((o is GameObject) ? o : null);
		if ((Object)(object)val 

BepInEx/plugins/DefenseDrone.dll

Decompiled 38 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Photon.Pun;
using UnityEngine;
using UnityEngine.UI;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace DefenseDroneMod;

[BepInPlugin("user.defensedrone", "Defense Drone", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private float dumpTimer;

	private bool dumped = true;

	private float regTimer;

	private float adminTimer;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Defense Drone loaded. F8 = dump drone state");
		Registrar.Prefer = ((BaseUnityPlugin)this).Config.Bind<string>("General", "SourceDroneName", "Torque", "Часть имени ванильного дрона, который копируется (Zero Gravity, Feather, Indestructible, Battery, Torque...). Пусто = авто.").Value;
		Registrar.PriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceMin", 40000f, "Минимальная цена Stun Drone в магазине, $").Value;
		Registrar.PriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceMax", 75000f, "Максимальная цена Stun Drone в магазине, $").Value;
		StunDroneLogic.BarSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SecondsPerCharge", 10f, "Сколько секунд длится один заряд Stun Drone, пока он держит цель").Value;
		StunDroneLogic.StunCharges = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Charges", 6, "Сколько зарядов (полосок) у Stun Drone").Value;
		StunDroneLogic.ReleaseOnDetach = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ReleaseOnDetach", false, "false = цель остаётся в стане, пока дрон не выключен и есть заряд, даже если луч отцепился; true = стан снимается сразу при отцеплении луча").Value;
		StunDroneLogic.StrictBeam = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "StrictBeam", true, "true = цель считается прицепленной, только если конец луча дрона реально лежит на ней (защита от залипшей ссылки на старую цель)").Value;
		Registrar.PriceScale = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "PriceScale", 0f, "Множитель цены: 0 = авто (по ванильному предмету), 0.001 = значение в тысячах, 1 = цена как есть").Value;
		Registrar.ShopMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Shop", "ShopMultiplier", 0f, "Множитель магазина игры: 0 = авто (ShopManager.itemValueMultiplier, обычно 4). Цена делится на него, чтобы в магазине было PriceMin..PriceMax").Value;
		Registrar.HealPriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "PriceMin", 25000f, "Минимальная цена Heal Drone в магазине, $").Value;
		Registrar.HealPriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "PriceMax", 50000f, "Максимальная цена Heal Drone в магазине, $").Value;
		StunDroneLogic.HealAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Heal Drone", "HealAmount", 5, "Сколько HP лечит за один тик").Value;
		StunDroneLogic.HealInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Heal Drone", "HealInterval", 1f, "Пауза между тиками лечения, секунд").Value;
		StunDroneLogic.HealCharges = ((BaseUnityPlugin)this).Config.Bind<int>("Heal Drone", "Charges", 10, "Сколько зарядов (полосок) у Heal Drone. Один тик лечения (HealAmount HP) = 1 заряд").Value;
		Registrar.DefPriceMin = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "PriceMin", 30000f, "Минимальная цена Defense Drone в магазине, $").Value;
		Registrar.DefPriceMax = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "PriceMax", 60000f, "Максимальная цена Defense Drone в магазине, $").Value;
		StunDroneLogic.DefCharges = ((BaseUnityPlugin)this).Config.Bind<int>("Defense Drone", "Charges", 6, "Сколько зарядов (полосок) у Defense Drone").Value;
		StunDroneLogic.DefBarSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "SecondsPerCharge", 10f, "Сколько секунд длится 1 заряд Defense Drone").Value;
		StunDroneLogic.DefDamageScale = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "DamageMultiplier", 0.25f, "Множитель входящего урона под защитой (0.25 = -75% урона)").Value;
		DefenseHudOverlay.ShieldOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldOffsetX", 8f, "Смещение иконки щита по X от правого края HealthMax (в единицах HUD)").Value;
		DefenseHudOverlay.ShieldOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldOffsetY", 0f, "Смещение иконки щита по Y от центра HealthMax (в единицах HUD), + вверх").Value;
		DefenseHudOverlay.ShieldScale = ((BaseUnityPlugin)this).Config.Bind<float>("Defense Drone", "ShieldScale", 0.7f, "Масштаб иконки щита").Value;
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)289))
		{
			StunDroneLogic[] array = Object.FindObjectsByType<StunDroneLogic>((FindObjectsSortMode)0);
			foreach (StunDroneLogic stunDroneLogic in array)
			{
				stunDroneLogic.DumpState(((BaseUnityPlugin)this).Logger);
			}
		}
		if (!Registrar.Done && Registrar.Tries < 300)
		{
			regTimer += Time.deltaTime;
			if (regTimer > 2f)
			{
				regTimer = 0f;
				Registrar.TryRegister(((BaseUnityPlugin)this).Logger);
			}
		}
		if (Registrar.AnyDone)
		{
			adminTimer += Time.deltaTime;
			if (adminTimer > 2f)
			{
				adminTimer = 0f;
				AdminSync.Run(((BaseUnityPlugin)this).Logger);
			}
		}
		if (!dumped)
		{
			dumpTimer += Time.deltaTime;
			if (dumpTimer > 10f)
			{
				dumped = true;
				Dumper.Run(((BaseUnityPlugin)this).Logger);
			}
		}
	}

	private void SpawnDrone(string itemName)
	{
		//IL_0111: 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_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: 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_0150: 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)
		StatsManager instance = StatsManager.instance;
		if ((Object)(object)instance == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"StatsManager not ready");
			return;
		}
		Item val = null;
		foreach (Item value in instance.itemDictionary.Values)
		{
			if ((Object)(object)value != (Object)null && value.itemName == itemName)
			{
				val = value;
				break;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)(itemName + " is not registered yet (wait for the log line DONE)"));
			return;
		}
		Type type = Registrar.FindType("REPOLib.Modules.Items");
		if (type == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"REPOLib not found");
			return;
		}
		Camera main = Camera.main;
		Vector3 val2 = (((Object)(object)main != (Object)null) ? (((Component)main).transform.position + ((Component)main).transform.forward * 2f) : Vector3.up);
		object obj = type.GetMethod("SpawnItem").Invoke(null, new object[3]
		{
			val,
			val2,
			Quaternion.identity
		});
		if (obj == null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"SpawnItem returned null (are you the host? see REPOLib lines in the log)");
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)(itemName + " spawned"));
		}
	}
}
public class StunDroneLogic : MonoBehaviour
{
	public enum Mode
	{
		Player,
		Monster
	}

	private enum Part
	{
		Skip,
		Main,
		Other
	}

	private const float Range = 6f;

	private const float MonsterStunSeconds = 1.5f;

	private const float NormalGravity = 30f;

	private const float PlayerStunSeconds = 3f;

	private const float AutoCooldown = 6f;

	private const BindingFlags RB = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

	public Mode mode;

	public static int StunCharges = 6;

	public static int HealCharges = 10;

	public static int DefCharges = 6;

	public static float DefBarSeconds = 10f;

	public static float DefDamageScale = 0.25f;

	public int charge = 1;

	private object target;

	private float stickUntil;

	private ItemAttributes[] attrs;

	private float gravTimer;

	private bool gravLogged;

	private static readonly Color OrangeC = new Color(1f, 0.5f, 0.05f, 1f);

	private static readonly Color GreenC = new Color(0.15f, 1f, 0.3f, 1f);

	private static readonly Color DarkBlueC = new Color(0.08f, 0.28f, 1f, 1f);

	private bool batLogged;

	private bool torqueLogged;

	private bool scriptsDone;

	private Texture2D iconTex;

	private bool iconPending;

	private int bornFrame;

	private bool iconLogged;

	private static bool logged;

	private float nextAuto;

	private float reapplyTimer;

	private bool targetingDone;

	private ItemDrone droneComp;

	private bool wasAttached;

	private bool loggedScan;

	private float nextDiag;

	private float holdTimer;

	private object attachedObj;

	public static bool StrictBeam = true;

	public static bool ReleaseOnDetach = false;

	public static float BarSeconds = 3f;

	private float drainTimer;

	private object stunned;

	private float attachStart;

	private bool capped;

	private object relTarget;

	private float relUntil;

	private float relNext;

	private static bool stunLogged;

	private float nextBeamLog;

	private HashSet<Renderer> batRend = new HashSet<Renderer>();

	private List<Renderer> beamList = new List<Renderer>();

	private Dictionary<Renderer, int[]> beamProps = new Dictionary<Renderer, int[]>();

	private float nextBeamFind;

	private bool fieldColorLogged;

	private Component batteryComp;

	private float nextBatFind;

	private bool batteryLogged;

	private bool uiDumped;

	private float lifeVal = -1f;

	private int lastCharge;

	private float nextBatDump;

	private int dumpedCharge = -1;

	public static int HealAmount = 5;

	public static float HealInterval = 1f;

	private float nextHeal;

	private bool healWarned;

	private Component tumbleCache;

	private PlayerAvatar cachedFor;

	private bool tumbleWarned;

	private bool stunWarned;

	private bool stunWarned2;

	private bool stunOk;

	private static HashSet<string> noStunLogged = new HashSet<string>();

	private int lastDefHp = -1;

	private PlayerAvatar lastDefPlayer;

	private int Cap => Math.Max(1, Defense ? DefCharges : (Heal ? HealCharges : StunCharges));

	private string DisplayName => Defense ? "Defense Drone" : (Heal ? "Heal Drone" : "Stun Drone");

	private bool Heal => this is HealDroneLogic;

	private bool Defense => this is DefenseDroneLogic;

	private Color Orange => Defense ? DarkBlueC : (Heal ? GreenC : OrangeC);

	private void Awake()
	{
		charge = Cap;
		CollectBatteryRenderers();
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val != (Object)null && ((object)val).GetType().Name == "ItemBattery")
			{
				SetNum(val, "batteryBars", Cap);
			}
		}
		mode = ((!Heal && !Defense && !(Random.value < 0.5f)) ? Mode.Monster : Mode.Player);
		Retexture();
		ApplyIcon();
		bornFrame = Time.frameCount;
		ApplyTargeting();
		attrs = ((Component)this).GetComponentsInChildren<ItemAttributes>(true);
		ForceName();
		Debug.Log((object)string.Concat("[StunDrone] spawned, mode=", mode, ", name=", DumpName()));
	}

	private void ForceName()
	{
		if (attrs == null)
		{
			return;
		}
		ItemAttributes[] array = attrs;
		foreach (ItemAttributes val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				SetStr(val, "itemName", DisplayName);
				SetStr(val, "instanceName", DisplayName);
				SetStr(val, "cachedItemName", DisplayName);
			}
		}
	}

	private string DumpName()
	{
		if (attrs == null || attrs.Length == 0)
		{
			return "<no ItemAttributes>";
		}
		ItemAttributes o = attrs[0];
		return GetStr(o, "itemName") + " / " + GetStr(o, "cachedItemName");
	}

	private static void SetStr(object o, string name, string v)
	{
		FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null && field.FieldType == typeof(string))
		{
			field.SetValue(o, v);
		}
	}

	private static string GetStr(object o, string name)
	{
		FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		return (field != null) ? (field.GetValue(o) as string) : "?";
	}

	private void ApplyGravity()
	{
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				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)) && !(fieldInfo.Name.ToLower() != "customgravity"))
					{
						float num = (float)fieldInfo.GetValue(val);
						if (!gravLogged)
						{
							Debug.Log((object)("[StunDrone] " + type.Name + "." + fieldInfo.Name + ": " + num + " -> " + 30f));
						}
						if (num != 30f)
						{
							fieldInfo.SetValue(val, 30f);
						}
					}
				}
				type = type.BaseType;
			}
		}
		gravLogged = true;
	}

	private void ApplyColors()
	{
		//IL_00af: 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_00e6: 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_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			if (!(val is ParticleSystemRenderer) && Classify(((Component)val).transform) == Part.Other && !IsBatteryRenderer(val))
			{
				Material material = val.material;
				if (material.HasProperty("_EmissionColor"))
				{
					material.SetColor("_EmissionColor", Orange);
				}
			}
		}
		Light[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Light>(true);
		foreach (Light val2 in componentsInChildren2)
		{
			val2.color = Orange;
		}
		LineRenderer[] componentsInChildren3 = ((Component)this).GetComponentsInChildren<LineRenderer>(true);
		foreach (LineRenderer val3 in componentsInChildren3)
		{
			val3.startColor = Orange;
			val3.endColor = Orange;
		}
		ParticleSystem[] componentsInChildren4 = ((Component)this).GetComponentsInChildren<ParticleSystem>(true);
		foreach (ParticleSystem val4 in componentsInChildren4)
		{
			MainModule main = val4.main;
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Orange);
		}
	}

	private void ApplyBatteryColor()
	{
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] battery members: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null || ((object)val).GetType().Name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) < 0)
			{
				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 (!batLogged)
					{
						object value = null;
						try
						{
							value = fieldInfo.GetValue(val);
						}
						catch
						{
						}
						stringBuilder.Append(type.Name).Append('.').Append(fieldInfo.Name)
							.Append('=')
							.Append(value)
							.Append("; ");
					}
					if (fieldInfo.FieldType == typeof(Color) && (fieldInfo.Name.Equals("batteryColor", StringComparison.OrdinalIgnoreCase) || fieldInfo.Name.Equals("batteryColorMain", StringComparison.OrdinalIgnoreCase) || fieldInfo.Name.Equals("batteryColorMedium", StringComparison.OrdinalIgnoreCase)))
					{
						fieldInfo.SetValue(val, Orange);
					}
				}
				type = type.BaseType;
			}
		}
		if (!batLogged)
		{
			batLogged = true;
			Debug.Log((object)stringBuilder.ToString());
		}
	}

	private void RemoveTorque()
	{
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] torque members: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				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)
				{
					string text = fieldInfo.Name.ToLower();
					if (text.Contains("torque") || text.Contains("spin"))
					{
						object value = null;
						try
						{
							value = fieldInfo.GetValue(val);
						}
						catch
						{
						}
						if (!torqueLogged)
						{
							stringBuilder.Append(type.Name).Append('.').Append(fieldInfo.Name)
								.Append('=')
								.Append(value)
								.Append("; ");
						}
						if (fieldInfo.FieldType == typeof(float))
						{
							fieldInfo.SetValue(val, 0f);
						}
						else if (fieldInfo.FieldType == typeof(bool))
						{
							fieldInfo.SetValue(val, false);
						}
						else if (fieldInfo.FieldType == typeof(Vector3))
						{
							fieldInfo.SetValue(val, Vector3.zero);
						}
					}
				}
				type = type.BaseType;
			}
		}
		if (!torqueLogged)
		{
			torqueLogged = true;
			Debug.Log((object)stringBuilder.ToString());
		}
	}

	private void RemoveTorqueScripts()
	{
		if (scriptsDone)
		{
			return;
		}
		scriptsDone = true;
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] scripts on drone: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			string name = ((object)val).GetType().Name;
			stringBuilder.Append(((Object)((Component)val).gameObject).name).Append(':').Append(name)
				.Append("; ");
			if (!((Object)(object)val == (Object)(object)this) && !(name == "ItemDrone"))
			{
				string text = name.ToLower();
				if (text.Contains("torque") || text.Contains("spin"))
				{
					Debug.Log((object)("[StunDrone] removing script " + name + " on " + ((Object)((Component)val).gameObject).name));
					Object.Destroy((Object)(object)val);
				}
			}
		}
		Debug.Log((object)stringBuilder.ToString());
	}

	private void LateUpdate()
	{
		ForceName();
		SyncBattery();
		TintBeams();
		if (Time.frameCount > bornFrame + 5)
		{
			RemoveTorqueScripts();
		}
		if (Time.time > gravTimer)
		{
			gravTimer = Time.time + 0.5f;
			ApplyGravity();
			ApplyColors();
			ApplyBatteryColor();
			ApplyDroneFieldColors();
			RemoveTorque();
			if ((Object)(object)iconTex != (Object)null && Time.frameCount > bornFrame + 3)
			{
				ApplyIconMaterial();
			}
		}
	}

	private void ApplyTargeting()
	{
		ItemDrone componentInChildren = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		if (!((Object)(object)componentInChildren == (Object)null))
		{
			SetBool(componentInChildren, "targetValuables", v: false);
			SetBool(componentInChildren, "targetNonValuables", v: false);
			SetBool(componentInChildren, "targetPlayers", v: true);
			SetBool(componentInChildren, "targetEnemies", !Heal && !Defense);
		}
	}

	private static void SetBool(object o, string name, bool v)
	{
		FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null && field.FieldType == typeof(bool))
		{
			field.SetValue(o, v);
		}
		else
		{
			Debug.LogWarning((object)("[StunDrone] field " + name + " not found"));
		}
	}

	private void ApplyIcon()
	{
		iconTex = LoadEmbedded(Defense ? "def_icon.png" : (Heal ? "heal_icon.png" : "icon.png"));
		Debug.Log((object)("[StunDrone] icon.png embedded in DLL: " + ((Object)(object)iconTex != (Object)null) + (((Object)(object)iconTex == (Object)null) ? "  (put tex\\3.png next to build.bat and rebuild)" : "")));
		if ((Object)(object)iconTex == (Object)null)
		{
			return;
		}
		ItemDrone componentInChildren = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		if ((Object)(object)componentInChildren != (Object)null)
		{
			FieldInfo field = typeof(ItemDrone).GetField("droneIcon", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(componentInChildren, iconTex);
			}
			else
			{
				Debug.LogWarning((object)"[StunDrone] field droneIcon not found");
			}
		}
		else
		{
			Debug.LogWarning((object)"[StunDrone] ItemDrone not found on prefab");
		}
		iconPending = true;
		bornFrame = Time.frameCount;
	}

	private void ApplyIconMaterial()
	{
		//IL_0107: 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_0155: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			bool flag = false;
			Transform val2 = ((Component)val).transform;
			while ((Object)(object)val2 != (Object)null)
			{
				if (((Object)val2).name.Replace('_', ' ').Trim().StartsWith("Drone Icon"))
				{
					flag = true;
					break;
				}
				val2 = val2.parent;
			}
			if (flag)
			{
				Material material = val.material;
				material.EnableKeyword("_EMISSION");
				material.SetTexture("_EmissionMap", (Texture)(object)iconTex);
				if (material.HasProperty("_MainTex"))
				{
					material.SetTexture("_MainTex", (Texture)(object)iconTex);
				}
				if (material.HasProperty("_BaseMap"))
				{
					material.SetTexture("_BaseMap", (Texture)(object)iconTex);
				}
				if (material.HasProperty("_EmissionColor"))
				{
					material.SetColor("_EmissionColor", Color.white);
				}
				if (material.HasProperty("_Color"))
				{
					material.SetColor("_Color", Color.white);
				}
				if (material.HasProperty("_BaseColor"))
				{
					material.SetColor("_BaseColor", Color.white);
				}
				num++;
			}
		}
		if (!iconLogged)
		{
			iconLogged = true;
			Debug.Log((object)("[StunDrone] icon applied to " + num + " renderer(s) named 'Drone Icon'"));
		}
	}

	private void Retexture()
	{
		//IL_00ac: 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_007e: 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_0258: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = (Defense ? LoadEmbedded("def_albedo.png") : (Heal ? LoadEmbedded("heal_albedo.png") : null)) ?? LoadEmbedded("albedo.png") ?? Procedural(Defense ? new Color(0.08f, 0.25f, 0.95f) : (Heal ? new Color(0.2f, 0.8f, 0.3f) : ((mode == Mode.Player) ? new Color(0.9f, 0.55f, 0.1f) : new Color(0.1f, 0.6f, 0.8f))));
		Texture2D val2 = (Defense ? LoadEmbedded("def_emission.png") : (Heal ? LoadEmbedded("heal_emission.png") : null)) ?? LoadEmbedded("emission.png");
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val3 in componentsInChildren)
		{
			if (IsBatteryRenderer(val3))
			{
				continue;
			}
			Part part = Classify(((Component)val3).transform);
			if (!logged)
			{
				Debug.Log((object)("[StunDrone] renderer '" + ((Object)val3).name + "' -> " + part));
			}
			if (part == Part.Skip)
			{
				continue;
			}
			Material material = val3.material;
			if (material.HasProperty("_MainTex"))
			{
				material.SetTexture("_MainTex", (Texture)(object)val);
			}
			if (material.HasProperty("_BaseMap"))
			{
				material.SetTexture("_BaseMap", (Texture)(object)val);
			}
			if (part == Part.Main)
			{
				if (material.HasProperty("_EmissionMap"))
				{
					material.SetTexture("_EmissionMap", (Texture)null);
				}
				material.DisableKeyword("_EMISSION");
			}
			else if ((Object)(object)val2 != (Object)null && material.HasProperty("_EmissionMap"))
			{
				material.EnableKeyword("_EMISSION");
				material.SetTexture("_EmissionMap", (Texture)(object)val2);
				material.SetColor("_EmissionColor", Color.white);
			}
		}
		logged = true;
	}

	private static Part Classify(Transform t)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			string text = ((Object)val).name.Replace('_', ' ').Trim();
			if (text.StartsWith("Drone Icon"))
			{
				return Part.Skip;
			}
			if (text.Contains("Drone Triangle") || text.Contains("Drone Pyramid"))
			{
				return Part.Other;
			}
			if (text == "Drone")
			{
				return Part.Main;
			}
			val = val.parent;
		}
		return Part.Skip;
	}

	private static Texture2D LoadEmbedded(string name)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
		if (stream == null)
		{
			return null;
		}
		MemoryStream memoryStream = new MemoryStream();
		stream.CopyTo(memoryStream);
		Texture2D val = new Texture2D(2, 2);
		ImageConversion.LoadImage(val, memoryStream.ToArray());
		return val;
	}

	private static Texture2D Procedural(Color c)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_002e: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(64, 64);
		for (int i = 0; i < 64; i++)
		{
			for (int j = 0; j < 64; j++)
			{
				val.SetPixel(j, i, ((j / 8 + i / 8) % 2 == 0) ? c : (c * 0.6f));
			}
		}
		val.Apply();
		return val;
	}

	private void Update()
	{
		if (!targetingDone && Time.frameCount > bornFrame + 2)
		{
			targetingDone = true;
			ApplyTargeting();
		}
		if (iconPending && Time.frameCount >= bornFrame + 3)
		{
			iconPending = false;
			ApplyIconMaterial();
		}
		KeepReleasing();
		if ((Object)(object)droneComp == (Object)null)
		{
			droneComp = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		}
		object obj = ((charge > 0) ? DetectAttached() : null);
		if (stunned != null && !ReleaseOnDetach && !Heal && !Defense)
		{
			object obj2 = stunned;
			Component val = (Component)((obj2 is Component) ? obj2 : null);
			obj = (((Object)(object)val != (Object)null && (Object)(object)val.gameObject != (Object)null && charge > 0 && ToggleOn()) ? stunned : null);
		}
		if (capped && obj == null)
		{
			capped = false;
		}
		if (capped)
		{
			obj = null;
		}
		if (stunned != null && !object.ReferenceEquals(stunned, obj))
		{
			Release(stunned);
			stunned = null;
		}
		if (obj != null && stunned == null)
		{
			if (object.ReferenceEquals(relTarget, obj))
			{
				relTarget = null;
			}
			stunned = obj;
			attachStart = Time.time;
			holdTimer = 0f;
			drainTimer = 0f;
			Debug.Log((object)string.Concat("[StunDrone] attached to ", obj, ", charge=", charge));
		}
		attachedObj = stunned;
		if (stunned == null)
		{
			return;
		}
		float num = (Defense ? DefBarSeconds : BarSeconds);
		if (!Heal)
		{
			drainTimer += Time.deltaTime;
		}
		if (!Heal && drainTimer >= num)
		{
			drainTimer = 0f;
			charge--;
			Debug.Log((object)("[StunDrone] charge=" + charge));
			if (charge <= 0)
			{
				Debug.Log((object)("[StunDrone] charge empty, releasing " + stunned));
				Release(stunned);
				stunned = null;
				attachedObj = null;
				return;
			}
		}
		if (Heal)
		{
			HealTick();
			return;
		}
		if (Defense)
		{
			object obj3 = stunned;
			PlayerAvatar val2 = (PlayerAvatar)((obj3 is PlayerAvatar) ? obj3 : null);
			if ((Object)(object)val2 != (Object)null)
			{
				DefenseTick(val2);
			}
			return;
		}
		object obj4 = stunned;
		PlayerAvatar val3 = (PlayerAvatar)((obj4 is PlayerAvatar) ? obj4 : null);
		if ((Object)(object)val3 != (Object)null)
		{
			StunPlayer(val3);
			return;
		}
		holdTimer -= Time.deltaTime;
		if (!(holdTimer > 0f))
		{
			holdTimer = 0.2f;
			object obj5 = stunned;
			Enemy val4 = (Enemy)((obj5 is Enemy) ? obj5 : null);
			if ((Object)(object)val4 != (Object)null)
			{
				StunEnemy(val4);
			}
		}
	}

	public void DumpState(ManualLogSource log)
	{
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine(string.Concat("==== ", DateTime.Now.ToString("HH:mm:ss"), "  mode=", mode, " charge=", charge, " stunned=", stunned, " toggleOn=", ToggleOn()));
		if ((Object)(object)droneComp == (Object)null)
		{
			droneComp = ((Component)this).GetComponentInChildren<ItemDrone>(true);
		}
		if ((Object)(object)droneComp != (Object)null)
		{
			Type type = ((object)droneComp).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object obj = null;
					try
					{
						obj = fieldInfo.GetValue(droneComp);
					}
					catch
					{
					}
					stringBuilder.AppendLine("  ItemDrone." + fieldInfo.Name + " (" + fieldInfo.FieldType.Name + ") = " + ((obj == null) ? "null" : obj.ToString()));
				}
				type = type.BaseType;
			}
		}
		LineRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<LineRenderer>(true);
		foreach (LineRenderer val in componentsInChildren)
		{
			stringBuilder.AppendLine("  LineRenderer " + ((Object)val).name + " enabled=" + ((Renderer)val).enabled + " active=" + ((Component)val).gameObject.activeInHierarchy + " points=" + val.positionCount + ((val.positionCount >= 2) ? string.Concat(" p0=", val.GetPosition(0), " pN=", val.GetPosition(val.positionCount - 1), " worldSpace=", val.useWorldSpace) : ""));
		}
		MonoBehaviour[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val2 in componentsInChildren2)
		{
			if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)this || (Object)(object)val2 == (Object)(object)droneComp)
			{
				continue;
			}
			string name = ((object)val2).GetType().Name;
			if (name.IndexOf("Line", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Magnet", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Drone", StringComparison.OrdinalIgnoreCase) < 0)
			{
				continue;
			}
			Type type = ((object)val2).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object obj = null;
					try
					{
						obj = fieldInfo.GetValue(val2);
					}
					catch
					{
					}
					stringBuilder.AppendLine("  " + name + "." + fieldInfo.Name + " (" + fieldInfo.FieldType.Name + ") = " + ((obj == null) ? "null" : obj.ToString()));
				}
				type = type.BaseType;
			}
		}
		try
		{
			string text = Path.Combine(Paths.BepInExRootPath, "StunDrone_state.txt");
			File.AppendAllText(text, stringBuilder.ToString());
			log.LogInfo((object)("State dumped: " + text));
		}
		catch (Exception ex)
		{
			log.LogError((object)("State dump failed: " + ex.Message));
		}
	}

	private void KeepReleasing()
	{
		if (relTarget == null)
		{
			return;
		}
		if (Time.time > relUntil)
		{
			relTarget = null;
		}
		else
		{
			if (Time.time < relNext)
			{
				return;
			}
			relNext = Time.time + 0.2f;
			object obj = relTarget;
			PlayerAvatar val = (PlayerAvatar)((obj is PlayerAvatar) ? obj : null);
			if (!((Object)(object)val == (Object)null))
			{
				Component val2 = FindTumble(val);
				if ((Object)(object)val2 != (Object)null)
				{
					CallMethod(val2, "TumbleOverrideTime", 0f);
					CallMethod(val2, "TumbleRequest", false, false);
				}
			}
		}
	}

	private void OnDisable()
	{
		if (stunned != null)
		{
			Release(stunned);
			stunned = null;
		}
	}

	private void OnDestroy()
	{
		if (stunned != null)
		{
			Release(stunned);
			stunned = null;
		}
	}

	private void Release(object target)
	{
		if (Heal)
		{
			return;
		}
		if (Defense)
		{
			ClearDefense(target);
			return;
		}
		relTarget = target;
		relUntil = Time.time + 1.2f;
		relNext = Time.time + 0.2f;
		try
		{
			PlayerAvatar val = (PlayerAvatar)((target is PlayerAvatar) ? target : null);
			if ((Object)(object)val != (Object)null)
			{
				Component val2 = FindTumble(val);
				if ((Object)(object)val2 != (Object)null)
				{
					CallMethod(val2, "TumbleOverrideTime", 0f);
					CallMethod(val2, "TumbleRequest", false, false);
				}
				Debug.Log((object)"[StunDrone] released player");
			}
			Enemy val3 = (Enemy)((target is Enemy) ? target : null);
			if (!((Object)(object)val3 != (Object)null))
			{
				return;
			}
			Component val4 = FindStun((Component)(object)val3);
			if ((Object)(object)val4 != (Object)null)
			{
				Type type = ((object)val4).GetType();
				while (type != null && type != typeof(MonoBehaviour))
				{
					FieldInfo field = type.GetField("stunTimer", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.FieldType == typeof(float))
					{
						field.SetValue(val4, 0.05f);
					}
					type = type.BaseType;
				}
			}
			MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)val3)).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val5 in componentsInChildren)
			{
				if ((Object)(object)val5 == (Object)null)
				{
					continue;
				}
				Type type = ((object)val5).GetType();
				while (type != null && type != typeof(MonoBehaviour))
				{
					FieldInfo field = type.GetField("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.FieldType == typeof(bool))
					{
						field.SetValue(val5, false);
					}
					PropertyInfo property = type.GetProperty("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null && property.PropertyType == typeof(bool) && property.CanWrite)
					{
						try
						{
							property.SetValue(val5, false, null);
						}
						catch
						{
						}
					}
					type = type.BaseType;
				}
			}
			Debug.Log((object)"[StunDrone] released enemy");
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[StunDrone] Release: " + ex.Message));
		}
	}

	private object DetectAttached()
	{
		object obj = null;
		if (!ToggleOn())
		{
			return null;
		}
		object obj2 = stunned;
		PlayerAvatar val = (PlayerAvatar)((obj2 is PlayerAvatar) ? obj2 : null);
		if ((Object)(object)val != (Object)null && IsHolder(val))
		{
			return val;
		}
		if ((Object)(object)droneComp != (Object)null)
		{
			Type type = ((object)droneComp).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object value;
					try
					{
						value = fieldInfo.GetValue(droneComp);
					}
					catch
					{
						continue;
					}
					Object val2 = (Object)((value is Object) ? value : null);
					IList list = value as IList;
					if (val2 == (Object)null && list != null)
					{
						foreach (object item in list)
						{
							val2 = (Object)((item is Object) ? item : null);
							if (val2 != (Object)null)
							{
								break;
							}
						}
					}
					if (val2 == (Object)null || val2 == (Object)(object)droneComp || val2 == (Object)(object)((Component)this).gameObject)
					{
						continue;
					}
					Component val3 = (Component)(object)((val2 is Component) ? val2 : null);
					GameObject val4 = (GameObject)(object)((val2 is GameObject) ? val2 : null);
					if ((Object)(object)val3 == (Object)null && (Object)(object)val4 != (Object)null)
					{
						val3 = (Component)(object)val4.transform;
					}
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					PlayerAvatar componentInParent = val3.GetComponentInParent<PlayerAvatar>();
					if ((Object)(object)componentInParent == (Object)null)
					{
						Component componentInParent2 = val3.GetComponentInParent(Registrar.FindType("PlayerTumble") ?? typeof(Transform));
						if ((Object)(object)componentInParent2 != (Object)null)
						{
							componentInParent = componentInParent2.GetComponentInParent<PlayerAvatar>();
						}
					}
					if ((Object)(object)componentInParent != (Object)null && !IsHolder(componentInParent))
					{
						obj = componentInParent;
						if (!loggedScan)
						{
							loggedScan = true;
							Debug.Log((object)("[StunDrone] target field (player): ItemDrone." + fieldInfo.Name));
						}
						break;
					}
					Enemy val5 = ((Heal || Defense) ? null : EnemyFrom(val3));
					if (!((Object)(object)val5 != (Object)null))
					{
						continue;
					}
					obj = val5;
					if (!loggedScan)
					{
						loggedScan = true;
						Debug.Log((object)("[StunDrone] target field (enemy): ItemDrone." + fieldInfo.Name));
					}
					break;
				}
				if (obj != null)
				{
					break;
				}
				type = type.BaseType;
			}
		}
		if (obj != null && StrictBeam && !BeamOnTarget(obj))
		{
			if (Time.time > nextBeamLog)
			{
				nextBeamLog = Time.time + 2f;
				Debug.Log((object)string.Concat("[StunDrone] ItemDrone still references ", obj, " but the beam is not on it -> not attached"));
			}
			obj = null;
		}
		if (obj != null)
		{
			return obj;
		}
		if ((Object)(object)droneComp != (Object)null && Time.time > nextDiag && LineOn() && ToggleOn())
		{
			nextDiag = Time.time + 3f;
			StringBuilder stringBuilder = new StringBuilder("[StunDrone] no target found; ItemDrone fields: ");
			Type type = ((object)droneComp).GetType();
			while (type != null && type != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					object value = null;
					try
					{
						value = fieldInfo.GetValue(droneComp);
					}
					catch
					{
					}
					stringBuilder.Append(fieldInfo.Name).Append('=').Append((value == null) ? "null" : value.ToString())
						.Append("; ");
				}
				type = type.BaseType;
			}
			Debug.Log((object)stringBuilder.ToString());
		}
		return null;
	}

	private bool ToggleOn()
	{
		Type type = Registrar.FindType("ItemToggle");
		if (type == null)
		{
			return true;
		}
		Component val = ((Component)this).GetComponentInChildren(type, true);
		if ((Object)(object)val == (Object)null)
		{
			val = ((Component)this).GetComponentInParent(type);
		}
		if ((Object)(object)val == (Object)null)
		{
			return true;
		}
		Type type2 = ((object)val).GetType();
		while (type2 != null)
		{
			FieldInfo field = type2.GetField("toggleState", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(bool))
			{
				return (bool)field.GetValue(val);
			}
			type2 = type2.BaseType;
		}
		return true;
	}

	private bool IsHolder(PlayerAvatar p)
	{
		try
		{
			Type type = Registrar.FindType("PhysGrabObject");
			if (type == null)
			{
				return false;
			}
			Component val = ((Component)this).GetComponentInParent(type);
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)this).GetComponentInChildren(type, true);
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			FieldInfo field = ((object)val).GetType().GetField("playerGrabbing", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			IList list = ((field != null) ? (field.GetValue(val) as IList) : null);
			if (list == null)
			{
				return false;
			}
			foreach (object item in list)
			{
				if (item == null)
				{
					continue;
				}
				Component val2 = (Component)((item is Component) ? item : null);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				PlayerAvatar val3 = val2.GetComponentInParent<PlayerAvatar>();
				if ((Object)(object)val3 == (Object)null)
				{
					FieldInfo field2 = item.GetType().GetField("playerAvatar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field2 != null)
					{
						object? value = field2.GetValue(item);
						val3 = (PlayerAvatar)((value is PlayerAvatar) ? value : null);
					}
				}
				if (!((Object)(object)val3 == (Object)(object)p))
				{
					continue;
				}
				return true;
			}
		}
		catch
		{
		}
		return false;
	}

	private static Transform EnemyRoot(Component e)
	{
		Type type = Registrar.FindType("EnemyParent");
		if (type != null)
		{
			Component componentInParent = e.GetComponentInParent(type);
			if ((Object)(object)componentInParent != (Object)null)
			{
				return componentInParent.transform;
			}
		}
		Transform val = null;
		Transform val2 = e.transform;
		while ((Object)(object)val2 != (Object)null)
		{
			if (((Object)val2).name.StartsWith("Enemy"))
			{
				val = val2;
			}
			val2 = val2.parent;
		}
		return ((Object)(object)val != (Object)null) ? val : e.transform.root;
	}

	private static Transform TargetRoot(Component c)
	{
		return (c is Enemy) ? EnemyRoot(c) : c.transform.root;
	}

	private static Component FindStun(Component e)
	{
		Component val = null;
		StringBuilder stringBuilder = (stunLogged ? null : new StringBuilder("[StunDrone] enemy state components: "));
		MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot(e)).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val2 in componentsInChildren)
		{
			if (!((Object)(object)val2 == (Object)null))
			{
				string name = ((object)val2).GetType().Name;
				if (stringBuilder != null && name.StartsWith("EnemyState"))
				{
					stringBuilder.Append(name).Append("; ");
				}
				if ((Object)(object)val == (Object)null && name.StartsWith("EnemyState") && name.ToLower().Contains("stun"))
				{
					val = (Component)(object)val2;
				}
			}
		}
		if (stringBuilder != null)
		{
			stunLogged = true;
			Debug.Log((object)(stringBuilder.ToString() + " -> stun: " + (((Object)(object)val != (Object)null) ? ((object)val).GetType().Name : "NOT FOUND")));
		}
		return val;
	}

	private static Enemy EnemyFrom(Component c)
	{
		Enemy componentInParent = c.GetComponentInParent<Enemy>();
		if ((Object)(object)componentInParent != (Object)null)
		{
			return componentInParent;
		}
		Type type = Registrar.FindType("EnemyParent");
		if (type != null)
		{
			Component componentInParent2 = c.GetComponentInParent(type);
			if ((Object)(object)componentInParent2 != (Object)null)
			{
				componentInParent = componentInParent2.GetComponentInChildren<Enemy>(true);
				if ((Object)(object)componentInParent != (Object)null)
				{
					return componentInParent;
				}
			}
		}
		Transform val = c.transform;
		while ((Object)(object)val != (Object)null)
		{
			MonoBehaviour[] components = ((Component)val).GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val2 in components)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Type type2 = ((object)val2).GetType();
				while (type2 != null && type2 != typeof(MonoBehaviour))
				{
					FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo in fields)
					{
						if (fieldInfo.FieldType == typeof(Enemy))
						{
							object? value = fieldInfo.GetValue(val2);
							Enemy val3 = (Enemy)((value is Enemy) ? value : null);
							if ((Object)(object)val3 != (Object)null)
							{
								return val3;
							}
						}
					}
					type2 = type2.BaseType;
				}
			}
			val = val.parent;
		}
		return null;
	}

	private bool BeamOnTarget(object target)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_009b: 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_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_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_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: 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_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		Component val = (Component)((target is Component) ? target : null);
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		bool flag = false;
		Bounds bounds = default(Bounds);
		((Bounds)(ref bounds))..ctor(val.transform.position, Vector3.one * 0.5f);
		bool flag2 = true;
		Renderer[] componentsInChildren = ((Component)TargetRoot(val)).GetComponentsInChildren<Renderer>(false);
		foreach (Renderer val2 in componentsInChildren)
		{
			if (!((Object)(object)val2 == (Object)null) && !(val2 is ParticleSystemRenderer) && !(val2 is LineRenderer))
			{
				if (flag2)
				{
					bounds = val2.bounds;
					flag2 = false;
				}
				else
				{
					((Bounds)(ref bounds)).Encapsulate(val2.bounds);
				}
			}
		}
		LineRenderer[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<LineRenderer>(false);
		foreach (LineRenderer val3 in componentsInChildren2)
		{
			if (!((Object)(object)val3 == (Object)null) && ((Renderer)val3).enabled && ((Component)val3).gameObject.activeInHierarchy && val3.positionCount >= 2)
			{
				flag = true;
				Vector3 val4 = val3.GetPosition(0);
				Vector3 val5 = val3.GetPosition(val3.positionCount - 1);
				if (!val3.useWorldSpace)
				{
					val4 = ((Component)val3).transform.TransformPoint(val4);
					val5 = ((Component)val3).transform.TransformPoint(val5);
				}
				if (!(Vector3.Distance(val4, val5) < 0.3f) && (((Bounds)(ref bounds)).SqrDistance(val4) < 4f || ((Bounds)(ref bounds)).SqrDistance(val5) < 4f))
				{
					return true;
				}
			}
		}
		if (!flag && Time.time > nextBeamLog)
		{
			nextBeamLog = Time.time + 2f;
			Debug.Log((object)"[StunDrone] no active LineRenderer on drone");
		}
		return false;
	}

	private bool LineOn()
	{
		Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(false);
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name == "Line" && ((Component)val).gameObject.activeInHierarchy)
			{
				return true;
			}
		}
		return false;
	}

	private static bool BoolMember(object o, string name)
	{
		Type type = o.GetType();
		while (type != null)
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(bool))
			{
				return (bool)field.GetValue(o);
			}
			PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.PropertyType == typeof(bool) && property.CanRead && property.GetIndexParameters().Length == 0)
			{
				try
				{
					return (bool)property.GetValue(o, null);
				}
				catch
				{
					return false;
				}
			}
			type = type.BaseType;
		}
		return false;
	}

	private static Component FindComp(Component c, string typeName)
	{
		Type type = Registrar.FindType(typeName);
		if (type == null)
		{
			return null;
		}
		Component val = c.GetComponentInChildren(type, true);
		if ((Object)(object)val == (Object)null)
		{
			val = c.GetComponentInParent(type);
		}
		if ((Object)(object)val == (Object)null)
		{
			val = ((Component)c.transform.root).GetComponentInChildren(type, true);
		}
		return val;
	}

	private static bool CallMethod(object o, string name, params object[] args)
	{
		Type type = o.GetType();
		while (type != null)
		{
			MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name != name)
				{
					continue;
				}
				ParameterInfo[] parameters = methodInfo.GetParameters();
				if (parameters.Length >= args.Length)
				{
					object[] array = new object[parameters.Length];
					for (int j = 0; j < parameters.Length; j++)
					{
						array[j] = ((j < args.Length) ? args[j] : (parameters[j].IsOptional ? parameters[j].DefaultValue : null));
					}
					try
					{
						methodInfo.Invoke(o, array);
						return true;
					}
					catch (Exception ex)
					{
						Debug.LogWarning((object)("[StunDrone] " + name + " threw: " + ((ex.InnerException != null) ? ex.InnerException.Message : ex.Message)));
					}
				}
			}
			type = type.BaseType;
		}
		return false;
	}

	private static Component FindTumble(PlayerAvatar p)
	{
		Type type = ((object)p).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.Name == "PlayerTumble")
				{
					object? value = fieldInfo.GetValue(p);
					Component val = (Component)((value is Component) ? value : null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
			PropertyInfo[] properties = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (!(propertyInfo.PropertyType.Name == "PlayerTumble") || !propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length != 0)
				{
					continue;
				}
				try
				{
					object? value2 = propertyInfo.GetValue(p, null);
					Component val = (Component)((value2 is Component) ? value2 : null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				catch
				{
				}
			}
			type = type.BaseType;
		}
		Component val2 = FindComp((Component)(object)p, "PlayerTumble");
		if ((Object)(object)val2 != (Object)null)
		{
			return val2;
		}
		Type type2 = Registrar.FindType("PlayerTumble");
		if (type2 == null)
		{
			return null;
		}
		Object[] array = Object.FindObjectsByType(type2, (FindObjectsSortMode)0);
		foreach (Object val3 in array)
		{
			Component val4 = (Component)(object)((val3 is Component) ? val3 : null);
			if ((Object)(object)val4 == (Object)null)
			{
				continue;
			}
			Type type3 = ((object)val4).GetType();
			while (type3 != null && type3 != typeof(MonoBehaviour))
			{
				FieldInfo[] fields = type3.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo2 in fields)
				{
					if (fieldInfo2.FieldType == typeof(PlayerAvatar) && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)p)
					{
						return val4;
					}
				}
				type3 = type3.BaseType;
			}
		}
		return null;
	}

	private PlayerAvatar FindNearestPlayer()
	{
		//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)
		PlayerAvatar result = null;
		float num = 6f;
		PlayerAvatar[] array = Object.FindObjectsByType<PlayerAvatar>((FindObjectsSortMode)0);
		foreach (PlayerAvatar val in array)
		{
			if (!BoolMember(val, "isDisabled") && !BoolMember(val, "deadSet") && !((Object)(object)FindTumble(val) == (Object)null))
			{
				float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = val;
				}
			}
		}
		return result;
	}

	private Enemy FindNearestEnemy(bool skipStunned)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		Enemy result = null;
		float num = 6f;
		Enemy[] array = Object.FindObjectsByType<Enemy>((FindObjectsSortMode)0);
		foreach (Enemy val in array)
		{
			if (!skipStunned || !val.IsStunned())
			{
				float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = val;
				}
			}
		}
		return result;
	}

	private static bool IsDronePartName(string n)
	{
		n = n.Replace('_', ' ').Trim();
		return n == "Drone" || n.StartsWith("Drone Triangle") || n.StartsWith("Drone Pyramid") || n.StartsWith("Drone Icon");
	}

	private void AddBatteryRefs(object v)
	{
		if (v == null)
		{
			return;
		}
		if (v is IEnumerable enumerable && !(v is string) && !(v is Object))
		{
			foreach (object item2 in enumerable)
			{
				AddBatteryRefs(item2);
			}
			return;
		}
		Object val = (Object)((v is Object) ? v : null);
		if (val == (Object)null)
		{
			return;
		}
		Transform val2 = null;
		Renderer val3 = (Renderer)(object)((val is Renderer) ? val : null);
		if ((Object)(object)val3 != (Object)null)
		{
			batRend.Add(val3);
			return;
		}
		Component val4 = (Component)(object)((val is Component) ? val : null);
		if ((Object)(object)val4 != (Object)null)
		{
			val2 = val4.transform;
		}
		GameObject val5 = (GameObject)(object)((val is GameObject) ? val : null);
		if ((Object)(object)val5 != (Object)null)
		{
			val2 = val5.transform;
		}
		if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)((Component)this).transform) && !((Component)this).transform.IsChildOf(val2) && !IsDronePartName(((Object)val2).name))
		{
			Renderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer item in componentsInChildren)
			{
				batRend.Add(item);
			}
		}
	}

	private void CollectBatteryRenderers()
	{
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)this)
			{
				continue;
			}
			string name = ((object)val).GetType().Name;
			if (name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) < 0)
			{
				continue;
			}
			if (name.IndexOf("Visual", StringComparison.OrdinalIgnoreCase) >= 0 && (Object)(object)((Component)val).transform != (Object)(object)((Component)this).transform && !IsDronePartName(((Object)((Component)val).transform).name))
			{
				Renderer[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer item in componentsInChildren2)
				{
					batRend.Add(item);
				}
			}
			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.IsPrimitive && !(fieldInfo.FieldType == typeof(string)))
					{
						object v = null;
						try
						{
							v = fieldInfo.GetValue(val);
						}
						catch
						{
						}
						AddBatteryRefs(v);
					}
				}
				type = type.BaseType;
			}
		}
		Debug.Log((object)("[StunDrone] battery renderers excluded from retexture: " + batRend.Count));
	}

	private bool IsBatteryRenderer(Renderer r)
	{
		if (batRend.Contains(r) || IsUnder(((Component)r).transform, "Battery") || IsUnder(((Component)r).transform, "Bar"))
		{
			return true;
		}
		Transform val = ((Component)r).transform;
		while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)((Component)this).transform)
		{
			MonoBehaviour[] components = ((Component)val).GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val2 in components)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)this && ((object)val2).GetType().Name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					batRend.Add(r);
					return true;
				}
			}
			val = val.parent;
		}
		return false;
	}

	private static bool IsUnder(Transform t, string part)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name.IndexOf(part, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private static int[] ColorProps(Material m)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Invalid comparison between Unknown and I4
		List<int> list = new List<int>();
		Shader val = (((Object)(object)m != (Object)null) ? m.shader : null);
		if ((Object)(object)val == (Object)null)
		{
			return list.ToArray();
		}
		int propertyCount = val.GetPropertyCount();
		for (int i = 0; i < propertyCount; i++)
		{
			if ((int)val.GetPropertyType(i) == 0)
			{
				list.Add(Shader.PropertyToID(val.GetPropertyName(i)));
			}
		}
		return list.ToArray();
	}

	private static Gradient SolidGradient(Color c)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		Gradient val = new Gradient();
		val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
		{
			new GradientColorKey(c, 0f),
			new GradientColorKey(c, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
		{
			new GradientAlphaKey(1f, 0f),
			new GradientAlphaKey(1f, 1f)
		});
		return val;
	}

	private void TintBeams()
	{
		//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_013e: 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_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		if (Time.time > nextBeamFind)
		{
			nextBeamFind = Time.time + 1f;
			beamList.Clear();
			Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !IsUnder(((Component)val).transform, "Drone Icon") && !IsBatteryRenderer(val) && (val is LineRenderer || val is ParticleSystemRenderer || val is TrailRenderer || Classify(((Component)val).transform) == Part.Skip))
				{
					beamList.Add(val);
				}
			}
		}
		Color orange = Orange;
		foreach (Renderer beam in beamList)
		{
			if (!((Object)(object)beam == (Object)null))
			{
				LineRenderer val2 = (LineRenderer)(object)((beam is LineRenderer) ? beam : null);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.startColor = orange;
					val2.endColor = orange;
					val2.colorGradient = SolidGradient(orange);
				}
				Material material = beam.material;
				if (!beamProps.TryGetValue(beam, out var value))
				{
					value = ColorProps(material);
					beamProps[beam] = value;
				}
				int[] array = value;
				foreach (int num in array)
				{
					Color color = material.GetColor(num);
					material.SetColor(num, new Color(orange.r, orange.g, orange.b, color.a));
				}
			}
		}
	}

	private void ApplyDroneFieldColors()
	{
		//IL_0100: 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)
		StringBuilder stringBuilder = new StringBuilder("[StunDrone] drone color fields: ");
		MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)this)
			{
				continue;
			}
			string name = ((object)val).GetType().Name;
			if (name == "ItemAttributes" || name.IndexOf("Battery", StringComparison.OrdinalIgnoreCase) >= 0 || val is Graphic)
			{
				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)
				{
					string text = fieldInfo.Name.ToLower();
					if (fieldInfo.FieldType == typeof(Color) && text.Contains("color"))
					{
						fieldInfo.SetValue(val, Orange);
						if (!fieldColorLogged)
						{
							stringBuilder.Append(name).Append('.').Append(fieldInfo.Name)
								.Append("; ");
						}
					}
					else if (fieldInfo.FieldType == typeof(Gradient) && (text.Contains("color") || text.Contains("gradient")))
					{
						fieldInfo.SetValue(val, SolidGradient(Orange));
						if (!fieldColorLogged)
						{
							stringBuilder.Append(name).Append('.').Append(fieldInfo.Name)
								.Append("(gradient); ");
						}
					}
				}
				type = type.BaseType;
			}
		}
		if (!fieldColorLogged)
		{
			fieldColorLogged = true;
			Debug.Log((object)stringBuilder.ToString());
		}
	}

	private static void SetNum(object o, string name, float v)
	{
		Type type = o.GetType();
		while (type != null && type != typeof(MonoBehaviour))
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(field == null))
			{
				if (field.FieldType == typeof(float))
				{
					field.SetValue(o, v);
				}
				else if (field.FieldType == typeof(int))
				{
					field.SetValue(o, Mathf.RoundToInt(v));
				}
				break;
			}
			type = type.BaseType;
		}
	}

	private static bool GetNum(object o, string name, out float v)
	{
		v = 0f;
		Type type = o.GetType();
		while (type != null && type != typeof(MonoBehaviour))
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(field == null))
			{
				if (field.FieldType == typeof(float))
				{
					v = (float)field.GetValue(o);
					return true;
				}
				if (field.FieldType == typeof(int))
				{
					v = (int)field.GetValue(o);
					return true;
				}
				return false;
			}
			type = type.BaseType;
		}
		return false;
	}

	private void SyncBattery()
	{
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)batteryComp == (Object)null)
		{
			if (Time.time < nextBatFind)
			{
				return;
			}
			nextBatFind = Time.time + 1f;
			MonoBehaviour[] componentsInChildren = ((Component)this).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && ((object)val).GetType().Name == "ItemBattery")
				{
					batteryComp = (Component)(object)val;
					break;
				}
			}
			if ((Object)(object)batteryComp == (Object)null)
			{
				return;
			}
		}
		if (!batteryLogged)
		{
			batteryLogged = true;
			Debug.Log((object)("[StunDrone] ItemBattery found, bars=" + Cap));
		}
		SetNum(batteryComp, "batteryBars", Cap);
		if (!uiDumped && Time.time > nextBatFind + 3f && batteryLogged)
		{
			uiDumped = true;
			StringBuilder stringBuilder = new StringBuilder("[StunDrone] battery UI dump: ");
			Graphic[] componentsInChildren2 = batteryComp.GetComponentsInChildren<Graphic>(true);
			foreach (Graphic val2 in componentsInChildren2)
			{
				string text = ((Object)val2).name;
				Transform parent = ((Component)val2).transform.parent;
				while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)batteryComp.transform)
				{
					text = ((Object)parent).name + "/" + text;
					parent = parent.parent;
				}
				stringBuilder.Append(text).Append(" [").Append(((object)val2).GetType().Name)
					.Append(((Component)val2).gameObject.activeInHierarchy ? "" : ",off")
					.Append(", ")
					.Append(val2.color)
					.Append("]; ");
			}
			Debug.Log((object)stringBuilder.ToString());
		}
		float v;
		if (lifeVal < 0f)
		{
			if (GetNum(batteryComp, "batteryLife", out v) && v >= 0f && v <= 100f)
			{
				lifeVal = v;
				charge = Mathf.Clamp(Mathf.FloorToInt(v * (float)Cap / 100f + 0.001f), 0, Cap);
				Debug.Log((object)("[StunDrone] restored charge " + charge + "/" + Cap + " from batteryLife=" + v));
			}
			else
			{
				lifeVal = 100f * (float)charge / (float)Cap;
			}
			lastCharge = charge;
		}
		if (GetNum(batteryComp, "batteryLife", out v) && v > lifeVal + 0.01f)
		{
			lifeVal = Mathf.Min(100f, v);
			charge = Mathf.Clamp(Mathf.FloorToInt(lifeVal * (float)Cap / 100f + 0.001f), 0, Cap);
		}
		else if (charge < lastCharge)
		{
			lifeVal = 100f * (float)charge / (float)Cap;
		}
		else if (charge > lastCharge)
		{
			lifeVal = Mathf.Max(lifeVal, 100f * (float)charge / (float)Cap);
		}
		if (lifeVal >= 99.5f)
		{
			lifeVal = 100f;
			charge = Cap;
		}
		lastCharge = charge;
		SetNum(batteryComp, "batteryLife", lifeVal);
		if (charge >= Cap)
		{
			SetNum(batteryComp, "batteryLifeInt", Cap);
		}
		if (Time.time > nextBatDump && charge != dumpedCharge)
		{
			nextBatDump = Time.time + 2f;
			dumpedCharge = charge;
			StringBuilder stringBuilder2 = new StringBuilder("[StunDrone] ItemBattery dump (charge=" + charge + "/" + Cap + "): ");
			Type type = ((object)batteryComp).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) || fieldInfo.FieldType == typeof(int) || fieldInfo.FieldType == typeof(bool))
					{
						stringBuilder2.Append(string.Concat(fieldInfo.Name, "=", fieldInfo.GetValue(batteryComp), "; "));
					}
				}
				type = type.BaseType;
			}
			Debug.Log((object)stringBuilder2.ToString());
		}
		Type type2 = ((object)batteryComp).GetType();
		while (type2 != null && type2 != typeof(MonoBehaviour))
		{
			FieldInfo[] fields = type2.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo2 in fields)
			{
				if (fieldInfo2.FieldType == typeof(float) && fieldInfo2.Name.ToLower().Contains("drain"))
				{
					fieldInfo2.SetValue(batteryComp, 0f);
				}
			}
			type2 = type2.BaseType;
		}
	}

	private static bool IsAuthority()
	{
		try
		{
			return !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient;
		}
		catch
		{
			return true;
		}
	}

	private static bool IntMember(object o, string name, out int v)
	{
		v = 0;
		Type type = o.GetType();
		while (type != null)
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(int))
			{
				v = (int)field.GetValue(o);
				return true;
			}
			PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.PropertyType == typeof(int) && property.CanRead && property.GetIndexParameters().Length == 0)
			{
				try
				{
					v = (int)property.GetValue(o, null);
					return true;
				}
				catch
				{
					return false;
				}
			}
			type = type.BaseType;
		}
		return false;
	}

	private static Component FindHealth(PlayerAvatar p)
	{
		Type type = ((object)p).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.Name == "PlayerHealth")
				{
					object? value = fieldInfo.GetValue(p);
					Component val = (Component)((value is Component) ? value : null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
			type = type.BaseType;
		}
		return FindComp((Component)(object)p, "PlayerHealth");
	}

	private bool NeedsHeal(PlayerAvatar p)
	{
		if ((Object)(object)p == (Object)null)
		{
			return false;
		}
		if (BoolMember(p, "isDisabled") || BoolMember(p, "deadSet"))
		{
			return false;
		}
		Component val = FindHealth(p);
		if ((Object)(object)val == (Object)null)
		{
			return true;
		}
		if (IntMember(val, "health", out var v) && IntMember(val, "maxHealth", out var v2))
		{
			return v < v2;
		}
		return true;
	}

	private void HealTick()
	{
		object obj = stunned;
		PlayerAvatar val = (PlayerAvatar)((obj is PlayerAvatar) ? obj : null);
		if ((Object)(object)val == (Object)null || Time.time < nextHeal)
		{
			return;
		}
		nextHeal = Time.time + HealInterval;
		if (!IsAuthority() || !NeedsHeal(val))
		{
			return;
		}
		Component val2 = FindHealth(val);
		if ((Object)(object)val2 == (Object)null)
		{
			if (!healWarned)
			{
				healWarned = true;
				Debug.LogWarning((object)"[HealDrone] PlayerHealth not found");
			}
		}
		else if (CallMethod(val2, "Heal", HealAmount, true) || CallMethod(val2, "Heal", HealAmount))
		{
			charge--;
			Debug.Log((object)("[HealDrone] healed " + HealAmount + " HP, charge=" + charge));
		}
		else if (!healWarned)
		{
			healWarned = true;
			Debug.LogWarning((object)"[HealDrone] PlayerHealth.Heal call failed");
		}
	}

	private void StunPlayer(PlayerAvatar p)
	{
		try
		{
			if ((Object)(object)tumbleCache == (Object)null || (Object)(object)cachedFor != (Object)(object)p)
			{
				tumbleCache = FindTumble(p);
				cachedFor = p;
			}
			Component val = tumbleCache;
			if ((Object)(object)val == (Object)null)
			{
				if (!tumbleWarned)
				{
					tumbleWarned = true;
					Debug.LogWarning((object)"[StunDrone] PlayerTumble not found");
				}
				return;
			}
			if (!CallMethod(val, "TumbleRequest", true, true) && !tumbleWarned)
			{
				tumbleWarned = true;
				Debug.LogWarning((object)"[StunDrone] TumbleRequest call failed");
			}
			CallMethod(val, "TumbleOverrideTime", 3f);
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[StunDrone] StunPlayer: " + ex.Message));
		}
	}

	private void StunEnemy(Enemy e)
	{
		try
		{
			Component val = FindStun((Component)(object)e);
			if ((Object)(object)val != (Object)null && CallMethod(val, "Set", 1.5f))
			{
				if (!stunOk)
				{
					stunOk = true;
					Debug.Log((object)("[StunDrone] enemy stunned via " + ((object)val).GetType().Name + ".Set on " + ((Object)e).name));
				}
				return;
			}
			if ((Object)(object)val != (Object)null && !stunWarned2)
			{
				stunWarned2 = true;
				StringBuilder stringBuilder = new StringBuilder("[StunDrone] " + ((object)val).GetType().Name + " methods: ");
				MethodInfo[] methods = ((object)val).GetType().GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					stringBuilder.Append(methodInfo.Name).Append('(');
					ParameterInfo[] parameters = methodInfo.GetParameters();
					foreach (ParameterInfo parameterInfo in parameters)
					{
						stringBuilder.Append(parameterInfo.ParameterType.Name).Append(' ');
					}
					stringBuilder.Append("); ");
				}
				Debug.LogWarning((object)stringBuilder.ToString());
			}
			if ((Object)(object)val == (Object)null && !noStunLogged.Contains(((Object)e).name))
			{
				noStunLogged.Add(((Object)e).name);
				Debug.LogWarning((object)("[StunDrone] enemy '" + ((Object)e).name + "' has no stun state -> freezing manually"));
			}
			FreezeEnemy(e);
			bool flag = false;
			MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val2 in componentsInChildren)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Type type = ((object)val2).GetType();
				while (type != null && type != typeof(MonoBehaviour))
				{
					FieldInfo field = type.GetField("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.FieldType == typeof(bool))
					{
						field.SetValue(val2, true);
						flag = true;
					}
					PropertyInfo property = type.GetProperty("Stunned", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null && property.PropertyType == typeof(bool) && property.CanWrite)
					{
						try
						{
							property.SetValue(val2, true, null);
							flag = true;
						}
						catch
						{
						}
					}
					type = type.BaseType;
				}
			}
			if (!flag)
			{
				Debug.LogWarning((object)"[StunDrone] no way to stun enemy (no EnemyState*Stun*, no Stunned flag)");
			}
			else if (!stunWarned)
			{
				stunWarned = true;
				Debug.LogWarning((object)"[StunDrone] used Stunned flag fallback (state component not found) - may not actually stop the AI");
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[StunDrone] StunEnemy: " + ex.Message));
		}
	}

	private void FreezeEnemy(Enemy e)
	{
		//IL_00b9: 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)
		MonoBehaviour[] componentsInChildren = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<MonoBehaviour>(true);
		foreach (MonoBehaviour val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)null))
			{
				string name = ((object)val).GetType().Name;
				if (name == "EnemyNavMeshAgent")
				{
					CallMethod(val, "Disable", 0.3f);
				}
			}
		}
		Rigidbody[] componentsInChildren2 = ((Component)EnemyRoot((Component)(object)e)).GetComponentsInChildren<Rigidbody>(true);
		foreach (Rigidbody val2 in componentsInChildren2)
		{
			if ((Object)(object)val2 != (Object)null && !val2.isKinematic)
			{
				val2.linearVelocity = Vector3.zero;
				val2.angularVelocity = Vector3.zero;
			}
		}
	}

	private void DefenseTick(PlayerAvatar p)
	{
		DefenseHighlight defenseHighlight = ((Component)p).GetComponent<DefenseHighlight>();
		if ((Object)(object)defenseHighlight == (Object)null)
		{
			defenseHighlight = ((Component)p).gameObject.AddComponent<DefenseHighlight>();
		}
		defenseHighlight.SetActive(active: true);
		DefenseHudOverlay.SetProtected(p, active: true);
		if (!IsAuthority())
		{
			return;
		}
		Component val = FindHealth(p);
		if ((Object)(object)val == (Object)null || !IntMember(val, "health", out var v))
		{
			return;
		}
		if ((Object)(object)lastDefPlayer != (Object)(object)p)
		{
			lastDefPlayer = p;
			lastDefHp = v;
			return;
		}
		if (v < lastDefHp && v > 0)
		{
			int num = lastDefHp - v;
			CallMethod(val, "Heal", num, false);
			IntMember(val, "health", out v);
		}
		lastDefHp = v;
	}

	private void ClearDefense(object target)
	{
		lastDefPlayer = null;
		lastDefHp = -1;
		PlayerAvatar val = (PlayerAvatar)((target is PlayerAvatar) ? target : null);
		if (!((Object)(object)val == (Object)null))
		{
			DefenseHighlight component = ((Component)val).GetComponent<DefenseHighlight>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetActive(active: false);
			}
			DefenseHudOverlay.SetProtected(val, active: false);
		}
	}
}
public class HealDroneLogic : StunDroneLogic
{
}
public class DefenseDroneLogic : StunDroneLogic
{
}
public class DefenseHudOverlay : MonoBehaviour
{
	private struct GraphicState
	{
		public Graphic graphic;

		public Color origColor;
	}

	private static DefenseHudOverlay instance;

	private static readonly Dictionary<int, float> protectedUntil = new Dictionary<int, float>();

	private static Texture2D shieldTex;

	public static float ShieldOffsetX = 8f;

	public static float ShieldOffsetY = 0f;

	public static float ShieldScale = 0.7f;

	private readonly List<GraphicState> tintedGraphics = new List<GraphicState>();

	private GameObject shieldBadgeGo;

	private RawImage shieldBadgeImg;

	private bool hudApplied;

	private float nextScan;

	public static void SetProtected(PlayerAvatar p, bool active)
	{
		if (!((Object)(object)p == (Object)null))
		{
			int instanceID = ((Object)p).GetInstanceID();
			if (active)
			{
				protectedUntil[instanceID] = Time.time + 1.5f;
			}
			else
			{
				protectedUntil.Remove(instanceID);
			}
			EnsureInstance();
		}
	}

	private static void EnsureInstance()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		if (!((Object)(object)instance != (Object)null))
		{
			GameObject val = new GameObject("DefenseDroneHudOverlay");
			Object.DontDestroyOnLoad((Object)(object)val);
			instance = val.AddComponent<DefenseHudOverlay>();
		}
	}

	private static bool IsLocalPlayerProtected()
	{
		if (protectedUntil.Count == 0)
		{
			return false;
		}
		float time = Time.time;
		List<int> list = new List<int>();
		bool flag = false;
		foreach (KeyValuePair<int, float> item in protectedUntil)
		{
			if (item.Value < time)
			{
				list.Add(item.Key);
			}
		}
		for (int i = 0; i < list.Count; i++)
		{
			protectedUntil.Remove(list[i]);
		}
		if (protectedUntil.Count == 0)
		{
			return false;
		}
		PlayerAvatar[] array = Object.FindObjectsByType<PlayerAvatar>((FindObjectsSortMode)0);
		foreach (PlayerAvatar val in array)
		{
			if (!((Object)(object)val == (Object)null) && protectedUntil.ContainsKey(((Object)val).GetInstanceID()) && IsLocalAvatar(val))
			{
				flag = true;
				break;
			}
		}
		if (!flag && protectedUntil.Count > 0)
		{
			flag = true;
		}
		return flag;
	}

	private static bool IsLocalAvatar(PlayerAvatar p)
	{
		if ((Object)(object)p == (Object)null)
		{
			return false;
		}
		try
		{
			PhotonView component = ((Component)p).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null)
			{
				return component.IsMine;
			}
		}
		catch
		{
		}
		try
		{
			FieldInfo field = ((object)p).GetType().GetField("photonView", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				object? value = field.GetValue(p);
				PhotonView val = (PhotonView)((value is PhotonView) ? value : null);
				if ((Object)(object)val != (Object)null)
				{
					return val.IsMine;
				}
			}
		}
		catch
		{
		}
		return false;
	}

	private static Texture2D GetShieldTexture()
	{
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)shieldTex != (Object)null)
		{
			return shieldTex;
		}
		try
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("def_shield.png");
			if (stream != null)
			{
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (ImageConversion.LoadImage(val, array))
				{
					shieldTex = val;
					return shieldTex;
				}
			}
		}
		catch
		{
		}
		Texture2D val2 = new Texture2D(32, 32, (TextureFormat)4, false);
		Color val3 = default(Color);
		((Color)(ref val3))..ctor(0f, 0f, 0f, 0f);
		for (int i = 0; i < 32; i++)
		{
			for (int j = 0; j < 32; j++)
			{
				val2.SetPixel(j, i, val3);
			}
		}
		val2.Apply();
		shieldTex = val2;
		return shieldTex;
	}

	private void Update()
	{
		if (!IsLocalPlayerProtected())
		{
			if (hudApplied)
			{
				RestoreHud();
			}
		}
		else if (!hudApplied || Time.time >= nextScan)
		{
			nextScan = Time.time + 0.1f;
			ApplyHud();
		}
	}

	private static bool IsInsideHealth(Transform t)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name == "Health")
			{
				return true;
			}
			if (((Object)val).name == "Game Hud")
			{
				break;
			}
			val = val.parent;
		}
		return false;
	}

	private static bool IsInsideNamed(Transform t, string name)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name == name)
			{
				return true;
			}
			if (((Object)val).name == "Health" || ((Object)val).name == "Game Hud")
			{
				break;
			}
			val = val.parent;
		}
		return false;
	}

	private static bool GetTextWorldBounds(Graphic g, RectTransform rt, out Vector3 a, out Vector3 b)
	{
		//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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0068: 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_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00bc: Unknown result type (might be due to invalid IL or missing references)
		a = Vector3.zero;
		b = Vector3.zero;
		try
		{
			PropertyInfo property = ((object)g).GetType().GetProperty("textBounds", BindingFlags.Instance | BindingFlags.Public);
			if (property == null || property.PropertyType != typeof(Bounds))
			{
				return false;
			}
			Bounds val = (Bounds)property.GetValue(g, null);
			if (((Bounds)(ref val)).size.x < 0.01f || ((Bounds)(ref val)).size.y < 0.01f)
			{
				return false;
			}
			a = ((Transform)rt).TransformPoint(((Bounds)(ref val)).min);
			b = ((Transform)rt).TransformPoint(((Bounds)(ref val)).max);
			return true;
		}
		catch
		{
			return false;
		}
	}

	private static RectTransform FindHealthRoot()
	{
		RectTransform val = null;
		RectTransform[] array = Object.FindObjectsByType<RectTransform>((FindObjectsSortMode)0);
		foreach (RectTransform val2 in array)
		{
			if (!((Object)(object)val2 == (Object)null) && !(((Object)((Component)val2).gameObject).name != "Health") && IsUnderGameHud((Transform)(object)val2) && ((Object)(object)val == (Object)null || (((Component)val2).gameObject.activeInHierarchy && !((Component)val).gameObject.activeInHierarchy)))
			{
				val = val2;
			}
		}
		return val;
	}

	private static bool IsUnderGameHud(Transform t)
	{
		Transform val = t;
		while ((Object)(object)val != (Object)null)
		{
			if (((Object)val).name == "Game Hud")
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private void ApplyHud()
	{
		//IL_03c5: 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_0158: 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_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: 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_0268: 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_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_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: 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_025d: Unknown result type (might be due to invalid IL or missing references)
		hudApplied = true;
		Color val = default(Color);
		((Color)(ref val))..ctor(0.14f, 0.66f, 1f, 1f);
		RectTransform val2 = FindHealthRoot();
		bool flag = false;
		bool flag2 = false;
		float num = 0f;
		float num2 = 0f;
		float num3 = 0f;
		float num4 = 0f;
		Vector3[] array = (Vector3[])(object)new Vector3[4];
		Graphic[] array2 = Object.FindObjectsByType<Graphic>((FindObjectsSortMode)0);
		foreach (Graphic val3 in array2)
		{
			if ((Object)(object)val3 == (Object)null || ((Object)(object)shieldBadgeGo != (Object)null && ((Component)val3).transform.IsChildOf(shieldBadgeGo.transform)) || !IsInsideHealth(((Component)val3).transform))
			{
				continue;
			}
			bool flag3 = false;
			for (int j = 0; j < tintedGraphics.Count; j++)
			{
				if ((Object)(object)tintedGraphics[j].graphic == (Object)(object)val3)
				{
					flag3 = true;
					break;
				}
			}
			if (!flag3)
			{
				tintedGraphics.Add(new GraphicState
				{
					graphic = val3,
					origColor = val3.color
				});
			}
			Color color = val;
			color.a = ((val3.color.a > 0f) ? val3.color.a : 1f);
			val3.color = color;
			if ((Object)(object)val2 == (Object)null || !((Component)val3).gameObject.activeInHierarchy || !((Behaviour)val3).enabled)
			{
				continue;
			}
			bool flag4 = IsInsideNamed(((Component)val3).transform, "HealthMax");
			if (!flag4 && flag2)
			{
				continue;
			}
			if (flag4 && !flag2)
			{
				flag = false;
				flag2 = true;
			}
			RectTransform rectTransform = val3.rectTransform;
			if ((Object)(object)rectTransform == (Object)null)
			{
				continue;
			}
			if (!GetTextWorldBounds(val3, rectTransform, out var a, out var b))
			{
				rectTransform.GetWorldCorners(array);
				a = array[0];
				b = array[2];
			}
			Vector3 val4 = ((Transform)val2).InverseTransformPoint(a);
			Vector3 val5 = ((Transform)val2).InverseTransformPoint(b);
			float num5 = Mathf.Min(val4.x, val5.x);
			float num6 = Mathf.Max(val4.x, val5.x);
			float num7 = Mathf.Min(val4.y, val5.y);
			float num8 = Mathf.Max(val4.y, val5.y);
			if (num6 - num5 < 0.01f || num8 - num7 < 0.01f)
			{
				continue;
			}
			if (!flag)
			{
				num = num5;
				num2 = num6;
				num3 = num7;
				num4 = num8;
				flag = true;
				continue;
			}
			if (num5 < num)
			{
				num = num5;
			}
			if (num6 > num2)
			{
				num2 = num6;
			}
			if (num7 < num3)
			{
				num3 = num7;
			}
			if (num8 > num4)
			{
				num4 = num8;
			}
		}
		if (!((Object)(object)val2 == (Object)null))
		{
			Vector2 localPos = default(Vector2);
			if (flag)
			{
				((Vector2)(ref localPos))..ctor(num2 + ShieldOffsetX, (num3 + num4) * 0.5f + ShieldOffsetY);
			}
			else
			{
				((Vector2)(ref localPos))..ctor(ShieldOffsetX, ShieldOffsetY);
			}
			EnsureShieldBadge(val2, localPos, 64f * ShieldScale);
		}
	}

	private void EnsureShieldBadge(RectTransform healthRoot, Vector2 localPos, float size)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_00cb: 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_00f7: 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_0119: 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_0133: 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)
		if ((Object)(object)shieldBadgeGo == (Object)null)
		{
			shieldBadgeGo = new GameObject("DefenseDroneShieldIcon", new Type[1] { typeof(RectTransform) });
			shieldBadgeImg = shieldBadgeGo.AddComponent<RawImage>();
			((Graphic)shieldBadgeImg).raycastTarget = false;
		}
		RectTransform component = shieldBadgeGo.GetComponent<RectTransform>();
		if ((Object)(object)((Transform)component).parent != (Object)(object)healthRoot)
		{
			((Transform)component).SetParent((Transform)(object)healthRoot, false);
			shieldBadgeGo.layer = ((Component)healthRoot).gameObject.layer;
		}
		shieldBadgeGo.SetActive(true);
		((Behaviour)shieldBadgeImg).enabled = true;
		shieldBadgeImg.texture = (Texture)(object)GetShieldTexture();
		((Graphic)shieldBadgeImg).color = Color.white;
		component.anchorMin = new Vector2(0.5f, 0.5f);
		component.anchorMax = new Vector2(0.5f, 0.5f);
		component.pivot = new Vector2(0f, 0.5f);
		((Transform)component).localScale = Vector3.one;
		((Transform)component).localRotation = Quaternion.identity;
		component.sizeDelta = new Vector2(size, size);
		((Transform)component).localPosition = new Vector3(localPos.x, localPos.y, 0f);
		((Transform)component).SetAsLastSibling();
	}

	private void RestoreHud()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		hudApplied = false;
		for (int i = 0; i < tintedGraphics.Count; i++)
		{
			GraphicState graphicState = tintedGraphics[i];
			if ((Object)(object)graphicState.graphic != (Object)null)
			{
				graphicState.graphic.color = graphicState.origColor;
			}
		}
		tintedGraphics.Clear();
		if ((Object)(object)shieldBadgeGo != (Object)null)
		{
			shieldBadgeGo.SetActive(false);
		}
	}

	private void OnDisable()
	{
		RestoreHud();
	}

	private void OnDestroy()
	{
		RestoreHud();
	}
}
public class DefenseHighlight : MonoBehaviour
{
	private struct MatState
	{
		public Material mat;

		public bool hadEmission;

		public Color origColor;

		public bool hasColor;

		public Color origBaseColor;

		public bool hasBaseColor;

		public Color origEmission;

		public bool hasEmission;
	}

	private static readonly Color GlowColor = new Color(0.06f, 0.22f, 1f, 1f);

	private static readonly Color TintColor = new Color(0.28f, 0.48f, 1f, 1f);

	private readonly List<MatState> states = new List<MatState>();

	private Light auraLight;

	private bool isHighlighted;

	private float nextRefresh;

	public void SetActive(bool active)
	{
		if (active)
		{
			if (!isHighlighted || Time.time > nextRefresh)
			{
				nextRefresh = Time.time + 0.25f;
				Apply();
			}
			isHighlighted = true;
		}
		else if (isHighlighted)
		{
			Restore();
			isHighlighted = false;
		}
	}

	private void Apply()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_004d: 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_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: 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_0212: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)auraLight == (Object)null)
		{
			GameObject val = new GameObject("DefenseDroneAuraLight");
			val.transform.SetParent(((Component)this).transform, false);
			val.transform.localPosition = new Vector3(0f, 1f, 0f);
			auraLight = val.AddComponent<Light>();
			auraLight.type = (LightType)2;
			auraLight.color = GlowColor;
			auraLight.range = 4.5f;
			auraLight.intensity = 2.6f;
		}
		((Behaviour)auraLight).enabled = true;
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val2 in componentsInChildren)
		{
			if ((Object)(object)val2 == (Object)null || val2 is ParticleSystemRenderer || val2 is LineRenderer)
			{
				continue;
			}
			Material material = val2.material;
			if ((Object)(object)material == (Object)null)
			{
				continue;
			}
			bool flag = false;
			for (int j = 0; j < states.Count; j++)
			{
				if ((Object)(object)states[j].mat == (Object)(object)material)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				MatState item = new MatState
				{
					mat = material,
					hadEmission = material.IsKeywordEnabled("_EMISSION")
				};
				if (material.HasProperty("_Color"))
				{
					item.hasColor = true;
					item.origColor = material.GetColor("_Color");
				}
				if (material.HasProperty("_BaseColor"))
				{
					item.hasBaseColor = true;
					item.origBaseColor = material.GetColor("_BaseColor");
				}
				if (material.HasProperty("_EmissionColor"))
				{
					item.hasEmission = true;
					item.origEmission = material.GetColor("_EmissionColor");
				}
				states.Add(item);
			}
			material.EnableKeyword("_EMISSION");
			if (material.HasProperty("_EmissionColor"))
			{
				material.SetColor("_EmissionColor", GlowColor * 1.35f);
			}
			if (material.HasProperty("_Color"))
			{
				material.SetColor("_Color", TintColor);
			}
			if (material.HasProperty("_BaseColor"))
			{
				material.SetColor("_BaseColor", TintColor);
			}
		}
	}

	private void Restore()
	{
		//IL_006b: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)auraLight != (Object)null)
		{
			((Behaviour)auraLight).enabled = false;
		}
		for (int i = 0; i < states.Count; i++)
		{
			MatState matState = states[i];
			if (!((Object)(object)matState.mat == (Object)null))
			{
				if (matState.hasColor)
				{
					matState.mat.SetColor("_Color", matState.origColor);
				}
				if (matState.hasBaseColor)
				{
					matState.mat.SetColor("_BaseColor", matState.origBaseColor);
				}
				if (matState.hasEmission)
				{
					matState.mat.SetColor("_EmissionColor", matState.origEmission);
				}
				if (!matState.hadEmission)
				{
					matState.mat.DisableKeyword("_EMISSION");
				}
			}
		}
		states.Clear();
	}

	private void OnDisable()
	{
		if (isHighlighted)
		{
			Restore();
			isHighlighted = false;
		}
	}

	private void OnDestroy()
	{
		if (isHighlighted)
		{
			Restore();
			isHighlighted = false;
		}
	}
}
internal static class Registrar
{
	private const BindingFlags BF = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

	public static int Tries;

	public static string Prefer = "";

	public static float PriceMin = 40000f;

	public static float PriceMax = 75000f;

	public static float PriceScale = 0f;

	public static float ShopMultiplier = 0f;

	public static float HealPriceMin = 25000f;

	public static float HealPriceMax = 50000f;

	public static float DefPriceMin = 30000f;

	public static float DefPriceMax = 60000f;

	private static bool StunDone = true;

	private static bool HealDone = true;

	private static bool DefDone;

	private static string lastMsg;

	public static bool Done => StunDone && HealDone && DefDone;

	public static bool AnyDone => StunDone || HealDone || DefDone;

	private static void Say(ManualLogSource log, string m)
	{
		if (!(m == lastMsg))
		{
			lastMsg = m;
			log.LogInfo((object)("[Register] " + m));
		}
	}

	private static FieldInfo Fld(Type t, string name)
	{
		while (t != null)
		{
			FieldInfo field = t.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				return field;
			}
			t = t.BaseType;
		}
		return null;
	}

	private static string GetS(object o, string name)
	{
		FieldInfo fieldInfo = Fld(o.GetType(), name);
		return (fieldInfo != null) ? (fieldInfo.GetValue(o) as string) : null;
	}

	private static void SetS(object o, string name, string v)
	{
		FieldInfo fieldInfo = Fld(o.GetType(), name);
		if (fieldInfo != null && fieldInfo.FieldType == typeof(string))
		{
			fieldInfo.SetValue(o, v);
		}
	}

	internal static Type FindType(string full)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			try
			{
				Type type = assembly.GetType(full);
				if (type != null)
				{
					return type;
				}
			}
			catch
			{
			}
		}
		return null;
	}

	private static GameObject ExtractGO(object o)
	{
		if (o == null)
		{
			return null;
		}
		GameObject val = (GameObject)((o is GameObject) ? o : null);
		if ((Object)