Beispiel #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            //Prepare
            string mapJson = null;

            //Open
            using (HaloMap map = new HaloMap(@"F:\XBox\Original\Games\Halo 2\Clean Maps\lockout.map"))
            {
                //Create serializer
                JsonSerializer serializer = new JsonSerializer();
                mapJson = serializer.Serialize(map).Stringify();

                //Save json
                using (StreamWriter writer = File.CreateText($@"F:\{map.Name}.json"))
                    writer.Write(mapJson);

                //Save
                map.Save($@"F:\{map.Name}.map");
            }
        }
Beispiel #2
0
        private void Click(object obj)
        {
            List <string>       strings = new List <string>();
            List <TagReference> tags    = new List <TagReference>();
            List <IndexEntry>   entries = new List <IndexEntry>();
            TagId currentId             = TagId.Null;

            var openDlg = new OpenFileDialog()
            {
                Filter = "XML Files (*.xml)|*.xml"
            };

            if (openDlg.ShowDialog() ?? false)
            {
                XmlDocument document = new XmlDocument();
                document.Load(openDlg.FileName);

                var tagsRoot        = Path.GetDirectoryName(openDlg.FileName);
                var manifest        = document["AbideTagManifest"];
                var tagNameManifest = manifest["TagNames"];

                foreach (XmlNode node in tagNameManifest)
                {
                    var tagName  = node.Attributes["Name"].InnerText;
                    var groupTag = new TagFourCc(node.Attributes["GroupTag"].InnerText);
                    tags.Add(new TagReference()
                    {
                        TagName  = tagName,
                        GroupTag = groupTag
                    });
                }

                var globals = Map.GetTagById(Map.GlobalsTagId);
                using (var tagData = Map.ReadTagData(globals))
                {
                    _ = tagData.Stream.Seek(globals.MemoryAddress, SeekOrigin.Begin);
                    var globalsTagGroup = TagLookup.CreateTagGroup(globals.Tag);
                    globalsTagGroup.Read(tagData.Stream.CreateReader());

                    var soundGlobals = (BlockField)globalsTagGroup.TagBlocks[0].Fields[4];
                    if (soundGlobals.BlockList.Count == 1)
                    {
                        var soundGlobalsBlock = soundGlobals.BlockList[0];
                        currentId = (TagId)soundGlobalsBlock.Fields[4].Value;
                    }
                }

                using (var map = new HaloMap(Map.FileName))
                {
                    var soundCacheFileGestaltEntry = map.IndexEntries[currentId];

                    foreach (var tag in tags)
                    {
                        if (map.IndexEntries.Any(e => e.Filename == tag.TagName && e.Root == tag.GroupTag))
                        {
                            tag.Id = map.IndexEntries.First(e => e.Filename == tag.TagName && e.Root == tag.GroupTag).Id;
                        }
                        else
                        {
                            var tagGroup = TagLookup.CreateTagGroup(tag.GroupTag);
                            tag.FileName = Path.Combine(tagsRoot, $"{tag.TagName}.{tagGroup.Name}");

                            var tagGroupFile = new AbideTagGroupFile();
                            tagGroupFile.Load(tag.FileName);

                            var entry = new IndexEntry()
                            {
                                Filename = tag.TagName,
                                Id       = currentId++,
                                Tag      = map.Tags.First(t => t.Root == tag.GroupTag),
                            };

                            entries.Add(entry);
                            tag.TagGroup = tagGroupFile.TagGroup;
                            tag.Id       = entry.Id;

                            foreach (var offset in tagGroupFile.GetResourceAddresses())
                            {
                                var resource = tagGroupFile.GetResource(offset);
                                _ = entry.Resources.AddResource((int)offset, resource);
                            }
                        }
                    }

                    soundCacheFileGestaltEntry.Id = currentId;

                    int insertionIndex = map.IndexEntries.IndexOf(e => e == soundCacheFileGestaltEntry);
                    foreach (var tag in tags.Where(t => File.Exists(t.FileName)))
                    {
                        ConvertToCache(tag.TagGroup, map, tags);
                        var entry = entries.First(e => e.Id == tag.Id);

                        using (var stream = new MemoryStream())
                            using (var writer = new BinaryWriter(stream))
                            {
                                tag.TagGroup.Write(writer);
                                entry.Data.SetBuffer(stream.ToArray());
                                _ = map.IndexEntries.Insert(insertionIndex, entry);
                            }
                    }

                    map.Save(Path.Combine(tagsRoot, $"{map.Name}.map"));
                }
            }
        }