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 void Write(BinaryWriterEx bhdWriter, BinaryWriterEx bdtWriter) { bhdWriter.WriteASCII("BHF3"); bhdWriter.WriteFixStr(BHDTimestamp, 8); bhdWriter.WriteByte((byte)Format); bhdWriter.WriteByte(0); bhdWriter.WriteByte(0); bhdWriter.WriteByte(0); bhdWriter.BigEndian = Binder.ForceBigEndian(Format); bhdWriter.WriteInt32(Files.Count); bhdWriter.WriteInt32(0); bhdWriter.WriteInt32(0); bhdWriter.WriteInt32(0); bdtWriter.WriteASCII("BDF3"); bdtWriter.WriteFixStr(BDTTimestamp, 8); bdtWriter.WriteInt32(0); for (int i = 0; i < Files.Count; i++) { BinderFile file = Files[i]; bhdWriter.WriteByte(0x40); bhdWriter.WriteByte(0); bhdWriter.WriteByte(0); bhdWriter.WriteByte(0); bhdWriter.WriteInt32(file.Bytes.Length); bhdWriter.WriteUInt32((uint)bdtWriter.Position); bhdWriter.WriteInt32(i); bhdWriter.ReserveUInt32($"FileName{i}"); if (Binder.HasUncompressedSize(Format)) { bhdWriter.WriteInt32(file.Bytes.Length); } bdtWriter.WriteBytes(file.Bytes); bdtWriter.Pad(0x10); } for (int i = 0; i < Files.Count; i++) { BinderFile file = Files[i]; bhdWriter.FillUInt32($"FileName{i}", (uint)bhdWriter.Position); bhdWriter.WriteShiftJIS(file.Name, true); } }
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)); }
public FileHeader(BinaryReaderEx br, Binder.Format format) { br.AssertByte(0x40); br.AssertByte(0); br.AssertByte(0); br.AssertByte(0); Size = br.ReadInt32(); Offset = br.ReadUInt32(); ID = br.ReadInt32(); uint fileNameOffset = br.ReadUInt32(); if (Binder.HasUncompressedSize(format)) { int uncompressedSize = br.ReadInt32(); } Name = br.GetShiftJIS(fileNameOffset); }
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)); }