Ejemplo n.º 1
0
        /// <summary>
        /// Saves the tag group to the file.
        /// </summary>
        public override void SaveToFile()
        {
            //Check
            if (!File.Exists(FileName))
            {
                //Create
                SaveFileDialog saveDlg = new SaveFileDialog()
                {
                    InitialDirectory = Path.Combine(RegistrySettings.WorkspaceDirectory, "tags"),
                    Filter           = FileFilter,
                    FileName         = FileName
                };
                saveDlg.CustomPlaces.Add(new FileDialogCustomPlace(Path.Combine(RegistrySettings.WorkspaceDirectory, "tags")));

                //Show
                if (saveDlg.ShowDialog() ?? false)
                {
                    FileName = saveDlg.FileName;
                }
                else
                {
                    return;
                }
            }

            //Save
            tagGroupFile.Save(FileName);

            //Remove dirty
            IsDirty = false;
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
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);
            }
        }