Ejemplo n.º 1
0
        public static VRamDescFile Read(Stream stream, Page.File file)
        {
            var result = new VRamDescFile();

            result.file = file;
            stream.Seek(file.GlobalDataOffset, SeekOrigin.Begin);
            stream.ReadValue(out result.header);
            result.fileName = stream.ReadString();
            return(result);
        }
Ejemplo n.º 2
0
        static void ExportTextures()
        {
            var path = @".pak";
            var stm  = File.OpenRead(path);
            var p    = new PakFileInput(stm, path);

            for (int i = 0; i < p.pages.Length; ++i)
            {
                var page = p.pages[i];
                for (int j = 0; j < page.files.Length; ++j)
                {
                    if (page.files[j].className == "VRAM_DESC")
                    {
                        var f = VRamDescFile.Read(stm, page.files[j]);

                        ExportDdsTexture(stm, f);

                        Console.WriteLine("Ololo");
                    }
                }
            }
        }
Ejemplo n.º 3
0
        static void ExportDdsTexture(Stream stm, VRamDescFile texture)
        {
            if (texture.header.width == texture.header.height)
            {
                return;
            }
            Dds.DDS_HEADER header = new Dds.DDS_HEADER();
            header.flags = Dds.DdsHeaderFlags.DDSD_CAPS | Dds.DdsHeaderFlags.DDSD_HEIGHT |
                           Dds.DdsHeaderFlags.DDSD_WIDTH | Dds.DdsHeaderFlags.DDSD_PIXELFORMAT |
                           Dds.DdsHeaderFlags.DDSD_MIPMAPCOUNT | Dds.DdsHeaderFlags.DDSD_LINEARSIZE;



            var realFilePath = Path.GetDirectoryName(texture.fileName);
            var fileName     = Path.GetFileName(realFilePath);

            string outFileName = Path.Join("D:\\TextureExport",
                                           fileName +
                                           $".{texture.header.width}_{texture.header.height}_unswizzled_page{texture.file.page.id}_file{texture.file.id}_fmt{texture.header.maybeFormat}" +
                                           ".dds");

            Console.WriteLine("Exporting texture " + outFileName);

            var rawData        = texture.ReadRawData(stm);
            var unswizzledData = UnswizzleTexture(rawData, texture.header.width, texture.header.height, texture.header.mipCount);

            if (texture.header.maybeFormat == 80)
            {
                header.ddspf = Dds.DDS_PIXELFORMAT.BC4_UNORM;
            }
            else if (texture.header.maybeFormat == 71 || (texture.header.maybeFormat == 72))
            {
                header.ddspf = Dds.DDS_PIXELFORMAT.DXT1;
            }
            else if (texture.header.maybeFormat == 35)
            {
                header.ddspf   = Dds.DDS_PIXELFORMAT.DXT1;
                unswizzledData = rawData;
            }
            else
            {
                header.ddspf = Dds.DDS_PIXELFORMAT.DXT1;
                Console.WriteLine($"unknown format {texture.header.maybeFormat} for texture {texture.fileName}");
                //return;
            }


            header.width             = texture.header.width;
            header.height            = texture.header.height;
            header.pitchOrLinearSize = (header.width * header.height) / 2;
            header.depth             = 1;
            header.mipMapCount       = texture.header.mipCount;
            header.reserved1         = new uint[11];
            header.caps = 0x1000; //DDSCAPS_TEXTURE
            header.size = (uint)Marshal.SizeOf <Dds.DDS_HEADER>();



            var ofs = File.OpenWrite(outFileName);


            ofs.WriteStruct(Dds.DdsMagic.Make());

            ofs.WriteStruct(header);
            ofs.Write(unswizzledData);
            ofs.Close();

            Console.WriteLine("Exporting texture done");
        }