Example #1
0
        public PapyrusTypeDebugInfo ReadDebugInfo(PapyrusAssemblyDefinition asm)
        {
            var debugTable = new PapyrusTypeDebugInfo();

            var debugTime = pexReader.ReadInt64();

            debugTable.DebugTime = debugTime;

            var functionCount = pexReader.ReadInt16();

            var methodDescriptions = new List <PapyrusMethodDecription>();

            for (var i = 0; i < functionCount; i++)
            {
                var dbgfunc = new PapyrusMethodDecription();
                dbgfunc.DeclaringTypeName = pexReader.ReadStringRef();
                dbgfunc.StateName         = pexReader.ReadStringRef();
                dbgfunc.Name            = pexReader.ReadStringRef();
                dbgfunc.MethodType      = (PapyrusMethodTypes)pexReader.ReadByte();
                dbgfunc.BodyLineNumbers = new List <short>();
                var lineNumberCount = pexReader.ReadInt16();
                for (var j = 0; j < lineNumberCount; j++)
                {
                    dbgfunc.BodyLineNumbers.Add(pexReader.ReadInt16());
                }
                methodDescriptions.Add(dbgfunc);
            }
            debugTable.MethodDescriptions = methodDescriptions;

            if (asm.VersionTarget == PapyrusVersionTargets.Fallout4)
            {
                var propertyGroupCount   = pexReader.ReadInt16();
                var propertyDescriptions = new List <PapyrusStatePropertyDescriptions>();
                for (var i = 0; i < propertyGroupCount; i++)
                {
                    var groupInfo = new PapyrusStatePropertyDescriptions();
                    groupInfo.ObjectName         = pexReader.ReadStringRef();
                    groupInfo.GroupName          = pexReader.ReadStringRef();
                    groupInfo.GroupDocumentation = pexReader.ReadStringRef();
                    groupInfo.Userflags          = pexReader.ReadInt32();
                    var propertyNameCount = pexReader.ReadInt16();
                    for (var j = 0; j < propertyNameCount; j++)
                    {
                        groupInfo.PropertyNames.Add(pexReader.ReadStringRef());
                    }
                    propertyDescriptions.Add(groupInfo);
                }
                debugTable.PropertyDescriptions = propertyDescriptions;

                var structureOrderCount = pexReader.ReadInt16();

                var structDescriptions = new List <PapyrusStructDescription>();
                for (var i = 0; i < structureOrderCount; i++)
                {
                    var structDescription = new PapyrusStructDescription();
                    structDescription.DeclaringTypeName = pexReader.ReadStringRef();
                    structDescription.Name = pexReader.ReadStringRef();
                    var fieldCount = pexReader.ReadInt16();
                    for (var j = 0; j < fieldCount; j++)
                    {
                        structDescription.FieldNames.Add(pexReader.ReadStringRef());
                    }
                    structDescriptions.Add(structDescription);
                }
                debugTable.StructDescriptions = structDescriptions;
            }
            return(debugTable);
        }
Example #2
0
        private void CreateDebugInfo(PapyrusAssemblyDefinition pex, PapyrusTypeDefinition papyrusType,
                                     TypeDefinition type)
        {
            var debug = pex.DebugInfo;

            debug.DebugTime = UnixTimeConverterUtility.Convert(DateTime.Now);

            if (pex.VersionTarget == PapyrusVersionTargets.Fallout4)
            {
                foreach (var t in papyrusType.NestedTypes)
                {
                    var structInfo = new PapyrusStructDescription();
                    structInfo.Name = papyrusType.Name;
                    structInfo.DeclaringTypeName = type.Name.Ref(pex);

                    foreach (var f in t.Fields)
                    {
                        structInfo.FieldNames.Add(f.Name);
                    }

                    debug.StructDescriptions.Add(structInfo);
                }
            }

            foreach (var s in papyrusType.States)
            {
                foreach (var method in s.Methods)
                {
                    var m = new PapyrusMethodDecription();
                    m.Name = method.Name;
                    m.DeclaringTypeName = type.Name.Ref(pex);
                    m.StateName         = "".Ref(pex);

                    if (method.Name.Value.ToLower().StartsWith("get_"))
                    {
                        m.MethodType = PapyrusMethodTypes.Getter;
                    }
                    else if (method.Name.Value.ToLower().StartsWith("set_"))
                    {
                        m.MethodType = PapyrusMethodTypes.Setter;
                    }
                    else
                    {
                        m.MethodType = PapyrusMethodTypes.Method;
                    }
                    var lastStart = 0;
                    method.Body.Instructions.ForEach(i =>
                    {
                        if (i.SequencePoint != null)
                        {
                            lastStart = i.SequencePoint.StartLine;
                            m.BodyLineNumbers.Add((short)i.SequencePoint.StartLine);
                        }
                        else
                        {
                            m.BodyLineNumbers.Add((short)lastStart);
                        }
                    });

                    debug.MethodDescriptions.Add(m);
                }
            }

            var stateProperties = new PapyrusStatePropertyDescriptions();

            stateProperties.GroupDocumentation = "".Ref(pex);
            stateProperties.GroupName          = "".Ref(pex);
            stateProperties.ObjectName         = type.Name.Ref(pex);

            foreach (var prop in type.Properties)
            {
                // TODO: This
                stateProperties.PropertyNames.Add(prop.Name.Ref(pex));
            }
            debug.PropertyDescriptions.Add(stateProperties);
        }