private static byte[] DecompressDCXDFLT(BinaryReaderEx br, Type type) { br.AssertASCII("DCX\0"); if (type == Type.DCX_DFLT_10000_24_9 || type == Type.DCX_DFLT_10000_44_9) { br.AssertInt32(0x10000); } else if (type == Type.DCX_DFLT_11000_44_8 || type == Type.DCX_DFLT_11000_44_9) { br.AssertInt32(0x11000); } br.AssertInt32(0x18); br.AssertInt32(0x24); if (type == Type.DCX_DFLT_10000_24_9) { br.AssertInt32(0x24); br.AssertInt32(0x2C); } else if (type == Type.DCX_DFLT_10000_44_9 || type == Type.DCX_DFLT_11000_44_8 || type == Type.DCX_DFLT_11000_44_9) { br.AssertInt32(0x44); br.AssertInt32(0x4C); } br.AssertASCII("DCS\0"); int uncompressedSize = br.ReadInt32(); int compressedSize = br.ReadInt32(); br.AssertASCII("DCP\0"); br.AssertASCII("DFLT"); br.AssertInt32(0x20); if (type == Type.DCX_DFLT_10000_24_9 || type == Type.DCX_DFLT_10000_44_9 || type == Type.DCX_DFLT_11000_44_9) { br.AssertInt32(0x9000000); } else if (type == Type.DCX_DFLT_11000_44_8) { br.AssertInt32(0x8000000); } br.AssertInt32(0x0); br.AssertInt32(0x0); br.AssertInt32(0x0); // These look suspiciously like flags br.AssertInt32(0x00010100); br.AssertASCII("DCA\0"); int compressedHeaderLength = br.ReadInt32(); return(SFUtil.ReadZlib(br, compressedSize)); }
internal File(BinaryReaderEx br, bool unicode, byte format) { Flags = br.AssertByte(0x00, 0x02, 0x03, 0x0A, 0x40, 0xC0); br.AssertByte(0); br.AssertByte(0); br.AssertByte(0); br.AssertInt32(-1); long compressedSize = br.ReadInt64(); long uncompressedSize = 0; if (format == 0x26 || format == 0x2A || format == 0x2E || format == 0x54 || format == 0x74) { uncompressedSize = br.ReadInt64(); } int fileOffset = br.ReadInt32(); if (format == 0x0C) { ID = -1; } else { ID = br.ReadInt32(); } int nameOffset = br.ReadInt32(); if (unicode) { Name = br.GetUTF16(nameOffset); } else { Name = br.GetShiftJIS(nameOffset); } if (Flags == 0x03 || Flags == 0xC0) { br.StepIn(fileOffset); Bytes = SFUtil.ReadZlib(br, (int)compressedSize); br.StepOut(); } else { Bytes = br.GetBytes(fileOffset, (int)compressedSize); } }
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)); }
internal File(BinaryReaderEx br, byte format) { Flags = br.AssertByte(0x00, 0x02, 0x40, 0xC0); br.AssertByte(0); br.AssertByte(0); br.AssertByte(0); int compressedSize = br.ReadInt32(); int fileOffset = br.ReadInt32(); ID = br.ReadInt32(); if (format == 0x40) { Name = null; } else { int fileNameOffset = br.ReadInt32(); Name = br.GetShiftJIS(fileNameOffset); } int uncompressedSize = compressedSize; if (format == 0x2E || format == 0x54 || format == 0x64 || format == 0x74) { uncompressedSize = br.ReadInt32(); } // Compressed if (Flags == 0xC0) { br.StepIn(fileOffset); Bytes = SFUtil.ReadZlib(br, compressedSize); br.StepOut(); } else { Bytes = br.GetBytes(fileOffset, compressedSize); } }
/// <summary> /// Deserializes file data from a stream. /// </summary> protected override void Read(BinaryReaderEx br) { br.BigEndian = false; br.AssertASCII("ENFL"); // Probably 4 bytes br.AssertInt32(0x10415); int compressedSize = br.ReadInt32(); int uncompressedSize = br.ReadInt32(); byte[] data = SFUtil.ReadZlib(br, compressedSize); br = new BinaryReaderEx(false, data); br.AssertInt32(0); int unkCount1 = br.ReadInt32(); int unkCount2 = br.ReadInt32(); br.AssertInt32(0); Struct1s = new List <Struct1>(unkCount1); for (int i = 0; i < unkCount1; i++) { Struct1s.Add(new Struct1(br)); } br.Pad(0x10); Struct2s = new List <Struct2>(unkCount2); for (int i = 0; i < unkCount2; i++) { Struct2s.Add(new Struct2(br)); } br.Pad(0x10); br.AssertInt16(0); Strings = new List <string>(unkCount2); for (int i = 0; i < unkCount2; i++) { Strings.Add(br.ReadUTF16()); } }
private static byte[] DecompressDCPDFLT(BinaryReaderEx br) { br.AssertASCII("DCP\0"); br.AssertASCII("DFLT"); br.AssertInt32(0x20); br.AssertInt32(0x9000000); br.AssertInt32(0); br.AssertInt32(0); br.AssertInt32(0); br.AssertInt32(0x00010100); br.AssertASCII("DCS\0"); int uncompressedSize = br.ReadInt32(); int compressedSize = br.ReadInt32(); byte[] decompressed = SFUtil.ReadZlib(br, compressedSize); br.AssertASCII("DCA\0"); br.AssertInt32(8); return(decompressed); }
internal static byte[] Decompress(BinaryReaderEx br, out Type type) { br.BigEndian = true; type = Type.Unknown; string magic = br.ReadASCII(4); if (magic == "DCP\0") { string format = br.GetASCII(4, 4); if (format == "DFLT") { type = Type.DCP_DFLT; } else if (format == "EDGE") { type = Type.DCP_EDGE; } } else if (magic == "DCX\0") { string format = br.GetASCII(0x28, 4); if (format == "EDGE") { type = Type.DCX_EDGE; } else if (format == "DFLT") { int unk04 = br.GetInt32(0x4); int unk10 = br.GetInt32(0x10); int unk30 = br.GetInt32(0x30); if (unk10 == 0x24) { type = Type.DCX_DFLT_10000_24_9; } else if (unk10 == 0x44) { if (unk04 == 0x10000) { type = Type.DCX_DFLT_10000_44_9; } else if (unk04 == 0x11000) { if (unk30 == 0x8000000) { type = Type.DCX_DFLT_11000_44_8; } else if (unk30 == 0x9000000) { type = Type.DCX_DFLT_11000_44_9; } } } } else if (format == "KRAK") { type = Type.DCX_KRAK; } } else { byte b0 = br.GetByte(0); byte b1 = br.GetByte(1); if (b0 == 0x78 && (b1 == 0x01 || b1 == 0x5E || b1 == 0x9C || b1 == 0xDA)) { type = Type.Zlib; } } br.Position = 0; if (type == Type.Zlib) { return(SFUtil.ReadZlib(br, (int)br.Length)); } else if (type == Type.DCP_EDGE) { return(DecompressDCPEDGE(br)); } else if (type == Type.DCP_DFLT) { return(DecompressDCPDFLT(br)); } else if (type == Type.DCX_EDGE) { return(DecompressDCXEDGE(br)); } else if (type == Type.DCX_DFLT_10000_24_9 || type == Type.DCX_DFLT_10000_44_9 || type == Type.DCX_DFLT_11000_44_8 || type == Type.DCX_DFLT_11000_44_9) { return(DecompressDCXDFLT(br, type)); } else if (type == Type.DCX_KRAK) { return(DecompressDCXKRAK(br)); } else { throw new FormatException("Unknown DCX format."); } }
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)); }