private void ReadATO1(BinaryReaderX br) { ATO1.Identifier = br.ReadString(4); ATO1.SectionSize = br.ReadUInt32(); ATO1.Padding1 = br.ReadBytes(8); ATO1.Unknown2 = br.ReadBytes((int)ATO1.SectionSize); // Read in the entire section at once since we don't know what it's for }
private void ReadATR1(BinaryReaderX br) { ATR1.Identifier = br.ReadString(4); ATR1.SectionSize = br.ReadUInt32(); ATR1.Padding1 = br.ReadBytes(8); ATR1.NumberOfAttributes = br.ReadUInt32(); ATR1.Unknown2 = br.ReadBytes((int)ATR1.SectionSize - sizeof(UInt32)); // Read in the entire section at once since we don't know what it's for PaddingSeek(br); }
private void ReadTXT2(BinaryReaderX br) { TXT2.Identifier = br.ReadString(4); TXT2.SectionSize = br.ReadUInt32(); TXT2.Padding1 = br.ReadBytes(8); long startOfStrings = br.BaseStream.Position; TXT2.NumberOfStrings = br.ReadUInt32(); List <UInt32> offsets = new List <UInt32>(); for (int i = 0; i < TXT2.NumberOfStrings; i++) { offsets.Add(br.ReadUInt32()); } for (int i = 0; i < TXT2.NumberOfStrings; i++) { String str = new String(); UInt32 nextOffset = (i + 1 < offsets.Count) ? ((UInt32)startOfStrings + offsets[i + 1]) : ((UInt32)startOfStrings + TXT2.SectionSize); br.BaseStream.Seek(startOfStrings + offsets[i], SeekOrigin.Begin); List <byte> result = new List <byte>(); while (br.BaseStream.Position < nextOffset && br.BaseStream.Position < Header.FileSize) { if (Header.EncodingByte == EncodingByte.UTF8) { result.Add(br.ReadByte()); } else { byte[] unichar = br.ReadBytes(2); if (br.ByteOrder == ByteOrder.BigEndian) { Array.Reverse(unichar); } result.AddRange(unichar); } } str.Value = result.ToArray(); str.Index = (uint)i; TXT2.OriginalStrings.Add(str); // Duplicate entries for editing String estr = new String(); estr.Value = str.Value; estr.Index = str.Index; TXT2.Strings.Add(estr); } // Tie in LBL1 labels foreach (Label lbl in LBL1.Labels) { lbl.String = TXT2.Strings[(int)lbl.Index]; } PaddingSeek(br); }
public MSBT(string filename = "null") { if (filename != "null") { File = new FileInfo(filename); if (File.Exists && filename.Length > 0) { FileStream fs = System.IO.File.Open(File.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReaderX br = new BinaryReaderX(fs); // Initialize Members LBL1.Groups = new List <Group>(); LBL1.Labels = new List <IEntry>(); TXT2.Strings = new List <IEntry>(); TXT2.OriginalStrings = new List <IEntry>(); // Header Header.Identifier = br.ReadString(8); if (Header.Identifier != "MsgStdBn") { throw new InvalidMSBTException("The file provided is not a valid MSBT file."); } // Byte Order Header.ByteOrderMark = br.ReadBytes(2); br.ByteOrder = Header.ByteOrderMark[0] > Header.ByteOrderMark[1] ? ByteOrder.LittleEndian : ByteOrder.BigEndian; Header.Unknown1 = br.ReadUInt16(); // Encoding Header.EncodingByte = (EncodingByte)br.ReadByte(); FileEncoding = (Header.EncodingByte == EncodingByte.UTF8 ? Encoding.UTF8 : Encoding.Unicode); Header.Unknown2 = br.ReadByte(); Header.NumberOfSections = br.ReadUInt16(); Header.Unknown3 = br.ReadUInt16(); Header.FileSizeOffset = (UInt32)br.BaseStream.Position; // Record offset for future use Header.FileSize = br.ReadUInt32(); Header.Unknown4 = br.ReadBytes(10); if (Header.FileSize != br.BaseStream.Length) { throw new InvalidMSBTException("The file provided is not a valid MSBT file."); } SectionOrder.Clear(); for (int i = 0; i < Header.NumberOfSections; i++) { switch (br.PeekString()) { case "LBL1": ReadLBL1(br); SectionOrder.Add("LBL1"); break; case "NLI1": ReadNLI1(br); SectionOrder.Add("NLI1"); break; case "ATO1": ReadATO1(br); SectionOrder.Add("ATO1"); break; case "ATR1": ReadATR1(br); SectionOrder.Add("ATR1"); break; case "TSY1": ReadTSY1(br); SectionOrder.Add("TSY1"); break; case "TXT2": ReadTXT2(br); SectionOrder.Add("TXT2"); break; } } br.Close(); } } else { // Initialize Members LBL1.Groups = new List <Group>(); LBL1.Labels = new List <IEntry>(); TXT2.Strings = new List <IEntry>(); TXT2.OriginalStrings = new List <IEntry>(); } }