Exemple #1
0
        public static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            UnrealTypes.Load();
            AssemblyRewriter rewriter = new AssemblyRewriter();

            if (System.Diagnostics.Debugger.IsAttached && args.Length == 0)
            {
                ManagedUnrealReflectionBase.UpdateSerializerCode();
                //RunTests(rewriter);
            }

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            foreach (string filePath in args)
            {
                ProcessAssembly(rewriter, filePath);
                additionalAssemblySearchPath = null;
            }

            stopwatch.Stop();
            Console.WriteLine("AssemblyRewriter finished " + stopwatch.Elapsed);
            Console.ReadLine();
        }
Exemple #2
0
        private static void RunTests(AssemblyRewriter rewriter)
        {
            string dir          = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string assemblyPath = Path.Combine(dir, "../", "UnrealEngine.Runtime.dll");

            if (File.Exists(assemblyPath))
            {
                ProcessAssembly(rewriter, assemblyPath);
            }
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            if (!args.Any())
            {
                Console.Error.WriteLine("Error: No input files. Add file path to dll as argument.");
                Environment.Exit(2);
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            UnrealTypes.Load();
            AssemblyRewriter rewriter = new AssemblyRewriter();

            if (Debugger.IsAttached)
            {
                ManagedUnrealReflectionBase.UpdateSerializerCode();
                //RunTests(rewriter);
            }

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            foreach (string filePath in args)
            {
                Console.WriteLine("Processing file: " + filePath);
                if (!ProcessAssembly(rewriter, filePath))
                {
                    Environment.ExitCode = 3;
                    break;
                }
                additionalAssemblySearchPath = null;
            }

            stopwatch.Stop();
            Console.WriteLine("AssemblyRewriter finished " + stopwatch.Elapsed);
            if (ManagedUnrealModuleInfo.NumWarnings > 0)
            {
                Console.WriteLine("!!!!!! " + ManagedUnrealModuleInfo.NumWarnings + " warning(s) whilst running AssemblyRewriter");
                ManagedUnrealModuleInfo.NumWarnings = 0;
            }
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            if (!args.Any())
            {
                Console.Error.WriteLine($"Error: No input files. Add file path to dll as argument.");
                Environment.Exit(2);
            }

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            UnrealTypes.Load();
            AssemblyRewriter rewriter = new AssemblyRewriter();

            if (System.Diagnostics.Debugger.IsAttached)
            {
                ManagedUnrealReflectionBase.UpdateSerializerCode();
                //RunTests(rewriter);
            }


            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            foreach (string filePath in args)
            {
                Console.WriteLine($"Processing file: {filePath}");
                var success = ProcessAssembly(rewriter, filePath);
                if (!success)
                {
                    Environment.ExitCode = 3;
                }
                additionalAssemblySearchPath = null;
            }

            stopwatch.Stop();
            Console.WriteLine("AssemblyRewriter finished " + stopwatch.Elapsed);
            Console.ReadLine();
        }
Exemple #5
0
        private static bool ProcessAssembly(AssemblyRewriter rewriter, string filePath)
        {
            if (File.Exists(filePath))
            {
                System.Reflection.Assembly assembly = null;

                string pdbFilePath = Path.ChangeExtension(filePath, ".pdb");
                if (Path.GetFileNameWithoutExtension(filePath) == "UnrealEngine.Runtime")
                {
                    // Required so that type comparisons work correctly (this should only be used for testing purposes)
                    assembly = typeof(ManagedUnrealModuleInfo).Assembly;
                }
                else if (File.Exists(pdbFilePath))
                {
                    assembly = System.Reflection.Assembly.Load(File.ReadAllBytes(filePath), File.ReadAllBytes(pdbFilePath));
                }
                else
                {
                    assembly = System.Reflection.Assembly.Load(File.ReadAllBytes(filePath));
                }

                additionalAssemblySearchPath = Path.GetDirectoryName(filePath);

                if (ManagedUnrealModuleInfo.AssemblyHasSerializedModuleInfo(assembly))
                {
                    if (ManagedUnrealModuleInfo.LoadModuleFromAssembly(assembly) == null)
                    {
                        throw new Exception("Assembly already rewritten but failed to deserialize module info " + assembly.GetName().Name);
                    }
                    Console.WriteLine("Skip \"" + assembly.GetName().Name + "\"");
                    return(true);
                }

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                ManagedUnrealModuleInfo moduleInfo = null;
                try
                {
                    moduleInfo = ManagedUnrealModuleInfo.CreateModuleFromAssembly(assembly);
                } catch (Exception e)
                {
                    Console.WriteLine("Error while parsing module \"" + assembly.GetName().Name + "\"");
                    Console.WriteLine();
                    Console.WriteLine(e.Message);
                    Console.WriteLine();
                    Console.WriteLine(e.ToString());
                }

                stopwatch.Stop();
                Console.WriteLine("Read \"" + assembly.GetName().Name + "\" " + stopwatch.Elapsed);

                if (moduleInfo != null)
                {
                    stopwatch.Reset();
                    stopwatch.Start();

                    var noError = true;

                    try
                    {
                        rewriter.RewriteModule(moduleInfo, filePath);
                        Console.WriteLine("Write \"" + assembly.GetName().Name + "\" " + stopwatch.Elapsed);
                    } catch (Exception e)
                    {
                        Console.WriteLine("Error when rewriting module \"" + assembly.GetName().Name + "\" " + stopwatch.Elapsed);
                        Console.WriteLine();
                        Console.WriteLine(e.Message);
                        Console.WriteLine();
                        Console.WriteLine(e.ToString());
                        noError = false;
                    } finally
                    {
                        stopwatch.Stop();
                    }

                    return(noError);
                }
            }
            return(false);
        }