public archivedfile(archivedfile basis) { form1 = basis.form1; spriteEditor = basis.spriteEditor; hash = basis.hash; offset = basis.offset; size = basis.size; filebytes = basis.filebytes; filemagic = basis.filemagic; filename = basis.filename; parentarcfile = basis.parentarcfile; parentrdtfile = basis.parentrdtfile; treeNode = basis.treeNode; should_this_file_be_decompressed__and_compressed_when_read = basis.should_this_file_be_decompressed__and_compressed_when_read; has_LZ11_filesize = basis.has_LZ11_filesize; was_LZ10_compressed = basis.was_LZ10_compressed; was_LZ11_compressed = basis.was_LZ11_compressed; STstrings = basis.STstrings; textFileStringType = basis.textFileStringType; rdtSubfileDataList = basis.rdtSubfileDataList; RDTSpriteNumFrames = basis.RDTSpriteNumFrames; RDTSpriteWidth = basis.RDTSpriteWidth; RDTSpriteHeight = basis.RDTSpriteHeight; RDTSpriteBPP = basis.RDTSpriteBPP; RDTSpriteFrameDurations = basis.RDTSpriteFrameDurations; RDTSpriteAlphaColour = basis.RDTSpriteAlphaColour; }
private void compareArcs_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Title = "Select first arc file"; openFileDialog1.CheckFileExists = true; openFileDialog1.CheckPathExists = true; openFileDialog1.Filter = "1PP archives (*.arc)|*.arc"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { OpenFileDialog openFileDialog2 = new OpenFileDialog(); openFileDialog2.Title = "Select second arc file"; openFileDialog2.CheckFileExists = true; openFileDialog2.CheckPathExists = true; openFileDialog1.Filter = "1PP archives (*.arc)|*.arc"; if (openFileDialog2.ShowDialog() == DialogResult.OK) { arcfile arc1 = new arcfile(); arc1.arcname = Path.GetFileName(openFileDialog1.FileName); arc1.filename = openFileDialog1.FileName; arc1.filebytes = File.ReadAllBytes(openFileDialog1.FileName); arc1.form1 = form1; arc1.ReadArc(); arcfile arc2 = new arcfile(); arc2.arcname = Path.GetFileName(openFileDialog2.FileName); arc2.filename = openFileDialog2.FileName; arc2.filebytes = File.ReadAllBytes(openFileDialog2.FileName); arc2.form1 = form1; arc2.ReadArc(); List <string> report = new List <string>(); foreach (archivedfile f in arc1.archivedfiles) { if (arc2.GetFileWithHash(f.hash) == null) { //if arc2 straight up doesn't have it string evaluatedFilename = f.filename; if (f.filename == "FILENAME_NOT_SET") { evaluatedFilename = f.hash.ToString(); } report.Add("File " + evaluatedFilename + " was present in " + Path.GetFileNameWithoutExtension(arc1.filename) + ", but not " + Path.GetFileNameWithoutExtension(arc2.filename) + "!"); } else { archivedfile equivalent = arc2.GetFileWithHash(f.hash); if (equivalent != null) { f.ReadFile(); equivalent.ReadFile(); if (f.filebytes.Length != equivalent.filebytes.Length) { //if it's present in both, but with different filesizes string evaluatedFilename = f.filename; if (f.filename == "FILENAME_NOT_SET") { evaluatedFilename = f.hash.ToString(); } report.Add("File " + evaluatedFilename + " was present in both archives, but is a different size in " + Path.GetFileNameWithoutExtension(arc2.filename) + "!"); } } } } foreach (archivedfile f in arc2.archivedfiles) { if (arc1.GetFileWithHash(f.hash) == null) { //if arc1 straight up doesn't have it string evaluatedFilename = f.filename; if (f.filename == "FILENAME_NOT_SET") { evaluatedFilename = f.hash.ToString(); } report.Add("File " + evaluatedFilename + " was present in " + Path.GetFileNameWithoutExtension(arc2.filename) + ", but not " + Path.GetFileNameWithoutExtension(arc1.filename) + "!"); } //don't need to do the second part again because it was already two-way } SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = ".txt files (*.txt)|*.txt"; saveFileDialog1.Title = "Save report"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { File.WriteAllLines(saveFileDialog1.FileName, report.ToArray()); } } } }
public void LoadFromFile(string FileName) { filebytes = File.ReadAllBytes(FileName); filepath = FileName; saveFileEditor.inventoryBox.Items.Clear(); saveFileEditor.exportDownloadArc.Enabled = false; using (BinaryReader reader = new BinaryReader(File.Open(FileName, FileMode.Open))) { game = (Game)reader.ReadInt32(); if (game == Game.EPF) { reader.BaseStream.Position = 0x100; if (reader.ReadInt32() == 0x00000000) { //then there's no embedded arc file, skip to later in the file } else { //load embedded arc file (e.g. puffle pranksters) reader.BaseStream.Position -= 0x04; embeddedArc = new arcfile(); embeddedArc.form1 = saveFileEditor.form1; embeddedArc.filename = Path.Combine(Path.GetDirectoryName(FileName), "download.arc"); embeddedArc.filecount = reader.ReadUInt32(); reader.BaseStream.Position = (0x104 + (0x0C * embeddedArc.filecount)) - 0x08; //go to where the offset for the last file is listed int filesize = reader.ReadInt32(); //the arc is at least as big as the offset of the last file, we just need to add the size of the last file to bring us up to the end of the arc int sizeToAddToTotalSize = reader.ReadInt32(); if (sizeToAddToTotalSize < 0) //if it's one of those weird FF sizes (for LZ11-compressed files I guess) { sizeToAddToTotalSize += (-2 * sizeToAddToTotalSize); } filesize += sizeToAddToTotalSize; while ((filesize % 4) != 0) { filesize++; } filesize += 4; //account for checksum embeddedArc.filebytes = new byte[filesize]; Array.Copy(filebytes, 0x100, embeddedArc.filebytes, 0, filesize); embeddedArc.ReadArc(); //the arc is then padded with 0x00 until the end of the line, and then the CRC-32 of the arc file follows. Byte[] newsletterImage = new byte[0x2960]; Array.Copy(filebytes, 0xCCF0, newsletterImage, 0, 0x2960); Console.WriteLine("test"); GetDownloadableMissionName(); Console.WriteLine("test2"); saveFileEditor.exportDownloadArc.Enabled = true; //Bitmap bm = embeddedArc.archivedfiles[0].NBFCtoImage(newsletterImage); //bm.Save(filepath + "image.png"); //File.WriteAllBytes(filepath+"image.raw",newsletterImage); Console.WriteLine("Last offset was " + reader.BaseStream.Position); } //LOAD INVENTORY reader.BaseStream.Position = 0xF650; saveFileEditor.inventoryBox.Items.Clear(); for (int i = 0; i < ItemsEPF.Length; i++) { saveFileEditor.inventoryBox.Items.Add(ItemsEPF[i]); if (reader.ReadByte() == 0x01) { saveFileEditor.inventoryBox.SetItemChecked(i, true); } } //LOAD LIFETIME COINS reader.BaseStream.Position = 0xF704; saveFileEditor.lifetimeCoins.Value = reader.ReadUInt32(); //lifetime coins //LOAD HIGH SCORES reader.BaseStream.Position = 0xF708; saveFileEditor.highScore1.Value = reader.ReadUInt32(); //snowboarding reader.BaseStream.Position = 0xF710; saveFileEditor.highScore2.Value = reader.ReadUInt32(); //cart surfer reader.BaseStream.Position = 0xF70C; saveFileEditor.highScore3.Value = reader.ReadUInt32(); //ice fishing reader.BaseStream.Position = 0xF714; saveFileEditor.highScore5.Value = reader.ReadUInt32(); //dance challenge reader.BaseStream.Position = 0xF718; saveFileEditor.highScore4.Value = reader.ReadUInt32(); //jet pack adventure //yes, I know that 4 and 5 are in the wrong order here, it's so that it matches the order shown in-game reader.BaseStream.Position = 0xF71C; saveFileEditor.highScore6.Value = reader.ReadUInt32(); //snow trekker //READ PENGUIN NAME saveFileEditor.penguinNameTextBox.Text = GetStringAtOffset(0xF720); oldPenguinName = saveFileEditor.penguinNameTextBox.Text; //READ ONLINE NAMES saveFileEditor.onlineName1.Text = GetStringAtOffset(0xF73A); oldOnlineName1 = saveFileEditor.penguinNameTextBox.Text; saveFileEditor.onlineName2.Text = GetStringAtOffset(0xF754); oldOnlineName2 = saveFileEditor.penguinNameTextBox.Text; saveFileEditor.onlineName3.Text = GetStringAtOffset(0xF76E); oldOnlineName3 = saveFileEditor.penguinNameTextBox.Text; //READ COINS reader.BaseStream.Position = 0xF7E4; saveFileEditor.coinsChooser.Value = reader.ReadUInt32(); //LOAD CURRENT MISSION reader.BaseStream.Position = 0xF7EC; currentMission = reader.ReadByte(); saveFileEditor.currentMissionChooser.Items.Clear(); foreach (string s in MissionNamesEPF) { saveFileEditor.currentMissionChooser.Items.Add(s); } saveFileEditor.currentMissionChooser.SelectedIndex = currentMission; //READ PENGUIN COLOUR reader.BaseStream.Position = 0xF7F0; penguinColour = reader.ReadByte(); saveFileEditor.colourChooser.Items.Clear(); foreach (string s in PenguinColours) { saveFileEditor.colourChooser.Items.Add(s); } saveFileEditor.colourChooser.SelectedIndex = penguinColour; //LOAD PUFFLES reader.BaseStream.Position = 0xF7FB; GetPuffles(reader.ReadByte()); //LOAD UNLOCKS (map, puffle whistle, etc.) reader.BaseStream.Position = 0xF7FC; GetUnlocks(reader.ReadByte()); //in Herbert's Revenge at least, the u16 at offset 0xA6 is a bitfield describing which missions are unlocked //(number of bits set + 1) = current mission } else if (game == Game.HR) { //READ PENGUIN COLOUR reader.BaseStream.Position = 0x24; penguinColour = reader.ReadByte(); saveFileEditor.colourChooser.Items.Clear(); foreach (string s in PenguinColours) { saveFileEditor.colourChooser.Items.Add(s); } saveFileEditor.colourChooser.SelectedIndex = penguinColour; //READ COINS reader.BaseStream.Position = 0x28; saveFileEditor.coinsChooser.Value = reader.ReadUInt32(); //READ PENGUIN NAME saveFileEditor.penguinNameTextBox.Text = GetStringAtOffset(0x58); oldPenguinName = saveFileEditor.penguinNameTextBox.Text; //READ CURRENT MISSION reader.BaseStream.Position = 0xA6; GetCurrentMission(reader.ReadUInt16()); saveFileEditor.currentMissionChooser.Items.Clear(); foreach (string s in MissionNamesHR) { saveFileEditor.currentMissionChooser.Items.Add(s); } saveFileEditor.currentMissionChooser.SelectedIndex = currentMission; //LOAD INVENTORY reader.BaseStream.Position = 0x0124; saveFileEditor.inventoryBox.Items.Clear(); for (int i = 0; i < ItemsHR.Length; i++) { saveFileEditor.inventoryBox.Items.Add(ItemsHR[i]); if (reader.ReadByte() == 0x01) { saveFileEditor.inventoryBox.SetItemChecked(i, true); } } } else { filepath = null; filebytes = null; MessageBox.Show("That is not a Club Penguin DS save file!", "File magic not recognised", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }