Beispiel #1
0
        private void deleteBundleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode t = treeView1.SelectedNode;

            if (t == null || t.Parent == null || t.Parent.Text != "bundles")
            {
                return;
            }
            int n = t.Index;

            toc.bundles.RemoveAt(n);
            BJSON.Entry        root    = toc.lines[0];
            BJSON.Field        bundles = root.fields[0];
            List <BJSON.Entry> list    = (List <BJSON.Entry>)bundles.data;

            list.RemoveAt(n);
            bundles.data = list;
            RefreshTree();
        }
Beispiel #2
0
 public void SaveFile(string path)
 {
     for (int i = 0; i < initfs.lines.Count; i++)
     {
         BJSON.Entry e = initfs.lines[i];
         if (e.fields != null && e.fields.Count != 0)
         {
             BJSON.Field        file = e.fields[0];
             List <BJSON.Field> data = (List <BJSON.Field>)file.data;
             foreach (BJSON.Field f in data)
             {
                 if (f.fieldname == "payload")
                 {
                     f.data = list[i].data;
                 }
             }
         }
         initfs.lines[i] = e;
     }
     initfs.Save(path);
     RefreshList();
 }
 private bool PrepareBJSON()
 {
     rtb2.AppendText("Preparing BJSON...\n");
     try
     {
         BJSON.Entry        root    = toc.lines[0];
         BJSON.Field        bundles = root.FindField("bundles");
         BJSON.Field        tbun    = bundles;
         List <BJSON.Entry> list    = new List <BJSON.Entry>();
         list.AddRange((List <BJSON.Entry>)bundles.data);
         tbun.data = new List <BJSON.Entry>();
         int countcopy = 0;
         for (int i = 0; i < list.Count; i++)
         {
             if (!SelectForDeletion[i])
             {
                 ((List <BJSON.Entry>)tbun.data).Add(list[i]);
                 countcopy++;
             }
             else
             {
                 SelectForReplacement.RemoveAt(i);
                 SelectForDuplication.RemoveAt(i);
                 SelectForDeletion.RemoveAt(i);
                 list.RemoveAt(i);
                 i--;
             }
         }
         rtb2.AppendText("Copied: " + countcopy + " / " + list.Count + "\n");
         root.fields[root.FindFieldIndex("bundles")] = tbun;
     }
     catch (Exception ex)
     {
         rtb2.AppendText("ERROR: " + ex.Message);
         return(false);
     }
     return(true);
 }
Beispiel #4
0
        private void keepOnlyThisBundleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode t = treeView1.SelectedNode;

            if (t == null || t.Parent == null || t.Parent.Text != "bundles")
            {
                return;
            }
            int n = t.Index;

            TOCFile.TOCBundleInfoStruct bunInfo = toc.bundles[n];
            toc.bundles.Clear();
            toc.bundles.Add(bunInfo);
            BJSON.Entry        root    = toc.lines[0];
            BJSON.Field        bundles = root.fields[0];
            List <BJSON.Entry> list    = (List <BJSON.Entry>)bundles.data;

            BJSON.Entry entry = list[n];
            list.Clear();
            list.Add(entry);
            bundles.data = list;
            RefreshTree();
        }
