Decompiled source of TeleporterDropToInventory v1.0.0

TeleporterDropToInventory.dll

Decompiled 9 hours 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 System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
using UnityEngine;

[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("TeleporterDropToInventory")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TeleporterDropToInventory")]
[assembly: AssemblyTitle("TeleporterDropToInventory")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace TeleporterDropToInventory
{
	[BepInIncompatibility("shbones.MoreMountains")]
	[BepInPlugin("com.Moffein.TeleporterDropToInventory", "TeleporterDropToInventory", "1.0.0")]
	public class TeleporterDropToInventoryPlugin : BaseUnityPlugin
	{
		public static ConfigEntry<bool> requireAlive;

		public static bool blacklistCommand;

		public static string blacklistedArtifactsString;

		public static HashSet<ArtifactDef> blacklistedArtifacts = new HashSet<ArtifactDef>();

		private void Awake()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			requireAlive = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Require Alive", false, "Only drop items to living players.");
			blacklistCommand = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Blacklist Command", true, "This mod does not take effect if Command is enabled.").Value;
			blacklistedArtifactsString = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Blacklisted Artifacts", "", "Disable this mod when any of these artifacts are enabled. Comma separated list (ex. Sacrifice, Command, Vengeance).").Value;
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OnLoad));
			BossGroup.DropRewards += new hook_DropRewards(BossGroup_DropRewards);
		}

		private void OnLoad()
		{
			if (blacklistCommand)
			{
				blacklistedArtifacts.Add(Artifacts.Command);
			}
			if (blacklistedArtifactsString.Trim().Length <= 0)
			{
				return;
			}
			string[] array = blacklistedArtifactsString.Split(",");
			string[] array2 = array;
			foreach (string text in array2)
			{
				string text2 = text.Trim();
				ArtifactDef val = ArtifactCatalog.FindArtifactDef(text2);
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = GetArtifactDefFromString(text2);
				}
				if (Object.op_Implicit((Object)(object)val))
				{
					blacklistedArtifacts.Add(val);
				}
			}
		}

		private static bool BlacklistedArtifactEnabled()
		{
			if (Object.op_Implicit((Object)(object)RunArtifactManager.instance))
			{
				foreach (ArtifactDef blacklistedArtifact in blacklistedArtifacts)
				{
					if (RunArtifactManager.instance.IsArtifactEnabled(blacklistedArtifact))
					{
						return true;
					}
				}
			}
			return false;
		}

		private static void BossGroup_DropRewards(orig_DropRewards orig, BossGroup self)
		{
			if (!BlacklistedArtifactEnabled())
			{
				DropRewardsToInventory(self);
			}
			else
			{
				orig.Invoke(self);
			}
		}

		private static void DropRewardsToInventory(BossGroup self)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Invalid comparison between Unknown and I4
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Invalid comparison between Unknown and I4
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Run.instance))
			{
				Debug.LogError((object)"No valid run instance!");
				return;
			}
			if (self.rng == null)
			{
				Debug.LogError((object)"RNG is null!");
				return;
			}
			if (!Object.op_Implicit((Object)(object)self.dropPosition))
			{
				Debug.LogWarning((object)"dropPosition not set for BossGroup! No item will be spawned.");
				return;
			}
			int participatingPlayerCount = Run.instance.participatingPlayerCount;
			if (participatingPlayerCount == 0)
			{
				return;
			}
			PickupIndex none = PickupIndex.none;
			if (Object.op_Implicit((Object)(object)self.dropTable))
			{
				none = self.dropTable.GenerateDrop(self.rng);
			}
			else
			{
				List<PickupIndex> list = Run.instance.availableTier2DropList;
				if (self.forceTier3Reward)
				{
					list = Run.instance.availableTier3DropList;
				}
				none = self.rng.NextElementUniform<PickupIndex>(list);
			}
			ItemIndex val = (ItemIndex)(-1);
			PickupDef pickupDef = PickupCatalog.GetPickupDef(none);
			if (pickupDef != null && (int)pickupDef.itemIndex != -1)
			{
				val = pickupDef.itemIndex;
			}
			int num = 1 + self.bonusRewardCount;
			if (self.scaleRewardsByPlayerCount)
			{
				num *= participatingPlayerCount;
			}
			Queue<ItemIndex> queue = new Queue<ItemIndex>();
			bool flag = self.bossDrops != null && self.bossDrops.Count > 0;
			bool flag2 = self.bossDropTables != null && self.bossDropTables.Count > 0;
			if (self.bossDrops != null && (flag || flag2))
			{
				for (int i = 0; i < num; i++)
				{
					PickupIndex val2 = PickupIndex.none;
					if (self.rng.nextNormalizedFloat <= self.bossDropChance)
					{
						if (flag2)
						{
							PickupDropTable val3 = self.rng.NextElementUniform<PickupDropTable>(self.bossDropTables);
							if ((Object)(object)val3 != (Object)null)
							{
								val2 = val3.GenerateDrop(self.rng);
							}
						}
						else
						{
							val2 = self.rng.NextElementUniform<PickupIndex>(self.bossDrops);
						}
					}
					if (val2 != PickupIndex.none)
					{
						PickupDef pickupDef2 = PickupCatalog.GetPickupDef(val2);
						if (pickupDef2 != null && (int)pickupDef2.itemIndex != -1)
						{
							queue.Enqueue(pickupDef2.itemIndex);
						}
					}
				}
			}
			int num2 = 0;
			while (num2 < num)
			{
				int num3 = num2;
				foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
				{
					if (Object.op_Implicit((Object)(object)instance.master) && Object.op_Implicit((Object)(object)instance.master.inventory) && (!requireAlive.Value || !instance.master.IsDeadAndOutOfLivesServer()))
					{
						ItemIndex val4 = val;
						if (queue.Count > 0)
						{
							val4 = queue.Dequeue();
						}
						instance.master.inventory.GiveItem(val4, 1);
						num2++;
					}
				}
				if (num2 == num3)
				{
					break;
				}
			}
		}

		private static ArtifactDef GetArtifactDefFromString(string partialName)
		{
			ArtifactDef val = ArtifactCatalog.FindArtifactDef(partialName);
			if (Object.op_Implicit((Object)(object)val))
			{
				return val;
			}
			ArtifactDef[] artifactDefs = ArtifactCatalog.artifactDefs;
			foreach (ArtifactDef val2 in artifactDefs)
			{
				if (GetArgNameForAtrifact(val2).ToLower().Contains(partialName.ToLower()))
				{
					return val2;
				}
			}
			return null;
		}

		private static string GetArgNameForAtrifact(ArtifactDef artifactDef)
		{
			return Regex.Replace(Language.GetString(artifactDef.nameToken), "[ '-]", string.Empty);
		}
	}
}
namespace R2API.Utils
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class ManualNetworkRegistrationAttribute : Attribute
	{
	}
}