Ejemplo n.º 1
0
        private static bool GetChunkSHA1(Superbundle.BundleInfo bundleInfo,
                                         List <TableOfContentsFile> commonBundles,
                                         Guid chunkId,
                                         out SHA1 chunkSHA1)
        {
            if (bundleInfo.Chunks != null)
            {
                var chunkInfo = bundleInfo.Chunks.FirstOrDefault(ci => ci.Id == chunkId);
                if (chunkInfo != null)
                {
                    chunkSHA1 = chunkInfo.SHA1;
                    return(true);
                }
            }

            var commonChunkInfo = commonBundles.SelectMany(cb => cb.Chunks)
                                  .FirstOrDefault(ci => ci.Id == chunkId);

            if (commonChunkInfo != null)
            {
                chunkSHA1 = commonChunkInfo.SHA1;
                return(true);
            }

            chunkSHA1 = default(SHA1);
            return(false);
        }
Ejemplo n.º 2
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);
        }