Decompiled source of ReforgedPotential v2.0.4

ReforgedPotential.dll

Decompiled 14 hours 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.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ReforgedPotential")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReforgedPotential")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("2.0.4")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.4.0")]
namespace ReforgedPotential;

[BepInPlugin("akuichi.ReforgedPotential", "Reforged Potential", "2.0.4")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[SynchronizationMode(/*Could not decode attribute arguments.*/)]
public class ReforgedPotential : BaseUnityPlugin
{
	public static class ChatHelpers
	{
		public static void ResetChatHideTimer()
		{
			Chat.instance.m_hideTimer = 0f;
		}
	}

	[HarmonyPatch(typeof(InventoryGui))]
	private static class InventoryGuiPatch
	{
		private class DoCraftingState
		{
			public UpgradeSnapshot Snapshot;
		}

		private class UpgradeSnapshot
		{
			public int OriginalQuality;

			public string SharedName;

			public int Variant;

			public Vector2i GridPos;
		}

		private enum UpgradeOutcome
		{
			Upgraded,
			Degraded,
			Destroyed,
			ReturnedIngredients,
			Unchanged,
			Unknown
		}

		private static Dictionary<string, string> originalRequirements = new Dictionary<string, string>();

		private static int currentEquivalentTier;

		[HarmonyPrefix]
		[HarmonyPatch("DoCrafting")]
		private static bool DoCraftingPrefix(InventoryGui __instance, Player player, out DoCraftingState __state)
		{
			//IL_0056: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			__state = null;
			try
			{
				CraftingStation currentCraftingStation = player.GetCurrentCraftingStation();
				bool upgrader = currentCraftingStation.m_upgrader;
				Logger.LogDebug((object)$"DoCraftingPrefix: Player is at upgrader station: {upgrader}, station name: {((Object)currentCraftingStation).name}");
				if (!upgrader)
				{
					return true;
				}
				int num = int.MinValue;
				string text = null;
				string sharedName = null;
				int craftVariant = __instance.m_craftVariant;
				Vector2i val = default(Vector2i);
				List<string> list = new List<string>();
				ItemData val2 = null;
				try
				{
					val2 = __instance.m_craftUpgradeItem;
					if (val2 != null)
					{
						num = val2.m_quality;
						val = val2.m_gridPos;
						text = ((Object)val2.m_dropPrefab).name;
						sharedName = val2.m_shared.m_name;
						Logger.LogDebug((object)$"DoCraftingPrefix: Captured upgrade item snapshot: prefab={text}, quality={num}, gridPos={val}, variant={craftVariant}");
					}
				}
				catch
				{
				}
				if (val2 != null)
				{
					__state = new DoCraftingState
					{
						Snapshot = new UpgradeSnapshot
						{
							OriginalQuality = num,
							SharedName = sharedName,
							GridPos = val,
							Variant = craftVariant
						}
					};
					Logger.LogDebug((object)"DoCraftingPrefix: Created DoCraftingState with snapshot of upgrade item.");
				}
			}
			catch (Exception arg)
			{
				Logger.LogWarning((object)$"DoCrafting prefix snapshot exception: {arg}");
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("DoCrafting")]
		private static void DoCraftingPostfix(object __instance, DoCraftingState __state)
		{
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (__state?.Snapshot == null)
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				CraftingStation currentCraftingStation = localPlayer.GetCurrentCraftingStation();
				if (!((Object)(object)currentCraftingStation != (Object)null) || !currentCraftingStation.m_upgrader)
				{
					return;
				}
				int x = __state.Snapshot.GridPos.x;
				int y = __state.Snapshot.GridPos.y;
				ItemData itemAt = ((Humanoid)localPlayer).GetInventory().GetItemAt(x, y);
				UpgradeOutcome upgradeOutcome = UpgradeOutcome.Unknown;
				UpgradeSnapshot snapshot = __state.Snapshot;
				if (itemAt != null)
				{
					if (itemAt.m_shared.m_name != snapshot.SharedName)
					{
						Logger.LogInfo((object)("DoCraftingPostfix: Upgrade result prefab name mismatch, assume its destroyed (original=" + snapshot.SharedName + ", new=" + itemAt.m_shared.m_name + ")"));
						upgradeOutcome = UpgradeOutcome.ReturnedIngredients;
					}
					else
					{
						Logger.LogDebug((object)($"DoCraftingPostfix: Upgrade result item found at grid position ({x}," + $"{y}) with quality {itemAt.m_quality} (original={snapshot.OriginalQuality})"));
						if (itemAt.m_quality > snapshot.OriginalQuality)
						{
							upgradeOutcome = UpgradeOutcome.Upgraded;
						}
						else if (itemAt.m_quality < snapshot.OriginalQuality)
						{
							upgradeOutcome = UpgradeOutcome.Degraded;
							if (itemAt.m_quality < 1)
							{
								Logger.LogDebug((object)"DoCraftingPostfix: Item degraded below 1, replacing with new item.");
								string name = ((Object)itemAt.m_dropPrefab).name;
								int stack = itemAt.m_stack;
								int originalQuality = snapshot.OriginalQuality;
								int variant = itemAt.m_variant;
								long crafterID = itemAt.m_crafterID;
								string crafterName = itemAt.m_crafterName;
								bool cheated = itemAt.m_cheated;
								((Humanoid)localPlayer).GetInventory().RemoveItem(itemAt);
								ItemData val = ((Humanoid)localPlayer).GetInventory().AddItem(name, stack, originalQuality, variant, crafterID, crafterName, snapshot.GridPos, cheated, false, true);
								Logger.LogDebug((object)("DoCraftingPostfix: Replacement item added to inventory: " + ((Object)val.m_dropPrefab).name + " with quality " + val.m_quality));
								MethodInfo methodInfo = AccessTools.Method(typeof(InventoryGui), "UpdateCraftingPanel", (Type[])null, (Type[])null);
								methodInfo.Invoke(__instance, new object[1] { false });
							}
						}
						else
						{
							upgradeOutcome = UpgradeOutcome.ReturnedIngredients;
						}
					}
				}
				else
				{
					Logger.LogInfo((object)$"DoCraftingPostfix: No item found at grid position ({x},{y}) after crafting, assuming destroyed");
					upgradeOutcome = UpgradeOutcome.ReturnedIngredients;
				}
				string playerName = localPlayer.GetPlayerName();
				string text = __state.Snapshot.SharedName ?? "<unknown item>";
				text = Localization.instance.Localize(text);
				int level = snapshot.OriginalQuality + 1;
				bool success = upgradeOutcome == UpgradeOutcome.Upgraded;
				BroadcastUpgradeResult(playerName, text, level, success);
			}
			catch (Exception)
			{
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("SetupCrafting")]
		private static void SetupCraftingPrefix(ref float ___m_upgraderDuration, ref float ___m_upgraderDurationPerLevel)
		{
			___m_upgraderDuration = UpgradeBaseDuration.Value;
			___m_upgraderDurationPerLevel = UpgradeDurationIncreasePerLevel.Value;
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnCraftPressed")]
		private static bool OnCraftPressedPrefix(InventoryGui __instance)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!EnableBossProgression.Value)
				{
					return true;
				}
				RecipeDataPair selectedRecipe = __instance.m_selectedRecipe;
				Recipe recipe = ((RecipeDataPair)(ref selectedRecipe)).Recipe;
				ItemData itemData = ((RecipeDataPair)(ref selectedRecipe)).ItemData;
				if ((Object)(object)recipe == (Object)null)
				{
					return true;
				}
				Player localPlayer = Player.m_localPlayer;
				CraftingStation currentCraftingStation = localPlayer.GetCurrentCraftingStation();
				if (!((Object)(object)currentCraftingStation != (Object)null) || !currentCraftingStation.m_upgrader)
				{
					return true;
				}
				if (itemData != null)
				{
					Requirement[] array = recipe.m_resources ?? Array.Empty<Requirement>();
					foreach (Requirement val in array)
					{
						if (val == null || (Object)(object)val.m_resItem == (Object)null)
						{
							continue;
						}
						string name = ((Object)val.m_resItem).name;
						if (!name.Contains("Upgrader"))
						{
							Logger.LogDebug((object)("Iterating resources needed to upgrade for " + itemData.m_shared.m_name + " skipping non upgrader resource: " + name + "."));
							continue;
						}
						Logger.LogDebug((object)("Iterating resources needed to upgrade for " + itemData.m_shared.m_name + " found upgrader resource: " + name + "."));
						int maxBossTier = UpgradeHelper.GetMaxBossTier();
						originalRequirements.TryGetValue(((Object)recipe.m_item).name, out var value);
						Logger.LogInfo((object)("original resource oncraft prefix " + value));
						int equipmentTier = UpgradeHelper.GetEquipmentTier(value);
						if (equipmentTier < 0)
						{
							Logger.LogWarning((object)("Could not determine equipment tier for upgrader '" + value + "'."));
							continue;
						}
						int maxUpgradeLevel = UpgradeHelper.GetMaxUpgradeLevel(equipmentTier, maxBossTier);
						int quality = itemData.m_quality;
						if (quality >= maxUpgradeLevel)
						{
							int requiredBossForNextUpgrade = UpgradeHelper.GetRequiredBossForNextUpgrade(equipmentTier, quality);
							Logger.LogDebug((object)("Player attempted to upgrade " + itemData.m_shared.m_name + " " + $"from quality {quality} to {quality + 1}. " + $"Item tier={equipmentTier}, " + $"highest boss tier={maxBossTier}, " + $"max allowed={maxUpgradeLevel}, " + $"required boss={requiredBossForNextUpgrade}."));
							string value2;
							string text = ((requiredBossForNextUpgrade != -1 && bossNames.TryGetValue(requiredBossForNextUpgrade, out value2)) ? value2 : null);
							Logger.LogDebug((object)("Player attempted to upgrade " + itemData.m_shared.m_name + " " + $"from quality {quality} to {quality + 1}. " + $"Item tier={equipmentTier}, " + $"highest boss tier={maxBossTier}, " + $"max allowed={maxUpgradeLevel}, " + "required boss=" + (text ?? "none") + "."));
							if (localPlayer != null)
							{
								((Character)localPlayer).Message((MessageType)2, (text != null) ? ("Defeat " + text + " to upgrade this weapon further.") : "Max upgrade level reached!", 0, (Sprite)null, false);
							}
							return false;
						}
						return true;
					}
					return false;
				}
				return true;
			}
			catch (Exception arg)
			{
				Logger.LogWarning((object)$"OnCraftPressed prefix exception: {arg}");
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetRecipe")]
		private static void SetRecipePostfix(InventoryGui __instance)
		{
			//IL_0038: 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)
			string text = "SetRecipePostfix: ";
			try
			{
				Player localPlayer = Player.m_localPlayer;
				CraftingStation currentCraftingStation = localPlayer.GetCurrentCraftingStation();
				if (!((Object)(object)currentCraftingStation != (Object)null) || !currentCraftingStation.m_upgrader)
				{
					return;
				}
				RecipeDataPair selectedRecipe = __instance.m_selectedRecipe;
				Recipe recipe = ((RecipeDataPair)(ref selectedRecipe)).Recipe;
				ItemData itemData = ((RecipeDataPair)(ref selectedRecipe)).ItemData;
				if (!originalRequirements.ContainsKey(((Object)recipe.m_item).name))
				{
					Requirement[] array = recipe.m_resources ?? Array.Empty<Requirement>();
					foreach (Requirement val in array)
					{
						if (val.m_upgraderResource)
						{
							string name = ((Object)val.m_resItem).name;
							originalRequirements.Add(((Object)recipe.m_item).name, name);
							break;
						}
					}
					originalRequirements.TryGetValue(((Object)recipe.m_item).name, out var value);
					Logger.LogDebug((object)(text + "Storing original upgrader resource for " + itemData.m_shared.m_name + " as " + value));
				}
				if ((Object)(object)recipe == (Object)null || itemData == null)
				{
					Logger.LogDebug((object)(text + "No selected recipe or item data found."));
					return;
				}
				ItemDrop val5 = default(ItemDrop);
				ItemDrop val6 = default(ItemDrop);
				ItemDrop val7 = default(ItemDrop);
				for (int j = 0; recipe.m_resources.Length > j; j++)
				{
					if (!recipe.m_resources[j].m_upgraderResource || !originalRequirements.TryGetValue(((Object)recipe.m_item).name, out var value2))
					{
						continue;
					}
					Logger.LogDebug((object)(text + "Found upgrader resource for " + itemData.m_shared.m_name + ": " + value2));
					int num = ((bossUpgradeValues != null && bossUpgradeValues.Count > 0) ? bossUpgradeValues.Keys.Max() : 8);
					Requirement val2 = recipe.m_resources[j];
					int quality = itemData.m_quality;
					int equipmentTier = UpgradeHelper.GetEquipmentTier(value2);
					int num2;
					int num3;
					if (!EnableBossProgression.Value && !EnableIdolProgression.Value)
					{
						num2 = equipmentTier;
						int maxUpgradeLevel = UpgradeHelper.GetMaxUpgradeLevel(equipmentTier, num);
						num3 = Math.Max(1, Math.Min(maxUpgradeLevel, quality));
						currentEquivalentTier = num2;
						Logger.LogDebug((object)$"{text}(BossOff/IdolOff): keeping base resource={value2}, baseTier={equipmentTier}, quality={quality}, candidateQuality={num3}");
					}
					else if (!EnableBossProgression.Value && EnableIdolProgression.Value)
					{
						int num4 = Math.Max(0, (quality - 1) / 4);
						int val3 = equipmentTier + num4;
						int val4 = ((bossUpgradeValues != null && bossUpgradeValues.Count > 0) ? bossUpgradeValues.Keys.Max() : 8);
						val3 = Math.Min(val3, val4);
						int num5 = Math.Max(0, val3 - equipmentTier);
						num2 = val3;
						int maxUpgradeLevel = 4;
						num3 = quality - num5 * 4;
						num3 = Math.Max(1, Math.Min(maxUpgradeLevel, num3));
						currentEquivalentTier = num2;
						Logger.LogDebug((object)$"{text}(BossOff/IdolOn): baseTier={equipmentTier}, quality={quality}, tierBlock={num4}, desiredTier={val3}, actualBlocksUsed={num5}, mappedTier={num2}, candidateQuality={num3}");
					}
					else if (EnableBossProgression.Value && !EnableIdolProgression.Value)
					{
						num2 = equipmentTier;
						int maxUpgradeLevel2 = UpgradeHelper.GetMaxUpgradeLevel(equipmentTier, num);
						int maxUpgradeLevel = Math.Max(1, maxUpgradeLevel2);
						num3 = Math.Max(1, Math.Min(maxUpgradeLevel, quality));
						currentEquivalentTier = num2;
						Logger.LogDebug((object)$"{text}(BossOn/IdolOff): keeping base resource={value2}, baseTier={equipmentTier}, quality={quality}, candidateQuality={num3}");
					}
					else
					{
						num2 = (currentEquivalentTier = UpgradeHelper.GetEquivalentTier(equipmentTier, quality, num));
						int maxUpgradeLevel3 = UpgradeHelper.GetMaxUpgradeLevel(equipmentTier, num);
						int maxUpgradeLevel = UpgradeHelper.GetMaxUpgradeLevel(num2, num);
						int num6 = maxUpgradeLevel3 - quality;
						num3 = maxUpgradeLevel - num6;
						num3 = Math.Max(1, Math.Min(maxUpgradeLevel, num3));
						Logger.LogDebug((object)$"{text}(Default): Base tier {equipmentTier}, quality {quality}, equivalent tier {num2}, candidateQuality {num3}.");
					}
					int num7 = Math.Max(0, num3 - 1);
					int num8 = Math.Max(1, CostScalingLevelStart.Value);
					int num9 = CostStart.Value;
					if (CostIncreaseInterval.Value > 0 && num7 >= num8)
					{
						num9 += ((num7 - num8) / CostIncreaseInterval.Value + 1) * CostIncreasePerInterval.Value;
					}
					if (!EnableIdolProgression.Value)
					{
						GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(value2);
						if ((Object)(object)itemPrefab != (Object)null && itemPrefab.TryGetComponent<ItemDrop>(ref val5))
						{
							Logger.LogInfo((object)$"{text}Keeping original resource {((Object)val5).name} and setting amount to {num9}.");
							val2.m_resItem = val5;
							val2.m_resItem.m_itemData.m_shared.m_upgradeChance = UpgradeChance.Value;
							val2.m_resItem.m_itemData.m_shared.m_breakChance = BreakChance.Value;
							val2.m_amount = num9;
						}
						else
						{
							Logger.LogError((object)(text + "Could not find prefab for original resource '" + value2 + "'."));
						}
					}
					else if (((Object)val2.m_resItem).name.Contains("Weapon"))
					{
						Logger.LogDebug((object)$"{text}Selected resource is a weapon. Setting cost to {num9} and tier to {num2}.");
						GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab($"Upgrader{num2}Weapon");
						if ((Object)(object)itemPrefab2 != (Object)null && itemPrefab2.TryGetComponent<ItemDrop>(ref val6))
						{
							Logger.LogInfo((object)$"{text}Found prefab for Upgrader{num2}Weapon. Setting resource to {((Object)val6).name} with amount {num9}.");
							val2.m_resItem = val6;
							val2.m_resItem.m_itemData.m_shared.m_upgradeChance = UpgradeChance.Value;
							val2.m_resItem.m_itemData.m_shared.m_breakChance = BreakChance.Value;
							val2.m_amount = num9;
						}
					}
					else if (((Object)val2.m_resItem).name.Contains("Armor"))
					{
						Logger.LogDebug((object)$"{text}Selected resource is armor. Setting cost to {num9} and tier to {num2}.");
						GameObject itemPrefab3 = ObjectDB.instance.GetItemPrefab($"Upgrader{num2}Armor");
						if ((Object)(object)itemPrefab3 != (Object)null && itemPrefab3.TryGetComponent<ItemDrop>(ref val7))
						{
							Logger.LogInfo((object)$"{text}Found prefab for Upgrader{num2}Armor. Setting resource to {((Object)val7).name} with amount {num9}.");
							val2.m_resItem = val7;
							val2.m_resItem.m_itemData.m_shared.m_upgradeChance = UpgradeChance.Value;
							val2.m_resItem.m_itemData.m_shared.m_breakChance = BreakChance.Value;
							val2.m_amount = num9;
						}
					}
					else
					{
						Logger.LogError((object)$"{text}Selected resource is neither weapon nor armor. Setting cost to {num9}.");
					}
				}
			}
			catch (Exception arg)
			{
				Logger.LogWarning((object)$"{text} exception: {arg}");
			}
		}
	}

	public static class UpgradeHelper
	{
		public static int GetMaxBossTier()
		{
			if (ZoneSystem.instance.CheckKey("defeated_frozenking", (GameKeyType)0, true) && ZoneSystem.instance.CheckKey("defeated_frozenking_p3", (GameKeyType)0, true))
			{
				return 8;
			}
			if (ZoneSystem.instance.CheckKey("GP_Fader", (GameKeyType)1, true))
			{
				return 7;
			}
			if (ZoneSystem.instance.CheckKey("GP_Queen", (GameKeyType)1, true))
			{
				return 6;
			}
			if (ZoneSystem.instance.CheckKey("GP_Yagluth", (GameKeyType)1, true))
			{
				return 5;
			}
			if (ZoneSystem.instance.CheckKey("GP_Moder", (GameKeyType)1, true))
			{
				return 4;
			}
			if (ZoneSystem.instance.CheckKey("GP_Bonemass", (GameKeyType)1, true))
			{
				return 3;
			}
			if (ZoneSystem.instance.CheckKey("GP_TheElder", (GameKeyType)1, true))
			{
				return 2;
			}
			if (ZoneSystem.instance.CheckKey("GP_Eikthyr", (GameKeyType)1, true))
			{
				return 1;
			}
			return 0;
		}

		public static int GetEquipmentTier(string prefabName)
		{
			if (string.IsNullOrEmpty(prefabName))
			{
				return -2;
			}
			if (prefabName.Contains("Upgrader7"))
			{
				return 7;
			}
			if (prefabName.Contains("Upgrader6"))
			{
				return 6;
			}
			if (prefabName.Contains("Upgrader5"))
			{
				return 5;
			}
			if (prefabName.Contains("Upgrader4"))
			{
				return 4;
			}
			if (prefabName.Contains("Upgrader3"))
			{
				return 3;
			}
			if (prefabName.Contains("Upgrader2"))
			{
				return 2;
			}
			if (prefabName.Contains("Upgrader1"))
			{
				return 1;
			}
			if (prefabName.Contains("Upgrader0"))
			{
				return 0;
			}
			return -1;
		}

		public static int GetMaxUpgradeLevel(int itemTier, int highestBossTier)
		{
			int num = BaseUpgradeLimit.Value;
			int num2 = itemTier + 1;
			for (int i = num2; i <= highestBossTier; i++)
			{
				if (bossUpgradeValues.TryGetValue(i, out var value))
				{
					num += value;
				}
			}
			if (itemTier == highestBossTier)
			{
				num++;
				Logger.LogDebug((object)($"GetMaxUpgradeLevel: itemTier={itemTier} matches " + $"highestBossTier={highestBossTier}, adding +1."));
			}
			return num;
		}

		public static int GetRequiredBossForNextUpgrade(int itemTier, int currentUpgrade)
		{
			int num = BaseUpgradeLimit.Value;
			Logger.LogDebug((object)$"GetRequiredBossForNextUpgrade: itemTier={itemTier}, currentUpgrade={currentUpgrade}, base={num}");
			for (int i = itemTier + 1; bossUpgradeValues.ContainsKey(i); i++)
			{
				int num2 = bossUpgradeValues[i];
				num += num2;
				string text = (bossNames.ContainsKey(i) ? bossNames[i] : "<unknown>");
				Logger.LogDebug((object)$"Checking bossTier={i}, bossValue={num2}, cumulativeUpgrade={num} (bossName={text})");
				if (currentUpgrade < num)
				{
					Logger.LogDebug((object)$"Next required bossTier={i} ({text}) to unlock upgrades beyond {currentUpgrade}.");
					return i;
				}
			}
			Logger.LogDebug((object)$"No boss tier found that unlocks upgrades beyond currentUpgrade={currentUpgrade}. cumulativeUpgrade={num}");
			return -1;
		}

		public static int GetEquivalentTier(int baseItemTier, int qualityLevel, int? highestBossTier = null)
		{
			int num = ((bossUpgradeValues != null && bossUpgradeValues.Count > 0) ? bossUpgradeValues.Keys.Max() : 0);
			int num2 = highestBossTier ?? num;
			if (baseItemTier > num2)
			{
				baseItemTier = num2;
			}
			int maxUpgradeLevel = GetMaxUpgradeLevel(baseItemTier, num2);
			int num3 = maxUpgradeLevel - qualityLevel;
			Logger.LogDebug((object)($"GetEquivalentTier: baseTier={baseItemTier}, " + $"quality={qualityLevel}, " + $"currentMax={maxUpgradeLevel}, " + $"distanceFromMax={num3}, " + $"maxBossTier={num2}"));
			for (int num4 = num2; num4 >= 0; num4--)
			{
				int maxUpgradeLevel2 = GetMaxUpgradeLevel(num4, num2);
				int num5 = maxUpgradeLevel2 - num3;
				if (num5 >= 1 && num5 <= maxUpgradeLevel2)
				{
					Logger.LogDebug((object)($"GetEquivalentTier: baseTier={baseItemTier}, " + $"quality={qualityLevel} => " + $"candidateTier={num4}, " + $"candidateQuality={num5}"));
					return num4;
				}
			}
			Logger.LogDebug((object)("GetEquivalentTier: no equivalent tier found for " + $"baseTier={baseItemTier}, quality={qualityLevel}; " + "returning baseTier."));
			return baseItemTier;
		}
	}

	public const string PluginGUID = "akuichi.ReforgedPotential";

	public const string PluginName = "Reforged Potential";

	public const string PluginVersion = "2.0.4";

	private readonly Harmony harmony = new Harmony("akuichi.ReforgedPotential");

	private const string Boss1Key = "GP_Eikthyr";

	private const string Boss2Key = "GP_TheElder";

	private const string Boss3Key = "GP_Bonemass";

	private const string Boss4Key = "GP_Moder";

	private const string Boss5Key = "GP_Yagluth";

	private const string Boss6Key = "GP_Queen";

	private const string Boss7Key = "GP_Fader";

	internal static ConfigEntry<bool> EnableServerSync;

	internal static ConfigEntry<bool> EnableBossProgression;

	internal static ConfigEntry<int> BaseUpgradeLimit;

	internal static ConfigEntry<int> Boss1MaxUpgradeLevel;

	internal static ConfigEntry<int> Boss2MaxUpgradeLevel;

	internal static ConfigEntry<int> Boss3MaxUpgradeLevel;

	internal static ConfigEntry<int> Boss4MaxUpgradeLevel;

	internal static ConfigEntry<int> Boss5MaxUpgradeLevel;

	internal static ConfigEntry<int> Boss6MaxUpgradeLevel;

	internal static ConfigEntry<int> Boss7MaxUpgradeLevel;

	internal static ConfigEntry<int> Boss8MaxUpgradeLevel;

	internal static Dictionary<int, int> bossUpgradeValues;

	internal static Dictionary<int, string> bossNames = new Dictionary<int, string>
	{
		{ -1, "No More Further Boss" },
		{ 0, "No Boss Defeated" },
		{ 1, "Eikthyr" },
		{ 2, "Elder" },
		{ 3, "Bonemass" },
		{ 4, "Moder" },
		{ 5, "Yagluth" },
		{ 6, "Queen" },
		{ 7, "Fader" },
		{ 8, "Kall Fimbulbringer" }
	};

	internal static ConfigEntry<bool> EnableIdolProgression;

	internal static ConfigEntry<bool> EnableRecipes;

	internal static ConfigEntry<string> Recipe_Upgrader0Armor;

	internal static ConfigEntry<string> Recipe_Upgrader0Weapon;

	internal static ConfigEntry<string> Recipe_Upgrader1Armor;

	internal static ConfigEntry<string> Recipe_Upgrader1Weapon;

	internal static ConfigEntry<string> Recipe_Upgrader2Armor;

	internal static ConfigEntry<string> Recipe_Upgrader2Weapon;

	internal static ConfigEntry<string> Recipe_Upgrader3Armor;

	internal static ConfigEntry<string> Recipe_Upgrader3Weapon;

	internal static ConfigEntry<string> Recipe_Upgrader4Armor;

	internal static ConfigEntry<string> Recipe_Upgrader4Weapon;

	internal static ConfigEntry<string> Recipe_Upgrader5Armor;

	internal static ConfigEntry<string> Recipe_Upgrader5Weapon;

	internal static ConfigEntry<string> Recipe_Upgrader6Armor;

	internal static ConfigEntry<string> Recipe_Upgrader6Weapon;

	internal static ConfigEntry<string> Recipe_Upgrader7Armor;

	internal static ConfigEntry<string> Recipe_Upgrader7Weapon;

	internal static ConfigEntry<string> Station_Global;

	internal static ConfigEntry<float> UpgradeChance;

	internal static ConfigEntry<float> BreakChance;

	internal static ConfigEntry<int> CostStart;

	internal static ConfigEntry<int> CostIncreaseInterval;

	internal static ConfigEntry<int> CostIncreasePerInterval;

	internal static ConfigEntry<int> CostScalingLevelStart;

	internal static ConfigEntry<float> UpgradeBaseDuration;

	internal static ConfigEntry<float> UpgradeDurationIncreasePerLevel;

	public static CustomRPC RPC_Reforged;

	public static ConfigEntry<bool> EnableGlobalUpgradeNotifications;

	public static ConfigEntry<string> SuccessMessage;

	public static ConfigEntry<string> FailedMessage;

	private void Awake()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_0028: Expected O, but got Unknown
		RPC_Reforged = NetworkManager.Instance.AddRPC("RPC_Reforged", new CoroutineHandler(RPC_ReforgedServerReceive), new CoroutineHandler(RPC_ReforgedClientReceive));
		InitConfig();
		CreateConfigWatcher();
		harmony.PatchAll();
	}

	private IEnumerator RPC_ReforgedServerReceive(long sender, ZPackage package)
	{
		Logger.LogMessage((object)"Received blob, processing");
		Logger.LogMessage((object)"Broadcasting to all clients");
		RPC_Reforged.SendPackage(ZNet.instance.m_peers, new ZPackage(package.GetArray()));
		string message = package.ReadString();
		if (message != "")
		{
			Logger.LogDebug((object)("[SERVER] Adding message to chat: " + message));
			ChatHelpers.ResetChatHideTimer();
			((Terminal)Chat.instance).AddString("Forge of Potential", message, (Type)2, false);
		}
		yield return null;
	}

	private IEnumerator RPC_ReforgedClientReceive(long sender, ZPackage package)
	{
		Logger.LogMessage((object)"Received blob, processing");
		string message = package.ReadString();
		if (message != "")
		{
			ChatHelpers.ResetChatHideTimer();
			((Terminal)Chat.instance).AddString("Forge of Potential", message, (Type)2, false);
		}
		yield return null;
	}

	public static void BroadcastUpgradeResult(string playerName, string itemName, int level, bool success)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Expected O, but got Unknown
		if (EnableGlobalUpgradeNotifications.Value)
		{
			string text = (success ? SuccessMessage.Value : FailedMessage.Value);
			string text2 = text.Replace("{PlayerName}", playerName).Replace("{ItemName}", itemName).Replace("{Level}", level.ToString());
			ZPackage val = new ZPackage();
			val.Write(text2);
			Logger.LogDebug((object)("Broadcasting upgrade result: " + text2));
			RPC_Reforged.SendPackage(ZRoutedRpc.instance.GetServerPeerID(), val);
		}
	}

	private void CreateConfigWatcher()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		ConfigFileWatcher val = new ConfigFileWatcher(((BaseUnityPlugin)this).Config, 1000L);
		val.OnConfigFileReloaded += delegate
		{
			Logger.LogInfo((object)"Config file reloaded, reinitializing config values.");
			InitConfig();
		};
	}

	private void InitConfig()
	{
		//IL_000e: 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_001c: Expected O, but got Unknown
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		//IL_004c: 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_0063: Expected O, but got Unknown
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Expected O, but got Unknown
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Expected O, but got Unknown
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: 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_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Expected O, but got Unknown
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Expected O, but got Unknown
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Expected O, but got Unknown
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Expected O, but got Unknown
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Expected O, but got Unknown
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Expected O, but got Unknown
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Expected O, but got Unknown
		//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Expected O, but got Unknown
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Expected O, but got Unknown
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_0362: Expected O, but got Unknown
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Expected O, but got Unknown
		//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c2: Expected O, but got Unknown
		//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f2: Expected O, but got Unknown
		//IL_0418: Unknown result type (might be due to invalid IL or missing references)
		//IL_0422: Expected O, but got Unknown
		//IL_0448: Unknown result type (might be due to invalid IL or missing references)
		//IL_0452: Expected O, but got Unknown
		//IL_0479: Unknown result type (might be due to invalid IL or missing references)
		//IL_0483: Expected O, but got Unknown
		//IL_054c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0556: Expected O, but got Unknown
		//IL_0580: Unknown result type (might be due to invalid IL or missing references)
		//IL_058a: Expected O, but got Unknown
		//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ba: Expected O, but got Unknown
		//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ee: Expected O, but got Unknown
		//IL_0618: Unknown result type (might be due to invalid IL or missing references)
		//IL_0622: Expected O, but got Unknown
		//IL_064c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0656: Expected O, but got Unknown
		//IL_0680: Unknown result type (might be due to invalid IL or missing references)
		//IL_068a: Expected O, but got Unknown
		//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_06be: Expected O, but got Unknown
		//IL_06e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f2: Expected O, but got Unknown
		//IL_071c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0726: Expected O, but got Unknown
		//IL_0750: Unknown result type (might be due to invalid IL or missing references)
		//IL_075a: Expected O, but got Unknown
		//IL_0784: Unknown result type (might be due to invalid IL or missing references)
		//IL_078e: Expected O, but got Unknown
		//IL_07b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c2: Expected O, but got Unknown
		//IL_07ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f6: Expected O, but got Unknown
		//IL_0820: Unknown result type (might be due to invalid IL or missing references)
		//IL_082a: Expected O, but got Unknown
		//IL_0854: Unknown result type (might be due to invalid IL or missing references)
		//IL_085e: Expected O, but got Unknown
		//IL_0888: Unknown result type (might be due to invalid IL or missing references)
		//IL_0892: Expected O, but got Unknown
		//IL_08bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c6: Expected O, but got Unknown
		//IL_08f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_08fa: Expected O, but got Unknown
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		};
		EnableServerSync = ((BaseUnityPlugin)this).Config.Bind<bool>("Server Only", "01. Enable Server Sync", true, new ConfigDescription("If true, config values are synchronized from server to clients.", (AcceptableValueBase)null, new object[1] { val }));
		val = new ConfigurationManagerAttributes
		{
			IsAdminOnly = EnableServerSync.Value
		};
		EnableGlobalUpgradeNotifications = ((BaseUnityPlugin)this).Config.Bind<bool>("Global Notifications", "01. Enable Global Upgrade Notifications", false, new ConfigDescription("Broadcast a message to all online players when someone attempts an upgrade.", (AcceptableValueBase)null, new object[1] { val }));
		SuccessMessage = ((BaseUnityPlugin)this).Config.Bind<string>("Global Notifications", "02. Success Message", "'{PlayerName}' successfully upgraded '{ItemName}' to level '{Level}'.", new ConfigDescription("Message shown on successful upgrade. Supports {PlayerName}, {ItemName}, {Level}.", (AcceptableValueBase)null, new object[1] { val }));
		FailedMessage = ((BaseUnityPlugin)this).Config.Bind<string>("Global Notifications", "03. Failed Message", "'{PlayerName}' tried to upgrade '{ItemName}' to level '{Level}', but failed.", new ConfigDescription("Message shown on failed upgrade. Supports {PlayerName}, {ItemName}, {Level}.", (AcceptableValueBase)null, new object[1] { val }));
		AcceptableValueRange<float> val2 = new AcceptableValueRange<float>(0f, 1f);
		UpgradeChance = ((BaseUnityPlugin)this).Config.Bind<float>("Upgrade Settings", "01. Upgrade Chance", 1f, new ConfigDescription("Chance for an upgrade to succeed.", (AcceptableValueBase)(object)val2, new object[1] { val }));
		BreakChance = ((BaseUnityPlugin)this).Config.Bind<float>("Upgrade Settings", "02. BreakChance", 0f, new ConfigDescription("Chance for an upgrade to fail and break the item when failing the upgrade check, failing this check results in losing 1 level instead", (AcceptableValueBase)(object)val2, new object[1] { val }));
		AcceptableValueRange<int> val3 = new AcceptableValueRange<int>(0, 1000);
		CostStart = ((BaseUnityPlugin)this).Config.Bind<int>("Upgrade Settings", "03. Cost Start", 1, new ConfigDescription("Base idol cost for upgrades. (Game Default is 1)", (AcceptableValueBase)(object)val3, new object[1] { val }));
		CostIncreasePerInterval = ((BaseUnityPlugin)this).Config.Bind<int>("Upgrade Settings", "04. Cost Increase Per Interval", 1, new ConfigDescription("Additional ingredient cost each time the cost scaling interval is reached starting at CostScalingLevelStart. (Starting at level X, the upgrade cost increases by this amount every Y levels. For example, with an increase of 1 every 2 levels starting at level 6: levels 1–5 cost 1, levels 6–7 cost 2, levels 8–9 cost 3, and so on.)", (AcceptableValueBase)null, new object[1] { val }));
		CostIncreaseInterval = ((BaseUnityPlugin)this).Config.Bind<int>("Upgrade Settings", "05. Cost Increase Interval", 1, new ConfigDescription("Number of levels between each cost increase. Set to 0 to disable cost scaling.", (AcceptableValueBase)(object)val3, new object[1] { val }));
		CostScalingLevelStart = ((BaseUnityPlugin)this).Config.Bind<int>("Upgrade Settings", "06. Cost Scaling Level Start", 1, new ConfigDescription("Level after at which cost scaling starts.", (AcceptableValueBase)(object)val3, new object[1] { val }));
		UpgradeBaseDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Upgrade Settings", "07. Upgrade Base Duration", 2f, new ConfigDescription("Base crafting duration for upgrading. (Game Default is 8)", (AcceptableValueBase)null, new object[1] { val }));
		UpgradeDurationIncreasePerLevel = ((BaseUnityPlugin)this).Config.Bind<float>("Upgrade Settings", "08. Upgrade Duration Increase Per Level", 1f, new ConfigDescription("Additional crafting duration per item level. (Game Default is 1)", (AcceptableValueBase)null, new object[1] { val }));
		EnableBossProgression = ((BaseUnityPlugin)this).Config.Bind<bool>("Boss Progression", "01. Enable Boss Progression", true, new ConfigDescription("If true, upgrades are limited by boss progression. Defeat bosses to unlock higher upgrade levels.", (AcceptableValueBase)null, new object[1] { val }));
		BaseUpgradeLimit = ((BaseUnityPlugin)this).Config.Bind<int>("Boss Progression", "02. Base Upgrade Limit", 5, new ConfigDescription("Base upgrade limit for all items before any additional calculations are made", (AcceptableValueBase)null, new object[1] { val }));
		Boss1MaxUpgradeLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Boss Progression", "03. Boss 1 Max Upgrade Level", 4, new ConfigDescription("Additional max upgrade level unlocked for wooden tier after defeating Eikthyr.", (AcceptableValueBase)null, new object[1] { val }));
		Boss2MaxUpgradeLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Boss Progression", "04. Boss 2 Max Upgrade Level", 4, new ConfigDescription("Additional max upgrade level unlocked for bronze tier and below after defeating Elder.", (AcceptableValueBase)null, new object[1] { val }));
		Boss3MaxUpgradeLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Boss Progression", "05. Boss 3 Max Upgrade Level", 4, new ConfigDescription("Additional max upgrade level unlocked for iron tier and below after defeating Bonemass.", (AcceptableValueBase)null, new object[1] { val }));
		Boss4MaxUpgradeLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Boss Progression", "06. Boss 4 Max Upgrade Level", 4, new ConfigDescription("Additional max upgrade level unlocked for silver tier and below after defeating Moder.", (AcceptableValueBase)null, new object[1] { val }));
		Boss5MaxUpgradeLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Boss Progression", "07. Boss 5 Max Upgrade Level", 4, new ConfigDescription("Additional max upgrade level unlocked for black metal tier and below after defeating Yagluth.", (AcceptableValueBase)null, new object[1] { val }));
		Boss6MaxUpgradeLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Boss Progression", "08. Boss 6 Max Upgrade Level", 4, new ConfigDescription("Additional max upgrade level unlocked for black marble tier and below after defeating Queen.", (AcceptableValueBase)null, new object[1] { val }));
		Boss7MaxUpgradeLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Boss Progression", "09. Boss 7 Max Upgrade Level", 4, new ConfigDescription("Additional max upgrade level unlocked for flametal tier and below after defeating Fader.", (AcceptableValueBase)null, new object[1] { val }));
		Boss8MaxUpgradeLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Boss Progression", "10. Boss 8 Max Upgrade Level", 100, new ConfigDescription("Additional max upgrade level unlocked for bloodgold tier and below after defeating Kall Fimbulbringer.", (AcceptableValueBase)null, new object[1] { val }));
		bossUpgradeValues = new Dictionary<int, int>
		{
			{ 0, 0 },
			{ 1, Boss1MaxUpgradeLevel.Value },
			{ 2, Boss2MaxUpgradeLevel.Value },
			{ 3, Boss3MaxUpgradeLevel.Value },
			{ 4, Boss4MaxUpgradeLevel.Value },
			{ 5, Boss5MaxUpgradeLevel.Value },
			{ 6, Boss6MaxUpgradeLevel.Value },
			{ 7, Boss7MaxUpgradeLevel.Value },
			{ 8, Boss8MaxUpgradeLevel.Value }
		};
		EnableIdolProgression = ((BaseUnityPlugin)this).Config.Bind<bool>("Idol Progression", "01. Enable Idol Progression", true, new ConfigDescription("If true, the required idol to upgrade an equipment will change to match it's current equivalent item tier and level (If boss progression is off, tiers will change every 4 levels)", (AcceptableValueBase)null, new object[1] { val }));
		Station_Global = ((BaseUnityPlugin)this).Config.Bind<string>("Crafting Station", "01. Global Station", "piece_artisanstation", new ConfigDescription("Global crafting station for all configurable upgrader recipes. Use station m_name (e.g. 'piece_workbench'). Empty = craftable by hand.", (AcceptableValueBase)null, new object[1] { val }));
		EnableRecipes = ((BaseUnityPlugin)this).Config.Bind<bool>("Recipes", "01. Enable Recipes", true, new ConfigDescription("Enable or disable all idol crafting recipes.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader0Armor = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "02. Wooden Protection Idol", "Wood:50,GreydwarfEye:10", new ConfigDescription("Ingredients for Wooden Protection Idol: comma-separated entries 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader0Weapon = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "03. Wooden Battle Idol", "Wood:50,GreydwarfEye:10", new ConfigDescription("Ingredients for Wooden Battle Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader1Armor = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "04. Bronze Protection Idol", "Bronze:10,SurtlingCore:1", new ConfigDescription("Ingredients for Bronze Protection Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader1Weapon = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "05. Bronze Battle Idol", "Bronze:10,SurtlingCore:1", new ConfigDescription("Ingredients for Bronze Battle Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader2Armor = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "06. Iron Protection Idol", "Iron:10,ElderBark:5", new ConfigDescription("Ingredients for Iron Protection Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader2Weapon = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "07. Iron Battle Idol", "Iron:10,ElderBark:5", new ConfigDescription("Ingredients for Iron Battle Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader3Armor = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "08. Silver Protection Idol", "Silver:10,FreezeGland:5,Obsidian:5", new ConfigDescription("Ingredients for Silver Protection Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader3Weapon = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "09. Silver Battle Idol", "Silver:10,FreezeGland:5,Obsidian:5", new ConfigDescription("Ingredients for Silver Battle Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader4Armor = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "10. Black Metal Protection Idol", "BlackMetal:10,Needle:2,Tar:5", new ConfigDescription("Ingredients for Black Metal Protection Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader4Weapon = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "11. Black Metal Battle Idol", "BlackMetal:10,Needle:2,Tar:5", new ConfigDescription("Ingredients for Black Metal Battle Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader5Armor = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "12. Black Marble Protection Idol", "BlackMarble:20,BugMeat:10,Carapace:10", new ConfigDescription("Ingredients for Black Marble Protection Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader5Weapon = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "13. Black Marble Battle Idol", "BlackMarble:20,BugMeat:10,Carapace:10", new ConfigDescription("Ingredients for Black Marble Battle Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader6Armor = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "14. Flametal Protection Idol", "FlametalNew:10,CharredBone:15", new ConfigDescription("Ingredients for Flametal Protection Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader6Weapon = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "15. Flametal Battle Idol", "FlametalNew:10,CharredBone:15", new ConfigDescription("Ingredients for Flametal Battle Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader7Armor = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "16. Bloodgold Protection Idol", "Gold:10,Coins:40,AncientCoin:10", new ConfigDescription("Ingredients for Bloodgold Protection Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		Recipe_Upgrader7Weapon = ((BaseUnityPlugin)this).Config.Bind<string>("Recipes", "17. Bloodgold Battle Idol", "Gold:10,Coins:40,AncientCoin:10", new ConfigDescription("Ingredients for Bloodgold Battle Idol: comma-separated 'PrefabName:Amount'.", (AcceptableValueBase)null, new object[1] { val }));
		AddConfigurableRecipes();
	}

	private void AddConfigurableRecipes()
	{
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Expected O, but got Unknown
		//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f6: Expected O, but got Unknown
		try
		{
			if (EnableRecipes == null || !EnableRecipes.Value)
			{
				Logger.LogInfo((object)"Configurable recipes are disabled; skipping AddConfigurableRecipes.");
				return;
			}
			(string, ConfigEntry<string>)[] array = new(string, ConfigEntry<string>)[16]
			{
				("Upgrader0Armor", Recipe_Upgrader0Armor),
				("Upgrader0Weapon", Recipe_Upgrader0Weapon),
				("Upgrader1Armor", Recipe_Upgrader1Armor),
				("Upgrader1Weapon", Recipe_Upgrader1Weapon),
				("Upgrader2Armor", Recipe_Upgrader2Armor),
				("Upgrader2Weapon", Recipe_Upgrader2Weapon),
				("Upgrader3Armor", Recipe_Upgrader3Armor),
				("Upgrader3Weapon", Recipe_Upgrader3Weapon),
				("Upgrader4Armor", Recipe_Upgrader4Armor),
				("Upgrader4Weapon", Recipe_Upgrader4Weapon),
				("Upgrader5Armor", Recipe_Upgrader5Armor),
				("Upgrader5Weapon", Recipe_Upgrader5Weapon),
				("Upgrader6Armor", Recipe_Upgrader6Armor),
				("Upgrader6Weapon", Recipe_Upgrader6Weapon),
				("Upgrader7Armor", Recipe_Upgrader7Armor),
				("Upgrader7Weapon", Recipe_Upgrader7Weapon)
			};
			int num = 0;
			(string, ConfigEntry<string>)[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				(string, ConfigEntry<string>) tuple = array2[i];
				string item = tuple.Item1;
				string text = tuple.Item2?.Value?.Trim();
				if (string.IsNullOrEmpty(text))
				{
					Logger.LogInfo((object)("AddConfigurableRecipes: '" + item + "' configuration is empty, skipping."));
					continue;
				}
				string craftingStation = (string.IsNullOrEmpty(Station_Global.Value.Trim().Trim(new char[1] { '$' })) ? null : Station_Global.Value.Trim().Trim(new char[1] { '$' }));
				RecipeConfig val = new RecipeConfig
				{
					Item = item,
					CraftingStation = craftingStation,
					Enabled = true,
					MinStationLevel = 1
				};
				bool flag = false;
				string[] array3 = text.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
				string[] array4 = array3;
				foreach (string text2 in array4)
				{
					string text3 = text2.Trim();
					if (string.IsNullOrEmpty(text3))
					{
						continue;
					}
					string[] array5 = text3.Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
					if (array5.Length != 2)
					{
						Logger.LogWarning((object)("AddConfigurableRecipes: invalid token '" + text3 + "' for '" + item + "'. Use 'PrefabName:Amount'."));
						continue;
					}
					string text4 = array5[0].Trim();
					if (!int.TryParse(array5[1].Trim(), out var result) || result <= 0)
					{
						Logger.LogWarning((object)("AddConfigurableRecipes: invalid amount in token '" + text3 + "' for '" + item + "'. Must be positive integer."));
					}
					else
					{
						val.AddRequirement(text4, result, 0);
						flag = true;
					}
				}
				if (!flag)
				{
					Logger.LogWarning((object)("AddConfigurableRecipes: no valid ingredients for '" + item + "' from '" + text + "'; skipping."));
				}
				else
				{
					ItemManager.Instance.AddRecipe(new CustomRecipe(val));
					num++;
					Logger.LogInfo((object)("AddConfigurableRecipes: added recipe for '" + item + "' (requirements: " + text + ")."));
				}
			}
			Logger.LogInfo((object)$"AddConfigurableRecipes: finished. Added {num} configurable recipe(s).");
		}
		catch (Exception arg)
		{
			Logger.LogError((object)$"AddConfigurableRecipes exception: {arg}");
		}
	}
}