예제 #1
0
 private void normalizeBuf(byte bits)
 {
     while (bits > this.bitpos)
     {
         ushort num = 0;
         if ((this.pos + 1) == this.buf.Length)
         {
             num = this.buf[this.buf.Length - 1];
         }
         else if (this.pos < this.buf.Length)
         {
             num = ByteHelper.READ_UINT16_LE(this.buf, this.pos);
         }
         this.pos    += 2;
         this.bitbuf |= (uint)(num << this.bitpos);
         this.bitpos += 0x10;
     }
 }
예제 #2
0
            public void write(BinaryWriter wr, int version)
            {
                wr.Write(id);
                byte[] bts = new byte[3];
                uint   ofs = offset;

                if (ofs > 0x7FFFFF)
                {
                    if (version == 331)
                    {
                        ofs = 0x800000 | ofs >> 3;
                    }
                    else
                    {
                        ofs = 0x800000 | ofs >> 4;
                    }
                }
                ByteHelper.WRITE24_LE(ofs, bts);
                wr.Write(bts);
                ByteHelper.WRITE24_LE(size, bts);
                bts[2] |= flags;
                wr.Write(bts);
            }
예제 #3
0
        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));
        }