From 0b7f5043e9fea9d8ec0d90b846eb54c1a450fba2 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Thu, 23 Apr 2020 16:11:05 -0400 Subject: [PATCH] Fix BCLIM saving (fixes bclyt editing in archives) --- .../FileFormats/Texture/BCLIM.cs | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/File_Format_Library/FileFormats/Texture/BCLIM.cs b/File_Format_Library/FileFormats/Texture/BCLIM.cs index 4a5f97fa..175634ef 100644 --- a/File_Format_Library/FileFormats/Texture/BCLIM.cs +++ b/File_Format_Library/FileFormats/Texture/BCLIM.cs @@ -66,7 +66,7 @@ namespace FirstPlugin } } - public override bool CanEdit { get; set; } = true; + public override bool CanEdit { get; set; } = false; public bool CanSave { get; set; } public string[] Description { get; set; } = new string[] { "Layout Image" }; @@ -130,7 +130,7 @@ namespace FirstPlugin form.Dock = DockStyle.Fill; form.ResetMenus(); form.AddFileContextEvent("Save", Save); - form.AddFileContextEvent("Replace", Replace); + // form.AddFileContextEvent("Replace", Replace); form.LoadProperties(prop); form.LoadImage(this); @@ -267,6 +267,27 @@ namespace FirstPlugin } } + public void Save(System.IO.Stream stream) + { + using (var writer = new FileWriter(stream, true)) + { + writer.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian; + + writer.Write(ImageData); + + long headerPos = writer.Position; + + image.ImageSize = (uint)ImageData.Length; + + header.Write(writer); + image.Write(writer); + + writer.Seek(headerPos + 0x0C, SeekOrigin.Begin); + writer.Write((uint)writer.BaseStream.Length); + } + } + + private void LoadComponents(TEX_FORMAT Format) { switch (Format) @@ -424,24 +445,6 @@ namespace FirstPlugin { } - public void Save(System.IO.Stream stream) - { - using (var writer = new FileWriter(stream, true)) - { - writer.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; - - writer.Write(ImageData); - - long headerPos = writer.Position; - - header.Write(writer); - image.Write(writer); - writer.Write(ImageData.Length); - - writer.Seek(headerPos + 0x0C, SeekOrigin.Begin); - writer.Write((uint)writer.BaseStream.Length); - } - } public class Header { @@ -465,8 +468,13 @@ namespace FirstPlugin public void Write(FileWriter writer) { - writer.WriteSignature("FLIM"); - writer.Write(ByteOrderMark); + writer.WriteSignature("CLIM"); + + if (writer.ByteOrder == Syroot.BinaryData.ByteOrder.BigEndian) + writer.Write((ushort)0xFFFE); + else + writer.Write((ushort)0xFEFF); + writer.Write(HeaderSize); writer.Write(Version); writer.Write(uint.MaxValue);