Пример #1
0
        public static RecordType GetNextType(
            IMutagenReadStream reader,
            out int contentLength,
            out long finalPos,
            bool hopGroup = true)
        {
            GroupHeader groupMeta = reader.GetGroup();
            RecordType  ret       = groupMeta.RecordType;

            contentLength = checked ((int)groupMeta.TotalLength);
            if (groupMeta.IsGroup)
            {
                if (hopGroup)
                {
                    ret = groupMeta.ContainedRecordType;
                }
                finalPos = reader.Position + groupMeta.TotalLength;
            }
            else
            {
                finalPos = reader.Position + reader.MetaData.Constants.MajorConstants.HeaderLength + contentLength;
            }
            return(ret);
        }
Пример #2
0
        private static void AlignWorldChildren(
            IMutagenReadStream reader,
            MutagenWriter writer)
        {
            reader.WriteTo(writer.BaseStream, 4);
            ReadOnlyMemorySlice <byte>?        roadStorage = null;
            ReadOnlyMemorySlice <byte>?        cellStorage = null;
            List <ReadOnlyMemorySlice <byte> > grupBytes   = new List <ReadOnlyMemorySlice <byte> >();

            for (int i = 0; i < 3; i++)
            {
                RecordType type = HeaderTranslation.GetNextRecordType(reader);
                switch (type.Type)
                {
                case "ROAD":
                    roadStorage = reader.ReadMemory(checked ((int)reader.GetMajorRecord().TotalLength));
                    break;

                case "CELL":
                    if (cellStorage != null)
                    {
                        throw new ArgumentException();
                    }
                    var cellMajorMeta = reader.GetMajorRecord();
                    var startPos      = reader.Position;
                    reader.Position += cellMajorMeta.HeaderLength;
                    long cellGroupLen = 0;
                    if (reader.TryGetGroup(out var cellSubGroupMeta) &&
                        cellSubGroupMeta.GroupType == writer.MetaData.Constants.GroupConstants.Cell.TopGroupType)
                    {
                        cellGroupLen = cellSubGroupMeta.TotalLength;
                    }
                    reader.Position = startPos;
                    cellStorage     = reader.ReadMemory(checked ((int)(cellMajorMeta.TotalLength + cellGroupLen)));
                    break;

                case "GRUP":
                    if (roadStorage != null &&
                        cellStorage != null)
                    {
                        i = 3;     // end loop
                        continue;
                    }
                    grupBytes.Add(reader.ReadMemory(checked ((int)reader.GetGroup().TotalLength)));
                    break;

                case "WRLD":
                    i = 3;     // end loop
                    continue;

                default:
                    throw new NotImplementedException();
                }
            }
            if (roadStorage != null)
            {
                writer.Write(roadStorage.Value);
            }
            if (cellStorage != null)
            {
                writer.Write(cellStorage.Value);
            }
            foreach (var item in grupBytes)
            {
                writer.Write(item);
            }
        }
Пример #3
0
        private static void AlignWorldChildren(
            IMutagenReadStream reader,
            MutagenWriter writer)
        {
            reader.WriteTo(writer.BaseStream, 4);
            ReadOnlyMemorySlice <byte>?roadStorage = null;
            ReadOnlyMemorySlice <byte>?cellStorage = null;
            var grupBytes = new List <ReadOnlyMemorySlice <byte> >();

            for (int i = 0; i < 3; i++)
            {
                MajorRecordHeader majorMeta = reader.GetMajorRecord();
                switch (majorMeta.RecordType.Type)
                {
                case "ROAD":
                    roadStorage = reader.ReadMemory(checked ((int)majorMeta.TotalLength));
                    break;

                case "CELL":
                    if (cellStorage != null)
                    {
                        throw new ArgumentException();
                    }
                    var startPos = reader.Position;
                    var cellMeta = reader.GetMajorRecord();
                    reader.Position += cellMeta.TotalLength;
                    var  cellGroupMeta = reader.GetGroup();
                    long cellGrupLen;
                    if (cellGroupMeta.IsGroup &&
                        cellGroupMeta.GroupType == (int)GroupTypeEnum.CellChildren)
                    {
                        cellGrupLen = cellGroupMeta.TotalLength;
                    }
                    else
                    {
                        cellGrupLen = 0;
                    }
                    reader.Position = startPos;
                    cellStorage     = reader.ReadMemory(checked ((int)(cellMeta.TotalLength + cellGrupLen)));
                    break;

                case "GRUP":
                    if (roadStorage != null &&
                        cellStorage != null)
                    {
                        i = 3;     // end loop
                        continue;
                    }
                    var groupMeta = reader.GetGroup();
                    grupBytes.Add(reader.ReadMemory(checked ((int)groupMeta.TotalLength)));
                    break;

                case "WRLD":
                    i = 3;     // end loop
                    continue;

                default:
                    throw new NotImplementedException();
                }
            }
            if (roadStorage != null)
            {
                writer.Write(roadStorage.Value);
            }
            if (cellStorage != null)
            {
                writer.Write(cellStorage.Value);
            }
            foreach (var item in grupBytes)
            {
                writer.Write(item);
            }
        }