public void Save(string filename) { var sjis = Encoding.GetEncoding("SJIS"); using (BinaryWriterX bw = new BinaryWriterX(File.Create(filename))) { //Table 0 bw.BaseStream.Position = 0x14; bw.WriteMultipleCompressed(table0, table0Comp); bw.WriteAlignment(4); //Table 1 header.table1Offset = (int)bw.BaseStream.Position >> 2; uint relOffset = 0; var count = 1; foreach (var label in Labels) { if (count == offsets.Count) { var byteCount = (uint)sjis.GetByteCount(label.Text) + 1; foreach (var entry in entries) { if (entry.ident == 0x18 && entry.value == offsets[count]) { entry.value = relOffset + byteCount; } } relOffset += byteCount; count++; } } offsets = entries.Where(e => e.ident == 0x18).Select(e => e.value).Distinct().ToList(); bw.WriteMultipleCompressed(entries, table1Comp); bw.WriteAlignment(4); //Text header.stringTableOffset = (int)bw.BaseStream.Position >> 2; bw.WriteStringsCompressed(Labels.Select(l => l.Text), stringComp, Encoding.GetEncoding("SJIS")); bw.WriteAlignment(4); //Header bw.BaseStream.Position = 0; bw.WriteStruct(header); } }