Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            //var sourceDirectory = @"C:\Users\Stephen Weistra\gitrepos\RogueTech";
            //var sourceDirectory = @"D:\XLRP Fixes\XLRP - Reference - 20190725 - With CAB";
            //var sourceDirectory = @"C:\Users\Stephen Weistra\gitrepos\XLRP-Sammael\Build\XLRP\1.8 Clean Build";
            //var sourceDirectory = @"C:\Users\Stephen Weistra\gitrepos\XLRP-Complete";
            //var sourceDirectory = @"D:\Test Data\XAI";

            //var sourceDirectory = @"C:\Users\Stephen Weistra\gitrepos\XLRP-Complete";
            //var btDirectory = @"D:\Test Data\BT Base Data";
            //var dlcDirectory = @"C:\Users\Stephen Weistra\gitrepos\bt-dlc-designdata";

            var sourceDirectory = @"C:\Games\Steam\steamapps\common\BATTLETECH\Mods";
            var btDirectory     = @"C:\Games\Steam\steamapps\common\BATTLETECH";
            var dlcDirectory    = @"C:\Games\Steam\steamapps\common\BATTLETECH\Repository\bt-dlc-designdata";

            var manifestService = new ManifestService();
            var manifest        = manifestService.InitManifestFromDisk(btDirectory, dlcDirectory);

            System.Console.WriteLine("Unknown types = \r\n" +
                                     $"{string.Join("\r\n", VersionManifestParser.UnknownTypes.ToList())}");

            var modService    = new ModService();
            var modCollection = modService.LoadModCollectionFromDirectory(sourceDirectory);

            modService.PublishLoadResults(modCollection);

            /*var typeUnion = VersionManifestParser.AllTypes;
             * modCollection.Mods.SelectMany(mod => mod.ManifestEntryGroups.Select(group => group.Type)).Distinct()
             *  .ToList().ForEach(s => typeUnion.Add(s));
             * var sortedTypes = typeUnion.ToList();
             * sortedTypes.Sort(string.CompareOrdinal);
             * var typeEnumString = TypeEnumGenerator.GenerateEnum(
             *  sortedTypes,
             *  "",
             *  "GameObjectTypeEnum"
             * );
             *
             * System.Console.WriteLine("Generated Type Enum:\r\n" +
             *                       $"{typeEnumString}");*/

            modCollection.ExpandManifestGroups();

            var result = ModMerger.Merge(manifest, modCollection);

            System.Console.WriteLine("Failed Merges : \r\n" +
                                     $"{string.Join("\r\n", ModMerger.FailedMerges.Select(tuple => $"{tuple.Item1.FileInfo.FullName} - {tuple.Item2}"))}");

            /*var objectsWithStatusEffects = result.mergedManifestEntries.Where(entry =>
             * {
             *  if (entry.GameObjectType == GameObjectTypeEnum.Prefab || !entry.FileInfo.Extension.Contains("json"))
             *  {
             *      return false;
             *  }
             *
             *  var statusEffects = entry.Json["statusEffects"];
             *  if (statusEffects == null)
             *  {
             *      return false;
             *  }
             *
             *  if (!(statusEffects is JArray))
             *  {
             *      if (statusEffects.Type != JTokenType.Null)
             *      {
             *          return true;
             *      }
             *
             *      return false;
             *  }
             *
             *  statusEffects = (JArray) statusEffects;
             *  foreach (var statusEffect in statusEffects)
             *  {
             *      var description = statusEffect["Description"];
             *      if (description == null)
             *      {
             *          return true;
             *      }
             *
             *      var id = description["Id"];
             *      if (id == null)
             *      {
             *          return true;
             *      }
             *  }
             *
             *  return false;
             * });*/

            ContentExtractors.GenerateStoreContentList(result.mergedManifestEntries, @"C:\tmp\",
                                                       @"test-xlrp-store-content.xlsx");
            // ContentExtractors.GenerateTacticalContentList(result.mergedManifestEntries, @"C:\tmp\", @"content.xlsx");

            /*var planetTags = PlanetTagEnumerator.EnumeratePlanetTags(result.mergedManifestEntries);
             * planetTags.GroupBy(tag => tag.category, tag => tag.value, (category, tags) => new {category = category, tags = tags}).ToList().ForEach(tagGroup =>
             * {
             *  System.Console.WriteLine($"-----{tagGroup.category}");
             *  System.Console.WriteLine(string.Join("\r\n", tagGroup.tags));
             * });*/

            //System.Console.WriteLine(string.Join("\r\n", );

            /*System.Console.WriteLine($"Objects with JObject statusEffects, status effects with NULL descriptions or description.IDs:\r\n" +
             *                       $"{string.Join("\r\n", objectsWithStatusEffects.Select(entry => entry.FileInfo.FullName))}");*/

            //var ablities = result.mergedManifestEntries.Where(entry => entry.GameObjectType == GameObjectTypeEnum.AbilityDef).ToList();
            //var bad_abilities = ablities.Where(entry => entry.Json["Description"] == null || entry.Json["Description"].ToString() == string.Empty).ToList();

            /*var modifiedIds = result.manifestEntryStackById.Where(pair => pair.Value.Count > 1);
             * System.Console.WriteLine($"Ids modified multiple times via modifications:\r\n" +
             *                       $"{string.Join("\r\n", modifiedIds.Select(pair => $"\t{pair.Key} - {pair.Value.Count}"))}");*/

            /*var weapons = result.mergedManifestEntries.Where(entry => entry.GameObjectType == GameObjectTypeEnum.WeaponDef).Select(entry => WeaponBase.FromJson(entry.Json.ToString())).ToList();
             * weapons.Sort((weapon1, weapon2) => string.CompareOrdinal(weapon1.Description.Id, weapon2.Description.Id));
             * using (var file = File.CreateText(@"c:\tmp\btms-weapons.csv"))
             * {
             *  file.WriteLine($"Description.Id|Category|AttackRecoil|weapon.AccuracyModifier|weapon.AmmoCategory|weapon.AoeCapable|" +
             *                 $"weapon.BonusValueA|weapon.BonusValueB|weapon.CanExplode|weapon.Category|weapon.CriticalChanceMultiplier|" +
             *                 $"weapon.Damage|weapon.DamageVariance|weapon.EvasiveDamageMultiplier|weapon.EvasivePipsIgnored|weapon.HeatDamage|weapon.HeatGenerated|" +
             *                 $"weapon.IndirectFireCapable|weapon.Instability|weapon.InventorySize|weapon.MaxRange|weapon.MinRange|weapon.OverheatedDamageMultiplier|" +
             *                 $"weapon.ProjectilesPerShot|weapon.RefireModifier|weapon.ShotsWhenFired|weapon.StartingAmmoCapacity|weapon.RangeSplit|" +
             *                 $"weapon.WeaponSubType");
             *  foreach (var weapon in weapons)
             *  {
             *      file.WriteLine($"{weapon.Description.Id}|{weapon.Category}|{weapon.AttackRecoil}|{weapon.AccuracyModifier}|{weapon.AmmoCategory}|{weapon.AoeCapable}|" +
             *                     $"'{weapon.BonusValueA}|'{weapon.BonusValueB}|{weapon.CanExplode}|{weapon.Category}|{weapon.CriticalChanceMultiplier}|" +
             *                     $"{weapon.Damage}|{weapon.DamageVariance}|{weapon.EvasiveDamageMultiplier}|{weapon.EvasivePipsIgnored}|{weapon.HeatDamage}|{weapon.HeatGenerated}|" +
             *                     $"{weapon.IndirectFireCapable}|{weapon.Instability}|{weapon.InventorySize}|{weapon.MaxRange}|{weapon.MinRange}|{weapon.OverheatedDamageMultiplier}|" +
             *                     $"{weapon.ProjectilesPerShot}|{weapon.RefireModifier}|{weapon.ShotsWhenFired}|{weapon.StartingAmmoCapacity}|{string.Join(",", weapon.RangeSplit)}|" +
             *                     $"{weapon.WeaponSubType}");
             *  }
             * }*/

            /*System.Console.WriteLine($"Mechs!\r\n" +
             *                       $"{string.Join("\r\n", result.mergedManifestEntries.Where(entry => entry.GameObjectType == GameObjectTypeEnum.MechDef).Select(entry => entry.Id))}");*/

            /*var weapons = result.mergedManifestEntries.Where(entry => entry.GameObjectType == GameObjectTypeEnum.WeaponDef).Select(entry => $"{entry.Id} - {entry.GameObjectType} - {entry.AssetBundleName}").ToList();
             * weapons.Sort();
             * System.Console.WriteLine("Distinct Weapon Definitions:\r\n" +
             *                       $"{string.Join("\r\n", weapons)}");
             *
             * System.Console.WriteLine($"Mechs!\r\n" +
             *  $"{string.Join("\r\n", result.mergedManifestEntries.Where(entry => entry.GameObjectType == GameObjectTypeEnum.MechDef).Select(entry => entry.Id))}");
             *
             * System.Console.WriteLine($"mechdef_annihilator_ANH-1A\r\n" +
             *                       $"{result.mergedManifestEntries.First(entry => entry.Id == "mechdef_annihilator_ANH-1A").Json}");*/

            System.Console.WriteLine("Press any key to exit...");
            System.Console.ReadKey();
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            args.ToList().ForEach(s =>
            {
                if (!Directory.Exists(s))
                {
                    throw new InvalidProgramException($"Specified directory [{s}] cannot be found.");
                }
            });

            var designsDirectory = args[0];
            var btDirectory      = args[1];
            var dlcDirectory     = args[2];
            var sourceDirectory  = args[3];

            // Load all Battle Engine designs available from the specified directory...
            var designFiles = Directory.EnumerateFiles(designsDirectory, "*.bed", SearchOption.AllDirectories);
            var mechDesigns = new List <MechDesign>();

            designFiles
            .ToList()
            .ForEach(filePath =>
            {
                var mechDesign = MechDesign.MechDesignFromFile(filePath);
                mechDesigns.Add(mechDesign);
            });

            Console.WriteLine($"Processed [{mechDesigns.Count()}] designs...");

            // Load the base HBS BT manifest...
            var manifestService = new ManifestService();
            var manifest        = manifestService.InitManifestFromDisk(btDirectory, dlcDirectory);

            // Load the Mod Collection resources...
            var modService    = new ModService();
            var modCollection = modService.LoadModCollectionFromDirectory(sourceDirectory);

            modService.PublishLoadResults(modCollection);
            modCollection.ExpandManifestGroups();

            // Merge the base manifest with the mod collection resources
            var result      = ModMerger.Merge(manifest, modCollection);
            var groupedData = result.mergedManifestEntries.GroupBy(entry => entry.GameObjectType, entry => entry,
                                                                   (type, entries) => new { GameObjectType = type, objects = entries });

            // Build up a handy-dandy type dictionary from the merged manifests...
            var typeDictionary = groupedData
                                 .ToDictionary(arg => arg.GameObjectType, arg => arg.objects.ToList());

            // Build up a handy-dandy list of mech asset bundles from chassis data...
            var chassisUsedAssetBundles = typeDictionary[GameObjectTypeEnum.ChassisDef]
                                          .Select(entry => entry.Json["PrefabIdentifier"].ToString().ToLower()).Distinct();

            var foundAssetBundles = typeDictionary[GameObjectTypeEnum.AssetBundle].Select(entry => entry.Id.ToLower());

            var unionAssetBundles = chassisUsedAssetBundles.Union(foundAssetBundles).Distinct().ToList();

            // Console.WriteLine(string.Join("\r\n", unionAssetBundles));

            System.Console.WriteLine("Failed Merges : \r\n" +
                                     $"{string.Join("\r\n", ModMerger.FailedMerges.Select(tuple => $"{tuple.Item1.FileInfo.FullName} - {tuple.Item2}"))}");

            var filterEras = new List <Era>()
            {
                Era.Star_League,
                Era.EarlySuccessionWar,
                Era.LateSuccessionWarLosTech,
                Era.LateSuccessionWarRenaissance,
                Era.Clan_Invasion
            };

            var filterTech = new List <TechLevel>()
            {
                TechLevel.IS
            };

            var filterChassisType = new List <ChassisType>()
            {
                ChassisType.Biped
            };

            var filteredDesigns =
                mechDesigns
                .Where(design => design.Eras.Any(data => filterEras.Contains(data.EraDetail.Era)))
                .Where(design => filterTech.Contains(design.TechLevel))
                .Where(design => filterChassisType.Contains(design.ChassisType))
                .ToList();

            Console.WriteLine(
                $"Filtered designs from [{mechDesigns.Count()}] to [{filteredDesigns.Count()}]. Filtering by available asset bundles...");

            var assetFilteredDesigns = filteredDesigns
                                       .Where(design => unionAssetBundles.Any(s =>
                                                                              s.Contains(design.InnerSphereChassisDesignation.ToLower()) ||
                                                                              (!string.IsNullOrEmpty(design.FilthyClanChassisDesignation) && s.Contains(design.FilthyClanChassisDesignation.ToLower()))))
                                       .ToList();

            Console.WriteLine($"Found [{assetFilteredDesigns.Count}] designs with dedicated asset bundles, filtering by chassis defs...");

            var chassisFilteredDesigns = assetFilteredDesigns
                                         .Where(design => typeDictionary[GameObjectTypeEnum.ChassisDef]
                                                .Where(entry => (entry.Id.ToLower().Contains(design.InnerSphereChassisDesignation.ToLower()) ||
                                                                 (!string.IsNullOrEmpty(design.FilthyClanChassisDesignation) &&
                                                                  entry.Id.ToLower().Contains(design.FilthyClanChassisDesignation.ToLower()))))
                                                .Any(entry =>
            {
                var id    = entry.Id.ToLower();
                var parts = id.ToLower().Split('_');
                if (!string.IsNullOrEmpty(design.VariantDesignation) && !parts.Contains(design.VariantDesignation.ToLower()))
                {
                    return(false);
                }

                // Must contain all hero designations if any exist
                var missingHeroDesignations = design.HeroDesignations.Except(parts);
                if (missingHeroDesignations.Any())
                {
                    return(false);
                }

                return(true);
            }))
                                         .ToList();

            Console.WriteLine($"Found [{chassisFilteredDesigns.Count()}] designs with dedicated chassis defs...");
            var outputDirectory = @"c:\tmp\Beds";

            if (Directory.Exists(outputDirectory))
            {
                Directory.Delete(outputDirectory);
            }

            Directory.CreateDirectory(outputDirectory);
            chassisFilteredDesigns.AsParallel().ForAll(design => File.Copy(design.FileInfo.FullName, Path.Combine(outputDirectory, design.FileInfo.Name)));
        }