Decompiled source of ItemStringParser v2.0.0

ItemStringParser.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using HG.Reflection;
using Microsoft.CodeAnalysis;
using R2API.Utils;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ItemStringParser")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+af20de05a04b3d8913164502ab96fb02853c5797")]
[assembly: AssemblyProduct("ItemStringParser")]
[assembly: AssemblyTitle("ItemStringParser")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[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 ItemStringParser
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Def.ItemStringParser", "ItemStringParser", "2.0.0")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class ItemStringParser : BaseUnityPlugin
	{
		private class ItemStringEntry
		{
			public string itemKey;

			public int repeat = 1;

			public int multiplier = 1;

			public float weight = 1f;
		}

		public enum ItemStringFormat
		{
			DEFAULT,
			WEIGHTED_OR_ONLY
		}

		public const string PluginGUID = "Def.ItemStringParser";

		public const string PluginAuthor = "Def";

		public const string PluginName = "ItemStringParser";

		public const string PluginVersion = "2.0.0";

		private static readonly Regex tokenPattern = new Regex("(?:(\\d+)\\s*x\\s*)?(\\w+)", RegexOptions.IgnoreCase);

		private static Dictionary<string, AsyncOperationHandle<BasicPickupDropTable>> loadedDropTables = new Dictionary<string, AsyncOperationHandle<BasicPickupDropTable>>();

		private static readonly Dictionary<string, string> dropTables = InitDropTables();

		public static PluginInfo PInfo { get; private set; }

		private static BasicPickupDropTable GetDroptable(string droptable)
		{
			//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)
			//IL_002c: 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)
			loadedDropTables[droptable] = loadedDropTables.GetValueOrDefault(droptable, Addressables.LoadAssetAsync<BasicPickupDropTable>((object)dropTables[droptable]));
			return loadedDropTables[droptable].WaitForCompletion();
		}

		private static Dictionary<string, string> InitDropTables()
		{
			Dictionary<string, string> dropTables = new Dictionary<string, string>();
			Add("RoR2/Base/CasinoChest/dtCasinoChest.asset");
			Add("RoR2/Base/CategoryChest/dtSmallChestDamage.asset");
			Add("RoR2/Base/CategoryChest/dtSmallChestHealing.asset");
			Add("RoR2/Base/CategoryChest/dtSmallChestUtility.asset");
			Add("RoR2/Base/Chest1/dtChest1.asset");
			Add("RoR2/Base/Chest2/dtChest2.asset");
			Add("RoR2/Base/Common/dtAISafeTier1Item.asset");
			Add("RoR2/Base/Common/dtAISafeTier2Item.asset");
			Add("RoR2/Base/Common/dtAISafeTier3Item.asset");
			Add("RoR2/Base/Common/dtEquipment.asset");
			Add("RoR2/Base/Common/dtTier1Item.asset");
			Add("RoR2/Base/Common/dtTier2Item.asset");
			Add("RoR2/Base/Common/dtTier3Item.asset");
			Add("RoR2/Base/Common/dtVoidChest.asset");
			Add("RoR2/Base/Duplicator/dtDuplicatorTier1.asset");
			Add("RoR2/Base/DuplicatorLarge/dtDuplicatorTier2.asset");
			Add("RoR2/Base/DuplicatorMilitary/dtDuplicatorTier3.asset");
			Add("RoR2/Base/DuplicatorWild/dtDuplicatorWild.asset");
			Add("RoR2/Base/GoldChest/dtGoldChest.asset");
			Add("RoR2/Base/LunarChest/dtLunarChest.asset");
			Add("RoR2/Base/MonsterTeamGainsItems/dtMonsterTeamTier1Item.asset");
			Add("RoR2/Base/MonsterTeamGainsItems/dtMonsterTeamTier2Item.asset");
			Add("RoR2/Base/MonsterTeamGainsItems/dtMonsterTeamTier3Item.asset");
			Add("RoR2/Base/Sacrifice/dtSacrificeArtifact.asset");
			Add("RoR2/Base/ShrineChance/dtShrineChance.asset");
			Add("RoR2/Base/TreasureCache/dtLockbox.asset");
			Add("RoR2/CommandChest/dtCommandChest.asset");
			Add("RoR2/DLC1/CategoryChest2/dtCategoryChest2Damage.asset");
			Add("RoR2/DLC1/CategoryChest2/dtCategoryChest2Healing.asset");
			Add("RoR2/DLC1/CategoryChest2/dtCategoryChest2Utility.asset");
			Add("RoR2/DLC1/GameModes/InfiniteTowerRun/ITAssets/dtITBossWave.asset");
			Add("RoR2/DLC1/GameModes/InfiniteTowerRun/ITAssets/dtITDefaultWave.asset");
			Add("RoR2/DLC1/GameModes/InfiniteTowerRun/ITAssets/dtITLunar.asset");
			Add("RoR2/DLC1/GameModes/InfiniteTowerRun/ITAssets/dtITSpecialBossWave.asset");
			Add("RoR2/DLC1/GameModes/InfiniteTowerRun/ITAssets/dtITVoid.asset");
			Add("RoR2/DLC1/TreasureCacheVoid/dtVoidLockbox.asset");
			Add("RoR2/DLC1/VoidCamp/dtVoidCamp.asset");
			Add("RoR2/DLC1/VoidTriple/dtVoidTriple.asset");
			Add("RoR2/DLC2/AurelioniteHeartPickupDropTable.asset");
			Add("RoR2/DLC2/dtShrineHalcyoniteTier1.asset");
			Add("RoR2/DLC2/dtShrineHalcyoniteTier2.asset");
			Add("RoR2/DLC2/dtShrineHalcyoniteTier3.asset");
			Add("RoR2/DLC2/GeodeRewardDropTable.asset");
			Add("RoR2/DLC2/Items/ExtraShrineItem/dtChanceDoll.asset");
			Add("RoR2/DLC2/Items/ItemDropChanceOnKill/dtSonorousEcho.asset");
			Add("RoR2/DLC3/Drifter/dtSalvage.asset");
			Add("RoR2/DLC3/DrifterBagChest/dtDrifterBagChest.asset");
			Add("RoR2/DLC3/Drones/dtJunkDrone.asset");
			Add("RoR2/DLC3/SolusHeart/dtSolusHeart.asset");
			Add("RoR2/DLC3/TemporaryItemsDistributor/dtTemporaryItemsDistributor.asset");
			return dropTables;
			void Add(string path)
			{
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
				dropTables.Add(fileNameWithoutExtension, path);
			}
		}

		public static T GetRandom<T>(List<T> list, T defaultValue)
		{
			if (list == null || list.Count == 0)
			{
				return defaultValue;
			}
			return list[Random.RandomRangeInt(0, list.Count)];
		}

		private static string GenerateRandomString(int length = 12)
		{
			Random random = new Random();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("Set_");
			for (int i = 0; i < length; i++)
			{
				stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[random.Next("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".Length)]);
			}
			return stringBuilder.ToString();
		}

		private static (string replacedString, Dictionary<string, string> replacements) ReplaceOuterBraces(string input)
		{
			StringBuilder stringBuilder = new StringBuilder();
			int num = 0;
			List<(int, int)> list = new List<(int, int)>();
			for (int i = 0; i < input.Length; i++)
			{
				if (input[i] == '{')
				{
					if (num == 0)
					{
						list.Add((i, -1));
					}
					num++;
				}
				else if (input[i] == '}')
				{
					num--;
					if (num == 0)
					{
						(int, int) tuple = list[list.Count - 1];
						list[list.Count - 1] = (tuple.Item1, i);
					}
				}
			}
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			int num2 = 0;
			foreach (var item in list)
			{
				stringBuilder.Append(input.Substring(num2, item.Item1 - num2));
				string text = input.Substring(item.Item1, item.Item2 - item.Item1 + 1);
				string value = text.Substring(1, text.Length - 2);
				string text2;
				do
				{
					text2 = GenerateRandomString();
				}
				while (dictionary.ContainsKey(text2));
				dictionary[text2] = value;
				stringBuilder.Append(text2);
				num2 = item.Item2 + 1;
			}
			stringBuilder.Append(input.Substring(num2));
			return (stringBuilder.ToString(), dictionary);
		}

		public static PickupIndex ResolveItemKey(string itemkey, bool availableOnly = true)
		{
			//IL_002d: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<PickupIndex, int> dictionary = new Dictionary<PickupIndex, int>();
			ResolveItemKey(itemkey, 1, dictionary, null, availableOnly);
			foreach (var (val2, num2) in dictionary)
			{
				if (num2 > 0 && val2 != PickupIndex.none)
				{
					return val2;
				}
			}
			return PickupIndex.none;
		}

		private static bool ResolveItemKey(string itemkey, int repeat, Dictionary<PickupIndex, int> resolvedItems, ManualLogSource log, bool availableOnly)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Invalid comparison between Unknown and I4
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Invalid comparison between Unknown and I4
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: 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_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: 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_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			List<PickupIndex> list = new List<PickupIndex>();
			string[] array = itemkey.Split("!");
			itemkey = array[0].Trim();
			for (int i = 1; i < array.Length; i++)
			{
				string text = array[i].Trim();
				PickupIndex val = PickupCatalog.FindPickupIndex(text);
				if (val != PickupIndex.none)
				{
					list.Add(val);
				}
				else
				{
					HandleWarning(log, "ResolveItemKey: Could not get pickup from blacklisted item: " + text);
				}
			}
			List<PickupIndex> list2 = null;
			switch (itemkey.ToLower())
			{
			case "tier1":
				list2 = Run.instance.availableTier1DropList.Except(list).ToList();
				break;
			case "tier2":
				list2 = Run.instance.availableTier2DropList.Except(list).ToList();
				break;
			case "tier3":
				list2 = Run.instance.availableTier3DropList.Except(list).ToList();
				break;
			case "boss":
				list2 = Run.instance.availableBossDropList.Except(list).ToList();
				break;
			case "lunar":
				list2 = Run.instance.availableLunarCombinedDropList.Except(list).ToList();
				break;
			case "voidtier1":
				list2 = Run.instance.availableVoidTier1DropList.Except(list).ToList();
				break;
			case "voidtier2":
				list2 = Run.instance.availableVoidTier2DropList.Except(list).ToList();
				break;
			case "voidtier3":
				list2 = Run.instance.availableVoidTier3DropList.Except(list).ToList();
				break;
			case "voidboss":
				list2 = Run.instance.availableVoidBossDropList.Except(list).ToList();
				break;
			case "foodtier":
				list2 = Run.instance.availableFoodTierDropList.Except(list).ToList();
				break;
			}
			if (list2 != null)
			{
				while (repeat > 0)
				{
					PickupIndex random = GetRandom(list2, PickupIndex.none);
					if (random == PickupIndex.none)
					{
						HandleWarning(log, "ResolveItemKey: Could not get pickup from item tier: " + itemkey + ", as all candidates are either disabled or locked behind expansion");
						return false;
					}
					resolvedItems[random] = resolvedItems.GetValueOrDefault(random) + 1;
					repeat--;
				}
				return true;
			}
			if (dropTables.ContainsKey(itemkey))
			{
				BasicPickupDropTable droptable = GetDroptable(itemkey);
				WeightedSelection<UniquePickup> val2 = new WeightedSelection<UniquePickup>(8);
				ChoiceInfo<UniquePickup>[] choices = droptable.selector.choices;
				for (int j = 0; j < choices.Length; j++)
				{
					ChoiceInfo<UniquePickup> val3 = choices[j];
					PickupIndex pickupIndex = val3.value.pickupIndex;
					if (!list.Contains(pickupIndex) && Run.instance.IsPickupAvailable(pickupIndex))
					{
						val2.AddChoice(val3);
					}
				}
				if (val2.Count == 0)
				{
					HandleWarning(log, "ResolveItemKey: Could not get pickup from droptable: " + itemkey + ", as all candidates are either disabled or locked behind expansion");
					return false;
				}
				while (repeat > 0)
				{
					UniquePickup val4 = val2.Evaluate(Random.Range(0f, 1f));
					if (((UniquePickup)(ref val4)).Equals(UniquePickup.none))
					{
						HandleWarning(log, "ResolveItemKey: Could not get pickup from droptable: " + itemkey);
						return false;
					}
					resolvedItems[val4.pickupIndex] = resolvedItems.GetValueOrDefault(val4.pickupIndex) + 1;
					repeat--;
				}
				return true;
			}
			ItemIndex val5 = ItemCatalog.FindItemIndex(itemkey);
			if ((int)val5 != -1)
			{
				if (availableOnly && !Run.instance.IsItemAvailable(val5))
				{
					HandleWarning(log, "ResolveItemKey: " + itemkey + " cannot be resolved as it is disabled in this run.");
					return false;
				}
				PickupIndex key = PickupCatalog.FindPickupIndex(val5);
				resolvedItems[key] = resolvedItems.GetValueOrDefault(key) + repeat;
				return true;
			}
			EquipmentIndex val6 = EquipmentCatalog.FindEquipmentIndex(itemkey);
			if ((int)val6 != -1)
			{
				if (availableOnly && !Run.instance.IsEquipmentAvailable(val6))
				{
					HandleWarning(log, "ResolveItemKey: " + itemkey + " cannot be resolved as it is disabled in this run.");
					return false;
				}
				PickupIndex key2 = PickupCatalog.FindPickupIndex(val6);
				resolvedItems[key2] = resolvedItems.GetValueOrDefault(key2) + repeat;
				return true;
			}
			HandleWarning(log, "ResolveItemKey: Could not find item key: " + itemkey);
			return false;
		}

		private static void HandleWarning(ManualLogSource log, string message)
		{
			if (log == null)
			{
				throw new ArgumentException(message);
			}
			log.LogWarning((object)message);
		}

		private static bool ParseItemString(string itemString, Dictionary<PickupIndex, int> resolvedItems, ManualLogSource log, bool availableOnly, int index, int repeat)
		{
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(itemString))
			{
				return true;
			}
			ItemStringFormat itemStringFormat = ItemStringFormat.DEFAULT;
			itemString = itemString.Trim();
			Dictionary<string, string> dictionary;
			(itemString, dictionary) = ReplaceOuterBraces(itemString);
			string[] array;
			bool flag;
			if (itemStringFormat == ItemStringFormat.WEIGHTED_OR_ONLY)
			{
				array = itemString.Split('|');
				flag = false;
			}
			else
			{
				if (itemString.Contains("&") && itemString.Contains("|"))
				{
					HandleWarning(log, "ParseItemStringReward: Cannot have & and | in the same group: '" + itemString + "'");
					return false;
				}
				if (itemString.Contains("|"))
				{
					array = itemString.Split('|');
					flag = false;
				}
				else
				{
					array = itemString.Split('&');
					flag = true;
				}
			}
			WeightedSelection<ItemStringEntry> val = new WeightedSelection<ItemStringEntry>(8);
			List<ItemStringEntry> list = new List<ItemStringEntry>();
			for (int i = 0; i < array.Length; i++)
			{
				ItemStringEntry itemStringEntry = new ItemStringEntry();
				string text = array[i];
				string text2 = text.Trim();
				string[] array2 = text2.Split(":", 2);
				text2 = array2[0].Trim();
				if (array2.Length > 1)
				{
					itemStringEntry.weight = float.Parse(array2[1].Trim());
				}
				if (itemStringFormat == ItemStringFormat.WEIGHTED_OR_ONLY)
				{
					itemStringEntry.itemKey = text2;
				}
				else
				{
					array2 = text2.Split("*", 2);
					text2 = array2[0].Trim();
					if (array2.Length > 1)
					{
						itemStringEntry.multiplier = int.Parse(array2[1].Trim());
					}
					Match match = tokenPattern.Match(text2);
					if (!match.Success)
					{
						HandleWarning(log, "Cannot parse segment '" + text.Trim() + "'");
						return false;
					}
					if (match.Groups[1].Success)
					{
						itemStringEntry.repeat = int.Parse(match.Groups[1].Value);
					}
					if (!match.Groups[2].Success)
					{
						HandleWarning(log, "Cannot parse segment '" + text.Trim() + "'");
						return false;
					}
					itemStringEntry.itemKey = match.Groups[2].Value;
				}
				val.AddChoice(itemStringEntry, itemStringEntry.weight);
				list.Add(itemStringEntry);
			}
			while (repeat > 0)
			{
				PickupIndex key;
				int value;
				if (flag)
				{
					foreach (ItemStringEntry item in list)
					{
						Dictionary<PickupIndex, int> dictionary2 = new Dictionary<PickupIndex, int>();
						if (!((!dictionary.ContainsKey(item.itemKey)) ? ResolveItemKey(item.itemKey, item.repeat, dictionary2, log, availableOnly) : ParseItemString(dictionary[item.itemKey], dictionary2, log, availableOnly, -1, item.repeat)))
						{
							continue;
						}
						foreach (KeyValuePair<PickupIndex, int> item2 in dictionary2)
						{
							item2.Deconstruct(out key, out value);
							PickupIndex key2 = key;
							int num = value;
							resolvedItems[key2] = resolvedItems.GetValueOrDefault(key2) + num * item.multiplier;
						}
					}
				}
				else
				{
					bool flag2 = false;
					int num2 = 10;
					int num3 = 0;
					while (!flag2)
					{
						num2--;
						if (num2 == 0)
						{
							HandleWarning(log, "Could not resolve to item rewards: " + itemString);
							return false;
						}
						ItemStringEntry itemStringEntry2 = ((index < 0) ? val.Evaluate(Random.Range(0f, 1f)) : list[(index + num3) % list.Count]);
						Dictionary<PickupIndex, int> dictionary3 = new Dictionary<PickupIndex, int>();
						flag2 = ((!dictionary.ContainsKey(itemStringEntry2.itemKey)) ? ResolveItemKey(itemStringEntry2.itemKey, itemStringEntry2.repeat, dictionary3, log, availableOnly) : ParseItemString(dictionary[itemStringEntry2.itemKey], dictionary3, log, availableOnly, -1, itemStringEntry2.repeat));
						if (flag2)
						{
							foreach (KeyValuePair<PickupIndex, int> item3 in dictionary3)
							{
								item3.Deconstruct(out key, out value);
								PickupIndex key3 = key;
								int num4 = value;
								resolvedItems[key3] = resolvedItems.GetValueOrDefault(key3) + num4 * itemStringEntry2.multiplier;
							}
						}
						else
						{
							num3++;
						}
					}
				}
				repeat--;
			}
			return true;
		}

		public static void ParseItemStringStrict(string itemString, Dictionary<PickupIndex, int> resolvedItems, bool availableOnly = true, int index = -1)
		{
			ParseItemString(itemString, resolvedItems, null, availableOnly, index, 1);
		}

		public static bool ParseItemString(string itemString, Dictionary<PickupIndex, int> resolvedItems, ManualLogSource log, bool availableOnly = true, int index = -1)
		{
			return ParseItemString(itemString, resolvedItems, log, availableOnly, index, 1);
		}

		public static void WriteDropTablesMarkdownFile(string filePath)
		{
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: 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_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: 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_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: 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_03fc: Unknown result type (might be due to invalid IL or missing references)
			using StreamWriter streamWriter = new StreamWriter(filePath);
			streamWriter.WriteLine("# Survivors");
			string[] array = SurvivorCatalog.allSurvivorDefs.Select((SurvivorDef survivor) => survivor.cachedName).ToArray();
			foreach (string text in array)
			{
				streamWriter.WriteLine(text ?? "");
			}
			streamWriter.WriteLine("# Bodies");
			array = BodyCatalog.allBodyPrefabs.Select((GameObject prefab) => ((Object)prefab).name).ToArray();
			foreach (string text2 in array)
			{
				streamWriter.WriteLine(text2 ?? "");
			}
			string text3 = "";
			streamWriter.WriteLine("# DropTables");
			streamWriter.WriteLine("| Drop Table Name                  | tier1 | tier2 | tier3 | boss | lunarEquipment | lunarItem | lunarCombined | equipment | voidTier1 | voidTier2 | voidTier3 | voidBoss | foodTier | powerShapes | canDropBeReplaced | requiredItemTags | bannedItemTags |");
			streamWriter.WriteLine("|----------------------------------|-------|-------|-------|------|----------------|-----------|---------------|-----------|-----------|-----------|-----------|----------|----------|-------------|-------------------|------------------|----------------|");
			foreach (KeyValuePair<string, string> dropTable in dropTables)
			{
				string key = dropTable.Key;
				text3 = ((!string.IsNullOrWhiteSpace(text3)) ? (text3 + " | \"" + key + "\"") : ("\"" + key + "\""));
				BasicPickupDropTable droptable = GetDroptable(key);
				string text4 = ((PickupDropTable)droptable).canDropBeReplaced.ToString();
				string text5 = string.Join(", ", droptable.requiredItemTags.Select((ItemTag e) => ((object)(ItemTag)(ref e)).ToString()));
				string text6 = string.Join(", ", droptable.bannedItemTags.Select((ItemTag e) => ((object)(ItemTag)(ref e)).ToString()));
				string text7 = droptable.tier1Weight.ToString();
				string text8 = droptable.tier2Weight.ToString();
				string text9 = droptable.tier3Weight.ToString();
				string text10 = droptable.bossWeight.ToString();
				string text11 = droptable.lunarEquipmentWeight.ToString();
				string text12 = droptable.lunarItemWeight.ToString();
				string text13 = droptable.lunarCombinedWeight.ToString();
				string text14 = droptable.equipmentWeight.ToString();
				string text15 = droptable.voidTier1Weight.ToString();
				string text16 = droptable.voidTier2Weight.ToString();
				string text17 = droptable.voidTier3Weight.ToString();
				string text18 = droptable.voidBossWeight.ToString();
				string text19 = droptable.foodTierWeight.ToString();
				string text20 = droptable.powerShapesWeight.ToString();
				streamWriter.WriteLine($"| {key,-32} | {text7} | {text8} | {text9} | {text10} | {text11} | {text12} | {text13} | {text14} | {text15} | {text16} | {text17} | {text18} | {text19} | {text20} | {text4} | {text5} | {text6} |");
			}
			string text21 = "";
			ItemIndex val = (ItemIndex)0;
			for (ItemIndex val2 = (ItemIndex)ItemCatalog.itemCount; val < val2; val = (ItemIndex)(val + 1))
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(val);
				if (!itemDef.tags.Contains((ItemTag)25) && itemDef.DoesNotContainTag((ItemTag)9))
				{
					text21 = ((!string.IsNullOrWhiteSpace(text21)) ? (text21 + " | \"" + ((Object)itemDef).name + "\"") : ("\"" + ((Object)itemDef).name + "\""));
				}
			}
			EquipmentIndex val3 = (EquipmentIndex)0;
			for (EquipmentIndex val4 = (EquipmentIndex)EquipmentCatalog.equipmentCount; val3 < val4; val3 = (EquipmentIndex)(val3 + 1))
			{
				EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(val3);
				if (equipmentDef.canDrop)
				{
					text21 = ((!string.IsNullOrWhiteSpace(text21)) ? (text21 + " | \"" + ((Object)equipmentDef).name + "\"") : ("\"" + ((Object)equipmentDef).name + "\""));
				}
			}
			streamWriter.WriteLine("# EBNF");
			streamWriter.WriteLine("```");
			streamWriter.WriteLine("<itemname>  ::= " + text21);
			streamWriter.WriteLine("<droptable> ::= " + text3);
			streamWriter.WriteLine("```");
		}
	}
}