public static TextDecoder get() { if (obj == null) { obj = new TextDecoder(); } return(obj); }
public string convert(string str) { if (txtConf == null) { throw new Exception("no ruchars config"); } string res = ""; for (int i = 0; i < str.Length; i++) { XmlNode found = null; string s = "" + str[i]; if (s == "\\") { s += str[i + 1]; if (s == "\\x") { s += "" + str[i + 2] + "" + str[i + 3]; } i += s.Length - 1; } foreach (XmlNode n in txtConf.ChildNodes) { if (found == null) { if (n.NodeType == XmlNodeType.Element && n.Name == "char") { if ("" + str[i] == n.Attributes["ru"].Value) { found = n; } } } } if (found == null) { char c = TextDecoder.replaceString(s); if (c < ' ' || c > (char)0xA0) { throw new Exception("character not found " + c); } res += c; } else { res += TextDecoder.replaceString(found.Attributes["en"].Value); } } return(res); }
public void addText(string txt, List <byte> txtdata, ref uint bitbuf, ref int bitpos, bool art) { addbit(false, txtdata, ref bitbuf, ref bitpos); addbit(art, txtdata, ref bitbuf, ref bitpos); for (int i = 0; i < txt.Length + 1; i++) { char c = (char)0; if (i < txt.Length) { c = txt[i]; } int len = 0; int code = TextDecoder.get().getCharCode(c, ref len); for (int j = 0; j < len; j++) { bool bit = (code >> (j) & 1) != 0; addbit(bit, txtdata, ref bitbuf, ref bitpos); } } }
string getChar(ref int ofs, ref int bit) { int val = 0; char ch = '\0'; for (int bts = 1; bts <= 18; ++bts) { if (getBit(ref ofs, ref bit)) { val |= 1 << (bts - 1); } if (TextDecoder.get().hasChar(val, bts, ref ch)) { if (ch >= 0xA0 && ch != '%') { return(LureNames.get().getName(ch - 0xa0)); } return(TextDecoder.replaceChar(ch)); } } return(null); }
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 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); } }
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(); }