Пример #1
0
        internal static PexObjectProperty Create(PexParseMeta parse)
        {
            var ret = new PexObjectProperty();

            ret.Name         = parse.ReadString();
            ret.TypeName     = parse.ReadString();
            ret.DocString    = parse.ReadString();
            ret.RawUserFlags = parse.Reader.ReadUInt32();

            var flags = parse.Reader.ReadUInt8();

            ret.Flags = (PropertyFlags)flags;

            if ((flags & 4) != 0)
            {
                ret.AutoVarName = parse.ReadString();
            }

            if ((flags & 5) == 1)
            {
                ret.ReadHandler = PexObjectFunction.Create(parse);
            }

            if ((flags & 6) == 2)
            {
                ret.WriteHandler = PexObjectFunction.Create(parse);
            }
            return(ret);
        }
Пример #2
0
        internal static PexObjectFunction Create(PexParseMeta parse)
        {
            var ret = new PexObjectFunction();

            ret.ReturnTypeName = parse.ReadString();
            ret.DocString      = parse.ReadString();
            ret.RawUserFlags   = parse.Reader.ReadUInt32();
            ret.Flags          = (FunctionFlags)parse.Reader.ReadUInt8();

            var parameters = parse.Reader.ReadUInt16();

            for (var i = 0; i < parameters; i++)
            {
                var parameter = PexObjectFunctionVariable.Create(parse);
                ret.Parameters.Add(parameter);
            }

            var locals = parse.Reader.ReadUInt16();

            for (var i = 0; i < locals; i++)
            {
                var local = PexObjectFunctionVariable.Create(parse);
                ret.Locals.Add(local);
            }

            var instructions = parse.Reader.ReadUInt16();

            for (var i = 0; i < instructions; i++)
            {
                var instruction = PexObjectFunctionInstruction.Create(parse);
                ret.Instructions.Add(instruction);
            }
            return(ret);
        }
Пример #3
0
        internal static PexObjectFunctionVariable Create(PexParseMeta parse)
        {
            var ret = new PexObjectFunctionVariable();

            ret.Name     = parse.ReadString();
            ret.TypeName = parse.ReadString();
            return(ret);
        }
Пример #4
0
        internal static PexObjectVariable Create(PexParseMeta parse)
        {
            var ret = new PexObjectVariable();

            ret.Name         = parse.ReadString();
            ret.TypeName     = parse.ReadString();
            ret.RawUserFlags = parse.Reader.ReadUInt32();

            ret.VariableData = PexObjectVariableData.Create(parse);
            return(ret);
        }
Пример #5
0
        internal static PexObjectStructInfoMember Create(PexParseMeta parse)
        {
            var ret = new PexObjectStructInfoMember();

            ret.Name         = parse.ReadString();
            ret.TypeName     = parse.ReadString();
            ret.RawUserFlags = parse.Reader.ReadUInt32();
            ret.Value        = PexObjectVariableData.Create(parse);
            ret.IsConst      = parse.Reader.ReadBoolean();
            ret.DocString    = parse.ReadString();
            return(ret);
        }
Пример #6
0
        internal static DebugStructOrder Create(PexParseMeta parse)
        {
            var ret = new DebugStructOrder();

            ret.ObjectName = parse.ReadString();
            ret.OrderName  = parse.ReadString();

            var count = parse.Reader.ReadUInt16();

            for (var i = 0; i < count; i++)
            {
                ret.Names.Add(parse.ReadString());
            }
            return(ret);
        }
Пример #7
0
        internal static DebugPropertyGroup Create(PexParseMeta parse)
        {
            var ret = new DebugPropertyGroup();

            ret.ObjectName = parse.ReadString();
            ret.GroupName  = parse.ReadString();

            var count = parse.Reader.ReadUInt16();

            for (var i = 0; i < count; i++)
            {
                ret.PropertyNames.Add(parse.ReadString());
            }
            return(ret);
        }
Пример #8
0
        internal static PexObjectVariableData Create(PexParseMeta parse)
        {
            var ret = new PexObjectVariableData();

            ret.VariableType = (VariableType)parse.Reader.ReadUInt8();
            switch (ret.VariableType)
            {
            case VariableType.Null:
                break;

            case VariableType.Identifier:
            case VariableType.String:
                ret.StringValue = parse.ReadString();
                break;

            case VariableType.Integer:
                ret.IntValue = parse.Reader.ReadInt32();
                break;

            case VariableType.Float:
                ret.FloatValue = parse.Reader.ReadFloat();
                break;

            case VariableType.Bool:
                //TODO: use ReadByte instead?
                ret.BoolValue = parse.Reader.ReadBoolean();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(ret);
        }
Пример #9
0
        internal static PexObjectNamedFunction Create(PexParseMeta parse)
        {
            var ret = new PexObjectNamedFunction();

            ret.FunctionName = parse.ReadString();
            ret.Function     = PexObjectFunction.Create(parse);
            return(ret);
        }
Пример #10
0
        internal static DebugFunction Create(PexParseMeta parse)
        {
            var ret = new DebugFunction();

            ret.ObjectName   = parse.ReadString();
            ret.StateName    = parse.ReadString();
            ret.FunctionName = parse.ReadString();

            ret.FunctionType = (DebugFunctionType)parse.Reader.ReadUInt8();

            var instructionCount = parse.Reader.ReadUInt16();

            for (var i = 0; i < instructionCount; i++)
            {
                var lineNumber = parse.Reader.ReadUInt16();
                ret.Instructions.Add(lineNumber);
            }
            return(ret);
        }
Пример #11
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);
            }
        }
Пример #12
0
        internal static PexObjectState Create(PexParseMeta parse)
        {
            var ret = new PexObjectState();

            ret.Name = parse.ReadString();

            var functions = parse.Reader.ReadUInt16();

            for (var i = 0; i < functions; i++)
            {
                var namedFunction = PexObjectNamedFunction.Create(parse);
                ret.Functions.Add(namedFunction);
            }
            return(ret);
        }
Пример #13
0
        internal static PexObjectStructInfo Create(PexParseMeta parse)
        {
            var ret = new PexObjectStructInfo();

            ret.Name = parse.ReadString();

            var count = parse.Reader.ReadUInt16();

            for (var i = 0; i < count; i++)
            {
                var member = PexObjectStructInfoMember.Create(parse);
                ret.Members.Add(member);
            }
            return(ret);
        }
Пример #14
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);
        }