private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1 || toc == null)
            {
                return;
            }
            TOCFile.TOCBundleInfoStruct b = toc.bundles[n];
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("TOC information\n===============\n\nPath     : {0}\nIs in CAS: {1}\n\n", toc.MyPath, toc.iscas);
            sb.AppendFormat("Bundle information\n==================\n\nId     : {0}\nOffset : 0x{1}\nSize   : 0x{2}\n", b.id, b.offset.ToString("X8"), b.size.ToString("X8"));
            sb.AppendFormat("IsDelta: {0}\nIsBase : {1}", b.isdelta, b.isbase);
            rtb1.Text = sb.ToString();
        }
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1 || toc == null)
            {
                return;
            }
            UnMark();
            OpenFileDialog d = new OpenFileDialog();

            d.Filter = "*.bundle|*.bundle";
            if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TOCFile.TOCBundleInfoStruct b = toc.bundles[n];
                SelectForReplacement[n] = d.FileName;
                RefreshMe();
            }
        }
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1 || toc == null)
            {
                return;
            }
            TOCFile.TOCBundleInfoStruct b = toc.bundles[n];
            SaveFileDialog d = new SaveFileDialog();

            d.Filter   = "*.bundle|*.bundle";
            d.FileName = Path.GetFileName(b.id.Replace("/", "\\"));
            if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                byte[] buff = toc.ExportBundleDataByPath(b.id);
                File.WriteAllBytes(d.FileName, buff);
                MessageBox.Show("Done.");
            }
        }
Exemple #4
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (toc == null)
            {
                return;
            }
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            TOCFile.TOCBundleInfoStruct info = toc.bundles[n];
            if (info.isbase)
            {
                return;
            }
            byte[] data = toc.ExportBinaryBundle(info);
            binBundle = new BinaryBundle(new MemoryStream(data));
            RefreshBinaryBundle();
        }
Exemple #5
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();
        }
        private void CompareTocs(string file1, string file2)
        {
            TOCFile toc1 = new TOCFile(file1);
            TOCFile toc2 = new TOCFile(file2);

            foreach (TOCFile.TOCBundleInfoStruct b in toc1.bundles)
            {
                TOCFile.TOCBundleInfoStruct b2 = new TOCFile.TOCBundleInfoStruct();
                b2.id = "";
                foreach (TOCFile.TOCBundleInfoStruct compare in toc2.bundles)
                {
                    if (b.id == compare.id)
                    {
                        b2 = compare;
                        break;
                    }
                }
                if (b2.id == "")
                {
                    P(" E:bundle not found in compare file - " + b.id);
                    continue;
                }
                StringBuilder sb = new StringBuilder();
                sb.Append(" D:bundle " + b.id + "\n");
                if (b.isbase != b2.isbase)
                {
                    sb.AppendFormat(" -base is different ({0}) vs ({1})\n", b.isbase, b2.isbase);
                }
                if (b.isdelta != b2.isdelta)
                {
                    sb.AppendFormat(" -delta is different ({0}) vs ({1})\n", b.isdelta, b2.isdelta);
                }
                if (b.size != b2.size)
                {
                    sb.AppendFormat(" -size is different ({0}) vs ({1})\n", b.size, b2.size);
                }
                if ((b.isbase != b2.isbase) || (b.isdelta != b2.isdelta) || (b.size != b2.size))
                {
                    P(sb.ToString());
                }
            }
            if (!file1.ToLower().Contains("chunk"))
            {
                foreach (TOCFile.TOCChunkInfoStruct b in toc1.chunks)
                {
                    TOCFile.TOCChunkInfoStruct b2 = new TOCFile.TOCChunkInfoStruct();
                    b2.id = new byte[0];
                    foreach (TOCFile.TOCChunkInfoStruct compare in toc2.chunks)
                    {
                        if (Helpers.ByteArrayCompare(b.id, compare.id))
                        {
                            b2 = compare;
                            break;
                        }
                    }
                    if (b2.id.Length == 0)
                    {
                        P(" E:chunk not found in compare file - " + Helpers.ByteArrayToHexString(b.id));
                        continue;
                    }
                    StringBuilder sb = new StringBuilder();
                    sb.Append(" D:chunk " + Helpers.ByteArrayToHexString(b.id) + "\n");
                    if (b.sha1 != null && Helpers.ByteArrayCompare(b.sha1, b2.sha1))
                    {
                        sb.AppendFormat(" -sha1 is different ({0}) vs ({1})\n", Helpers.ByteArrayToHexString(b.sha1), Helpers.ByteArrayToHexString(b2.sha1));
                    }
                    if (b.offset != b2.offset)
                    {
                        sb.AppendFormat(" -offset is different ({0}) vs ({1})\n", b.offset, b2.offset);
                    }
                    if (b.size != b2.size)
                    {
                        sb.AppendFormat(" -size is different ({0}) vs ({1})\n", b.size, b2.size);
                    }
                    if ((b.sha1 != null && Helpers.ByteArrayCompare(b.sha1, b2.sha1)) || (b.offset != b2.offset) || (b.size != b2.size))
                    {
                        P(sb.ToString());
                    }
                }
            }
            CompareSB(file1.ToLower().Replace(".toc", ".sb"), file2.ToLower().Replace(".toc", ".sb"));
        }
