Exemplo n.º 1
0
        public static byte[] GetDataBySha1(byte[] sha1, int maxsize = 0x7FFFFFFF)
        {
            CATFile cat = null;

            if (cat_base == null)
            {
                string path = GlobalStuff.FindSetting("gamepath") + "Data\\cas.cat";
                cat_base = new CATFile(path);
            }
            List <uint> casline = cat_base.FindBySHA1(sha1);

            if (casline.Count == 9)
            {
                cat = cat_base;
            }
            else
            {
                if (cat_patch == null)
                {
                    string path = GlobalStuff.FindSetting("gamepath") + "Update\\Patch\\Data\\cas.cat";
                    cat_patch = new CATFile(path);
                }
                cat     = cat_patch;
                casline = cat_patch.FindBySHA1(sha1);
            }
            if (casline.Count == 9)
            {
                if (cas == null || cas.casnumber != casline[7])
                {
                    string[] files = Directory.GetFiles(Path.GetDirectoryName(cat.MyPath));
                    foreach (string file in files)
                    {
                        if (Path.GetFileName(file) == CASFile.GetCASFileName(casline[7]))
                        {
                            cas = new CASFile(file);
                            break;
                        }
                    }
                }
                if (cas != null && cas.casnumber == casline[7])
                {
                    CASFile.CASEntry ce = cas.ReadEntry(casline.ToArray(), maxsize);
                    return(ce.data);
                }
            }
            return(new byte[0]);
        }
