Decompiled source of ChillDrone v2.2.3

ChillDrone.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Chen.ChillDrone.Drone.States;
using Chen.GradiusMod;
using Chen.GradiusMod.Drones;
using Chen.GradiusMod.Items;
using Chen.GradiusMod.Items.GradiusOption;
using Chen.GradiusMod.Items.GradiusOption.Components;
using Chen.Helpers.GeneralHelpers;
using Chen.Helpers.LogHelpers;
using Chen.Helpers.UnityHelpers;
using EntityStates;
using EntityStates.EngiTurret.EngiTurretWeapon;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.CharacterAI;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("ChillDrone.Tests")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ChillDrone")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.1.4.0")]
[assembly: AssemblyInformationalVersion("2.1.4+44422714d29c364deecd704783c4fdff8a82034d")]
[assembly: AssemblyProduct("ChillDrone")]
[assembly: AssemblyTitle("ChillDrone")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.4.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Chen.ChillDrone
{
	[BepInPlugin("com.Chen.ChillDrone", "ChillDrone", "2.2.3")]
	[BepInDependency("com.bepis.r2api", "5.3.0")]
	[BepInDependency("com.Chen.ChensHelpers", "1.2.1")]
	[BepInDependency("com.Chen.ChensGradiusMod", "4.0.2")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class ModPlugin : BaseUnityPlugin
	{
		public const string ModVer = "2.2.3";

		public const string ModName = "ChillDrone";

		public const string ModGuid = "com.Chen.ChillDrone";

		internal static ConfigFile cfgFile;

		internal static Log Log;

		internal static List<DroneInfo> dronesList = new List<DroneInfo>();

		internal static AssetBundle assetBundle;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			Log = new Log(((BaseUnityPlugin)this).Logger);
			Log.Debug((object)"Initializing config file...");
			cfgFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "com.Chen.ChillDrone.cfg"), true);
			Log.Debug((object)"Loading asset bundle...");
			assetBundle = new AssetsManager(new BundleInfo("Chen.ChillDrone.chilldrone_assets", (BundleType)0)).Register();
			Extensions.ConvertShaders(assetBundle);
			Log.Debug((object)"Registering Chill Drone...");
			dronesList = DroneCatalog.Initialize("com.Chen.ChillDrone", cfgFile);
			DroneCatalog.ScopedSetupAll(dronesList);
		}

		internal static bool DebugCheck()
		{
			return false;
		}
	}
}
namespace Chen.ChillDrone.Drone
{
	internal class ChillDrone : Drone<ChillDrone>
	{
		private static readonly Lazy<InteractableSpawnCard> _iscBasis = LazyAddressable<InteractableSpawnCard>("RoR2/Base/Drones/iscBrokenDrone1.asset");

		private static readonly Lazy<SkillDef> _skillBasis = LazyAddressable<SkillDef>("RoR2/Base/Drones/Drone1BodyGun.asset");

		private static readonly Lazy<GameObject> _flameDroneMaster = LazyAddressable<GameObject>("RoR2/Base/Drones/FlameDroneMaster.prefab");

		private static readonly Lazy<InteractableSpawnCard> _missileDroneSpawnCard = LazyAddressable<InteractableSpawnCard>("RoR2/Base/Drones/iscBrokenMissileDrone.asset");

		private static readonly Lazy<GameObject> _flameDroneBody = LazyAddressable<GameObject>("RoR2/Base/Drones/FlameDroneBody.prefab");

		public static ModdedDamageType chillOnHit { get; private set; }

		public static BuffDef chillBuff { get; private set; }

		public static InteractableSpawnCard iSpawnCard { get; private set; }

		public float baseMaxHealth { get; private set; }

		public override bool canHaveOptions => true;

		private GameObject brokenObject { get; set; }

		private DirectorCardHolder iDirectorCardHolder { get; set; }

		private GameObject droneBody { get; set; }

