Decompiled source of UncappedAttackSpeed v1.0.0

UncapAttackSpeed.dll

Decompiled 6 months ago
using System;
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.Logging;
using EntityStates;
using EntityStates.Commando.CommandoWeapon;
using HG.Reflection;
using IL.EntityStates.Commando.CommandoWeapon;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
internal static class log
{
	private static ManualLogSource logger;

	internal static void start(ManualLogSource logSource)
	{
		logger = logSource;
	}

	internal static void start(string name)
	{
		logger = Logger.CreateLogSource(name);
	}

	internal static void info(object data)
	{
		logger.LogInfo(data);
	}

	internal static void message(object data)
	{
		logger.LogMessage(data);
	}

	internal static void warning(object data)
	{
		logger.LogWarning(data);
	}

	internal static void error(object data)
	{
		logger.LogError(data);
	}

	internal static void fatal(object data)
	{
		logger.LogFatal(data);
	}
}
namespace UncapAttackSpeed;

[BepInPlugin("dolso.uncapattackspeed", "UncapAttackSpeed", "1.0.0")]
internal class Main : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		log.start(((BaseUnityPlugin)this).Logger);
		FirePistol2.FixedUpdate += new Manipulator(IL_FirePistol2_FixedUpdate);
		EntityStateConfiguration val = Addressables.LoadAssetAsync<EntityStateConfiguration>((object)"RoR2/Base/Commando/EntityStates.Commando.CommandoWeapon.FirePistol2.asset").WaitForCompletion();
		int num = 5;
		if (val.serializedFieldsCollection.serializedFields[num].fieldName != "baseDuration")
		{
			log.error("Incorrect field name, retrying");
			for (int i = 0; i < val.serializedFieldsCollection.serializedFields.Length; i++)
			{
				log.info(val.serializedFieldsCollection.serializedFields[i].fieldName);
				if (val.serializedFieldsCollection.serializedFields[i].fieldName == "baseDuration")
				{
					log.message("found field at index = " + i);
					num = i;
					break;
				}
			}
		}
		val.serializedFieldsCollection.serializedFields[num].fieldValue.stringValue = "0.166";
	}

	private static void IL_FirePistol2_FixedUpdate(ILContext il)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_00b2: 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)
		ILCursor val = new ILCursor(il);
		int num3 = default(int);
		if (!val.TryGotoNext(new Func<Instruction, bool>[4]
		{
			(Instruction a) => ILPatternMatchingExt.MatchLdarg(a, 0),
			(Instruction a) => ILPatternMatchingExt.MatchCallOrCallvirt<BaseSkillState>(a, "get_activatorSkillSlot"),
			(Instruction a) => ILPatternMatchingExt.MatchCallOrCallvirt<GenericSkill>(a, "get_stock"),
			(Instruction a) => ILPatternMatchingExt.MatchLdcI4(a, ref num3)
		}))
		{
			log.error("Failed: Commando FixedUpdate IL Hook");
			return;
		}
		val.Emit(OpCodes.Ldarg_0);
		val.EmitDelegate<Action<FirePistol2>>((Action<FirePistol2>)delegate(FirePistol2 self)
		{
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			if (!((EntityState)self).inputBank.skill1.down)
			{
				((EntityState)self).outer.SetNextStateToMain();
			}
			else
			{
				float duration = self.duration;
				for (float num = Mathf.Min(((EntityState)self).fixedAge - duration, duration * 3f); num > 0f; num -= duration)
				{
					float num2 = ((num >= self.duration) ? 1f : (num % duration / duration));
					if (num2 >= Random.Range(0f, 1f))
					{
						self.pistol++;
						if (self.pistol >= 2)
						{
							self.pistol = 0;
						}
						if (self.pistol % 2 == 0)
						{
							((EntityState)self).PlayAnimation("Gesture Additive, Left", "FirePistol, Left");
							self.FireBullet("MuzzleLeft");
						}
						else
						{
							((EntityState)self).PlayAnimation("Gesture Additive, Right", "FirePistol, Right");
							self.FireBullet("MuzzleRight");
						}
					}
				}
				FirePistol2 val2 = new FirePistol2();
				val2.pistol = ((self.pistol != 1) ? 1 : 0);
				((EntityState)self).outer.SetNextState((EntityState)(object)val2);
				((EntityState)self).skillLocator.primary.OnExecute();
			}
		});
		val.Emit(OpCodes.Ret);
	}
}