Decompiled source of ExponentialItemsFixed v1.7.0

ExponentialItemsFixed.dll

Decompiled 5 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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("ExponentialItemsFixed")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExponentialItemsFixed")]
[assembly: AssemblyTitle("ExponentialItemsFixed")]
[assembly: AssemblyVersion("1.0.0.0")]
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 ExponentialItemsFixed
{
	[BepInPlugin("com.Tepot.ExponentialItems", "Exponential Items Fixed", "1.0.0")]
	public class ExponentialItemsPlugin : BaseUnityPlugin
	{
		private ConfigEntry<int> StackMultiplier;

		private ConfigEntry<int> MaxStackCap;

		private ConfigEntry<float> DoubleChance;

		private ConfigEntry<bool> EnableVoid;

		private static bool _isProcessing;

		public void Awake()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			StackMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("1. Math", "Multiplier", 2, "How much to multiply items by. 2 = Double.");
			MaxStackCap = ((BaseUnityPlugin)this).Config.Bind<int>("2. Safety", "Max Stack Cap", 200, "The mod will stop multiplying items once you reach this amount. Prevents game crashes from having 1 million items.");
			DoubleChance = ((BaseUnityPlugin)this).Config.Bind<float>("3. Pacing", "Chance to Multiply", 100f, "Percent chance (0-100) that an item will multiply when picked up. Set to 50 for a more balanced run.");
			EnableVoid = ((BaseUnityPlugin)this).Config.Bind<bool>("4. Stability", "Enable Void Items", true, "If set to false, Void items will NEVER multiply. Useful if Void items cause crashes or infinite loops.");
			Inventory.GiveItem_ItemIndex_int += (hook_GiveItem_ItemIndex_int)delegate(orig_GiveItem_ItemIndex_int orig, Inventory self, ItemIndex index, int count)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				GenericHook(self, index, count, delegate(Inventory s, ItemIndex i, int c)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					orig.Invoke(s, i, c);
				});
			};
			Inventory.GiveItemPermanent_ItemIndex_int += (hook_GiveItemPermanent_ItemIndex_int)delegate(orig_GiveItemPermanent_ItemIndex_int orig, Inventory self, ItemIndex index, int count)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				GenericHook(self, index, count, delegate(Inventory s, ItemIndex i, int c)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					orig.Invoke(s, i, c);
				});
			};
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Exponential Items v1.0.0 Loaded with Full Configs!");
		}

		private void GenericHook(Inventory self, ItemIndex itemIndex, int count, Action<Inventory, ItemIndex, int> originalMethod)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_003a: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Invalid comparison between Unknown and I4
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Invalid comparison between Unknown and I4
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			if (count <= 0)
			{
				originalMethod(self, itemIndex, count);
				return;
			}
			if ((Object)(object)self == (Object)null || (int)itemIndex == -1 || _isProcessing)
			{
				originalMethod(self, itemIndex, count);
				return;
			}
			_isProcessing = true;
			try
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex);
				if ((((Object)(object)itemDef != (Object)null && (int)itemDef.tier == 6) || (int)itemDef.tier == 7 || (int)itemDef.tier == 8 || (int)itemDef.tier == 9) && !EnableVoid.Value)
				{
					originalMethod(self, itemIndex, count);
					return;
				}
				int itemCount = self.GetItemCount(itemIndex);
				if (itemCount >= MaxStackCap.Value)
				{
					originalMethod(self, itemIndex, count);
					return;
				}
				if (itemCount > 0 && Random.Range(0f, 100f) > DoubleChance.Value)
				{
					originalMethod(self, itemIndex, count);
					return;
				}
				int num = StackMultiplier.Value;
				if (num < 1)
				{
					num = 1;
				}
				if (itemCount > 0)
				{
					int num2 = itemCount * (num - 1);
					int num3 = itemCount + num2;
					if (num3 > MaxStackCap.Value)
					{
						num2 = MaxStackCap.Value - itemCount;
					}
					count = num2;
				}
				originalMethod(self, itemIndex, count);
			}
			finally
			{
				_isProcessing = false;
			}
		}
	}
}