public string processNames(string s) { string res = s; int cnt = BinaryHelper.readU16_LE(data, 0) / 2; for (int i = 1; i < cnt; i++) { int strt = BinaryHelper.readU16_LE(data, i * 2); string nm = BinaryHelper.readZString(data, strt); char code = (char)(i + 0xA0); res.Replace(nm, "" + code); } return(res); }
public void readEntries() { if (BinaryHelper.readString(diskData, 0, 6) != "heywow") { throw new Exception("Bad file header format " + file); } if (BinaryHelper.readU16_BE(diskData, 6) != dskid) { throw new Exception("Bad file id format " + file); } for (int i = 0; i < 191; i++) { entries[i] = new FileEntry(diskData, 8 + i * 8); } }
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 byte[] runVGA(byte[] data) { xdata = data; d1 = BinaryHelper.readU32_LE(data, 0x400); byte al = dssi(); r.Add(al); Int16 bp = (Int16)(al << 2); while (true) { int l = 0; bool nbp = true; if (nextBt()) { if (nextBt()) { if (nextBt()) { al = dssi(); r.Add(al); bp = (Int16)(al << 2); nbp = false; } else { l = 3; } } else if (nextBt()) { l = 2; } else { l = 1; } } else if (nextBt()) { al = (byte)(bp >> 2); byte ah = dssi(); if (ah == 0) { al = dssi(); if (al == 0) { return(r.ToArray()); } } else { setBytes(al, ah); } nbp = false; } if (nbp) { al = xdata[bp + l]; r.Add(al); bp = (Int16)(al << 2); } } }
public void saveDisk() { if (!File.Exists(file + ".bak")) { File.Copy(file, file + ".bak", false); } for (int i = 0; i < 191; i++) { entries[i].save(diskData, 8 + 8 * i); } byte[] data = diskData; if (dskid == 0) { FileStream f = new FileStream(file, FileMode.Open); byte[] oldd = new byte[f.Length]; f.Read(oldd, 0, oldd.Length); f.Close(); int[] mods = new int[100]; int[] ofs = new int[100]; int cnt = 0; int b = 6; int cofs = 0; int nextofs = 0; while (oldd[b] != 0xFF) { mods[cnt] = oldd[b]; ofs[cnt] = (int)BinaryHelper.readU32_LE(oldd, b + 1); if (mods[cnt] == LANG_ID) { cofs = ofs[cnt]; } cnt++; b += 5; } int delta = 0; for (int i = 0; i < cnt; i++) { if (cofs < ofs[i] && cofs + data.Length > ofs[i]) { nextofs = ofs[i]; delta = cofs + data.Length - ofs[i]; } } if (delta != 0) { while (delta % 16 != 0) { delta++; } byte[] newd = new byte[oldd.Length + delta]; Array.Copy(oldd, newd, cofs); Array.Copy(oldd, nextofs, newd, nextofs + delta, oldd.Length - nextofs); for (int i = 0; i < cnt; i++) { if (ofs[i] > cofs) { ofs[i] += delta; BinaryHelper.write_LE(newd, 6 + i * 5 + 1, (uint)ofs[i]); } } oldd = newd; } Array.Copy(data, 0, oldd, cofs, data.Length); data = oldd; } FileStream fs = new FileStream(file, FileMode.Create); fs.Write(data, 0, data.Length); fs.Close(); }
public LureDisk(int id, string paths) { string file2 = ""; dskid = id; string[] pts = paths.Split(';'); file = "lure.dat"; if (id > 0) { file = "disk" + id.ToString() + ".vga"; file2 = "Disk" + id.ToString() + ".vga"; } if (!File.Exists(file)) { if (File.Exists(file2)) { file = file2; } else { foreach (string p in pts) { string s = p; if (s[s.Length - 1] != '/') { s += "/"; } if (File.Exists(s + file)) { file = s + file; break; } if (File.Exists(s + file2)) { file = s + file2; break; } } } } if (!File.Exists(file)) { throw new Exception("Disk not found " + file); } string xfile = file; if (File.Exists(xfile + ".bak")) { xfile += ".bak"; } FileStream fs = new FileStream(xfile, FileMode.Open); diskData = new byte[fs.Length]; fs.Read(diskData, 0, diskData.Length); fs.Close(); if (id == 0) { if (BinaryHelper.readString(diskData, 0, 4) != "lure") { throw new Exception("bad lure.dat"); } int b = 6; while (diskData[b] != LureConfig.get().lang_id) { b += 5; if (diskData[b] == 0xff) { throw new Exception("lure.dat language " + LureConfig.get().lang_id.ToString() + " not found"); } } int dofs = (int)BinaryHelper.readU32_LE(diskData, b + 1); b = 6; int dsz = int.MaxValue; while (diskData[b] != 0xFF) { int sofs = (int)BinaryHelper.readU32_LE(diskData, b + 1); b += 5; if (sofs > dofs) { if (sofs - dofs < dsz) { dsz = sofs - dofs; } } } byte[] newdisk = new byte[dsz]; Array.Copy(diskData, dofs, newdisk, 0, dsz); diskData = newdisk; } readEntries(); }
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); }
public string getName(int index) { int nmStart = BinaryHelper.readU16_LE(data, index * 2); return(BinaryHelper.readZString(data, nmStart)); }