Exemplo n.º 1
0
 public DownloadVM(
     NavigationService navigation,
     ManifestService manifest)
 {
     _navigation = navigation ?? throw new ArgumentNullException(nameof(navigation));
     _manifest   = manifest ?? throw new ArgumentNullException(nameof(manifest));
 }
Exemplo n.º 2
0
 public InstallVM(
     NavigationService navigation,
     ManifestService manifest)
 {
     _navigation = navigation ?? throw new ArgumentNullException(nameof(navigation));
     _manifest   = manifest ?? throw new ArgumentNullException(nameof(manifest));
     ScheduleVerify();
 }
Exemplo n.º 3
0
 public VerifyVM(
     NavigationService navigation,
     ManifestService manifest,
     RegistryService registry)
 {
     _navigation = navigation ?? throw new ArgumentNullException(nameof(navigation));
     _manifest   = manifest ?? throw new ArgumentNullException(nameof(manifest));
     _registry   = registry ?? throw new ArgumentNullException(nameof(registry));
 }
        protected string CreateVisualElementsManifest()
        {
            string fullPath = GetManifestPath();

            if (File.Exists(fullPath))
            {
                var xml = File.ReadAllText(fullPath);
                if (ManifestService.Validate(xml))
                {
                    var manifest = ManifestService.Parse(xml);
                    xml = ManifestService.Create(manifest);
                    if (!File.Exists(Path.Combine(LaunchScriptFolder, manifest.GetSetSquare150x150Logo())))
                    {
                        manifest.SetSquare150x150LogoOn(Path.Combine(Constants.ICONFOLDERNAME, TargetObject.Id + ".png"));
                    }
                    if (!File.Exists(Path.Combine(LaunchScriptFolder, manifest.GetSetSquare70x70Logo())))
                    {
                        manifest.SetSquare70x70LogoOn(Path.Combine(Constants.ICONFOLDERNAME, TargetObject.Id + "_70.png"));
                    }
                    var newXml = ManifestService.Create(manifest);
                    if (newXml != xml)
                    {
                        File.WriteAllText(fullPath, newXml);
                    }
                    return(fullPath);
                }
            }

            string foregroundTextStyle = "light";
            string backgroundColorCode = "#000000";

            (var bgColor, var brightness) = CreateTileImage();
            foregroundTextStyle           = brightness > 0.4f ? "dark" : "light";
            backgroundColorCode           = bgColor.ToHexCode();
            string script =
                "<Application xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
                "<VisualElements\n" +
                $"BackgroundColor = \"{backgroundColorCode}\"\n" +
                "ShowNameOnSquare150x150Logo = \"on\"\n" +
                $"ForegroundText = \"{foregroundTextStyle}\"\n" +
                $"Square150x150Logo = \"{Constants.ICONFOLDERNAME}\\{TargetObject.Id}.png\"\n" +
                $"Square70x70Logo = \"{Constants.ICONFOLDERNAME}\\{TargetObject.Id}_70.png\"/>\n" +
                "</Application>";

            try
            {
                using (var scriptFile = new StreamWriter(fullPath, false))
                {
                    scriptFile.Write(script);
                }
                return(fullPath);
            }
            catch (Exception) { }

            return(string.Empty);
        }
Exemplo n.º 5
0
 public PlayVM(
     NavigationService navigation,
     ManifestService manifest,
     RegistryService registry,
     SettingsService settings)
 {
     _navigation = navigation ?? throw new ArgumentNullException(nameof(navigation));
     _manifest   = manifest ?? throw new ArgumentNullException(nameof(manifest));
     _registry   = registry ?? throw new ArgumentNullException(nameof(registry));
     _settings   = settings ?? throw new ArgumentNullException(nameof(settings));
 }
    private IEnumerator setContentSystem()
    {
        ManifestService manifestService             = new ManifestService();
        bool            contentComplete             = false;
        InitializeManifestDefinitionCommand command = new InitializeManifestDefinitionCommand(manifestService, delegate(ContentManifest manifest, ScenePrereqContentBundlesManifest scenePrereqBundlesManifest, bool requiresAppUpgrade, bool appUpgradeAvailable)
        {
            Service.Set(new Content(manifest));
            contentComplete = true;
        });

        command.Execute();
        while (!contentComplete)
        {
            yield return(null);
        }
    }
