Пример #1
0
        private bool repackFile(TPF.Texture tpfEntry, string name, string baseDir, string subDir)
        {
            string inputPath = baseDir + "\\" + subDir + "\\" + name + ".dds";

            //DBGTEX_DETAIL crashes this, what in the heck
            if (inputPath != null && File.Exists(inputPath) && name != "DBGTEX_DETAIL")
            {
                byte[] inputBytes = File.ReadAllBytes(inputPath);

                DXGIFormat originalFormat = DDSFile.Read(new MemoryStream(tpfEntry.Bytes)).Format;

                DXGIFormat newFormat = DDSFile.Read(new MemoryStream(inputBytes)).Format;

                if (originalFormat != DXGIFormat.Unknown && newFormat != DXGIFormat.Unknown && originalFormat != newFormat)
                {
                    byte[] newBytes = convertFile(inputPath, originalFormat);
                    if (newBytes != null)
                    {
                        inputBytes = newBytes;
                    }
                }

                tpfEntry.Bytes = inputBytes;

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        public static int GetTpfFormatFromDdsBytes(FBX2FLVERImporter importer, string texName, byte[] ddsBytes)
        {
            using (var ddsStream = new MemoryStream(ddsBytes))
            {
                DXGIFormat format = DDSFile.Read(ddsStream).Format;

                switch (format)
                {
                //DSR:
                case DXGIFormat.BC1_UNorm:
                case DXGIFormat.BC1_UNorm_SRGB:
                    return(0);

                case DXGIFormat.BC2_UNorm:
                case DXGIFormat.BC2_UNorm_SRGB:
                    return(3);

                case DXGIFormat.BC3_UNorm:
                case DXGIFormat.BC3_UNorm_SRGB:
                    return(5);

                case DXGIFormat.R16G16_Float:
                    return(35);

                case DXGIFormat.BC5_UNorm:
                    return(36);

                case DXGIFormat.BC6H_UF16:
                    return(37);

                case DXGIFormat.BC7_UNorm:
                case DXGIFormat.BC7_UNorm_SRGB:
                    return(38);

                //DS3:
                //case DXGIFormat.B5G5R5A1_UNorm:
                //    return 6;
                //case DXGIFormat.B8G8R8A8_UNorm:
                //case DXGIFormat.B8G8R8A8_UNorm_SRGB:
                //    return 9;
                //case DXGIFormat.B8G8R8X8_UNorm:
                //case DXGIFormat.B8G8R8X8_UNorm_SRGB:
                //    return 10;
                //case DXGIFormat.R16G16B16A16_Float:
                //    return 22;
                default:
                    importer.PrintWarning($"Texture \"{texName}\" has an unrecognized" +
                                          $" DDS format type ({format.ToString()}) and will likely appear garbled ingame. " +
                                          $"For greatest compatibility, use DXT1 (aka BC1_UNorm) or DXT5 (aka BC3_UNorm) " +
                                          $"for your textures.");
                    return(0);
                }
            }
        }
Пример #3
0
 public UnpackReportFile(TPF.Texture tex)
 {
     using (var ms = new MemoryStream(tex.Bytes))
         using (var dds = DDSFile.Read(ms))
         {
             Name   = tex.Name;
             Format = dds?.Format ?? DXGIFormat.Unknown;
             Width  = dds?.MipChains[0][0].Width ?? -1;
             Height = dds?.MipChains[0][0].Height ?? -1;
         }
 }
Пример #4
0
        public static byte GetTpfFormatFromDdsBytes(byte[] ddsBytes)
        {
            using (var ddsStream = new MemoryStream(ddsBytes))
            {
                DXGIFormat format = DDSFile.Read(ddsStream).Format;

                switch (format)
                {
                //DSR:
                case DXGIFormat.BC1_UNorm:
                case DXGIFormat.BC1_UNorm_SRGB:
                    return(0);

                case DXGIFormat.BC2_UNorm:
                case DXGIFormat.BC2_UNorm_SRGB:
                    return(3);

                case DXGIFormat.BC3_UNorm:
                case DXGIFormat.BC3_UNorm_SRGB:
                    return(5);

                case DXGIFormat.R16G16_Float:
                    return(35);

                case DXGIFormat.BC5_UNorm:
                    return(36);

                case DXGIFormat.BC6H_UF16:
                    return(37);

                case DXGIFormat.BC7_UNorm:
                case DXGIFormat.BC7_UNorm_SRGB:
                    return(38);

                //DS3:
                //case DXGIFormat.B5G5R5A1_UNorm:
                //    return 6;
                //case DXGIFormat.B8G8R8A8_UNorm:
                //case DXGIFormat.B8G8R8A8_UNorm_SRGB:
                //    return 9;
                //case DXGIFormat.B8G8R8X8_UNorm:
                //case DXGIFormat.B8G8R8X8_UNorm_SRGB:
                //    return 10;
                //case DXGIFormat.R16G16B16A16_Float:
                //    return 22;
                default:
                    return(0);
                }
            }
        }
Пример #5
0
        private bool repackFile(TPF.Texture tpfEntry, string name, string baseDir, string subDir)
        {
            string inputPath = getSwappedPath(name, subDir, out bool dds);

            if (inputPath != null && File.Exists(inputPath))
            {
                byte[] inputBytes = File.ReadAllBytes(inputPath);

                DXGIFormat originalFormat = DDSFile.Read(new MemoryStream(tpfEntry.Bytes)).Format;
                if (originalFormat == DXGIFormat.Unknown)
                {
                    appendError("Error: {0}\r\n\u2514\u2500 Could not determine format of game file.", subDir + "\\" + name + ".dds");
                }

                bool convert = !dds;
                if (dds)
                {
                    DXGIFormat newFormat = DDSFile.Read(new MemoryStream(inputBytes)).Format;

                    if (newFormat == DXGIFormat.Unknown)
                    {
                        appendError("Error: {0}\r\n\u2514\u2500 Could not determine format of override file.", inputPath);
                    }

                    if (originalFormat != DXGIFormat.Unknown && newFormat != DXGIFormat.Unknown && originalFormat != newFormat)
                    {
                        convert = true;
                    }
                }

                if (convert)
                {
                    byte[] newBytes = convertFile(inputPath, originalFormat);
                    if (newBytes != null)
                    {
                        inputBytes = newBytes;
                    }
                }

                tpfEntry.Bytes = inputBytes;
                lock (countLock)
                    textureCount++;

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #6
0
        private void ModdedTexOpen()
        {
            moddedTexPathBox.Text = moddedTexPath;
            moddedTexOpen         = true;
            if (!isWebImage)
            {
                texturePreview2.Image = null;
            }
            moddedFormat = "None";
            // Check if file is dds or png
            if (DDSFile.IsDDSFile(moddedTexPath) == true)
            {
                // Get dds data
                DDSContainer moddedTexture = DDSFile.Read(moddedTexPath);
                moddedFormat      = moddedTexture.Format.ToString();
                moddedDDS.MipMaps = moddedTexture.MipChains[0].Count;
                if (moddedFormat == "BC3_UNorm")
                {
                    moddedFormat = "DXT5";
                }
                else if (moddedFormat == "BC1_UNorm")
                {
                    moddedFormat = "DXT1";
                }
                moddedDDS.Format = moddedFormat;

                // Convert to png for preview
                DDSImage     modDDS    = new DDSImage(moddedTexPath);
                MemoryStream pngStream = new MemoryStream();
                modDDS.SaveAsPng(pngStream);
                var newPNG = Image.FromStream(pngStream);

                // Change labels
                moddedTexCompression.Text = moddedDDS.Format;
                mipMapCountLabel2.Text    = moddedDDS.MipMaps.ToString();
                texturePreview2.Image     = newPNG;
                previewLabel2.Text        = "Preview:";
                moddedDDS.ResX            = texturePreview2.Image.Width;
                moddedDDS.ResY            = texturePreview2.Image.Height;
                resolutionCheck2.Text     = moddedDDS.ResX.ToString() + "x" + moddedDDS.ResY.ToString();
                texturePreview2.SizeMode  = PictureBoxSizeMode.Zoom;

                // Dispose
                pngStream.Dispose();
                moddedTexture.Dispose();
            }
            else
            {
                // Bitmap/Png format
                if (moddedTexPath.Contains(".bmp"))
                {
                    moddedTexCompression.Text = "None (Bitmap)";
                }
                else if (moddedTexPath.Contains(".png"))
                {
                    moddedTexCompression.Text = "None (PNG)";
                }
                else
                {
                    moddedTexCompression.Text = "None";
                }
                mipMapCountLabel2.Text = "None";
                previewLabel2.Text     = "Preview:";
                if (!isWebImage)
                {
                    texturePreview2.Image    = new Bitmap(moddedTexPath);
                    texturePreview2.SizeMode = PictureBoxSizeMode.Zoom;
                }
                resolutionCheck2.Text = texturePreview2.Image.Width.ToString() + "x" + texturePreview2.Image.Height.ToString();
            }
            EnableButtons();
        }
Пример #7
0
        public override object Execute(List <string> args)
        {
            if (args.Count != 2)
            {
                return(false);
            }

            if (!int.TryParse(args[0], NumberStyles.HexNumber, null, out int imageIndex))
            {
                return(false);
            }

            if (Bitmap.Images.Count == 0)
            {
                Bitmap.Flags = BitmapRuntimeFlags.UsingTagInteropAndTagResource;
                Bitmap.Images.Add(new Bitmap.Image {
                    Signature = new Tag("bitm")
                });
                Bitmap.Resources.Add(new TagResourceReference());
            }

            if (imageIndex < 0 || imageIndex >= Bitmap.Images.Count)
            {
                Console.Error.WriteLine("Invalid image index.");
                return(true);
            }

            var imagePath = args[1];

            Console.WriteLine("Importing image data...");

#if !DEBUG
            try
            {
#endif
            DDSFile file = new DDSFile();

            using (var imageStream = File.OpenRead(imagePath))
                using (var reader = new EndianReader(imageStream))
                {
                    file.Read(reader);
                }

            var bitmapTextureInteropDefinition = BitmapInjector.CreateBitmapResourceFromDDS(Cache, file);
            var reference = Cache.ResourceCache.CreateBitmapResource(bitmapTextureInteropDefinition);

            // set the tag data

            Bitmap.Resources[imageIndex] = reference;
            Bitmap.Images[imageIndex]    = BitmapUtils.CreateBitmapImageFromResourceDefinition(bitmapTextureInteropDefinition.Texture.Definition.Bitmap);

            using (var tagsStream = Cache.OpenCacheReadWrite())
                Cache.Serialize(tagsStream, Tag, Bitmap);
#if !DEBUG
        }

        catch (Exception ex)
        {
            Console.WriteLine("Importing image data failed: " + ex.Message);
            return(true);
        }
#endif


            Console.WriteLine("Done!");

            return(true);
        }