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); } }
public void Save(Stream output) { //Update image #region Compiling and saving new image var img = new MemoryStream(); var i0a = new BitmapInfo(image_0).pixelMap(BitmapInfo.Channel.Alpha); var i1a = new BitmapInfo(image_1).pixelMap(BitmapInfo.Channel.Alpha); var i2a = new BitmapInfo(image_2).pixelMap(BitmapInfo.Channel.Alpha); bmp = new Bitmap(bmp.Width, bmp.Height); for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { bmp.SetPixel(x, y, Color.FromArgb(255, i0a[x, y], i1a[x, y], i2a[x, y])); } } xi.Image = bmp; xi.Save(img); xpck.Files[0].FileData = img; #endregion //Compact charSizeInfo var compactCharSizeInfo = new List <CharSizeInfo>(); #region Compacting and updating dictionaries foreach (var info in lstCharSizeInfoLarge) { if (compactCharSizeInfo.Contains(info.Value)) { dicGlyphLarge[info.Key].char_size = (ushort)(compactCharSizeInfo.FindIndex(c => c.Equals(info.Value)) % 1024 + dicGlyphLarge[info.Key].CharWidth * 1024); } else { dicGlyphLarge[info.Key].char_size = (ushort)(compactCharSizeInfo.Count % 1024 + dicGlyphLarge[info.Key].CharWidth * 1024); compactCharSizeInfo.Add(info.Value); } } foreach (var info in lstCharSizeInfoSmall) { if (compactCharSizeInfo.Contains(info.Value)) { dicGlyphSmall[info.Key].char_size = (ushort)(compactCharSizeInfo.FindIndex(c => c.Equals(info.Value)) % 1024 + dicGlyphSmall[info.Key].CharWidth * 1024); } else { dicGlyphSmall[info.Key].char_size = (ushort)(compactCharSizeInfo.Count % 1024 + dicGlyphSmall[info.Key].CharWidth * 1024); compactCharSizeInfo.Add(info.Value); } } #endregion //Writing var ms = new MemoryStream(); using (var bw = new BinaryWriterX(ms, true)) { //Table0 xfheader.table0EntryCount = (short)compactCharSizeInfo.Count; bw.BaseStream.Position = 0x28; bw.WriteMultipleCompressed(compactCharSizeInfo, t0Comp); bw.WriteAlignment(4); //Table1 xfheader.table1Offset = (short)(bw.BaseStream.Position >> 2); xfheader.table1EntryCount = (short)dicGlyphLarge.Count; bw.WriteMultipleCompressed(dicGlyphLarge.Select(d => d.Value), t1Comp); bw.WriteAlignment(4); //Table2 xfheader.table2Offset = (short)(bw.BaseStream.Position >> 2); xfheader.table2EntryCount = (short)dicGlyphSmall.Count; bw.WriteMultipleCompressed(dicGlyphSmall.Select(d => d.Value), t2Comp); bw.WriteAlignment(4); //Header bw.BaseStream.Position = 0; bw.WriteStruct(xfheader); } xpck.Files[1].FileData = ms; xpck.Save(output); }