		private GameObject droneMaster { get; set; }

		private static InteractableSpawnCard interactableSpawnCardBasis => _iscBasis.Value;

		private static InteractableSpawnCard missileDroneSpawnCard => _missileDroneSpawnCard.Value;

		private static SkillDef skillBasis => _skillBasis.Value;

		private static GameObject flameDroneMaster => _flameDroneMaster.Value;

		private static CharacterBody flameDroneBody
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)_flameDroneBody.Value))
				{
					return null;
				}
				return _flameDroneBody.Value.GetComponent<CharacterBody>();
			}
		}

		protected override GameObject DroneCharacterMasterObject => droneMaster;

		protected override void SetupConfig()
		{
			((Drone)this).spawnWeightWithMachinesArtifact = 0;
			((Drone)this).SetupConfig();
			baseMaxHealth = ((Drone)this).config.Bind<float>(((Drone)this).configCategory, "BaseMaxHealth", baseMaxHealth, "The max health of the drone at level 1. The health gained per level scales along with it. Set to 0 to use 90% of the vanilla Incinerator Drone's health.").Value;
		}

		protected override void SetupComponents()
		{
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Expected O, but got Unknown
			//IL_0498: Unknown result type (might be due to invalid IL or missing references)
			//IL_049a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0599: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0608: Unknown result type (might be due to invalid IL or missing references)
			//IL_060d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0618: Unknown result type (might be due to invalid IL or missing references)
			//IL_061f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0626: Unknown result type (might be due to invalid IL or missing references)
			//IL_0628: Unknown result type (might be due to invalid IL or missing references)
			//IL_062d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0636: Expected O, but got Unknown
			//IL_0637: Unknown result type (might be due to invalid IL or missing references)
			//IL_063c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0644: Unknown result type (might be due to invalid IL or missing references)
			//IL_0646: Unknown result type (might be due to invalid IL or missing references)
			//IL_064b: Unknown result type (might be due to invalid IL or missing references)
			//IL_064d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0657: Expected O, but got Unknown
			((Drone)this).SetupComponents();
			LanguageAPI.Add("CHILL_DRONE_NAME", "Chill Drone");
			LanguageAPI.Add("CHILL_DRONE_CONTEXT", "Repair Chill Drone");
			LanguageAPI.Add("CHILL_DRONE_INTERACTABLE_NAME", "Broken Chill Drone");
			LanguageAPI.Add("CHILL_DRONE_PICKUP", "Slows nearby enemies with chilling beams.");
			LanguageAPI.Add("CHILL_DRONE_DESCRIPTION", $"Fires beams at every enemy within <style=cIsUtility>{EmitSlow.detectionDistance}m</style> in front of it, " + "<style=cIsUtility>slowing</style> them by <style=cIsUtility>70%</style> while they are hit.");
			LanguageAPI.Add("CHILL_DRONE_SKILL_DESCRIPTION", $"Chilling Beams: Beam every nearby enemy for up to {EmitSlow.duration} seconds, <style=cIsUtility>slowing</style> them.");
			GameObject val = ((Drone)this).CreatePickupDisplay(ModPlugin.assetBundle.LoadAsset<GameObject>("Assets/GEMO/mdlChillDrone.prefab"));
			brokenObject = PrefabAPI.InstantiateClone(((SpawnCard)interactableSpawnCardBasis).prefab, ((Drone)this).name + "Broken", true);
			SummonMasterBehavior component = brokenObject.GetComponent<SummonMasterBehavior>();
			droneMaster = PrefabAPI.InstantiateClone(component.masterPrefab, ((Drone)this).name + "Master", true);
			ContentAddition.AddMaster(droneMaster);
			AISkillDriver[] components = droneMaster.GetComponents<AISkillDriver>();
			for (int i = 0; i < components.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)components[i]);
			}
			AISkillDriver[] array = Extensions.DeepCopyComponentsTo<AISkillDriver>(flameDroneMaster, droneMaster).ToArray();
			if (array.Length > 3)
			{
				array[1].maxDistance = EmitSlow.detectionDistance;
				array[2].maxDistance = array[1].maxDistance + EmitSlow.detectionDistance * 0.5f;
				array[3].minDistance = array[2].maxDistance;
			}
			else
			{
				ModPlugin.Log.Warning((object)(((Drone)this).name + ": The Incinerator Drone skill drivers changed. Attack ranges are left at their default values."));
			}
			Extensions.SetAllDriversToAimTowardsEnemies(array);
			CharacterMaster component2 = droneMaster.GetComponent<CharacterMaster>();
			droneBody = PrefabAPI.InstantiateClone(component2.bodyPrefab, ((Drone)this).name + "Body", true);
			ContentAddition.AddBody(droneBody);
			CharacterBody component3 = droneBody.GetComponent<CharacterBody>();
			component3.baseNameToken = "CHILL_DRONE_NAME";
			CharacterBody val2 = flameDroneBody;
			component3.baseMaxHealth = (Object.op_Implicit((Object)(object)val2) ? val2.baseMaxHealth : component3.baseMaxHealth) * 0.9f;
			component3.levelMaxHealth = (Object.op_Implicit((Object)(object)val2) ? val2.levelMaxHealth : component3.levelMaxHealth) * 0.9f;
			if (baseMaxHealth > 0f)
			{
				component3.levelMaxHealth *= baseMaxHealth / component3.baseMaxHealth;
				component3.baseMaxHealth = baseMaxHealth;
			}
			component3.baseRegen *= 3f;
			component3.baseDamage = 3f;
			component3.baseCrit = 0f;
			component3.baseArmor *= 1.3f;
			component3.baseMoveSpeed *= 0.7f;
			component3.levelRegen *= 3f;
			component3.levelDamage = 1f;
			component3.levelCrit = 0f;
			component3.levelArmor *= 1.3f;
			component3.levelMoveSpeed *= 0.7f;
			component3.portraitIcon = ModPlugin.assetBundle.LoadAsset<Texture>("Assets/GEMO/texChillDrone.png");
			GameObject val3 = ModPlugin.assetBundle.LoadAsset<GameObject>("Assets/GEMO/mdlChillDrone.prefab");
			Quaternion localRotation = val3.transform.localRotation;
			Extensions.ReplaceModel(droneBody, val3, false);
			val3.transform.localRotation = localRotation;
			Extensions.InitializeDroneModelComponents(val3, component3, 1.3f);
			((Component)val3.transform.Find("PropellerLEffect")).gameObject.AddComponent<RotateObject>().rotationSpeed = new Vector3(0f, 0f, 900f);
			((Component)val3.transform.Find("PropellerREffect")).gameObject.AddComponent<RotateObject>().rotationSpeed = new Vector3(0f, 0f, -900f);
			SkillLocator component4 = droneBody.GetComponent<SkillLocator>();
			bool flag = default(bool);
			ContentAddition.AddEntityState<EmitSlow>(ref flag);
			SkillDef val4 = Object.Instantiate<SkillDef>(skillBasis);
			val4.activationState = new SerializableEntityStateType(typeof(EmitSlow));
			val4.baseRechargeInterval = 4f;
			val4.beginSkillCooldownOnSkillEnd = true;
			val4.baseMaxStock = 1;
			val4.fullRestockOnAssign = false;
			ContentAddition.AddSkillDef(val4);
			SkillFamily val5 = Object.Instantiate<SkillFamily>(component4.primary.skillFamily);
			val5.variants = (Variant[])(object)new Variant[1];
			Variant[] variants = val5.variants;
			Variant val6 = new Variant
			{
				skillDef = val4,
				unlockableDef = null
			};
			((Variant)(ref val6)).viewableNode = new Node("", false, (Node)null);
			variants[0] = val6;
			Reflection.SetFieldValue<SkillFamily>((object)component4.primary, "_skillFamily", val5);
			ContentAddition.AddSkillFamily(val5);
			Extensions.GetOrAddComponent<CharacterDeathBehavior>((Component)(object)component3).deathState = new SerializableEntityStateType(typeof(DeathState));
			component2.bodyPrefab = droneBody;
			component.masterPrefab = droneMaster;
			PurchaseInteraction component5 = brokenObject.GetComponent<PurchaseInteraction>();
			component5.cost = 80;
			component5.Networkcost = component5.cost;
			component5.contextToken = "CHILL_DRONE_CONTEXT";
			component5.displayNameToken = "CHILL_DRONE_INTERACTABLE_NAME";
			brokenObject.GetComponent<GenericDisplayNameProvider>().displayToken = "CHILL_DRONE_NAME";
			GameObject val7 = ModPlugin.assetBundle.LoadAsset<GameObject>("Assets/GEMO/mdlChillDroneBroken.prefab");
			MeshRenderer componentInChildren = val7.GetComponentInChildren<MeshRenderer>();
			((Drone)this).ReplaceBrokenModel(brokenObject, val7, (Renderer)(object)componentInChildren, (GameObject[])(object)new GameObject[1] { ((Component)val7.transform.GetChild(0)).gameObject });
			Transform val8 = Drone.FindBrokenDamagePoint(val7);
			if (Object.op_Implicit((Object)(object)val8))
			{
				val8.localPosition = Vector3.zero;
				val8.localRotation = Quaternion.identity;
				val8.localScale = Vector3.one;
			}
			iSpawnCard = Object.Instantiate<InteractableSpawnCard>(interactableSpawnCardBasis);
			((Object)iSpawnCard).name = "iscBroken" + ((Drone)this).name;
			((SpawnCard)iSpawnCard).prefab = brokenObject;
			if (Object.op_Implicit((Object)(object)missileDroneSpawnCard))
			{
				((SpawnCard)iSpawnCard).directorCreditCost = ((SpawnCard)missileDroneSpawnCard).directorCreditCost;
			}
			DirectorCard card = new DirectorCard
			{
				spawnCard = (SpawnCard)(object)iSpawnCard,
				selectionWeight = 2,
				minimumStageCompletions = 0,
				spawnDistance = (MonsterSpawnDistance)1,
				preventOverhead = false
			};
			iDirectorCardHolder = new DirectorCardHolder
			{
				Card = card,
				MonsterCategory = (MonsterCategory)0,
				InteractableCategory = (InteractableCategory)5
			};
			((Drone)this).droneDef = ((Drone)this).CreateDroneDef(Drone.LoadVanillaDroneDef("RoR2/Base/Drones/MissileDrone.asset"), droneBody, brokenObject, iSpawnCard, "CHILL_DRONE", component3.portraitIcon, val, Drone.LoadVanillaDroneDef("RoR2/Base/Drones/Drone1.asset"));
		}

		protected override void SetupBehavior()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			((Drone)this).SetupBehavior();
			ItemBase<GradiusOption>.instance.SetToRotateOptions(((Object)droneMaster).name);
			ItemBase<GradiusOption>.instance.SetRotateOptionMultiplier(((Object)droneMaster).name, 1.2f);
			chillOnHit = DamageAPI.ReserveDamageType();
			chillBuff = ScriptableObject.CreateInstance<BuffDef>();
			chillBuff.canStack = false;
			chillBuff.isDebuff = true;
			((Object)chillBuff).name = "Chill Drone - Chilled";
			chillBuff.iconSprite = ModPlugin.assetBundle.LoadAsset<Sprite>("Assets/texBuffChill.png");
			ContentAddition.AddBuffDef(chillBuff);
			DirectorAPI.InteractableActions += DirectorAPI_InteractableActions;
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(ChillDrone_GetStatCoefficients);
			HealthComponent.TakeDamage += new hook_TakeDamage(HealthComponent_TakeDamage);
		}

		private void HealthComponent_TakeDamage(orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self, damageInfo);
			if (Object.op_Implicit((Object)(object)self.body) && DamageAPI.HasModdedDamageType(damageInfo, chillOnHit))
			{
				self.body.AddTimedBuff(chillBuff, 1f);
			}
		}

		private void ChillDrone_GetStatCoefficients(CharacterBody sender, StatHookEventArgs args)
		{
			if (sender.HasBuff(chillBuff))
			{
				args.moveSpeedMultAdd -= 0.7f;
				args.jumpPowerMultAdd -= 0.7f;
			}
		}

		private void DirectorAPI_InteractableActions(DccsPool arg0, StageInfo arg1)
		{
			if (Object.op_Implicit((Object)(object)arg0) && (((StageInfo)(ref arg1)).CheckStage((Stage)32, Array.Empty<string>()) || ((StageInfo)(ref arg1)).CheckStage((Stage)256, Array.Empty<string>())))
			{
				Helpers.ForEachPoolEntryInDccsPool(arg0, (Action<PoolEntry>)delegate(PoolEntry poolEntry)
				{
					DirectorAPI.AddCard(poolEntry.dccs, iDirectorCardHolder);
				});
			}
		}

		private static Lazy<T> LazyAddressable<T>(string key)
		{
			return new Lazy<T>(delegate
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				T val = Addressables.LoadAssetAsync<T>((object)key).WaitForCompletion();
				if (val == null)
				{
					ModPlugin.Log.Error((object)("Failed to load the addressable asset " + key + "."));
				}
				return val;
			});
		}

		internal static bool DebugCheck()
		{
			return false;
		}
	}
}
namespace Chen.ChillDrone.Drone.States
{
	internal class DeathState : DroneDeathState
	{
		protected override bool SpawnInteractable { get; set; } = ((Drone)Drone<ChillDrone>.instance).canBeRepurchased;

