From 18a64c528ba2a8af45c30c02c4f76fd1164bff4f Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Sun, 1 Sep 2019 20:41:04 -0400 Subject: [PATCH] Perfectly save bflyt files with parts --- .../FileFormats/Layout/CAFE/BFLYT.cs | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs index 4f732666..86867d49 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs @@ -1048,20 +1048,24 @@ namespace LayoutBXLYT.Cafe public List Properties = new List(); + private string PropertyName; + public PRT1(FileReader reader, Header header) : base(reader) { - StartPosition = reader.Position - 8; + StartPosition = reader.Position - 84; uint properyCount = reader.ReadUInt32(); MagnifyX = reader.ReadSingle(); MagnifyY = reader.ReadSingle(); for (int i = 0; i < properyCount; i++) - Properties.Add(new PartProperty(reader, header, this)); + Properties.Add(new PartProperty(reader, header, StartPosition)); + + PropertyName = reader.ReadZeroTerminatedString(); } public override void Write(FileWriter writer, BxlytHeader header) { - long startPos = writer.Position; + long startPos = writer.Position - 8; base.Write(writer, header); writer.Write(Properties.Count); writer.Write(MagnifyX); @@ -1069,6 +1073,12 @@ namespace LayoutBXLYT.Cafe for (int i = 0; i < Properties.Count; i++) Properties[i].Write(writer, header, startPos); + + writer.WriteString(PropertyName); + writer.Align(4); + + for (int i = 0; i < Properties.Count; i++) + Properties[i].WriteProperties(writer, header, startPos); } } @@ -1082,7 +1092,7 @@ namespace LayoutBXLYT.Cafe public BasePane Property { get; set; } - public PartProperty(FileReader reader, Header header, PRT1 prt1) + public PartProperty(FileReader reader, Header header, long StartPosition) { Name = reader.ReadString(0x18).Replace("\0", string.Empty); UsageFlag = reader.ReadByte(); @@ -1097,12 +1107,14 @@ namespace LayoutBXLYT.Cafe if (propertyOffset != 0) { - reader.SeekBegin(prt1.StartPosition + propertyOffset); + reader.SeekBegin(StartPosition + propertyOffset); long startPos = reader.Position; string signtature = reader.ReadString(4, Encoding.ASCII); uint sectionSize = reader.ReadUInt32(); + Console.WriteLine($"signtature " + signtature); + switch (signtature) { case "pic1": @@ -1120,22 +1132,26 @@ namespace LayoutBXLYT.Cafe case "prt1": Property = new PRT1(reader, header); break; + default: + Console.WriteLine("Unknown section! " + signtature); + break; } } if (userDataOffset != 0) { - reader.SeekBegin(prt1.StartPosition + userDataOffset); + reader.SeekBegin(StartPosition + userDataOffset); } if (panelInfoOffset != 0) { - reader.SeekBegin(prt1.StartPosition + panelInfoOffset); + reader.SeekBegin(StartPosition + panelInfoOffset); } reader.SeekBegin(pos); } + private long _ofsPos; public void Write(FileWriter writer, BxlytHeader header, long startPos) { writer.WriteString(Name, 0x18); @@ -1144,14 +1160,17 @@ namespace LayoutBXLYT.Cafe writer.Write(MaterialUsageFlag); writer.Write((byte)0); //Reserve offset spaces - long _ofsPos = writer.Position; + _ofsPos = writer.Position; writer.Write(0); //Property Offset writer.Write(0); //External User Data writer.Write(0); //Panel Info Offset + } + public void WriteProperties(FileWriter writer, BxlytHeader header, long startPos) + { if (Property != null) { - writer.WriteUint32Offset(_ofsPos); + writer.WriteUint32Offset(_ofsPos, startPos); Header.WriteSection(writer, Property.Signature, Property, () => Property.Write(writer, header)); } }