Decompiled source of NerfRecycler v0.1.0

NerfRecycler.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using HG;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RoR2;
using RoR2.DirectionalSearch;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.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 Prototype
{
	[BepInPlugin("prototype.nerf.recycler", "NerfRecycler", "0.1.0")]
	public class NerfRecycler : BaseUnityPlugin
	{
		public const string version = "0.1.0";

		public const string identifier = "prototype.nerf.recycler";

		protected void Awake()
		{
			Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(SetLanguage));
			add("RoR2/DLC1/MinorConstructOnKill/MinorConstructOnKill.asset", (ItemTag)3);
			replace("RoR2/Base/ParentEgg/ParentEgg.asset", (ItemTag)1, (ItemTag)2);
			add("RoR2/Base/LunarTrinket/LunarTrinket.asset", (ItemTag)3);
			add("RoR2/Base/LunarSkillReplacements/LunarUtilityReplacement.asset", (ItemTag)2);
			replace("RoR2/DLC1/HalfSpeedDoubleHealth/HalfSpeedDoubleHealth.asset", (ItemTag)3, (ItemTag)2);
			replace("RoR2/DLC1/LunarSun/LunarSun.asset", (ItemTag)3, (ItemTag)1);
			replace("RoR2/Base/RandomDamageZone/RandomDamageZone.asset", (ItemTag)3, (ItemTag)1);
			static void add(string key, ItemTag tag)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				AsyncOperationHandle<ItemDef> val2 = load(key);
				val2.Completed += delegate(AsyncOperationHandle<ItemDef> handle)
				{
					ArrayUtils.ArrayAppend<ItemTag>(ref handle.Result.tags, ref tag);
				};
			}
			static AsyncOperationHandle<ItemDef> load(string key)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return Addressables.LoadAssetAsync<ItemDef>((object)key);
			}
			static void replace(string key, ItemTag previous, ItemTag tag)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				AsyncOperationHandle<ItemDef> val = load(key);
				val.Completed += delegate(AsyncOperationHandle<ItemDef> handle)
				{
					//IL_0019: Unknown result type (might be due to invalid IL or missing references)
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					//IL_002a: Expected I4, but got Unknown
					handle.Result.tags[Array.IndexOf(handle.Result.tags, previous)] = (ItemTag)(int)tag;
				};
			}
		}

		private void SetLanguage()
		{
			Language language = Language.english;
			remove("EQUIPMENT_RECYCLER_PICKUP");
			remove("EQUIPMENT_RECYCLER_DESC");
			void remove(string token)
			{
				language.SetStringByToken(token, language.GetLocalizedStringByToken(token).Replace(" or Equipment", ""));
			}
		}

		[HarmonyPatch(typeof(PickupSearchFilter), "PassesFilter")]
		[HarmonyPostfix]
		private static void ItemOnly(GenericPickupController genericPickupController, ref bool __result)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			if (__result && (int)GetIndex(genericPickupController.pickupIndex) == -1)
			{
				__result = false;
			}
		}

		[HarmonyPatch(typeof(EquipmentSlot), "FireRecycle")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> IL)
		{
			MethodInfo hook = SymbolExtensions.GetMethodInfo((Expression<Action>)(() => PickupTransmutationManager.GetAvailableGroupFromPickupIndex(default(PickupIndex))));
			MethodInfo target = SymbolExtensions.GetMethodInfo((Expression<Action>)(() => FilterByCategory(default(PickupIndex), null)));
			foreach (CodeInstruction instruction in IL)
			{
				if (CodeInstructionExtensions.Calls(instruction, hook))
				{
					yield return new CodeInstruction(OpCodes.Dup, (object)null);
					yield return instruction;
					yield return new CodeInstruction(OpCodes.Call, (object)target);
				}
				else
				{
					yield return instruction;
				}
			}
		}

		private static PickupIndex[] FilterByCategory(PickupIndex target, PickupIndex[] original)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			int num = Run.instance.treasureRng.RangeInt(0, 100);
			PickupIndex[] array = null;
			ItemTier tier = item(target).tier;
			PickupIndex[] array2;
			int num2;
			PickupIndex[] itemVoidBossGroup;
			if (tier - 6 > 1)
			{
				if (tier - 8 > 1)
				{
					goto IL_010f;
				}
				PickupIndex[] itemVoidTier3Group = PickupTransmutationManager.itemVoidTier3Group;
				itemVoidBossGroup = PickupTransmutationManager.itemVoidBossGroup;
				num2 = 0;
				array2 = (PickupIndex[])(object)new PickupIndex[itemVoidTier3Group.Length + itemVoidBossGroup.Length];
				PickupIndex[] array3 = itemVoidTier3Group;
				foreach (PickupIndex val in array3)
				{
					array2[num2] = val;
					num2++;
				}
				array3 = itemVoidBossGroup;
				foreach (PickupIndex val in array3)
				{
					array2[num2] = val;
					num2++;
				}
				original = array2;
			}
			switch (num)
			{
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
				array = PickupTransmutationManager.itemVoidBossGroup;
				break;
			case 5:
			case 6:
			case 7:
			case 8:
			case 9:
			case 10:
			case 11:
			case 12:
			case 13:
			case 14:
				array = PickupTransmutationManager.itemVoidTier3Group;
				break;
			case 15:
			case 16:
			case 17:
			case 18:
			case 19:
			case 20:
			case 21:
			case 22:
			case 23:
			case 24:
			case 25:
			case 26:
			case 27:
			case 28:
			case 29:
				array = PickupTransmutationManager.itemVoidTier2Group;
				break;
			case 30:
			case 31:
			case 32:
			case 33:
			case 34:
			case 35:
			case 36:
			case 37:
			case 38:
			case 39:
			case 40:
			case 41:
			case 42:
			case 43:
			case 44:
			case 45:
			case 46:
			case 47:
			case 48:
			case 49:
				array = PickupTransmutationManager.itemVoidTier1Group;
				break;
			}
			goto IL_010f;
			IL_010f:
			if (num >= 75)
			{
				return original;
			}
			if (array == null)
			{
				array = original;
			}
			List<PickupIndex> list = new List<PickupIndex>();
			IEnumerable<ItemTag> source = item(target).tags.Where((ItemTag category) => category - 1 <= 2);
			array2 = array;
			foreach (PickupIndex val2 in array2)
			{
				if (source.Any((Func<ItemTag, bool>)item(val2).ContainsTag))
				{
					list.Add(val2);
				}
			}
			if (list.Count <= 1)
			{
				return original;
			}
			num2 = 0;
			itemVoidBossGroup = (PickupIndex[])(object)new PickupIndex[list.Count];
			foreach (PickupIndex item in list)
			{
				itemVoidBossGroup[num2] = item;
				num2++;
			}
			return itemVoidBossGroup;
			static ItemDef item(PickupIndex pickup)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return ItemCatalog.GetItemDef(GetIndex(pickup));
			}
		}

		private static ItemIndex GetIndex(PickupIndex pickup)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return PickupCatalog.GetPickupDef(pickup).itemIndex;
		}
	}
}