Пример #1
0
        private static void DecryptBdat(Options options)
        {
            if (options.Input == null)
            {
                throw new NullReferenceException("No input file was specified.");
            }

            if (File.Exists(options.Input))
            {
                string output = options.Output ?? options.Input;
                DecryptFile(options.Input, output);
            }

            if (Directory.Exists(options.Input))
            {
                string   pattern   = options.Filter ?? "*";
                string[] filenames = Directory.GetFiles(options.Input, pattern);
                foreach (string filename in filenames)
                {
                    DecryptFile(filename, filename);
                }
            }

            void DecryptFile(string input, string output)
            {
                var bdat = new DataBuffer(File.ReadAllBytes(input), options.Game, 0);

                BdatTools.DecryptBdat(bdat);
                File.WriteAllBytes(output, bdat.File);
                Console.WriteLine("Finished decrypting");
            }
        }
        private static void ReadBdat(byte[] file, BdatStringCollection tables, string filename)
        {
            if (file.Length <= 12)
            {
                throw new InvalidDataException("File is too short");
            }
            int fileLength = BitConverter.ToInt32(file, 4);

            if (file.Length != fileLength)
            {
                throw new InvalidDataException("Incorrect file length field");
            }

            BdatTools.DecryptBdat(file);

            int tableCount = BitConverter.ToInt32(file, 0);

            for (int i = 0; i < tableCount; i++)
            {
                int offset = BitConverter.ToInt32(file, 8 + 4 * i);
                var table  = ReadTable(file, offset);
                if (table == null)
                {
                    continue;
                }
                if (tableCount > 1)
                {
                    table.Filename = filename;
                }
                tables.Add(table);
            }
        }
Пример #3
0
        private static void CombineBdat(Options options)
        {
            //if (options.Input == null) throw new NullReferenceException("No input file was specified.");
            if (options.Output == null)
            {
                throw new NullReferenceException("No output file was specified.");
            }

            BdatTable[] tables   = ReadBdatTables(options, false).Tables;
            byte[]      combined = BdatTools.Combine(tables);
            File.WriteAllBytes(options.Output, combined);
        }
Пример #4
0
        private static void ReadBdat(byte[] file, BdatCollection tables)
        {
            if (file.Length <= 12)
            {
                throw new InvalidDataException("File is too short");
            }
            int fileLength = BitConverter.ToInt32(file, 4);

            if (file.Length != fileLength)
            {
                throw new InvalidDataException("Incorrect file length field");
            }

            BdatTools.DecryptBdat(file);

            int tableCount = BitConverter.ToInt32(file, 0);

            for (int i = 0; i < tableCount; i++)
            {
                int offset = BitConverter.ToInt32(file, 8 + 4 * i);
                ReadTable(file, offset, tables);
            }
        }
Пример #5
0
 private static void DecryptBdatFile(string filename)
 {
     byte[] bdat = File.ReadAllBytes(filename);
     BdatTools.DecryptBdat(bdat);
     File.WriteAllBytes(filename, bdat);
 }