Пример #1
0
        /// <summary>
        ///     Gets the SDL2 data from a byte array buffer.
        /// </summary>
        /// <param name="Buffer">The buffer with the data</param>
        /// <returns>The SDL2 data</returns>
        public static SDL2Data GetDataFromBuffer(byte[] Buffer)
        {
            SDL2Data Output = new SDL2Data();

            using (MemoryStream SDL2 = new MemoryStream(Buffer))
            {
                EncryptedBinary Reader = new EncryptedBinary(SDL2);
                
                string Signature = Reader.ReadString(4);
                if (Signature != "SDL2") throw new Exception("SDL2 signature not found!");
                Output.Key = Reader.Key = Reader.ReadUInt32();

                ushort Table0Count = Reader.ReadUInt16XOrBE();
                ushort DialogsCount = Reader.ReadUInt16XOrBE();

                Output.Unknown = new UnknownEntry[Table0Count];

                for (int i = 0; i < Table0Count; i++)
                {
                    uint SectionBOffset = Reader.ReadUInt32XOrBE();
                    uint SectionAOffset = Reader.ReadUInt32XOrBE();
                    long Position = SDL2.Position;

                    UnknownEntry Entry = new UnknownEntry();

                    SDL2.Seek(SectionAOffset, SeekOrigin.Begin);
                    uint Entries = Reader.ReadUInt32XOrBE();
                    Entry.Values = new SectionAEntry[Entries];
                    for (int j = 0; j < Entries; j++)
                    {
                        Entry.Values[j].Value0 = Reader.ReadUInt32XOrBE();
                        Entry.Values[j].Value1 = Reader.ReadUInt32XOrBE();
                    }

                    SDL2.Seek(SectionBOffset, SeekOrigin.Begin);
                    Entry.Value0 = Reader.ReadUInt32XOrBE();
                    Entry.Value1 = Reader.ReadUInt32XOrBE();
                    Output.Unknown[i] = Entry;

                    SDL2.Seek(Position, SeekOrigin.Begin);
                }

                Output.Dialogs = new string[DialogsCount];

                for (int i = 0; i < DialogsCount; i++)
                {
                    uint DialogOffset = Reader.ReadUInt32XOrBE();
                    long Position = SDL2.Position;

                    SDL2.Seek(DialogOffset, SeekOrigin.Begin);
                    Output.Dialogs[i] = Reader.ReadUTF8();

                    SDL2.Seek(Position, SeekOrigin.Begin);
                }
            }

            return Output;
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        ///     Gets the SDL2 data from a byte array buffer.
        /// </summary>
        /// <param name="Buffer">The buffer with the data</param>
        /// <returns>The SDL2 data</returns>
        public static SDL2Data GetDataFromBuffer(byte[] Buffer)
        {
            SDL2Data Output = new SDL2Data();

            using (MemoryStream SDL2 = new MemoryStream(Buffer))
            {
                EncryptedBinary Reader = new EncryptedBinary(SDL2);

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

                ushort Table0Count  = Reader.ReadUInt16XOrBE();
                ushort DialogsCount = Reader.ReadUInt16XOrBE();

                Output.Unknown = new UnknownEntry[Table0Count];

                for (int i = 0; i < Table0Count; i++)
                {
                    uint SectionBOffset = Reader.ReadUInt32XOrBE();
                    uint SectionAOffset = Reader.ReadUInt32XOrBE();
                    long Position       = SDL2.Position;

                    UnknownEntry Entry = new UnknownEntry();

                    SDL2.Seek(SectionAOffset, SeekOrigin.Begin);
                    uint Entries = Reader.ReadUInt32XOrBE();
                    Entry.Values = new SectionAEntry[Entries];
                    for (int j = 0; j < Entries; j++)
                    {
                        Entry.Values[j].Value0 = Reader.ReadUInt32XOrBE();
                        Entry.Values[j].Value1 = Reader.ReadUInt32XOrBE();
                    }

                    SDL2.Seek(SectionBOffset, SeekOrigin.Begin);
                    Entry.Value0      = Reader.ReadUInt32XOrBE();
                    Entry.Value1      = Reader.ReadUInt32XOrBE();
                    Output.Unknown[i] = Entry;

                    SDL2.Seek(Position, SeekOrigin.Begin);
                }

                Output.Dialogs = new string[DialogsCount];

                for (int i = 0; i < DialogsCount; i++)
                {
                    uint DialogOffset = Reader.ReadUInt32XOrBE();
                    long Position     = SDL2.Position;

                    SDL2.Seek(DialogOffset, SeekOrigin.Begin);
                    Output.Dialogs[i] = Reader.ReadUTF8();

                    SDL2.Seek(Position, SeekOrigin.Begin);
                }
            }

            return(Output);
        }
Пример #4
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;
        }