private void decompressFileToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { saveFileDialog.Filter = "Decompressed Data|*.dec|All files|*.*"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { using (Stream stream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader reader = new BinaryReader(stream)) { if (Helpers.LocateRawDataIdentifier(reader).Length < 2) { MessageBox.Show("Operation failed.", "Failure"); return; } BeginMarquee(); long secondRawData = Helpers.LocateRawDataIdentifier(reader)[1]; reader.BaseStream.Seek(10, SeekOrigin.Current); // ignore everything until the compression byte byte compression = reader.ReadByte(); bool success = false; Helpers.DoBackgroundWork(() => { if (secondRawData > 0) { if (compression == 0x08) { success = Odyssey.ReadFile(openFileDialog.FileName, false, saveFileDialog.FileName); } else if (compression == 0x05) { success = Steep.ReadFile(openFileDialog.FileName, false, saveFileDialog.FileName); } } }, () => { EndMarquee(); if (success) { MessageBox.Show("Decompressed file successfully. Check the folder where the compressed file is located.", "Success"); } else { MessageBox.Show("Unknown compression type.", "Failure"); } }); } } } } }
private void saveDecompressedDataAsToolStripMenuItem_Click(object sender, EventArgs e) { if (treeView.SelectedNode == null) { return; } EntryTreeNode node = (EntryTreeNode)treeView.SelectedNode; Forge forge = node.GetForge(); string text = node.Text; byte[] decompressedData = null; BeginMarquee(); Helpers.DoBackgroundWork(() => { Forge.FileEntry entry = forge.GetFileEntry(text); byte[] rawData = forge.GetRawData(entry); decompressedData = Odyssey.ReadFile(rawData); }, () => { EndMarquee(); // failure if (decompressedData.Length == 0 || decompressedData == null) { MessageBox.Show("Could not decompress data.", "Failure"); return; } saveFileDialog.FileName = string.Concat(node.Text, ".", Helpers.ExtensionForGame(node.Game)); saveFileDialog.Filter = $"{Helpers.NameOfGame(node.Game)} Data|*.{Helpers.ExtensionForGame(node.Game)}|All Files|*.*"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { File.WriteAllBytes(saveFileDialog.FileName, decompressedData); } catch (IOException ee) { Console.WriteLine(ee); } finally { MessageBox.Show("Done"); } } }); }
private List <EntryTreeNode> PopulateEntry(EntryTreeNode node) { // extract the contents from the forge Forge forge = node.GetForge(); byte[] data = forge.GetRawData(node.Offset, node.Size); // decompress string file = $"{node.Text}.{Helpers.ExtensionForGame(node.Game)}"; if (node.Game == Game.ODYSSEY) { Helpers.WriteToFile(file, Odyssey.ReadFile(data), true); } else if (node.Game == Game.ORIGINS) { Helpers.WriteToFile(file, Odyssey.ReadFile(data), true); } else if (node.Game == Game.STEEP) { Helpers.WriteToFile(file, Steep.ReadFile(data), true); } // path will hold the file name node.Path = file; // get resource locations and create nodes List <EntryTreeNode> nodes = new List <EntryTreeNode>(); using (Stream stream = new FileStream(Helpers.GetTempPath(file), FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader reader = new BinaryReader(stream)) { Helpers.ResourceLocation[] locations = Helpers.LocateResourceIdentifiers(reader); foreach (Helpers.ResourceLocation location in locations) { nodes.Add(new EntryTreeNode { Game = node.Game, Path = file, ResourceType = location.Type, Text = location.Type.ToString(), Type = EntryTreeNodeType.SUBENTRY }); } } } return(nodes); }
private void saveDecompressedDataAsToolStripMenuItem_Click(object sender, EventArgs e) { if (treeView.SelectedNode == null) { return; } EntryTreeNode node = (EntryTreeNode)treeView.SelectedNode; Forge forge = node.Forge; string text = node.Text; byte[] decompressedData = null; BeginMarquee(); Helpers.DoBackgroundWork(() => { Forge.FileEntry entry = forge.GetFileEntry(text); byte[] rawData = forge.GetRawData(entry); decompressedData = Odyssey.ReadFile(rawData); }, () => { EndMarquee(); saveFileDialog.FileName = $"{node.Text}.dec"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { File.WriteAllBytes(saveFileDialog.FileName, decompressedData); } catch (IOException ee) { Console.WriteLine(ee); } finally { MessageBox.Show("Done"); } } }); }
private void treeView_BeforeExpand(object sender, TreeViewCancelEventArgs e) { if (e.Node == null || e.Node.Tag == null) { return; } EntryTreeNode curNode = (EntryTreeNode)e.Node; string text = curNode.Text; string tag = (string)curNode.Tag; // a forge file if (tag.EndsWith(".forge")) { // dump resources used by currentForge if (currentForge != null) { currentForge.Dump(); } currentForge = new Forge(tag); Helpers.DoBackgroundWork(() => { currentForge.Read(); }, () => { // show message if there are over 10000 files in the forge if (currentForge.FileEntries.Length > 10000 && MessageBox.Show("This forge file contains more " + "than 10000 entries (" + currentForge.FileEntries.Length + " exactly). Loading all these " + "entries will take a while and Blacksmith will freeze.\n\nContinue?", "Large forge file!", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } // delete the empty tree node e.Node.Nodes.RemoveAt(0); // show and update the progress bar toolStripProgressBar.Visible = true; toolStripProgressBar.Value = 0; toolStripProgressBar.Maximum = currentForge.FileEntries.Length; // load entries into this forge's tree node for (int i = 0; i < currentForge.FileEntries.Length; i++) { string name = currentForge.FileEntries[i].NameTable.Name; EntryTreeNode node = new EntryTreeNode { Text = name, Tag = string.Format("{0}{1}{2}", curNode.Tag, FORGE_ENTRY_IDENTIFIER, name), // set the tag of this file's tree node Size = currentForge.FileEntries[i].IndexTable.RawDataSize }; node.Nodes.Add(new EntryTreeNode()); // add empty node (for entry's contents) curNode.Nodes.Add(node); toolStripProgressBar.Value++; } // reset and hide the progress bar toolStripProgressBar.Value = toolStripProgressBar.Maximum = 0; toolStripProgressBar.Visible = false; }); } // forge entry else if (tag.Contains(FORGE_ENTRY_IDENTIFIER) && !tag.Contains(FORGE_SUBENTRY_IDENTIFIER)) { // extract, if the entry has an empty node or if data as a file does not exist if (curNode.Nodes.Count == 1 && curNode.Nodes[0].Text == "" && !File.Exists(Helpers.GetTempPath(text))) { BeginMarquee(); Helpers.DoBackgroundWork(() => { Forge.FileEntry entry = currentForge.GetFileEntry(text); byte[] rawData = currentForge.GetRawData(entry); Helpers.WriteToTempFile(text, rawData); Odyssey.ReadFile(Helpers.GetTempPath(text)); }, () => { EndMarquee(); // remove nodes curNode.Nodes.Clear(); string combined = $"{Helpers.GetTempPath(text)}-combined"; // look for supported resource types using (Stream stream = new FileStream(combined, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader reader = new BinaryReader(stream)) { // create nodes based on located resource types foreach (Helpers.ResourceLocation loc in Helpers.LocateResourceIdentifiers(reader)) { curNode.Nodes.Add(new EntryTreeNode { Text = loc.Type.ToString(), Tag = string.Format("{0}{1}{2}", tag, FORGE_SUBENTRY_IDENTIFIER, loc.Type.ToString()), ResourceType = loc.Type }); } } } }); } } }
private void treeView_BeforeExpand(object sender, TreeViewCancelEventArgs e) { if (e.Node == null || e.Node.Tag == null) { return; } EntryTreeNode node = (EntryTreeNode)e.Node; int levels = LevelsDeep(node.FullPath); Forge forge = levels == 1 ? node.Forge : levels == 2 ? ((EntryTreeNode)node.Parent).Forge: ((EntryTreeNode)node.Parent.Parent).Forge; Console.WriteLine(levels + " deep"); string text = node.Text; string tag = (string)node.Tag; if (string.IsNullOrEmpty(text)) { return; } // a forge file if (tag.EndsWith(".forge")) { // dump resources used by currentForge if (currentForge != null) { currentForge.Dump(); } currentForge = new Forge(tag); Helpers.DoBackgroundWork(() => { currentForge.Read(); }, () => { // show message if there are over 10000 files in the forge if (forge.FileEntries.Length > 10000 && MessageBox.Show("This forge file contains more " + "than 10000 entries (" + forge.FileEntries.Length + " exactly). Loading all these " + "entries will take a while and Blacksmith will freeze.\n\nContinue?", "Large forge file!", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } // delete the empty tree node e.Node.Nodes.RemoveAt(0); // show and update the progress bar toolStripProgressBar.Visible = true; toolStripProgressBar.Value = 0; toolStripProgressBar.Maximum = forge.FileEntries.Length; Helpers.DoBackgroundWork(() => { // load entries into this forge's tree node if (!forge.IsFullyRead()) { return; } for (int i = 0; i < forge.FileEntries.Length; i++) { if (forge.FileEntries[i].NameTable == null) { continue; } string name = forge.FileEntries[i].NameTable.Name; EntryTreeNode n = new EntryTreeNode { Text = name, Forge = forge, Tag = $"{node.Tag}{FORGE_ENTRY_IDENTIFIER}{name}", // set the tag of this file's tree node Offset = forge.FileEntries[i].IndexTable.OffsetToRawDataTable, Size = forge.FileEntries[i].IndexTable.RawDataSize, Game = node.Game }; n.Nodes.Add(new EntryTreeNode()); // add empty node (for entry's contents) Invoke(new Action(() => { if (this != null && toolStripProgressBar.Value < 3001) // I recieved an error stating that the progress bar cannot go above 3001 { node.Nodes.Add(n); toolStripProgressBar.Value++; } })); } }, () => { // reset and hide the progress bar toolStripProgressBar.Value = toolStripProgressBar.Maximum = 0; toolStripProgressBar.Visible = false; }); }); } // forge entry else if (tag.Contains(FORGE_ENTRY_IDENTIFIER) && !tag.Contains(FORGE_SUBENTRY_IDENTIFIER)) { // extract, if the entry has an empty node if (node.Nodes.Count == 1 && node.Nodes[0].Text == "") { BeginMarquee(); Helpers.DoBackgroundWork(() => { byte[] rawData = forge.GetRawData(node.Offset, (int)node.Size); Helpers.WriteToFile($"{text}.ext", rawData, true); if (node.Game == Game.ODYSSEY || node.Game == Game.ORIGINS) // temporary, until this Origins no longer works like Odyssey { Odyssey.ReadFile(Helpers.GetTempPath($"{text}.ext")); } else { Steep.ReadFile(Helpers.GetTempPath($"{text}.ext")); } }, () => { EndMarquee(); // remove nodes node.Nodes.Clear(); // look for supported resource types. steep stays out, for now (because it causes crashes). string combined = $"{Helpers.GetTempPath(text)}.dec"; if (File.Exists(combined)) { using (Stream stream = new FileStream(combined, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader reader = new BinaryReader(stream)) { // create nodes based on located resource types foreach (Helpers.ResourceLocation loc in Helpers.LocateResourceIdentifiers(reader)) { node.Nodes.Add(new EntryTreeNode { Text = loc.Type.ToString(), Tag = $"{tag}{FORGE_SUBENTRY_IDENTIFIER}{loc.Type.ToString()}", ResourceType = loc.Type, Game = node.Game }); } } } } }); } } }