Exemplo n.º 7
0
        private static IDictionary <Type, object> InitializeDefaultServiceMap()
        {
            var configurationService  = new ConfigurationService();
            var commandService        = new CommandService();
            var fileService           = new FileService();
            var testCollectionService = new TestCollectionService(configurationService, fileService, commandService);
            var manifestService       = new ManifestService(configurationService, fileService);
            var testService           = new TestService();

            return(new Dictionary <Type, object>
            {
                { typeof(IConfigurationService), configurationService },
                { typeof(ICommandService), commandService },
                { typeof(IFileService), fileService },
                { typeof(ITestCollectionService), testCollectionService },
                { typeof(IManifestService), manifestService },
                { typeof(ITestService), testService }
            });
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
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)));
        }
        protected (Color bgColor, float brightness) CreateTileImage()
        {
            string iconPath   = GetGameIconPath();
            Color  bgColor    = Color.DarkGray;
            float  brightness = 0.5f;

            if (System.IO.File.Exists(iconPath))
            {
                Bitmap bitmap = null;
                if (Path.GetExtension(iconPath).ToLower() == ".ico")
                {
                    bitmap = ExtractBitmapFromIcon(iconPath, 150, 150);
                }
                if (bitmap == null)
                {
                    bitmap = new Bitmap(iconPath);
                }
                if (bitmap != null && bitmap.Width > 0 && bitmap.Height > 0)
                {
                    brightness = GetAverageBrightness(bitmap);

                    bgColor = GetDominantColor(bitmap, brightness);

                    // resize 70x70
                    int newWidth  = 70;
                    int newHeight = 70;
                    if (bitmap.Width <= bitmap.Height)
                    {
                        float scale = (float)newHeight / bitmap.Height;
                        newWidth = (int)Math.Round(bitmap.Width * scale);
                    }
                    else
                    {
                        float scale = (float)newWidth / bitmap.Width;
                        newHeight = (int)Math.Round(bitmap.Height * scale);
                    }
                    Bitmap resized = new Bitmap(newWidth, newHeight);
                    using (Graphics graphics = Graphics.FromImage(resized))
                    {
                        graphics.RenderingOrigin   = new Point(34, 34);
                        graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                        if (bitmap.Width <= 16 && bitmap.Height <= 16)
                        {
                            graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                            graphics.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.Half;
                            graphics.CompositingMode   = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                            graphics.DrawImage(bitmap, new RectangleF(0, 0, 70, 70), new RectangleF(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel);
                        }
                        else
                        {
                            graphics.DrawImage(bitmap, new Rectangle(0, 0, newWidth, newHeight));
                        }
                    }
                    resized.Save(GetTileSmallIconPath(), ImageFormat.Png);
                    resized.Dispose();

                    // resize 150x150
                    newWidth  = 150;
                    newHeight = 150;
                    if (bitmap.Width <= bitmap.Height)
                    {
                        float scale = (float)newHeight / bitmap.Height;
                        newWidth = (int)Math.Round(bitmap.Width * scale);
                    }
                    else
                    {
                        float scale = (float)newWidth / bitmap.Width;
                        newHeight = (int)Math.Round(bitmap.Height * scale);
                    }
                    resized = new Bitmap(newWidth, newHeight);
                    using (Graphics graphics = Graphics.FromImage(resized))
                    {
                        graphics.RenderingOrigin = new Point(74, 74);
                        if (bitmap.Width <= 64 && bitmap.Height <= 64)
                        {
                            graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                            graphics.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.Half;
                            graphics.CompositingMode   = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                            graphics.DrawImage(bitmap, new RectangleF(0, 0, 150, 150), new RectangleF(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel);
                        }
                        else
                        {
                            graphics.DrawImage(bitmap, new Rectangle(0, 0, newWidth, newHeight));
                        }
                    }
                    var tileIconPath   = GetTileIconPath();
                    var showTextOnTile = true;
                    if (File.Exists(GetManifestPath()))
                    {
                        var manifest = ManifestService.Parse(File.ReadAllText(GetManifestPath()));
                        showTextOnTile = manifest.IsShowNameOnSquare150x150LogoSetOnOn();
                    }
                    if (FadeTileEdge && showTextOnTile)
                    {
                        float percentage = 0.28f;
                        if (TargetObject.Name.Length >= 12 && TargetObject.Name.Split(null).Length > 1)
                        {
                            percentage = 0.42f;
                        }
                        BlendEdge(resized, Edge.Top, percentage, 2.8f, 0.5f);
                    }
                    resized.Save(tileIconPath, ImageFormat.Png);
                    brightness = GetLowerThirdBrightness(resized, bgColor);
                    resized.Dispose();
                }
                bitmap.Dispose();
            }
            return(bgColor, brightness);
        }