Beispiel #5
0
        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            TreeNode t = treeView1.SelectedNode;

            if (t == null || (t.Nodes != null && t.Nodes.Count != 0))
            {
                return;
            }
            List <int> Indices = GetIndices(t);

            BJSON.Entry entry = sb.lines[Indices[0]];
            BJSON.Field field = null;
            byte        swap  = 0;

            for (int i = 1; i < Indices.Count - 1; i++)
            {
                if (i % 2 == swap)
                {
                    if (field.data is List <BJSON.Entry> )
                    {
                        List <BJSON.Entry> list = (List <BJSON.Entry>)field.data;
                        entry = list[Indices[i]];
                    }
                    if (field.data is List <BJSON.Field> )
                    {
                        List <BJSON.Field> list = (List <BJSON.Field>)field.data;
                        field = list[Indices[i]];
                        if (swap == 0)
                        {
                            swap = 1;
                        }
                        else
                        {
                            swap = 0;
                        }
                    }
                }
                else
                {
                    field = entry.fields[Indices[i]];
                }
            }
            if (field != null)
            {
                TOCTool_InputForm input = new TOCTool_InputForm();
                switch (field.type)
                {
                case 1:
                    return;

                case 7:
                    input.hb1.Enabled = false;
                    input.rtb1.Text   = (string)field.data;
                    break;

                case 6:
                    byte[] tmp = new byte[1];
                    if ((bool)field.data)
                    {
                        tmp[0] = 1;
                    }
                    input.hb1.ByteProvider = new FixedByteProvider(tmp);
                    input.rtb1.Enabled     = false;
                    break;

                default:
                    if (field.data is byte[])
                    {
                        input.hb1.ByteProvider = new DynamicByteProvider((byte[])field.data);
                        input.rtb1.Enabled     = false;
                    }
                    break;
                }
                DialogResult res = input.ShowDialog();
                MemoryStream m;
                if (res == System.Windows.Forms.DialogResult.OK)
                {
                    switch (field.type)
                    {
                    case 7:
                        field.data = input.rtb1.Text;
                        break;

                    case 6:
                        m = new MemoryStream();
                        for (long i = 0; i < input.hb1.ByteProvider.Length; i++)
                        {
                            m.WriteByte(input.hb1.ByteProvider.ReadByte(i));
                        }
                        if (m.Length == 1)
                        {
                            m.Seek(0, 0);
                            if ((byte)m.ReadByte() == 0)
                            {
                                field.data = false;
                            }
                            else
                            {
                                field.data = true;
                            }
                        }
                        break;

                    default:
                        if (field.data is byte[])
                        {
                            m = new MemoryStream();
                            for (long i = 0; i < input.hb1.ByteProvider.Length; i++)
                            {
                                m.WriteByte(input.hb1.ByteProvider.ReadByte(i));
                            }
                            field.data = m.ToArray();
                        }
                        break;
                    }
                    RefreshTree();
                }
            }
        }
        private bool BuildSBBinary(string tocname)
        {
            rtb2.AppendText("Building SB file...\n");
            string dir       = Path.GetDirectoryName(tocname) + "\\";
            string filename  = Path.GetFileNameWithoutExtension(tocname) + ".sb";
            string odir      = Path.GetDirectoryName(toc.MyPath) + "\\";
            string ofilename = Path.GetFileNameWithoutExtension(toc.MyPath) + ".sb";

            rtb2.AppendText("Writing " + filename + " ...\n");
            try
            {
                BJSON.Entry        root    = toc.lines[0];
                BJSON.Field        bundles = root.FindField("bundles");
                BJSON.Field        tbun    = bundles;
                List <BJSON.Entry> list    = (List <BJSON.Entry>)bundles.data;
                FileStream         fs      = new FileStream(dir + filename, FileMode.Create, FileAccess.Write);
                FileStream         ofs     = new FileStream(odir + ofilename, FileMode.Open, FileAccess.Read);
                long gl_off = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    BJSON.Entry e            = list[i];
                    long        offset       = 0;
                    int         size         = 0;
                    bool        isbase       = false;
                    BJSON.Field offset_field = new BJSON.Field();
                    BJSON.Field size_field   = new BJSON.Field();
                    BJSON.Field isbase_field = new BJSON.Field();
                    foreach (BJSON.Field f in e.fields)
                    {
                        switch (f.fieldname)
                        {
                        case "offset":
                            offset       = BitConverter.ToInt64((byte[])f.data, 0);
                            offset_field = f;
                            break;

                        case "size":
                            size       = BitConverter.ToInt32((byte[])f.data, 0);
                            size_field = f;
                            break;

                        case "base":
                            isbase       = (bool)f.data;
                            isbase_field = f;
                            break;
                        }
                    }
                    if (SelectForReplacement[i] == null)
                    {
                        if (isbase)
                        {
                            continue;
                        }
                        offset_field.data = BitConverter.GetBytes(gl_off);
                        CopyFileStream(ofs, fs, offset, size);
                    }
                    else
                    {
                        byte[] buf = File.ReadAllBytes(SelectForReplacement[i]);
                        size = buf.Length;
                        if (isbase)
                        {
                            isbase_field.data = false;
                        }
                        offset_field.data = BitConverter.GetBytes(gl_off);
                        size_field.data   = BitConverter.GetBytes((long)size);
                        fs.Write(buf, 0, size);
                    }
                    gl_off += size;
                    if (SelectForDuplication[i])
                    {
                        BJSON.Entry te = new BJSON.Entry();
                        te.type       = e.type;
                        te.type87name = e.type87name;
                        te.fields     = new List <BJSON.Field>();
                        foreach (BJSON.Field f in e.fields)
                        {
                            BJSON.Field tf = new BJSON.Field();
                            tf.fieldname = f.fieldname;
                            tf.type      = f.type;
                            switch (f.fieldname)
                            {
                            case "offset":
                                tf.data = BitConverter.GetBytes(BitConverter.ToInt64((byte[])f.data, 0));
                                break;

                            case "size":
                                tf.data = BitConverter.GetBytes(BitConverter.ToInt32((byte[])f.data, 0));
                                break;

                            case "base":
                                tf.data = (bool)f.data;
                                break;

                            default:
                                tf.data = f.data;
                                break;
                            }
                            te.fields.Add(tf);
                        }
                        list.Insert(i + 1, te);
                        bundles.data = list;
                        SelectForDuplication.Insert(i + 1, false);
                        SelectForReplacement.Insert(i + 1, null);
                    }
                }
                ofs.Close();
                fs.Close();
                rtb2.AppendText("Saved " + filename + "\n");
            }
            catch (Exception ex)
            {
                rtb2.AppendText("ERROR: " + ex.Message);
                return(false);
            }
            return(true);
        }