コード例 #1
0
ファイル: Header.cs プロジェクト: revel8n/rpftool
 public void Write(BigEndianBinaryWriter bw)
 {
     bw.Write((int)Identifier);
     bw.Write(EntryCount);
     bw.Write(Unknown1);
     bw.Write((int)-3);           // not encrypted, we won't write encrypted archives :)
 }
コード例 #2
0
ファイル: DirectoryEntry.cs プロジェクト: revel8n/rpftool
        public override void Write(BigEndianBinaryWriter bw)
        {
            bw.Write(Flags);
            bw.Write(NameOffset);

            uint temp = (uint)ContentEntryIndex | 0x80000000;
            bw.Write(temp);
            bw.Write(ContentEntryCount);
        }
コード例 #3
0
 public override void Write(BigEndianBinaryWriter bw)
 {
     bw.Write(NameOffset);
     bw.Write(Flags);
     bw.Write((int)((uint)ContentEntryIndex | 0x80000000));
     /*
     if (newEntryIndex > 0)
         bw.Write((int)((uint)newEntryIndex | 0x80000000));
     else
         bw.Write((int)((uint)ContentEntryIndex | 0x80000000));
      */
     bw.Write(ContentEntryCount);
     bw.Write(UNKNOWN);
 }
コード例 #4
0
ファイル: File.cs プロジェクト: reditec/RDR-Explorer
        public void save(FileStream newRPFstream, BackgroundWorker thread, DoWorkEventArgs e)
        {
            int fileprogress = 0;
            try
            {
                if (_stream != null)
                {
                    _stream.Position = 0;
                    var bw = new BigEndianBinaryWriter(newRPFstream);
                    var br = new BinaryReader(_stream);

                    Header.EntryCount = TOC.count;
                    Header.Write(bw);
                    bw.Write(new byte[Header.EntryCount * 20]);
                    var tocOffset = 0x10;
                    TOC.ReorderOffset();
                    bw.Write(new byte[(TOC.fileStart-1) - bw.BaseStream.Position]); // 614400
                    //if (System.IO.File.Exists(@"D:\xbox stuff\xboxtemp\RDR undead\offsets.txt"))
                    //    System.IO.File.Delete(@"D:\xbox stuff\xboxtemp\RDR undead\offsets.txt");
                    //if (System.IO.File.Exists(@"D:\xbox stuff\xboxtemp\RDR undead\offsets_mod.txt"))
                    //    System.IO.File.Delete(@"D:\xbox stuff\xboxtemp\RDR undead\offsets_mod.txt");
                    foreach (var entry in TOC)
                    {
                        //    System.IO.File.AppendAllText(@"D:\xbox stuff\xboxtemp\RDR undead\offsets.txt", entry._Offset.ToString() + " - " + entry.count + Environment.NewLine);
                        if ((thread.CancellationPending == true))
                        {
                            e.Cancel = true;
                            return;
                        }

                        thread.ReportProgress(Convert.ToInt32(((double)fileprogress / TOC.count) * 100.0));
                        var fileEntry = entry as FileEntry;
                        if (fileEntry != null)
                        {
                            if (!fileEntry.IsResourceFile && !fileEntry.IsCompressed && fileEntry.SizeInArchive > 100000)
                            {
                                long paddingsize = (RoundUp(bw.BaseStream.Position, 2048)) - bw.BaseStream.Position;
                                bw.Write(new byte[(int)paddingsize]);
                            }
                            else if (fileEntry.IsResourceFile)
                            {
                                long paddingsize = (RoundUp(bw.BaseStream.Position, 2048)) - bw.BaseStream.Position;
                                if (paddingsize == 0)
                                    paddingsize = 2048;
                                bw.Write(new byte[(int)paddingsize]);
                            }
                            else
                            {
                                long paddingsize;
                                if (fileEntry.SizeInArchive > 110000)
                                    paddingsize = (RoundUp(bw.BaseStream.Position, 2048)) - bw.BaseStream.Position;
                                else
                                {
                                    paddingsize = (RoundUp(bw.BaseStream.Position, 8)) - bw.BaseStream.Position;
                                    if (paddingsize == 0)
                                        paddingsize = 8;
                                }
                                bw.Write(new byte[(int)paddingsize]);
                            }
                            if (fileEntry.CustomData != null)
                            {
                                fileEntry.Offset = bw.BaseStream.Position;
                                bw.Write(fileEntry.CustomData);
                                //fileEntry.SetCustomData(null);
                            }
                            else
                            {
                                br.BaseStream.Position = fileEntry.Offset;
                                byte[] buffer = br.ReadBytes(fileEntry.SizeInArchive);
                                fileEntry.Offset = bw.BaseStream.Position;
                                bw.Write(buffer);
                            }
                        }
                        fileprogress++;
                        //   System.IO.File.AppendAllText(@"D:\xbox stuff\xboxtemp\RDR undead\offsets_mod.txt", entry._Offset.ToString() + " - " + entry.count + Environment.NewLine);
                    }
                    if (br.BaseStream.Length > bw.BaseStream.Length)
                    {
                        bw.Write(new byte[br.BaseStream.Length - bw.BaseStream.Length]);
                    }
                    bw.Seek(tocOffset, SeekOrigin.Begin);
                    TOC.ReorderCount();
                    TOC.Write(bw);
                    newRPFstream.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(fileprogress.ToString() + ex.Message + Environment.NewLine + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #5
0
ファイル: FileEntry.cs プロジェクト: reditec/RDR-Explorer
 public override void Write(BigEndianBinaryWriter bw)
 {
     bw.Write(NameOffset);
     bw.Write(SizeInArchive);
     if (IsResourceFile)
         bw.Write((int)((Offset / 8) | (byte)ResourceType));
     else
         bw.Write((int)(Offset / 8));
     var temp = DecompressedSize;
     if (IsCompressed)
     {
         temp |= 0x40000000;
     }
     if (IsResourceFile)
     {
         temp = (int)(temp | 0x80000000);
         temp = Flags1;
     }
     bw.Write(temp);
     bw.Write(Flags2);
 }
コード例 #6
0
ファイル: TOCEntry.cs プロジェクト: reditec/RDR-Explorer
 public abstract void Write(BigEndianBinaryWriter bw);
コード例 #7
0
ファイル: File.cs プロジェクト: revel8n/rpftool
        public void save()
        {
            try
            {
                if (_stream != null)
                {
                    if (_stream.Length > 0)
                    {
                        _stream.Position = 0;

                        var bw = new BigEndianBinaryWriter(_stream);

                        Header.Write(bw);

                        // Recalculate the offset/sizes of the TOC entries
                        var tocOffset = 0x800;

                        foreach (var entry in TOC)
                        {
                            var fileEntry = entry as FileEntry;
                            if (fileEntry != null && fileEntry.CustomData != null)
                            {

                                if (fileEntry.CustomData.Length <= fileEntry.SizeInArchive)
                                {
                                    // Clear up the old data
                                    _stream.Seek(fileEntry.Offset, SeekOrigin.Begin);
                                    bw.Write(new byte[fileEntry.SizeInArchive]);

                                    // We can fit it in the existing block... so lets do that.
                                    _stream.Seek(fileEntry.Offset, SeekOrigin.Begin);

                                    fileEntry.SizeInArchive = fileEntry.CustomData.Length;
                                    fileEntry.Size = fileEntry.customsize;
                                    bw.Write(fileEntry.CustomData);
                                }
                                else
                                {
                                    bool zero = true;
                                    byte[] zbuffer = new byte[fileEntry.CustomData.Length - fileEntry.SizeInArchive];
                                    zbuffer = ReadData(fileEntry.Offset + fileEntry.SizeInArchive, zbuffer.Length);
                                    foreach (byte b in zbuffer)
                                    {
                                        if (b != 0)
                                        {
                                            zero = false;
                                            break;
                                        }
                                    }
                                    if (zero == false)
                                    {
                                        MessageBox.Show("The new data was " + Convert.ToString(fileEntry.CustomData.Length - fileEntry.SizeInArchive) + " bytes larger than the original and there was not enough trailing space to write the file, make the file smaller and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                    else
                                    {
                                        // Clear up the old data
                                        _stream.Seek(fileEntry.Offset, SeekOrigin.Begin);
                                        bw.Write(new byte[fileEntry.SizeInArchive]);

                                        // We can fit it in the existing block... so lets do that.
                                        _stream.Seek(fileEntry.Offset, SeekOrigin.Begin);

                                        fileEntry.SizeInArchive = fileEntry.CustomData.Length;
                                        fileEntry.Size = fileEntry.customsize;
                                        bw.Write(fileEntry.CustomData);
                                    }
                                }
                                fileEntry.SetCustomData(null);
                            }
                        }

                        _stream.Seek(tocOffset, SeekOrigin.Begin);

                        TOC.Write(bw);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
               // throw new Exception(ex.Message, ex);
            }
        }
コード例 #8
0
ファイル: FileEntry.cs プロジェクト: revel8n/rpftool
 public override void Write(BigEndianBinaryWriter bw)
 {
 }