public void Init() { if (GlobalStuff.FindSetting("isNew") == "1") { MessageBox.Show("Please initialize the database in Misc > Database with Scan"); this.BeginInvoke(new MethodInvoker(Close)); return; } string path = GlobalStuff.FindSetting("gamepath"); path += "Data\\cas.cat"; cat = new CATFile(path); SQLiteConnection con = Database.GetConnection(); con.Open(); SQLiteDataReader reader = new SQLiteCommand("SELECT path FROM langsbfiles WHERE path LIKE '%\\loctext\\%' ORDER BY path ", con).ExecuteReader(); toolStripComboBox1.Items.Clear(); languages = new List <string>(); while (reader.Read()) { languages.Add(reader.GetString(0)); } con.Close(); foreach (string l in languages) { toolStripComboBox1.Items.Add(Path.GetFileNameWithoutExtension(l)); } toolStripComboBox1.SelectedIndex = 0; language = new SBFile(languages[0]); MakeTree(); init = true; }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.sb|*.sb"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { sb = new SBFile(d.FileName); } else { return; } if (cat == null) { d.Filter = "*.cat|*.cat"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { cat = new CATFile(d.FileName); } } if (langTOC == null) { d.Filter = "*.toc|*.toc"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { langTOC = new TOCFile(d.FileName); } LoadTOC(); } RefreshMe(); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.cas|*.cas"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { cas = new CASFile(d.FileName); OpenFileDialog d2 = new OpenFileDialog(); d2.Filter = "*.cat|*.cat"; if (d2.ShowDialog() == System.Windows.Forms.DialogResult.OK) { cat = new CATFile(d2.FileName); cas.SetCAT(cat); if (cas.Indexes.Count > 100) { hs1.Maximum = cas.Indexes.Count - 100; } else { hs1.Maximum = 0; } RefreshList(); } } }
public void Init() { if (GlobalStuff.FindSetting("isNew") == "1") { MessageBox.Show("Please initialize the database in Misc > Database with Scan"); this.BeginInvoke(new MethodInvoker(Close)); return; } string path = GlobalStuff.FindSetting("gamepath"); path += "Data\\cas.cat"; cat = new CATFile(path); SQLiteConnection con = Database.GetConnection(); con.Open(); SQLiteDataReader reader = new SQLiteCommand("SELECT name,sha1 FROM res WHERE rtype='36F3F2C0' ORDER BY name", con).ExecuteReader(); shaderDatabases = new Dictionary <string, string>(); while (reader.Read()) { if (!shaderDatabases.ContainsKey(reader.GetString(0))) { shaderDatabases.Add(reader.GetString(0), reader.GetString(1)); } } con.Close(); MakeTree(); init = true; }
private void checkCATToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.cat|*.cat"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { cat = new CATFile(d.FileName); Check(); } }
public static CATFile getCatFile() { if (cat == null) { string path = GlobalStuff.FindSetting("gamepath"); path += "Data\\cas.cat"; cat = new CATFile(path); } return(cat); }
private void toolStripButton3_Click(object sender, EventArgs e) { try { string input = Microsoft.VisualBasic.Interaction.InputBox("Please enter offset in decimal", "Find by offset and cas number", ""); uint offset = Convert.ToUInt32(input); input = Microsoft.VisualBasic.Interaction.InputBox("Please enter cas number decimal", "Find by offset and cas number", ""); uint casnr = Convert.ToUInt32(input); input = Microsoft.VisualBasic.Interaction.InputBox("Search base(b) or patch(p)?", "Find by offset and cas number", "b"); CATFile cat = null; if (input != "p") { cat = new CATFile(GlobalStuff.FindSetting("gamepath") + "Data\\cas.cat"); } else { cat = new CATFile(GlobalStuff.FindSetting("gamepath") + "Update\\Patch\\Data\\cas.cat"); } byte[] sha1 = new byte[0]; for (int i = 0; i < cat.lines.Count; i++) { if (cat.lines[i][7] == casnr && cat.lines[i][5] <= offset && cat.lines[i][5] + cat.lines[i][6] > offset) { MemoryStream m = new MemoryStream(); for (int j = 0; j < 5; j++) { Helpers.WriteLEUInt(m, cat.lines[i][j]); } sha1 = m.ToArray(); break; } } cat = null; if (sha1.Length == 0) { MessageBox.Show("SHA1 not found!"); return; } toolStripTextBox1.Text = Helpers.ByteArrayToHexString(sha1); Thread t = new Thread(ThreadedSearch); t.Start(); MessageBox.Show("Done."); return; } catch (Exception) { } }
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 openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.cat|*.cat"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { cat = new CATFile(d.FileName); if (cat.lines.Count > 100) { hScrollBar1.Maximum = cat.lines.Count - 100; } else { hScrollBar1.Maximum = 0; } RefreshList(); } }
private void StartScan(string basepath) { rtb1.Text = ""; Log("Starting Scan..."); Mod.GetOrSetAuthor(); Stopwatch sp = new Stopwatch(); sp.Start(); GlobalStuff.AssignSetting("isNew", "0"); GlobalStuff.settings.Add("gamepath", basepath); Database.SaveSettings(); CATFile cat = ScanCAT(); ScanFiles(); ScanBundles(cat); sp.Stop(); Log("\n\n===============\nTime : " + sp.Elapsed.ToString() + "\nDone."); MessageBox.Show("Done."); }
private void ScanBundles(CATFile cat) { Log("Saving bundles into db..."); SQLiteConnection con = Database.GetConnection(); con.Open(); SQLiteDataReader reader = Database.getAll("sbfiles", con); StringBuilder sb = new StringBuilder(); List <string> files = new List <string>(); while (reader.Read()) { files.Add(reader.GetString(0)); } int counter = 1; Stopwatch sp = new Stopwatch(); sp.Start(); foreach (string file in files) { Log("Opening " + file + " ..."); SBFile sbfile = new SBFile(file); Log(" found " + sbfile.bundles.Count + " bundles, saving to db..."); var transaction = con.BeginTransaction(); int counter2 = 1; foreach (Bundle b in sbfile.bundles) { if (b.ebx == null) { b.ebx = new List <Bundle.ebxtype>(); } Log(" processing bundle: " + (counter2++) + "/" + sbfile.bundles.Count + " \"" + b.path + "\" (ebxcount = " + b.ebx.Count + ") ..."); Database.AddBundle(file, b, con, cat); } transaction.Commit(); long elapsed = sp.ElapsedMilliseconds; long ETA = ((elapsed / counter) * files.Count); TimeSpan ETAt = TimeSpan.FromMilliseconds(ETA); Log((counter++) + "/" + files.Count + " files done." + " - Elapsed: " + sp.Elapsed.ToString() + " ETA: " + ETAt.ToString()); } con.Clone(); }
private CATFile ScanCAT() { Log("Loading CAT..."); string path = GlobalStuff.FindSetting("gamepath") + "Data\\cas.cat"; CATFile cat = new CATFile(path); SQLiteConnection con = Database.GetConnection(); con.Open(); var transaction = con.BeginTransaction(); Database.ClearSHA1db(con); int counter = 0; Log("Saving sha1s into db..."); foreach (uint[] line in cat.lines) { Database.AddSHA1(line, con); if ((counter % 100000) == 0) { rtb1.AppendText(counter + "/" + cat.lines.Count + "\n"); rtb1.SelectionStart = rtb1.Text.Length; rtb1.ScrollToCaret(); transaction.Commit(); transaction = con.BeginTransaction(); } counter++; } Log("Saving chunk ids into db..."); foreach (CATFile.ChunkType c in cat.chunks) { Database.AddChunk(c.id, c.sha1, con); } transaction.Commit(); con.Close(); return(cat); }
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); } }
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; }