public virtual void WriteEndAtom()
        {
            var currentAtomData = atomStack.Peek();

            long currentPostion = writer.BaseStream.Position;

            writer.Seek((int)currentAtomData.Position, SeekOrigin.Begin);
            if (currentAtomData.IsExtendedSize)
            {
                writer.Seek(8, SeekOrigin.Current);
                writer.Write((ulong)currentAtomData.Size);
            }
            else if (currentAtomData.Size > uint.MaxValue)
            {
                if (currentAtomData.PrecededByWideAtom)
                {
                    writer.Seek(-8, SeekOrigin.Current);
                    WriteAtomHeader(currentAtomData.type, (ulong)currentAtomData.Size);
                }
                else
                {
                    throw new Exception();
                }
            }
            else
            {
                writer.Write((uint)currentAtomData.Size);
            }

            writer.Seek((int)currentPostion, SeekOrigin.Begin);
            lastWasWideAtom = currentAtomData.type == 1234;
            atomStack.Pop();
        }
        public virtual void WriteEndBox()
        {
            long currentPostion = writer.BaseStream.Position;

            writer.Seek((int)boxStack.Peek().Position, SeekOrigin.Begin);
            writer.Write((uint)boxStack.Peek().Size);

            writer.Seek((int)currentPostion, SeekOrigin.Begin);

            boxStack.Pop();
        }
Пример #3
0
        public void Save(Stream outputStream)
        {
            using (var writer = new BigEndianBinaryWriter(outputStream))
            {
                // -- WRITE HEADER
                writer.Write(FileLength);
                writer.Write(HeaderLength);
                writer.Write(CommandLength);
                writer.Write(StringDeclarationLength);
                writer.Write(CalculatedStringDefinitionLength);
                writer.Write(Unknown1);
                writer.Write(Unknown2);
                writer.Write(Unknown3);
                writer.Write(Unknown4);

                // -- WRITE COMMAND SECTION
                writer.Write(CommandSection);

                // -- WRITE STRING LENGTHS
                writer.Write(0);
                writer.Write(1);

                int bytes = 1;
                for (int i = 0; i < Strings.Length - 1; i++)
                {
                    bytes += JIS.GetByteCount(Strings[i]) + 1;
                    writer.Write(bytes);
                }

                writer.Write((byte)0);

                foreach (String str in Strings)
                {
                    writer.Write(JIS.GetBytes(str));
                    writer.Write((byte)0);
                }

                writer.Write(EndSequence);

                long length = writer.BaseStream.Position;
                writer.Seek(0, SeekOrigin.Begin);
                writer.Write((int)length);
            }
        }
Пример #4
0
        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);
            }
        }