示例#1
0
        private void OpenTagReferenceRequested(object sender, TagReferenceEventArgs e)
        {
            //Get file name
            string fileName = Path.Combine(RegistrySettings.WorkspaceDirectory, "tags", e.TagReference);

            try
            {
                //Load
                AbideTagGroupFile tagGroupFile = new AbideTagGroupFile();
                using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    tagGroupFile.Load(stream);

                //Create
                TagFileModel tagGroupFileViewModel = new TagFileModel(fileName, tagGroupFile);
                tagGroupFileViewModel.CloseCallback              = File_Close;
                tagGroupFileViewModel.OpenTagReferenceRequested += OpenTagReferenceRequested;
                Files.Add(tagGroupFileViewModel);

                //Set
                SelectedFile = tagGroupFileViewModel;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to open the specified file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                throw ex;
            }
        }
示例#2
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Create dialog
            using (NewTagGroupDialog groupDialog = new NewTagGroupDialog())
            {
                //Show
                if (groupDialog.ShowDialog() == DialogResult.OK)
                {
                    //Create file
                    AbideTagGroupFile file = new AbideTagGroupFile()
                    {
                        TagGroup = groupDialog.SelectedGroup
                    };

                    //Get name
                    string tagName = "tag"; int tagIndex = 1;
                    while (openEditors.ContainsKey($"{tagName}{tagIndex}"))
                    {
                        tagIndex++;
                    }

                    //Create editor
                    TagGroupFileEditor editor = new TagGroupFileEditor($"{tagName}{tagIndex}.{file.TagGroup.GroupName}", file)
                    {
                        MdiParent = this
                    };
                    editor.FileNameChanged += Editor_FileNameChanged;
                    editor.FormClosed      += Editor_FormClosed;

                    //Show
                    editor.Show();
                }
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            var tagReferences = new List <string>();
            var file          = new AbideTagGroupFile();

            file.Load(args[0]);

            DiscoverReferences(tagReferences, file.TagGroup);
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TagGroupFileEditor"/> class using the specified file name and tag group file.
        /// </summary>
        /// <param name="fileName">The path of the tag group file.</param>
        /// <param name="tagGroupFile">The tag group file.</param>
        public TagGroupFileEditor(string fileName, AbideTagGroupFile tagGroupFile) : this()
        {
            //Setup
            TagGroupFile = tagGroupFile ?? throw new ArgumentNullException(nameof(tagGroupFile));
            m_FileName   = fileName ?? throw new ArgumentNullException(nameof(fileName));

            //Set
            Text = fileName;
        }
示例#5
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Prepare
            AbideTagGroupFile file = null;

            //Initialize
            using (OpenFileDialog openDlg = new OpenFileDialog())
            {
                //Setup
                openDlg.Filter = "All files (*.*)|*.*";
                openDlg.CustomPlaces.Add(new FileDialogCustomPlace(RegistrySettings.WorkspaceDirectory));

                //Show
                if (openDlg.ShowDialog() == DialogResult.OK)
                {
                    //Check
                    if (openEditors.ContainsKey(openDlg.FileName))
                    {
                        openEditors[openDlg.FileName].Show();
                    }
#if DEBUG
                    //Load file
                    file = new AbideTagGroupFile();
                    file.Load(openDlg.FileName);
#else
                    try
                    {
                        using (Stream stream = openDlg.OpenFile())
                        {
                            //Load file
                            file = new AbideTagGroupFile();
                            file.Load(stream);
                        }
                    }
                    catch { file = null; MessageBox.Show($"An error occured while opening {openDlg.FileName}.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
#endif

                    //Check
                    if (file != null)
                    {
                        //Create editor
                        TagGroupFileEditor editor = new TagGroupFileEditor(openDlg.FileName, file)
                        {
                            MdiParent = this
                        };
                        editor.FileNameChanged += Editor_FileNameChanged;
                        editor.FormClosed      += Editor_FormClosed;

                        //Show
                        editor.Show();
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TagFileModel"/> class using the specified file name and tag group.
        /// </summary>
        /// <param name="fileName">The name of the file.</param>
        /// <param name="groupTag">The tag group.</param>
        public TagFileModel(string fileName, AbideTagGroupFile tagGroupFile = null) : base(fileName)
        {
            //Setup
            this.tagGroupFile = tagGroupFile;

            //Loop
            foreach (ITagBlock tagBlock in tagGroupFile.TagGroup)
            {
                TagBlocks.Add(new TagBlockModel()
                {
                    Owner = this, TagBlock = tagBlock
                });
            }
        }
示例#7
0
        private void OpenFile()
        {
            //Prepare
            string tagsDirectory = Path.Combine(RegistrySettings.WorkspaceDirectory, "tags");

            //Create
            OpenFileDialog openDlg = new OpenFileDialog
            {
                InitialDirectory = tagsDirectory,
                Filter           = "All Files (*.*)|*.*"
            };

            //Add custom place
            openDlg.CustomPlaces.Add(new FileDialogCustomPlace(tagsDirectory));

            //Show
            if (openDlg.ShowDialog() ?? false)
            {
                if (!Files.Any(f => f.FileName == openDlg.FileName))
                {
                    try
                    {
                        //Load
                        AbideTagGroupFile tagGroupFile = new AbideTagGroupFile();
                        using (var stream = openDlg.OpenFile())
                            tagGroupFile.Load(stream);

                        //Create
                        TagFileModel tagGroupFileViewModel = new TagFileModel(openDlg.FileName, tagGroupFile);
                        tagGroupFileViewModel.CloseCallback              = File_Close;
                        tagGroupFileViewModel.OpenTagReferenceRequested += OpenTagReferenceRequested;
                        Files.Add(tagGroupFileViewModel);

                        //Set
                        SelectedFile = tagGroupFileViewModel;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Unable to open the specified file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        throw ex;
                    }
                }
            }
        }
示例#8
0
        private static void DiscoverReferences(List <string> tagReferences, Block tagBlock)
        {
            foreach (var field in tagBlock)
            {
                switch (field)
                {
                case TagReferenceField tagReferenceField:
                    var tagString = tagReferenceField.String;
                    if (!string.IsNullOrEmpty(tagString))
                    {
                        if (!tagReferences.Contains(tagString))
                        {
                            string fileName = Path.Combine(TagsDirectory, tagString);
                            if (File.Exists(fileName))
                            {
                                tagReferences.Add(tagString);
                                var file = new AbideTagGroupFile();
                                file.Load(fileName);
                                DiscoverReferences(tagReferences, file.TagGroup);
                            }
                        }
                    }
                    break;

                case BlockField blockField:
                    foreach (var block in blockField.BlockList)
                    {
                        DiscoverReferences(tagReferences, block);
                    }
                    break;

                case StructField structField:
                    DiscoverReferences(tagReferences, structField.Block);
                    break;
                }
            }
        }
示例#9
0
        private void decompileButton_Click(object sender, EventArgs e)
        {
            //Loop
            foreach (TagId id in checkedTagIds)
            {
                //Get index entry
                IndexEntry entry = mapFile.IndexEntries[id];

                //Check
                if (entry != null)
                {
                    //Read
                    Group tagGroup = TagLookup.CreateTagGroup(entry.Root);
                    using (var stream = entry.Data.GetVirtualStream())
                        using (var reader = stream.CreateReader())
                        {
                            reader.BaseStream.Seek(entry.Address, SeekOrigin.Begin);
                            tagGroup.Read(reader);
                        }

                    //Collect references
                    AbideTagGroupFile tagGroupFile = new AbideTagGroupFile()
                    {
                        TagGroup = Convert.ToGuerilla(tagGroup, soundCacheFileGestalt, entry, mapFile)
                    };
                    resourceManager.CollectResources(tagGroupFile.TagGroup);

                    //Get file name
                    string fileName = Path.Combine(RegistrySettings.WorkspaceDirectory, "tags", $"{entry.Filename}.{tagGroup.GroupName}");

                    //Create directory?
                    if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                    }

                    //Save tag file
                    tagGroupFile.Save(fileName);
                }
            }

            //Decompile resources
            foreach (string resourceString in resourceManager.GetResources())
            {
                //Find entry
                IndexEntry entry = mapFile.IndexEntries[cacheResources.FindIndex(resourceString)];

                //Check
                if (entry != null)
                {
                    //Read
                    Group tagGroup = TagLookup.CreateTagGroup(entry.Root);
                    using (var stream = entry.Data.GetVirtualStream())
                        using (var reader = stream.CreateReader())
                        {
                            reader.BaseStream.Seek(entry.Address, SeekOrigin.Begin);
                            tagGroup.Read(reader);
                        }

                    //Collect references
                    AbideTagGroupFile tagGroupFile = new AbideTagGroupFile()
                    {
                        TagGroup = Convert.ToGuerilla(tagGroup, soundCacheFileGestalt, entry, mapFile)
                    };

                    //Get file name
                    string fileName = Path.Combine(RegistrySettings.WorkspaceDirectory, "tags", $"{entry.Filename}.{tagGroup.GroupName}");

                    //Create directory?
                    if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                    }

                    //Save tag file
                    tagGroupFile.Save(fileName);
                }
            }
        }
示例#10
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"));
                }
            }
        }
示例#11
0
        private void IndexEntry_Export(TagManifest manifest, IndexEntry entry, ITagGroup soundCacheFileGestalt, string outputDirectory)
        {
            //Check
            if (entry == null || manifest == null || outputDirectory == null)
            {
                return;
            }
            if (manifest.TagIdReferences.Contains(entry.Id.Dword))
            {
                return;
            }

            //Prepare
            AbideTagGroupFile tagGroupFile = new AbideTagGroupFile()
            {
                Id = entry.Id
            };
            Group  tagGroup     = TagLookup.CreateTagGroup(entry.Root);
            string localPath    = $"{entry.Filename}.{tagGroup.GroupName}";
            string absolutePath = Path.Combine(outputDirectory, localPath);

            //Check
            using (BinaryReader reader = entry.TagData.CreateReader())
            {
                //Add reference
                manifest.TagIdReferences.Add(entry.Id.Dword);

                //Read
                entry.TagData.Seek((uint)entry.PostProcessedOffset, SeekOrigin.Begin);
                tagGroup.Read(reader);

                //Get references
                foreach (ITagBlock tagBlock in tagGroup)
                {
                    TagBock_BuildReferences(manifest, tagBlock, outputDirectory);
                }

                //Add file
                manifest.TagFileNames.Add(localPath);

                //Add raws
                foreach (RawSection section in Enum.GetValues(typeof(RawSection)))
                {
                    foreach (RawStream raw in entry.Raws[section])
                    {
                        tagGroupFile.SetRaw(raw.RawOffset, raw.ToArray());
                    }
                }

                //Convert cache to guerilla
                tagGroup = Guerilla.Library.Convert.ToGuerilla(tagGroup, soundCacheFileGestalt, entry, Map);

                //Copy raws
                if (tagGroup.GroupTag == HaloTags.snd_)
                {
                    int        rawOffset = 0;
                    IndexEntry soundCacheFileGestaltEntry = Map.GetSoundCacheFileGestaltEntry();
                    Block      soundBlock = tagGroup.TagBlocks[0];
                    foreach (Block pitchRangeBlock in ((BlockField)soundBlock.Fields[13]).BlockList)
                    {
                        foreach (Block permutationBlock in ((BlockField)pitchRangeBlock.Fields[7]).BlockList)
                        {
                            foreach (Block permutationChunkBlock in ((BlockField)permutationBlock.Fields[6]).BlockList)
                            {
                                rawOffset = (int)permutationChunkBlock.Fields[0].Value;
                                if (soundCacheFileGestaltEntry.Raws[RawSection.Sound].ContainsRawOffset(rawOffset))
                                {
                                    tagGroupFile.SetRaw(rawOffset, soundCacheFileGestaltEntry.Raws[RawSection.Sound][rawOffset].ToArray());
                                }
                            }
                        }
                    }
                    foreach (Block extraInfoBlock in ((BlockField)soundBlock.Fields[15]).BlockList)
                    {
                        ITagBlock globalGeometryBlockInfoStruct = (ITagBlock)extraInfoBlock.Fields[2].Value;
                        if (soundCacheFileGestaltEntry.Raws[RawSection.LipSync].ContainsRawOffset(rawOffset))
                        {
                            tagGroupFile.SetRaw(rawOffset, soundCacheFileGestaltEntry.Raws[RawSection.LipSync][rawOffset].ToArray());
                        }
                    }
                }

                //Create
                Directory.CreateDirectory(Path.GetDirectoryName(absolutePath));

                //Set tag group
                tagGroupFile.TagGroup = tagGroup;

                //Create file
                using (FileStream fs = new FileStream(absolutePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
                    tagGroupFile.Save(fs);
            }
        }