Exemplo n.º 1
0
        public override bool import(byte[] file)
        {
            byte[] xdata = new byte[xlen];
            for (int i = 0; i < xdata.Length; i++)
            {
                xdata[i] = 0;
            }
            for (int i = 0; i < 128; i++)
            {
                xdata[i] = (byte)fwidth;
            }
            Bitmap bmp = new Bitmap(new System.IO.MemoryStream(file));

            for (int i = 0; i < 16; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    int       idx = i * 8 + j;
                    Rectangle rct = new Rectangle(j * 32, i * height, 32, height);
                    byte      wdh = 0;
                    for (int k = 0; k < height; k++)
                    {
                        UInt16 data = 0;
                        UInt16 mask = 0;
                        for (int m = 0; m < 16; m++)
                        {
                            Color dc = bmp.GetPixel(rct.X + m, rct.Y + k);
                            Color mc = bmp.GetPixel(rct.X + 16 + m, rct.Y + k);
                            if (dc.ToArgb() != Color.White.ToArgb())// || mc.ToArgb()!=Color.White.ToArgb())
                            {
                                if (wdh < m + 1)
                                {
                                    wdh = (byte)(m + 1);
                                }
                            }
                            data <<= 1;
                            mask <<= 1;
                            if (dc.ToArgb() != Color.White.ToArgb())
                            {
                                data |= 1;
                            }
                            if (mc.ToArgb() != Color.White.ToArgb())
                            {
                                mask |= 1;
                            }
                        }
                        if (data != 0 || mask != 0)
                        {
                            ByteHelper.WRITE_BE(data, xdata, 128 + idx * height * 4 + (k * 4));
                            ByteHelper.WRITE_BE(mask, xdata, 130 + idx * height * 4 + (k * 4));
                        }
                    }
                    if (wdh != 0)
                    {
                        xdata[idx] = wdh;
                    }
                }
            }
            return(SkyDisk.get().importFile((int)filenum, xdata));
        }
Exemplo n.º 2
0
 public BText(uint fnum, XmlElement ruch)
     : base(fnum)
 {
     hftbl = HuffText.getHuffText();
     byte[] data = SkyDisk.get().readFile((int)fnum);
     ruCharNode = ruch;
     prepare(data);
 }
Exemplo n.º 3
0
 public static SkyDisk get()
 {
     if (obj == null)
     {
         obj = new SkyDisk();
     }
     return(obj);
 }
Exemplo n.º 4
0
 public BCharset(uint fnum, int hgt, int spc)
     : base(fnum)
 {
     height   = hgt;
     this.spc = spc;
     byte[] xdt = SkyDisk.get().readFile((int)filenum);
     fwidth = xdt[0];
     xlen   = xdt.Length;
 }
Exemplo n.º 5
0
 public override bool import(byte[] file)
 {
     byte[] img = BImage.import8bitBitmap(file, hdr.width,
                                          hdr.height * hdr.n_sprites, 0);
     byte[] data = new byte[img.Length + SkyDisk.FileHeader.size];
     Array.Copy(hdr.buf, data, SkyDisk.FileHeader.size);
     Array.Copy(img, 0, data, SkyDisk.FileHeader.size, img.Length);
     return(SkyDisk.get().importFile((int)filenum, data));
 }
Exemplo n.º 6
0
 public override bool import(byte[] file)
 {
     byte[] data = null;
     if (!WavFile.loadFromStream(new MemoryStream(file), ref data))
     {
         throw new Exception("bad wave format");
     }
     data[0] = 0x81;
     data[1] = 0;
     return(SkyDisk.get().importFile((int)filenum, data));
 }
Exemplo n.º 7
0
        public static int[,] getHuffText()
        {
            switch (SkyDisk.get().getVersion())
            {
            case 109: return(_huffTree_00109);

            case 267: return(_huffTree_00267);

            case 228: return(_huffTree_00288);

            case 303: return(_huffTree_00303);

            case 331: return(_huffTree_00331);

            case 348: return(_huffTree_00348);

            case 365: return(_huffTree_00365);

            case 368: return(_huffTree_00368);

            case 372: return(_huffTree_00372);
            }
            throw new ApplicationException("unknown game version");
        }
