Beispiel #1
0
        public async Task Run()
        {
            using var inmemMap = new MemoryStream();
            using (var map = File.Open(this.Args.MapPath, FileMode.Open))
            {
                H2mccCompression.Decompress(map, inmemMap);
                inmemMap.Position = 0;

                // Load to determine where to write patches to
                var factory = new MapFactory(this.Args.MapPath);
                this.scene = factory.LoadSingleH2mccMap(inmemMap);
            }

            var tagPatcher = new TagPatcher(scene, inmemMap);
            var settings   = new JsonSerializerOptions()
            {
                ReadCommentHandling = JsonCommentHandling.Skip
            };
            var patches = JsonSerializer.Deserialize <TagPatch[]>(File.ReadAllText(this.Args.TagPatchPath), settings);

            foreach (var patch in patches)
            {
                tagPatcher.Apply(patch);
            }

            inmemMap.Position = 0;
            var sig = H2BaseMap.CalculateSignature(inmemMap);

            inmemMap.WriteInt32At(BlamSerializer.StartsAt <H2vMapHeader>(h => h.StoredSignature), sig);
            inmemMap.Position = 0;

            using (var map = File.Open(this.Args.MapPath, FileMode.Open))
            {
                inmemMap.CopyTo(map);
            }
        }
Beispiel #2
0
        public static void Run(BulkPatchTaskArgs args)
        {
            if (args.RawMapsDirectory == null)
            {
                // TODO: better
                args.RawMapsDirectory = @"C:\Program Files\ModifiableWindowsApps\HaloMCC\halo2\h2_maps_win64_dx11";
            }

            if (Directory.Exists(args.RawMapsDirectory) == false)
            {
                Console.WriteLine("Please enter the path to your 'clean' maps");
                Console.Write(">");

                args.RawMapsDirectory = Console.ReadLine().Trim();
            }

            var patches = FindDirectory(args.PatchesDirectory);
            var maps    = FindDirectory(args.RawMapsDirectory);

            Directory.CreateDirectory(args.PatchedMapsDirectory);

            var folderFilter = GetRegexForFilter(args.PatchFilter);

            var patchDirs = Directory.GetDirectories(patches)
                            .Where(d => folderFilter.IsMatch(Path.GetFileName(d)))
                            .ToArray();

            Parallel.ForEach(patchDirs, patchDir =>
            {
                var mapName        = Path.GetFileName(patchDir);
                var rawMapPath     = Path.Combine(maps, mapName + ".map");
                var patchedMapPath = Path.Combine(args.PatchedMapsDirectory, mapName + ".map");

                if (File.Exists(rawMapPath) == false)
                {
                    Console.WriteLine($"Patch dir for '{mapName}', but no map found at '{rawMapPath}'");
                    return;
                }

                var rawMap     = File.OpenRead(rawMapPath);
                var patchedMap = new MemoryStream();

                H2mccCompression.Decompress(rawMap, patchedMap);

                var factory = new MapFactory(Path.GetDirectoryName(rawMapPath));
                var scene   = factory.LoadSingleH2mccMap(patchedMap);

                var tagPatches = Directory.GetFiles(patchDir, "*.tagpatch", SearchOption.AllDirectories);

                var tagPatcher = new TagPatcher(scene, patchedMap);

                foreach (var tagPatchPath in tagPatches)
                {
                    Console.WriteLine($"TagPatching '{scene.Header.Name}' with '{tagPatchPath.Substring(patchDir.Length)}'");

                    var settings = new JsonSerializerOptions()
                    {
                        ReadCommentHandling = JsonCommentHandling.Skip
                    };
                    var patches = JsonSerializer.Deserialize <TagPatch[]>(File.ReadAllText(tagPatchPath), settings);
                    foreach (var patch in patches)
                    {
                        tagPatcher.Apply(patch);
                    }
                }

                var scriptPatchFiles = Directory.GetFiles(patchDir, "*.tree", SearchOption.AllDirectories);

                foreach (var patchFile in scriptPatchFiles)
                {
                    Console.WriteLine($"Patching '{scene.Header.Name}' with '{patchFile.Substring(patchDir.Length)}'");
                    ScriptTreePatcher.PatchMap(scene, patchedMap, patchFile);
                }


                var sig = H2BaseMap.CalculateSignature(patchedMap);
                patchedMap.WriteUInt32At(BlamSerializer.StartsAt <H2mccMapHeader>(h => h.StoredSignature), (uint)sig);

                using var patchedFile = new FileStream(patchedMapPath, FileMode.Create);
                H2mccCompression.Compress(patchedMap, patchedFile);
            });

            Console.WriteLine("Done!");
        }