public void Save(Stream output, ImageInfo image) { using var bw = new BinaryWriterX(output, _header.byteOrder); // Calculate offsets var nw4cOffset = ((image.ImageData.Length + 0xF) & ~0xF); var headerOffset = nw4cOffset + Nw4CHeaderSize; // Write image data output.Write(image.ImageData); // Write NW4C header _header.fileSize = headerOffset + 0x8 + (_bclimHeader == null ? BflimHeaderSize : BclimHeaderSize); output.Position = nw4cOffset; bw.WriteType(_header); // Write img header if (_bclimHeader != null) { _bclimHeader.format = (byte)image.ImageFormat; _bclimHeader.dataSize = image.ImageData.Length; _bclimHeader.width = (short)image.ImageSize.Width; _bclimHeader.height = (short)image.ImageSize.Height; var section = new NW4CSection <BclimHeader> { magic = "imag", sectionSize = 0x4 + BclimHeaderSize, sectionData = _bclimHeader }; output.Position = headerOffset; bw.WriteType(section); } else { _bflimHeader.format = (byte)image.ImageFormat; _bflimHeader.dataSize = image.ImageData.Length; _bflimHeader.width = (short)image.ImageSize.Width; _bflimHeader.height = (short)image.ImageSize.Height; var section = new NW4CSection <BclimHeader> { magic = "imag", sectionSize = 0x4 + BclimHeaderSize, sectionData = _bclimHeader }; output.Position = headerOffset; bw.WriteType(section); } }
public BCLYT(Stream input) { using (var sr = new BinaryReaderX(input)) { sections = sr.ReadSections(); NW4CSection last = null; List <string> fnl = null; foreach (var sec in sections) { using (var br = new BinaryReaderX(new MemoryStream(sec.Data))) { switch (sec.Magic) { case "lyt1": sec.Object = br.ReadStruct <Layout>(); break; case "txl1": case "fnl1": int txlCount = br.ReadInt32(); br.ReadMultiple(txlCount, _ => br.ReadInt32()); sec.Object = br.ReadMultiple(txlCount, _ => br.ReadCStringA()); break; case "mat1": // incomplete break; case "pic1": // incomplete case "pan1": // incomplete case "wnd1": // incomplete case "bnd1": // incomplete var pane = br.ReadStruct <Pane>(); sec.Object = pane; //if (sec.Magic == "pic1") //Debug.WriteLine($"<{sec.Magic} name='{pane.name}' size='{pane.size.x},{pane.size.y}'>"); break; case "txt1": var txtPane = br.ReadStruct <Pane>(); var txtBox = br.ReadStruct <TextBox>(); var str = ""; if (txtBox.string_length != 0) { str = br.ReadCStringW(); } //sec.Object = new { txtPane, txtBox, str }; sec.Object = Tuple.Create(txtPane, txtBox, str); break; case "pts1": case "pas1": case "pae1": case "grs1": case "gre1": break; case "grp1": // incomplete break; case "usd1": if (last != null && last.Magic == "txt1") { var x = string.Concat(sec.Data.Skip(16).Select(b => (char)b)).TrimEnd('\0').Replace("\0", "|"); var t = ((Tuple <Pane, TextBox, string>)last.Object); //if (t.Item3 != "") throw new Exception(); last.Object = Tuple.Create(t.Item1, t.Item2, x); } // incomplete break; default: throw new NotSupportedException($"Unknown magic {sec.Magic}"); } } last = sec; } var txts = sections.Where(z => z.Magic == "txt1").Select(z => z.Object).ToList(); } }