Esempio n. 1
0
        /// <summary>
        ///     Transforms a binary DBIN2 file into a serializable object.
        /// </summary>
        /// <param name="FileName">The file name of the binary file</param>
        /// <returns>The object</returns>
        private static DBIN2 Unbinarize(string FileName)
        {
            DBIN2 Output = new DBIN2();

            using (FileStream DBIN2 = new FileStream(FileName, FileMode.Open))
            {
                EncryptedBinary Reader = new EncryptedBinary(DBIN2);

                string Signature = Reader.ReadString(4);
                if (Signature != "DBN2")
                {
                    throw new Exception("DBN2 signature not found!");
                }
                Output.Key = Reader.Key = Reader.ReadUInt32();

                uint Entries = Reader.ReadUInt32XOrBE();
                Output.Unknown = Reader.ReadUInt32XOrBE();

                Output.Entries = new SDL2Entry[Entries];

                for (int i = 0; i < Entries; i++)
                {
                    DBIN2.Seek(0x10 + i * 0x10, SeekOrigin.Begin);

                    SDL2Entry Entry = new SDL2Entry();
                    Entry.Unknown0 = Reader.ReadUInt32XOrBE();
                    Entry.Unknown1 = Reader.ReadUInt32XOrBE();
                    uint Offset = Reader.ReadUInt32XOrBE();
                    uint Length = Reader.ReadUInt32XOrBE();

                    byte[] Buffer = new byte[Length];
                    DBIN2.Seek(Offset, SeekOrigin.Begin);
                    DBIN2.Read(Buffer, 0, Buffer.Length);
                    Entry.SDL2 = SDL2.GetDataFromBuffer(Buffer);

                    Output.Entries[i] = Entry;
                }
            }

            return(Output);
        }
Esempio n. 2
0
        /// <summary>
        ///     Transforms a object into a binary DBIN2 file.
        /// </summary>
        /// <param name="FileName">The output file name</param>
        /// <param name="Data">The object to be binarized</param>
        private static void Binarize(string FileName, DBIN2 Data)
        {
            using (FileStream Output = new FileStream(FileName, FileMode.Create))
            {
                EncryptedBinary Writer = new EncryptedBinary(Output);

                Writer.WriteString("DBN2");
                Writer.WriteUInt32(Data.Key);
                Writer.Key = Data.Key;

                Writer.WriteUInt32XOrBE((uint)Data.Entries.Length);
                Writer.WriteUInt32XOrBE(Data.Unknown);

                int DataOffset = 0x10 + Data.Entries.Length * 0x10;
                for (int i = 0; i < Data.Entries.Length; i++)
                {
                    Output.Seek(0x10 + i * 0x10, SeekOrigin.Begin);

                    byte[] Buffer = SDL2.GetBufferFromData(Data.Entries[i].SDL2);
                    Writer.WriteUInt32XOrBE(Data.Entries[i].Unknown0);
                    Writer.WriteUInt32XOrBE(Data.Entries[i].Unknown1);
                    Writer.WriteUInt32XOrBE((uint)DataOffset);
                    Writer.WriteUInt32XOrBE((uint)Buffer.Length);

                    Output.Seek(DataOffset, SeekOrigin.Begin);
                    Output.Write(Buffer, 0, Buffer.Length);
                    DataOffset += Buffer.Length;

                    //Align the buffer to 64-bits if needed
                    while ((DataOffset & 7) != 0)
                    {
                        Writer.WriteUInt8XOr(0);
                        DataOffset++;
                    }
                }
            }
        }