		protected override InteractableSpawnCard GetInteractableSpawnCard => ChillDrone.iSpawnCard;
	}
	internal class EmitSlow : BaseState
	{
		private static FireBeam _fireBeamInstance;

		public static readonly float detectionDistance = 20f;

		public static readonly float duration = 5f;

		private static readonly float angularDetection = 60f;

		private static readonly string muzzleString = "Muzzle";

		private static readonly float maxDistance = detectionDistance * 2f;

		private float stopwatch;

		private float fireTimer;

		private Transform modelTransform;

		private BullseyeSearch enemyFinder;

		private Ray aimRay;

		private List<HurtBox> results = new List<HurtBox>();

		private readonly List<GameObject> laserEffectInstances = new List<GameObject>();

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

		private Transform muzzleTransform;

		private static FireBeam fireBeamInstance
		{
			get
			{
				if (_fireBeamInstance == null)
				{
					EntityState obj = EntityStateCatalog.InstantiateState(typeof(FireBeam));
					_fireBeamInstance = (FireBeam)(object)((obj is FireBeam) ? obj : null);
				}
				return _fireBeamInstance;
			}
		}

		private static GameObject laserPrefab => fireBeamInstance.laserPrefab;

		private static string attackSoundString => fireBeamInstance.attackSoundString;

