Decompiled source of SweepingBarrage v1.2.1

SweepingBarrage.dll

Decompiled 2 months 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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using EntityStates;
using EntityStates.FORCED_REASSEMBLY.Commando;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SweepingBarrage")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SweepingBarrage")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e5a8b1e1-b02a-432c-b8a9-670c39c45614")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SweepBarrage
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.Forced_Reassembly.SweepingBarrage", "Sweeping Barrage", "1.0.0")]
	public class SweepBarragePlugin : BaseUnityPlugin
	{
		public static SkillDef SweepBarrageSkill;

		public static AssetBundle mainAssetBundle;

		[Obsolete]
		private void Awake()
		{
			//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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SweepingBarrage.sweepingbarragebundle"))
			{
				mainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
			SkillDef val = ScriptableObject.CreateInstance<SkillDef>();
			val.activationState = new SerializableEntityStateType(typeof(FireSweepBarrage));
			val.activationStateMachineName = "Weapon";
			val.baseMaxStock = 1;
			val.baseRechargeInterval = 7f;
			val.beginSkillCooldownOnSkillEnd = true;
			val.canceledFromSprinting = false;
			val.cancelSprintingOnActivation = true;
			val.fullRestockOnAssign = true;
			val.interruptPriority = (InterruptPriority)1;
			val.isCombatSkill = true;
			val.mustKeyPress = false;
			val.rechargeStock = 1;
			val.requiredStock = 1;
			val.stockToConsume = 1;
			val.icon = mainAssetBundle.LoadAsset<Sprite>("SweepBarrageIconGoodVersion");
			val.skillDescriptionToken = "Automatically fire at all enemies in front of you for <style=cIsDamage>380% damage</style> damage per shot.";
			val.skillName = "COMMANDO_SPECIAL_SWEEPBARRAGE_NAME";
			val.skillNameToken = "Sweeping Barrage";
			((Object)val).name = val.skillName;
			SweepBarrageSkill = val;
			LanguageAPI.Add("COMMANDO_SPECIAL_SWEEPBARRAGE_NAME", "Sweep Barrage");
			ContentAddition.AddSkillDef(val);
			GameObject val2 = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Commando/CommandoBody.prefab").WaitForCompletion();
			SkillLocator component = val2.GetComponent<SkillLocator>();
			SkillFamily skillFamily = component.special.skillFamily;
			Array.Resize(ref skillFamily.variants, skillFamily.variants.Length + 1);
			Variant[] variants = skillFamily.variants;
			int num = skillFamily.variants.Length - 1;
			Variant val3 = new Variant
			{
				skillDef = val,
				unlockableName = ""
			};
			((Variant)(ref val3)).viewableNode = new Node(val.skillNameToken, false, (Node)null);
			variants[num] = val3;
			bool flag = default(bool);
			ContentAddition.AddEntityState<FireSweepBarrage>(ref flag);
		}

		public static void DumpEntityStateConfig(EntityStateConfiguration esc)
		{
			for (int i = 0; i < esc.serializedFieldsCollection.serializedFields.Length; i++)
			{
				if (Object.op_Implicit(esc.serializedFieldsCollection.serializedFields[i].fieldValue.objectValue))
				{
					Debug.Log((object)(esc.serializedFieldsCollection.serializedFields[i].fieldName + " - " + (object)esc.serializedFieldsCollection.serializedFields[i].fieldValue.objectValue));
				}
				else
				{
					Debug.Log((object)(esc.serializedFieldsCollection.serializedFields[i].fieldName + " - " + esc.serializedFieldsCollection.serializedFields[i].fieldValue.stringValue));
				}
			}
		}
	}
}
namespace EntityStates.FORCED_REASSEMBLY.Commando
{
	public class FireSweepBarrage : BaseState
	{
		public static string enterSound;

		public static string muzzle = "MuzzleRight";

		public static string fireSoundString = "Play_commando_M1";

		public static GameObject muzzleEffectPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Common/VFX/MuzzleflashBarrage.prefab").WaitForCompletion();

		public static GameObject tracerEffectPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Toolbot/TracerToolbotRebar.prefab").WaitForCompletion();

		public static float baseTotalDuration = 1f;

		public static float baseFiringDuration = 0.6f;

		public static float fieldOfView = 120f;

		public static float maxDistance = 120f;

		public static float damageCoefficient = 3.8f;

		public static float procCoefficient = 0.7f;

		public static float force = 300f;

		public static int minimumFireCount = 3;

		public static GameObject impactEffectPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Common/VFX/OmniImpactVFX.prefab").WaitForCompletion();

		private float totalDuration;

		private float firingDuration;

		private int totalBulletsToFire;

		private int totalBulletsFired;

		private int targetHurtboxIndex;

		private float timeBetweenBullets;

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

		private float fireTimer;

		private ChildLocator childLocator;

		private int muzzleIndex;

		private Transform muzzleTransform;

