void Init(int readerIndex, Stream stream) { readers[readerIndex] = new EndianBinaryReader(stream, isLittleEndian); EndianBinaryReader reader = readers[readerIndex]; int localDirCount = reader.ReadInt32(); int localFileCount = reader.ReadInt32(); directoryCount += localDirCount; fileCount += localFileCount; directoryList[readerIndex] = new string[localDirCount]; // Check signature if (reader.ReadInt16() != 257) { throw new FormatException("This is not a valid CNT archive!"); } byte xorKey = reader.ReadByte(); // Load directories for (int i = 0; i < localDirCount; i++) { int strLen = reader.ReadInt32(); string directory = ""; for (int j = 0; j < strLen; j++) { directory += (char)(xorKey ^ reader.ReadByte()); } directoryList[readerIndex][i] = directory; } // Load and check version byte verId = reader.ReadByte(); switch (verId) { case 246: version = CNTVersion.Rayman2; break; default: version = CNTVersion.Rayman2Vignette; break; } // Read files for (int i = 0; i < localFileCount; i++) { int dirIndex = reader.ReadInt32(); int size = reader.ReadInt32(); string file = ""; for (int j = 0; j < size; j++) { file += (char)(xorKey ^ reader.ReadByte()); } byte[] fileXorKey = new byte[4]; reader.Read(fileXorKey, 0, 4); uint magic2 = reader.ReadUInt32(); int dataPointer = reader.ReadInt32(); int fileSize = reader.ReadInt32(); string dir = dirIndex != -1 ? directoryList[readerIndex][dirIndex] : ""; fileList.Add(new FileStruct() { directory = dir, name = file, pointer = dataPointer, size = fileSize, xorKey = fileXorKey, magic2 = magic2, fileNum = readerIndex }); } }
public async Task Init(int readerIndex, Reader reader) { PartialHttpStream httpStream = reader.BaseStream as PartialHttpStream; if (httpStream != null) { await httpStream.FillCacheForRead(11); } int localDirCount = reader.ReadInt32(); int localFileCount = reader.ReadInt32(); directoryCount += localDirCount; fileCount += localFileCount; directoryList[readerIndex] = new string[localDirCount]; // Check signature if (reader.ReadInt16() != 257) { throw new FormatException("This is not a valid CNT archive!"); } byte xorKey = reader.ReadByte(); // Load directories //Debug.Log("directories"); if (httpStream != null) { await httpStream.FillCacheForRead(300 *localDirCount); } await MapLoader.WaitIfNecessary(); for (int i = 0; i < localDirCount; i++) { //if (httpStream != null) yield return c.StartCoroutine(httpStream.FillCacheForRead(4)); int strLen = reader.ReadInt32(); string directory = ""; //if (httpStream != null) yield return c.StartCoroutine(httpStream.FillCacheForRead(strLen)); for (int j = 0; j < strLen; j++) { directory += (char)(xorKey ^ reader.ReadByte()); } directoryList[readerIndex][i] = directory; } // Load and check version //if (httpStream != null) yield return c.StartCoroutine(httpStream.FillCacheForRead(1)); byte verId = reader.ReadByte(); switch (verId) { case 246: version = CNTVersion.Rayman2; break; default: version = CNTVersion.Rayman2Vignette; break; } // Read files //Debug.Log("files"); if (httpStream != null) { await httpStream.FillCacheForRead(300 *localFileCount); } for (int i = 0; i < localFileCount; i++) { //if (httpStream != null) yield return c.StartCoroutine(httpStream.FillCacheForRead(8)); int dirIndex = reader.ReadInt32(); int size = reader.ReadInt32(); string file = ""; //if (httpStream != null) yield return c.StartCoroutine(httpStream.FillCacheForRead(size + 16)); for (int j = 0; j < size; j++) { file += (char)(xorKey ^ reader.ReadByte()); } byte[] fileXorKey = new byte[4]; reader.Read(fileXorKey, 0, 4); uint magic2 = reader.ReadUInt32(); int dataPointer = reader.ReadInt32(); int fileSize = reader.ReadInt32(); string dir = dirIndex != -1 ? directoryList[readerIndex][dirIndex] : ""; fileList.Add(new FileStruct() { directory = dir, name = file, pointer = dataPointer, size = fileSize, xorKey = fileXorKey, magic2 = magic2, fileNum = readerIndex }); } }
public CNTFile(Stream stream) { r = new BinaryReader(stream); int directoryCount = r.ReadInt32(); int fileCount = r.ReadInt32(); // Check signature if (r.ReadInt16() != 257) { throw new InvalidDataException("This is not a valid CNT archive!"); } byte xorKey = r.ReadByte(); // Load directories for (int i = 0; i < directoryCount; i++) { int strLen = r.ReadInt32(); string directory = ""; for (int j = 0; j < strLen; j++) { directory += (char)(xorKey ^ r.ReadByte()); } directoryList.Add(directory); } // Load and check version byte verId = r.ReadByte(); switch (verId) { case 246: version = CNTVersion.Rayman2; break; default: version = CNTVersion.Rayman2Vignette; break; } // Read files for (int i = 0; i < fileCount; i++) { int dirIndex = r.ReadInt32(); int size = r.ReadInt32(); string file = ""; for (int j = 0; j < size; j++) { file += (char)(xorKey ^ r.ReadByte()); } byte[] fileXorKey = new byte[4]; r.Read(fileXorKey, 0, 4); int magic2 = r.ReadInt32(); int dataPointer = r.ReadInt32(); int fileSize = r.ReadInt32(); string dir = dirIndex != -1 ? directoryList[dirIndex] : ""; fileList.Add(new FileStruct() { directory = dir, name = file, pointer = dataPointer, size = fileSize, xorKey = fileXorKey, magic2 = magic2 }); } }