public static void SetModifiedValueButtonDiceFormula <T>(int rolls, DiceType dice, string name, string guid)
 {
     if (GL.Button(Strings.GetText("button_SetTo") + $" {rolls} * {dice}", GL.ExpandWidth(false)))
     {
         ModifiedDiceFormula diceFormula = new ModifiedDiceFormula();
         diceFormula.m_Rolls = rolls;
         diceFormula.m_Dice  = dice;
         FileInfo file = new FileInfo(Storage.modEntryPath + Storage.modifiedBlueprintsFolder + "\\" + guid + ".json");
         if (File.Exists(file.FullName))
         {
             T modifiedItem = ModifiedBlueprintTools.DeserialiseItem <T>(file);
             Traverse.Create(modifiedItem).Property(name).SetValue(diceFormula);
             string json = JsonConvert.SerializeObject(modifiedItem, Formatting.Indented);
             File.WriteAllText(file.FullName, json);
         }
         else
         {
             T modifiedItem = default(T);
             modifiedItem = Activator.CreateInstance <T>();
             Traverse.Create(modifiedItem).Property(name).SetValue(diceFormula);
             string json = JsonConvert.SerializeObject(modifiedItem, Formatting.Indented);
             File.WriteAllText(file.FullName, json);
         }
         ModifiedBlueprintTools.blueprintLists = false;
         ModifiedBlueprintTools.Patch();
     }
 }
        public static void PatchItem <T>(FileInfo file, BlueprintScriptableObject blueprintScriptableObject, string guid)
        {
            Common.ModLoggerDebug($"{guid} -> {blueprintScriptableObject} ({blueprintScriptableObject.GetType()})");

            T   jsonItem  = DeserialiseItem <T>(file);
            var blueprint = Convert.ChangeType(blueprintScriptableObject, blueprintScriptableObject.GetType());

            foreach (PropertyInfo property in jsonItem.GetType().GetProperties())
            {
                if (property.Name == "m_BaseDamage" && Traverse.Create(jsonItem).Property("m_BaseDamage").GetValue() != null)
                {
                    ModifiedDiceFormula dice        = (ModifiedDiceFormula)property.GetValue(jsonItem);
                    DiceFormula         diceFormula = new DiceFormula((int)dice.m_Rolls, (DiceType)dice.m_Dice);
                    Traverse.Create(blueprint).Field("m_BaseDamage").SetValue(diceFormula);

                    Common.ModLoggerDebug($"{blueprint} m_BaseDamage set to {diceFormula}.");
                }
                else if (property.Name == "m_DamageDice" && Traverse.Create(jsonItem).Property("m_DamageDice").GetValue() != null)
                {
                    ModifiedDiceFormula dice        = (ModifiedDiceFormula)property.GetValue(jsonItem);
                    DiceFormula         diceFormula = new DiceFormula((int)dice.m_Rolls, (DiceType)dice.m_Dice);
                    Traverse.Create(blueprint).Field("m_DamageDice").SetValue(diceFormula);

                    Common.ModLoggerDebug($"{blueprint} m_DamageDice set to {diceFormula}.");
                }
                else if (property.Name == "m_Enchantments" && Traverse.Create(jsonItem).Property("m_Enchantments").GetValue() != null)
                {
                    if (typeof(T) == typeof(EnchantableEquipment))
                    {
                        string[] enchantmentsGUIDS = (string[])Traverse.Create(jsonItem).Property("m_Enchantments").GetValue();
                        BlueprintEquipmentEnchantment[] enchantmentsBlueprints = new BlueprintEquipmentEnchantment[enchantmentsGUIDS.Length];
                        for (int i = 0; i < enchantmentsGUIDS.Length; i++)
                        {
                            string enchantmentGUID = CleanEnchantment(enchantmentsGUIDS[i]);
                            enchantmentsBlueprints[i] = (BlueprintEquipmentEnchantment)Utilities.GetBlueprintByGuid <BlueprintEquipmentEnchantment>(enchantmentGUID);
                        }

                        Traverse.Create(blueprint).Field("m_Enchantments").SetValue(enchantmentsBlueprints);

                        Common.ModLoggerDebug($"{blueprint} m_Enchantments set to {enchantmentsBlueprints}.");
                    }
                    else if (typeof(T) == typeof(ModifiedWeapon))
                    {
                        string[] enchantmentsGUIDS = (string[])Traverse.Create(jsonItem).Property("m_Enchantments").GetValue();
                        BlueprintWeaponEnchantment[] enchantmentsBlueprints = new BlueprintWeaponEnchantment[enchantmentsGUIDS.Length];
                        for (int i = 0; i < enchantmentsGUIDS.Length; i++)
                        {
                            string enchantmentGUID = CleanEnchantment(enchantmentsGUIDS[i]);
                            enchantmentsBlueprints[i] = (BlueprintWeaponEnchantment)Utilities.GetBlueprintByGuid <BlueprintWeaponEnchantment>(enchantmentGUID);
                        }
                        Traverse.Create(blueprint).Field("m_Enchantments").SetValue(enchantmentsBlueprints);

                        Common.ModLoggerDebug($"{blueprint} m_Enchantments set to {enchantmentsBlueprints}.");
                    }
                }
                else
                {
                    SetBlueprintField(blueprint, jsonItem, property.Name);
                }
            }
        }