Exemplo n.º 8
0
        public override bool import(byte[] file)
        {
            byte[]      buf = new byte[256 * 3];
            XmlDocument doc = xmlFromBytes(file);

            if (doc.DocumentElement.Name != "bassru-palette")
            {
                throw new ApplicationException("Bad palette file format");
            }
            foreach (XmlNode nd in doc.DocumentElement.ChildNodes)
            {
                if (nd.NodeType == XmlNodeType.Element && nd.Name == "color")
                {
                    int  id = int.Parse(nd.Attributes["id"].Value);
                    byte c  = byte.Parse(nd.Attributes["r"].Value);
                    buf[id * 3]     = (byte)(((c << 4) & 0x03) | (c >> 2));
                    c               = byte.Parse(nd.Attributes["g"].Value);
                    buf[id * 3 + 1] = (byte)(((c << 4) & 0x03) | (c >> 2));
                    c               = byte.Parse(nd.Attributes["b"].Value);
                    buf[id * 3 + 2] = (byte)(((c << 4) & 0x03) | (c >> 2));
                }
            }
            return(SkyDisk.get().importFile((int)filenum, buf));
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
0
 public static SkyDisk get()
 {
     if (obj==null) obj=new SkyDisk();
     return obj;
 }
Exemplo n.º 11
0
        public void patch()
        {
            SkyDisk.get().InstallPack = install_pack;
            Console.WriteLine("Patching");
            string pth = Path.GetDirectoryName(dskfile) + "\\";

            if (pth == "\\")
            {
                pth = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\";
                if (outfile == dskfile)
                {
                    outfile = pth + outfile;
                }
                dskfile = pth + dskfile;
            }
            SkyDisk.get().path = pth;
            SkyDisk.get().readDinner();
            int resid = -1;

            byte[]     res = null;
            XmlElement r   = null;
            XmlElement c   = null;
            XmlElement p   = null;

            foreach (XmlElement n in patchXml.DocumentElement.ChildNodes)
            {
                if (n.Name == "f")
                {
                    p = n;
                }
                else if (n.Name == "c")
                {
                    c = n;
                }
                else if (n.Name == "r")
                {
                    r = n;
                }
            }
            foreach (XmlElement e in p.ChildNodes)
            {
                int rid = int.Parse(e.Attributes["r"].Value);
                Console.WriteLine(e.Attributes["f"].Value);
                BResource br = BResourceHelper.getResource(e, c);
                if (resid != rid)
                {
                    res = getRes(rid, r);
                }
                resid = rid;
                br.import(res);
            }
            Console.WriteLine("Saving");
            try
            {
                if (dskfile == outfile)
                {
                    File.Copy(SkyDisk.get().path + "sky.dsk", SkyDisk.get().path + "sky.backup.dsk");
                    File.Copy(SkyDisk.get().path + "sky.dnr", SkyDisk.get().path + "sky.backup.dnr");
                }
            }
            catch (Exception)
            {
            }

            SkyDisk.get().saveDiskAndDinner(outfile);
            Console.WriteLine("DONE");
        }
Exemplo n.º 12
0
 public BSprites(uint fnum)
     : base(fnum)
 {
     SkyDisk.DinnerEntry e = SkyDisk.get().fileInfo((int)fnum, false);
     hdr = SkyDisk.get().readHeader(fnum);
 }
Exemplo n.º 13
0
 public virtual bool import(byte[] data)
 {
     return(SkyDisk.get().importFile((int)filenum, data));
 }
Exemplo n.º 14
0
        public override bool import(byte[] file)
        {
            Bitmap bmp = new Bitmap(new System.IO.MemoryStream(file));

            if (bmp.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                throw new ApplicationException("Bad bitmap pixel format");
            }
            if (bmp.Width != 320 || bmp.Height % GAME_SCREEN_HEIGHT != 0)
            {
                throw new ApplicationException("Bad bmp size");
            }
            frames = bmp.Height / GAME_SCREEN_HEIGHT;
            List <byte> data = new List <byte>();

            data.Add((byte)frames);
            ColorPalette p    = bmp.Palette;
            int          ucol = -1;

            for (int i = 255; i >= 0 && ucol == -1; i--)
            {
                if (p.Entries[i].ToArgb() == bgColor.ToArgb())
                {
                    ucol = i;
                }
            }
            if (ucol == -1)
            {
                throw new ApplicationException("Transparent color not found");
            }
            BitmapData bd = bmp.LockBits(new Rectangle(0, 0, 320, bmp.Height),
                                         ImageLockMode.ReadWrite, bmp.PixelFormat);

            for (int i = 0; i < frames; i++)
            {
                bool empty  = true;
                byte cnt    = 0;
                int  cntpos = 0;
                for (int j = 0; j < GAME_SCREEN_HEIGHT; j++)
                {
                    System.Runtime.InteropServices.Marshal.Copy(new IntPtr(bd.Scan0.ToInt64() + (j + i * GAME_SCREEN_HEIGHT) * bd.Stride), pixels, 0, bd.Width);
                    for (int k = 0; k < 320; k++)
                    {
                        byte c = pixels[k];
                        if (empty)
                        {
                            if (c == ucol)
                            {
                                cnt++;
                                if (cnt == 0xFF)
                                {
                                    data.Add(cnt);
                                    cnt = 0;
                                }
                            }
                            else
                            {
                                data.Add(cnt);
                                cnt    = 1;
                                cntpos = data.Count;
                                data.Add(cnt);
                                data.Add(c);
                                empty = false;
                            }
                        }
                        else
                        {
                            if (c != ucol)
                            {
                                cnt++;
                                data.Add(c);
                                if (cnt == 0xFF)
                                {
                                    data[cntpos] = cnt;
                                    cnt          = 0;
                                    cntpos       = data.Count;
                                    data.Add(cnt);
                                }
                            }
                            else
                            {
                                data[cntpos] = cnt;
                                cnt          = 1;
                                empty        = true;
                            }
                        }
                    }
                }
                if (empty)
                {
                    data.Add(cnt);
                    data.Add(0);
                }
                else
                {
                    data[cntpos] = cnt;
                }
            }
            bmp.UnlockBits(bd);
            return(SkyDisk.get().importFile((int)filenum, data.ToArray()));
        }
Exemplo n.º 15
0
 public override bool import(byte[] file)
 {
     return(SkyDisk.get().importFile((int)filenum,
                                     import8bitBitmap(file, w, h, mode)));
 }