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.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.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.2.2")] [assembly: AssemblyInformationalVersion("1.2.2+e44bb814b2fef39403ee9cd5166f4df68ae61a8f")] [assembly: AssemblyVersion("1.2.2.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.2.2")] 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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 ___m_tempWornItems) { //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_03d5: Expected O, but got Unknown //IL_03f1: Unknown result type (might be due to invalid IL or missing references) //IL_03f8: Expected O, but got Unknown if (!modEnabled.Value || !___m_tempWornItems.Any()) { return; } List list = new List(); List list2 = new List(); List list3 = new List(); List list4 = new List(); List list5 = new List(); foreach (ItemData ___m_tempWornItem in ___m_tempWornItems) { if (!IsAtRequiredRepairStation(___m_tempWornItem)) { list4.Add(new RepairItemData(___m_tempWornItem)); continue; } List list6 = RepairReqs(___m_tempWornItem); if (list6 == null) { list.Add(new RepairItemData(___m_tempWornItem)); continue; } List list7 = new List(); foreach (Requirement item in list6) { if (item.m_amount != 0) { list7.Add(FormatRequirementLine(item)); } } bool flag = true; foreach (Requirement item2 in list6) { if (Object.op_Implicit((Object)(object)item2.m_resItem)) { int amount = item2.m_amount; if (CountNamedItems(((Humanoid)Player.m_localPlayer).GetInventory(), item2.m_resItem.m_itemData.m_shared.m_name) < amount) { flag = false; break; } } } if (!flag) { list3.Add(new RepairItemData(___m_tempWornItem, list7)); } else { list2.Add(new RepairItemData(___m_tempWornItem, list7)); } } orderedWornItems = new List(); foreach (RepairItemData item3 in list) { list5.Add("" + Localization.instance.Localize(item3.item.m_shared.m_name) + ": Free"); orderedWornItems.Add(item3.item); } foreach (RepairItemData item4 in list2) { list5.Add("" + Localization.instance.Localize(item4.item.m_shared.m_name) + ": " + string.Join(", ", item4.reqstring)); orderedWornItems.Add(item4.item); } foreach (RepairItemData item5 in list3) { list5.Add("" + Localization.instance.Localize(item5.item.m_shared.m_name) + ": " + string.Join(", ", item5.reqstring)); orderedWornItems.Add(item5.item); } foreach (RepairItemData item6 in list4) { string text = Localization.instance.Localize(item6.item.m_shared.m_name); list5.Add("" + text + " - " + GetRepairNeedLabel(item6.item) + ""); orderedWornItems.Add(item6.item); } ___m_tempWornItems = new List(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; } if (list5.Count == 0) { list5.Add("Nothing to repair."); } list5.Add("-------------------- \r\n Coins: " + CountNamedItems(((Humanoid)Player.m_localPlayer).GetInventory(), "$item_coins") + ""); Transform val3 = Utils.FindChild(val2.transform, "Text", (IterativeSearchType)0); if (!((Object)(object)val3 == (Object)null)) { TMP_Text component = ((Component)val3).GetComponent(); if (!((Object)(object)component == (Object)null)) { component.richText = true; component.alignment = (TextAlignmentOptions)1026; component.fontSize = 20f; string currentStationLevelLabel = GetCurrentStationLevelLabel(); component.text = "Repair an Item\r\n" + currentStationLevelLabel + "\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) { return; } if (!IsAtRequiredRepairStation(item)) { __result = false; } if (!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 list = RepairReqs(item, log: true); if (list == null) { return; } List list2 = new List(); foreach (Requirement item2 in list) { if (item2?.m_resItem?.m_itemData?.m_shared != null) { list2.Add(FormatRequirementLine(item2, colored: false)); } } bool flag = true; foreach (Requirement item3 in list) { if (Object.op_Implicit((Object)(object)item3.m_resItem)) { int amount = item3.m_amount; if (CountNamedItems(((Humanoid)Player.m_localPlayer).GetInventory(), item3.m_resItem.m_itemData.m_shared.m_name) < amount) { flag = false; break; } } } string text; if (flag) { ConsumeRepairRequirements(Player.m_localPlayer, list); 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, false); Dbgl(text); } } public const string Version = "1.2.2"; public const string ModName = "Repair Requires Coins"; private static bool isDebug = true; public static ConfigEntry modEnabled; public static ConfigEntry showAllRepairsInToolTip; public static ConfigEntry materialRequirementMult; public static ConfigEntry titleTooltipColor; public static ConfigEntry hasEnoughTooltipColor; public static ConfigEntry notEnoughTooltipColor; private static List orderedWornItems = new List(); 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 coinOnly; public static ConfigEntry BlackMetalScrap; public static ConfigEntry BlackMetal; public static ConfigEntry Bronze; public static ConfigEntry Chain; public static ConfigEntry Chitin; public static ConfigEntry Copper; public static ConfigEntry CopperOre; public static ConfigEntry Flametal; public static ConfigEntry FlametalOre; public static ConfigEntry Frometal; public static ConfigEntry FrometalOre; public static ConfigEntry FrostinfusedDarkmetal; public static ConfigEntry HeatedIron; public static ConfigEntry Heavymetal; public static ConfigEntry HeavymetalOre; public static ConfigEntry Heavyscale; public static ConfigEntry Iron; public static ConfigEntry ScrapIron; public static ConfigEntry LeatherScraps; public static ConfigEntry PrimordialIce; public static ConfigEntry Silver; public static ConfigEntry SilverOre; public static ConfigEntry Tin; public static ConfigEntry TinOre; public static ConfigEntry DeerHide; public static ConfigEntry TrollHide; public static ConfigEntry WolfPelt; public static ConfigEntry LoxPelt; public static ConfigEntry WitheredBone; public static ConfigEntry BoneFragments; public static ConfigEntry LinenThread; public static ConfigEntry ElderBark; public static ConfigEntry Obsidian; public static ConfigEntry FreezeGland; public static ConfigEntry Crystal; public static ConfigEntry YimirRemains; public static ConfigEntry HardAntler; public static ConfigEntry SalamanderFurTH; public static ConfigEntry WolfFang; public static ConfigEntry Root; public static ConfigEntry Flint; public static ConfigEntry Needle; public static ConfigEntry Wood; public static ConfigEntry RoundLog; public static ConfigEntry SerpentScale; public static ConfigEntry WorldTreeFragment; public static ConfigEntry BurningWorldTreeFragment; public static ConfigEntry Stone; private static MethodInfo inventoryRemoveByName; private static CraftingStation liveLevelStation; private static int liveLevelValue; private static int liveLevelFrame; 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("General", "Enabled", true, "Enable this mod"); showAllRepairsInToolTip = ((BaseUnityPlugin)this).Config.Bind("General", "ShowAllRepairsInToolTip", true, "Show all repairs in tooltip when hovering over repair button."); titleTooltipColor = ((BaseUnityPlugin)this).Config.Bind("General", "TitleTooltipColor", "FFFFFFFF", "Color to use in tooltip title."); hasEnoughTooltipColor = ((BaseUnityPlugin)this).Config.Bind("General", "HasEnoughTooltipColor", "00FF00FF", "Color to use in tooltip for repairable item names."); notEnoughTooltipColor = ((BaseUnityPlugin)this).Config.Bind("General", "NotEnoughTooltipColor", "FF0000FF", "Color to use in tooltip for items that cannot be repaired yet."); materialRequirementMult = ((BaseUnityPlugin)this).Config.Bind("General", "MaterialRequirementMult", 0.5f, "Multiplier for amount of each material required."); coinOnly = ((BaseUnityPlugin)this).Config.Bind("General", "CoinOnly", true, "If true, repair costs coins only. If false, repair costs coins plus the original materials."); savedValues = new WeaponAndArmorValues(); BlackMetalScrap = ((BaseUnityPlugin)this).Config.Bind("Item Values", "BlackMetalScrap", 5f, "BlackMetalScrap exchange rate"); BlackMetal = ((BaseUnityPlugin)this).Config.Bind("Item Values", "BlackMetal", 5f, "BlackMetal exchange rate"); Bronze = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Bronze", 2f, "Bronze exchange rate"); Chain = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Chain", 2f, "Chain exchange rate"); Chitin = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Chitin", 2f, "Chitin exchange rate"); Copper = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Copper", 1f, "Copper exchange rate"); CopperOre = ((BaseUnityPlugin)this).Config.Bind("Item Values", "CopperOre", 1f, "CopperOre exchange rate"); Flametal = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Flametal", 21f, "Flametal exchange rate"); FlametalOre = ((BaseUnityPlugin)this).Config.Bind("Item Values", "FlametalOre", 21f, "FlametalOre exchange rate"); Frometal = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Frometal", 13f, "Frometal exchange rate"); FrometalOre = ((BaseUnityPlugin)this).Config.Bind("Item Values", "FrometalOre", 13f, "FrometalOre exchange rate"); FrostinfusedDarkmetal = ((BaseUnityPlugin)this).Config.Bind("Item Values", "FrostinfusedDarkmetal", 85f, "FrostinfusedDarkmetal exchange rate"); HeatedIron = ((BaseUnityPlugin)this).Config.Bind("Item Values", "HeatedIron", 2f, "HeatedIron exchange rate"); Heavymetal = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Heavymetal", 8f, "Heavymetal exchange rate"); HeavymetalOre = ((BaseUnityPlugin)this).Config.Bind("Item Values", "HeavymetalOre", 8f, "HeavymetalOre exchange rate"); Heavyscale = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Heavyscale", 8f, "Heavyscale exchange rate"); Iron = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Iron", 2f, "Iron exchange rate"); ScrapIron = ((BaseUnityPlugin)this).Config.Bind("Item Values", "ScrapIron", 2f, "ScrapIron exchange rate"); LeatherScraps = ((BaseUnityPlugin)this).Config.Bind("Item Values", "LeatherScraps", 1f, "LeatherScraps exchange rate"); PrimordialIce = ((BaseUnityPlugin)this).Config.Bind("Item Values", "PrimordialIce", 13f, "PrimordialIce exchange rate"); Silver = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Silver", 2f, "Silver exchange rate"); SilverOre = ((BaseUnityPlugin)this).Config.Bind("Item Values", "SilverOre", 2f, "SilverOre exchange rate"); Tin = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Tin", 1f, "Tin exchange rate"); TinOre = ((BaseUnityPlugin)this).Config.Bind("Item Values", "TinOre", 1f, "TinOre exchange rate"); DeerHide = ((BaseUnityPlugin)this).Config.Bind("Item Values", "DeerHide", 1f, "DeerHide exchange rate"); TrollHide = ((BaseUnityPlugin)this).Config.Bind("Item Values", "TrollHide", 2f, "TrollHide exchange rate"); WolfPelt = ((BaseUnityPlugin)this).Config.Bind("Item Values", "WolfPelt", 3f, "WolfPelt exchange rate"); LoxPelt = ((BaseUnityPlugin)this).Config.Bind("Item Values", "LoxPelt", 5f, "LoxPelt exchange rate"); WitheredBone = ((BaseUnityPlugin)this).Config.Bind("Item Values", "WitheredBone", 3f, "WitheredBone exchange rate"); BoneFragments = ((BaseUnityPlugin)this).Config.Bind("Item Values", "BoneFragments", 1f, "BoneFragments exchange rate"); LinenThread = ((BaseUnityPlugin)this).Config.Bind("Item Values", "LinenThread", 5f, "LinenThread exchange rate"); ElderBark = ((BaseUnityPlugin)this).Config.Bind("Item Values", "ElderBark", 1f, "ElderBark exchange rate"); Obsidian = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Obsidian", 5f, "Obsidian exchange rate"); FreezeGland = ((BaseUnityPlugin)this).Config.Bind("Item Values", "FreezeGland", 1f, "FreezeGland exchange rate"); Crystal = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Crystal", 1f, "Crystal exchange rate"); YimirRemains = ((BaseUnityPlugin)this).Config.Bind("Item Values", "YimirRemains", 3f, "YimirRemains exchange rate"); HardAntler = ((BaseUnityPlugin)this).Config.Bind("Item Values", "HardAntler", 1f, "HardAntler exchange rate"); SalamanderFurTH = ((BaseUnityPlugin)this).Config.Bind("Item Values", "SalamanderFurTH", 9f, "SalamanderFurTH exchange rate"); WolfFang = ((BaseUnityPlugin)this).Config.Bind("Item Values", "WolfFang", 3f, "WolfFang exchange rate"); Root = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Root", 2f, "Root exchange rate"); Flint = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Flint", 1f, "Flint exchange rate"); Needle = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Needle", 5f, "Needle exchange rate"); Wood = ((BaseUnityPlugin)this).Config.Bind("Item Values", "Wood", -1f, "Wood exchange rate"); RoundLog = ((BaseUnityPlugin)this).Config.Bind("Item Values", "RoundLog", 1f, "RoundLog exchange rate"); SerpentScale = ((BaseUnityPlugin)this).Config.Bind("Item Values", "SerpentScale", 3f, "SerpentScale exchange rate"); WorldTreeFragment = ((BaseUnityPlugin)this).Config.Bind("Item Values", "WorldTreeFragment", 8f, "WorldTreeFragment exchange rate"); BurningWorldTreeFragment = ((BaseUnityPlugin)this).Config.Bind("Item Values", "BurningWorldTreeFragment", 13f, "BurningWorldTreeFragment exchange rate"); Stone = ((BaseUnityPlugin)this).Config.Bind("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 int CountNamedItems(Inventory inventory, string itemName) { if (inventory == null || string.IsNullOrEmpty(itemName)) { return 0; } int num = 0; foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem?.m_shared?.m_name == itemName) { num += allItem.m_stack; } } return num; } private static void RemoveNamedItems(Inventory inventory, string itemName, int amount) { if (inventory == null || string.IsNullOrEmpty(itemName) || amount <= 0) { return; } if (inventoryRemoveByName == null) { MethodInfo methodInfo = null; foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(typeof(Inventory))) { if (!(declaredMethod.Name != "RemoveItem")) { ParameterInfo[] parameters = declaredMethod.GetParameters(); if (parameters.Length >= 2 && !(parameters[0].ParameterType != typeof(string)) && !(parameters[1].ParameterType != typeof(int)) && (methodInfo == null || parameters.Length < methodInfo.GetParameters().Length)) { methodInfo = declaredMethod; } } } inventoryRemoveByName = methodInfo; } if (inventoryRemoveByName != null) { ParameterInfo[] parameters2 = inventoryRemoveByName.GetParameters(); object[] array = new object[parameters2.Length]; array[0] = itemName; array[1] = amount; for (int i = 2; i < parameters2.Length; i++) { if (parameters2[i].HasDefaultValue) { array[i] = parameters2[i].DefaultValue; } else if (parameters2[i].ParameterType == typeof(int)) { array[i] = -1; } else if (parameters2[i].ParameterType == typeof(bool)) { array[i] = true; } else { array[i] = null; } } inventoryRemoveByName.Invoke(inventory, array); return; } List allItems = inventory.GetAllItems(); int num = allItems.Count - 1; while (num >= 0 && amount > 0) { ItemData val = allItems[num]; if (!(val?.m_shared?.m_name != itemName)) { int num2 = Mathf.Min(val.m_stack, amount); val.m_stack -= num2; amount -= num2; if (val.m_stack <= 0) { inventory.RemoveItem(val); } } num--; } } private static void ConsumeRepairRequirements(Player player, List reqs) { if ((Object)(object)player == (Object)null || reqs == null) { return; } Inventory inventory = ((Humanoid)player).GetInventory(); foreach (Requirement req in reqs) { if (req?.m_resItem?.m_itemData?.m_shared != null) { RemoveNamedItems(inventory, req.m_resItem.m_itemData.m_shared.m_name, req.m_amount); } } } private static string FormatRequirementLine(Requirement req, bool colored = true) { string name = req.m_resItem.m_itemData.m_shared.m_name; string text = Localization.instance.Localize(name); bool flag = name == "$item_coins" || ((Object)req.m_resItem).name == "Coins"; if (!colored) { return req.m_amount + " " + (flag ? "Coins" : text); } if (flag) { string text2 = ((CountNamedItems(((Humanoid)Player.m_localPlayer).GetInventory(), name) >= req.m_amount) ? "FFFF00FF" : "FF0000FF"); return "" + req.m_amount + " Coins"; } string text3 = ((CountNamedItems(((Humanoid)Player.m_localPlayer).GetInventory(), name) >= req.m_amount) ? "00FF00FF" : "FF0000FF"); return "" + req.m_amount + " " + text; } private static bool RecipeRepairsAtStation(Recipe recipe, CraftingStation current) { if ((Object)(object)recipe == (Object)null || !Object.op_Implicit((Object)(object)current)) { return false; } if (Object.op_Implicit((Object)(object)recipe.m_repairStation) && recipe.m_repairStation.m_name == current.m_name) { return true; } if (Object.op_Implicit((Object)(object)recipe.m_craftingStation) && recipe.m_craftingStation.m_name == current.m_name) { return true; } return false; } private static CraftingStation GetRequiredRepairStation(Recipe recipe) { if ((Object)(object)recipe == (Object)null) { return null; } if (Object.op_Implicit((Object)(object)recipe.m_repairStation)) { return recipe.m_repairStation; } return recipe.m_craftingStation; } private static int GetRequiredRepairStationLevel(Recipe recipe) { if ((Object)(object)recipe == (Object)null) { return 1; } return Mathf.Max(1, recipe.m_minStationLevel); } private static bool IsAtRequiredRepairStation(ItemData item) { if (item == null || (Object)(object)Player.m_localPlayer == (Object)null) { return false; } CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation(); if (!Object.op_Implicit((Object)(object)currentCraftingStation)) { return false; } Recipe val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetRecipe(item) : null); if ((Object)(object)val == (Object)null || !RecipeRepairsAtStation(val, currentCraftingStation)) { return false; } return GetLiveStationLevel(currentCraftingStation) >= GetRequiredRepairStationLevel(val); } private static int GetLiveStationLevel(CraftingStation station) { if (!Object.op_Implicit((Object)(object)station)) { return 0; } int frameCount = Time.frameCount; if (liveLevelFrame == frameCount && (Object)(object)liveLevelStation == (Object)(object)station) { return liveLevelValue; } FieldInfo fieldInfo = AccessTools.Field(typeof(CraftingStation), "m_updateExtensionTimer"); if (fieldInfo != null) { fieldInfo.SetValue(station, 999f); } MethodInfo methodInfo = AccessTools.Method(typeof(CraftingStation), "GetExtensions", (Type[])null, (Type[])null); if (methodInfo != null) { methodInfo.Invoke(station, null); } FieldInfo fieldInfo2 = AccessTools.Field(typeof(CraftingStation), "m_attachedExtensions"); IList list = ((fieldInfo2 != null) ? (fieldInfo2.GetValue(station) as IList) : null); int num = 0; if (list != null) { foreach (object item in list) { if (Object.op_Implicit((Object)((item is Object) ? item : null))) { num++; } } } else { num = Math.Max(0, station.GetLevel(true) - 1); } liveLevelStation = station; liveLevelFrame = frameCount; liveLevelValue = 1 + num; return liveLevelValue; } private static string GetCurrentStationLevelLabel() { CraftingStation val = (((Object)(object)Player.m_localPlayer != (Object)null) ? Player.m_localPlayer.GetCurrentCraftingStation() : null); if (!Object.op_Implicit((Object)(object)val)) { return ""; } return Localization.instance.Localize(val.m_name) + " Lvl: " + GetLiveStationLevel(val); } private static string GetRepairNeedLabel(ItemData item) { Recipe val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetRecipe(item) : null); if ((Object)(object)val == (Object)null) { return "Needs recipe"; } CraftingStation requiredRepairStation = GetRequiredRepairStation(val); if (!Object.op_Implicit((Object)(object)requiredRepairStation)) { return "cannot repair here"; } string text = Localization.instance.Localize(requiredRepairStation.m_name); return "Needs " + text + " Lvl: " + GetRequiredRepairStationLevel(val); } private static ItemDrop GetCoinsItemDrop() { GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab("Coins") : null); if ((Object)(object)val == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { val = ZNetScene.instance.GetPrefab("Coins"); } if (!((Object)(object)val != (Object)null)) { return null; } return val.GetComponent(); } private static List RepairReqs(ItemData item, bool log = false) { //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Expected O, but got Unknown //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0255: 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 list = new List(recipe.m_resources); int calculatedRepairCoinCost = 0; 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 num2 = (int)methodInfo2.Invoke(null, parameters); foreach (KeyValuePair item2 in (List>)epicLootGetEnchantCosts.Invoke(null, new object[2] { item, num2 })) { list.Add(new Requirement { m_amount = item2.Value, m_resItem = item2.Key }); } } catch { } } List list2 = new List(); for (int i = 0; i < list.Count; i++) { if (!((Object)(object)list[i]?.m_resItem == (Object)null)) { Requirement val = 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 num3 = 0; for (int num4 = item.m_quality; num4 > 0; num4--) { num3 += val.GetAmount(num4); } int amount = Mathf.RoundToInt((float)num3 * num * materialRequirementMult.Value); val.m_amount = amount; ApplyMaterialRepairCost(val, list2, ref calculatedRepairCoinCost); } } if (calculatedRepairCoinCost > 0) { ItemDrop coinsItemDrop = GetCoinsItemDrop(); if ((Object)(object)coinsItemDrop == (Object)null && coinOnly.Value) { if (list2.Count <= 0) { return null; } return list2; } if ((Object)(object)coinsItemDrop != (Object)null && calculatedRepairCoinCost > 0) { list2.Add(new Requirement { m_resItem = coinsItemDrop, m_amount = calculatedRepairCoinCost, m_amountPerLevel = 0, m_recover = false }); } } if (list2.Count == 0) { return null; } return list2; } private static void ApplyMaterialRepairCost(Requirement req, List reqs, ref int calculatedRepairCoinCost) { float rate; bool flag = TryGetMaterialRate(((Object)req.m_resItem).name, out rate); if (flag && rate == -1f) { return; } if (flag && req.m_amount > 0) { if (rate * (float)req.m_amount <= 1f) { calculatedRepairCoinCost++; } else { calculatedRepairCoinCost += Mathf.RoundToInt(rate * (float)req.m_amount); } } if (!coinOnly.Value && req.m_amount > 0) { reqs.Add(req); } } private static bool TryGetMaterialRate(string prefabName, out float rate) { rate = 0f; if (savedValues == null || string.IsNullOrEmpty(prefabName)) { return false; } PropertyInfo property = typeof(WeaponAndArmorValues).GetProperty(prefabName); if (property == null) { return false; } rate = Convert.ToSingle(property.GetValue(savedValues, null)); return true; } } internal class RepairItemData : ItemData { public List reqstring; public ItemData item; public RepairItemData(ItemData item, List reqstring = null) { this.reqstring = reqstring; this.item = item; } }