Esempio n. 1
0
        public static DxTexture ReadFromWpd(WpdArchiveListing listing, WpdEntry entry)
        {
            using (Stream headers = listing.Accessor.ExtractHeaders())
                using (Stream content = listing.Accessor.ExtractContent())
                {
                    headers.SetPosition(entry.Offset);

                    GtexData      gtex;
                    SectionHeader sectionHeader = headers.ReadContent <SectionHeader>();
                    switch (sectionHeader.Type)
                    {
                    case SectionType.Txb:
                        gtex = ReadGtexFromTxb(headers);
                        break;

                    case SectionType.Vtex:
                        gtex = ReadGtexFromVtex(headers);
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    return(LoadFromStream(gtex, content));
                }
        }
Esempio n. 2
0
        private void Inject(WpdEntry entry, String targetPath)
        {
            string targetExtension = entry.Extension.ToLowerInvariant();

            IWpdEntryInjector injector;

            if (_injectors.TryGetValue(targetExtension, out injector))
            {
                string targetFullPath = targetPath + '.' + injector.SourceExtension;
                using (Stream input = _source.TryOpen(targetFullPath))
                {
                    if (input != null)
                    {
                        injector.Inject(entry, input, _headers, _content, _buff);
                        _injected = true;
                        return;
                    }
                }
            }

            if (_conversion != true)
            {
                string targetFullPath = targetPath + '.' + targetExtension;
                using (Stream input = _source.TryOpen(targetFullPath))
                {
                    if (input != null)
                    {
                        DefaultInjector.Inject(entry, input, _headers, _content, _buff);
                        _injected = true;
                    }
                }
            }
        }
        private void Inject(WpdArchiveListing listing, WpdEntry[] fontEntries, WflContent[] fontContent)
        {
            UiInjectionManager manager = new UiInjectionManager();

            using (MemoryInjectionSource source = new MemoryInjectionSource())
            {
                String injectionRoot = Path.Combine(source.ProvideRootDirectory(), listing.ExtractionSubpath);
                for (int i = 0; i < fontEntries.Length; i++)
                {
                    WpdEntry   entry         = fontEntries[i];
                    WflContent content       = fontContent[i];
                    String     injectionPath = Path.Combine(injectionRoot, entry.Name);

                    MemoryStream stream = new MemoryStream(1024);
                    source.RegisterStream(injectionPath, stream);

                    WflFileWriter writer = new WflFileWriter(stream);
                    writer.Write(content);
                    stream.SetPosition(0);
                }

                UiWpdInjector injector = new UiWpdInjector(listing, fontEntries, false, source);
                injector.Inject(manager);
            }
            manager.WriteListings();
        }
 private static TextureSection[] ReadTextureHeaders(Stream xgrStream, WpdEntry[] textureEntries)
 {
     TextureSection[] result = new TextureSection[textureEntries.Length];
     for (int i = 0; i < result.Length; i++)
     {
         WpdEntry entry = textureEntries[i];
         using (StreamSegment textureHeaderInput = new StreamSegment(xgrStream, entry.Offset, entry.Length, FileAccess.Read))
             result[i] = textureHeaderInput.ReadContent <TextureSection>();
     }
     return(result);
 }
Esempio n. 5
0
        public static void InjectSingle(WpdArchiveListing listing, WpdEntry entry, MemoryStream output)
        {
            using (MemoryInjectionSource source = new MemoryInjectionSource())
            {
                source.RegisterStream(String.Empty, output);
                UiWpdInjector injector = new UiWpdInjector(listing, new[] { entry }, false, source);

                UiInjectionManager manager = new UiInjectionManager();
                injector.Inject(manager);
                manager.WriteListings();
            }
        }
        public void Inject(WpdEntry entry, Stream input, Lazy <Stream> headers, Lazy <Stream> content, Byte[] buff)
        {
            int sourceSize = (int)input.Length;

            headers.Value.Position = entry.Offset;

            SectionHeader sectionHeader = headers.Value.ReadContent <SectionHeader>();
            VtexHeader    textureHeader = headers.Value.ReadContent <VtexHeader>();

            byte[] unknownData = new byte[textureHeader.GtexOffset - VtexHeader.Size];
            headers.Value.Read(unknownData, 0, unknownData.Length);

            GtexData data = headers.Value.ReadContent <GtexData>();

            if (data.MipMapData.Length != 1)
            {
                throw new NotImplementedException();
            }

            DdsHeader ddsHeader = DdsHeaderDecoder.FromFileStream(input);

            DdsHeaderEncoder.ToGtexHeader(ddsHeader, data.Header);

            GtexMipMapLocation mipMapLocation = data.MipMapData[0];
            int dataSize = sourceSize - 128;

            if (dataSize <= mipMapLocation.Length)
            {
                content.Value.Seek(mipMapLocation.Offset, SeekOrigin.Begin);
            }
            else
            {
                content.Value.Seek(0, SeekOrigin.End);
                mipMapLocation.Offset = (int)content.Value.Position;
            }

            input.CopyToStream(content.Value, dataSize, buff);
            mipMapLocation.Length = dataSize;

            using (MemoryStream ms = new MemoryStream(180))
            {
                sectionHeader.WriteToStream(ms);
                textureHeader.WriteToStream(ms);

                ms.Write(unknownData, 0, unknownData.Length);
                data.WriteToStream(ms);

                ms.SetPosition(0);

                DefaultWpdEntryInjector defaultInjector = new DefaultWpdEntryInjector();
                defaultInjector.Inject(entry, ms, headers, content, buff);
            }
        }
 private static WflContent[] ReadFontContent(Stream xgr, WpdEntry[] fontEntries)
 {
     WflContent[] result = new WflContent[fontEntries.Length];
     for (int i = 0; i < result.Length; i++)
     {
         WpdEntry entry = fontEntries[i];
         using (StreamSegment wflInput = new StreamSegment(xgr, entry.Offset, entry.Length, FileAccess.Read))
         {
             WflFileReader reader = new WflFileReader(wflInput);
             result[i] = reader.Read();
         }
     }
     return(result);
 }
Esempio n. 8
0
        private UiNode[] ExpandWpdChilds()
        {
            ImgbArchiveAccessor imgbAccessor = new ImgbArchiveAccessor(_listing, _indices, _binary);
            WpdArchiveListing   wpdListing   = WpdArchiveListingReader.Read(imgbAccessor);

            UiNode[] result = new UiNode[wpdListing.Count];
            for (int i = 0; i < result.Length; i++)
            {
                WpdEntry xgrEntry = wpdListing[i];
                result[i] = new UiWpdTableLeaf(xgrEntry.Name, xgrEntry, wpdListing)
                {
                    Parent = this
                };
            }
            return(result);
        }
Esempio n. 9
0
        private IWpdEntryExtractor GetExtractor(WpdEntry entry, out String targetExtension)
        {
            targetExtension = entry.Extension.ToLowerInvariant();

            IWpdEntryExtractor result;

            if (_extractors.TryGetValue(targetExtension, out result))
            {
                targetExtension = result.TargetExtension;
            }
            else if (_conversion != true)
            {
                result = DefaultExtractor;
            }

            return(result);
        }
Esempio n. 10
0
        public void Inject(WpdEntry entry, Stream input, Lazy <Stream> headers, Lazy <Stream> content, Byte[] buff)
        {
            int sourceSize = (int)input.Length;

            if (sourceSize <= entry.Length)
            {
                headers.Value.Seek(entry.Offset, SeekOrigin.Begin);
            }
            else
            {
                headers.Value.Seek(0, SeekOrigin.End);
                entry.Offset = (int)headers.Value.Position;
            }

            input.CopyToStream(headers.Value, sourceSize, buff);
            entry.Length = sourceSize;
        }
Esempio n. 11
0
        private void OnWpdLeafSelected(UiWpdTableLeaf wpdLeaf)
        {
            WpdEntry          entry   = wpdLeaf.Entry;
            WpdArchiveListing listing = wpdLeaf.Listing;

            switch (entry.Extension)
            {
            case "txbh":
            case "vtex":
                _textureViewer.Show(listing, entry);
                break;

            case "ykd":
                _ykd.Show(listing, entry);
                break;
            }
        }
        public void Extract(WpdEntry entry, Stream output, Lazy <Stream> headers, Lazy <Stream> content, Byte[] buff)
        {
            headers.Value.Position = entry.Offset;

            SectionHeader sectionHeader = headers.Value.ReadContent <SectionHeader>();
            TextureHeader textureHeader = headers.Value.ReadContent <TextureHeader>();
            GtexData      gtex          = headers.Value.ReadContent <GtexData>();

            DdsHeader header = DdsHeaderDecoder.FromGtexHeader(gtex.Header);

            DdsHeaderEncoder.ToFileStream(header, output);

            foreach (GtexMipMapLocation mipMap in gtex.MipMapData)
            {
                content.Value.Position = mipMap.Offset;
                content.Value.CopyToStream(output, mipMap.Length, buff);
            }
        }
Esempio n. 13
0
 public void Show(WpdArchiveListing listing, WpdEntry entry)
 {
     Visibility = Visibility.Visible;
     Texture    = DxTextureReader.ReadFromWpd(listing, entry);
 }
Esempio n. 14
0
 public void Extract(WpdEntry entry, Stream output, Lazy <Stream> headers, Lazy <Stream> content, Byte[] buff)
 {
     headers.Value.Position = entry.Offset;
     headers.Value.CopyToStream(output, entry.Length, buff);
 }
Esempio n. 15
0
 public UiWpdTableLeaf(string name, WpdEntry entry, WpdArchiveListing listing)
     : base(name, UiNodeType.FileTableLeaf)
 {
     Entry   = entry;
     Listing = listing;
 }