public static bool Prefix(ItemActionEntryRepair __instance)
        {
            // Check if this feature is enabled.
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }

            XUi               xui       = __instance.ItemController.xui;
            ItemValue         itemValue = ((XUiC_ItemStack)__instance.ItemController).ItemStack.itemValue;
            ItemClass         forId     = ItemClass.GetForId(itemValue.type);
            EntityPlayerLocal player    = xui.playerUI.entityPlayer;

            XUiC_CraftingWindowGroup childByType = xui.FindWindowGroupByName("crafting").GetChildByType <XUiC_CraftingWindowGroup>();

            List <ItemStack> repairItems = new List <ItemStack>();

            // If the item has a repairItems, use that, instead of the vanilla version.
            if (forId.Properties.Classes.ContainsKey("RepairItems"))
            {
                Recipe            recipe             = new Recipe();
                DynamicProperties dynamicProperties3 = forId.Properties.Classes["RepairItems"];
                recipe.ingredients = ItemsUtilities.ParseProperties(dynamicProperties3);

                // Get an adjusted Craftint time from the player.
                recipe.craftingTime = (int)EffectManager.GetValue(PassiveEffects.CraftingTime, null, recipe.craftingTime, xui.playerUI.entityPlayer, recipe, FastTags.Parse(recipe.GetName()), true, true, true, true, 1, true);
                ItemsUtilities.ConvertAndCraft(recipe, player, __instance.ItemController);
                return(false);
            }
            else if (forId.Properties.Contains("RepairItems")) // to support <property name="RepairItems" value="resourceWood,10,resourceForgedIron,10" />
            {
                Recipe recipe  = new Recipe();
                string strData = forId.Properties.Values["RepairItems"].ToString();
                recipe.ingredients = ItemsUtilities.ParseProperties(strData);

                // Get an adjusted Craftint time from the player.
                recipe.craftingTime = (int)EffectManager.GetValue(PassiveEffects.CraftingTime, null, recipe.craftingTime, xui.playerUI.entityPlayer, recipe, FastTags.Parse(recipe.GetName()), true, true, true, true, 1, true);
                ItemsUtilities.ConvertAndCraft(recipe, player, __instance.ItemController);
                return(false);
            }
            // If there's no RepairTools defined, then fall back to recipe reduction
            else if (forId.RepairTools == null || forId.RepairTools.Length <= 0)
            {
                // Determine, based on percentage left,
                int RecipeCountReduction = 2;
                if (itemValue.PercentUsesLeft < 0.2)
                {
                    RecipeCountReduction = 3;
                }

                // Use the helper method to reduce the recipe count, and control displaying on the UI for consistenncy.
                ItemsUtilities.ConvertAndCraft(forId.GetItemName(), RecipeCountReduction, player, __instance.ItemController);
                return(false);
            }

            // Fall back to possible RepairTools
            return(true);
        }
        public static bool Prefix(ItemActionEntryRepair __instance, StateTypes ___state, string ___lblReadBook, string ___lblNeedMaterials)
        {
            // Check if this feature is enabled.
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }

            StateTypes stateTypes = ___state;

            if (stateTypes == StateTypes.RecipeLocked)
            {
                GameManager.ShowTooltip(__instance.ItemController.xui.playerUI.entityPlayer, ___lblReadBook);
                return(false);
            }
            if (stateTypes != StateTypes.NotEnoughMaterials)
            {
                return(false);
            }

            GameManager.ShowTooltip(__instance.ItemController.xui.playerUI.entityPlayer, ___lblNeedMaterials);
            List <ItemStack> stack = new List <ItemStack>();
            ItemClass        forId = ItemClass.GetForId(((XUiC_ItemStack)__instance.ItemController).ItemStack.itemValue.type);

            if (forId.Properties.Classes.ContainsKey("RepairItems"))
            {
                DynamicProperties dynamicProperties3 = forId.Properties.Classes["RepairItems"];
                stack = ItemsUtilities.ParseProperties(dynamicProperties3);
                ItemsUtilities.CheckIngredients(stack, __instance.ItemController.xui.playerUI.entityPlayer);
                return(false);
            }
            else if (forId.Properties.Contains("RepairItems")) // to support <property name="RepairItems" value="resourceWood,10,resourceForgedIron,10" />
            {
                string strData = forId.Properties.Values["RepairItems"].ToString();
                stack = ItemsUtilities.ParseProperties(strData);
                ItemsUtilities.CheckIngredients(stack, __instance.ItemController.xui.playerUI.entityPlayer);
                return(false);
            }
            else if (forId.RepairTools == null || forId.RepairTools.Length <= 0)
            {
                Recipe recipe = ItemsUtilities.GetReducedRecipes(forId.GetItemName(), 2);
                ItemsUtilities.CheckIngredients(recipe.ingredients, __instance.ItemController.xui.playerUI.entityPlayer);
                return(false);
            }

            return(true);
        }