private bool WriteTXT2(BinaryWriterX bw) { bool result = false; try { // Calculate Section Size UInt32 newSize = (UInt32)(TXT2.NumberOfStrings * sizeof(UInt32) + sizeof(UInt32)); for (int i = 0; i < TXT2.NumberOfStrings; i++) { newSize += (UInt32)((String)TXT2.Strings[i]).Value.Length; } bw.WriteASCII(TXT2.Identifier); bw.Write(newSize); bw.Write(TXT2.Padding1); long startOfStrings = bw.BaseStream.Position; bw.Write(TXT2.NumberOfStrings); List <UInt32> offsets = new List <UInt32>(); UInt32 offsetsLength = TXT2.NumberOfStrings * sizeof(UInt32) + sizeof(UInt32); UInt32 runningTotal = 0; for (int i = 0; i < TXT2.NumberOfStrings; i++) { offsets.Add(offsetsLength + runningTotal); runningTotal += (UInt32)((String)TXT2.Strings[i]).Value.Length; } for (int i = 0; i < TXT2.NumberOfStrings; i++) { bw.Write(offsets[i]); } for (int i = 0; i < TXT2.NumberOfStrings; i++) { for (int j = 0; j < TXT2.Strings.Count; j++) { TXT2.OriginalStrings[i] = TXT2.Strings[i]; } if (Header.EncodingByte == EncodingByte.UTF8) { bw.Write(((String)TXT2.Strings[i]).Value); } else { if (Header.ByteOrderMark[0] == 0xFF) { bw.Write(((String)TXT2.Strings[i]).Value); } else { for (int j = 0; j < ((String)TXT2.Strings[i]).Value.Length; j += 2) { bw.Write(((String)TXT2.Strings[i]).Value[j + 1]); bw.Write(((String)TXT2.Strings[i]).Value[j]); } } } } PaddingWrite(bw); result = true; } catch (Exception) { result = false; } return(result); }
private bool WriteLBL1(BinaryWriterX bw) { bool result = false; try { // Calculate Section Size UInt32 newSize = sizeof(UInt32); foreach (Group grp in LBL1.Groups) { newSize += (UInt32)(sizeof(UInt32) + sizeof(UInt32)); } foreach (Label lbl in LBL1.Labels) { newSize += (UInt32)(sizeof(byte) + lbl.Name.Length + sizeof(UInt32)); } // Calculate Group Offsets UInt32 offsetsLength = LBL1.NumberOfGroups * sizeof(UInt32) * 2 + sizeof(UInt32); UInt32 runningTotal = 0; for (int i = 0; i < LBL1.Groups.Count; i++) { LBL1.Groups[i].Offset = offsetsLength + runningTotal; foreach (Label lbl in LBL1.Labels) { if (lbl.Checksum == i) { runningTotal += (UInt32)(sizeof(byte) + lbl.Name.Length + sizeof(UInt32)); } } } bw.WriteASCII(LBL1.Identifier); bw.Write(newSize); bw.Write(LBL1.Padding1); bw.Write(LBL1.NumberOfGroups); foreach (Group grp in LBL1.Groups) { bw.Write(grp.NumberOfLabels); bw.Write(grp.Offset); } foreach (Group grp in LBL1.Groups) { foreach (Label lbl in LBL1.Labels) { if (lbl.Checksum == LBL1.Groups.IndexOf(grp)) { bw.Write(Convert.ToByte(lbl.Length)); bw.WriteASCII(lbl.Name); bw.Write(lbl.Index); } } } PaddingWrite(bw); result = true; } catch (Exception) { result = false; } return(result); }