Exemplo n.º 2
0
        public static void AddBundle(string filepath, Bundle b, SQLiteConnection con, CATFile cat)
        {
            if (b.ebx == null)
            {
                b.ebx = new List <Bundle.ebxtype>();
            }
            if (b.res == null)
            {
                b.res = new List <Bundle.restype>();
            }
            if (b.chunk == null)
            {
                b.chunk = new List <Bundle.chunktype>();
            }
            SQLCommand("INSERT INTO bundles VALUES (NULL,'" + filepath + "','" + b.path + "', " + b.ebx.Count + ", " + b.res.Count + ", " + b.chunk.Count + " )", con);
            SQLiteCommand    command = new SQLiteCommand("SELECT last_insert_rowid()", con);
            SQLiteDataReader reader  = command.ExecuteReader();

            reader.Read();
            long   id          = (long)reader.GetValue(0);
            var    transaction = con.BeginTransaction();
            string basepath    = Path.GetDirectoryName(cat.MyPath) + "\\";

            if (!exceptions.Contains(b.path))
            {
                foreach (Bundle.ebxtype ebx in b.ebx)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (byte bb in ebx.SHA1)
                    {
                        sb.Append(bb.ToString("X2"));
                    }
                    List <uint> line = cat.FindBySHA1(ebx.SHA1);
                    string      type = "";
                    string      guid = "";
                    if (line.Count == 9)
                    {
                        CASFile          cas   = new CASFile(basepath + "cas_" + line[7].ToString("d2") + ".cas");
                        CASFile.CASEntry entry = cas.ReadEntry(line.ToArray());
                        try
                        {
                            /* Just obtain the Guid and Type from raw EBX */
                            Tools.ExtractEbxGuidAndType(new MemoryStream(entry.data), out type, out guid);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    SQLCommand("INSERT INTO ebx VALUES ('" + ebx.name.Replace("'", "") + "','" + sb.ToString() + "', " + id + ", '" + type + "', '" + guid + "')", con);
                }
            }
            transaction.Commit();
            transaction = con.BeginTransaction();
            foreach (Bundle.restype res in b.res)
            {
                StringBuilder sb = new StringBuilder();
                foreach (byte bb in res.SHA1)
                {
                    sb.Append(bb.ToString("X2"));
                }
                uint restype = BitConverter.ToUInt32(res.rtype, 0);
                SQLCommand("INSERT INTO res VALUES ('" + res.name.Replace("'", "") + "','" + sb.ToString() + "', '" + restype.ToString("X8") + "', " + id + ")", con);
            }
            transaction.Commit();
            transaction = con.BeginTransaction();
            foreach (Bundle.chunktype chunk in b.chunk)
            {
                StringBuilder sb = new StringBuilder();
                foreach (byte bb in chunk.id)
                {
                    sb.Append(bb.ToString("X2"));
                }
                StringBuilder sb2 = new StringBuilder();
                foreach (byte bb2 in chunk.SHA1)
                {
                    sb2.Append(bb2.ToString("X2"));
                }
                SQLCommand("INSERT INTO chunk VALUES ('" + sb.ToString() + "', '" + sb2.ToString() + "', " + id + ")", con);
            }
            transaction.Commit();
        }
 public void RefreshMe()
 {
     if (sb == null)
     {
         return;
     }
     listTex    = new List <TextureInfo>();
     listChunks = new List <ChunkInfo>();
     listBox1.Items.Clear();
     rtb1.Text = "Searching for Textures...";
     Application.DoEvents();
     foreach (Tools.Entry e in sb.lines)
     {
         if (e.type == 0x82)
         {
             foreach (Tools.Field f in e.fields)
             {
                 if (f.fieldname == "bundles" && f.type == 1)
                 {
                     FindTextures((List <Tools.Entry>)f.data);
                 }
             }
         }
     }
     rtb1.AppendText("done.\nLoading cat file...");
     Application.DoEvents();
     if (cat == null)
     {
         OpenFileDialog d = new OpenFileDialog();
         d.Filter = "*.cat|*.cat";
         if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             cat = new CATFile(d.FileName);
         }
         else
         {
             rtb1.AppendText("aborted.");
             return;
         }
     }
     rtb1.AppendText("done.\nSearching cat for SHA1s...");
     pb1.Maximum = listTex.Count + listChunks.Count;
     pb1.Value   = 0;
     for (int i = 0; i < listTex.Count; i++)
     {
         pb1.Value++;
         if ((i & 10) == 0)
         {
             Application.DoEvents();
         }
         TextureInfo t   = listTex[i];
         List <uint> res = cat.FindBySHA1(t.sha1);
         if (res.Count == 8)
         {
             t.catline  = res;
             listTex[i] = t;
         }
     }
     for (int i = 0; i < listChunks.Count; i++)
     {
         pb1.Value++;
         if ((i & 10) == 0)
         {
             Application.DoEvents();
         }
         ChunkInfo   c   = listChunks[i];
         List <uint> res = cat.FindBySHA1(c.sha1);
         if (res.Count == 8)
         {
             c.catline     = res;
             listChunks[i] = c;
         }
     }
     rtb1.AppendText("done.\nLinking Textures and Chunks...");
     pb1.Value = 0;
     Application.DoEvents();
     LinkTexAndChunks();
     rtb1.AppendText("done.\nFinished!");
     Application.DoEvents();
     foreach (TextureInfo t in listTex)
     {
         listBox1.Items.Add(t.fullpath);
     }
 }
        private void extractResourceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode t = treeView1.SelectedNode;

            if (t == null)
            {
                return;
            }
            TreeNode sha1t = null;

            foreach (TreeNode child in t.Nodes)
            {
                if (child.Text == "sha1")
                {
                    sha1t = child;
                    break;
                }
            }
            if (sha1t == null)
            {
                return;
            }
            string sha1 = sha1t.Nodes[0].Text;

            byte[] sha1b = Tools.StringToByteArray(sha1);
            if (cat == null)
            {
                OpenFileDialog d = new OpenFileDialog();
                d.Filter = "*.cat|*.cat";
                if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    cat = new CATFile(d.FileName);
                }
                else
                {
                    return;
                }
            }
            List <uint> catline = cat.FindBySHA1(sha1b);

            CASFile.CASEntry ce = new CASFile.CASEntry();
            if (catline.Count == 8)
            {
                if (cas != null && cas.casnumber == catline[7])
                {
                    ce = cas.ReadEntry(catline.ToArray());
                }
                else
                {
                    OpenFileDialog d       = new OpenFileDialog();
                    string         casname = CASFile.GetCASFileName(catline[7]);
                    d.Filter   = casname + "|" + casname;
                    d.FileName = casname;
                    if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        cas = new CASFile(d.FileName);
                        ce  = cas.ReadEntry(catline.ToArray());
                    }
                    else
                    {
                        return;
                    }
                }
            }
            else
            {
                MessageBox.Show("SHA1 Not found!");
                return;
            }
            SaveFileDialog d2 = new SaveFileDialog();

            d2.Filter   = "*.bin|*.bin";
            d2.FileName = sha1 + ".bin";
            if (d2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                File.WriteAllBytes(d2.FileName, ce.data);
                MessageBox.Show("Done.");
                return;
            }
            return;
        }