		private static float fireFrequency => fireBeamInstance.fireFrequency;

		private static GameObject effectPrefab => fireBeamInstance.effectPrefab;

		private static float minSpread => fireBeamInstance.minSpread;

		private static float maxSpread => fireBeamInstance.maxSpread;

		private static float force => fireBeamInstance.force;

		private static GameObject hitEffectPrefab => fireBeamInstance.hitEffectPrefab;

		private void InitializeEnemyFinder()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			enemyFinder = new BullseyeSearch
			{
				viewer = ((EntityState)this).characterBody,
				maxDistanceFilter = detectionDistance,
				maxAngleFilter = angularDetection,
				searchOrigin = ((Ray)(ref aimRay)).origin,
				searchDirection = ((Ray)(ref aimRay)).direction,
				filterByLoS = true,
				sortMode = (SortMode)3,
				teamMaskFilter = TeamMask.allButNeutral
			};
			if (Object.op_Implicit((Object)(object)((EntityState)this).teamComponent))
			{
				((TeamMask)(ref enemyFinder.teamMaskFilter)).RemoveTeam(((EntityState)this).teamComponent.teamIndex);
			}
			enemyFinder.RefreshCandidates();
			results = enemyFinder.GetResults().ToList();
		}

		private void FireBullet(Ray laserRay)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)effectPrefab))
			{
				EffectManager.SimpleMuzzleFlash(effectPrefab, ((EntityState)this).gameObject, muzzleString, false);
			}
			if (((EntityState)this).isAuthority)
			{
				BulletAttack val = new BulletAttack
				{
					owner = ((EntityState)this).gameObject,
					weapon = ((EntityState)this).gameObject,
					origin = ((Ray)(ref laserRay)).origin,
					aimVector = ((Ray)(ref laserRay)).direction,
					minSpread = minSpread,
					maxSpread = maxSpread,
					bulletCount = 1u,
					damage = base.damageStat,
					procCoefficient = 1f / fireFrequency,
					force = force,
					muzzleName = muzzleString,
					hitEffectPrefab = hitEffectPrefab,
					isCrit = Util.CheckRoll(base.critStat, ((EntityState)this).characterBody.master),
					HitEffectNormal = false,
					maxDistance = maxDistance,
					radius = 0f
				};
				DamageAPI.AddModdedDamageType(val, ChillDrone.chillOnHit);
				val.Fire();
			}
		}

		private void InitializeOptionDataStructure()
		{
			ItemBase<GradiusOption>.instance.FireForAllOptions(((EntityState)this).characterBody, (Action<GameObject, OptionBehavior, GameObject, Vector3>)delegate(GameObject option, OptionBehavior behavior, GameObject _t, Vector3 _d)
			{
				if (behavior.O.ContainsKey("laserEffectInstances"))
				{
					(behavior.O["laserEffectInstances"] as List<GameObject>).Clear();
				}
				else
				{
					behavior.O["laserEffectInstances"] = new List<GameObject>();
				}
				if (behavior.O.ContainsKey("laserEffectInstanceEndTransforms"))
				{
					(behavior.O["laserEffectInstanceEndTransforms"] as List<Transform>).Clear();
				}
				else
				{
					behavior.O["laserEffectInstanceEndTransforms"] = new List<Transform>();
				}
			});
		}

		private void OptionsFire(Action<GameObject, OptionBehavior, GameObject, Vector3, List<GameObject>, List<Transform>> action)
		{
			ItemBase<GradiusOption>.instance.FireForAllOptions(((EntityState)this).characterBody, (Action<GameObject, OptionBehavior, GameObject, Vector3>)delegate(GameObject option, OptionBehavior behavior, GameObject target, Vector3 direction)
			{
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				if (behavior.O.ContainsKey("laserEffectInstances") && behavior.O.ContainsKey("laserEffectInstanceEndTransforms"))
				{
					List<GameObject> arg = behavior.O["laserEffectInstances"] as List<GameObject>;
					List<Transform> arg2 = behavior.O["laserEffectInstanceEndTransforms"] as List<Transform>;
					action(option, behavior, target, direction, arg, arg2);
				}
			});
		}

		private void OptionFireBullet(Ray laserRay, GameObject option)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)effectPrefab))
			{
				Extensions.MuzzleEffect(option, effectPrefab, false);
			}
			if (((EntityState)this).isAuthority)
			{
				float damage = base.damageStat * ItemBase<GradiusOption>.instance.damageMultiplier;
				BulletAttack val = new BulletAttack
				{
					owner = ((EntityState)this).gameObject,
					weapon = option,
					origin = ((Ray)(ref laserRay)).origin,
					aimVector = ((Ray)(ref laserRay)).direction,
					minSpread = minSpread,
					maxSpread = maxSpread,
					bulletCount = 1u,
					damage = damage,
					procCoefficient = 1f / fireFrequency,
					force = force * ItemBase<GradiusOption>.instance.damageMultiplier,
					muzzleName = muzzleString,
					hitEffectPrefab = hitEffectPrefab,
					isCrit = Util.CheckRoll(base.critStat, ((EntityState)this).characterBody.master),
					HitEffectNormal = false,
					maxDistance = maxDistance,
					radius = 0f
				};
				DamageAPI.AddModdedDamageType(val, ChillDrone.chillOnHit);
				val.Fire();
			}
		}

		public override void OnEnter()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			((BaseState)this).OnEnter();
			InitializeOptionDataStructure();
			Util.PlaySound(attackSoundString, ((EntityState)this).gameObject);
			aimRay = ((BaseState)this).GetAimRay();
			InitializeEnemyFinder();
			if (!Object.op_Implicit((Object)(object)laserPrefab))
			{
				return;
			}
			modelTransform = ((EntityState)this).GetModelTransform();
			if (!Object.op_Implicit((Object)(object)modelTransform))
			{
				return;
			}
			muzzleTransform = modelTransform.Find(muzzleString);
			if (!Object.op_Implicit((Object)(object)muzzleTransform))
			{
				return;
			}
			for (int i = 0; i < results.Count; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(laserPrefab, muzzleTransform.position, muzzleTransform.rotation);
				val.transform.parent = muzzleTransform;
				laserEffectInstances.Add(val);
				laserEffectInstanceEndTransforms.Add(val.GetComponent<ChildLocator>().FindChild("LaserEnd"));
				OptionsFire(delegate(GameObject option, OptionBehavior _b, GameObject _t, Vector3 _d, List<GameObject> laserEffects, List<Transform> laserEndTransforms)
				{
					GameObject val2 = Object.Instantiate<GameObject>(laserPrefab, option.transform);
					val2.transform.parent = option.transform;
					laserEffects.Add(val2);
					laserEndTransforms.Add(val2.GetComponent<ChildLocator>().FindChild("LaserEnd"));
				});
			}
		}

		public override void FixedUpdate()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			((EntityState)this).FixedUpdate();
			stopwatch += Time.fixedDeltaTime;
			fireTimer += Time.fixedDeltaTime;
			float num = fireFrequency * ((EntityState)this).characterBody.attackSpeed;
			float num2 = 1f / num;
			Vector3 val = (Object.op_Implicit((Object)(object)muzzleTransform) ? muzzleTransform.position : ((Ray)(ref aimRay)).origin);
			Ray val4 = default(Ray);
			RaycastHit val5 = default(RaycastHit);
			for (int i = 0; i < results.Count; i++)
			{
				HurtBox hurtBox = results[i];
				GameObject val2 = laserEffectInstances[i];
				if (Object.op_Implicit((Object)(object)hurtBox) && Object.op_Implicit((Object)(object)hurtBox.healthComponent) && hurtBox.healthComponent.alive)
				{
					Transform val3 = laserEffectInstanceEndTransforms[i];
					Vector3 position = ((Component)hurtBox).transform.position;
					((Ray)(ref val4))..ctor(val, position - val);
					if (fireTimer > num2)
					{
						FireBullet(val4);
					}
					if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val3))
					{
						Vector3 point = ((Ray)(ref val4)).GetPoint(maxDistance);
						if (Util.CharacterRaycast(((EntityState)this).gameObject, val4, ref val5, maxDistance, LayerMask.op_Implicit(LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.world)).mask) | LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.entityPrecise)).mask)), (QueryTriggerInteraction)0))
						{
							point = ((RaycastHit)(ref val5)).point;
						}
						val3.position = point;
					}
					OptionsFire(delegate(GameObject option, OptionBehavior _b, GameObject _t, Vector3 _d, List<GameObject> laserEffects, List<Transform> laserEndTransforms)
					{
						//IL_0019: Unknown result type (might be due to invalid IL or missing references)
						//IL_001e: Unknown result type (might be due to invalid IL or missing references)
						//IL_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_0032: 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_0034: Unknown result type (might be due to invalid IL or missing references)
						//IL_0035: Unknown result type (might be due to invalid IL or missing references)
						//IL_0067: Unknown result type (might be due to invalid IL or missing references)
						//IL_0096: Unknown result type (might be due to invalid IL or missing references)
						//IL_009b: Unknown result type (might be due to invalid IL or missing references)
						//IL_009d: Unknown result type (might be due to invalid IL or missing references)
						//IL_009e: Unknown result type (might be due to invalid IL or missing references)
						//IL_009f: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
						//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
						//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
						//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
						//IL_00da: Unknown result type (might be due to invalid IL or missing references)
						Transform val6 = laserEndTransforms[i];
						Vector3 position2 = option.transform.position;
						Vector3 position3 = ((Component)hurtBox).transform.position;
						Ray laserRay = default(Ray);
						((Ray)(ref laserRay))..ctor(position2, position3 - position2);
						if (fireTimer > num2)
						{
							OptionFireBullet(laserRay, option);
						}
						if (Object.op_Implicit((Object)(object)laserEffects[i]) && Object.op_Implicit((Object)(object)val6))
						{
							Vector3 point2 = ((Ray)(ref laserRay)).GetPoint(maxDistance);
							RaycastHit val7 = default(RaycastHit);
							if (Physics.Raycast(position2, position3 - position2, ref val7, maxDistance, LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.world)).mask) | LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.entityPrecise)).mask), (QueryTriggerInteraction)0))
							{
								point2 = ((RaycastHit)(ref val7)).point;
							}
							val6.position = point2;
						}
					});
				}
				else if (Object.op_Implicit((Object)(object)val2))
				{
					OptionsFire(delegate(GameObject option, OptionBehavior _b, GameObject _t, Vector3 _d, List<GameObject> laserEffects, List<Transform> laserEndTransforms)
					{
						EntityState.Destroy((Object)(object)laserEffects[i]);
						laserEffects.RemoveAt(i);
						laserEndTransforms.RemoveAt(i);
					});
					EntityState.Destroy((Object)(object)val2);
					results.RemoveAt(i);
					laserEffectInstances.RemoveAt(i);
					laserEffectInstanceEndTransforms.RemoveAt(i);
					int num3 = i;
					i = num3 - 1;
				}
			}
			if (fireTimer > num2)
			{
				fireTimer = 0f;
			}
			if (((EntityState)this).isAuthority && (stopwatch >= duration || results.Count == 0))
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
		}

		public override void OnExit()
		{
			foreach (GameObject laserEffectInstance in laserEffectInstances)
			{
				if (Object.op_Implicit((Object)(object)laserEffectInstance))
				{
					EntityState.Destroy((Object)(object)laserEffectInstance);
				}
			}
			laserEffectInstances.Clear();
			laserEffectInstanceEndTransforms.Clear();
			OptionsFire(delegate(GameObject _o, OptionBehavior _b, GameObject _t, Vector3 _d, List<GameObject> laserEffects, List<Transform> laserEndTransforms)
			{
				foreach (GameObject laserEffect in laserEffects)
				{
					if (Object.op_Implicit((Object)(object)laserEffect))
					{
						EntityState.Destroy((Object)(object)laserEffect);
					}
				}
				laserEffects.Clear();
				laserEndTransforms.Clear();
			});
			results.Clear();
			((EntityState)this).OnExit();
		}
	}
}