コード例 #1
0
        public async Task Run()
        {
            var path = this.Args.File;

            if (File.Exists(path) == false)
            {
                path = Path.Combine(Environment.CurrentDirectory, path);
            }

            if (File.Exists(path) == false)
            {
                Console.WriteLine("Couldn't find file for " + this.Args.File);
                return;
            }

            var mem = new MemoryStream();

            File.OpenRead(path).CopyTo(mem);
            mem.Seek(0, SeekOrigin.Begin);
            var sig = H2BaseMap.CalculateSignature(mem);

            var factory = new MapFactory(Path.GetDirectoryName(this.Args.File));
            var h2map   = factory.Load(Path.GetFileName(this.Args.File));

            if (h2map is not H2mccMap mccMap)
            {
                throw new NotSupportedException("Only MCC maps are supported in this tool");
            }

            Console.WriteLine("Loaded map");
        }
コード例 #2
0
ファイル: PackTask.cs プロジェクト: ronbrogan/OpenH2
        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);
        }
コード例 #3
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);
            }
        }
コード例 #4
0
ファイル: BulkPatchTask.cs プロジェクト: ronbrogan/OpenH2
        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!");
        }