public static IEnumerable <ATopicReference> Factory(MutagenFrame frame) { while (frame.TryReadSubrecord(RecordTypes.PDTO, out var _)) { var type = (ATopicReference.TopicType)frame.ReadInt32(); switch (type) { case ATopicReference.TopicType.Ref: yield return(new TopicReference() { Reference = new FormLink <IDialogTopicGetter>(FormLinkBinaryTranslation.Instance.Parse(frame)) }); break; case ATopicReference.TopicType.Subtype: yield return(new TopicReferenceSubtype() { Subtype = new RecordType(frame.ReadInt32()) }); break; default: throw new NotImplementedException(); } } }
public static void FillBinaryPointToPointConnections(MutagenFrame frame, IPathGridInternal item) { if (!frame.TryReadSubrecord(RecordTypes.DATA, out var subMeta)) { return; } uint ptCount = frame.Reader.ReadUInt16(); if (!frame.Reader.TryReadSubrecord(PGRP, out subMeta)) { return; } var pointDataSpan = frame.Reader.ReadSpan(subMeta.ContentLength); var bytePointsNum = pointDataSpan.Length / POINT_LEN; if (bytePointsNum != ptCount) { throw new ArgumentException($"Unexpected point byte length, when compared to expected point count. {pointDataSpan.Length} bytes: {bytePointsNum} != {ptCount} points."); } bool readPGRR = false; for (int recAttempt = 0; recAttempt < 2; recAttempt++) { if (frame.Reader.Complete) { break; } subMeta = frame.GetSubrecord(); switch (subMeta.RecordType.TypeInt) { case 0x47414750: //"PGAG": frame.Reader.Position += subMeta.HeaderLength; if (ByteArrayBinaryTranslation <MutagenFrame, MutagenWriter> .Instance.Parse( frame.SpawnWithLength(subMeta.ContentLength, checkFraming: false), item: out var unknownBytes)) { item.PGAG = unknownBytes; } else { item.PGAG = default; } break; case 0x52524750: // "PGRR": frame.Reader.Position += subMeta.HeaderLength; var connectionInts = frame.Reader.ReadSpan(subMeta.ContentLength).AsInt16Span(); int numPts = pointDataSpan.Length / POINT_LEN; PathGridPoint[] pathGridPoints = new PathGridPoint[numPts]; for (int i = 0; i < numPts; i++) { var pt = ReadPathGridPoint(pointDataSpan, out var numConn); pt.Connections.AddRange(connectionInts.Slice(0, numConn).ToArray()); pathGridPoints[i] = pt; pointDataSpan = pointDataSpan.Slice(16); connectionInts = connectionInts.Slice(numConn); } item.PointToPointConnections = pathGridPoints.ToExtendedList(); readPGRR = true; break; default: break; } } if (!readPGRR) { ExtendedList <PathGridPoint> list = new ExtendedList <PathGridPoint>(); while (pointDataSpan.Length > 0) { list.Add( ReadPathGridPoint(pointDataSpan, out var numConn)); pointDataSpan = pointDataSpan.Slice(16); } item.PointToPointConnections = list; } }