Ejemplo n.º 1
0
        public void Run()
        {
            using var map = new FileStream(this.args.FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, 80192, false);

            var sig = H2BaseMap.CalculateSignature(map);

            var sigOffset = BlamSerializer.StartsAt <H2mccMapHeader>(h => h.StoredSignature);

            map.WriteUInt32At(sigOffset, (uint)sig);
            map.Seek(0, SeekOrigin.Begin);

            // Create destination map on disk
            using var outMap = File.OpenWrite(this.args.OutPath);

            H2mccCompression.Compress(map, outMap);
        }
Ejemplo n.º 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!");
        }