diff --git a/File_Format_Library/FileFormats/Layout/BFLYT.cs b/File_Format_Library/FileFormats/Layout/BFLYT.cs index 6495e24e..a8cd9190 100644 --- a/File_Format_Library/FileFormats/Layout/BFLYT.cs +++ b/File_Format_Library/FileFormats/Layout/BFLYT.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Toolbox; using System.Windows.Forms; using Toolbox.Library; +using Toolbox.Library.IO; namespace FirstPlugin { @@ -48,5 +49,94 @@ namespace FirstPlugin { return null; } + + public class Header + { + private const string Magic = "FLYT"; + + private ushort ByteOrderMark; + private ushort HeaderSize; + + public uint Version; + + public void Read(FileReader reader) + { + reader.ReadSignature(4, Magic); + ByteOrderMark = reader.ReadUInt16(); + reader.CheckByteOrderMark(ByteOrderMark); + HeaderSize = reader.ReadUInt16(); + Version = reader.ReadUInt32(); + uint FileSize = reader.ReadUInt32(); + ushort sectionCount = reader.ReadUInt16(); + reader.ReadUInt16(); //Padding + + reader.SeekBegin(HeaderSize); + for (int i = 0; i < sectionCount; i++) + { + long pos = reader.Position; + + string Signature = reader.ReadString(4, Encoding.ASCII); + uint SectionSize = reader.ReadUInt32(); + + SectionCommon section = new SectionCommon(); + + switch (Signature) + { + //If the section is not supported store the raw bytes + default: + section.Data = reader.ReadBytes((int)SectionSize); + break; + } + + section.Signature = Signature; + section.SectionSize = SectionSize; + + reader.SeekBegin(pos + SectionSize + 0x10); + reader.Align(16); + } + } + + public void Write(FileWriter writer) + { + writer.WriteSignature(Magic); + writer.Write(ByteOrderMark); + writer.Write(HeaderSize); + writer.Write(Version); + writer.Write(uint.MaxValue); //Reserve space for file size later + writer.Write(ushort.MaxValue); //Reserve space for section count later + writer.Seek(2); //padding + + + + + //Write the total file size + using (writer.TemporarySeek(0x0C, System.IO.SeekOrigin.Begin)) + { + writer.Write((uint)writer.BaseStream.Length); + } + } + } + + public class LYT1 : SectionCommon + { + } + + public class SectionCommon + { + internal string Signature { get; set; } + internal uint SectionSize { get; set; } + + internal byte[] Data { get; set; } + + public void Write(FileWriter writer) + { + writer.WriteSignature(Signature); + if (Data != null) + { + writer.Write(Data.Length); + writer.Write(Data); + } + } + } } } diff --git a/Switch_Toolbox_Library/Toolbox.Library.dll b/Switch_Toolbox_Library/Toolbox.Library.dll index 312bf4b7..8615c74d 100644 Binary files a/Switch_Toolbox_Library/Toolbox.Library.dll and b/Switch_Toolbox_Library/Toolbox.Library.dll differ diff --git a/Switch_Toolbox_Library/Toolbox.Library.pdb b/Switch_Toolbox_Library/Toolbox.Library.pdb index 43f1dc36..20468697 100644 Binary files a/Switch_Toolbox_Library/Toolbox.Library.pdb and b/Switch_Toolbox_Library/Toolbox.Library.pdb differ