private static void WriteFileHeader(BinderFile file, BinaryWriterEx bw, int index, Binder.Format format) { bw.WriteByte((byte)file.Flags); bw.WriteByte(0); bw.WriteByte(0); bw.WriteByte(0); bw.ReserveInt32($"CompressedSize{index}"); bw.ReserveUInt32($"FileData{index}"); if (Binder.HasID(format)) { bw.WriteInt32(file.ID); } if (Binder.HasName(format)) { bw.ReserveUInt32($"FileName{index}"); } if (Binder.HasUncompressedSize(format)) { bw.WriteInt32(file.Bytes.Length); } }
private static BinderFile ReadFile(BinaryReaderEx br, Binder.Format format) { Binder.FileFlags flags = br.ReadEnum8 <Binder.FileFlags>(); br.AssertByte(0); br.AssertByte(0); br.AssertByte(0); int compressedSize = br.ReadInt32(); uint fileOffset = br.ReadUInt32(); int id = -1; if (Binder.HasID(format)) { id = br.ReadInt32(); } string name = null; if (Binder.HasName(format)) { uint fileNameOffset = br.ReadUInt32(); name = br.GetShiftJIS(fileNameOffset); } if (Binder.HasUncompressedSize(format)) { int uncompressedSize = br.ReadInt32(); } byte[] bytes; if (Binder.IsCompressed(flags)) { br.StepIn(fileOffset); bytes = SFUtil.ReadZlib(br, compressedSize); br.StepOut(); } else { bytes = br.GetBytes(fileOffset, compressedSize); } return(new BinderFile(flags, id, name, bytes)); }
private static BinderFile ReadFile(BinaryReaderEx br, bool unicode, Binder.Format format) { Binder.FileFlags flags = br.ReadEnum8 <Binder.FileFlags>(); br.AssertByte(0); br.AssertByte(0); br.AssertByte(0); br.AssertInt32(-1); long compressedSize = br.ReadInt64(); if (Binder.HasUncompressedSize(format)) { long uncompressedSize = br.ReadInt64(); } uint fileOffset = br.ReadUInt32(); int id = -1; if (Binder.HasID(format)) { id = br.ReadInt32(); } string name = null; if (Binder.HasName(format)) { uint nameOffset = br.ReadUInt32(); if (unicode) { name = br.GetUTF16(nameOffset); } else { name = br.GetShiftJIS(nameOffset); } } if (format == Binder.Format.x20) { br.AssertInt64(0); } byte[] bytes; if (Binder.IsCompressed(flags)) { if (format == Binder.Format.x2E) { bytes = br.GetBytes(fileOffset, (int)compressedSize); bytes = DCX.Decompress(bytes, out DCX.Type type); if (type != DCX.Type.DemonsSoulsEDGE) { throw null; } } else { br.StepIn(fileOffset); bytes = SFUtil.ReadZlib(br, (int)compressedSize); br.StepOut(); } } else { bytes = br.GetBytes(fileOffset, (int)compressedSize); } return(new BinderFile(flags, id, name, bytes)); }