Esempio n. 1
0
 protected virtual bool ParseDat(BinaryReader stream)
 {
     stream.BaseStream.Seek(0x04, SeekOrigin.Begin);
     header = new DatHeader {
         fileSize = XorTools.ReadXorInt32(stream),
         dataSize = XorTools.ReadXorInt32(stream) + 16,
     };
     return((stream.BaseStream.Length - header.fileSize) == 32);
 }
Esempio n. 2
0
        private KeybindSection ParseSection(BinaryReader stream)
        {
            byte[]         headerBytes = XorTools.ReadXorBytes(stream, 3, 0x73);
            KeybindSection section     = new KeybindSection {
                type = headerBytes[0],
                size = headerBytes[1],
            };

            section.data = XorTools.ReadXorBytes(stream, section.size, 0x73);
            Array.Reverse(section.data);
            return(section);
        }
Esempio n. 3
0
        private HotbarSlot ParseSection(BinaryReader stream)
        {
            byte       xor = 0x31;
            HotbarSlot ac  = new HotbarSlot {
                action = XorTools.ReadXorByte(stream, xor),
                flag   = XorTools.ReadXorByte(stream, xor),
                unk1   = XorTools.ReadXorByte(stream, xor),
                unk2   = XorTools.ReadXorByte(stream, xor),
                job    = XorTools.ReadXorByte(stream, xor),
                hotbar = XorTools.ReadXorByte(stream, xor),
                slot   = XorTools.ReadXorByte(stream, xor),
                type   = XorTools.ReadXorByte(stream, xor),
            };

            return(ac);
        }
Esempio n. 4
0
        internal bool Load()
        {
            if (string.IsNullOrEmpty(_filePath))
            {
                throw new FileFormatException("No path to HOTBAR.DAT file provided.");
            }
            if (!File.Exists(_filePath))
            {
                throw new FileFormatException("Missing HOTBAR.DAT file.");
            }

            using var fileStream = File.Open(_filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            using var memStream  = new MemoryStream();
            if (fileStream.CanRead && fileStream.CanSeek)
            {
                fileStream.CopyTo(memStream);
            }

            fileStream.Dispose();
            if (memStream.Length == 0)
            {
                memStream.Dispose();
                return(false);
            }

            using var reader = new BinaryReader(memStream);
            reader.BaseStream.Seek(0x04, SeekOrigin.Begin);

            var fileSize = XorTools.ReadXorInt32(reader);
            var dataSize = XorTools.ReadXorInt32(reader) + 16;

            var sourceSize = reader.BaseStream.Length;

            if (sourceSize - fileSize != 32)
            {
                reader.Dispose();
                memStream.Dispose();
                throw new FileFormatException("Invalid HOTBAR.DAT size.");
            }

            reader.BaseStream.Seek(0x60, SeekOrigin.Begin);
            try
            {
                reader.BaseStream.Seek(0x10, SeekOrigin.Begin);
                while (reader.BaseStream.Position < dataSize)
                {
                    var ac = ParseSection(reader);
                    if (ac.Job <= 0x23)
                    {
                        if (ac.Type == 0x1D)
                        {
                            //Console.WriteLine(string.Format("{0} ({1}): {2} {3}", ac.ToString(), ac.job, ac.action, ac.type));
                        }
                        _hotbarData[ac.Hotbar][ac.Slot][ac.Job] = ac;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new FileFormatException("Invalid HOTBAR.DAT format: " + ex.Message);
            }
            finally
            {
                reader.Dispose();
                memStream.Dispose();
            }
            return(true);
        }
Esempio n. 5
0
        internal bool Load()
        {
            if (string.IsNullOrEmpty(_filePath))
            {
                throw new FileFormatException("No path to KEYBIND.DAT file provided.");
            }

            if (!File.Exists(_filePath))
            {
                throw new FileFormatException("Missing KEYBIND.DAT file.");
            }

            using var fileStream = File.Open(_filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            using var memStream  = new MemoryStream();
            if (fileStream.CanRead && fileStream.CanSeek)
            {
                fileStream.CopyTo(memStream);
            }

            fileStream.Dispose();
            if (memStream.Length == 0)
            {
                memStream.Dispose();
                return(false);
            }

            using var reader = new BinaryReader(memStream);
            reader.BaseStream.Seek(0x04, SeekOrigin.Begin);

            var fileSize = XorTools.ReadXorInt32(reader);
            var dataSize = XorTools.ReadXorInt32(reader) + 16;

            var sourceSize = reader.BaseStream.Length;

            if (sourceSize - fileSize != 32)
            {
                reader.Dispose();
                memStream.Dispose();
                throw new FileFormatException("Invalid KEYBIND.DAT size.");
            }

            reader.BaseStream.Seek(0x60, SeekOrigin.Begin);
            try
            {
                reader.BaseStream.Seek(0x11, SeekOrigin.Begin);
                while (reader.BaseStream.Position < dataSize)
                {
                    var command = ParseSection(reader);
                    var keybind = ParseSection(reader);

                    var key = System.Text.Encoding.UTF8.GetString(command.Data);
                    key = key.Substring(0, key.Length - 1); // Trim off \0
                    var dat     = System.Text.Encoding.UTF8.GetString(keybind.Data);
                    var datKeys = dat.Split(',');
                    if (datKeys.Length != 3)
                    {
                        continue;
                    }
                    var key1 = datKeys[0].Split('.');
                    var key2 = datKeys[1].Split('.');
                    KeybindList.Add(key, new Keybind
                    {
                        MainKey1 = int.Parse(key1[0], System.Globalization.NumberStyles.HexNumber),
                        MainKey2 = int.Parse(key2[0], System.Globalization.NumberStyles.HexNumber),
                        ModKey1  = int.Parse(key1[1], System.Globalization.NumberStyles.HexNumber),
                        ModKey2  = int.Parse(key2[1], System.Globalization.NumberStyles.HexNumber),
                    });
                }
            }
            catch (Exception ex)
            {
                throw new FileFormatException("Invalid HOTBAR.DAT format: " + ex.Message);
            }
            finally
            {
                reader.Dispose();
                memStream.Dispose();
            }
            return(true);
        }