Decompiled source of ArtificerM1Reload v1.1.1

ArtificerM1Reload.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using EntityStates;
using EntityStates.Mage.Weapon;
using On.EntityStates.Mage.Weapon;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ArtificerM1Reload")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6d2af6ecc79eed4d572c9f8acb28bbe695e327c9")]
[assembly: AssemblyProduct("ArtificerM1Reload")]
[assembly: AssemblyTitle("ArtificerM1Reload")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace R2API.Utils
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class ManualNetworkRegistrationAttribute : Attribute
	{
	}
}
namespace ArtificerM1Reload
{
	public class MageStockController : MonoBehaviour
	{
		public class SkillInfo
		{
			public GameObject reloadEffectPrefab;

			public float baseReloadDuration;

			public int rechargeStock;

			public SkillInfo()
			{
				reloadEffectPrefab = fireMuzzleflashEffectPrefab;
				baseReloadDuration = defaultReloadTime;
				rechargeStock = 1;
			}

			public SkillInfo(GameObject reloadEffectPrefab, float baseCooldown, int rechargeStock)
			{
				this.reloadEffectPrefab = reloadEffectPrefab;
				baseReloadDuration = baseCooldown;
				this.rechargeStock = rechargeStock;
			}
		}

		public static float graceDuration = 0.4f;

		public static float defaultReloadTime = 1f;

		private CharacterBody body;

		private SkillLocator skills;

		private float reloadStopwatch;

		private float delayStopwatch;

		private bool rightMuzzle;

		public static GameObject fireMuzzleflashEffectPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Mage/MuzzleflashMageFire.prefab").WaitForCompletion();

		public static GameObject lightningMuzzleflashEffectPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Mage/MuzzleflashMageLightning.prefab").WaitForCompletion();

		public static GameObject iceMuzzleflashEffectPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Junk/Mage/MuzzleflashMageIce.prefab").WaitForCompletion();

		public static Dictionary<Type, SkillInfo> StatePairs = new Dictionary<Type, SkillInfo>();

		private void Awake()
		{
			body = ((Component)this).GetComponent<CharacterBody>();
			skills = ((Component)this).GetComponent<SkillLocator>();
			reloadStopwatch = 0f;
			delayStopwatch = 0f;
			rightMuzzle = true;
		}

		private void FixedUpdate()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)skills).hasAuthority)
			{
				return;
			}
			if (skills.primary.stock < skills.primary.maxStock)
			{
				Dictionary<Type, SkillInfo> statePairs = StatePairs;
				SerializableEntityStateType activationState = skills.primary.activationState;
				if (statePairs.ContainsKey(((SerializableEntityStateType)(ref activationState)).stateType))
				{
					if (skills.primary.stock <= 0)
					{
						delayStopwatch = 0f;
					}
					if (delayStopwatch > 0f)
					{
						delayStopwatch -= Time.fixedDeltaTime;
						return;
					}
					reloadStopwatch -= Time.fixedDeltaTime;
					if (reloadStopwatch <= 0f)
					{
						reloadStopwatch += GetReloadDuration() / body.attackSpeed;
						GenericSkill primary = skills.primary;
						primary.stock += GetRechargeStock();
						skills.primary.rechargeStopwatch = 0f;
						Util.PlaySound("Play_railgunner_m2_reload_basic", ((Component)this).gameObject);
						ShowReloadVFX();
						if (skills.primary.stock > skills.primary.maxStock)
						{
							skills.primary.stock = skills.primary.maxStock;
						}
					}
					return;
				}
			}
			reloadStopwatch = GetReloadDuration() / body.attackSpeed;
		}

		public void FireSkill(float duration)
		{
			delayStopwatch = graceDuration;
			reloadStopwatch = GetReloadDuration() / body.attackSpeed;
		}

		private void ShowReloadVFX()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			SkillInfo value = null;
			Dictionary<Type, SkillInfo> statePairs = StatePairs;
			SerializableEntityStateType activationState = skills.primary.activationState;
			statePairs.TryGetValue(((SerializableEntityStateType)(ref activationState)).stateType, out value);
			if (value != null && (Object)(object)value.reloadEffectPrefab != (Object)null)
			{
				EffectManager.SimpleMuzzleFlash(value.reloadEffectPrefab, ((Component)this).gameObject, rightMuzzle ? "MuzzleRight" : "MuzzleLeft", true);
			}
			rightMuzzle = !rightMuzzle;
		}

		private float GetReloadDuration()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			SkillInfo value = null;
			Dictionary<Type, SkillInfo> statePairs = StatePairs;
			SerializableEntityStateType activationState = skills.primary.activationState;
			statePairs.TryGetValue(((SerializableEntityStateType)(ref activationState)).stateType, out value);
			return value?.baseReloadDuration ?? defaultReloadTime;
		}

		private int GetRechargeStock()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			SkillInfo value = null;
			Dictionary<Type, SkillInfo> statePairs = StatePairs;
			SerializableEntityStateType activationState = skills.primary.activationState;
			statePairs.TryGetValue(((SerializableEntityStateType)(ref activationState)).stateType, out value);
			return value?.rechargeStock ?? 1;
		}
	}
	[BepInPlugin("com.Moffein.ArtificerM1Reload", "ArtificerM1Reload", "1.1.1")]
	public class ArtificerM1Reload : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_OnEnter <>9__0_0;

			internal void <Awake>b__0_0(orig_OnEnter orig, FireFireBolt self)
			{
				orig.Invoke(self);
				MageStockController component = ((EntityState)self).gameObject.GetComponent<MageStockController>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.FireSkill(self.duration);
				}
			}
		}

		public void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0030: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0069: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			MageStockController.graceDuration = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Stats", "Grace Duration"), 0.4f, new ConfigDescription("Time after firing before the reload starts. Ignored when out of stocks.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			MageStockController.defaultReloadTime = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Stats", "Reload Time"), 1f, new ConfigDescription("Time it takes to reload a shot. Modded skills may have a different value from this.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			GameObject val = LegacyResourcesAPI.Load<GameObject>("Prefabs/CharacterBodies/MageBody");
			SkillDef val2 = Addressables.LoadAssetAsync<SkillDef>((object)"RoR2/Base/Mage/MageBodyFireFirebolt.asset").WaitForCompletion();
			SkillDef val3 = Addressables.LoadAssetAsync<SkillDef>((object)"RoR2/Base/Mage/MageBodyFireLightningBolt.asset").WaitForCompletion();
			MageStockController.SkillInfo value = new MageStockController.SkillInfo(MageStockController.fireMuzzleflashEffectPrefab, MageStockController.defaultReloadTime, 1);
			MageStockController.SkillInfo value2 = new MageStockController.SkillInfo(MageStockController.lightningMuzzleflashEffectPrefab, MageStockController.defaultReloadTime, 1);
			MageStockController.StatePairs.Add(typeof(FireFireBolt), value);
			MageStockController.StatePairs.Add(typeof(FireLightningBolt), value2);
			val.AddComponent<MageStockController>();
			val2.rechargeStock = 0;
			val3.rechargeStock = 0;
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				hook_OnEnter val4 = delegate(orig_OnEnter orig, FireFireBolt self)
				{
					orig.Invoke(self);
					MageStockController component = ((EntityState)self).gameObject.GetComponent<MageStockController>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.FireSkill(self.duration);
					}
				};
				<>c.<>9__0_0 = val4;
				obj = (object)val4;
			}
			FireFireBolt.OnEnter += (hook_OnEnter)obj;
		}
	}
}