Esempio n. 1
0
        public void ExtractXMA(string directory)
        {
            if (BlamSoundGestalt == null)
            {
                using (var stream = Cache.OpenCacheRead())
                    BlamSoundGestalt = PortingContextFactory.LoadSoundGestalt(Cache, stream);
            }


            var resourceDefinition = Cache.ResourceCache.GetSoundResourceDefinition(Sound.Resource);
            var xmaFileSize        = BlamSoundGestalt.GetFileSize(Sound.SoundReference.PitchRangeIndex, Sound.SoundReference.PitchRangeCount);

            if (xmaFileSize < 0)
            {
                return;
            }

            var xmaData = resourceDefinition.Data.Data;

            if (xmaData == null)
            {
                Console.WriteLine($"ERROR: Failed to find sound data!");
                return;
            }

            var    parts    = Tag.Name.Split('\\');
            string baseName = parts[parts.Length - 1];

            for (int pitchRangeIndex = Sound.SoundReference.PitchRangeIndex; pitchRangeIndex < Sound.SoundReference.PitchRangeIndex + Sound.SoundReference.PitchRangeCount; pitchRangeIndex++)
            {
                var relativePitchRangeIndex = pitchRangeIndex - Sound.SoundReference.PitchRangeIndex;
                var permutationCount        = BlamSoundGestalt.GetPermutationCount(pitchRangeIndex);

                for (int i = 0; i < permutationCount; i++)
                {
                    BlamSound blamSound       = SoundConverter.GetXMA(Cache, BlamSoundGestalt, Sound, relativePitchRangeIndex, i, xmaData);
                    string    permutationName = $"{baseName}_{relativePitchRangeIndex}_{i}";
                    var       fileName        = $"{directory}\\{permutationName}.xma";

                    using (EndianWriter output = new EndianWriter(new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None), EndianFormat.BigEndian))
                    {
                        XMAFile XMAfile = new XMAFile(blamSound);
                        XMAfile.Write(output);
                    }
                }
            }
        }
Esempio n. 2
0
 public void LoadResourceCache()
 {
     // means no resources
     if (Cache.BaseMapFile.Header.SectionTable.Sections[(int)CacheFileSectionType.ResourceSection].Size == 0)
     {
         return;
     }
     // means resources but no tags, campaign.map for example. The resource section only contains pages for resources
     else if (Cache.BaseMapFile.Header.SectionTable.Sections[(int)CacheFileSectionType.TagSection].Size == 0)
     {
         return;
     }
     // TODO: figure out another way to handle this
     else
     {
         using (var cacheStream = Cache.OpenCacheRead())
         {
             ResourceGestalt     = Cache.Deserialize <ResourceGestalt>(cacheStream, Cache.TagCacheGen3.GlobalInstances["zone"]);
             ResourceLayoutTable = Cache.Deserialize <ResourceLayoutTable>(cacheStream, Cache.TagCacheGen3.GlobalInstances["play"]);
         }
     }
     isLoaded = true;
 }