Exemplo n.º 1
0
        public override bool import(string filename)
        {
            byte[] buf = new byte[256 * 3];
            Array.Copy(data, buf, 256 * 3);
            XmlDocument doc = new XmlDocument();

            doc.Load(filename);
            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.º 2
0
        public void saveEngTextFile()
        {
            if (File.Exists(engtxtfile))
            {
                return;
            }
            BinaryWriter br  = new BinaryWriter(new FileStream(engtxtfile, FileMode.CreateNew));
            uint         ofs = 0;

            for (int i = 0; i < 16; i++)
            {
                br.Write(ofs);
            }
            for (int i = 0; i < 8; i++)
            {
                byte[] data = SkyDisk.get().readFile(60600 + i);
                ofs = (uint)br.BaseStream.Position;
                uint sz = (uint)data.Length;
                br.BaseStream.Position = (i * 8);
                br.Write(ofs);
                br.Write(sz);
                br.BaseStream.Position = ofs;
                br.Write(data);
            }
            br.Close();
            reload();
        }
Exemplo n.º 3
0
 public byte[] getData()
 {
     if (xdata == null)
     {
         xdata = SkyDisk.get().readFile((int)fnum);
     }
     return(xdata);
 }
Exemplo n.º 4
0
 public static SkyDisk get()
 {
     if (obj == null)
     {
         obj = new SkyDisk();
     }
     return(obj);
 }
Exemplo n.º 5
0
 public override bool import(string filename)
 {
     byte[] img = BImage.import8bitBitmap(filename, hdr.width,
                                          hdr.height * hdr.n_sprites, Config.get().findPalette(pal), 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
 private void button6_Click(object sender, EventArgs e)
 {
     saveFileDialog1.Filter      = "Sky Disk File (*.dsk)|*.dsk|Sky Dinner File(*.dnr)|*.dnr";
     saveFileDialog1.FilterIndex = 0;
     if (saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
         SkyDisk.get().saveDiskAndDinner(saveFileDialog1.FileName);
     }
 }
Exemplo n.º 7
0
 public BSprites(uint fnum, string pal)
     : base(fnum, ResView.SpritesView.get())
 {
     this.pal = pal;
     byte[] data           = getData();
     SkyDisk.DinnerEntry e = SkyDisk.get().fileInfo((int)fnum, false);
     hdr     = new SkyDisk.FileHeader(data);
     sprdata = new byte[data.Length - SkyDisk.FileHeader.size];
     Array.Copy(data, SkyDisk.FileHeader.size, sprdata, 0, sprdata.Length);
     unused = sprdata.Length - (hdr.width * hdr.height * hdr.n_sprites);
 }
Exemplo n.º 8
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count != 1)
     {
         return;
     }
     saveFileDialog1.Filter      = "Binary file(*.bin)|*.bin|All Files(*.*)|*.*";
     saveFileDialog1.FilterIndex = 0;
     if (saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
         int file = int.Parse(listView1.SelectedItems[0].SubItems[0].Text);
         SkyDisk.get().saveFile(file, false, saveFileDialog1.FileName);
     }
 }
Exemplo n.º 9
0
        public virtual bool import(string filename)
        {
            FileStream fs = new FileStream(filename, FileMode.Open);

            if (fs.Length != getData().Length)
            {
                fs.Close();
                return(false);
            }
            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);
            fs.Close();
            return(SkyDisk.get().importFile((int)filenum, data));
        }
Exemplo n.º 10
0
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBox1.Text = "";
            if (listView1.SelectedItems.Count != 1)
            {
                return;
            }
            uint fnum = uint.Parse(listView1.SelectedItems[0].SubItems[0].Text);

            SkyDisk.FileHeader fh = SkyDisk.get().readHeader(fnum);
            String             s  = String.Format(@"flags=0x{0:X}
x={1:d} (0x{1:X})
y={2:d} (0x{2:X})
width={3:d} (0x{3:X})
height={4:d} (0x{4:X})
sp_size=0x{5:X}
tot_size=0x{6:X}
n_sprites={7:d} (0x{7:X})
offset_x={8:d} (0x{8:X})
offset_y={9:d} (0x{9:X})
compressed_size=0x{10:X}
-------
total_size=0x{11:X}
flags_byte=0x{12:X}
"
                                                  , fh.flags, fh.x, fh.y, fh.width, fh.height, fh.sp_size, fh.tot_size,
                                                  fh.n_sprites, fh.offset_x, fh.offset_y, fh.compressed_size, fh.totalsize, fh.flagbyte
                                                  );

            textBox1.Text = s;
            clearRes();
            Config.FileInfo fi = Config.get().findFile(fnum);
            if (fi.fid != 0)
            {
                BResource res = BResourceHelper.getResource(fi.node);
                if (res.control != null)
                {
                    cntrl = res.control;
                    panel1.Controls.Add(cntrl);
                    res.initControl();
                }
                textBox2.Text = fi.comment;
                label2.Text   = String.Format("{0:d} unused bytes", res.unusedBytes);
            }
        }
Exemplo n.º 11
0
 private void button1_Click(object sender, EventArgs e)
 {
     while (!File.Exists(path + "sky.dsk") || !File.Exists(path + "sky.dnr"))
     {
         openFileDialog1.Filter      = "Sky disk file (*.dsk)|*.dsk";
         openFileDialog1.FilterIndex = 1;
         openFileDialog1.FileName    = "";
         if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
         {
             return;
         }
         path = Path.GetDirectoryName(openFileDialog1.FileName) + "\\";
     }
     SkyDisk.get().path = path;
     SkyDisk.get().readDinner();
     load();
     button2.Enabled = button6.Enabled = button7.Enabled = button8.Enabled = true;
 }
