コード例 #1
0
ファイル: SkyDisk.cs プロジェクト: winterheart/game-utilities
 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);
 }
コード例 #2
0
ファイル: Text.cs プロジェクト: winterheart/game-utilities
        public override bool import(string filename)
        {
            XmlDocument   doc     = new XmlDocument();
            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);
            }
            doc.Load(filename);
            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  cmt = "", md = "";
                    if (t.Attributes["comment"] != null)
                    {
                        cmt = t.Attributes["comment"].Value;
                    }
                    if (t.Attributes["mode"] != null)
                    {
                        md = t.Attributes["mode"].Value;
                    }
                    if (cmt != "" || md != "")
                    {
                        string cm   = "";
                        bool   isru = Config.get().isTextRu(filenum, i, N, ref cm);
                        if (cm != cmt || (isru && md == "en") || (!isru && md == "ru"))
                        {
                            if (md == "ru")
                            {
                                isru = true;
                            }
                            if (md == "en")
                            {
                                isru = false;
                            }
                            Config.get().setTextInfo(filenum, (uint)i, (uint)N, isru, cmt);
                        }
                    }
                    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));
        }