private static bool ConvertTexture(Superbundle.BundleInfo bundleInfo,
                                           Superbundle.ResourceInfo resourceInfo,
                                           ICatalogEntryInfo entry,
                                           string outputPath,
                                           CatalogLookup catalogLookup,
                                           List <TableOfContentsFile> commonBundles)
        {
            TextureHeader textureHeader;

            using (var temp = new MemoryStream())
            {
                Extraction.Extract(resourceInfo, entry, temp);
                temp.Position = 0;
                textureHeader = TextureHeader.Read(temp);
                if (temp.Position != temp.Length)
                {
                    throw new FormatException();
                }
            }

            if (textureHeader.Type != TextureType._2d)
            {
                return(false);
            }

            if (textureHeader.Unknown00 != 0 ||
                textureHeader.Unknown04 != 0 ||
                textureHeader.Unknown10 != 0 ||
                textureHeader.Unknown14 != 0 ||
                textureHeader.Unknown1C != 1)
            {
                throw new FormatException();
            }

            SHA1 chunkSHA1;

            if (GetChunkSHA1(bundleInfo, commonBundles, textureHeader.DataChunkId, out chunkSHA1) == false)
            {
                throw new InvalidOperationException();
            }

            var dataEntry = catalogLookup.GetEntry(chunkSHA1, textureHeader.TotalSize);

            byte[] dataBytes;
            using (var temp = new MemoryStream())
            {
                Extraction.Extract(dataEntry, textureHeader.TotalSize, temp);
                temp.Position = 0;
                dataBytes     = temp.GetBuffer();
            }

            DDSUtils.WriteFile(textureHeader, dataBytes, outputPath + ".dds");
            return(true);
        }
示例#2
0
        public static void Extract(Superbundle.IDataInfo bundleInfo, ICatalogEntryInfo catalogInfo, Stream output)
        {
            if (bundleInfo == null)
            {
                throw new ArgumentNullException("bundleInfo");
            }

            if (catalogInfo == null)
            {
                throw new ArgumentNullException("catalogInfo");
            }

            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            Stream input;

            if (bundleInfo.InlineData != null)
            {
                if (bundleInfo.InlineData.Length != bundleInfo.Size)
                {
                    throw new InvalidOperationException();
                }

                input = new MemoryStream(bundleInfo.InlineData, false);
            }
            else
            {
                input          = File.OpenRead(catalogInfo.DataPath);
                input.Position = catalogInfo.Offset;
            }

            using (input)
            {
                if (bundleInfo.Size == bundleInfo.OriginalSize)
                {
                    output.WriteFromStream(input, bundleInfo.Size);
                }
                else
                {
                    Decompress(input, output, bundleInfo.OriginalSize);
                }
            }
        }
示例#3
0
        public static void Extract(ICatalogEntryInfo catalogInfo, long uncompressedSize, Stream output)
        {
            if (catalogInfo == null)
            {
                throw new ArgumentNullException("catalogInfo");
            }

            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            using (var input = File.OpenRead(catalogInfo.DataPath))
            {
                input.Position = catalogInfo.Offset;
                Decompress(input, output, uncompressedSize);
            }
        }