コード例 #1
0
        /// <summary>
        /// Unpack and decrypt the contents of cache.bin.
        /// </summary>
        private static void UnPack(string cachePath)
        {
            Console.WriteLine("Unpacking...");

            if (!File.Exists(cachePath))
            {
                throw new FileNotFoundException($"{cachePath} is an invalid cache.bin file!");
            }

            payload = File.ReadAllBytes(cachePath);
            Decrypt();

            using (MemoryStream stream = new MemoryStream(payload))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    reader.ReadUInt32(); // version?

                    uint chunkCount = reader.ReadUInt32();
                    for (uint i = 0u; i < chunkCount; i++)
                    {
                        chunks.Add(new Chunk(reader));
                    }
                }
            }

            Console.WriteLine("Saving chunk keys as keys.json...");
            File.WriteAllText("keys.json", ChunkKeyJson.Save(chunks));
        }
コード例 #2
0
        public static string Save(IEnumerable <Chunk> fileChunks)
        {
            var keys = new ChunkKeyJson();

            foreach (Chunk chunk in fileChunks)
            {
                keys.Chunks.Add(new ChunkKey
                {
                    Id   = chunk.ChunkHeader.Id,
                    Key1 = chunk.ChunkHeader.Key1,
                    Key2 = chunk.ChunkHeader.Key2,
                    Key3 = chunk.ChunkHeader.Key3
                });
            }

            return(JsonConvert.SerializeObject(keys));
        }
コード例 #3
0
        /// <summary>
        /// Pack and encrypt the contents of modified chunk files into a new cache.bin.
        /// </summary>
        private static void Pack(string assetPath)
        {
            Console.WriteLine("Packing...");

            if (!Directory.Exists(assetPath))
            {
                throw new DirectoryNotFoundException($"{assetPath} is an invalid directory!");
            }

            string keysPath = Path.Combine(assetPath, "keys.json");

            if (!File.Exists(keysPath))
            {
                throw new FileNotFoundException($"{assetPath} doesn't contain the keys.json file!");
            }

            ChunkKeyJson chunkKeys = JsonConvert.DeserializeObject <ChunkKeyJson>(File.ReadAllText(keysPath));

            string[] chunkFilePaths = Directory.GetFiles(assetPath, "*.raw");
            if (chunkFilePaths.Length < 9)
            {
                throw new InvalidDataException($"Invalid amount of chunks files, expected 9 got {chunkFilePaths.Length}!");
            }

            foreach (string chunkPath in chunkFilePaths)
            {
                uint id = uint.Parse(Path.GetFileNameWithoutExtension(chunkPath));
                ChunkKeyJson.ChunkKey chunkKey = chunkKeys.Chunks.SingleOrDefault(c => c.Id == id);

                chunks.Add(new Chunk(chunkKey, File.ReadAllBytes(chunkPath)));
            }

            payload = BitConverter.GetBytes(1u)
                      .Concat(BitConverter.GetBytes(chunkFilePaths.Length))
                      .ToArray();

            chunks.ForEach(c => payload = payload.Concat(c.Payload).ToArray());

            Decrypt();

            Console.WriteLine("Saving chunks as cache.bin...");
            File.WriteAllBytes(Path.Combine(assetPath, "cache.bin"), payload);
        }