Exemple #7
0
        public static void AddBundle(int tocid, bool incas, Bundle b, TOCFile.TOCBundleInfoStruct info, SQLiteConnection con)
        {
            Debug.LogLn(" EBX:" + b.ebx.Count + " RES:" + b.res.Count + " CHUNK:" + b.chunk.Count, true);
            SQLCommand("INSERT INTO bundles (tocfile, frostid, offset, size, base, delta) VALUES (" + tocid + ",'" + info.id + "'," + info.offset + ", " + info.size + ", '" + info.isbase + "', '" + info.isdelta + "' )", con);
            int            bundleid    = (int)GetLastRowId(con);
            TOCInformation toci        = GetTocInformationByIndex(tocid);
            var            transaction = con.BeginTransaction();
            int            counter     = 0;

            if (b.ebx != null)
            {
                foreach (Bundle.ebxtype ebx in b.ebx)
                {
                    try
                    {
                        if (ebx.name != null && ebx.originalSize != null && ebx.size != null)
                        {
                            EBXInformation inf = new EBXInformation();
                            inf.basesha1     = Helpers.ByteArrayToHexString(ebx.baseSha1);
                            inf.bundlepath   = b.path;
                            inf.casPatchType = ebx.casPatchType;
                            inf.deltasha1    = Helpers.ByteArrayToHexString(ebx.deltaSha1);
                            inf.ebxname      = ebx.name;
                            inf.incas        = incas;
                            inf.isbase       = info.isbase;
                            inf.isdelta      = info.isdelta;
                            if (toci.type == TYPE_BASEGAME)
                            {
                                inf.isbasegamefile = true;
                            }
                            if (toci.type == TYPE_UPDATE)
                            {
                                inf.isDLC = true;
                            }
                            if (toci.type == TYPE_PATCH)
                            {
                                inf.isPatch = true;
                            }
                            inf.offset      = info.offset;
                            inf.sha1        = Helpers.ByteArrayToHexString(ebx.Sha1);
                            inf.size        = info.size;
                            inf.tocfilepath = toci.path;
                            byte[] data = new byte[0];
                            if (inf.incas)
                            {
                                data = SHA1Access.GetDataBySha1(ebx.Sha1, 0x38);
                            }
                            else
                            {
                                BinaryBundle bb = null;
                                foreach (AddEBXHelpStruct h in aehelp)
                                {
                                    if (h.tocpath == inf.tocfilepath && h.bpath == inf.bundlepath)
                                    {
                                        bb = h.b;
                                        break;
                                    }
                                }
                                if (bb == null)
                                {
                                    TOCFile toc        = new TOCFile(inf.tocfilepath);
                                    byte[]  bundledata = toc.ExportBundleDataByPath(inf.bundlepath);
                                    bb = new BinaryBundle(new MemoryStream(bundledata));
                                    AddEBXHelpStruct h = new AddEBXHelpStruct();
                                    h.tocpath = inf.tocfilepath;
                                    h.bpath   = inf.bundlepath;
                                    h.b       = bb;
                                    if (aehelp.Count > 10)
                                    {
                                        aehelp.RemoveAt(0);
                                    }
                                }
                                foreach (BinaryBundle.EbxEntry ebx2 in bb.EbxList)
                                {
                                    if (inf.ebxname == ebx2._name)
                                    {
                                        data = ebx2._data;
                                    }
                                }
                            }
                            inf.guid = Helpers.ByteArrayToHexString(data, 0x28, 0x10);
                            AddEBXLUTFile(inf, con);
                            if ((counter++) % 100 == 0)
                            {
                                transaction.Commit();
                                transaction = con.BeginTransaction();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            transaction.Commit();
            transaction = con.BeginTransaction();
            if (b.res != null)
            {
                foreach (Bundle.restype res in b.res)
                {
                    try
                    {
                        if (res.name != null)
                        {
                            AddRESFile(res.name, res.SHA1, res.rtype, bundleid, con);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            transaction.Commit();
            transaction = con.BeginTransaction();
            if (b.chunk != null)
            {
                foreach (Bundle.chunktype chunk in b.chunk)
                {
                    try
                    {
                        AddChunk(chunk.id, chunk.SHA1, bundleid, con);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            transaction.Commit();
        }