Ejemplo n.º 1
0
        public void LoadSoundTag(CacheBase Cache, CacheBase.IndexItem Tag)
        {
            if (Cache.Version != DefinitionSet.Halo4Retail)
            {
                throw new Exception("This is for H4 ONLY");
            }

            cache = (CacheH4R)Cache;
            tag   = Tag;

            snd = (SoundH4R)DefinitionsManager.snd_(cache, tag);

            LoadCacheSoundPacks(cache);

            lstPerms.Items.Clear();
            _perms.Clear();
            _soundbanks.Clear();

            ObjectLoadWorker();

            if (lstPerms.Items.Count > 0)
            {
                Enabled = true;
                lstPerms.SelectedIndex = 0;
                label1.Text            = _perms[0].Format.ToString();
            }
            else
            {
                label1.Text = "";
                Enabled     = false;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Save all permutations of a sound tag as separate sound files.
        /// </summary>
        /// <param name="Folder">The base filename. Permutation names will be appended accordingly.</param>
        /// <param name="Cache">The CacheFile containing the tag.</param>
        /// <param name="Tag">The sound tag.</param>
        /// <param name="Format">The format in which to save the data.</param>
        public static void SaveAllAsSeparate(string Folder, CacheBase Cache, CacheBase.IndexItem Tag, SoundFormat Format, bool Overwrite)
        {
            var snd_ = DefinitionsManager.snd_(Cache, Tag);
            var ugh_ = Cache.ugh_;

            var indices = new List <int>();

            for (int i = 0; i < ugh_.PlayBacks[snd_.PlaybackIndex].PermutationCount; i++)
            {
                indices.Add(i);
            }

            SaveSelected(Folder, Cache, Tag, Format, indices, Overwrite);
        }
Ejemplo n.º 3
0
        public void LoadSoundTag(CacheBase Cache, CacheBase.IndexItem Tag)
        {
            cache = Cache;
            tag   = Tag;

            snd = DefinitionsManager.snd_(cache, tag);

            if (cache.ugh_ == null)
            {
                lstPerms.Items.Clear();
                Enabled = false;
                return;
            }
            else
            {
                Enabled = true;
            }

            ugh      = cache.ugh_;
            playback = ugh.PlayBacks[snd.PlaybackIndex];

            Perms = new List <ugh_.SoundPermutation>();

            for (int i = 0; i < playback.PermutationCount; i++)
            {
                Perms.Add(ugh.SoundPermutations[playback.FirstPermutation + i]);
            }

            lstPerms.Items.Clear();

            foreach (var perm in Perms)
            {
                lstPerms.Items.Add(ugh.SoundNames[perm.NameIndex]);
            }

            lstPerms.SelectedIndex = 0;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves all permutations of a sound tag concatenated as a single sound file.
        /// </summary>
        /// <param name="Filename">The file to save the data to.</param>
        /// <param name="Cache">The CacheFile containing the tag.</param>
        /// <param name="Tag">The sound tag.</param>
        /// <param name="Format">The format in which to save the data.</param>
        public static void SaveAllAsSingle(string Filename, CacheBase Cache, CacheBase.IndexItem Tag, SoundFormat Format)
        {
            var snd_ = DefinitionsManager.snd_(Cache, Tag);

            #region XMA
            if (Format == SoundFormat.XMA)
            {
                var total = GetTotalSize(Cache.ugh_, Cache.ugh_.PlayBacks[snd_.PlaybackIndex]);

                byte[] buffer = Cache.GetSoundRaw(snd_.RawID, total);

                if (buffer.Length == 0)
                {
                    throw new Exception("Empty raw data.");
                }
                var codec = Cache.ugh_.Codecs[snd_.CodecIndex];
                var xma   = GetXMA(buffer, snd_.SampleRate, codec.Type);

                if (!Directory.GetParent(Filename).Exists)
                {
                    Directory.GetParent(Filename).Create();
                }

                var          fs = File.OpenWrite(Filename);
                EndianWriter sw = new EndianWriter(fs, EndianFormat.BigEndian);
                sw.Write(xma);

                sw.Close();
                sw.Dispose();
            }
            #endregion
            #region WAV
            else if (Format == SoundFormat.WAV)
            {
                var tempName = Path.GetTempFileName();

                SaveAllAsSingle(tempName, Cache, Tag, SoundFormat.XMA);

                var info = new ProcessStartInfo(towav, tempName)
                {
                    CreateNoWindow   = true,
                    UseShellExecute  = false,
                    WorkingDirectory = Directory.GetParent(tempName).FullName
                };

                Process.Start(info).WaitForExit();

                if (File.Exists(Filename))
                {
                    File.Delete(Filename);
                }
                if (!Directory.GetParent(Filename).Exists)
                {
                    Directory.GetParent(Filename).Create();
                }
                File.Move(Path.ChangeExtension(tempName, "wav"), Filename);
                if (File.Exists(tempName))
                {
                    File.Delete(tempName);
                }
            }
            #endregion
            #region RAW
            else if (Format == SoundFormat.RAW)
            {
                byte[] buffer = Cache.GetSoundRaw(snd_.RawID, GetTotalSize(Cache.ugh_, Cache.ugh_.PlayBacks[snd_.PlaybackIndex]));

                if (!Directory.GetParent(Filename).Exists)
                {
                    Directory.GetParent(Filename).Create();
                }

                var          fs = new FileStream(Filename, FileMode.Create);
                BinaryWriter sw = new BinaryWriter(fs);

                sw.Write(buffer);
                sw.Close();
                sw.Dispose();
            }
            #endregion
            #region Other
            else
            {
                throw new InvalidOperationException("Invalid sound format received.");
            }
            #endregion
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Saves selected permutations of a sound tag.
        /// </summary>
        /// <param name="Folder">The folder to save all files in. Each file will be named as the permutation name.</param>
        /// <param name="Cache">The CacheFile containing the tag.</param>
        /// <param name="Tag">The sound tag.</param>
        /// <param name="Format">The format in which to save the data.</param>
        /// <param name="Indices">The indices of the permutations to extract.</param>
        public static void SaveSelected(string Folder, CacheBase Cache, CacheBase.IndexItem Tag, SoundFormat Format, List <int> Indices, bool Overwrite)
        {
            var           snd_  = DefinitionsManager.snd_(Cache, Tag);
            List <byte[]> perms = new List <byte[]>();

            var ugh_     = Cache.ugh_;
            var playback = ugh_.PlayBacks[snd_.PlaybackIndex];
            var data     = Cache.GetSoundRaw(snd_.RawID, GetTotalSize(ugh_, playback));

            if (playback.PermutationCount == 1)
            {
                perms.Add(data);
            }
            else
            {
                Folder = Directory.GetParent(Folder) + "\\" + Path.GetFileNameWithoutExtension(Folder);

                for (int i = 0; i < playback.PermutationCount; i++)
                {
                    var perm = Cache.ugh_.SoundPermutations[playback.FirstPermutation + i];
                    perms.Add(GetPermData(data, ugh_, perm));
                }
            }

            #region XMA
            if (Format == SoundFormat.XMA)
            {
                foreach (int index in Indices)
                {
                    string Filename = (playback.PermutationCount == 1) ? Folder : Folder + "\\" + ugh_.SoundNames[ugh_.SoundPermutations[playback.FirstPermutation + index].NameIndex].Name + ".xma";
                    if (!Filename.EndsWith(".xma"))
                    {
                        Filename += ".xma";
                    }

                    if (File.Exists(Filename) && !Overwrite)
                    {
                        continue;
                    }

                    byte[] buffer = perms[index];
                    var    codec  = Cache.ugh_.Codecs[snd_.CodecIndex];
                    var    xma    = GetXMA(buffer, snd_.SampleRate, codec.Type);

                    if (!Directory.GetParent(Filename).Exists)
                    {
                        Directory.GetParent(Filename).Create();
                    }

                    var          fs = new FileStream(Filename, FileMode.Create);
                    EndianWriter sw = new EndianWriter(fs, EndianFormat.BigEndian);
                    sw.Write(xma);

                    sw.Close();
                    sw.Dispose();
                }
            }
            #endregion
            #region WAV
            else if (Format == SoundFormat.WAV)
            {
                foreach (int index in Indices)
                {
                    string Filename = (playback.PermutationCount == 1) ? Folder : Folder + "\\" + ugh_.SoundNames[ugh_.SoundPermutations[playback.FirstPermutation + index].NameIndex].Name + ".wav";
                    if (!Filename.EndsWith(".wav"))
                    {
                        Filename += ".wav";
                    }

                    if (File.Exists(Filename) && !Overwrite)
                    {
                        continue;
                    }

                    var tempName = Path.GetTempFileName();

                    #region Write XMA
                    var buffer = perms[index];
                    var codec  = Cache.ugh_.Codecs[snd_.CodecIndex];
                    var xma    = GetXMA(buffer, snd_.SampleRate, codec.Type);

                    var          fs = File.OpenWrite(tempName);
                    EndianWriter sw = new EndianWriter(fs, EndianFormat.BigEndian);
                    sw.Write(xma);

                    sw.Close();
                    sw.Dispose();
                    #endregion

                    var info = new ProcessStartInfo(towav, tempName)
                    {
                        CreateNoWindow   = true,
                        UseShellExecute  = false,
                        WorkingDirectory = Directory.GetParent(tempName).FullName
                    };

                    Process.Start(info).WaitForExit();

                    if (File.Exists(Filename))
                    {
                        File.Delete(Filename);
                    }
                    if (!Directory.GetParent(Filename).Exists)
                    {
                        Directory.GetParent(Filename).Create();
                    }
                    File.Move(Path.ChangeExtension(tempName, "wav"), Filename);
                    if (File.Exists(tempName))
                    {
                        File.Delete(tempName);
                    }
                }
            }
            #endregion
            #region RAW
            else if (Format == SoundFormat.RAW)
            {
                foreach (int index in Indices)
                {
                    string Filename = (playback.PermutationCount == 1) ? Folder : Folder + "\\" + ugh_.SoundNames[ugh_.SoundPermutations[playback.FirstPermutation + index].NameIndex].Name + ".bin";
                    if (!Filename.EndsWith(".bin"))
                    {
                        Filename += ".bin";
                    }

                    if (File.Exists(Filename) && !Overwrite)
                    {
                        continue;
                    }

                    byte[] buffer = perms[index];

                    if (!Directory.GetParent(Filename).Exists)
                    {
                        Directory.GetParent(Filename).Create();
                    }

                    var          fs = new FileStream(Filename, FileMode.Create);
                    BinaryWriter sw = new BinaryWriter(fs);

                    sw.Write(buffer);
                    sw.Close();
                    sw.Dispose();
                }
            }
            #endregion
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Save all permutations of a sound tag as separate sound files.
        /// </summary>
        /// <param name="Folder">The base filename. Permutation names will be appended accordingly.</param>
        /// <param name="Cache">The CacheFile containing the tag.</param>
        /// <param name="Tag">The sound tag.</param>
        /// <param name="Format">The format in which to save the data.</param>
        public void SaveAllAsSeparate(string Folder, CacheBase Cache, CacheBase.IndexItem Tag, SoundFormat Format, bool Overwrite)
        {
            if (Format != SoundFormat.WAV)
            {
                throw new NotSupportedException("Halo4Retail only supports WAV.");
            }
            if (Cache.Version != DefinitionSet.Halo4Retail)
            {
                throw new Exception("This is for H4 ONLY");
            }

            if (scanner == null)
            {
                scanner = new SoundScanner();
                scanner.FoundSoundBankFile += FoundSoundBankFile;
                scanner.FoundSoundPackFile += FoundSoundPackFile;
            }

            cache = (CacheH4R)Cache;
            tag   = Tag;

            snd = (SoundH4R)DefinitionsManager.snd_(cache, tag);

            LoadCacheSoundPacks(cache);

            if (cache.SoundFiles == null)
            {
                cache.SoundFiles = new Dictionary <uint, List <SoundFileInfo> >();
                ObjectLoadWorker();
            }

            bool s1, s2;
            List <SoundFileInfo> sfi1, sfi2, sfi3;

            s1 = cache.SoundFiles.TryGetValue(snd.SoundAddress1, out sfi1);
            s2 = cache.SoundFiles.TryGetValue(snd.SoundAddress2, out sfi2);

            if (!s1 && !s2)
            {
                throw new Exception("No permutations found.");
            }

            sfi3 = new List <SoundFileInfo>();
            if (s1)
            {
                sfi3.AddRange(sfi1);
            }
            if (s2)
            {
                sfi3.AddRange(sfi2);
            }

            for (int i = 0; i < sfi3.Count; i++)
            {
                var info = sfi3[i];

                var fName = Path.GetFileName(tag.Filename);

                fName = Folder + "\\" + fName + " [" + i.ToString() + "]" + ".wav";

                if (File.Exists(fName) && !Overwrite)
                {
                    return;
                }

                RIFX rifx = ReadRIFX(info);

                switch (info.Format)
                {
                case Composer.SoundFormat.XMA:
                    if (!Directory.GetParent(fName).Exists)
                    {
                        Directory.GetParent(fName).Create();
                    }
                    SoundExtraction.ExtractXMAToWAV(info.Reader, info.Offset, rifx, fName);
                    break;

                case Composer.SoundFormat.WwiseOGG:
                    if (!Directory.GetParent(fName).Exists)
                    {
                        Directory.GetParent(fName).Create();
                    }
                    SoundExtraction.ExtractWwiseToOGG(info.Reader, info.Offset, info.Size, fName);
                    break;

                default:
                    throw new NotSupportedException(info.Format.ToString() + " not supported.");
                }
            }
        }