Exemplo n.º 1
0
            public static int[] GetListCounts(IMutagenReadStream frame)
            {
                var subFrame = frame.ReadSubrecord(RecordTypes.XCNT);

                if (subFrame.ContentLength != 20)
                {
                    throw new ArgumentException($"XCNT record had unexpected length {subFrame.ContentLength} != 20");
                }

                int[] ret = new int[5];
                for (int i = 0; i < ret.Length; i++)
                {
                    ret[i] = checked ((int)frame.ReadUInt32());
                }

                var formIDCount = ret.Sum();

                var dataHeader  = frame.ReadSubrecord(RecordTypes.DATA);
                var expectedLen = formIDCount * 4;

                if (dataHeader.ContentLength != expectedLen)
                {
                    throw new ArgumentException($"DATA record had unexpected length that did not match previous counts {dataHeader.ContentLength} != {expectedLen}");
                }
                return(ret);
            }
Exemplo n.º 2
0
        public static void ProcessStringLink(
            IMutagenReadStream stream,
            BinaryFileProcessor.ConfigConstructor instr,
            List <KeyValuePair <uint, uint> > processedStrings,
            IStringsLookup overlay,
            ref uint newIndex)
        {
            var sub = stream.ReadSubrecord();

            if (sub.ContentLength != 4)
            {
                throw new ArgumentException();
            }
            var curIndex = BinaryPrimitives.ReadUInt32LittleEndian(stream.GetSpan(4));

            if (!overlay.TryLookup(curIndex, out var str))
            {
                instr.SetSubstitution(stream.Position, new byte[4]);
            }
            else if (curIndex != 0)
            {
                var assignedIndex = newIndex++;
                processedStrings.Add(new KeyValuePair <uint, uint>(curIndex, assignedIndex));
                byte[] b = new byte[4];
                BinaryPrimitives.WriteUInt32LittleEndian(b, assignedIndex);
                instr.SetSubstitution(stream.Position, b);
            }
            stream.Position -= sub.HeaderLength;
        }