public void setSize(UInt32 size) { flags = (UInt16)(((size & 0xFF0000) >> 8) | (UInt16)(flags & 0x00FF)); tot_size = (UInt16)(size & 0xFFFF); ByteHelper.WRITE_LE(flags, buf); ByteHelper.WRITE_LE(tot_size, buf, 12); }
public void writeBits(uint value, byte bits) { this.bitbuf |= (uint)((value & ((1 << (bits & 0x1f)) - 1)) << (this.bitpos & 0x1f)); this.bitpos += bits; while (this.bitpos >= 0x10) { ushort num = (ushort)(this.bitbuf & 0xffff); this.bitpos -= 0x10; this.bitbuf = this.bitbuf >> 0x10; ByteHelper.WRITE_LE(num, this.buf, this.pos); this.pos += this.advsize; this.advsize = 2; } }
public override bool import(byte[] file) { XmlDocument doc = xmlFromBytes(file); uint bitbuf = 0; int bitpos = 0; List <byte> txtdata = new List <byte>(); List <UInt16> bs = new List <UInt16>(); List <UInt16> skp = new List <UInt16>(); bs.Add(0); for (int i = 0; i < 32; i++) { skp.Add(0); } if (doc.DocumentElement.Name != "bassru-text" && doc.DocumentElement.Name != "bassru-text-all") { throw new ApplicationException("Bad BassRu Text XML - bad root node name"); } XmlNode blockroot = doc.DocumentElement; if (doc.DocumentElement.Name == "bassru-text-all") { blockroot = findFile(doc.DocumentElement, (int)filenum); } for (int i = 0; i < blockCount; i++) { XmlNode n = findBlock(blockroot, i); int bc = 32; if (i == blockCount - 1) { bc = lastblksz; } for (int N = 0; N < bc; N++) { XmlNode t = findText(n, N); string val = ""; foreach (XmlNode x in t.ChildNodes) { if (x.NodeType == XmlNodeType.Text) { val = x.Value; } } val = fromRuConv(val); appendText(ref bs, ref skp, ref txtdata, ref bitbuf, ref bitpos, i, N, val); } } if (bitpos > 0) { addBits(ref txtdata, ref bitbuf, ref bitpos, 0, 8 - bitpos); } byte[] res = new byte[4 + txtdata.Count + (bs.Count * 2) + skp.Count]; ushort ofs = 4; for (int i = 0; i < blockCount - 1; i++) { ByteHelper.WRITE_LE(bs[i], res, ofs); ofs += 2; } ByteHelper.WRITE_LE(ofs, res); for (int j = 0; j < 32 * blockCount - 32 + lastblksz; j++) { UInt16 r = skp[j]; if (r > 0x7F) { r >>= 3; r |= 0x80; } res[ofs] = (byte)r; ofs++; } ByteHelper.WRITE_LE(ofs, res, 2); Array.Copy(txtdata.ToArray(), 0, res, ofs, txtdata.Count); return(SkyDisk.get().importFile((int)filenum, res)); }