Exemple #1
0
        void Read(int recordLevel)
        {
            var rootHeader = new Header(_r, Format, null);

            if ((Format == GameFormatId.TES3 && rootHeader.Type != "TES3") || (Format != GameFormatId.TES3 && rootHeader.Type != "TES4"))
            {
                throw new FormatException($"{FilePath} record header {rootHeader.Type} is not valid for this {Format}");
            }
            var rootRecord = rootHeader.CreateRecord(rootHeader.Position, recordLevel);

            rootRecord.Read(_r, FilePath, Format);
            // morrowind hack
            if (Format == GameFormatId.TES3)
            {
                var group = new RecordGroup(_r, FilePath, Format, recordLevel);
                group.AddHeader(new Header
                {
                    Label    = null,
                    DataSize = (uint)(_r.BaseStream.Length - _r.BaseStream.Position),
                    Position = _r.BaseStream.Position,
                });
                group.Load();
                Groups = group.Records.GroupBy(x => x.Header.Type)
                         .ToDictionary(x => x.Key, x =>
                {
                    var s = new RecordGroup(_r, FilePath, Format, recordLevel)
                    {
                        Records = x.ToList()
                    };
                    s.AddHeader(new Header {
                        Label = Encoding.ASCII.GetBytes(x.Key)
                    });
                    return(s);
                });
                return;
            }
            // read groups
            Groups = new Dictionary <string, RecordGroup>();
            var endPosition = _r.BaseStream.Length;

            while (_r.BaseStream.Position < endPosition)
            {
                var header = new Header(_r, Format, null);
                if (header.Type != "GRUP")
                {
                    throw new InvalidOperationException($"{header.Type} not GRUP");
                }
                var nextPosition = _r.BaseStream.Position + header.DataSize;
                var label        = Encoding.ASCII.GetString(header.Label);
                if (!Groups.TryGetValue(label, out RecordGroup group))
                {
                    group = new RecordGroup(_r, FilePath, Format, recordLevel);
                    Groups.Add(label, group);
                }
                group.AddHeader(header);
                _r.BaseStream.Position = nextPosition;
            }
        }
Exemple #2
0
        RecordGroup ReadGRUP(Header header, Header recordHeader)
        {
            var nextPosition = _r.BaseStream.Position + recordHeader.DataSize;

            if (Groups == null)
            {
                Groups = new List <RecordGroup>();
            }
            var group = new RecordGroup(_r, _filePath, _formatId, _recordLevel);

            group.AddHeader(recordHeader);
            Groups.Add(group);
            _r.BaseStream.Position = nextPosition;
            // print header path
            var headerPath = string.Join("/", GetHeaderPath(new List <string>(), header).ToArray());

            Console.WriteLine($"Grup: {headerPath} {header.GroupType}");
            return(group);
        }