Decompiled source of RepairRequiresCoins v1.1.2

plugins/RepairRequiresMats.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5538460d90047a9975dbc890163848bf3fbda762")]
[assembly: AssemblyVersion("1.1.0.0")]
public class WeaponAndArmorValues
{
	public float BlackMetalScrap { get; set; }

	public float BlackMetal { get; set; }

	public float Bronze { get; set; }

	public float Chain { get; set; }

	public float Chitin { get; set; }

	public float Copper { get; set; }

	public float CopperOre { get; set; }

	public float Flametal { get; set; }

	public float FlametalOre { get; set; }

	public float Frometal { get; set; }

	public float FrometalOre { get; set; }

	public float FrostinfusedDarkmetal { get; set; }

	public float HeatedIron { get; set; }

	public float Heavymetal { get; set; }

	public float HeavymetalOre { get; set; }

	public float Heavyscale { get; set; }

	public float Iron { get; set; }

	public float LeatherScraps { get; set; }

	public float PrimordialIce { get; set; }

	public float ScrapIron { get; set; }

	public float Silver { get; set; }

	public float SilverOre { get; set; }

	public float Tin { get; set; }

	public float TinOre { get; set; }

	public float DeerHide { get; set; }

	public float TrollHide { get; set; }

	public float WolfPelt { get; set; }

	public float LoxPelt { get; set; }

	public float WitheredBone { get; set; }

	public float BoneFragments { get; set; }

	public float LinenThread { get; set; }

	public float ElderBark { get; set; }

	public float Obsidian { get; set; }

	public float FreezeGland { get; set; }

	public float Crystal { get; set; }

	public float YimirRemains { get; set; }

	public float HardAntler { get; set; }

	public float SalamanderFurTH { get; set; }

	public float WolfFang { get; set; }

	public float Root { get; set; }

	public float Flint { get; set; }

	public float Needle { get; set; }

	public float Wood { get; set; }

	public float RoundLog { get; set; }

	public float SerpentScale { get; set; }

	public float WorldTreeFragment { get; set; }

	public float BurningWorldTreeFragment { get; set; }

	public float Stone { get; set; }
}
namespace RepairRequiresMats;