		public override void OnEnter()
		{
			//IL_0091: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			((BaseState)this).OnEnter();
			totalDuration = baseTotalDuration / base.attackSpeedStat;
			firingDuration = baseFiringDuration / base.attackSpeedStat;
			((EntityState)this).characterBody.SetAimTimer(3f);
			((EntityState)this).PlayAnimation("Gesture, Additive", "FireBarrage", "FireBarrage.playbackRate", totalDuration, 0f);
			((EntityState)this).PlayAnimation("Gesture, Override", "FireBarrage", "FireBarrage.playbackRate", totalDuration, 0f);
			Util.PlaySound(enterSound, ((EntityState)this).gameObject);
			Ray aimRay = ((BaseState)this).GetAimRay();
			BullseyeSearch val = new BullseyeSearch();
			val.teamMaskFilter = TeamMask.GetEnemyTeams(((BaseState)this).GetTeam());
			val.maxAngleFilter = fieldOfView * 0.5f;
			val.maxDistanceFilter = maxDistance;
			val.searchOrigin = ((Ray)(ref aimRay)).origin;
			val.searchDirection = ((Ray)(ref aimRay)).direction;
			val.sortMode = (SortMode)3;
			val.filterByLoS = true;
			val.RefreshCandidates();
			targetHurtboxes = val.GetResults().Where((Func<HurtBox, bool>)Util.IsValid).Distinct((IEqualityComparer<HurtBox>?)(object)default(EntityEqualityComparer))
				.ToList();
			totalBulletsToFire = Mathf.Max(targetHurtboxes.Count, minimumFireCount);
			timeBetweenBullets = firingDuration / (float)totalBulletsToFire;
			childLocator = ((Component)((EntityState)this).GetModelTransform()).GetComponent<ChildLocator>();
			muzzleIndex = childLocator.FindChildIndex(muzzle);
			muzzleTransform = childLocator.FindChild(muzzleIndex);
		}

		private void Fire()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_0146: 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_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_015f: 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_016c: 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_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Expected O, but got Unknown
			if (totalBulletsFired >= totalBulletsToFire)
			{
				return;
			}
			if (!string.IsNullOrEmpty(muzzle))
			{
				EffectManager.SimpleMuzzleFlash(muzzleEffectPrefab, ((EntityState)this).gameObject, muzzle, false);
			}
			Util.PlaySound(fireSoundString, ((EntityState)this).gameObject);
			((EntityState)this).PlayAnimation("Gesture Additive, Right", "FirePistol, Right");
			if (NetworkServer.active && targetHurtboxes.Count > 0)
			{
				DamageInfo val = new DamageInfo();
				val.damage = base.damageStat * damageCoefficient;
				val.attacker = ((EntityState)this).gameObject;
				val.procCoefficient = procCoefficient;
				val.crit = Util.CheckRoll(base.critStat, ((EntityState)this).characterBody.master);
				if (targetHurtboxIndex >= targetHurtboxes.Count)
				{
					targetHurtboxIndex = 0;
				}
				HurtBox val2 = targetHurtboxes[targetHurtboxIndex];
				if (Object.op_Implicit((Object)(object)val2))
				{
					HealthComponent healthComponent = val2.healthComponent;
					if (Object.op_Implicit((Object)(object)healthComponent))
					{
						targetHurtboxIndex++;
						Vector3 val3 = ((Component)val2).transform.position - ((EntityState)this).characterBody.corePosition;
						Vector3 normalized = ((Vector3)(ref val3)).normalized;
						val.force = force * normalized;
						val.position = ((Component)val2).transform.position;
						EffectManager.SimpleImpactEffect(impactEffectPrefab, ((Component)val2).transform.position, normalized, true);
						healthComponent.TakeDamage(val);
						GlobalEventManager.instance.OnHitEnemy(val, ((Component)healthComponent).gameObject);
					}
					if (Object.op_Implicit((Object)(object)tracerEffectPrefab) && Object.op_Implicit((Object)(object)childLocator))
					{
						int num = childLocator.FindChildIndex(muzzle);
						childLocator.FindChild(num);
						EffectData val4 = new EffectData
						{
							origin = ((Component)val2).transform.position,
							start = muzzleTransform.position
						};
						val4.SetChildLocatorTransformReference(((EntityState)this).gameObject, num);
						EffectManager.SpawnEffect(tracerEffectPrefab, val4, true);
					}
				}
			}
			totalBulletsFired++;
		}

		public override void FixedUpdate()
		{
			((EntityState)this).FixedUpdate();
			fireTimer -= Time.fixedDeltaTime;
			if (fireTimer <= 0f)
			{
				Fire();
				fireTimer += timeBetweenBullets;
			}
			if (((EntityState)this).isAuthority && ((EntityState)this).fixedAge >= totalDuration)
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
		}

		public override InterruptPriority GetMinimumInterruptPriority()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return (InterruptPriority)2;
		}

		public override void OnExit()
		{
			int num = totalBulletsToFire - totalBulletsFired;
			for (int i = 0; i < num; i++)
			{
				Fire();
			}
			((EntityState)this).OnExit();
		}
	}
}