public void Serialize(SerializingFile con) { Magic = con + Magic; Version = con + Version; DataOffset = con + DataOffset; EntryOffset = con + EntryOffset; FileCount = con + FileCount; BlockTableOffset = con + BlockTableOffset; MaxBlockSize = con + MaxBlockSize; if (con.IsLoading) { CompressionScheme = new char[4]; } for (var i = 0; i < 4; i++) { CompressionScheme[i] = con + CompressionScheme[i]; } if (Magic != 1397113170 || Version != 0x00010000 || MaxBlockSize != 0x00010000) { throw new Exception("Not supported DLC file!"); } }
public void Serialize(SerializingFile con) { if (con.IsLoading) { _header = new DlcHeader(); } _header.Serialize(con); con.Seek((int)_header.EntryOffset, SeekOrigin.Begin); if (con.IsLoading) { DlcFiles = new DlcFileEntry[_header.FileCount]; } for (var i = 0; i < _header.FileCount; i++) { DlcFiles[i].Serialize(con, _header); } if (con.IsLoading) { ReadFileNames(con); } }
public void Load(string fileName) { _converter = ByteOrderConverter.LittleEndian; FileName = fileName; var con = new SerializingFile(new FileStream(fileName, FileMode.Open, FileAccess.Read)); Serialize(con); con.Memory.Close(); }
public void Serialize(SerializingFile con, DlcHeader dlcHeader) { DlcHeader = dlcHeader; MyOffset = (uint)con.GetPos(); if (con.IsLoading) { Hash = new byte[16]; } for (var i = 0; i < 16; i++) { Hash[i] = con + Hash[i]; } BlockSizeIndex = con + BlockSizeIndex; UncompressedSize = con + UncompressedSize; UncompressedSizeAdder = con + UncompressedSizeAdder; RealUncompressedSize = UncompressedSize + UncompressedSizeAdder << 32; DataOffset = con + DataOffset; DataOffsetAdder = con + DataOffsetAdder; RealDataOffset = DataOffset + DataOffsetAdder << 32; if (BlockSizeIndex == 0xFFFFFFFF) { BlockOffsets = new long[1]; BlockOffsets[0] = RealDataOffset; BlockSizes = new ushort[1]; BlockSizes[0] = (ushort)UncompressedSize; BlockTableOffset = 0; } else { var numBlocks = (int)Math.Ceiling(UncompressedSize / (double)dlcHeader.MaxBlockSize); if (con.IsLoading) { BlockOffsets = new long[numBlocks]; BlockSizes = new ushort[numBlocks]; } BlockOffsets[0] = RealDataOffset; var pos = con.Memory.Position; con.Seek((int)getBlockOffset((int)BlockSizeIndex, dlcHeader.EntryOffset, dlcHeader.FileCount), SeekOrigin.Begin); BlockTableOffset = con.Memory.Position; BlockSizes[0] = con + BlockSizes[0]; for (var i = 1; i < numBlocks; i++) { BlockSizes[i] = con + BlockSizes[i]; BlockOffsets[i] = BlockOffsets[i - 1] + BlockSizes[i]; } con.Seek((int)pos, SeekOrigin.Begin); } }
public void ReadFileNames(SerializingFile con) { DlcFileEntry e; var f = -1; for (var i = 0; i < _header.FileCount; i++) { e = DlcFiles[i]; e.FileName = "UNKNOWN"; DlcFiles[i] = e; if (CompareByteArray(DlcFiles[i].Hash, TocHash)) { f = i; } } if (f == -1) { return; } var m = DecompressEntry(f); m.Seek(0, 0); var r = new StreamReader(m); while (!r.EndOfStream) { var line = r.ReadLine(); var hash = ComputeHash(line); f = -1; for (var i = 0; i < _header.FileCount; i++) { if (CompareByteArray(DlcFiles[i].Hash, hash)) { f = i; } } if (f != -1) { e = DlcFiles[f]; e.FileName = line; DlcFiles[f] = e; } } }