Exemple #1
0
        public void Save(string filePath, ObjectDatabase objectDatabase, TextureDatabase textureDatabase,
                         BoneDatabase boneDatabase)
        {
            // Assume it's being exported for F2nd PS3
            if (BinaryFormatUtilities.IsClassic(Format) &&
                filePath.EndsWith(".osd", StringComparison.OrdinalIgnoreCase))
            {
                Format     = BinaryFormat.F2nd;
                Endianness = Endianness.BigEndian;
            }

            // Or reverse
            else if (BinaryFormatUtilities.IsModern(Format) &&
                     filePath.EndsWith(".bin", StringComparison.OrdinalIgnoreCase))
            {
                Format     = BinaryFormat.DT;
                Endianness = Endianness.LittleEndian;
            }

            string fileName = Path.GetFileName(filePath);

            bool exported = false;

            if (objectDatabase != null && TextureSet != null)
            {
                var objectEntry = objectDatabase.GetObjectByFileName(fileName);
                if (objectEntry != null)
                {
                    string textureOutputPath =
                        Path.Combine(Path.GetDirectoryName(filePath), objectEntry.TextureFileName);

                    TextureSet.Save(textureOutputPath);
                    exported = true;
                }
            }

            if (!exported && TextureSet != null)
            {
                string textureOutputPath = string.Empty;

                // Try to assume a texture output name
                if (filePath.EndsWith("_obj.bin", StringComparison.OrdinalIgnoreCase))
                {
                    textureOutputPath = $"{filePath.Substring( 0, filePath.Length - 8 )}_tex.bin";
                }

                else if (filePath.EndsWith(".osd", StringComparison.OrdinalIgnoreCase))
                {
                    textureOutputPath = Path.ChangeExtension(filePath, "txd");
                }

                if (!string.IsNullOrEmpty(textureOutputPath))
                {
                    TextureSet.Save(textureOutputPath);
                }
            }

            using (var destination = File.Create(filePath))
                Save(destination, objectDatabase, textureDatabase, boneDatabase);
        }
Exemple #2
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <TextureDatabase>((path) =>
            {
                // Assume it's being exported for F2nd PS3
                if (BinaryFormatUtilities.IsClassic(Data.Format) && path.EndsWith(".txi", StringComparison.OrdinalIgnoreCase))
                {
                    Data.Format     = BinaryFormat.F2nd;
                    Data.Endianness = Endianness.BigEndian;
                }

                // Or reverse
                else if (BinaryFormatUtilities.IsModern(Data.Format) && path.EndsWith(".bin", StringComparison.OrdinalIgnoreCase))
                {
                    Data.Format     = BinaryFormat.DT;
                    Data.Endianness = Endianness.LittleEndian;
                }

                Data.Save(path);
            });
            RegisterReplaceHandler <TextureDatabase>(BinaryFile.Load <TextureDatabase>);
            RegisterDataUpdateHandler(() =>
            {
                var data        = new TextureDatabase();
                data.Format     = Format;
                data.Endianness = Endianness;
                data.Textures.AddRange(Textures.Data);
                return(data);
            });
        }
        public override void Save(string filePath)
        {
            // Assume it's being exported for F2nd PS3
            if (BinaryFormatUtilities.IsClassic(Format) && filePath.EndsWith(".txi", StringComparison.OrdinalIgnoreCase))
            {
                Format     = BinaryFormat.F2nd;
                Endianness = Endianness.BigEndian;
            }

            // Or reverse
            else if (BinaryFormatUtilities.IsModern(Format) && filePath.EndsWith(".bin", StringComparison.OrdinalIgnoreCase))
            {
                Format     = BinaryFormat.DT;
                Endianness = Endianness.LittleEndian;
            }

            base.Save(filePath);
        }
        public override void Save(string filePath)
        {
            // Assume it's being exported for F2nd PS3
            if (BinaryFormatUtilities.IsClassic(Format) &&
                filePath.EndsWith(".txd", StringComparison.OrdinalIgnoreCase))
            {
                Format     = BinaryFormat.F2nd;
                Endianness = Endianness.Big;
            }

            // Or vice versa
            else if (BinaryFormatUtilities.IsModern(Format) &&
                     filePath.EndsWith(".bin", StringComparison.OrdinalIgnoreCase))
            {
                Format     = BinaryFormat.DT;
                Endianness = Endianness.Little;
            }

            // Save a TXI if we are modern
            if (filePath.EndsWith(".txd", StringComparison.OrdinalIgnoreCase))
            {
                var textureDatabase = new TextureDatabase();

                foreach (var texture in Textures)
                {
                    textureDatabase.Textures.Add(new TextureInfo
                    {
                        Id   = texture.Id,
                        Name = texture.Name ?? Guid.NewGuid().ToString()
                    });
                }

                textureDatabase.Format     = Format;
                textureDatabase.Endianness = Endianness;
                textureDatabase.Save(Path.ChangeExtension(filePath, "txi"));
            }

            base.Save(filePath);
        }
Exemple #5
0
 public static bool IsClassic(this BinaryFormat format) =>
 BinaryFormatUtilities.IsClassic(format);
        protected override void InitializeCore()
        {
            RegisterReplaceHandler <TextureSet>(BinaryFile.Load <TextureSet>);
            RegisterExportHandler <TextureSet>((path) =>
            {
                // Assume it's being exported for F2nd PS3
                if (BinaryFormatUtilities.IsClassic(Data.Format) && path.EndsWith(".txd", StringComparison.OrdinalIgnoreCase))
                {
                    Data.Format     = BinaryFormat.F2nd;
                    Data.Endianness = Endianness.BigEndian;
                }

                // Or reverse
                else if (BinaryFormatUtilities.IsModern(Data.Format) && path.EndsWith(".bin", StringComparison.OrdinalIgnoreCase))
                {
                    Data.Format     = BinaryFormat.DT;
                    Data.Endianness = Endianness.LittleEndian;
                }

                Data.Save(path);
            });
            RegisterImportHandler <Texture>((path) =>
            {
                var texture = TextureEncoder.Encode(path);
                var node    = DataNodeFactory.Create <Texture>(Path.GetFileNameWithoutExtension(path), texture);
                Textures.Add(node);
            });
            RegisterImportHandler <Bitmap>((path) =>
            {
                var texture = TextureEncoder.Encode(path);
                var node    = DataNodeFactory.Create <Texture>(Path.GetFileNameWithoutExtension(path), texture);
                Textures.Add(node);
            });
            RegisterCustomHandler("Export All", () =>
            {
                using (var saveFileDialog = new SaveFileDialog())
                {
                    saveFileDialog.AutoUpgradeEnabled = true;
                    saveFileDialog.CheckPathExists    = true;
                    saveFileDialog.Title    = "Select a folder to export textures to.";
                    saveFileDialog.FileName = "Enter into a directory and press Save";

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        var outputDirectory = Path.GetDirectoryName(saveFileDialog.FileName);
                        foreach (var texture in Data.Textures)
                        {
                            if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr)
                            {
                                TextureDecoder.DecodeToPNG(texture, Path.Combine(outputDirectory, texture.Name + ".png"));
                            }
                            else
                            {
                                TextureDecoder.DecodeToDDS(texture, Path.Combine(outputDirectory, texture.Name + ".dds"));
                            }
                        }
                    }
                }
            }, Keys.Control | Keys.Shift | Keys.E);
            RegisterDataUpdateHandler(() =>
            {
                var data        = new TextureSet();
                data.Format     = Format;
                data.Endianness = Endianness;
                data.Textures.AddRange(Textures.Data);
                return(data);
            });
        }