Exemple #1
0
        private static void Main(string[] args)
        {
            Stream tmp = File.OpenWrite(args[1]);

            Console.WriteLine("Start:");
            Stream meme = File.OpenRead(args[0]);

            if (DDSExport.CanImportCore(meme) == true)
            {
                Console.WriteLine("Open DDS");
                DDSStream DDSFILE = new DDSStream(meme);
                Console.WriteLine("Swizzling");
                GNFTexture momo = new GNFTexture(DDSFILE);
                Console.WriteLine("Write GNFTexture");
                GNFexport.ExportCore(momo, tmp);
            }
            tmp.Close();

            // validate GNF
            Stream tmp1 = File.OpenRead(args[1]);

            if (GNFexport.CanImportCore(tmp1))
            {
                Console.WriteLine("GNF is valid");
            }
        }
        /// <summary>
        /// Converts the given texture dictionary to a field texture archive, and returns a new texture dictionary filled with dummy textures for each texture in the given texture dictionary.
        /// </summary>
        /// <param name="textureDictionary"></param>
        /// <param name="archiveFilePath"></param>
        /// <returns></returns>
        public static TextureDictionary ConvertToFieldTextureArchive(TextureDictionary textureDictionary, string archiveFilePath, bool usePS4Format = false)
        {
            var archiveBuilder = new ArchiveBuilder();

            // Create bgTexArcData00.txt
            var fieldTextureArchiveDataInfoStream = new MemoryStream();

            using (var streamWriter = new StreamWriter(fieldTextureArchiveDataInfoStream, Encoding.Default, 4096, true))
            {
                streamWriter.WriteLine("1,");
                streamWriter.WriteLine($"{textureDictionary.Count},");
            }

            archiveBuilder.AddFile("bgTexArcData00.txt", fieldTextureArchiveDataInfoStream);

            // Convert textures
            foreach (var texture in textureDictionary.Textures)
            {
                var textureInfo      = TextureInfo.GetTextureInfo(texture);
                var texturePixelData = TextureUtilities.GetPixelData(texture);

                // Create field texture & save it
                Stream textureStream = new MemoryStream();
                if (!usePS4Format)
                {
                    var fieldTexture = new FieldTexturePS3(textureInfo.PixelFormat, ( byte )textureInfo.MipMapCount, ( short )textureInfo.Width,
                                                           ( short )textureInfo.Height, texturePixelData);
                    fieldTexture.Save(textureStream);
                }
                else
                {
                    var fieldTexture = new GNFTexture(textureInfo.PixelFormat, ( byte )textureInfo.MipMapCount, ( short )textureInfo.Width,
                                                      ( short )textureInfo.Height, texturePixelData, false);
                    fieldTexture.Save(textureStream);
                }

                archiveBuilder.AddFile(texture.Name, textureStream);
            }

            // Finally build archive file
            archiveBuilder.BuildFile(archiveFilePath);

            // Dummy out textures in texture dictionary
            var newTextureDictionary = new TextureDictionary(textureDictionary.Version);

            foreach (var texture in textureDictionary.Textures)
            {
                newTextureDictionary.Add(Texture.CreateDefaultTexture(texture.Name));
            }

            return(newTextureDictionary);
        }
Exemple #3
0
        public static Bitmap Decode(GNFTexture texture)
        {
            var ddsBytes = DecodeToDDS(texture);

            return(DecodeDDS(ddsBytes));
        }
Exemple #4
0
        public static byte[] DecodeToDDS(GNFTexture texture)
        {
            var imageFormat     = ImageEngineFormat.DDS_DXT5;
            var dx10ImageFormat = DDS_Header.DXGI_FORMAT.DXGI_FORMAT_UNKNOWN;

            switch (texture.SurfaceFormat)
            {
            case GNF.SurfaceFormat.BC1:
                imageFormat = ImageEngineFormat.DDS_DXT1;
                break;

            case GNF.SurfaceFormat.BC2:
                imageFormat = ImageEngineFormat.DDS_DXT2;
                break;

            case GNF.SurfaceFormat.BC3:
                imageFormat = ImageEngineFormat.DDS_DXT5;
                break;

            case GNF.SurfaceFormat.BC4:
                imageFormat = ImageEngineFormat.DDS_ATI1;
                break;

            case GNF.SurfaceFormat.BC5:
                imageFormat = ImageEngineFormat.DDS_ATI2_3Dc;
                break;

            case GNF.SurfaceFormat.BC6:
                imageFormat     = ImageEngineFormat.DDS_DX10;
                dx10ImageFormat = DDS_Header.DXGI_FORMAT.DXGI_FORMAT_BC6H_UF16;
                break;

            case GNF.SurfaceFormat.BC7:
                imageFormat = ImageEngineFormat.DDS_DX10;

                switch (texture.ChannelType)
                {
                case ChannelType.Srgb:
                    dx10ImageFormat = DDS_Header.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM_SRGB;
                    break;

                default:
                    dx10ImageFormat = DDS_Header.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM;
                    break;
                }
                break;
            }

            var ddsHeaderSize = 0x80;

            if (dx10ImageFormat != DDS_Header.DXGI_FORMAT.DXGI_FORMAT_UNKNOWN)
            {
                ddsHeaderSize += 20;
            }

            var ddsBytes = new byte[ddsHeaderSize + texture.Data.Length];

            // create & write header
            var ddsHeader = new DDS_Header(1, texture.Height, texture.Width, imageFormat, dx10ImageFormat);

            ddsHeader.WriteToArray(ddsBytes, 0);

            // unswizzle
            var data = Swizzler.UnSwizzle(texture.Data, texture.Width, texture.Height, imageFormat == ImageEngineFormat.DDS_DXT1 ? 8 : 16, SwizzleType.PS4);

            // write pixel data
            Array.Copy(data, 0, ddsBytes, ddsHeaderSize, texture.Data.Length);

            return(ddsBytes);
        }
Exemple #5
0
 public static void ExportCore(GNFTexture obj, Stream stream, string filename = null)
 {
     obj.Save(stream);
 }