[BepInPlugin("cjayride.RepairRequiresCoins", "Repair Requires Coins", "1.1.1")]
public class BepInExPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(UITooltip), "LateUpdate")]
	private static class UITooltip_LateUpdate_Patch
	{
		private static void Postfix(UITooltip __instance, UITooltip ___m_current, GameObject ___m_tooltip)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (modEnabled.Value && (Object)(object)___m_current == (Object)(object)__instance && (Object)(object)___m_tooltip != (Object)null && ((Object)((Component)___m_current).transform).name == "RepairButton")
			{
				___m_tooltip.transform.position = Input.mousePosition + new Vector3(-200f, -100f);
			}
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "UpdateRepair")]
	private static class InventoryGui_UpdateRepair_Patch
	{
		private static void Postfix(InventoryGui __instance, ref List<ItemData> ___m_tempWornItems)
		{
			//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Expected O, but got Unknown
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Expected O, but got Unknown
			if (!modEnabled.Value || !___m_tempWornItems.Any())
			{
				return;
			}
			List<RepairItemData> list = new List<RepairItemData>();
			List<RepairItemData> list2 = new List<RepairItemData>();
			List<RepairItemData> list3 = new List<RepairItemData>();
			List<RepairItemData> list4 = new List<RepairItemData>();
			List<string> list5 = new List<string>();
			foreach (ItemData ___m_tempWornItem in ___m_tempWornItems)
			{
				if (!Traverse.Create((object)__instance).Method("CanRepair", new object[1] { ___m_tempWornItem }).GetValue<bool>())
				{
					list4.Add(new RepairItemData(___m_tempWornItem));
					continue;
				}
				List<Requirement> list6 = RepairReqs(___m_tempWornItem);
				if (list6 == null)
				{
					list.Add(new RepairItemData(___m_tempWornItem));
					continue;
				}
				List<string> list7 = new List<string>();
				foreach (Requirement item in list6)
				{
					if (item.m_amount != 0)
					{
						list7.Add($"{item.m_amount} {Localization.instance.Localize(item.m_resItem.m_itemData.m_shared.m_name)}");
					}
				}
				bool flag = true;
				foreach (Requirement item2 in list6)
				{
					if (Object.op_Implicit((Object)(object)item2.m_resItem))
					{
						int amount = item2.m_amount;
						if (((Humanoid)Player.m_localPlayer).GetInventory().CountItems(item2.m_resItem.m_itemData.m_shared.m_name, -1, true) < amount)
						{
							flag = false;
							break;
						}
					}
				}
				if (!flag)
				{
					list3.Add(new RepairItemData(___m_tempWornItem, list7));
				}
				else
				{
					list2.Add(new RepairItemData(___m_tempWornItem, list7));
				}
			}
			orderedWornItems = new List<ItemData>();
			foreach (RepairItemData item3 in list)
			{
				list5.Add("<color=#" + hasEnoughTooltipColor.Value + ">" + Localization.instance.Localize(item3.item.m_shared.m_name) + ": Free</color>");
				orderedWornItems.Add(item3.item);
			}
			foreach (RepairItemData item4 in list2)
			{
				list5.Add("<color=#" + hasEnoughTooltipColor.Value + ">" + Localization.instance.Localize(item4.item.m_shared.m_name) + ": " + string.Join(", ", item4.reqstring) + "</color>");
				orderedWornItems.Add(item4.item);
			}
			foreach (RepairItemData item5 in list3)
			{
				list5.Add("<color=#" + notEnoughTooltipColor.Value + ">" + Localization.instance.Localize(item5.item.m_shared.m_name) + ": " + string.Join(", ", item5.reqstring) + "</color>");
				orderedWornItems.Add(item5.item);
			}
			foreach (RepairItemData item6 in list4)
			{
				orderedWornItems.Add(item6.item);
			}
			___m_tempWornItems = new List<ItemData>(orderedWornItems);
			if (!showAllRepairsInToolTip.Value)
			{
				return;
			}
			UITooltip val = (UITooltip)typeof(UITooltip).GetField("m_current", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
			GameObject val2 = (GameObject)typeof(UITooltip).GetField("m_tooltip", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
			if ((Object)(object)val2 == (Object)null || ((Object)((Component)val).transform).name != "RepairButton")
			{
				return;
			}
			List<ItemData> allItems = ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems();
			int num = 0;
			if (list5.Count == 0)
			{
				list5.Add("Nothing to repair.");
			}
			int num2 = 0;
			foreach (ItemData item7 in allItems)
			{
				if (item7.m_shared.m_name == "$item_coins")
				{
					num2 += item7.GetValue();
				}
			}
			num = num2;
			list5.Add("-------------------- \r\n <b>Coins: " + num + "</b>");
			((Component)Utils.FindChild(val2.transform, "Text", (IterativeSearchType)0)).GetComponent<TMP_Text>().richText = true;
			((Component)Utils.FindChild(val2.transform, "Text", (IterativeSearchType)0)).GetComponent<TMP_Text>().alignment = (TextAlignmentOptions)1026;
			((Component)Utils.FindChild(val2.transform, "Text", (IterativeSearchType)0)).GetComponent<TMP_Text>().fontSize = 20f;
			((Component)Utils.FindChild(val2.transform, "Text", (IterativeSearchType)0)).GetComponent<TMP_Text>().text = "<b><color=#" + titleTooltipColor.Value + ">[" + Localization.instance.Localize("$inventory_repairbutton") + "]</color></b>\r\n -------------------- \r\n" + string.Join("\r\n", list5);
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "CanRepair")]
	private static class InventoryGui_CanRepair_Patch
	{
		private static void Postfix(ItemData item, ref bool __result)
		{
			if (!modEnabled.Value || !modEnabled.Value || !Environment.StackTrace.Contains("RepairOneItem") || Environment.StackTrace.Contains("HaveRepairableItems") || !__result || item?.m_shared == null || !((Object)(object)Player.m_localPlayer != (Object)null) || orderedWornItems.Count <= 0)
			{
				return;
			}
			if (orderedWornItems[0] != item)
			{
				__result = false;
				return;
			}
			List<Requirement> list = RepairReqs(item, log: true);
			if (list == null)
			{
				return;
			}
			List<string> list2 = new List<string>();
			foreach (Requirement item2 in list)
			{
				if (item2?.m_resItem?.m_itemData?.m_shared != null)
				{
					list2.Add($"{item2.m_amount} {Localization.instance.Localize(item2.m_resItem.m_itemData.m_shared.m_name)}");
				}
			}
			bool flag = true;
			foreach (Requirement item3 in list)
			{
				if (Object.op_Implicit((Object)(object)item3.m_resItem))
				{
					int amount = item3.m_amount;
					if (((Humanoid)Player.m_localPlayer).GetInventory().CountItems(item3.m_resItem.m_itemData.m_shared.m_name, -1, true) < amount)
					{
						flag = false;
						break;
					}
				}
			}
			string text;
			if (flag)
			{
				Player.m_localPlayer.ConsumeResources(list.ToArray(), 1, -1);
				text = "Used " + string.Join(", ", list2) + " to repair " + Localization.instance.Localize(item.m_shared.m_name);
				__result = true;
			}
			else
			{
				text = "Require " + string.Join(", ", list2) + " to repair " + item.m_shared.m_name;
				__result = false;
			}
			((Character)Player.m_localPlayer).Message((MessageType)1, text, 0, (Sprite)null);
			Dbgl(text);
		}
	}

	public const string Version = "1.1.1";

	public const string ModName = "Repair Requires Coins";

	private static bool isDebug = true;

	public static ConfigEntry<bool> modEnabled;

	public static ConfigEntry<bool> showAllRepairsInToolTip;

	public static ConfigEntry<float> materialRequirementMult;

	public static ConfigEntry<string> titleTooltipColor;

	public static ConfigEntry<string> hasEnoughTooltipColor;

	public static ConfigEntry<string> notEnoughTooltipColor;

	private static List<ItemData> orderedWornItems = new List<ItemData>();

	private static BepInExPlugin context;

	private static Assembly epicLootAssembly;

	private static MethodInfo epicLootIsMagic;

	private static MethodInfo epicLootGetRarity;

	private static MethodInfo epicLootGetEnchantCosts;

	public static WeaponAndArmorValues savedValues;

	public static ConfigEntry<bool> coinOnly;

	public static ConfigEntry<float> BlackMetalScrap;

	public static ConfigEntry<float> BlackMetal;

	public static ConfigEntry<float> Bronze;

	public static ConfigEntry<float> Chain;

	public static ConfigEntry<float> Chitin;

	public static ConfigEntry<float> Copper;

	public static ConfigEntry<float> CopperOre;

	public static ConfigEntry<float> Flametal;

	public static ConfigEntry<float> FlametalOre;

	public static ConfigEntry<float> Frometal;

	public static ConfigEntry<float> FrometalOre;

	public static ConfigEntry<float> FrostinfusedDarkmetal;

	public static ConfigEntry<float> HeatedIron;

	public static ConfigEntry<float> Heavymetal;

	public static ConfigEntry<float> HeavymetalOre;

	public static ConfigEntry<float> Heavyscale;

	public static ConfigEntry<float> Iron;

	public static ConfigEntry<float> ScrapIron;

	public static ConfigEntry<float> LeatherScraps;

	public static ConfigEntry<float> PrimordialIce;

	public static ConfigEntry<float> Silver;

	public static ConfigEntry<float> SilverOre;

	public static ConfigEntry<float> Tin;

	public static ConfigEntry<float> TinOre;

	public static ConfigEntry<float> DeerHide;

	public static ConfigEntry<float> TrollHide;

	public static ConfigEntry<float> WolfPelt;

	public static ConfigEntry<float> LoxPelt;

	public static ConfigEntry<float> WitheredBone;

	public static ConfigEntry<float> BoneFragments;

	public static ConfigEntry<float> LinenThread;

	public static ConfigEntry<float> ElderBark;

	public static ConfigEntry<float> Obsidian;

	public static ConfigEntry<float> FreezeGland;

	public static ConfigEntry<float> Crystal;

	public static ConfigEntry<float> YimirRemains;

	public static ConfigEntry<float> HardAntler;

	public static ConfigEntry<float> SalamanderFurTH;

	public static ConfigEntry<float> WolfFang;

	public static ConfigEntry<float> Root;

	public static ConfigEntry<float> Flint;

	public static ConfigEntry<float> Needle;

	public static ConfigEntry<float> Wood;

	public static ConfigEntry<float> RoundLog;

	public static ConfigEntry<float> SerpentScale;

	public static ConfigEntry<float> WorldTreeFragment;

	public static ConfigEntry<float> BurningWorldTreeFragment;

	public static ConfigEntry<float> Stone;

	public static void Dbgl(string str = "", bool pref = true)
	{
		if (isDebug)
		{
			Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
		}
	}

	private void Awake()
	{
		context = this;
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
		showAllRepairsInToolTip = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowAllRepairsInToolTip", true, "Show all repairs in tooltip when hovering over repair button.");
		titleTooltipColor = ((BaseUnityPlugin)this).Config.Bind<string>("General", "TitleTooltipColor", "FFFFFFFF", "Color to use in tooltip title.");
		hasEnoughTooltipColor = ((BaseUnityPlugin)this).Config.Bind<string>("General", "HasEnoughTooltipColor", "FFFFFFFF", "Color to use in tooltip for items with enough resources to repair.");
		notEnoughTooltipColor = ((BaseUnityPlugin)this).Config.Bind<string>("General", "NotEnoughTooltipColor", "FF0000FF", "Color to use in tooltip for items with enough resources to repair.");
		materialRequirementMult = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaterialRequirementMult", 0.5f, "Multiplier for amount of each material required.");
		coinOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CoinOnly", true, "Repair only using coins.");
		savedValues = new WeaponAndArmorValues();
		BlackMetalScrap = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "BlackMetalScrap", 5f, "BlackMetalScrap exchange rate");
		BlackMetal = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "BlackMetal", 5f, "BlackMetal exchange rate");
		Bronze = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Bronze", 2f, "Bronze exchange rate");
		Chain = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Chain", 2f, "Chain exchange rate");
		Chitin = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Chitin", 2f, "Chitin exchange rate");
		Copper = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Copper", 1f, "Copper exchange rate");
		CopperOre = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "CopperOre", 1f, "CopperOre exchange rate");
		Flametal = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Flametal", 21f, "Flametal exchange rate");
		FlametalOre = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "FlametalOre", 21f, "FlametalOre exchange rate");
		Frometal = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Frometal", 13f, "Frometal exchange rate");
		FrometalOre = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "FrometalOre", 13f, "FrometalOre exchange rate");
		FrostinfusedDarkmetal = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "FrostinfusedDarkmetal", 85f, "FrostinfusedDarkmetal exchange rate");
		HeatedIron = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "HeatedIron", 2f, "HeatedIron exchange rate");
		Heavymetal = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Heavymetal", 8f, "Heavymetal exchange rate");
		HeavymetalOre = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "HeavymetalOre", 8f, "HeavymetalOre exchange rate");
		Heavyscale = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Heavyscale", 8f, "Heavyscale exchange rate");
		Iron = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Iron", 2f, "Iron exchange rate");
		ScrapIron = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "ScrapIron", 2f, "ScrapIron exchange rate");
		LeatherScraps = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "LeatherScraps", 1f, "LeatherScraps exchange rate");
		PrimordialIce = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "PrimordialIce", 13f, "PrimordialIce exchange rate");
		Silver = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Silver", 2f, "Silver exchange rate");
		SilverOre = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "SilverOre", 2f, "SilverOre exchange rate");
		Tin = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Tin", 1f, "Tin exchange rate");
		TinOre = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "TinOre", 1f, "TinOre exchange rate");
		DeerHide = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "DeerHide", 1f, "DeerHide exchange rate");
		TrollHide = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "TrollHide", 2f, "TrollHide exchange rate");
		WolfPelt = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "WolfPelt", 3f, "WolfPelt exchange rate");
		LoxPelt = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "LoxPelt", 5f, "LoxPelt exchange rate");
		WitheredBone = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "WitheredBone", 3f, "WitheredBone exchange rate");
		BoneFragments = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "BoneFragments", 1f, "BoneFragments exchange rate");
		LinenThread = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "LinenThread", 5f, "LinenThread exchange rate");
		ElderBark = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "ElderBark", 1f, "ElderBark exchange rate");
		Obsidian = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Obsidian", 5f, "Obsidian exchange rate");
		FreezeGland = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "FreezeGland", 1f, "FreezeGland exchange rate");
		Crystal = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Crystal", 1f, "Crystal exchange rate");
		YimirRemains = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "YimirRemains", 3f, "YimirRemains exchange rate");
		HardAntler = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "HardAntler", 1f, "HardAntler exchange rate");
		SalamanderFurTH = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "SalamanderFurTH", 9f, "SalamanderFurTH exchange rate");
		WolfFang = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "WolfFang", 3f, "WolfFang exchange rate");
		Root = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Root", 2f, "Root exchange rate");
		Flint = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Flint", 1f, "Flint exchange rate");
		Needle = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Needle", 5f, "Needle exchange rate");
		Wood = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Wood", -1f, "Wood exchange rate");
		RoundLog = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "RoundLog", 1f, "RoundLog exchange rate");
		SerpentScale = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "SerpentScale", 3f, "SerpentScale exchange rate");
		WorldTreeFragment = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "WorldTreeFragment", 8f, "WorldTreeFragment exchange rate");
		BurningWorldTreeFragment = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "BurningWorldTreeFragment", 13f, "BurningWorldTreeFragment exchange rate");
		Stone = ((BaseUnityPlugin)this).Config.Bind<float>("Item Values", "Stone", -1f, "Stone exchange rate");
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		try
		{
			savedValues.BlackMetalScrap = BlackMetalScrap.Value;
			savedValues.BlackMetal = BlackMetal.Value;
			savedValues.Bronze = Bronze.Value;
			savedValues.BlackMetal = BlackMetal.Value;
			savedValues.Bronze = Bronze.Value;
			savedValues.Chain = Chain.Value;
			savedValues.Chitin = Chitin.Value;
			savedValues.Copper = Copper.Value;
			savedValues.CopperOre = CopperOre.Value;
			savedValues.Flametal = Flametal.Value;
			savedValues.FlametalOre = FlametalOre.Value;
			savedValues.Frometal = Frometal.Value;
			savedValues.FrometalOre = FrometalOre.Value;
			savedValues.FrostinfusedDarkmetal = FrostinfusedDarkmetal.Value;
			savedValues.HeatedIron = HeatedIron.Value;
			savedValues.Heavymetal = Heavymetal.Value;
			savedValues.HeavymetalOre = HeavymetalOre.Value;
			savedValues.Heavyscale = Heavyscale.Value;
			savedValues.Iron = Iron.Value;
			savedValues.LeatherScraps = LeatherScraps.Value;
			savedValues.PrimordialIce = PrimordialIce.Value;
			savedValues.ScrapIron = ScrapIron.Value;
			savedValues.Silver = Silver.Value;
			savedValues.SilverOre = SilverOre.Value;
			savedValues.Tin = Tin.Value;
			savedValues.TinOre = TinOre.Value;
			savedValues.DeerHide = DeerHide.Value;
			savedValues.TrollHide = TrollHide.Value;
			savedValues.WolfPelt = WolfPelt.Value;
			savedValues.LoxPelt = LoxPelt.Value;
			savedValues.WitheredBone = WitheredBone.Value;
			savedValues.BoneFragments = BoneFragments.Value;
			savedValues.LinenThread = LinenThread.Value;
			savedValues.ElderBark = ElderBark.Value;
			savedValues.Obsidian = Obsidian.Value;
			savedValues.FreezeGland = FreezeGland.Value;
			savedValues.Crystal = Crystal.Value;
			savedValues.YimirRemains = YimirRemains.Value;
			savedValues.HardAntler = HardAntler.Value;
			savedValues.SalamanderFurTH = SalamanderFurTH.Value;
			savedValues.WolfFang = WolfFang.Value;
			savedValues.Flint = Flint.Value;
			savedValues.Needle = Needle.Value;
			savedValues.Wood = Wood.Value;
			savedValues.RoundLog = RoundLog.Value;
			savedValues.SerpentScale = SerpentScale.Value;
			savedValues.WorldTreeFragment = WorldTreeFragment.Value;
			savedValues.BurningWorldTreeFragment = BurningWorldTreeFragment.Value;
			savedValues.Stone = Stone.Value;
		}
		catch
		{
			savedValues.BlackMetalScrap = 5f;
			savedValues.BlackMetal = 5f;
			savedValues.Bronze = 2f;
			savedValues.Chain = 2f;
			savedValues.Chitin = 2f;
			savedValues.Copper = 1f;
			savedValues.CopperOre = 1f;
			savedValues.Flametal = 21f;
			savedValues.FlametalOre = 21f;
			savedValues.Frometal = 13f;
			savedValues.FrometalOre = 85f;
			savedValues.FrostinfusedDarkmetal = 2f;
			savedValues.HeatedIron = 8f;
			savedValues.Heavymetal = 8f;
			savedValues.HeavymetalOre = 8f;
			savedValues.Heavyscale = 2f;
			savedValues.Iron = 1f;
			savedValues.LeatherScraps = 13f;
			savedValues.PrimordialIce = 2f;
			savedValues.ScrapIron = 2f;
			savedValues.Silver = 2f;
			savedValues.SilverOre = 2f;
			savedValues.Tin = 1f;
			savedValues.TinOre = 1f;
			savedValues.DeerHide = 1f;
			savedValues.TrollHide = 2f;
			savedValues.WolfPelt = 3f;
			savedValues.LoxPelt = 5f;
			savedValues.WitheredBone = 3f;
			savedValues.BoneFragments = 1f;
			savedValues.LinenThread = 5f;
			savedValues.ElderBark = 1f;
			savedValues.Obsidian = 5f;
			savedValues.FreezeGland = 1f;
			savedValues.Crystal = 1f;
			savedValues.YimirRemains = 3f;
			savedValues.HardAntler = 1f;
			savedValues.SalamanderFurTH = 9f;
			savedValues.WolfFang = 3f;
			savedValues.Root = 2f;
			savedValues.Flint = 1f;
			savedValues.Needle = 5f;
			savedValues.Wood = -1f;
			savedValues.RoundLog = 1f;
			savedValues.SerpentScale = 3f;
			savedValues.WorldTreeFragment = 8f;
			savedValues.BurningWorldTreeFragment = 13f;
			savedValues.Stone = -1f;
		}
	}

	private void Start()
	{
		if (Chainloader.PluginInfos.ContainsKey("randyknapp.mods.epicloot"))
		{
			epicLootAssembly = ((object)Chainloader.PluginInfos["randyknapp.mods.epicloot"].Instance).GetType().Assembly;
			epicLootIsMagic = epicLootAssembly.GetType("EpicLoot.ItemDataExtensions").GetMethod("IsMagic", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(ItemData) }, null);
			epicLootGetRarity = epicLootAssembly.GetType("EpicLoot.ItemDataExtensions").GetMethod("GetRarity", BindingFlags.Static | BindingFlags.Public);
			epicLootGetEnchantCosts = epicLootAssembly.GetType("EpicLoot.Crafting.EnchantHelper").GetMethod("GetEnchantCosts", BindingFlags.Static | BindingFlags.Public);
			Dbgl($"Loaded Epic Loot assembly; epicLootIsMagic {epicLootIsMagic != null}, epicLootGetRarity {epicLootGetRarity != null}, epicLootGetEnchantCosts {epicLootGetEnchantCosts != null}");
		}
	}

	private static List<Requirement> RepairReqs(ItemData item, bool log = false)
	{
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Expected O, but got Unknown
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Expected O, but got Unknown
		//IL_1cdc: Unknown result type (might be due to invalid IL or missing references)
		//IL_1ce1: Unknown result type (might be due to invalid IL or missing references)
		//IL_1cf5: Unknown result type (might be due to invalid IL or missing references)
		//IL_1d09: Unknown result type (might be due to invalid IL or missing references)
		//IL_1d1d: Unknown result type (might be due to invalid IL or missing references)
		//IL_1d33: Expected O, but got Unknown
		float num = (item.GetMaxDurability() - item.m_durability) / item.GetMaxDurability();
		Recipe recipe = ObjectDB.instance.GetRecipe(item);
		if (recipe == null)
		{
			return null;
		}
		List<Requirement> list = new List<Requirement>(recipe.m_resources);
		int num2 = 0;
		GameObject prefab = ZNetScene.instance.GetPrefab("GoldRubyRing");
		ItemData val = prefab.GetComponent<ItemDrop>().m_itemData.Clone();
		Recipe recipe2 = ObjectDB.instance.GetRecipe(val);
		List<Requirement> list2 = new List<Requirement>(recipe2.m_resources);
		bool flag = false;
		if (epicLootAssembly != null)
		{
			try
			{
				MethodInfo methodInfo = epicLootIsMagic;
				object[] parameters = (object[])(object)new ItemData[1] { item };
				flag = (bool)methodInfo.Invoke(null, parameters);
			}
			catch
			{
			}
		}
		if (flag)
		{
			try
			{
				MethodInfo methodInfo2 = epicLootGetRarity;
				object[] parameters = (object[])(object)new ItemData[1] { item };
				int num3 = (int)methodInfo2.Invoke(null, parameters);
				List<KeyValuePair<ItemDrop, int>> list3 = (List<KeyValuePair<ItemDrop, int>>)epicLootGetEnchantCosts.Invoke(null, new object[2] { item, num3 });
				foreach (KeyValuePair<ItemDrop, int> item2 in list3)
				{
					list.Add(new Requirement
					{
						m_amount = item2.Value,
						m_resItem = item2.Key
					});
				}
			}
			catch
			{
			}
		}
		List<Requirement> list4 = new List<Requirement>();
		for (int i = 0; i < list.Count; i++)
		{
			Requirement val2 = new Requirement
			{
				m_resItem = list[i].m_resItem,
				m_amount = list[i].m_amount,
				m_amountPerLevel = list[i].m_amountPerLevel,
				m_recover = list[i].m_recover
			};
			int num4 = 0;
			for (int num5 = item.m_quality; num5 > 0; num5--)
			{
				num4 += val2.GetAmount(num5);
			}
			int amount = Mathf.RoundToInt((float)num4 * num * materialRequirementMult.Value);
			val2.m_amount = amount;
			switch (((Object)val2.m_resItem).name)
			{
			case "BlackMetalScrap":
				if (savedValues.BlackMetalScrap != -1f)
				{
					num2 = ((!(savedValues.BlackMetalScrap * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.BlackMetalScrap * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "BlackMetal":
				if (savedValues.BlackMetal != -1f)
				{
					num2 = ((!(savedValues.BlackMetal * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.BlackMetal * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Bronze":
				if (savedValues.Bronze != -1f)
				{
					num2 = ((!(savedValues.Bronze * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Bronze * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Chain":
				if (savedValues.Chain != -1f)
				{
					num2 = ((!(savedValues.Chain * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Chain * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Chitin":
				if (savedValues.Chitin != -1f)
				{
					num2 = ((!(savedValues.Chitin * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Chitin * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Copper":
				if (savedValues.Copper != -1f)
				{
					num2 = ((!(savedValues.Copper * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Copper * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "CopperOre":
				if (savedValues.CopperOre != -1f)
				{
					num2 = ((!(savedValues.CopperOre * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.CopperOre * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Flametal":
				if (savedValues.Flametal != -1f)
				{
					num2 = ((!(savedValues.Flametal * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Flametal * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "FlametalOre":
				if (savedValues.FlametalOre != -1f)
				{
					num2 = ((!(savedValues.FlametalOre * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.FlametalOre * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Frometal":
				if (savedValues.Frometal != -1f)
				{
					num2 = ((!(savedValues.Frometal * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Frometal * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "FrometalOre":
				if (savedValues.FrometalOre != -1f)
				{
					num2 = ((!(savedValues.FrometalOre * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.FrometalOre * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "FrostinfusedDarkmetal":
				if (savedValues.FrostinfusedDarkmetal != -1f)
				{
					num2 = ((!(savedValues.FrostinfusedDarkmetal * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.FrostinfusedDarkmetal * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "HeatedIron":
				if (savedValues.HeatedIron != -1f)
				{
					num2 = ((!(savedValues.HeatedIron * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.HeatedIron * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Heavymetal":
				if (savedValues.Heavymetal != -1f)
				{
					num2 = ((!(savedValues.Heavymetal * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Heavymetal * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "HeavymetalOre":
				if (savedValues.HeavymetalOre != -1f)
				{
					num2 = ((!(savedValues.HeavymetalOre * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.HeavymetalOre * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Heavyscale":
				if (savedValues.Heavyscale != -1f)
				{
					num2 = ((!(savedValues.Heavyscale * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Heavyscale * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Iron":
				if (savedValues.Iron != -1f)
				{
					num2 = ((!(savedValues.Iron * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Iron * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "LeatherScraps":
				if (savedValues.LeatherScraps != -1f)
				{
					num2 = ((!(savedValues.LeatherScraps * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.LeatherScraps * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "PrimordialIce":
				if (savedValues.PrimordialIce != -1f)
				{
					num2 = ((!(savedValues.PrimordialIce * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.PrimordialIce * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "ScrapIron":
				if (savedValues.ScrapIron != -1f)
				{
					num2 = ((!(savedValues.ScrapIron * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.ScrapIron * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Silver":
				if (savedValues.Silver != -1f)
				{
					num2 = ((!(savedValues.Silver * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Silver * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "SilverOre":
				if (savedValues.SilverOre != -1f)
				{
					num2 = ((!(savedValues.SilverOre * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.SilverOre * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Tin":
				if (savedValues.Tin != -1f)
				{
					num2 = ((!(savedValues.Tin * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Tin * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "TinOre":
				if (savedValues.TinOre != -1f)
				{
					num2 = ((!(savedValues.TinOre * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.TinOre * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "DeerHide":
				if (savedValues.DeerHide != -1f)
				{
					num2 = ((!(savedValues.DeerHide * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.DeerHide * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "TrollHide":
				if (savedValues.TrollHide != -1f)
				{
					num2 = ((!(savedValues.TrollHide * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.TrollHide * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "WolfPelt":
				if (savedValues.WolfPelt != -1f)
				{
					num2 = ((!(savedValues.WolfPelt * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.WolfPelt * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "LoxPelt":
				if (savedValues.LoxPelt != -1f)
				{
					num2 = ((!(savedValues.LoxPelt * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.LoxPelt * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "WitheredBone":
				if (savedValues.WitheredBone != -1f)
				{
					num2 = ((!(savedValues.WitheredBone * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.WitheredBone * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "BoneFragments":
				if (savedValues.BoneFragments != -1f)
				{
					num2 = ((!(savedValues.BoneFragments * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.BoneFragments * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "LinenThread":
				if (savedValues.LinenThread != -1f)
				{
					num2 = ((!(savedValues.LinenThread * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.LinenThread * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "ElderBark":
				if (savedValues.ElderBark != -1f)
				{
					num2 = ((!(savedValues.ElderBark * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.ElderBark * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Obsidian":
				if (savedValues.Obsidian != -1f)
				{
					num2 = ((!(savedValues.Obsidian * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Obsidian * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "FreezeGland":
				if (savedValues.FreezeGland != -1f)
				{
					num2 = ((!(savedValues.FreezeGland * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.FreezeGland * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Crystal":
				if (savedValues.Crystal != -1f)
				{
					num2 = ((!(savedValues.Crystal * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Crystal * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "YimirRemains":
				if (savedValues.YimirRemains != -1f)
				{
					num2 = ((!(savedValues.YimirRemains * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.YimirRemains * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "HardAntler":
				if (savedValues.HardAntler != -1f)
				{
					num2 = ((!(savedValues.HardAntler * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.HardAntler * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "SalamanderFurTH":
				if (savedValues.SalamanderFurTH != -1f)
				{
					num2 = ((!(savedValues.SalamanderFurTH * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.SalamanderFurTH * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "WolfFang":
				if (savedValues.WolfFang != -1f)
				{
					num2 = ((!(savedValues.WolfFang * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.WolfFang * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Root":
				if (savedValues.Root != -1f)
				{
					num2 = ((!(savedValues.Root * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Root * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Flint":
				if (savedValues.Flint != -1f)
				{
					num2 = ((!(savedValues.Flint * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Flint * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Needle":
				if (savedValues.Needle != -1f)
				{
					num2 = ((!(savedValues.Needle * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Needle * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Wood":
				if (savedValues.Wood != -1f)
				{
					num2 = ((!(savedValues.Wood * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.Wood * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "RoundLog":
				if (savedValues.RoundLog != -1f)
				{
					num2 = ((!(savedValues.RoundLog * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.RoundLog * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "SerpentScale":
				if (savedValues.SerpentScale != -1f)
				{
					num2 = ((!(savedValues.SerpentScale * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.SerpentScale * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "WorldTreeFragment":
				if (savedValues.WorldTreeFragment != -1f)
				{
					num2 = ((!(savedValues.WorldTreeFragment * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.WorldTreeFragment * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "BurningWorldTreeFragment":
				if (savedValues.BurningWorldTreeFragment != -1f)
				{
					num2 = ((!(savedValues.BurningWorldTreeFragment * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.BurningWorldTreeFragment * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			case "Stone":
				if (savedValues.Stone != -1f)
				{
					num2 = ((!(savedValues.BurningWorldTreeFragment * (float)val2.m_amount <= 1f)) ? (num2 + Mathf.RoundToInt(savedValues.BurningWorldTreeFragment * (float)val2.m_amount)) : (num2 + 1));
				}
				break;
			}
		}
		if (num2 > 0)
		{
			List<Requirement> list5 = new List<Requirement>();
			for (int j = 0; j < list2.Count; j++)
			{
				Requirement val3 = new Requirement
				{
					m_resItem = list2[j].m_resItem,
					m_amount = list2[j].m_amount,
					m_amountPerLevel = list2[j].m_amountPerLevel,
					m_recover = list2[j].m_recover
				};
				if (((Object)val3.m_resItem).name == "Coins")
				{
					val3.m_amount = num2;
					list4.Add(val3);
				}
			}
			return list4;
		}
		return null;
	}
}
internal class RepairItemData : ItemData
{
	public List<string> reqstring;

	public ItemData item;

	public RepairItemData(ItemData item, List<string> reqstring = null)
	{
		this.reqstring = reqstring;
		this.item = item;
	}
}