示例#1
0
        private static void Read(PexFile file, IBinaryReadStream br)
        {
            var magic = br.ReadUInt32();

            if (magic != PexMagic)
            {
                throw new InvalidDataException($"File does not have fast code! Magic does not match {PexMagic:x8} is {magic:x8}");
            }

            file.MajorVersion    = br.ReadUInt8();
            file.MinorVersion    = br.ReadUInt8();
            file.GameId          = br.ReadUInt16();
            file.CompilationTime = br.ReadUInt64().ToDateTime();
            file.SourceFileName  = br.ReadPrependedString(2);
            file.Username        = br.ReadPrependedString(2);
            file.MachineName     = br.ReadPrependedString(2);

            var stringsCount = br.ReadUInt16();

            var bundle = new PexParseMeta(
                file._gameCategory,
                br,
                new Dictionary <ushort, string>());

            for (var i = 0; i < stringsCount; i++)
            {
                bundle.Strings.Add((ushort)i, br.ReadPrependedString(2));
            }

            var hasDebugInfo = bundle.Reader.ReadUInt8() == 1;

            if (hasDebugInfo)
            {
                file.DebugInfo = Mutagen.Bethesda.Pex.DebugInfo.Create(bundle);
            }

            var userFlagCount = br.ReadUInt16();

            for (var i = 0; i < userFlagCount; i++)
            {
                var str = bundle.ReadString();
                file.UserFlags[br.ReadUInt8()] = str;
            }

            var objectCount = br.ReadUInt16();

            for (var i = 0; i < objectCount; i++)
            {
                var pexObject = PexObject.Create(bundle);
                file.Objects.Add(pexObject);
            }
        }
示例#2
0
        internal static PexObject Create(PexParseMeta parse)
        {
            var ret = new PexObject();

            ret.Name = parse.ReadString();

            /*
             * This is the size of the entire object in bytes not some count variable for a loop. This also includes
             * the size of itself thus the - sizeof(uint)
             */
            var size       = parse.Reader.ReadUInt32() - sizeof(uint);
            var currentPos = parse.Reader.Position;

            ret.ParentClassName = parse.ReadString();
            ret.DocString       = parse.ReadString();

            if (parse.Category == GameCategory.Fallout4)
            {
                ret.IsConst = parse.Reader.ReadBoolean();
            }

            ret.RawUserFlags  = parse.Reader.ReadUInt32();
            ret.AutoStateName = parse.ReadString();

            if (parse.Category == GameCategory.Fallout4)
            {
                var infoCount = parse.Reader.ReadUInt16();
                for (var i = 0; i < infoCount; i++)
                {
                    var structInfo = PexObjectStructInfo.Create(parse);
                    ret.StructInfos.Add(structInfo);
                }
            }

            var variables = parse.Reader.ReadUInt16();

            for (var i = 0; i < variables; i++)
            {
                var variable = PexObjectVariable.Create(parse);
                ret.Variables.Add(variable);
            }

            var properties = parse.Reader.ReadUInt16();

            for (var i = 0; i < properties; i++)
            {
                var property = PexObjectProperty.Create(parse);
                ret.Properties.Add(property);
            }

            var states = parse.Reader.ReadUInt16();

            for (var i = 0; i < states; i++)
            {
                var state = PexObjectState.Create(parse);
                ret.States.Add(state);
            }

            var newPos = parse.Reader.Position;

            if (newPos != currentPos + size)
            {
                throw new InvalidDataException("Current position in Stream does not match expected position: " +
                                               $"Current: {newPos} Expected: {currentPos + size}");
            }

            return(ret);
        }