private void toolStripButton14_Click(object sender, EventArgs e) { SaveFileDialog d = new SaveFileDialog(); d.Filter = "*.bin|*.bin"; TreeNode t = treeView4.SelectedNode; if (t == null || t.Nodes == null || t.Nodes.Count != 0) { return; } string path = Helpers.GetPathFromNode(t, "/"); path = path.Substring(1, path.Length - 1); d.FileName = t.Text + ".bin"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { foreach (DBAccess.EBXInformation ebx in ebxlist) { if (path == ebx.ebxname && ebx.casPatchType == 0 && !ebx.isbase) { byte[] data = new byte[0]; if (ebx.incas) { data = SHA1Access.GetDataBySha1(Helpers.HexStringToByteArray(ebx.sha1)); } else { TOCFile toc = new TOCFile(ebx.tocfilepath); byte[] bundledata = toc.ExportBundleDataByPath(ebx.bundlepath); BinaryBundle b = new BinaryBundle(new MemoryStream(bundledata)); foreach (BinaryBundle.EbxEntry ebx2 in b.EbxList) { if (path == ebx2._name) { data = ebx2._data; } } } File.WriteAllBytes(d.FileName, data); MessageBox.Show("Done."); return; } } } }
private void RefreshPreview() { try { int n = listBox2.SelectedIndex; if (n == -1) { return; } status.Text = "Getting header infos from db..."; Application.DoEvents(); DBAccess.RESInformation ti = ttprevlist[n]; DBAccess.BundleInformation buni = DBAccess.GetBundleInformationById(ti.bundlepath)[0]; DBAccess.TOCInformation toci = DBAccess.GetTocInformationByIndex(buni.tocIndex); byte[] resdata = new byte[0]; if (toci.incas) { status.Text = "Getting header data from sha1..."; Application.DoEvents(); resdata = SHA1Access.GetDataBySha1(Helpers.HexStringToByteArray(ti.sha1)); } else { status.Text = "Getting header data from binary bundle..."; Application.DoEvents(); TOCFile toc = new TOCFile(toci.path); byte[] bundledata = toc.ExportBundleDataByPath(buni.bundlepath); BinaryBundle b = new BinaryBundle(new MemoryStream(bundledata)); foreach (BinaryBundle.ResEntry res in b.ResList) { if (res._name == ti.resname) { resdata = res._data; break; } } } hb2.ByteProvider = new DynamicByteProvider(resdata); status.Text = "Ready"; } catch (Exception ex) { status.Text = "General error, after state '" + status.Text + "' : " + ex.Message; } }
private void openInEBXToolToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode t = treeView4.SelectedNode; if (t == null || t.Nodes == null || t.Nodes.Count != 0) { return; } string path = Helpers.GetPathFromNode(t, "/"); path = path.Substring(1, path.Length - 1); foreach (DBAccess.EBXInformation ebx in ebxlist) { if (path == ebx.ebxname && ebx.casPatchType == 0 && !ebx.isbase) { byte[] data = new byte[0]; if (ebx.incas) { data = SHA1Access.GetDataBySha1(Helpers.HexStringToByteArray(ebx.sha1)); } else { TOCFile toc = new TOCFile(ebx.tocfilepath); byte[] bundledata = toc.ExportBundleDataByPath(ebx.bundlepath); BinaryBundle b = new BinaryBundle(new MemoryStream(bundledata)); foreach (BinaryBundle.EbxEntry ebx2 in b.EbxList) { if (path == ebx2._name) { data = ebx2._data; } } } ContentTools.EBXTool ebxtool = new ContentTools.EBXTool(); ebxtool.MdiParent = this.MdiParent; ebxtool.Show(); ebxtool.WindowState = FormWindowState.Maximized; ebxtool.LoadEbx(data); break; } } }
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."); } }
private void treeView3_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode t = treeView3.SelectedNode; if (t == null || t.Nodes == null || t.Nodes.Count != 0) { return; } string path = Helpers.GetPathFromNode(t, "/"); for (int i = 0; i < tblist.Count; i++) { if (path.Contains(tblist[i].bundlepath)) { DBAccess.BundleInformation bi = tblist[i]; if (bi.isbase) { return; } TOCFile toc = new TOCFile(bi.filepath); byte[] data = toc.ExportBundleDataByPath(bi.bundlepath); Bundle b = null; if (bi.incas) { List <BJSON.Entry> tmp = new List <BJSON.Entry>(); BJSON.ReadEntries(new MemoryStream(data), tmp); b = Bundle.Create(tmp[0]); } else { b = Bundle.Create(data, true); } if (b == null) { return; } 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>(); } int total = b.ebx.Count + b.res.Count + b.chunk.Count; StringBuilder sb = new StringBuilder(); sb.AppendFormat("Total count : {0}\n", total); sb.AppendFormat("EBX count : {0}\n", b.ebx.Count); sb.AppendFormat("RES count : {0}\n", b.res.Count); sb.AppendFormat("CHUNK count : {0}\n", b.chunk.Count); rtb1.Text = sb.ToString(); DBAccess.BundleInformation[] dupBun = DBAccess.GetBundleInformationById(bi.bundlepath); listBox3.Items.Clear(); int count = 0; int l = GlobalStuff.FindSetting("gamepath").Length; foreach (DBAccess.BundleInformation dup in dupBun) { DBAccess.TOCInformation ti = DBAccess.GetTocInformationByIndex(dup.tocIndex); listBox3.Items.Add((count++) + " : " + ti.path.Substring(l, ti.path.Length - l) + " -> Delta:" + dup.isdelta + " Base:" + dup.isbase); } } } }
private void RefreshPreview() { try { int n = listBox2.SelectedIndex; if (n == -1) { return; } status.Text = "Getting header infos from db..."; Application.DoEvents(); DBAccess.RESInformation ti = ttprevlist[n]; DBAccess.BundleInformation buni = DBAccess.GetBundleInformationById(ti.bundlepath)[0]; DBAccess.TOCInformation toci = DBAccess.GetTocInformationByIndex(buni.tocIndex); BinaryBundle b = new BinaryBundle(); byte[] resdata = new byte[0]; if (toci.incas) { status.Text = "Getting header data from sha1..."; Application.DoEvents(); resdata = SHA1Access.GetDataBySha1(Helpers.HexStringToByteArray(ti.sha1)); } else { status.Text = "Getting header data from binary bundle..."; Application.DoEvents(); TOCFile toc = new TOCFile(toci.path); byte[] bundledata = toc.ExportBundleDataByPath(buni.bundlepath); b = new BinaryBundle(new MemoryStream(bundledata)); foreach (BinaryBundle.ResEntry res in b.ResList) { if (res._name == ti.resname) { resdata = res._data; break; } } } hb2.ByteProvider = new DynamicByteProvider(resdata); Mesh mesh = new Mesh(new MemoryStream(resdata)); foreach (Mesh.MeshLOD lod in mesh.header.LODs) { byte[] id = lod.ChunkID; byte[] data = new byte[0]; if (toci.incas) { DBAccess.ChunkInformation ci = DBAccess.GetChunkInformationById(id); if (ci.sha1 == null) { continue; } data = SHA1Access.GetDataBySha1(ci.sha1); } else { byte t = id[0]; id[0] = id[3]; id[3] = t; t = id[1]; id[1] = id[2]; id[2] = t; t = id[6]; id[6] = id[7]; id[7] = t; t = id[4]; id[4] = id[5]; id[5] = t; foreach (BinaryBundle.ChunkEntry c in b.ChunkList) { if (Helpers.ByteArrayCompare(id, c.id)) { data = c._data; } } if (data.Length == 0) { DBAccess.ChunkInformation ci = DBAccess.GetChunkInformationById(id); if (ci.sha1 == null) { continue; } data = SHA1Access.GetDataBySha1(ci.sha1); } } mesh.LoadChunkData(lod, new MemoryStream(data)); } MeshRenderObject mro = new MeshRenderObject(mesh); renderer.list.Clear(); renderer.list.Add(mro); renderer.worldoffset = -mro.center; renderer.CamDistance = mro.min.Length() + mro.max.Length(); status.Text = "Ready"; } catch (Exception ex) { status.Text = "General error, after state '" + status.Text + "' : " + ex.Message; } }
private void toolStripButton15_Click(object sender, EventArgs e) { int errorcount = 0; FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string basepath = fbd.SelectedPath + "\\"; int casptype = toolStripComboBox1.SelectedIndex; int count = 0; foreach (DBAccess.EBXInformation ebx in ebxlist) { if (ebx.casPatchType == casptype) { byte[] data = new byte[0]; if (ebx.incas) { data = SHA1Access.GetDataBySha1(Helpers.HexStringToByteArray(ebx.sha1), 0x40); } else { TOCFile toc = new TOCFile(ebx.tocfilepath); byte[] bundledata = toc.ExportBundleDataByPath(ebx.bundlepath); BinaryBundle b = new BinaryBundle(new MemoryStream(bundledata)); foreach (BinaryBundle.EbxEntry ebx2 in b.EbxList) { if (ebx.ebxname == ebx2._name) { data = ebx2._data; } } } EBXStream ex = new EBXStream(new MemoryStream(data)); if (!ex.ErrorLoading) { string subfilename = ebx.ebxname.Replace("/", "\\").Replace("'", "") + ".xml"; string subpath = Path.GetDirectoryName(subfilename) + "\\"; if (!Directory.Exists(basepath + subpath)) { Directory.CreateDirectory(basepath + subpath); } File.WriteAllText(basepath + subfilename, ex.toXML()); if (count++ % 123 == 0) { ebxstatus.Text = "Writing #" + count + " " + basepath + subfilename + " ..."; Application.DoEvents(); } } else { errorcount++; if (count++ % 123 == 0) { this.Text = "Errors exporting : " + errorcount.ToString() + " =(" + ((float)errorcount / (float)count) * 100f + "%) Last:" + ebx.ebxname; Application.DoEvents(); } } } } this.Text = "Content Browser"; ebxstatus.Text = "Ready. Processed Ebx:" + count + " Errors: " + errorcount + " (" + ((float)errorcount / (float)count) * 100f + "%)"; } }
private void CheckSelectionEBX() { TreeNode t = treeView4.SelectedNode; if (t == null || t.Nodes == null || t.Nodes.Count != 0) { return; } string path = Helpers.GetPathFromNode(t, "/"); path = path.Substring(1, path.Length - 1); if (path == lastpath) { return; } lastpath = path; foreach (DBAccess.EBXInformation ebx in ebxlist) { if (path == ebx.ebxname && ebx.casPatchType != 2 && !ebx.isbase) { string c = "b"; if (ebx.isDLC) { c = "u"; } if (ebx.isPatch) { c = "p"; } byte[] data = new byte[0]; if (ebx.incas) { data = SHA1Access.GetDataBySha1(Helpers.HexStringToByteArray(ebx.sha1)); } else { TOCFile toc = new TOCFile(ebx.tocfilepath); byte[] bundledata = toc.ExportBundleDataByPath(ebx.bundlepath); BinaryBundle b = new BinaryBundle(new MemoryStream(bundledata)); foreach (BinaryBundle.EbxEntry ebx2 in b.EbxList) { if (path.Contains(ebx2._name)) { data = ebx2._data; } } } if (toolStripButton11.Checked) { hb1.BringToFront(); hb1.ByteProvider = new DynamicByteProvider(data); } else if (toolStripComboBox1.SelectedIndex < 2) { rtb2.BringToFront(); rtb2.Text = ""; rtb2.Visible = false; try { ebxstatus.Text = "Processing..."; Application.DoEvents(); EBXStream ebxf = new EBXStream(new MemoryStream(data), ebxpb1); ebxstatus.Text = "Displaying..."; rtb2.Text = ebxf.toXML(); ebxstatus.Text = "Ready (Type is " + c + ")"; } catch (Exception ex) { rtb2.Text = "Error:\n" + ex.Message; } rtb2.Visible = true; } return; } } }
public static void AddEBXLUTFile(EBXInformation ebx, SQLiteConnection con) { string ftype = "b"; if (ebx.isDLC) { ftype = "u"; } if (ebx.isPatch) { ftype = "p"; } string guid = ""; byte[] data = new byte[0]; if (ebx.incas) { data = SHA1Access.GetDataBySha1(Helpers.HexStringToByteArray(ebx.sha1)); } else { BinaryBundle b = null; foreach (AddEBXHelpStruct h in aehelp) { if (h.tocpath == ebx.tocfilepath && h.bpath == ebx.bundlepath) { b = h.b; break; } } if (b == null) { TOCFile toc = new TOCFile(ebx.tocfilepath); byte[] bundledata = toc.ExportBundleDataByPath(ebx.bundlepath); b = new BinaryBundle(new MemoryStream(bundledata)); AddEBXHelpStruct h = new AddEBXHelpStruct(); h.tocpath = ebx.tocfilepath; h.bpath = ebx.bundlepath; h.b = b; if (aehelp.Count > 10) { aehelp.RemoveAt(0); } } foreach (BinaryBundle.EbxEntry ebx2 in b.EbxList) { if (ebx.ebxname == ebx2._name) { data = ebx2._data; } } } guid = Helpers.ByteArrayToHexString(data, 0x28, 0x10); SQLCommand("INSERT INTO ebxlut (path,sha1,basesha1,deltasha1,casptype,guid,bundlepath,offset,size,isbase,isdelta,tocpath,incas,filetype) VALUES ('" + ebx.ebxname.Replace("'", "''") + "','" + ebx.sha1 + "','" + ebx.basesha1 + "','" + ebx.deltasha1 + "'," + ebx.casPatchType + ",'" + guid + "','" + ebx.bundlepath + "'," + ebx.offset + "," + ebx.size + ",'" + ebx.isbase + "','" + ebx.isdelta + "','" + ebx.tocfilepath + "','" + ebx.incas + "','" + ftype + "')", con); }
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(); }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { int n = listBox1.SelectedIndex; if (n == -1) { return; } try { statustext.Text = "Getting header infos from db..."; Application.DoEvents(); hb1.ByteProvider = new DynamicByteProvider(new byte[0]); if (File.Exists("tmp\\tmp.dds")) { File.Delete("tmp\\tmp.dds"); } DBAccess.BundleInformation buni = bil[n]; DBAccess.TextureInformation ti = new DBAccess.TextureInformation(); foreach (DBAccess.TextureInformation t in til) { if (t.bundleIndex == buni.index) { ti = t; } } DBAccess.TOCInformation toci = DBAccess.GetTocInformationByIndex(buni.tocIndex); byte[] resdata = new byte[0]; if (toci.incas) { statustext.Text = "Getting header data from sha1..."; Application.DoEvents(); resdata = SHA1Access.GetDataBySha1(ti.sha1); } else { statustext.Text = "Getting header data from binary bundle..."; Application.DoEvents(); TOCFile toc = new TOCFile(toci.path); byte[] bundledata = toc.ExportBundleDataByPath(buni.bundlepath); BinaryBundle b = new BinaryBundle(new MemoryStream(bundledata)); foreach (BinaryBundle.ResEntry res in b.ResList) { if (res._name == ti.name) { resdata = res._data; break; } } } hb1.ByteProvider = new DynamicByteProvider(resdata); statustext.Text = "Getting texture infos from db..."; Application.DoEvents(); TextureMetaResource tmr = new TextureMetaResource(resdata); DBAccess.ChunkInformation ci = DBAccess.GetChunkInformationById(tmr.chunkid); if (ci.bundleIndex == -1) { throw new Exception("no chunk info found in db"); } DBAccess.BundleInformation buni2 = DBAccess.GetBundleInformationByIndex(ci.bundleIndex); DBAccess.TOCInformation toci2 = DBAccess.GetTocInformationByIndex(buni2.tocIndex); byte[] texdata = new byte[0]; if (toci2.incas) { statustext.Text = "Getting texture data from sha1..."; Application.DoEvents(); texdata = SHA1Access.GetDataBySha1(ci.sha1); } else { statustext.Text = "Getting texture data from binary bundle..."; Application.DoEvents(); TOCFile toc = new TOCFile(toci2.path); byte[] bundledata = toc.ExportBundleDataByPath(buni2.bundlepath); BinaryBundle b = new BinaryBundle(new MemoryStream(bundledata)); foreach (BinaryBundle.ChunkEntry chunk in b.ChunkList) { if (Helpers.MatchByteArray(chunk.id, ci.id)) { texdata = chunk._data; break; } } } hb2.ByteProvider = new DynamicByteProvider(texdata); statustext.Text = "Making Preview..."; Application.DoEvents(); MemoryStream m = new MemoryStream(); tmr.WriteTextureHeader(m); m.Write(texdata, 0, texdata.Length); if (!Directory.Exists("tmp")) { Directory.CreateDirectory("tmp"); } File.WriteAllBytes("tmp\\tmp.dds", m.ToArray()); try { pb1.Image = DevIL.DevIL.LoadBitmap("tmp\\tmp.dds"); pb1.BringToFront(); } catch (Exception) { statustext.Text = "Error loading dds, after state '" + statustext.Text + "'"; } statustext.Text = "Ready"; } catch (Exception) { statustext.Text = "General error, after state '" + statustext.Text + "'"; } }