/// <summary> /// Declare a new instance of a package file /// </summary> /// <param name="file">The package file's path</param> public Package(String file) { DBPF pFile = new DBPF(file); try { IoBuffer fileR = new IoBuffer(File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read)); filePath = file; file_ = fileR; } catch { throw new Exception("File could not be opened; is the path valid?"); } }
private void btnLoad_Click(object sender, EventArgs e) { lblTitle.Text = "Loading..."; lblTitle.Refresh(); // Set the title text and refresh //lsbContents.Items.Clear(); // Clear the items before we begin DBPF dbpfFile = new DBPF(txbPath.Text); DBPFEntry dbpfFileEntry = new DBPFEntry(); // ---------------------------- // Test UI Data file info // ---------------------------- // Index info: // ---------------------------- // Index type: ptShortFileIndex // Version: 0x0000000100000001 // Hole index empty // ---------------------------- // File info: // ---------------------------- // Instance ID: 0x49060F07 // Instance (high): 0x00000000 // Group: 0xA99D8A11 // Type: UI (0x00000000) // Compressed: Yes :( // Size: 0x000014cf // ---------------------------- Package pkg = new Package(txbPath.Text); //richTextBox1.Text = pkg.Read(0x0000047E, 0x0000006A, pkg.file_); richTextBox2.Text = pkg.Read(1, pkg.file_); //lblLeftLen.Text = richTextBox1.Text.Length.ToString(); lblD2.Text = richTextBox2.Text.Length.ToString() + " bytes"; MessageBox.Show(pkg.numFiles.ToString()); int i = 1; while (i < pkg.numFiles) { //lsbContents.Items.Add("File " + i.ToString()); } this.lblTitle.Text = "The Sims 2 Package Extractor"; // ---------------------------- }
/// <summary> /// Read a file from the package /// </summary> /// <param name="filenumber">The number of the file to read</param> /// <param name="file">The package file's IoBuffer</param> /// <returns></returns> public string Read(int filenumber, IoBuffer file) { // Read header int i = 1; string toReturn = ""; DBPF dFile = new DBPF(filePath); DBPFEntry dEntry = new DBPFEntry(); UInt32 lastPos = 0x00000000; file.Seek(SeekOrigin.Begin, 0); file.Skip(24); UInt32 numEntries = file.ReadUInt32(); numFiles = (int) numEntries; //UInt32 indOffset = file.ReadUInt32(); //file.Skip(16); file.Skip(20); UInt32 minVersion = file.ReadUInt32(); //file.Seek(SeekOrigin.Begin, indOffset); // Goto the start of the index file.Seek(SeekOrigin.Begin, 86); // Goto the start of the index Byte[] fOffset; Byte[] fSize; while (i <= filenumber) { file.Seek(SeekOrigin.Begin, lastPos + 86); if ((int)minVersion == 1) { file.ReadBytes(11); fOffset = file.ReadBytes(2); String temp = BitConverter.ToString(fOffset).Replace("-", ""); lastPos = lastPos + UInt32.Parse(temp, System.Globalization.NumberStyles.AllowHexSpecifier); dEntry.FileOffset = 0x00000066 + UInt32.Parse(temp, System.Globalization.NumberStyles.AllowHexSpecifier); //uifile1.FileOffset = fOffset; file.Seek(SeekOrigin.Current, -2); fSize = file.ReadBytes(3); temp = BitConverter.ToString(fSize).Replace("-", ""); lastPos = lastPos + UInt32.Parse(temp, System.Globalization.NumberStyles.AllowHexSpecifier); //uifile1.FileSize = fSize; dEntry.FileSize = UInt32.Parse(temp, System.Globalization.NumberStyles.AllowHexSpecifier); //prevFileStop = BitConverter.ToInt64(fOffset, 0) + BitConverter.ToInt64(fSize, 0); } else { file.ReadBytes(16); fOffset = file.ReadBytes(2); String temp = BitConverter.ToString(fOffset).Replace("-", ""); lastPos = lastPos + UInt32.Parse(temp, System.Globalization.NumberStyles.AllowHexSpecifier); dEntry.FileOffset = 0x00000066 + UInt32.Parse(temp, System.Globalization.NumberStyles.AllowHexSpecifier); //uifile1.FileOffset = fOffset; file.Seek(SeekOrigin.Current, -2); fSize = file.ReadBytes(3); temp = BitConverter.ToString(fSize).Replace("-", ""); lastPos = lastPos + UInt32.Parse(temp, System.Globalization.NumberStyles.AllowHexSpecifier); //uifile1.FileSize = fSize; dEntry.FileSize = UInt32.Parse(temp, System.Globalization.NumberStyles.AllowHexSpecifier); //prevFileStop = BitConverter.ToInt64(fOffset, 0) + BitConverter.ToInt64(fSize, 0); } if (i != filenumber) i++; else break; } toReturn = Hex2Ascii(BitConverter.ToString(dFile.GetEntry(dEntry)).Replace("-", "")); return toReturn; }
/// <summary> /// Read a file from the package /// </summary> /// <param name="fileSize">The size of the file</param> /// <param name="fileOffset">The offset of the file</param> /// <param name="file">The package file's IoBuffer</param> /// <returns></returns> public string Read(UInt32 fileSize, UInt32 fileOffset, IoBuffer file) { string toReturn = ""; DBPF dFile = new DBPF(filePath); DBPFEntry dEntry = new DBPFEntry(); file.Seek(SeekOrigin.Begin, 0); file.Skip(24); UInt32 numEntries = file.ReadUInt32(); file.Skip(20); UInt32 minVersion = file.ReadUInt32(); file.Seek(SeekOrigin.Begin, 86); // Go to the start of the index dEntry.FileOffset = fileOffset; dEntry.FileSize = fileSize; toReturn = Hex2Ascii(BitConverter.ToString(dFile.GetEntry(dEntry)).Replace("-", "")); return toReturn; }