Decompiled source of TricornEliteEquipment v1.0.2

TricornEliteEquipment.dll

Decompiled 9 months 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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("Chinchi")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allow the Tricorn to target Elite monsters.")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+a9823b3430bb96b72032093c674fd16e406f757b")]
[assembly: AssemblyProduct("TricornEliteEquipment")]
[assembly: AssemblyTitle("TricornEliteEquipment")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/schinchi/TricornEliteEquipment")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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("GChinchi.TricornEliteEquipment", "TricornEliteEquipment", "1.0.2")]
	public class TricornEliteEquipment : BaseUnityPlugin
	{
		public const string PluginGUID = "GChinchi.TricornEliteEquipment";

		public const string PluginAuthor = "GChinchi";

		public const string PluginName = "TricornEliteEquipment";

		public const string PluginVersion = "1.0.2";

		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(EquipmentSlot_UpdateTargets);
			EquipmentSlot.FireBossHunter += new Manipulator(EquipmentSlot_FireBossHunter);
		}

		private void EquipmentSlot_FireBossHunter(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (!val.TryGotoNext(new Func<Instruction, bool>[5]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 2),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 3),
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 15f),
				(Instruction x) => ILPatternMatchingExt.MatchCall<Vector3>(x, "op_Multiply"),
				(Instruction x) => ILPatternMatchingExt.MatchCall<PickupDropletController>(x, "CreatePickupDroplet")
			}))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to patch EquipmentSlot.FireBossHunter #1");
				return;
			}
			val.Emit(OpCodes.Br_S, val.Next);
			val.Emit(OpCodes.Pop);
			Instruction prev = val.Prev;
			val.Emit(OpCodes.Ldloc_1);
			val.EmitDelegate<Func<DeathRewards, PickupIndex>>((Func<DeathRewards, PickupIndex>)((DeathRewards deathRewards) => PickupCatalog.FindPickupIndex(deathRewards.characterBody.inventory.currentEquipmentIndex)));
			if (!val.TryGotoPrev((MoveType)0, new Func<Instruction, bool>[5]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 1),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<DeathRewards>(x, "bossDropTable"),
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<EquipmentSlot>(x, "rng"),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<PickupDropTable>(x, "GenerateDrop")
			}))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to patch EquipmentSlot.FireBossHunter #2");
				return;
			}
			val.Index += 2;
			val.Emit(OpCodes.Dup);
			val.Emit(OpCodes.Brfalse, prev);
		}

		private void EquipmentSlot_UpdateTargets(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (!val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<DeathRewards>(x, "bossDropTable")
			}))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to patch EquipmentSlot.UpdateTargets");
				return;
			}
			val.Index += 2;
			val.Emit(OpCodes.Ldloc_S, (byte)8);
			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;
			});
		}
	}
}