List <AmmoIndexEntry> Load(string entityFolder) { var index = new List <AmmoIndexEntry>(); foreach (var entityFilename in Directory.EnumerateFiles(Path.Combine(DataRoot, entityFolder), "*.xml", SearchOption.AllDirectories)) { Console.WriteLine(entityFilename); var parser = new ClassParser <AmmoParams>(); var entity = parser.Parse(entityFilename); if (entity == null) { continue; } var jsonFilename = Path.Combine(OutputFolder, "ammo", $"{entity.__ref.ToLower()}.json"); var json = JsonConvert.SerializeObject(new { Raw = new { Entity = entity, } }); File.WriteAllText(jsonFilename, json); BulletProjectileParams projectiles = entity.projectileParams.BulletProjectileParams; var indexEntry = new AmmoIndexEntry { className = entity.ClassName, reference = entity.__ref, damage = Damage.FromDamageInfo(projectiles != null && projectiles.damage.Length > 0 ? projectiles.damage[0] : new DamageInfo()), speed = entity.speed, range = entity.lifetime * entity.speed, detonates = entity.projectileParams.BulletProjectileParams?.detonationParams?.ProjectileDetonationParams?.explosionParams != null, detonationDamage = Damage.FromDamageInfo(entity.projectileParams.BulletProjectileParams?.detonationParams?.ProjectileDetonationParams?.explosionParams?.damage[0]) }; index.Add(indexEntry); } return(index); }
List <ItemIndexEntry> Load(string itemsFolder) { var folderPath = Path.Combine(DataRoot, itemsFolder); var index = new List <ItemIndexEntry>(); foreach (var entityFilename in Directory.EnumerateFiles(folderPath, "*.xml", SearchOption.AllDirectories)) { if (avoidFile(entityFilename)) { continue; } EntityClassDefinition entity = null; // Entity Console.WriteLine(entityFilename); var entityParser = new ClassParser <EntityClassDefinition>(); entity = entityParser.Parse(entityFilename); if (entity == null) { continue; } if (avoidType(entity.Components?.SAttachableComponentParams?.AttachDef.Type)) { continue; } // If the entity has a loadout file, then load it if (entity.Components?.SEntityComponentDefaultLoadoutParams?.loadout?.SItemPortLoadoutXMLParams != null) { entity.Components.SEntityComponentDefaultLoadoutParams.loadout.SItemPortLoadoutXMLParams.loadoutPath = OnXmlLoadout(entity.Components.SEntityComponentDefaultLoadoutParams.loadout.SItemPortLoadoutXMLParams.loadoutPath); } var indexEntry = CreateIndexEntry(entity); indexEntry.jsonUrl = $"/api/items/{entity.ClassName.ToLower()}.json"; indexEntry.xmlSource = Path.GetRelativePath(DataRoot, entityFilename); // Add it to the item index index.Add(indexEntry); } return(index); }
List <AmmoParams> Load(string entityFolder) { var index = new List <AmmoParams>(); var parser = new ClassParser <AmmoParams>(); foreach (var filename in Directory.EnumerateFiles(Path.Combine(DataRoot, entityFolder), "*.xml", SearchOption.AllDirectories)) { if (verbose) { Console.WriteLine(filename); } var ammoParams = parser.Parse(filename); if (ammoParams == null) { continue; } index.Add(ammoParams); } return(index); }
public (Vehicle, EntityClassDefinition, ShipIndexEntry)? LoadShip(string entityFilename) { EntityClassDefinition entity = null; Vehicle vehicle = null; string vehicleModification = null; Console.WriteLine(entityFilename); // Entity var entityParser = new ClassParser <EntityClassDefinition>(); entity = entityParser.Parse(entityFilename); if (entity == null) { return(null); } if (entity.Components?.SEntityComponentDefaultLoadoutParams?.loadout?.SItemPortLoadoutXMLParams != null) { entity.Components.SEntityComponentDefaultLoadoutParams.loadout.SItemPortLoadoutXMLParams.loadoutPath = OnXmlLoadout(entity.Components.SEntityComponentDefaultLoadoutParams.loadout.SItemPortLoadoutXMLParams.loadoutPath); } if (entity.Components.VehicleComponentParams == null) { return(null); } // Vehicle var vehicleFilename = entity.Components?.VehicleComponentParams?.vehicleDefinition; if (vehicleFilename != null) { vehicleFilename = Path.Combine(DataRoot, "Data", vehicleFilename.Replace('/', '\\')); vehicleModification = entity.Components?.VehicleComponentParams?.modification; Console.WriteLine(vehicleFilename); var vehicleParser = new VehicleParser(); vehicle = vehicleParser.Parse(vehicleFilename, vehicleModification); } bool isGroundVehicle = entity.Components?.VehicleComponentParams.vehicleCareer == "@vehicle_focus_ground"; bool isGravlevVehicle = entity.Components?.VehicleComponentParams.isGravlevVehicle ?? false; bool isSpaceship = !(isGroundVehicle || isGravlevVehicle); var indexEntry = new ShipIndexEntry { className = entity.ClassName, type = entity.Components?.SAttachableComponentParams?.AttachDef.Type, subType = entity.Components?.SAttachableComponentParams?.AttachDef.SubType, name = entity.Components.VehicleComponentParams.vehicleName, career = entity.Components.VehicleComponentParams.vehicleCareer, role = entity.Components.VehicleComponentParams.vehicleRole, dogFightEnabled = Convert.ToBoolean(entity.Components.VehicleComponentParams.dogfightEnabled), size = vehicle?.size, isGroundVehicle = isGroundVehicle, isGravlevVehicle = isGravlevVehicle, isSpaceship = isSpaceship, noParts = vehicle == null || vehicle.Parts == null || vehicle.Parts.Length == 0, manufacturerCode = Manufacturers.Where(x => x.reference == entity.Components.VehicleComponentParams.manufacturer).FirstOrDefault()?.code, manufacturerName = Manufacturers.Where(x => x.reference == entity.Components.VehicleComponentParams.manufacturer).FirstOrDefault()?.name }; return(vehicle, entity, indexEntry); }
static void Main(string[] args) { string scDataRoot = null; string outputRoot = null; string itemFile = null; bool shipsOnly = false; var p = new OptionSet { { "scdata=", v => scDataRoot = v }, { "input=", v => scDataRoot = v }, { "output=", v => outputRoot = v }, { "itemfile=", v => itemFile = v }, { "shipsonly", v => shipsOnly = true } }; var extra = p.Parse(args); var badArgs = false; if (extra.Count > 0) { badArgs = true; } else if (!String.IsNullOrEmpty(itemFile) && (!String.IsNullOrEmpty(scDataRoot) || !String.IsNullOrEmpty(outputRoot))) { badArgs = true; } else if (String.IsNullOrEmpty(itemFile) && (String.IsNullOrEmpty(scDataRoot) || String.IsNullOrEmpty(outputRoot))) { badArgs = true; } if (badArgs) { Console.WriteLine("Usage:"); Console.WriteLine(" Loader.exe -input=<path to extracted Star Citizen data> -output=<path to JSON output folder>"); Console.WriteLine(" or Loader.exe -itemfile=<path to an SCItem XML file>"); Console.WriteLine(); return; } JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore }; if (itemFile != null) { var entityParser = new ClassParser <scdb.Xml.Entities.EntityClassDefinition>(); var entity = entityParser.Parse(itemFile); var json = JsonConvert.SerializeObject(entity); Console.WriteLine(json); return; } // Prep the output folder if (Directory.Exists(outputRoot) && !shipsOnly) { var info = new DirectoryInfo(outputRoot); foreach (var file in info.GetFiles()) { file.Delete(); } foreach (var dir in info.GetDirectories()) { dir.Delete(true); } } else { Directory.CreateDirectory(outputRoot); } // A loadout loader to help with any XML loadouts we encounter while parsing entities var loadoutLoader = new LoadoutLoader { OutputFolder = outputRoot, DataRoot = scDataRoot }; // Localisation Console.WriteLine("Load Localisation"); var labelLoader = new LabelsLoader { OutputFolder = outputRoot, DataRoot = scDataRoot }; var labels = labelLoader.Load("english"); var localisationSvc = new LocalisationService(labels); // Manufacturers Console.WriteLine("Load Manufacturers"); var manufacturerLoader = new ManufacturerLoader(localisationSvc) { OutputFolder = outputRoot, DataRoot = scDataRoot }; var manufacturerIndex = manufacturerLoader.Load(); // Ammunition Console.WriteLine("Load Ammunition"); var ammoLoader = new AmmoLoader { OutputFolder = outputRoot, DataRoot = scDataRoot }; var ammoIndex = ammoLoader.Load(); // Items if (!shipsOnly) { Console.WriteLine("Load Items"); var itemLoader = new ItemLoader { OutputFolder = outputRoot, DataRoot = scDataRoot, OnXmlLoadout = path => loadoutLoader.Load(path), Manufacturers = manufacturerIndex, Ammo = ammoIndex }; itemLoader.Load(); } // Ships and vehicles Console.WriteLine("Load Ships and Vehicles"); var shipLoader = new ShipLoader { OutputFolder = outputRoot, DataRoot = scDataRoot, OnXmlLoadout = path => loadoutLoader.Load(path), Manufacturers = manufacturerIndex }; shipLoader.Load(); // Prices if (!shipsOnly) { Console.WriteLine("Load Shops"); var shopLoader = new ShopLoader(localisationSvc) { OutputFolder = outputRoot, DataRoot = scDataRoot }; shopLoader.Load(); } // Starmap if (!shipsOnly) { Console.WriteLine("Load Starmap"); var starmapLoader = new StarmapLoader(localisationSvc) { OutputFolder = outputRoot, DataRoot = scDataRoot }; starmapLoader.Load(); } Console.WriteLine("Finished!"); }
List <ShopItem> GetInventory(Node prices, ShopLayoutNode shopNode) { var items = new List <ShopItem>(); if (shopNode?.ShopInventoryNodes.Length > 0) { foreach (var itemNode in shopNode.ShopInventoryNodes) { var product = FindInventoryNode(prices, itemNode.InventoryID); if (product == null) { Console.WriteLine($"Can't find product {itemNode.Name} ({itemNode.InventoryID}) "); } else { var parser = new ClassParser <EntityClassDefinition>(); var entity = parser.Parse(Path.Combine(DataRoot, product.Filename)); var item = new ShopItem { name = itemNode.Name.ToLower(), basePriceOffsetPercentage = itemNode.BasePriceOffsetPercentage, maxDiscountPercentage = itemNode.MaxDiscountPercentage, maxPremiumPercentage = itemNode.MaxPremiumPercentage, inventory = itemNode.Inventory, optimalInventoryLevel = itemNode.OptimalInventoryLevel, maxInventory = itemNode.MaxInventory, autoRestock = Convert.ToBoolean(itemNode.AutoRestock), autoConsume = Convert.ToBoolean(itemNode.AutoConsume), refreshRatePercentagePerMinute = itemNode.RefreshRatePercentagePerMinute, shopBuysThis = itemNode.TransactionTypes.Any(x => x.Data == "Sell"), shopSellsThis = itemNode.TransactionTypes.Any(x => x.Data == "Buy"), shopRentThis = itemNode.TransactionTypes.Any(x => x.Data == "Rent"), basePrice = product.BasePrice, filename = product.Filename, node_reference = itemNode.ID, item_reference = itemNode.InventoryID, rentalTemplates = new List <ShopRentalTemplate>() }; foreach (var rentalTemplate in itemNode.RentalTemplates) { var template = rentalTemplates.Find(y => y.ShopRentalTemplate.ID == rentalTemplate.Data); if (template != null) { item.rentalTemplates.Add(template.ShopRentalTemplate); } } if (entity?.Components.SAttachableComponentParams != null) { item.displayName = localisationService.GetText(entity.Components.SAttachableComponentParams.AttachDef.Localization.Name); item.tags = entity.Components.SAttachableComponentParams.AttachDef.Tags.Split(" "); item.type = entity.Components.SAttachableComponentParams.AttachDef.Type; item.subType = entity.Components.SAttachableComponentParams.AttachDef.SubType; } if (entity?.Components.CommodityComponentParams != null) { item.displayName = localisationService.GetText(entity.Components.CommodityComponentParams.name); } items.Add(item); } } } return(items); }