Decompiled source of BetterBossLootDropping v1.0.1

BetterBossLootDropping.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("BetterBossLootDropping")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+003612221a4fcc026deb5b2b18e6dbf40d984d59")]
[assembly: AssemblyProduct("BetterBossLootDropping")]
[assembly: AssemblyTitle("BetterBossLootDropping")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 BetterBossLootDropping
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("FakeMichau.BetterBossLootDropping", "BetterBossLootDropping", "1.0.1")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class BetterBossLootDropping : BaseUnityPlugin
	{
		public const string PluginGUID = "FakeMichau.BetterBossLootDropping";

		public const string PluginAuthor = "FakeMichau";

		public const string PluginName = "BetterBossLootDropping";

		public const string PluginVersion = "1.0.1";

		public void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			ModConfig.InitConfig(((BaseUnityPlugin)this).Config);
			BossGroup.DropRewards += new hook_DropRewards(BossGroup_DropRewards);
			if (RiskOfOptionsCompat.Enabled)
			{
				RiskOfOptionsCompat.AddOptions();
			}
		}

		private void BossGroup_DropRewards(orig_DropRewards orig, BossGroup self)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: 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_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: 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)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			ArtifactDef val = ArtifactCatalog.FindArtifactDef("Command");
			if (RunArtifactManager.instance.IsArtifactEnabled(val) || (RoR2Application.isInSinglePlayer && ModConfig.DisableInSingle.Value) || ModConfig.DisableMod.Value)
			{
				orig.Invoke(self);
				return;
			}
			int livingPlayerCount = Run.instance.livingPlayerCount;
			int participatingPlayerCount = Run.instance.participatingPlayerCount;
			if (participatingPlayerCount == 0 || !Object.op_Implicit((Object)(object)self.dropPosition))
			{
				return;
			}
			UniquePickup val2 = default(UniquePickup);
			if (Object.op_Implicit((Object)(object)self.dropTable))
			{
				val2 = self.dropTable.GeneratePickup(self.rng);
			}
			else
			{
				List<PickupIndex> list = Run.instance.availableTier2DropList;
				if (self.forceTier3Reward)
				{
					list = Run.instance.availableTier3DropList;
				}
				((UniquePickup)(ref val2))..ctor(self.rng.NextElementUniform<PickupIndex>(list));
			}
			int num = 1 + self.bonusRewardCount;
			if (self.scaleRewardsByPlayerCount)
			{
				num *= participatingPlayerCount;
			}
			if (ModConfig.RoundDownItems.Value)
			{
				num /= livingPlayerCount;
				num *= livingPlayerCount;
			}
			float num2 = 360f / (float)num;
			Vector3 val3 = Quaternion.AngleAxis((float)Random.Range(0, 360), Vector3.up) * (Vector3.up * 40f + Vector3.forward * 5f);
			Quaternion val4 = Quaternion.AngleAxis(num2, Vector3.up);
			List<PlayerCharacterMasterController> list2 = new List<PlayerCharacterMasterController>();
			using (List<PlayerCharacterMasterController>.Enumerator enumerator = PlayerCharacterMasterController._instances.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if ((Object)(object)enumerator.Current != (Object)null && enumerator.Current.master.hasBody)
					{
						list2.Add(enumerator.Current);
					}
				}
			}
			List<PlayerCharacterMasterController> list3 = list2.OrderBy((PlayerCharacterMasterController item) => self.rng.Next()).ToList();
			int num3 = 0;
			for (int i = 0; i < num; i++)
			{
				UniquePickup val5 = val2;
				if ((self.bossDrops.Count > 0 || self.bossDropTables.Count > 0) && self.rng.nextNormalizedFloat <= self.bossDropChance)
				{
					val5 = ((self.bossDropTables.Count > 0) ? self.rng.NextElementUniform<PickupDropTable>(self.bossDropTables).GeneratePickup(self.rng) : self.rng.NextElementUniform<UniquePickup>(self.bossDrops));
				}
				if (ModConfig.LootIntoInventory.Value)
				{
					if (ModConfig.DropRedItems.Value)
					{
						Scene activeScene = SceneManager.GetActiveScene();
						if (((Scene)(ref activeScene)).name.ToLower() == "shipgraveyard" && ((Object)self).name.StartsWith("SuperRoboBallEncounter"))
						{
							PickupDropletController.CreatePickupDroplet(val5, self.dropPosition.position, val3, false);
							val3 = val4 * val3;
							continue;
						}
					}
					if (((PickupIndex)(ref val5.pickupIndex)).pickupDef.isLunar && !ModConfig.LunarIntoInventory.Value)
					{
						PickupDropletController.CreatePickupDroplet(val5, list3[num3].master.GetBodyObject().transform.position, new Vector3(self.rng.nextNormalizedFloat, self.rng.nextNormalizedFloat, self.rng.nextNormalizedFloat), false);
					}
					else
					{
						list3[num3].master.inventory.GiveItemPermanent(((PickupIndex)(ref val5.pickupIndex)).pickupDef.itemIndex, 1);
						GenericPickupController.SendPickupMessage(list3[num3].master, val5);
					}
					num3++;
					if (num3 >= list3.Count)
					{
						num3 = 0;
					}
				}
				else
				{
					((MonoBehaviour)this).StartCoroutine(Utils.DelayedDrop(val5, self.dropPosition.position, val3, ModConfig.DelayLength.Value * (float)i));
					val3 = val4 * val3;
				}
			}
		}
	}
	internal class ModConfig
	{
		public static ConfigEntry<bool> DisableMod;

		public static ConfigEntry<bool> DisableInSingle;

		public static ConfigEntry<bool> RoundDownItems;

		public static ConfigEntry<bool> LootIntoInventory;

		public static ConfigEntry<bool> LunarIntoInventory;

		public static ConfigEntry<bool> DropRedItems;

		public static ConfigEntry<float> DelayLength;

		public static void InitConfig(ConfigFile config)
		{
			DisableMod = config.Bind<bool>("Settings", "Disable the mod", false, "Disables the mod completely.");
			DisableInSingle = config.Bind<bool>("Settings", "Disable the mod in singleplayer", false, "Should the mod be disabled only while playing singleplayer.");
			RoundDownItems = config.Bind<bool>("Settings", "Round down items", false, "With uneven amount of players still living, should the amount of items per player be rounded down.\nThat way each player gets the same number of items every time.");
			LootIntoInventory = config.Bind<bool>("Loot into inventory", "Loot into inventory", true, "Should boss items go straight into inventory\nDisabling this option will enable delayed dropping of loot.");
			LunarIntoInventory = config.Bind<bool>("Loot into inventory", "Lunar items into inventory", false, "Should boss loot changed into lunar items via Eulogy Zero go into inventory. \n(otherwise they will drop on the ground in front of a player that rolled it)");
			DropRedItems = config.Bind<bool>("Loot into inventory", "Drop red boss items on the ground", false, "Applies to Siren's Call where you destroy eggs to spawn a boss that drops red items.");
			DelayLength = config.Bind<float>("Delayed drop", "Delay between items dropping", 0.2f, "How much time passes between each item starting to drop.");
		}
	}
	internal class RiskOfOptionsCompat
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static IsDisabledDelegate <0>__CheckMod;

			public static IsDisabledDelegate <1>__CheckLII;

			public static IsDisabledDelegate <2>__CheckDrop;
		}

		private static bool? _enabled;

		public static bool Enabled
		{
			get
			{
				bool valueOrDefault = _enabled.GetValueOrDefault();
				if (!_enabled.HasValue)
				{
					valueOrDefault = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");
					_enabled = valueOrDefault;
				}
				return _enabled.Value;
			}
		}

		public static void AddOptions()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0074: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_00a9: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00b3: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00de: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_00e8: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_0113: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_0169: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ModConfig.DisableMod));
			ConfigEntry<bool> disableInSingle = ModConfig.DisableInSingle;
			CheckBoxConfig val = new CheckBoxConfig();
			object obj = <>O.<0>__CheckMod;
			if (obj == null)
			{
				IsDisabledDelegate val2 = CheckMod;
				<>O.<0>__CheckMod = val2;
				obj = (object)val2;
			}
			((BaseOptionConfig)val).checkIfDisabled = (IsDisabledDelegate)obj;
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(disableInSingle, val));
			ConfigEntry<bool> roundDownItems = ModConfig.RoundDownItems;
			CheckBoxConfig val3 = new CheckBoxConfig();
			object obj2 = <>O.<0>__CheckMod;
			if (obj2 == null)
			{
				IsDisabledDelegate val4 = CheckMod;
				<>O.<0>__CheckMod = val4;
				obj2 = (object)val4;
			}
			((BaseOptionConfig)val3).checkIfDisabled = (IsDisabledDelegate)obj2;
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(roundDownItems, val3));
			ConfigEntry<bool> lootIntoInventory = ModConfig.LootIntoInventory;
			CheckBoxConfig val5 = new CheckBoxConfig();
			object obj3 = <>O.<0>__CheckMod;
			if (obj3 == null)
			{
				IsDisabledDelegate val6 = CheckMod;
				<>O.<0>__CheckMod = val6;
				obj3 = (object)val6;
			}
			((BaseOptionConfig)val5).checkIfDisabled = (IsDisabledDelegate)obj3;
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(lootIntoInventory, val5));
			ConfigEntry<bool> lunarIntoInventory = ModConfig.LunarIntoInventory;
			CheckBoxConfig val7 = new CheckBoxConfig();
			object obj4 = <>O.<1>__CheckLII;
			if (obj4 == null)
			{
				IsDisabledDelegate val8 = CheckLII;
				<>O.<1>__CheckLII = val8;
				obj4 = (object)val8;
			}
			((BaseOptionConfig)val7).checkIfDisabled = (IsDisabledDelegate)obj4;
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(lunarIntoInventory, val7));
			ConfigEntry<bool> dropRedItems = ModConfig.DropRedItems;
			CheckBoxConfig val9 = new CheckBoxConfig();
			object obj5 = <>O.<1>__CheckLII;
			if (obj5 == null)
			{
				IsDisabledDelegate val10 = CheckLII;
				<>O.<1>__CheckLII = val10;
				obj5 = (object)val10;
			}
			((BaseOptionConfig)val9).checkIfDisabled = (IsDisabledDelegate)obj5;
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(dropRedItems, val9));
			ConfigEntry<float> delayLength = ModConfig.DelayLength;
			StepSliderConfig val11 = new StepSliderConfig
			{
				min = 0f,
				max = 1f,
				increment = 0.05f
			};
			object obj6 = <>O.<2>__CheckDrop;
			if (obj6 == null)
			{
				IsDisabledDelegate val12 = CheckDrop;
				<>O.<2>__CheckDrop = val12;
				obj6 = (object)val12;
			}
			((BaseOptionConfig)val11).checkIfDisabled = (IsDisabledDelegate)obj6;
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(delayLength, val11));
			ModSettingsManager.SetModDescription("Enhanced way of getting boss loot.");
		}

		private static bool CheckDrop()
		{
			if (!ModConfig.DisableMod.Value)
			{
				return ModConfig.LootIntoInventory.Value;
			}
			return true;
		}

		private static bool CheckMod()
		{
			return ModConfig.DisableMod.Value;
		}

		private static bool CheckLII()
		{
			if (!ModConfig.DisableMod.Value)
			{
				return !ModConfig.LootIntoInventory.Value;
			}
			return true;
		}
	}
	internal class Utils
	{
		[CompilerGenerated]
		private sealed class <DelayedDrop>d__0 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public float delayInSecs;

			public UniquePickup uniquePickup;

			public Vector3 position;

			public Vector3 vector;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayedDrop>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Expected O, but got Unknown
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(delayInSecs);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					PickupDropletController.CreatePickupDroplet(uniquePickup, position, vector, false);
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[IteratorStateMachine(typeof(<DelayedDrop>d__0))]
		public static IEnumerator DelayedDrop(UniquePickup uniquePickup, Vector3 position, Vector3 vector, float delayInSecs)
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedDrop>d__0(0)
			{
				uniquePickup = uniquePickup,
				position = position,
				vector = vector,
				delayInSecs = delayInSecs
			};
		}
	}
}