public static long ParseRecord(IMutagenReadStream reader)
        {
            reader.Position += 4;
            var len = checked ((int)reader.ReadUInt32());

            return(reader.Position + len + reader.MetaData.Constants.MajorConstants.LengthAfterLength);
        }
Beispiel #2
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);
            }
Beispiel #3
0
        private void FixVMADScriptIDs(IMutagenReadStream stream, long fileOffset, ushort objectFormat)
        {
            // skip name
            var len = stream.ReadUInt16();

            stream.Position += len;
            // Skip flags
            stream.Position += 1;
            var propCount = stream.ReadUInt16();

            for (int j = 0; j < propCount; j++)
            {
                // skip name
                len              = stream.ReadUInt16();
                stream.Position += len;
                var type = (ScriptProperty.Type)stream.ReadUInt8();
                // skip flags
                stream.Position += 1;
                // Going to cheat here, and use the autogenerated records
                ScriptProperty prop = type switch
                {
                    ScriptProperty.Type.None => new ScriptProperty(),
                    ScriptProperty.Type.Object => new ScriptObjectProperty(),
                    ScriptProperty.Type.String => new ScriptStringProperty(),
                    ScriptProperty.Type.Int => new ScriptIntProperty(),
                    ScriptProperty.Type.Float => new ScriptFloatProperty(),
                    ScriptProperty.Type.Bool => new ScriptBoolProperty(),
                    ScriptProperty.Type.ArrayOfObject => new ScriptObjectListProperty(),
                    ScriptProperty.Type.ArrayOfString => new ScriptStringListProperty(),
                    ScriptProperty.Type.ArrayOfInt => new ScriptIntListProperty(),
                    ScriptProperty.Type.ArrayOfFloat => new ScriptFloatListProperty(),
                    ScriptProperty.Type.ArrayOfBool => new ScriptBoolListProperty(),
                    _ => throw new NotImplementedException(),
                };
                switch (prop)
                {
                case ScriptObjectProperty obj:
                    FixObjectPropertyIDs(stream, fileOffset, objectFormat);
                    break;

                case ScriptObjectListProperty objList:
                    var count = stream.ReadUInt32();
                    for (int i = 0; i < count; i++)
                    {
                        FixObjectPropertyIDs(stream, fileOffset, objectFormat);
                    }
                    break;

                default:
                    prop.CopyInFromBinary(new MutagenFrame(stream));
                    break;
                }
            }
        }