public void LoadFile(string path) { initfs = new TOCFile(path); list = new List <FileEntry>(); foreach (BJSON.Entry e in initfs.lines) { if (e.fields != null && e.fields.Count != 0) { BJSON.Field file = e.fields[0]; List <BJSON.Field> data = (List <BJSON.Field>)file.data; FileEntry entry = new FileEntry(); foreach (BJSON.Field f in data) { switch (f.fieldname) { case "name": entry.name = (string)f.data; break; case "payload": entry.data = (byte[])f.data; break; } } list.Add(entry); } } RefreshList(); }
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 toolStripMenuItem1_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "InitFS_Win32 file|initfs_win32"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { tocFile = new TOCFile(d.FileName); DisplayCurrentTOCFile(); } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.toc|*.toc"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { toc = new TOCFile(d.FileName); RefreshTree(); } }
private void toolStripButton1_Click(object sender, EventArgs e) { int n = toolStripComboBox1.SelectedIndex; if (n == -1) { return; } langTOC = new TOCFile(Languages[n]); LoadTOC(); MessageBox.Show("Done."); }
public void Convert(DATFile datFile, TSCFile tscFile, TOCFile tocFile) { this.datFile = datFile; tscFile.ICAO = datFile.AirportHeader.ICAOCode; tscFile.AirportLongName = datFile.AirportHeader.Name; tscFile.AirportShortName = datFile.AirportHeader.Name; if (datFile.LandRunways != null) { foreach (var landRunway in datFile.LandRunways) { TSCRunway runway = new TSCRunway(); runway.Width = landRunway.Width; runway.End1 = new TSCRunwayEnd(); runway.End2 = new TSCRunwayEnd(); ConvertRunwayEnd(runway.End1, landRunway.End1); ConvertRunwayEnd(runway.End2, landRunway.End2); tscFile.Runways.Add(runway); } } tscFile.Location = this.CalculateAirportCenterPoint(); var airportNameClean = tscFile.AirportShortName.Replace(" ", "_").ToLower(); // Add the runway object TSCSceneryObject runwayObject = new TSCSceneryObject(); runwayObject.GeometryFile = String.Format("{0}_{1}_rwy", tscFile.ICAO.ToLower(), airportNameClean); runwayObject.Position = new GeoCoordinate3d(tscFile.Location); runwayObject.Type = "ground"; // Add the decals object TSCSceneryObject decalObject = new TSCSceneryObject(); decalObject.GeometryFile = String.Format("{0}_{1}_decal", tscFile.ICAO.ToLower(), airportNameClean); decalObject.Position = new GeoCoordinate3d(tscFile.Location); decalObject.Type = "decal"; tscFile.Objects.Add(runwayObject); tscFile.Objects.Add(decalObject); }
public static void AddTOCFile(string path, string type, SQLiteConnection con) { string md5 = Helpers.ByteArrayToHexString(Helpers.ComputeHash(path)); Debug.LogLn(" MD5: " + md5 + " Filename: " + Path.GetFileName(path)); TOCFile toc = new TOCFile(path); bool incas = false; foreach (BJSON.Field f1 in toc.lines[0].fields) { if (f1.fieldname == "cas") { incas = (bool)f1.data; } } SQLCommand("INSERT INTO tocfiles (path, md5, incas, type) VALUES ('" + path + "', '" + md5 + "','" + incas + "','" + type + "')", con); }
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; } }
public void LoadFile(string path) { this.Text = "SB Tool - " + path; toc = new TOCFile(Helpers.GetFileNameWithOutExtension(path) + ".toc"); if (toc.iscas) { toolStrip1.Visible = true; splitContainer2.BringToFront(); sb = new SBFile(path); RefreshTree(); } else { toolStrip1.Visible = false; tabControl1.BringToFront(); RefreshBinary(); } }
private void toolStripMenuItem3_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.bundle|*.bundle"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { toc = null; toolStrip1.Visible = true; splitContainer2.BringToFront(); MemoryStream m = new MemoryStream(File.ReadAllBytes(d.FileName)); binBundle = new BinaryBundle(m); tabControl1.BringToFront(); RefreshBinary(); RefreshBinaryBundle(); return; } }
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 opnSingleToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.toc|*.toc"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { toc = new TOCFile(d.FileName); SelectForDeletion = new List <bool>(); SelectForReplacement = new List <string>(); SelectForDuplication = new List <bool>(); foreach (TOCFile.TOCBundleInfoStruct b in toc.bundles) { SelectForDeletion.Add(false); SelectForReplacement.Add(null); SelectForDuplication.Add(false); } RefreshMe(); rtb2.Text = ""; } }
public void PreviewFile(string path) { string ext = Path.GetExtension(path).ToLower(); TOCFile toc; switch (ext) { case ".toc": toc = new TOCFile(path); if (toc != null && toc.lines != null) { Helpers.FillTreeFast(treeView2, toc.lines); } break; case ".sb": string tocpath = Helpers.GetFileNameWithOutExtension(path) + ".toc"; if (File.Exists(tocpath)) { toc = new TOCFile(tocpath); if (toc != null && toc.lines != null && toc.lines.Count != 0) { foreach (BJSON.Field f in toc.lines[0].fields) { if (f.fieldname == "cas" && (bool)f.data) { SBFile sb = new SBFile(path); if (sb != null && sb.lines != null) { Helpers.FillTreeFast(treeView2, sb.lines); } return; } } } } break; } }
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; } Sounds = new List <SoundEntry>(); SQLiteConnection con = Database.GetConnection(); con.Open(); SQLiteDataReader reader = new SQLiteCommand("SELECT * FROM langtocfiles WHERE path LIKE '%\\loc\\%' ORDER BY path ", con).ExecuteReader(); toolStripComboBox1.Items.Clear(); Languages = new List <string>(); while (reader.Read()) { Languages.Add(reader.GetString(0)); } foreach (string l in Languages) { toolStripComboBox1.Items.Add(Path.GetFileName(l)); } langTOC = new TOCFile(Languages[0]); LoadTOC(); toolStripComboBox1.SelectedIndex = 0; reader = new SQLiteCommand("SELECT DISTINCT name FROM ebx WHERE type = 'SoundWaveAsset' ORDER BY name ", con).ExecuteReader(); while (reader.Read()) { SoundEntry e = new SoundEntry(); e.path = reader.GetString(0); Sounds.Add(e); } con.Close(); MakeTree(); init = true; }
public void GenerateAirportCsvList(AirportList airportList) { var csvFile = XP2AFSConverterManager.Settings.XP2AFSConverterFolder + @"airports.csv"; var writer = new StreamWriter(csvFile); var csv = new CsvWriter(writer); csv.WriteHeader <AirportCsvListItem>(); csv.NextRecord(); int i = 0; foreach (var airport in airportList.Airports) { // Exclude sea runways, closed runways and helipads if (!airport.AirportName.StartsWith("[S]") && !airport.AirportName.StartsWith("[X]") && !airport.AirportName.StartsWith("[H]")) { var airportXPFullDirectory = DirectoryHelper.GetAirportXPFullDirectory(airport.AirportCode, XP2AFSConverterManager.Settings); var airportZipFilename = airportXPFullDirectory + @"\" + airport.AirportCode + ".zip"; var airportFilename = airportXPFullDirectory + @"\airport.xml"; var airportSceneryFilename = airportXPFullDirectory + @"\scenery.xml"; if (File.Exists(airportZipFilename)) { //if (airport.AirportCode == "") log.InfoFormat("Adding airport {0} of {1}", i + 1, airportList.Airports.Count); // Parse the DST and DAT files var datFileLoader = new DATFileLoader(); var datFile = datFileLoader.GetDATFileFromXPZip(airport.AirportCode, airportZipFilename); //var dsfFile = this.GetDSFFileFromXPZip(airport.AirportCode, airportZipFilename); var sceneryFile = DeserializeSceneryFile(airportSceneryFilename); // Create empty AFS files var tscFile = new TSCFile(); var tocFile = new TOCFile(); var datConverter = new DATConverter(); // Convert the X-Plane files datConverter.Convert(datFile, tscFile, tocFile); if (datFile.AirportHeader.AirportType == AirportType.Airport && datFile.LandRunways != null) { TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; AirportCsvListItem airportListItem = new AirportCsvListItem(); airportListItem.Code = airport.AirportCode; airportListItem.Name = textInfo.ToTitleCase(airport.AirportName.ToLower()); airportListItem.IsHelipad = false; if (datFile.MetadataLookup.ContainsKey("datum_lat")) { double lat; if (Double.TryParse(datFile.MetadataLookup["datum_lat"], out lat)) { airportListItem.Latitude = lat; } } if (datFile.MetadataLookup.ContainsKey("datum_lon")) { double lon; if (Double.TryParse(datFile.MetadataLookup["datum_lon"], out lon)) { airportListItem.Longitude = lon; } } if (datFile.MetadataLookup.ContainsKey("country")) { airportListItem.Country = datFile.MetadataLookup["country"]; } if (datFile.MetadataLookup.ContainsKey("state")) { airportListItem.Region = datFile.MetadataLookup["state"]; } if (datFile.MetadataLookup.ContainsKey("city")) { airportListItem.City = datFile.MetadataLookup["city"]; } if (datFile.MetadataLookup.ContainsKey("region_code")) { airportListItem.RegionCode = datFile.MetadataLookup["region_code"]; } if (datFile.MetadataLookup.ContainsKey("icao_code")) { airportListItem.ICAO = datFile.MetadataLookup["icao_code"]; } if (datFile.MetadataLookup.ContainsKey("iata_code")) { airportListItem.IATA = datFile.MetadataLookup["iata_code"]; } if (datFile.MetadataLookup.ContainsKey("faa_code")) { airportListItem.FAACode = datFile.MetadataLookup["faa_code"]; } if (datFile.Pavements == null || datFile.Pavements.Count == 0) { airportListItem.HasPavements = false; } else { airportListItem.HasPavements = true; } if (sceneryFile.Type == "3D") { airportListItem.Is3D = true; } else { airportListItem.Is3D = false; } foreach (var runway in datFile.LandRunways) { airportListItem.RunwaySurfaceType = (int)runway.SurfaceType; } airportListItem.RunwayCount = datFile.LandRunways.Count; // If we couldn't get a value from the metadata we need to get it elsewhere if (!airportListItem.Latitude.HasValue || !airportListItem.Longitude.HasValue) { airportListItem.Latitude = tscFile.Location.Latitude; airportListItem.Longitude = tscFile.Location.Longitude; } csv.WriteRecord(airportListItem); csv.NextRecord(); } } else { log.ErrorFormat("Could not find the data for airport {0} make sure it is downloaded", airport.AirportCode); } } i++; } writer.Flush(); writer.Close(); writer = null; }
private void ConvertAirport(string icaoCode) { log.InfoFormat("Converting {0}", icaoCode); var airportXPFullDirectory = DirectoryHelper.GetAirportXPFullDirectory(icaoCode, XP2AFSConverterManager.Settings); var airportZipFilename = airportXPFullDirectory + @"\" + icaoCode + ".zip"; var airportFilename = airportXPFullDirectory + @"\airport.xml"; var airportSceneryFilename = airportXPFullDirectory + @"\scenery.xml"; var airportAFSFullDirectory = DirectoryHelper.GetAirportAFSFullDirectory(icaoCode, XP2AFSConverterManager.Settings); // Make sure the 'input' folder exists if (!Directory.Exists(airportAFSFullDirectory + @"\Input")) { Directory.CreateDirectory(airportAFSFullDirectory + @"\Input"); } var tscFilename = airportAFSFullDirectory + @"\Input\" + icaoCode + ".tsc"; var tocFilename = airportAFSFullDirectory + @"\Input\" + icaoCode + ".toc"; var tmcFilename = airportAFSFullDirectory + @"\Input\" + icaoCode + ".tmc"; if (File.Exists(airportZipFilename)) { // Parse the DST and DAT files var datFileLoader = new DATFileLoader(); var dsfFileLoader = new DSFFileLoader(); var datFile = datFileLoader.GetDATFileFromXPZip(icaoCode, airportZipFilename); var dsfFile = dsfFileLoader.GetDSFFileFromXPZip(icaoCode, airportZipFilename); // Create empty AFS files var tscFile = new TSCFile(); var tocFile = new TOCFile(); var tmcFile = new TMCFile(); // Convert the X-Plane files this.datConverter.Convert(datFile, tscFile, tocFile); this.dsfConverter.Convert(dsfFile, tscFile, tocFile); // Update the TMC file this.UpdateTMCFile(tmcFile, airportAFSFullDirectory); // Get strings of the AFS files var tscFileString = tscFile.ToString(); var tocFileString = tocFile.ToString(); var tmcFileString = tmcFile.ToString(); if (!Directory.Exists(airportAFSFullDirectory)) { Directory.CreateDirectory(airportAFSFullDirectory); } // Write the AFS files File.WriteAllText(tscFilename, tscFileString); File.WriteAllText(tocFilename, tocFileString); File.WriteAllText(tmcFilename, tmcFileString); var maxScriptGenerator = new MaxScriptGenerator(); maxScriptGenerator.GenerateScripts(icaoCode, datFile, dsfFile, tscFile, airportAFSFullDirectory, DirectoryHelper.GetTexturesDirectory(XP2AFSConverterManager.Settings)); log.Info("Airport conversion done"); } else { log.ErrorFormat("Could not find the data for airport {0} make sure it is downloaded", icaoCode); } }
public void Insert(ZipArchiveEntry Entry) { string efn = Entry.FullName.Replace('\\', '/'); int i = efn.LastIndexOf('/'); TOCFile file = new TOCFile(); file.Name = Entry.Name; file.FullName = efn; file.Entry = Entry; if (i != -1) { var dir = Directories.Create(efn.Substring(0, i)); file.Parent = dir; dir.FileTable.Add(file); } else { file.Parent = this; FileTable.Add(file); } }
public void Convert(DSFFile dsfFile, TSCFile tscFile, TOCFile tocFile) { this.dsfFile = dsfFile; }
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; } }
public static bool RebuildISO(string source, string target) { if (!Directory.Exists(source)) { return(false); } if (!Directory.Exists(source + "/&&systemdata")) { return(false); } if (!File.Exists(source + "/&&systemdata/Game.toc") || !File.Exists(source + "/&&systemdata/AppLoader.ldr") || !File.Exists(source + "/&&systemdata/Start.dol") || !File.Exists(source + "/&&systemdata/ISO.hdr")) { return(false); } long dolptr; long tocptr; long toclen; byte[] hdr = new byte[9280]; FileStream iso = new FileStream(target, FileMode.Create, FileAccess.Write); { FileInfo tocinfo = new FileInfo(source + "/&&systemdata/Game.toc"); FileInfo alinfo = new FileInfo(source + "/&&systemdata/AppLoader.ldr"); FileInfo dolinfo = new FileInfo(source + "/&&systemdata/Start.dol"); dolptr = 9280 + alinfo.Length; if (dolptr % 4096 != 0) { dolptr += 4096 - (dolptr % 4096); } tocptr = dolinfo.Length + dolptr; if (tocptr % 4096 != 0) { tocptr += 4096 - (tocptr % 4096); } toclen = tocinfo.Length; } using (FileStream hdrfile = new FileStream(source + "/&&systemdata/ISO.hdr", FileMode.Open, FileAccess.Read)) { if (hdrfile.Length != 9280) { return(false); } hdrfile.Read(hdr, 0, 9280); iso.Write(hdr, 0, 1056); Data.WriteUInt32(iso, (uint)dolptr); Data.WriteUInt32(iso, (uint)tocptr); Data.WriteUInt32(iso, (uint)toclen); Data.WriteUInt32(iso, (uint)toclen); iso.Write(hdr, 1072, 8208); } using (FileStream apploader = new FileStream(source + "/&&systemdata/AppLoader.ldr", FileMode.Open, FileAccess.Read)) { byte[] buf = new byte[dolptr - 9280 - 92]; apploader.Read(buf, 0, buf.Length); iso.Write(buf, 0, buf.Length); } Data.WritePaddingFast(iso, 92); using (FileStream dol = new FileStream(source + "/&&systemdata/Start.dol", FileMode.Open, FileAccess.Read)) { byte[] buf = new byte[tocptr - dolptr]; dol.Read(buf, 0, buf.Length); iso.Write(buf, 0, buf.Length); } using (FileStream toc = new FileStream(source + "/&&systemdata/Game.toc", FileMode.Open, FileAccess.Read)) { byte[] buf = new byte[toclen]; toc.Read(buf, 0, buf.Length); iso.Write(buf, 0, buf.Length); } long filestart = iso.Position + toclen; TOCFile tocfile = new TOCFile(source + "/&&systemdata/Game.toc"); List <TOCFile.Entry> entries = tocfile.EnumerateFiles(true); foreach (TOCFile.Entry entry in entries) { using (FileStream fs = new FileStream(source + "/" + entry.FullPath, FileMode.Open, FileAccess.Read)) { if (iso.Position < entry.offset) { Data.WritePaddingFast(iso, (int)(entry.offset - iso.Position)); } byte[] buf = new byte[entry.length]; fs.Read(buf, 0, buf.Length); iso.Write(buf, 0, buf.Length); } } iso.Close(); return(true); }
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 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 + "'"; } }
private static void ScanTOCsForBundles() { Debug.LogLn("Saving bundles into db..."); SQLiteConnection con = GetConnection(); con.Open(); SQLiteDataReader reader = getAll("tocfiles", con); StringBuilder sb = new StringBuilder(); List <string> files = new List <string>(); List <int> fileids = new List <int>(); while (reader.Read()) { fileids.Add(reader.GetInt32(0)); files.Add(reader.GetString(1)); } int counter = 0; Stopwatch sp = new Stopwatch(); sp.Start(); foreach (string file in files) { counter++; Debug.LogLn("Opening " + file + " ..."); TOCFile tocfile = new TOCFile(file); int counter2 = 0; foreach (TOCFile.TOCBundleInfoStruct info in tocfile.bundles) { counter2++; Bundle b; string pathsb = Helpers.GetFileNameWithOutExtension(file) + ".sb"; FileStream fs = new FileStream(pathsb, FileMode.Open, FileAccess.Read); fs.Seek(0, SeekOrigin.End); long filesize = fs.Position; if (info.offset > filesize) { fs.Close(); continue; } fs.Seek(info.offset, 0); byte[] buff = new byte[info.size]; fs.Read(buff, 0, info.size); if (tocfile.iscas) { if (buff[0] != 0x82) { continue; } List <BJSON.Entry> list = new List <BJSON.Entry>(); BJSON.ReadEntries(new MemoryStream(buff), list); b = Bundle.Create(list[0]); } else { uint magic = BitConverter.ToUInt32(buff, 4); if (magic != 0xd58e799d) { continue; } b = Bundle.Create(buff, true); } string log = " adding bundle: " + (counter2) + "/" + tocfile.bundles.Count + " "; if (info.isbase) { log += "ISBASEG "; } if (info.isdelta) { log += "ISDELTA "; } log += "ID: " + info.id; Debug.Log(log, true); AddBundle(fileids[counter - 1], tocfile.iscas, b, info, con); } counter2 = 0; var transaction = con.BeginTransaction(); foreach (TOCFile.TOCChunkInfoStruct info in tocfile.chunks) { AddGlobalChunk(fileids[counter - 1], info.id, info.sha1, info.offset, info.size, con); Debug.LogLn(" adding chunk: " + (counter2) + "/" + tocfile.chunks.Count + " " + Helpers.ByteArrayToHexString(info.id), counter2 % 1000 == 0); if (counter2 % 1000 == 0) { transaction.Commit(); transaction = con.BeginTransaction(); } counter2++; } transaction.Commit(); long elapsed = sp.ElapsedMilliseconds; long ETA = ((elapsed / counter) * files.Count); TimeSpan ETAt = TimeSpan.FromMilliseconds(ETA); Debug.LogLn((counter) + "/" + files.Count + " files done." + " - Elapsed: " + sp.Elapsed.ToString() + " ETA: " + ETAt.ToString()); } con.Close(); }
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 bool ExtractISO(string source, string target) { if (!File.Exists(source)) { return(false); } if (!Directory.Exists(target + "/&&systemdata")) { Directory.CreateDirectory(target + "/&&systemdata"); } long dolptr; long tocptr; long toclen; byte[] hdr = new byte[9280]; FileStream iso = new FileStream(source, FileMode.Open, FileAccess.Read); if (iso.Length < 9280) { return(false); } iso.Read(hdr, 0, 9280); dolptr = (hdr[1056] << 24) | (hdr[1057] << 16) | (hdr[1058] << 8) | hdr[1059]; tocptr = (hdr[1060] << 24) | (hdr[1061] << 16) | (hdr[1062] << 8) | hdr[1063]; toclen = (hdr[1064] << 24) | (hdr[1065] << 16) | (hdr[1066] << 8) | hdr[1067]; if (dolptr > iso.Length || tocptr > iso.Length || tocptr + toclen > iso.Length) { return(false); } using (FileStream hdrfile = new FileStream(target + "/&&systemdata/ISO.hdr", FileMode.Create, FileAccess.Write)) hdrfile.Write(hdr, 0, hdr.Length); using (FileStream apploader = new FileStream(target + "/&&systemdata/AppLoader.ldr", FileMode.Create, FileAccess.Write)) { byte[] buf = new byte[dolptr - 9280 - 92]; iso.Read(buf, 0, buf.Length); apploader.Write(buf, 0, buf.Length); } iso.Seek(dolptr, SeekOrigin.Begin); using (FileStream dol = new FileStream(target + "/&&systemdata/Start.dol", FileMode.Create, FileAccess.Write)) { byte[] buf = new byte[tocptr - dolptr]; iso.Read(buf, 0, buf.Length); dol.Write(buf, 0, buf.Length); } iso.Seek(tocptr, SeekOrigin.Begin); long filestart = iso.Position + toclen; TOCFile tocfile = new TOCFile(iso, (int)toclen); List <TOCFile.Entry> entries = tocfile.EnumerateEntries(); if (filestart % 4096 != 0) { filestart += 4096 - (filestart % 4096); } uint firstoffset = tocfile.FirstOffset; foreach (TOCFile.Entry entry in entries) { if (entry.children.Count > 0 && !Directory.Exists(target + "/" + entry.FullPath)) { Directory.CreateDirectory(target + "/" + entry.FullPath); } } foreach (TOCFile.Entry entry in entries) { if (entry.children.Count > 0) { continue; } using (FileStream fs = new FileStream(target + "/" + entry.FullPath, FileMode.Create, FileAccess.Write)) { byte[] buf = new byte[entry.length]; iso.Seek(entry.offset, SeekOrigin.Begin); iso.Read(buf, 0, buf.Length); fs.Write(buf, 0, buf.Length); } } iso.Close(); tocfile.Save(target + "/&&systemdata/Game.toc"); return(true); }
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(); }
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); }
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 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")); }