Exemplo n.º 12
0
 public void load()
 {
     listView1.ListViewItemSorter = null;
     listView1.Items.Clear();
     srt.clear();
     foreach (SkyDisk.DinnerEntry e in SkyDisk.get().dinners)
     {
         ListViewItem li = listView1.Items.Add(e.id.ToString());
         li.SubItems.Add(String.Format("{0:X}", e.offset));
         li.SubItems.Add(String.Format("{0:X}", e.size));
         //li.SubItems.Add(String.Format("{0:X}", e.flags));
         li.SubItems.Add(String.Format("{0:s}", e.compressed ? "yes" : "no"));
         li.SubItems.Add(String.Format("{0:s}", e.header ? "yes" : "no"));
         Config.FileInfo fi = Config.get().findFile(e.id);
         li.SubItems.Add(fi.type);
         li.SubItems.Add(fi.comment);
     }
     listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
     listView1.ListViewItemSorter = srt;
 }
Exemplo n.º 13
0
        public override bool import(string filename)
        {
            FileStream fs  = new FileStream(filename, FileMode.Open);
            WavFile    w   = new WavFile();
            bool       res = w.loadFromStream(fs);

            fs.Close();
            if (!res)
            {
                throw new Exception("Bad wave file");
            }
            if (!w.checkFormat(WavFile.getFormat()))
            {
                throw new Exception("Bad wave file format");
            }
            byte[] raw = w.rawBytes();
            raw[0] = 0x81;
            raw[1] = 0;
            return(SkyDisk.get().importFile((int)filenum, raw));
        }
Exemplo n.º 14
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.º 15
0
        private void button8_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter      = "Bass Ru Script (*.xml)|*.xml";
            openFileDialog1.FilterIndex = 0;
            openFileDialog1.Multiselect = false;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(openFileDialog1.FileName);
                    if (doc.DocumentElement.Name != "bassru-script")
                    {
                        throw new ApplicationException("Bad script root node");
                    }
                    int max = 0;
                    foreach (XmlNode nd in doc.DocumentElement.ChildNodes)
                    {
                        if (nd.NodeType == XmlNodeType.Element)
                        {
                            if (nd.Name == "load" || nd.Name == "import" || nd.Name == "export" || nd.Name == "save")
                            {
                                max++;
                            }
                        }
                    }
                    ScriptProgressForm.get().init(max);
                    foreach (XmlNode nd in doc.DocumentElement.ChildNodes)
                    {
                        if (nd.NodeType == XmlNodeType.Element)
                        {
                            string          cd = Directory.GetCurrentDirectory();
                            uint            id = 0;
                            string          fl = "";
                            Config.FileInfo fi;
                            BResource       res = null;
                            switch (nd.Name)
                            {
                            case "load":
                                path = nd.Attributes["path"].Value;
                                if (path[path.Length - 1] != '\\')
                                {
                                    path += "\\";
                                }
                                ScriptProgressForm.get().progress("load from " + path);
                                button1.PerformClick();
                                Directory.SetCurrentDirectory(cd);
                                break;

                            case "import":
                            case "export":
                                id = uint.Parse(nd.Attributes["id"].Value);
                                fl = nd.Attributes["file"].Value;
                                ScriptProgressForm.get().progress(nd.Name + " " + id.ToString() + (nd.Name == "import"?" from ":" to ") + fl);
                                fi = Config.get().findFile(id);
                                if (fi.fid == 0)
                                {
                                    throw new ApplicationException("Unknown file type " + id.ToString());
                                }
                                res = BResourceHelper.getResource(fi.node);
                                if (nd.Name == "import")
                                {
                                    res.import(fl);
                                }
                                else
                                {
                                    res.export(fl);
                                }
                                break;

                            case "save":
                                string pth = nd.Attributes["path"].Value;
                                if (pth[pth.Length - 1] != '\\')
                                {
                                    pth += "\\";
                                }
                                ScriptProgressForm.get().progress("save to " + pth);
                                SkyDisk.get().saveDiskAndDinner(pth + "sky.dsk");
                                Directory.SetCurrentDirectory(cd);
                                break;
                            }
                        }
                    }
                    ScriptProgressForm.get().fini();
                    load();
                }
                catch (Exception ex)
                {
                    ScriptProgressForm.get().fini();
                    MessageBox.Show("Error while script run:" + ex.Message);
                    load();
                    //throw;
                }
            }
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        public override bool import(string filename)
        {
            byte[] xdata = new byte[csdata.Length + 128];
            for (int i = 0; i < xdata.Length; i++)
            {
                xdata[i] = 0;
            }
            for (int i = 0; i < 128; i++)
            {
                xdata[i] = (byte)widths[i];
            }
            Bitmap bmp = new Bitmap(filename);
            Bitmap b2  = makeBitmap(true, Color.Black, Color.White, Color.Red);

            if (bmp.Width != b2.Width || bmp.Height != b2.Height)
            {
                throw new ApplicationException("Bad charset bitmap size");
            }
            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())
                            {
                                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.º 18
0
        public override bool import(string filename)
        {
            Bitmap bmp = new Bitmap(filename);

            if (bmp.Width != 320 || bmp.Height != GAME_SCREEN_HEIGHT * screenCnt)
            {
                throw new ApplicationException("Bad bmp size");
            }
            List <byte> data = new List <byte>();

            data.Add((byte)screenCnt);
            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 < screenCnt; 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.º 19
0
 public override bool import(string filename)
 {
     return(SkyDisk.get().importFile((int)filenum,
                                     import8bitBitmap(filename, w, h, Config.get().findPalette(pal), mode)));
 }
Exemplo n.º 20
0
 public static SkyDisk get()
 {
     if (obj==null) obj=new SkyDisk();
     return obj;
 }