コード例 #1
0
        public static CatalogFile Read(Stream input)
        {
            const Endian endian = Endian.Little;

            var magic1 = input.ReadValueU64(endian);
            var magic2 = input.ReadValueU64(endian);

            if (magic1 != Signature || magic2 != Signature)
            {
                throw new FormatException();
            }

            var instance = new CatalogFile();

            var chunkCount          = input.ReadValueU32(endian);
            var patchCount          = input.ReadValueU32(endian);
            var encryptedChunkCount = input.ReadValueU32(endian);
            var unknown1C           = input.ReadValueS32(endian);
            var unknown20           = input.ReadValueS32(endian);
            var unknown24           = input.ReadValueS32(endian);

            if (patchCount != 0 || unknown1C != 0 || unknown20 != 0 || unknown24 != 0)
            {
                throw new FormatException();
            }

            instance.ChunkEntries.Clear();

            for (int i = 0; i < chunkCount; i++)
            {
                var chunk = ChunkEntry.Read(input, endian);

                if (chunk.IsEncrypted == true)
                {
                    throw new FormatException();
                }

                instance.ChunkEntries.Add(chunk);
            }

            for (int i = 0; i < encryptedChunkCount; i++)
            {
                var encryptedChunk = EncryptedChunkEntry.Read(input, endian);

                if (encryptedChunk.Chunk.IsEncrypted == false)
                {
                    throw new FormatException();
                }

                if (encryptedChunk.Chunk.Size != encryptedChunk.CryptoInfo.Size)
                {
                    throw new FormatException();
                }

                instance.EncryptedChunkEntries.Add(encryptedChunk);
            }

            if (input.Position != input.Length)
            {
                throw new FormatException();
            }

            return(instance);
        }
コード例 #2
0
        public static CatalogFile Read(Stream input)
        {
            const Endian endian = Endian.Little;

            var magic1 = input.ReadValueU64(endian);
            var magic2 = input.ReadValueU64(endian);

            if (magic1 != Signature || magic2 != Signature)
            {
                throw new FormatException();
            }

            var instance = new CatalogFile();

            var normalCount    = input.ReadValueU32(endian);
            var patchCount     = input.ReadValueU32(endian);
            var encryptedCount = input.ReadValueU32(endian);
            var unknown1C      = input.ReadValueS32(endian); // patch version related?
            var unknown20      = input.ReadValueS32(endian); // patch version related?
            var unknown24      = input.ReadValueS32(endian); // patch version related?

            instance.NormalEntries.Clear();
            for (int i = 0; i < normalCount; i++)
            {
                var entry = NormalEntry.Read(input, endian);
                if (entry.IsEncrypted == true)
                {
                    throw new FormatException();
                }
                instance.NormalEntries.Add(entry);
            }

            instance.EncryptedEntries.Clear();
            for (int i = 0; i < encryptedCount; i++)
            {
                var encryptedEntry = EncryptedChunkEntry.Read(input, endian);
                if (encryptedEntry.Entry.IsEncrypted == false)
                {
                    throw new FormatException();
                }
                if (encryptedEntry.Entry.Size != encryptedEntry.CryptoInfo.Size)
                {
                    throw new FormatException();
                }
                instance.EncryptedEntries.Add(encryptedEntry);
            }

            instance.PatchEntries.Clear();
            for (int i = 0; i < patchCount; i++)
            {
                var entry = PatchEntry.Read(input, endian);
                instance.PatchEntries.Add(entry);
            }

            if (input.Position != input.Length)
            {
                throw new FormatException();
            }

            return(instance);
        }