Ejemplo n.º 1
0
        public void TestPapyrusMethodFlags()
        {
            var m = new PapyrusMethodDefinition(PapyrusAssemblyDefinition.CreateAssembly(PapyrusVersionTargets.Fallout4));

            m.SetFlags(PapyrusMethodFlags.Global);
            Assert.IsTrue(m.IsGlobal);
            Assert.IsFalse(m.IsNative);

            m.IsNative = true;
            Assert.IsTrue(m.IsGlobal);
            Assert.IsTrue(m.IsNative);


            m.IsGlobal = false;
            Assert.IsFalse(m.IsGlobal);
            Assert.IsTrue(m.IsNative);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Converts the assembly.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        protected override PapyrusAssemblyOutput ConvertAssembly(ClrAssemblyInput input)
        {
            var clr        = input.Assembly;
            var mainModule = clr.MainModule;

            papyrusAssemblies.Clear();

            propertyMethods = new List <MethodDefinition>();

            var papyrusAssemblyToTypeDefinition = new Dictionary <PapyrusAssemblyDefinition, TypeDefinition>();


            // Keep track on the enum types so we can verify any parameter, variables, etc, and change the type into integers.
            ResolveEnumDefinitions(mainModule);

            foreach (var type in mainModule.Types)
            {
                try
                {
                    // We will skip this one for now
                    // as it will not really provide us with any necessary information at this early stage.
                    if (type.Name == "<Module>")
                    {
                        continue;
                    }

                    // Find all delegate types and methods and create references to them.
                    delegatePairDefinition = delegateFinder.FindDelegateTypes(type);

                    activeClrType = type;

                    var pex = PapyrusAssemblyDefinition.CreateAssembly(input.TargetPapyrusVersion);

                    SetHeaderInfo(input, pex, type);

                    CreateType(pex, type, processorOptions);

                    papyrusAssemblies.Add(pex);

                    papyrusAssemblyToTypeDefinition.Add(pex, type);


                    // After the type has been processed
                    // we will create the methods and then create the debug info as we do not have any info regarding the methods until those have been created ;-)

                    foreach (var t in pex.Types)
                    {
                        var firstState = t.States.FirstOrDefault();
                        if (firstState == null)
                        {
                            continue;                     // no state was found??
                        }
                        CreateMethods(papyrusAssemblies, type, t, pex, processorOptions)
                        .ForEach(firstState.Methods.Add);

                        CreateDebugInfo(pex, t, type);
                    }
                }
                catch (ProhibitedCodingBehaviourException exc)
                {
                    userInterface.DrawError($"Error processing '{type.FullName}': Prohibited use of " + exc.OpCode.GetValueOrDefault().Code + " in " +
                                            exc.Method.FullName + " at " + exc.Offset);
                }
                catch (Exception exc)
                {
                    userInterface.DrawError($"Error processing '{type.FullName}': Unhandled Exception - " + exc);
                }
            }

            return(new PapyrusAssemblyOutput(papyrusAssemblies.ToArray()));
        }