Example #1
0
        public void Open(string path)
        {
            using (var reader = new DataReader(new FileStream(path, FileMode.Open)))
            {
                _buffer = reader.ReadBytes((int)reader.Length);

                reader.Seek(0);

                var headerId = reader.ReadInt32();

                if (headerId != ValidHeaderId)
                {
                    reader.Close();

                    return;
                }

                var version = reader.ReadInt32();

                if (version != 1)
                {
                    reader.Close();

                    return;
                }

                _unknownInt16 = reader.ReadInt16();
                var count = reader.ReadInt16();
                Entries = new ConditionalEntries();

                for (var i = 0; i < count; i++)
                {
                    var temp = new ConditionalEntry
                    {
                        Id         = reader.ReadInt32(),
                        Offset     = reader.ReadInt32(),
                        ListOffset = i * 8 + 12,
                        Size       = -1
                    };

                    Entries.Add(temp);
                }

                // Sort by Offset
                Entries = new ConditionalEntries(Entries.OrderBy(entry => entry.Offset));

                GetSize(reader.BaseStream.Length);

                foreach (var entry in Entries)
                {
                    entry.Data = new byte[entry.Size];

                    reader.Seek(entry.Offset);
                    reader.Read(entry.Data, 0, entry.Size);
                }

                // Sort by Id
                Entries = new ConditionalEntries(Entries.OrderBy(entry => entry.Id));
            }
        }
Example #2
0
        public ConditionalsFile(string path = "")
        {
            Entries           = new ConditionalEntries();
            _stringComparison = StringComparison.OrdinalIgnoreCase;
            ByteOrder         = ByteOrder.LittleEndian;

            if (!path.IsNullOrEmpty())
            {
                Open(path);
            }
        }
        public static ConditionalsFile Load(string path)
        {
            var conditionalsFile = new ConditionalsFile();

            using (var reader = new DataReader(new FileStream(path, FileMode.Open)))
            {
                var _buffer = reader.ReadBytes((int)reader.Length);

                reader.Seek(0);

                var headerId = reader.ReadInt32();

                if (headerId != ConditionalsFile.ValidHeaderId)
                {
                    reader.Close();

                    return(null);
                }

                var version = reader.ReadInt32();

                if (version != 1)
                {
                    reader.Close();

                    return(null);
                }

                var unknownInt16 = reader.ReadInt16();
                var count        = reader.ReadInt16();
                var entries      = new ConditionalEntries();

                for (var i = 0; i < count; i++)
                {
                    var temp = new ConditionalEntry
                    {
                        Id         = reader.ReadInt32(),
                        Offset     = reader.ReadInt32(),
                        ListOffset = i * 8 + 12,
                        Size       = -1
                    };

                    entries.Add(temp);
                }

                // Sort by Offset
                entries = new ConditionalEntries(entries.OrderBy(entry => entry.Offset));

                CalculateEntriesSize(entries, reader.Length);

                foreach (var entry in entries)
                {
                    entry.Data = new byte[entry.Size];

                    reader.Seek(entry.Offset);
                    reader.Read(entry.Data, 0, entry.Size);
                }

                // Sort by Id
                conditionalsFile.Entries = new ConditionalEntries(entries.OrderBy(entry => entry.Id));
            }

            return(conditionalsFile);
        }