private void exportSelectedToolStripMenuItem_Click(object sender, EventArgs e) { int m = hs1.Value; int n = listBox1.SelectedIndex; if (n == -1 || m == -1 || cas == null || cat == null) { return; } int Idx = m + n; CASFile.CASEntry en = cas.ReadEntry(Idx); SaveFileDialog d = new SaveFileDialog(); d.Filter = "*.bin|*.bin"; string filename = "CAS" + cas.casnumber.ToString("d2") + "_"; for (int i = 0; i < 5; i++) { filename += cat.lines[cas.Indexes[Idx]][i].ToString("x8"); } filename += ".bin"; d.FileName = filename; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { File.WriteAllBytes(d.FileName, en.data.ToArray()); MessageBox.Show("Done."); } }
private void sHA1ToolStripMenuItem_Click(object sender, EventArgs e) { int m = hs1.Value; int n = listBox1.SelectedIndex; if (n == -1 || m == -1 || cas == null || cat == null) { return; } int Idx = m + n; CASFile.CASEntry en = cas.ReadEntry(Idx); SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider(); byte[] result = sha1.ComputeHash(en.compressed); string s = "SHA1:\n"; int count = 1; foreach (byte b in result) { if ((count++) % 4 == 0) { s += b.ToString("X2") + " "; } else { s += b.ToString("X2") + " "; } } MessageBox.Show(s); }
private void ExtractAllTextures(string target, bool withpath) { if (cat == null) { return; } rtb1.Text = ""; string basepath = Path.GetDirectoryName(cat.MyPath) + "\\"; pb1.Value = 0; pb1.Maximum = listTex.Count; for (int i = 0; i < listTex.Count; i++) { TextureInfo t = listTex[i]; if (t.chunk.catline != null && CheckCASExist(basepath, t.chunk.catline[7])) { string path = GetDDSTargetFullPath(target, withpath, t); CASFile cas = new CASFile(CASFile.GetCASFileName(basepath, t.chunk.catline[7])); CASFile.CASEntry e = cas.ReadEntry(t.chunk.catline.ToArray()); WriteDDSFile(ref t, path, ref e); rtb1.AppendText("Wrote file: " + path + "\n"); Application.DoEvents(); pb1.Value = i; } } rtb1.AppendText("Done.\n"); }
public static byte[] getDataBySHA1(string sha1, SQLiteConnection con) { SQLiteDataReader reader = Database.getAllWhere("sha1db", "line LIKE '" + sha1 + "%'", con); if (!reader.Read()) { return(new byte[0]); } string lines = reader.GetString(0); byte[] buff = Tools.StringToByteArray(lines); uint[] line = new uint[9]; MemoryStream m = new MemoryStream(buff); m.Seek(20, 0); uint offset = Tools.ReadLEUInt(m); uint size = Tools.ReadLEUInt(m); uint casn = Tools.ReadLEUInt(m); reader = Database.getAllWhere("casfiles", "path LIKE '%cas_" + casn.ToString("d2") + ".cas'", con); if (!reader.Read()) { return(new byte[0]); } CASFile cas = new CASFile(reader.GetString(0)); CASFile.CASEntry entry = cas.ReadEntry(offset, size); return(entry.data); }
private void WriteDDSFile(ref TextureInfo t, string path, ref CASFile.CASEntry e) { Directory.CreateDirectory(Path.GetDirectoryName(path)); using (FileStream targetStream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite)) using (BinaryWriter targetWriter = new BinaryWriter(targetStream)) { BuildTextureHeader(t, targetWriter); targetWriter.Write(e.data); } }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { int m = hs1.Value; int n = listBox1.SelectedIndex; if (n == -1 || m == -1 || cas == null || cat == null) { return; } int Idx = m + n; CASFile.CASEntry en = cas.ReadEntry(Idx); hb1.ByteProvider = new DynamicByteProvider(en.data.ToArray()); }
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]); }
private void LinkTexAndChunks() { if (cat == null) { return; } string basepath = Path.GetDirectoryName(cat.MyPath) + "\\"; for (int i = 0; i < listTex.Count; i++) { TextureInfo t = listTex[i]; if (t.catline != null && CheckCASExist(basepath, t.catline[7])) { CASFile cas = new CASFile(CASFile.GetCASFileName(basepath, t.catline[7])); CASFile.CASEntry e = cas.ReadEntry(t.catline.ToArray()); byte[] id = null; LoadTextureData(ref t, ref id, e.data); LoadChunkData(ref t, i, id); } } }
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(); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode t = treeView1.SelectedNode; if (t == null) { return; } if (t.Text == "82") { TreeNode t2 = null; foreach (TreeNode child in t.Nodes) { if (child.Text == "sha1") { t2 = child; break; } } if (t2 != null) { string sha1 = t2.Nodes[0].Text; byte[] sha1buff = 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> casline = cat.FindBySHA1(sha1buff); if (casline.Count == 8) { if (cas == null) { 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()); hb1.ByteProvider = new DynamicByteProvider(ce.data); hb1.BringToFront(); rtb1.Text = Tools.DecompileLUAC(ce.data); if (rtb1.Text != "") { rtb1.BringToFront(); } } } } } }
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; }