Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private static bool ConvertTexture(MemoryStream data,
                                           string outputPath,
                                           ChunkLookup chunkLookup,
                                           ChunkLoader chunkLoader)
        {
            var textureHeader = TextureHeader.Read(data);

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

            if (textureHeader.Unknown10 != 0 ||
                (textureHeader.Flags != TextureFlags.None &&
                 textureHeader.Flags != TextureFlags.Unknown0 &&
                 textureHeader.Flags != (TextureFlags.Unknown0 | TextureFlags.Unknown3) &&
                 textureHeader.Flags != TextureFlags.Unknown5) ||
                textureHeader.Unknown1C != 1)
            {
                throw new FormatException();
            }

            SHA1 chunkSHA1;
            long size;

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

            var dataChunkInfo = chunkLookup.GetChunkVariant(chunkSHA1, size);

            if (dataChunkInfo == null)
            {
                throw new InvalidOperationException();
            }

            byte[] dataBytes;
            using (var temp = new MemoryStream())
            {
                chunkLoader.Load(dataChunkInfo, textureHeader.TotalSize, temp);
                temp.Position = 0;
                dataBytes     = temp.GetBuffer();
            }

            using (var output = File.Create(outputPath))
            {
                DDSUtils.WriteFile(textureHeader, dataBytes, output);
            }

            return(true);
        }