Decompiled source of TricornEliteEquipment v1.0.3

TricornEliteEquipment.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Chinchi")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allow the Tricorn to target Elite monsters.")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+ccf3e1c4068fd0ca26b54171e7dfc0829264cf17")]
[assembly: AssemblyProduct("TricornEliteEquipment")]
[assembly: AssemblyTitle("TricornEliteEquipment")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/schinchi/TricornEliteEquipment")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TricornEliteEquipment
{
	[BepInPlugin("Chinchi.TricornEliteEquipment", "TricornEliteEquipment", "1.0.3")]
	public class TricornEliteEquipment : BaseUnityPlugin
	{
		public const string PluginGUID = "Chinchi.TricornEliteEquipment";

		public const string PluginAuthor = "Chinchi";

		public const string PluginName = "TricornEliteEquipment";

		public const string PluginVersion = "1.0.3";

		public void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			EquipmentSlot.UpdateTargets += new Manipulator(CheckForBossOrElite);
			EquipmentSlot.FireBossHunter += new Manipulator(KillBossOrElite);
		}

		private void KillBossOrElite(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_01a8: 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)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			int num4 = default(int);
			if (!val.TryGotoNext(new Func<Instruction, bool>[5]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num4),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<DeathRewards>(x, "bossDropTable"),
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<EquipmentSlot>(x, "rng"),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<PickupDropTable>(x, "GeneratePickup")
			}))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to patch EquipmentSlot.FireBossHunter #1");
				return;
			}
			Instruction next = val.Next;
			int num3 = default(int);
			int num2 = default(int);
			float num = default(float);
			if (!val.TryGotoNext(new Func<Instruction, bool>[5]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num3),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num2),
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, ref num),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Vector3>(x, "op_Multiply"),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<PickupDropletController>(x, "CreatePickupDroplet")
			}))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to patch EquipmentSlot.FireBossHunter #2");
				return;
			}
			_ = val.Next;
			val.Emit(OpCodes.Br_S, val.Next);
			val.Emit(OpCodes.Pop);
			Instruction prev = val.Prev;
			val.Emit(OpCodes.Ldloc_1);
			val.EmitDelegate<Func<DeathRewards, UniquePickup>>((Func<DeathRewards, UniquePickup>)((DeathRewards deathRewards) => new UniquePickup(PickupCatalog.FindPickupIndex(deathRewards.characterBody.inventory.currentEquipmentIndex))));
			val.Goto(next, (MoveType)0, false);
			val.Index += 2;
			val.Emit(OpCodes.Dup);
			val.Emit(OpCodes.Brfalse, prev);
		}

		private void CheckForBossOrElite(ILContext il)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			int hurtBoxVarIndex = -1;
			if (!val.TryGotoNext(new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref hurtBoxVarIndex),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<HurtBox>(x, "healthComponent"),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Object>(x, "op_Implicit")
			}))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to patch EquipmentSlot.UpdateTargets #1");
				return;
			}
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<DeathRewards>(x, "bossDropTable"),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Object>(x, "op_Implicit")
			}))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to patch EquipmentSlot.UpdateTargets #2");
				return;
			}
			val.Emit(OpCodes.Ldloc, hurtBoxVarIndex);
			val.EmitDelegate<Func<bool, HurtBox, bool>>((Func<bool, HurtBox, bool>)delegate(bool hasBossDropTable, HurtBox hurtBox)
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				if (hasBossDropTable)
				{
					return true;
				}
				Inventory inventory = hurtBox.healthComponent.body.inventory;
				if (!Object.op_Implicit((Object)(object)inventory))
				{
					return false;
				}
				EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(inventory.currentEquipmentIndex);
				return Object.op_Implicit((Object)(object)equipmentDef) && equipmentDef.dropOnDeathChance > 0f;
			});
		}
	}
}