public static Mech BuildTestMech(float tonnage) { Mech mech = new Mech(); MechDef mechDef = new MechDef(); DescriptionDef descriptionDef = new DescriptionDef("foo", "bar", "raboof", "", 100, 0, true, "", "", ""); ChassisDef chassisDef = new ChassisDef(descriptionDef, "", "", "", "", "", tonnage, tonnage, WeightClass.ASSAULT, 0, 0, 0, 0, 0, 0, new float[] { 0 }, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, 0, 0, 0, new LocationDef[] { }, new MechComponentRef[] { }, new HBS.Collections.TagSet()); Traverse tonnageT = Traverse.Create(chassisDef).Property("Tonnage"); tonnageT.SetValue(tonnage); Traverse chassisT = Traverse.Create(mechDef).Field("_chassisDef"); chassisT.SetValue(chassisDef); Traverse mechDefT = Traverse.Create(mech).Property("MechDef"); mechDefT.SetValue(mechDef); mech = (Mech)InitAbstractActor(mech); return(mech); }
// This always returns a quantity of 1! public static SalvageDef CloneToXName(SalvageDef salvageDef, int quantity, int count) { string uiNameWithQuantity = $"{salvageDef.Description.UIName} <lowercase>[QTY:{quantity}]</lowercase>"; DescriptionDef newDescDef = new DescriptionDef( salvageDef.Description.Id, salvageDef.Description.Name, salvageDef.Description.Details, salvageDef.Description.Icon, salvageDef.Description.Cost, salvageDef.Description.Rarity, salvageDef.Description.Purchasable, salvageDef.Description.Manufacturer, salvageDef.Description.Model, uiNameWithQuantity ); SalvageDef newDef = new SalvageDef(salvageDef) { Description = newDescDef, RewardID = $"{salvageDef.RewardID}_c{count}_qty{quantity}", Count = 1 }; return(newDef); }
// This always returns a quantity of 1! public static SalvageDef CloneToXName(SalvageDef salvageDef, int quantity, int count) { // don't create QTY:1 strings string displayName = !String.IsNullOrEmpty(salvageDef.Description.UIName) ? salvageDef.Description.UIName : salvageDef.Description.Name; string uiNameWithQuantity = quantity > 1 ? $"{displayName} <lowercase>[QTY:{quantity}]</lowercase>" : displayName; // increase the value of the def DescriptionDef newDescDef = new DescriptionDef( salvageDef.Description.Id, salvageDef.Description.Name, salvageDef.Description.Details, salvageDef.Description.Icon, salvageDef.Description.Cost * quantity, salvageDef.Description.Rarity, salvageDef.Description.Purchasable, salvageDef.Description.Manufacturer, salvageDef.Description.Model, uiNameWithQuantity ); SalvageDef newDef = new SalvageDef(salvageDef) { Description = newDescDef, RewardID = $"{salvageDef.RewardID}_c{count}_qty{quantity}", Count = 1 }; Mod.Log.Debug?.Write($"Incoming for {quantity}, Cost in {salvageDef.Description.Cost}, out {newDef.Description.Cost}"); return(newDef); }
// This always returns a quantity of 1! public static SalvageDef CloneToXName(SalvageDef salvageDef, int quantity, int count) { string localItemName = new Text(salvageDef.Description.Name).ToString(); string localItemAndQuantity = new Text( Mod.Config.DialogText[ModConfig.DT_ITEM_AND_QUANTITY], new object[] { localItemName, quantity } ).ToString(); DescriptionDef newDescDef = new DescriptionDef( salvageDef.Description.Id, salvageDef.Description.Name, salvageDef.Description.Details, salvageDef.Description.Icon, salvageDef.Description.Cost, salvageDef.Description.Rarity, salvageDef.Description.Purchasable, salvageDef.Description.Manufacturer, salvageDef.Description.Model, localItemAndQuantity ); SalvageDef newDef = new SalvageDef(salvageDef) { Description = newDescDef, RewardID = $"{salvageDef.RewardID}_c{count}_qty{quantity}", Count = 1 }; return(newDef); }
internal static void AddBonusDescriptions( DescriptionDef descriptionDef, IEnumerable <string> elements, string elementTemplate, string descriptionTemplate) { var adapter = new DescriptionDefAdapter(descriptionDef); var bonuses = string.Join("", elements.Where(x => x != null).Select(x => elementTemplate.Replace("{{element}}", x)).ToArray()); adapter.Details = descriptionTemplate.Replace("{{elements}}", bonuses).Replace("{{originalDescription}}", adapter.Details); }
static void Postfix(Shop __instance, ShopDefItem item, Shop.ShopType shopType, ref int __result) { try { if (shopType == Shop.ShopType.Faction) { DescriptionDef itemDescription = __instance.GetItemDescription(item); __result = Mathf.CeilToInt(itemDescription.Cost * item.DiscountModifier); } } catch (Exception e) { PersistentMapClient.Logger.LogError(e); } }
public static void Postfix(Shop __instance, ref DescriptionDef __result, ShopDefItem item, SimGameState ___Sim) { try { // Info only /* * if (item.Type == ShopItemType.Mech) * { * Logger.Debug("[Shop_GetItemDescription_POSTFIX] item.Type: " + item.Type.ToString()); * Logger.Debug("[Shop_GetItemDescription_POSTFIX] item.ID: " + item.ID); * // BEN: Beware! Description.Cost gets calculated in MechDef.RefreshBattleValue called by MechDef.CopyFrom and possibly some MechDef constructors... * Logger.Debug("[Shop_GetItemDescription_POSTFIX] ___Sim.DataManager.MechDefs.Get(item.ID).Description.Id: " + ___Sim.DataManager.MechDefs.Get(item.ID).Description.Id); * Logger.Debug("[Shop_GetItemDescription_POSTFIX] ___Sim.DataManager.MechDefs.Get(item.ID).Description.Name: " + ___Sim.DataManager.MechDefs.Get(item.ID).Description.Name); * Logger.Debug("[Shop_GetItemDescription_POSTFIX] ___Sim.DataManager.MechDefs.Get(item.ID).Description.Cost: " + ___Sim.DataManager.MechDefs.Get(item.ID).Description.Cost); * Logger.Debug("[Shop_GetItemDescription_POSTFIX] __result.Cost: " + __result.Cost); * * return; * } */ if (item.Type != ShopItemType.MechPart) { return; } //Logger.Debug("[Shop_GetItemDescription_POSTFIX] __result.Cost BEFORE: " + __result.Cost); MechDef mechDef = ___Sim.DataManager.MechDefs.Get(item.ID); DescriptionDef description = mechDef.Description; int defaultMechPartMax = ___Sim.Constants.Story.DefaultMechPartMax; int AdjustedMechPartCost = (int)Math.Floor((mechDef.Chassis.Description.Cost / defaultMechPartMax) * LittleThings.Settings.EnableAdjustedMechPartCostMultiplier); __result = new DescriptionDef(description.Id, string.Format("{0} Mech Part", description.Name), description.Details, description.Icon, AdjustedMechPartCost, description.Rarity, description.Purchasable, description.Manufacturer, description.Model, description.UIName); /* * Logger.Debug("[Shop_GetItemDescription_POSTFIX] description.Name: " + description.Name); * Logger.Debug("[Shop_GetItemDescription_POSTFIX] mechDef.SimGameMechPartCost: " + mechDef.SimGameMechPartCost); * Logger.Debug("[Shop_GetItemDescription_POSTFIX] mechDef.Chassis.Description.Cost: " + mechDef.Chassis.Description.Cost); * Logger.Debug("[Shop_GetItemDescription_POSTFIX] ___Sim.Constants.Story.DefaultMechPartMax: " + ___Sim.Constants.Story.DefaultMechPartMax); * Logger.Debug("[Shop_GetItemDescription_POSTFIX] Recalculate MechPartCost (Chassis.Cost / PartsToAssemble) * Settings.AdjustMechPartCostMultiplier: (" + mechDef.Chassis.Description.Cost + " / " + defaultMechPartMax + ") * " + LittleThings.Settings.EnableAdjustedMechPartCostMultiplier); * Logger.Debug("[Shop_GetItemDescription_POSTFIX] AdjustedMechPartCost: " + AdjustedMechPartCost); * Logger.Debug("[Shop_GetItemDescription_POSTFIX] __result.Cost AFTER: " + __result.Cost); * Logger.Debug("---"); */ } catch (Exception e) { Logger.Error(e); } }
public static SalvageDef CreateMechPart(Contract contract, SimGameConstants sc, MechDef m) { SalvageDef salvageDef = new SalvageDef(); salvageDef.Type = SalvageDef.SalvageType.MECH_PART; salvageDef.ComponentType = ComponentType.MechPart; salvageDef.Count = 1; salvageDef.Weight = sc.Salvage.DefaultMechPartWeight; DescriptionDef description = m.Description; DescriptionDef description2 = new DescriptionDef(description.Id, string.Format("{0} {1}", description.Name, sc.Story.DefaultMechPartName), description.Details, description.Icon, description.Cost, description.Rarity, description.Purchasable, description.Manufacturer, description.Model, description.UIName); salvageDef.Description = description2; salvageDef.RewardID = contract.GenerateRewardUID(); return(salvageDef); }
public static void Postfix(ListElementController_SalvageMechPart_NotListView __instance, InventoryItemElement_NotListView theWidget, MechDef ___mechDef, SalvageDef ___salvageDef) { Mod.Log.Debug($"LEC_SMP_NLV:RIOW - entered"); if (___salvageDef.RewardID != null && ___salvageDef.RewardID.Contains("_qty")) { int qtyIdx = ___salvageDef.RewardID.IndexOf("_qty"); string countS = ___salvageDef.RewardID.Substring(qtyIdx + 4); int count = int.Parse(countS); Mod.Log.Debug($"LEC_SMP_NLV:RIOW - found quantity {count}, changing mechdef"); DescriptionDef currentDesc = ___mechDef.Chassis.Description; string newUIName = $"{currentDesc.UIName} <lowercase>[QTY:{count}]</lowercase>"; Text newPartName = new Text(newUIName, new object[] { }); theWidget.mechPartName.SetText(newPartName); } }
public static bool Prefix(Shop __instance, ref int __result, ShopDefItem item, Shop.PurchaseType purchaseType, Shop.ShopType shopType) { DescriptionDef itemDescription = __instance.GetItemDescription(item); if (itemDescription == null) { Debug.LogError("Error :: Shop.GetPrice() GetItemDescription on: " + item.ID + " returned a NULL"); __result = 0; return(false); } var this_system = Traverse.Create(__instance).Field("system").GetValue <StarSystem>(); float num = (float)itemDescription.Cost; float shop = this_system.Discount.Shop; if (num <= 0) { __result = Mathf.RoundToInt(num); return(false); } if (purchaseType != Shop.PurchaseType.Normal) { num *= item.DiscountModifier; } int num2 = Mathf.RoundToInt(num + (num * shop)); float num3; var this_shop = Traverse.Create(__instance).Field("Sim").GetValue <SimGameState>(); if (shopType != Shop.ShopType.Faction) { if (shopType != Shop.ShopType.BlackMarket) { num3 = this_shop.GetReputationShopAdjustment(this_system.Def.OwnerValue) * num; } else { num3 = this_shop.GetReputationShopAdjustment(FactionEnumeration.GetAuriganPiratesFactionValue()) * num; } } else { num3 = this_shop.GetReputationShopAdjustment(this_system.Def.FactionShopOwnerValue) * num; } __result = Mathf.CeilToInt(Mathf.Clamp((float)num2 + num3, 0f, 1E+09f)); return(false); }
public static void newmap() { JArray jarray = JArray.Parse(File.ReadAllText(@"C:\Program Files (x86)\Steam\steamapps\common\BATTLETECH\mods\OldData\systems.json")); string newdata = File.ReadAllText(@"C:\Program Files (x86)\Steam\steamapps\common\BATTLETECH\mods\OldData\planetstest.json"); JArray newdataArray = JArray.Parse(newdata); foreach (JObject system in jarray) { if (!((string)system["affiliation"]).Equals("Clans") && !((string)system["affiliation"]).Equals("Inhabited system") && !((string)system["affiliation"]).Equals("No record") && !((string)system["affiliation"]).Equals("Clan") && !((string)system["affiliation"]).Equals("New Delphi Compact") && !((string)system["affiliation"]).Equals("Alexandrian Covenant") && !((string)system["affiliation"]).Equals("Society of St.Andreas") && !((string)system["affiliation"]).Equals("Hidden system") && !((string)system["affiliation"]).Equals("Society of St. Andreas") && !((string)system["affiliation"]).Equals("Tortuga Dominions") && !((string)system["affiliation"]).Equals("Fiefdom of Randis") && !((string)system["name"]).Equals("New St. Andrews") && !((string)system["name"]).Equals("Mica I") && !((string)system["name"]).Equals("Mica V") && !((string)system["name"]).Equals("Novo Franklin") && !((string)system["name"]).Equals("New Vandenberg") && !((string)system["name"]).Equals("Mica VII")) { FakeVector3 vector = new FakeVector3(); vector.x = (float)system["x"]; vector.y = (float)system["y"]; vector.z = 0; Faction faction; string folder = ""; TagSet tags = new TagSet(); int maxspecials = 0; switch ((string)system["affiliation"]) { case "Lyran Commonwealth": maxspecials++; faction = Faction.Steiner; folder = "Steiner"; tags.Add("planet_civ_innersphere"); tags.Add("planet_faction_steiner"); break; case "Free Worlds League": maxspecials++; faction = Faction.Marik; folder = "Marik"; tags.Add("planet_civ_innersphere"); tags.Add("planet_faction_marik"); break; case "Draconis Combine": maxspecials++; faction = Faction.Kurita; folder = "Kurita"; tags.Add("planet_civ_innersphere"); tags.Add("planet_faction_kurita"); break; case "Federated Suns": maxspecials++; faction = Faction.Davion; folder = "Davion"; tags.Add("planet_civ_innersphere"); tags.Add("planet_faction_davion"); break; case "Capellan Confederation": maxspecials++; faction = Faction.Liao; folder = "Liao"; tags.Add("planet_civ_innersphere"); tags.Add("planet_faction_liao"); break; case "Aurigan Coalition": faction = Faction.AuriganRestoration; folder = "Aurigan"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_restoration"); break; case "ComStar": maxspecials++; faction = Faction.ComStar; folder = "ComStar"; tags.Add("planet_civ_innersphere"); break; case "Magistracy of Canopus": faction = Faction.MagistracyOfCanopus; folder = "Magistracy"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_magistracy"); break; case "Taurian Concordat": faction = Faction.TaurianConcordat; folder = "Taurian"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_taurian"); break; case "Outworlds Alliance": faction = Faction.Betrayers; folder = "Outworld"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_outworlds"); break; case "Marian Hegemony": faction = Faction.AuriganDirectorate; folder = "Hegemony"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_marian"); break; case "Oberon Confederation": faction = Faction.MagistracyCentrella; folder = "Oberon"; maxspecials++; tags.Add("planet_civ_periphery"); tags.Add("planet_other_pirate"); tags.Add("planet_other_blackmarket"); tags.Add("planet_faction_oberon"); break; case "Lothian League": faction = Faction.MajestyMetals; folder = "Lothian"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_lothian"); break; case "Circinus Federation": faction = Faction.Nautilus; folder = "Circinus"; maxspecials++; tags.Add("planet_civ_periphery"); tags.Add("planet_other_pirate"); tags.Add("planet_other_blackmarket"); tags.Add("planet_faction_circinus"); break; case "Illyrian Palatinate": faction = Faction.AuriganMercenaries; folder = "Illyrian"; tags.Add("planet_civ_periphery"); tags.Add("planet_faction_illyrian"); break; default: faction = Faction.Locals; folder = "Locals"; tags.Add("planet_civ_periphery"); break; } if (((string)system["name"]).Equals("Galatea")) { faction = Faction.MercenaryReviewBoard; folder = "MRB"; tags.Remove("planet_faction_steiner"); } string beginjson = File.ReadAllText("C:/Users/morph/Desktop/Neuer Ordner (4)/starsystemdef_Detroit.json"); string name = (string)system["name"]; StarSystemDef def = new StarSystemDef(); def.FromJSON(beginjson); bool fueling = false; string details = " "; List <Biome.BIOMESKIN> biomes = new List <Biome.BIOMESKIN>();; bool newdatafound = false; foreach (JObject newdataObject in newdataArray) { biomes = new List <Biome.BIOMESKIN>(); if (system["name"].Equals(newdataObject["Planet_Name"])) { newdatafound = true; if (!string.IsNullOrEmpty((string)newdataObject["Description"])) { details = ((string)newdataObject["Description"]).Replace("\t", "").Replace("\\", "").Replace("</P>", "").Replace("<P>", "").Replace("\r", "").Replace("\n", "").Replace("</p>", "").Replace("<p>", ""); if (details.Length > 255) { details = details.Substring(0, 255); } } if ((int)newdataObject["Industry"] != 0) { tags.Add("planet_industry_mining"); if ((int)newdataObject["Industry"] >= 100000000) { maxspecials++; tags.Add("planet_industry_rich"); } else { tags.Add("planet_industry_recreation"); } } else { tags.Add("planet_industry_agriculture"); tags.Add("planet_industry_aquaculture"); tags.Add("planet_industry_poor"); } if (!string.IsNullOrEmpty((string)newdataObject["comstar_facility"]) && !((string)newdataObject["comstar_facility"]).Equals("None")) { tags.Add("planet_industry_research"); tags.Add("planet_other_comstar"); tags.Add("planet_other_starleague"); maxspecials++; } if ((int)newdataObject["Capital_Planet"] == 1) { tags.Add("planet_other_capital"); maxspecials++; } if ((long)newdataObject["population"] > 1000000000) { tags.Add("planet_pop_large"); maxspecials++; maxspecials++; if ((long)newdataObject["population"] > 5000000000) { tags.Add("planet_other_megacity"); maxspecials++; } } else if ((int)newdataObject["population"] > 100000000) { tags.Add("planet_pop_medium"); maxspecials++; } else if ((int)newdataObject["population"] > 1000000) { tags.Add("planet_pop_small"); } else { tags.Add("planet_pop_none"); } if ((int)newdataObject["Charge_Station"] == 1) { fueling = true; } if ((int)newdataObject["Factory"] == 123) { tags.Add("planet_industry_manufacturing"); maxspecials++; maxspecials++; } if ((int)newdataObject["hiringhall"] == 1) { tags.Add("planet_other_hub"); } switch ((int)newdataObject["terrain_class_ID"]) { case 1: { tags.Add("planet_climate_terran"); tags.Add("planet_other_megaforest"); biomes.Add(Biome.BIOMESKIN.highlandsSpring); biomes.Add(Biome.BIOMESKIN.highlandsFall); biomes.Add(Biome.BIOMESKIN.lowlandsSpring); biomes.Add(Biome.BIOMESKIN.lowlandsFall); biomes.Add(Biome.BIOMESKIN.badlandsParched); break; } case 2: { tags.Add("planet_climate_lunar"); tags.Add("planet_other_moon"); biomes.Add(Biome.BIOMESKIN.martianVacuum); biomes.Add(Biome.BIOMESKIN.lunarVacuum); break; } case 3: { tags.Add("planet_climate_desert"); tags.Add("planet_other_storms"); biomes.Add(Biome.BIOMESKIN.desertParched); break; } case 4: { tags.Add("planet_climate_arid"); tags.Add("planet_other_mudflats"); tags.Add("planet_other_fungus"); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); biomes.Add(Biome.BIOMESKIN.badlandsParched); break; } case 5: { tags.Add("planet_climate_arctic"); biomes.Add(Biome.BIOMESKIN.polarFrozen); biomes.Add(Biome.BIOMESKIN.tundraFrozen); break; } case 6: { tags.Add("planet_climate_tropical"); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); biomes.Add(Biome.BIOMESKIN.lowlandsSpring); biomes.Add(Biome.BIOMESKIN.lowlandsFall); break; } case 7: { tags.Add("planet_climate_rocky"); biomes.Add(Biome.BIOMESKIN.highlandsSpring); biomes.Add(Biome.BIOMESKIN.highlandsFall); break; } case 8: { tags.Add("planet_climate_mars"); tags.Add("planet_other_volcanic"); biomes.Add(Biome.BIOMESKIN.martianVacuum); biomes.Add(Biome.BIOMESKIN.badlandsParched); break; } case 10: { tags.Add("planet_climate_terran"); tags.Add("planet_other_megaforest"); biomes.Add(Biome.BIOMESKIN.highlandsSpring); biomes.Add(Biome.BIOMESKIN.highlandsFall); biomes.Add(Biome.BIOMESKIN.lowlandsSpring); biomes.Add(Biome.BIOMESKIN.lowlandsFall); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); break; } case 18: { tags.Add("planet_climate_water"); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); biomes.Add(Biome.BIOMESKIN.highlandsSpring); break; } default: { tags.Add("planet_climate_terran"); biomes.Add(Biome.BIOMESKIN.highlandsSpring); biomes.Add(Biome.BIOMESKIN.highlandsFall); biomes.Add(Biome.BIOMESKIN.lowlandsSpring); biomes.Add(Biome.BIOMESKIN.lowlandsFall); biomes.Add(Biome.BIOMESKIN.desertParched); biomes.Add(Biome.BIOMESKIN.badlandsParched); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); biomes.Add(Biome.BIOMESKIN.lunarVacuum); biomes.Add(Biome.BIOMESKIN.martianVacuum); biomes.Add(Biome.BIOMESKIN.polarFrozen); biomes.Add(Biome.BIOMESKIN.tundraFrozen); break; } } break; } } if (newdatafound) { tags.Add("planet_size_medium"); } else { tags.Add("planet_climate_terran"); tags.Add("planet_size_medium"); biomes.Add(Biome.BIOMESKIN.highlandsSpring); biomes.Add(Biome.BIOMESKIN.highlandsFall); biomes.Add(Biome.BIOMESKIN.lowlandsSpring); biomes.Add(Biome.BIOMESKIN.lowlandsFall); biomes.Add(Biome.BIOMESKIN.desertParched); biomes.Add(Biome.BIOMESKIN.badlandsParched); biomes.Add(Biome.BIOMESKIN.lowlandsCoastal); biomes.Add(Biome.BIOMESKIN.lunarVacuum); biomes.Add(Biome.BIOMESKIN.martianVacuum); biomes.Add(Biome.BIOMESKIN.polarFrozen); biomes.Add(Biome.BIOMESKIN.tundraFrozen); } DescriptionDef desc = new DescriptionDef(("starsystemdef_" + system["name"]).Replace(" ", string.Empty).Replace("'", string.Empty), (string)system["name"], details, "", 0, 0, false, "", "", ""); StarSystemDef def2 = new StarSystemDef(desc, vector, tags, false, 7, faction, getAllies(faction), getEnemies(faction), def.SystemInfluence, def.TravelRequirements); foreach (JObject newdataObject in newdataArray) { if (system["name"].Equals(newdataObject["Planet_Name"])) { break; } } ReflectionHelper.InvokePrivateMethode(def2, "set_FuelingStation", new object[] { fueling }); ReflectionHelper.InvokePrivateMethode(def2, "set_Difficulty", new object[] { 5 }); ReflectionHelper.InvokePrivateMethode(def2, "set_StarType", new object[] { StarType.G }); ReflectionHelper.InvokePrivateMethode(def2, "set_JumpDistance", new object[] { 7 }); ReflectionHelper.InvokePrivateMethode(def2, "set_ShopMaxSpecials", new object[] { maxspecials }); ReflectionHelper.InvokePrivateMethode(def2, "set_SupportedBiomes", new object[] { biomes }); foreach (JObject newdataObject in newdataArray) { if (system["name"].Equals(newdataObject["Planet_Name"])) { ReflectionHelper.InvokePrivateMethode(def2, "set_StarType", new object[] { getStartype((string)newdataObject["SpecClass"]) }); if ((float)newdataObject["travel_time"] != 0f) { ReflectionHelper.InvokePrivateMethode(def2, "set_JumpDistance", new object[] { (int)newdataObject["travel_time"] }); } break; } } string json = def2.ToJSON(); JObject jsonObject = JObject.Parse(json); JObject descriptionjson = (JObject)jsonObject["Description"]; descriptionjson.Add("Id", "starsystemdef_" + ((string)system["name"]).Replace(" ", string.Empty).Replace("'", string.Empty)); descriptionjson.Add("Name", (string)system["name"]); descriptionjson.Add("Details", details); // string json = JsonConvert.SerializeObject(def2, new Newtonsoft.Json.Converters.StringEnumConverter()); string path = "C:/Program Files (x86)/Steam/steamapps/common/BATTLETECH/mods/OldData/" + folder + "/starsystemdef_" + ((string)system["name"]).Replace(" ", string.Empty).Replace("'", string.Empty) + ".json"; (new FileInfo(path)).Directory.Create(); File.WriteAllText(path, jsonObject.ToString()); } } }