public void import(XmlDocument doc) { XmlNode blk = null; if (doc.DocumentElement.Name == "lure-strings") { blk = LureCommon.findNode(doc.DocumentElement, "block"); } else if (doc.DocumentElement.Name == "lure-texts") { blk = LureCommon.findNode(LureCommon.findNode(doc.DocumentElement, "file", "id", resnum.ToString()), "block"); } else { throw new Exception("bad strings xml"); } ushort count = BinaryHelper.readU16_LE(data, 0); int curofs = 2; for (int i = 0; i < count; i++) { XmlNode nd = LureCommon.findNode(blk, "text", "id", i.ToString()); string val = ""; if (nd.ChildNodes.Count > 0) { val = LureConfig.get().convert(nd.ChildNodes[0].Value); } data = LureCommon.checkArrLength(data, curofs + val.Length + 1); BinaryHelper.writeZString(data, ref curofs, val); } LureDisks.setResource(resnum, data); }
public LureAnim(int resnum, string pal) { this.resnum = resnum; palette = pal; xdata = Decompressor.decompress(LureDisks.getResource(resnum)); cdata = LureDisks.getResource(resnum + 1); }
public void import(Bitmap bmp) { if (bmp.Width != 61 * 8 || bmp.Height != 16) { throw new Exception("bad font bmp"); } for (int i = 0; i < 122; i++) { for (int j = 0; j < 8; j++) { byte ln = 0; int xofs = i * 8 - (i < 61?0:61 * 8); for (int k = 0; k < 8; k++) { Color cl = bmp.GetPixel(xofs + k, j + (i < 61?0:8)); if (cl.ToArgb() == Color.Black.ToArgb()) { ln |= (byte)(1 << (8 - 1 - k)); } } data[i * 8 + j] = ln; } } LureDisks.setResource(resnum, data); }
public void import(Bitmap bmp) { if (bmp.Width != width || bmp.Height != height) { throw new Exception(String.Format("Wrong bmp size {0}x{1} (need {2}x{3})", bmp.Width, bmp.Height, width, height)); } ColorPalette pal = bmp.Palette; LureConfig.LurePalette xpal = LureConfig.get().getPalette(palette); for (int i = 0; i < 256; i++) { if (pal.Entries[i].ToArgb() != xpal.cols[i].ToArgb()) { throw new Exception("Palette differs"); } } byte[] res = new byte[width * height]; BitmapData bd = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bmp.PixelFormat); for (int i = 0; i < height; i++) { System.Runtime.InteropServices.Marshal.Copy(new IntPtr(bd.Scan0.ToInt64() + i * bd.Stride), res, i * bd.Width, bd.Width); } bmp.UnlockBits(bd); byte[] nr = Compressor.compress(res); LureDisks.setResource(resnum, nr); }
static void test(string[] args) { Console.WriteLine("running test"); int[] imgs = new int[] { 5, 0x18, 0x1A, 0x1C, 0x1E, 0x40, 0x42, 0x44, 0x46, 0x24 }; for (int i = 0; i < imgs.Length; i++) { Console.WriteLine(String.Format("----test compression res {0:D}(0x{0:X})", imgs[i])); byte[] data = LureDisks.getResource(imgs[i]); byte[] real = Decompressor.decompress(data); byte[] udata = Compressor.compress(real); byte[] xdata = Decompressor.decompress(udata); bool eq = true; if (xdata.Length != real.Length) { eq = false; } else { for (int j = 0; j < xdata.Length && eq; j++) { if (xdata[j] != real[j]) { eq = false; } } } Console.WriteLine("decompress test " + (eq?"OK":"FAILED")); Console.WriteLine(String.Format("res {0:d} compress real={1:d} our={2:d}", imgs[i], data.Length, udata.Length)); eq = true; if (data.Length == udata.Length) { for (int j = 0; j < data.Length; j++) { if (data[j] != udata[j]) { eq = false; } } } else { eq = false; } Console.WriteLine("res " + imgs[i].ToString() + " " + (eq?"EQUAL":"not equal")); if (!eq) { FileStream fs = new FileStream("res" + imgs[i].ToString() + "real.bin", FileMode.Create); fs.Write(data, 0, data.Length); fs.Close(); fs = new FileStream("res" + imgs[i].ToString() + "our.bin", FileMode.Create); fs.Write(udata, 0, udata.Length); fs.Close(); fs = new FileStream("res" + imgs[i].ToString() + "unpacked.bin", FileMode.Create); fs.Write(real, 0, real.Length); fs.Close(); } } Console.ReadKey(); }
public static LureDisks getDisks() { if (obj == null) { obj = new LureDisks(); } return(obj); }
public LureImage(int resnum, int w, int h, string pal) { this.resnum = resnum; width = w; height = h; palette = pal; //xdata = LureDisks.getResource(resnum); xdata = Decompressor.decompress(LureDisks.getResource(resnum)); }
public void import(Bitmap bmp) { if (bmp.Width != 320 || bmp.Height % 200 != 0) { throw new Exception(String.Format("Wrong bmp size {0}x{1} (need 320x200n)", bmp.Width, bmp.Height)); } ColorPalette pal = bmp.Palette; LureConfig.LurePalette xpal = LureConfig.get().getPalette(palette); for (int i = 0; i < 256; i++) { if (pal.Entries[i].ToArgb() != xpal.cols[i].ToArgb()) { throw new Exception("Palette differs"); } } byte[] data = new byte[320 * bmp.Height]; BitmapData bd = bmp.LockBits(new Rectangle(0, 0, 320, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); for (int i = 0; i < bmp.Height; i++) { System.Runtime.InteropServices.Marshal.Copy(new IntPtr(bd.Scan0.ToInt64() + i * bd.Stride), data, i * bd.Width, bd.Width); } bmp.UnlockBits(bd); int screens = bmp.Height / 200; byte[] dt2 = new byte[xlen]; byte[] cmd = new byte[0]; int rOfs = xlen; int cOfs = 0; Array.Copy(data, dt2, xlen); for (int i = 1; i < screens; i++) { byte[] pix; byte[] code; compressScreen(data, i, out pix, out code); Array.Resize <byte>(ref dt2, dt2.Length + pix.Length); Array.Copy(pix, 0, dt2, rOfs, pix.Length); rOfs += pix.Length; Array.Resize <byte>(ref cmd, cmd.Length + code.Length); Array.Copy(code, 0, cmd, cOfs, code.Length); cOfs += code.Length; } data = null; byte[] nr = Compressor.compress(dt2); LureDisks.setResource(resnum, nr); LureDisks.setResource(resnum + 1, cmd); }
static void dump(int id) { string of = LureConfig.get().outputFile(id.ToString() + ".bin"); Console.WriteLine("dumping " + id.ToString() + " to " + of); byte[] data = LureDisks.getResource(id); if (LureConfig.get().compress) { data = Decompressor.decompress(data); } LureCommon.dumpFile(data, of); }
static void list(string[] argv) { bool known = false; int dsk = -1; int aid = 1; while (aid < argv.Length) { string s = argv[aid]; aid++; switch (s) { case "known": known = true; break; case "disk": dsk = LureCommon.strToInt(argv[aid]); aid++; break; default: throw new Exception("unknown param " + s); } } Console.WriteLine(" id offset size type"); for (int i = 0; i < 5; i++) { if (dsk == -1 || dsk == i) { Console.WriteLine("-=DISK " + i.ToString() + "=-"); foreach (LureDisk.FileEntry f in LureDisks.get(i).entries) { if (f.id == 0xFFFF) { break; } LureConfig.LureFile lf = LureConfig.get().findFile(f.id); if (!known || lf != null) { Console.WriteLine(string.Format("{0,5:D}{1,12:X8}{2,12:X8}{3,20:s}", f.id, f.realOfs, f.realSize, (lf == null?"":lf.type))); } } } } }
public void import(XmlDocument doc) { if (doc.DocumentElement.Name != "lure-decoder") { throw new Exception("bad decoder xml"); } byte[] dec = new byte[1]; int pos = 0; foreach (XmlNode nd in doc.DocumentElement.ChildNodes) { impNode(nd, ref dec, ref pos); } dec = LureCommon.checkArrLength(dec, pos + 1); dec[pos] = 0xff; pos++; LureDisks.setResource(LureConfig.get().decode_tbl, dec); //readDecoder(); }
public static LureDisks getDisks() { if (obj==null) obj=new LureDisks(); return obj; }
public LureStringList(int id) { resnum = id; data = LureDisks.getResource(id); }
public void import(XmlDocument xml) { XmlNode blkhld = null; if (xml.DocumentElement.Name == "lure-text") { blkhld = xml.DocumentElement; } else if (xml.DocumentElement.Name == "lure-texts") { blkhld = LureCommon.findNode(xml.DocumentElement, "file", "id", resnum.ToString()); } else { throw new Exception("Bad text xml"); } TextDecoder.get().readDecoder(true); XmlDocument prev = export(true); TextDecoder.get().readDecoder(false); uint bitbuf = 0; int bitpos = 0; List <byte> txtdata = new List <byte>(); List <UInt16> bs = new List <UInt16>(); List <byte> skp = new List <byte>(); int prevblk = 0; foreach (XmlNode nd in prev.DocumentElement.ChildNodes) { XmlNode blk = LureCommon.findNode(blkhld, "block", "id", nd.Attributes["id"].Value); int prevtxt = prevblk; foreach (XmlNode tnd in nd.ChildNodes) { //bool art = tnd.Attributes["art"].Value == "1"; XmlNode txt = LureCommon.findNode(blk, "text", "id", tnd.Attributes["id"].Value); string val = ""; if (txt.ChildNodes.Count > 0) { val = txt.ChildNodes[0].Value; } val = LureNames.get().processNames(LureConfig.get().convert(val)); addText(val, txtdata, ref bitbuf, ref bitpos, tnd.Attributes["art"].Value == "1"); if (bitpos % 2 == 1) { addbit(false, txtdata, ref bitbuf, ref bitpos); } // if (tnd != nd.LastChild) { int ofs = (txtdata.Count << 2) + bitpos / 2; int d = ofs - prevtxt; if (d > 0x7F) { while ((d & 7) != 0) { addbit(false, txtdata, ref bitbuf, ref bitpos); ofs = (txtdata.Count << 2) + bitpos / 2; d = ofs - prevtxt; } d = (d >> 3) | 0x80; } skp.Add((byte)d); prevtxt = ofs; } } if (nd != prev.DocumentElement.LastChild) { int offset = (txtdata.Count << 2) + bitpos / 2; bs.Add((UInt16)(offset - prevblk)); prevblk = offset; } } while (bitpos != 0) { addbit(false, txtdata, ref bitbuf, ref bitpos); } data = new byte[4 + bs.Count * 2 + skp.Count + txtdata.Count]; int o = 4; for (int i = 0; i < bs.Count; i++) { BinaryHelper.write_LE(data, o, bs[i]); o += 2; } BinaryHelper.write_LE(data, 0, (UInt16)o); for (int i = 0; i < skp.Count; i++) { data[o++] = skp[i]; } BinaryHelper.write_LE(data, 2, (UInt16)o); for (int i = 0; i < txtdata.Count; i++) { data[o++] = txtdata[i]; } LureDisks.setResource(resnum, data); }
public LureText(int resnum) { this.resnum = resnum; data = LureDisks.getResource(resnum); }
static void import(int id) { if (id == -1) { Console.WriteLine("import all"); int mode = LureConfig.get().textfmt; string ext = ".xml"; if (mode == 1) { ext = ".txt"; } string d = LureConfig.get().direcroty("./"); if (!Directory.Exists(d)) { Directory.CreateDirectory(d); } if (d[d.Length - 1] != '\\' && d[d.Length - 1] != '/') { d += "/"; } foreach (LureConfig.LureFile f in LureConfig.get().lureFiles) { switch (f.type) { case "font": new LureFont(f.id).import(new System.Drawing.Bitmap(d + "lure_font.bmp")); break; case "text_decode_table": TextDecoder.get().import(LureCommon.loadXml(d + "decoder.xml")); break; case "image": int w = LureCommon.strToInt(f.node.Attributes["width"].Value); int h = LureCommon.strToInt(f.node.Attributes["height"].Value); string pal = f.node.Attributes["palette"].Value; string nm = "image" + f.id.ToString(); if (f.node.Attributes["name"] != null) { nm = f.node.Attributes["name"].Value; } new LureImage(f.id, w, h, pal).import(new System.Drawing.Bitmap(d + nm + ".bmp")); break; case "anim": string apal = f.node.Attributes["palette"].Value; string anm = "anim" + f.id.ToString(); if (f.node.Attributes["name"] != null) { anm = f.node.Attributes["name"].Value; } new LureAnim(f.id, apal).import(new System.Drawing.Bitmap(d + anm + ".bmp")); break; } } LureTexts.getAllTexts().load(d + "lure_text" + ext, mode); } else { Console.WriteLine("import " + id.ToString()); importResource(id); } LureDisks.saveAll(); }