void procNode(int code, int len, XmlNode nd, int maxlen) { if (len > maxlen) { return; } XmlNode n = nd.AppendChild(nd.OwnerDocument.CreateElement("node")); string bin = ""; for (int i = 0; i < len; i++) { bin = (((code >> i) & 1) == 1 ? "1" : "0") + bin; } n.Attributes.Append(n.OwnerDocument.CreateAttribute("len")).Value = len.ToString(); n.Attributes.Append(n.OwnerDocument.CreateAttribute("code")).Value = bin; char c = ' '; if (hasChar(LureCommon.revert(code, len), len, ref c)) { n.Attributes.Append(n.OwnerDocument.CreateAttribute("value")).Value = replaceChar(c); return; } procNode(code << 1, len + 1, n, maxlen); procNode((code << 1) | 1, len + 1, n, maxlen); }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Console.WriteLine("vlure v" + VERSION + " by Br. John Fn None"); #if !NO_CATCH try #endif { string[] argv = LureConfig.get().setParams(args); if (LureConfig.get().help || argv.Length == 0 || argv[0] == "help") { usage(); return; } switch (argv[0]) { case "list": list(argv); return; case "dump": dump(LureCommon.strToInt(getarg(argv, 1))); return; case "export": export(getarg(argv, 1) == "all"?-1:LureCommon.strToInt(argv[1])); return; case "import": import(getarg(argv, 1) == "all" ? -1 : LureCommon.strToInt(argv[1])); return; case "img": int w = 0; int h = 0; try { w = LureCommon.strToInt(argv[2]); h = LureCommon.strToInt(argv[3]); }catch {} Application.Run(viewImage(LureCommon.strToInt(argv[1]), w, h)); return; case "test": test(argv); return; default: throw new Exception("unknown command " + argv[0]); } } #if !NO_CATCH catch (Exception ex) { Console.WriteLine("ERROR: " + ex.Message + "\n" + ex.StackTrace); Console.ReadKey(); } #endif }
static Form viewImage(int fileid, int w, int h) { LureConfig.LureFile f = LureConfig.get().findFile(fileid); string pal = ""; string nm = ""; if (f != null) { pal = f.node.Attributes["palette"].Value; if (f.node.Attributes["name"] != null) { nm = f.node.Attributes["name"].Value; } if (w == 0) { w = LureCommon.strToInt(f.node.Attributes["width"].Value); } if (h == 0) { h = LureCommon.strToInt(f.node.Attributes["height"].Value); } } if (w == 0) { w = 320; } if (h == 0) { h = 200; } return(new ImgForm(fileid, w, h, pal, nm)); }
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 void saveImage(int fileid, int w, int h, string pal, string name) { foreach (XmlNode nd in fileConf.ChildNodes) { if (nd.NodeType == XmlNodeType.Element && nd.Name == "file") { if (nd.Attributes["type"].Value == "image" && LureCommon.strToInt(nd.Attributes["id"].Value) == fileid) { nd.ParentNode.RemoveChild(nd); } } } XmlNode fl = fileConf.AppendChild(conf.CreateElement("file")); fl.Attributes.Append(conf.CreateAttribute("id")).Value = fileid.ToString(); fl.Attributes.Append(conf.CreateAttribute("type")).Value = "image"; fl.Attributes.Append(conf.CreateAttribute("width")).Value = w.ToString(); fl.Attributes.Append(conf.CreateAttribute("height")).Value = h.ToString(); fl.Attributes.Append(conf.CreateAttribute("palette")).Value = pal; if (name != "image" + fileid.ToString()) { fl.Attributes.Append(conf.CreateAttribute("name")).Value = name; } conf.Save(cpath + "\\vlure.xml"); }
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); }
public XmlDocument export() { XmlDocument doc = LureCommon.makeXml("lure-decoder"); int maxlen = 0; foreach (Letter l in letters) { if (l.len > maxlen) { maxlen = l.len; } } procNode(0, 1, doc.DocumentElement, maxlen); procNode(1, 1, doc.DocumentElement, maxlen); return(doc); }
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 XmlDocument export() { XmlDocument res = LureCommon.makeXml("lure-strings"); XmlNode blk = res.DocumentElement.AppendChild(res.CreateElement("block")); ushort count = BinaryHelper.readU16_LE(data, 0); int ofs = 2; for (int i = 0; i < count; i++) { string str = BinaryHelper.readZString(data, ofs); ofs += str.Length + 1; XmlNode txt = blk.AppendChild(res.CreateElement("text")); txt.Attributes.Append(res.CreateAttribute("id")).Value = i.ToString(); if (str != "") { txt.AppendChild(res.CreateTextNode(str)); } } return(res); }
public void impNode(XmlNode nd, ref byte[] dec, ref int pos) { if (nd.NodeType != XmlNodeType.Element || nd.Name != "node") { return; } if (nd.Attributes["value"] != null) { char c = replaceString(nd.Attributes["value"].Value); string cd = nd.Attributes["code"].Value; dec = LureCommon.checkArrLength(dec, pos + cd.Length + 2); dec[pos] = (byte)c; pos++; BinaryHelper.writeZString(dec, ref pos, cd); return; } foreach (XmlNode n in nd.ChildNodes) { impNode(n, ref dec, ref pos); } }
public LureFile(XmlNode nd) { id = LureCommon.strToInt(nd.Attributes["id"].Value); type = nd.Attributes["type"].Value; node = nd; }
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(); }
public LureTexts() { texts = LureCommon.makeXml("lure-texts"); }
public static void importResource(int id) { LureConfig.LureFile f = LureConfig.get().findFile(id); if (f == null) { throw new Exception("File not found in config " + id.ToString()); } string infile = ""; switch (f.type) { case "text": case "string_list": case "text_decode_table": infile = LureConfig.get().inputFile(id.ToString() + ".xml"); LureCommon.checkFile(infile); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(infile); if (f.type == "text") { new LureText(f.id).import(doc); } else if (f.type == "text_decode_table") { TextDecoder.get().import(doc); } else { new LureStringList(f.id).import(doc); } break; case "font": infile = LureConfig.get().inputFile(id.ToString() + ".bmp"); LureCommon.checkFile(infile); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(infile); new LureFont(f.id).import(bmp); 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; } infile = LureConfig.get().outputFile(nm + ".bmp"); new LureImage(f.id, w, h, pal).import(new System.Drawing.Bitmap(infile)); break; case "anim": string apal = f.node.Attributes["palette"].Value; string anm = "image" + f.id.ToString(); if (f.node.Attributes["name"] != null) { anm = f.node.Attributes["name"].Value; } infile = LureConfig.get().outputFile(anm + ".bmp"); new LureAnim(f.id, apal).import(new System.Drawing.Bitmap(infile)); break; default: throw new Exception("dont know how to import " + f.type); } }
public static void exportResource(int id) { LureConfig.LureFile f = LureConfig.get().findFile(id); if (f == null) { throw new Exception("File not found in config " + id.ToString()); } string outfile = ""; switch (f.type) { case "text": case "string_list": case "text_decode_table": outfile = LureConfig.get().outputFile(id.ToString() + ".xml"); if (f.type == "text") { new LureText(f.id).export().Save(outfile); } else if (f.type == "text_decode_table") { TextDecoder.get().export().Save(outfile); } else { new LureStringList(f.id).export().Save(outfile); } break; case "font": outfile = LureConfig.get().outputFile(id.ToString() + ".bmp"); new LureFont(f.id).export().Save(outfile, ImageFormat.Bmp); 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; } outfile = LureConfig.get().outputFile(nm + ".bmp"); new LureImage(f.id, w, h, pal).export().Save(outfile, ImageFormat.Bmp); break; case "anim": string apal = f.node.Attributes["palette"].Value; string anm = "image" + f.id.ToString(); if (f.node.Attributes["name"] != null) { anm = f.node.Attributes["name"].Value; } outfile = LureConfig.get().outputFile(anm + ".bmp"); new LureAnim(f.id, apal).export().Save(outfile, ImageFormat.Bmp); break; default: throw new Exception("dont know how to export " + f.type); } }
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 XmlDocument export(bool arts) { XmlDocument res = LureCommon.makeXml("lure-text"); ushort skipTblOfs = BinaryHelper.readU16_LE(data, 0); ushort textData = BinaryHelper.readU16_LE(data, 2); int ofs = 4; int bglob = 0; int blkid = 0; while (ofs <= skipTblOfs) { XmlElement bNode = (XmlElement)res.DocumentElement.AppendChild(res.CreateElement("block")); bNode.Attributes.Append(res.CreateAttribute("id")).Value = blkid.ToString(); int tid = 0; int tofs = skipTblOfs + 32 * blkid; int tglob = 0; while (tid < 32 && tofs < textData) { XmlElement tNode = (XmlElement)bNode.AppendChild(res.CreateElement("text")); tNode.Attributes.Append(res.CreateAttribute("id")).Value = tid.ToString(); int glob = bglob + tglob; int bit = glob & 3; if ((bit & 3) != 0) { bit = 0x80 >> (bit * 2); } else { bit = 0x80; } glob >>= 2; glob += textData; //final pos while (getBit(ref glob, ref bit)) { glob += 2; } //bool b1 = getBit(ref ofs, ref bit); bool art = getBit(ref glob, ref bit); if (arts) { tNode.Attributes.Append(res.CreateAttribute("art")).Value = art?"1":"0"; } readString(tNode, glob, bit); if ((data[tofs] & 0x80) == 0) { tglob += data[tofs]; } else { tglob += (data[tofs] & 0x7f) << 3; } tofs++; tid++; } blkid++; bglob += BinaryHelper.readU16_LE(data, ofs); ofs += 2; } return(res); }