Decompiled source of ExponentialItemsReloaded v1.2.9

plugins/ExponentialItemsReloaded/ExponentialItemsReloaded.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
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: AssemblyVersion("0.0.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 ExponentialItemsReloaded
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.cryptidlabs.exponentialitemsreloaded", "ExponentialItemsReloaded", "1.2.8")]
	public class ExponentialItemsReloadedPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.cryptidlabs.exponentialitemsreloaded";

		public const string PluginName = "ExponentialItemsReloaded";

		public const string PluginVersion = "1.2.8";

		private static ArtifactDef exponentialArtifactDef;

		private static ConfigEntry<bool> requireArtifactEnabled;

		private static ConfigEntry<int> maxStack;

		private static ConfigEntry<int> baseSize;

		private static ConfigEntry<bool> affectTier1;

		private static ConfigEntry<bool> affectTier2;

		private static ConfigEntry<bool> affectTier3;

		private static ConfigEntry<bool> affectBoss;

		private static ConfigEntry<bool> affectLunar;

		private static ConfigEntry<bool> affectVoid;

		private static ConfigEntry<bool> affectTierless;

		private static ConfigEntry<bool> affectTemporaryItems;

		private static ConfigEntry<bool> affectEquipment;

		private static ConfigEntry<bool> debugLogging;

		private static ConfigEntry<bool> debugLogArtifactList;

		private static bool suppressExponentialHook;

		public void Awake()
		{
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Expected O, but got Unknown
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Expected O, but got Unknown
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Expected O, but got Unknown
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Expected O, but got Unknown
			requireArtifactEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Require Artifact Enabled", true, "If true, exponential stacking only applies while Artifact of Exponents is enabled. If false, the mod is always active.");
			maxStack = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Max Stack Size", 4096, "Maximum item stack count this mod will try to reach.");
			baseSize = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Base Size", 2, "Exponential base. 2 gives 1,2,4,8... 3 gives 1,3,9,27...");
			affectTier1 = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Filters", "Affect White Items", true, "Allows common/white items to stack exponentially.");
			affectTier2 = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Filters", "Affect Green Items", true, "Allows uncommon/green items to stack exponentially.");
			affectTier3 = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Filters", "Affect Red Items", true, "Allows legendary/red items to stack exponentially.");
			affectBoss = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Filters", "Affect Boss Items", true, "Allows boss/yellow items to stack exponentially.");
			affectLunar = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Filters", "Affect Lunar Items", true, "Allows lunar items to stack exponentially.");
			affectVoid = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Filters", "Affect Void Items", true, "Allows void items to stack exponentially.");
			affectTierless = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Filters", "Affect Tierless Items", false, "Allows tierless/hidden/internal items to stack exponentially. Usually safer off.");
			affectTemporaryItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Filters", "Affect Temporary Items", false, "Allows Alloyed Collective temporary items/FoodTier-style temporary items to stack exponentially. Experimental; leave off if things get weird.");
			affectEquipment = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Filters", "Affect Equipment", false, "Reserved safety option. This mod currently only modifies item pickups, not equipment pickups.");
			debugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Enable Debug Logging", false, "Logs item stack changes when the mod applies exponential stacking.");
			debugLogArtifactList = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Log Artifact List On Load", false, "Logs every loaded artifact on game load. Useful for troubleshooting missing artifacts, noisy otherwise.");
			RegisterArtifact();
			Inventory.GiveItem_ItemIndex_int += new hook_GiveItem_ItemIndex_int(Inventory_GiveItem_ItemIndex_int);
			Inventory.GiveItem_ItemDef_int += new hook_GiveItem_ItemDef_int(Inventory_GiveItem_ItemDef_int);
			Inventory.GiveItemTemp += new hook_GiveItemTemp(Inventory_GiveItemTemp);
			GenericPickupController.AttemptGrant += new hook_AttemptGrant(GenericPickupController_AttemptGrant);
			CharacterBody.RecalculateStats += new hook_RecalculateStats(CharacterBody_RecalculateStats);
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} loaded. Artifact registered: {1}", "ExponentialItemsReloaded", (Object)(object)exponentialArtifactDef != (Object)null));
			if (debugLogArtifactList.Value)
			{
				RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(LogLoadedArtifacts));
			}
		}

		private void RegisterArtifact()
		{
			LanguageAPI.Add("ARTIFACT_EXPONENTIALITEMS_NAME", "Artifact of Exponents");
			LanguageAPI.Add("ARTIFACT_EXPONENTIALITEMS_DESC", "Items stack exponentially instead of one at a time.");
			exponentialArtifactDef = ScriptableObject.CreateInstance<ArtifactDef>();
			exponentialArtifactDef.cachedName = "ExponentialItems";
			exponentialArtifactDef.nameToken = "ARTIFACT_EXPONENTIALITEMS_NAME";
			exponentialArtifactDef.descriptionToken = "ARTIFACT_EXPONENTIALITEMS_DESC";
			Sprite val = LoadSprite("icon_selected.png");
			Sprite val2 = LoadSprite("icon_deselected.png");
			if ((Object)(object)val != (Object)null)
			{
				exponentialArtifactDef.smallIconSelectedSprite = val;
			}
			if ((Object)(object)val2 != (Object)null)
			{
				exponentialArtifactDef.smallIconDeselectedSprite = val2;
			}
			ContentAddition.AddArtifactDef(exponentialArtifactDef);
		}

		private Sprite LoadSprite(string fileName)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), fileName);
			if (!File.Exists(text))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Icon file not found: " + text));
				return null;
			}
			try
			{
				byte[] array = File.ReadAllBytes(text);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				ImageConversion.LoadImage(val, array);
				((Object)val).name = Path.GetFileNameWithoutExtension(fileName);
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Failed to load icon {fileName}: {arg}");
				return null;
			}
		}

		private void Inventory_GiveItem_ItemIndex_int(orig_GiveItem_ItemIndex_int orig, Inventory self, ItemIndex itemIndex, int count)
		{
			//IL_00d1: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (suppressExponentialHook || !ShouldApply(self, itemIndex, count))
				{
					orig.Invoke(self, itemIndex, count);
					return;
				}
				int currentStackForExponential = GetCurrentStackForExponential(self, itemIndex);
				int nextTargetStack = GetNextTargetStack(currentStackForExponential);
				if (nextTargetStack <= currentStackForExponential)
				{
					orig.Invoke(self, itemIndex, count);
					return;
				}
				int num = Math.Max(1, nextTargetStack - currentStackForExponential);
				LogDebug($"GiveItem {itemIndex}: current={currentStackForExponential}, target={nextTargetStack}, adding={num}");
				suppressExponentialHook = true;
				try
				{
					orig.Invoke(self, itemIndex, num);
				}
				finally
				{
					suppressExponentialHook = false;
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
				orig.Invoke(self, itemIndex, count);
			}
		}

		private void Inventory_GiveItem_ItemDef_int(orig_GiveItem_ItemDef_int orig, Inventory self, ItemDef itemDef, int count)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if ((Object)(object)itemDef == (Object)null)
			{
				orig.Invoke(self, itemDef, count);
				return;
			}
			Inventory_GiveItem_ItemIndex_int((orig_GiveItem_ItemIndex_int)delegate(Inventory inventory, ItemIndex itemIndex, int itemCount)
			{
				orig.Invoke(inventory, itemDef, itemCount);
			}, self, itemDef.itemIndex, count);
		}

		private void Inventory_GiveItemTemp(orig_GiveItemTemp orig, Inventory self, ItemIndex itemIndex, float countToAdd)
		{
			//IL_010b: 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)
			//IL_0037: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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)
			try
			{
				if (suppressExponentialHook || countToAdd <= 0f || !ShouldApplyTemporaryGrant(self, itemIndex))
				{
					orig.Invoke(self, itemIndex, countToAdd);
					return;
				}
				int itemCountEffective = self.GetItemCountEffective(itemIndex);
				int itemCountTemp = self.GetItemCountTemp(itemIndex);
				float tempItemRawValue = self.GetTempItemRawValue(itemIndex);
				int nextTargetStack = GetNextTargetStack(itemCountEffective);
				if (nextTargetStack <= itemCountEffective)
				{
					orig.Invoke(self, itemIndex, countToAdd);
					return;
				}
				float num = Math.Max(countToAdd, nextTargetStack - itemCountEffective);
				LogTempGrant($"GiveItemTemp {itemIndex}: effectiveCurrent={itemCountEffective}, tempCurrent={itemCountTemp}, rawCurrent={tempItemRawValue}, incoming={countToAdd}, target={nextTargetStack}, adding={num}");
				suppressExponentialHook = true;
				try
				{
					orig.Invoke(self, itemIndex, num);
				}
				finally
				{
					suppressExponentialHook = false;
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
				orig.Invoke(self, itemIndex, countToAdd);
			}
		}

		private void GenericPickupController_AttemptGrant(orig_AttemptGrant orig, GenericPickupController self, CharacterBody body)
		{
			//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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Invalid comparison between Unknown and I4
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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)
			Inventory val = (Object.op_Implicit((Object)(object)body) ? body.inventory : null);
			PickupIndex pickupIndex = self.pickupIndex;
			PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
			ItemIndex val2 = (ItemIndex)((pickupDef == null) ? (-1) : ((int)pickupDef.itemIndex));
			int num = (((Object)(object)val != (Object)null && (int)val2 != -1) ? GetCurrentStackForExponential(val, val2) : 0);
			orig.Invoke(self, body);
			try
			{
				if ((Object)(object)val == (Object)null || (int)val2 == -1 || suppressExponentialHook || !ShouldApplyItem(val, val2))
				{
					return;
				}
				int currentStackForExponential = GetCurrentStackForExponential(val, val2);
				if (currentStackForExponential <= num)
				{
					return;
				}
				int nextTargetStack = GetNextTargetStack(num);
				if (nextTargetStack <= currentStackForExponential)
				{
					return;
				}
				int num2 = nextTargetStack - currentStackForExponential;
				LogDebug($"Pickup {val2}: before={num}, after={currentStackForExponential}, target={nextTargetStack}, adding={num2}");
				suppressExponentialHook = true;
				try
				{
					GiveExtraStacksForExponential(val, val2, num2);
				}
				finally
				{
					suppressExponentialHook = false;
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
		}

		private void CharacterBody_RecalculateStats(orig_RecalculateStats orig, CharacterBody self)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Invalid comparison between Unknown and I4
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (debugLogging == null || !debugLogging.Value || (Object)(object)self == (Object)null || (Object)(object)self.inventory == (Object)null)
			{
				return;
			}
			Inventory inventory = self.inventory;
			GenericStaticEnumerable<ItemIndex, AllItemsEnumerator> allItems = ItemCatalog.allItems;
			AllItemsEnumerator enumerator = allItems.GetEnumerator();
			try
			{
				while (((AllItemsEnumerator)(ref enumerator)).MoveNext())
				{
					ItemIndex current = ((AllItemsEnumerator)(ref enumerator)).Current;
					if ((int)current == -1)
					{
						continue;
					}
					ItemDef itemDef = ItemCatalog.GetItemDef(current);
					if (!((Object)(object)itemDef == (Object)null))
					{
						int itemCountEffective = inventory.GetItemCountEffective(current);
						if (itemCountEffective > 0 && IsTemporaryItem(itemDef))
						{
							((BaseUnityPlugin)this).Logger.LogInfo((object)$"[TempItems] RecalculateStats found: {GetItemDebugName(itemDef)} | tier={itemDef.tier} | effectiveCount={itemCountEffective}");
						}
					}
				}
			}
			finally
			{
				((IDisposable)(AllItemsEnumerator)(ref enumerator)).Dispose();
			}
		}

		private static int GetCurrentStackForExponential(Inventory inventory, ItemIndex itemIndex)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)inventory == (Object)null || (int)itemIndex == -1)
			{
				return 0;
			}
			ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex);
			if (IsTemporaryItem(itemDef))
			{
				return inventory.GetItemCountEffective(itemIndex);
			}
			return inventory.GetItemCountPermanent(itemIndex);
		}

		private static void GiveExtraStacksForExponential(Inventory inventory, ItemIndex itemIndex, int amountToGive)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)inventory == (Object)null) && (int)itemIndex != -1 && amountToGive > 0)
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex);
				if (IsTemporaryItem(itemDef))
				{
					inventory.GiveItemTemp(itemIndex, (float)amountToGive);
				}
				else
				{
					inventory.GiveItemPermanent(itemIndex, amountToGive);
				}
			}
		}

		private static int GetNextTargetStack(int current)
		{
			int num = Math.Max(2, baseSize.Value);
			int num2 = Math.Max(1, maxStack.Value);
			if (current < 0)
			{
				return 1;
			}
			if (current >= num2)
			{
				return current;
			}
			if (current == 0)
			{
				return 1;
			}
			double y = Math.Floor(Math.Log(current, num)) + 1.0;
			int val = (int)Math.Pow(num, y);
			return Math.Min(num2, Math.Max(current + 1, val));
		}

		private static void LogTempGrant(string message)
		{
			Debug.Log((object)("[ExponentialItemsReloaded] [TempGrant] " + message));
		}

		private static bool ShouldApplyTemporaryGrant(Inventory self, ItemIndex itemIndex)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)self == (Object)null || (int)itemIndex == -1)
			{
				return false;
			}
			if ((Object)(object)exponentialArtifactDef == (Object)null)
			{
				return false;
			}
			if (requireArtifactEnabled.Value)
			{
				if ((Object)(object)RunArtifactManager.instance == (Object)null)
				{
					return false;
				}
				if (!RunArtifactManager.instance.IsArtifactEnabled(exponentialArtifactDef))
				{
					return false;
				}
			}
			if (!affectTemporaryItems.Value)
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex);
				LogDebug("Blocked temporary grant: " + GetItemDebugName(itemDef));
				return false;
			}
			ItemDef itemDef2 = ItemCatalog.GetItemDef(itemIndex);
			string itemDebugName = GetItemDebugName(itemDef2);
			object obj;
			if (itemDef2 == null)
			{
				obj = null;
			}
			else
			{
				ItemTier tier = itemDef2.tier;
				obj = ((object)(ItemTier)(ref tier)).ToString();
			}
			if (obj == null)
			{
				obj = "<null>";
			}
			LogDebug("Allowed temporary grant: " + itemDebugName + " | tier=" + (string?)obj);
			return true;
		}

		private static bool ShouldApplyItem(Inventory self, ItemIndex itemIndex)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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)
			if ((Object)(object)self == (Object)null || (int)itemIndex == -1)
			{
				return false;
			}
			if ((Object)(object)exponentialArtifactDef == (Object)null)
			{
				return false;
			}
			if (requireArtifactEnabled.Value)
			{
				if ((Object)(object)RunArtifactManager.instance == (Object)null)
				{
					return false;
				}
				if (!RunArtifactManager.instance.IsArtifactEnabled(exponentialArtifactDef))
				{
					return false;
				}
			}
			ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex);
			if ((Object)(object)itemDef == (Object)null)
			{
				return false;
			}
			if (IsTemporaryItem(itemDef))
			{
				if (!affectTemporaryItems.Value)
				{
					LogDebug($"Blocked temporary item: {GetItemDebugName(itemDef)} | tier={itemDef.tier}");
					return false;
				}
				LogDebug($"Allowed temporary item: {GetItemDebugName(itemDef)} | tier={itemDef.tier}");
				return true;
			}
			if (!IsAllowedByTierConfig(itemDef))
			{
				LogDebug($"Blocked by tier config: {GetItemDebugName(itemDef)} | tier={itemDef.tier}");
				return false;
			}
			if (!affectTierless.Value && IsTierlessOrHidden(itemDef))
			{
				LogDebug($"Blocked tierless/hidden item: {GetItemDebugName(itemDef)} | tier={itemDef.tier}");
				return false;
			}
			return true;
		}

		private static bool ShouldApply(Inventory self, ItemIndex itemIndex, int count)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (count != 1)
			{
				return false;
			}
			return ShouldApplyItem(self, itemIndex);
		}

		private static bool IsAllowedByTierConfig(ItemDef itemDef)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//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_0009: 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_0038: Expected I4, but got Unknown
			ItemTier tier = itemDef.tier;
			ItemTier val = tier;
			switch ((int)val)
			{
			case 0:
				return affectTier1.Value;
			case 1:
				return affectTier2.Value;
			case 2:
				return affectTier3.Value;
			case 4:
				return affectBoss.Value;
			case 3:
				return affectLunar.Value;
			case 6:
			case 7:
			case 8:
			case 9:
				return affectVoid.Value;
			default:
				return true;
			}
		}

		private static bool IsTierlessOrHidden(ItemDef itemDef)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			return (int)itemDef.tier == 5 || itemDef.hidden;
		}

		private static bool IsTemporaryItem(ItemDef itemDef)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)itemDef == (Object)null)
			{
				return false;
			}
			ItemTier tier = itemDef.tier;
			string text = ((object)(ItemTier)(ref tier)).ToString();
			string text2 = ((Object)itemDef).name ?? string.Empty;
			string text3 = itemDef.nameToken ?? string.Empty;
			string text4 = text2.ToLowerInvariant();
			string text5 = text3.ToLowerInvariant();
			if (text.IndexOf("Food", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if (text.IndexOf("Temp", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Temporary", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if (text4.Contains("temp") || text4.Contains("temporary") || text5.Contains("temp") || text5.Contains("temporary"))
			{
				return true;
			}
			if (itemDef.hidden)
			{
				return true;
			}
			return false;
		}

		private static string GetItemDebugName(ItemDef itemDef)
		{
			if ((Object)(object)itemDef == (Object)null)
			{
				return "<null itemDef>";
			}
			string text = ((Object)itemDef).name ?? "<no name>";
			string text2 = itemDef.nameToken ?? "<no nameToken>";
			return text + " / " + text2;
		}

		private void LogLoadedArtifacts()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Total Artifacts Loaded: {ArtifactCatalog.artifactCount}");
			for (int i = 0; i < ArtifactCatalog.artifactCount; i++)
			{
				ArtifactDef artifactDef = ArtifactCatalog.GetArtifactDef((ArtifactIndex)i);
				if ((Object)(object)artifactDef != (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Artifact: " + artifactDef.cachedName));
				}
			}
		}

		private static void LogDebug(string message)
		{
			if (debugLogging != null && debugLogging.Value)
			{
				Debug.Log((object)("[ExponentialItemsReloaded] " + message));
			}
		}
	}
}