Exemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();

            taskButtons[buttonDecompile]      = () => new DecompileTask(this, "src/decompiled");
            taskButtons[buttonDiffMerged]     = () => new DiffTask(this, "src/decompiled", "src/merged", "patches/merged", MergedDiffCutoff);
            taskButtons[buttonPatchMerged]    = () => new PatchTask(this, "src/decompiled", "src/merged", "patches/merged", MergedDiffCutoff);
            taskButtons[buttonDiffTerraria]   = () => new DiffTask(this, "src/merged", "src/Terraria", "patches/Terraria", TerrariaDiffCutoff);
            taskButtons[buttonPatchTerraria]  = () => new PatchTask(this, "src/merged", "src/Terraria", "patches/Terraria", TerrariaDiffCutoff);
            taskButtons[buttonDiffModLoader]  = () => new DiffTask(this, "src/Terraria", "src/tModLoader", "patches/tModLoader", tModLoaderDiffCutoff, FormatTask.tModLoaderFormat);
            taskButtons[buttonPatchModLoader] = () => new PatchTask(this, "src/Terraria", "src/tModLoader", "patches/tModLoader", tModLoaderDiffCutoff, FormatTask.tModLoaderFormat);
            taskButtons[buttonSetupDebugging] = () => new SetupDebugTask(this);
            taskButtons[buttonFormat]         = () => new FormatTask(this, FormatTask.tModLoaderFormat);

            taskButtons[buttonRegenSource] = () =>
                                             new RegenSourceTask(this, new[] { buttonPatchMerged, buttonPatchTerraria, buttonPatchModLoader, buttonSetupDebugging }
                                                                 .Select(b => taskButtons[b]()).ToArray());

            taskButtons[buttonSetup] = () =>
                                       new SetupTask(this, new[] { buttonDecompile, buttonPatchMerged, buttonPatchTerraria, buttonPatchModLoader, buttonSetupDebugging }
                                                     .Select(b => taskButtons[b]()).ToArray());

            menuItemWarnings.Checked = Program.SuppressWarnings.Get();
            menuItemSingleDecompileThread.Checked = SingleDecompileThread.Get();

            Closing += (sender, args) =>
            {
                if (buttonCancel.Enabled)
                {
                    cancelSource.Cancel();
                    args.Cancel   = true;
                    closeOnCancel = true;
                }
            };
        }
Exemplo n.º 2
0
        public override void Run()
        {
            taskInterface.SetStatus("Deleting Old Src");

            if (Directory.Exists(FullSrcDir))
            {
                Directory.Delete(FullSrcDir, true);
            }

            var resolver   = new EmbeddedAssemblyResolver();
            var readParams = new ReaderParameters()
            {
                AssemblyResolver = resolver
            };

            taskInterface.CancellationToken().ThrowIfCancellationRequested();
            taskInterface.SetStatus("Loading Terraria.exe");
            clientModule = ModuleDefinition.ReadModule(TerrariaPath, readParams);

            taskInterface.CancellationToken().ThrowIfCancellationRequested();
            taskInterface.SetStatus("Loading TerrariaServer.exe");
            serverModule = ModuleDefinition.ReadModule(TerrariaServerPath, readParams);

            resolver.baseModule = clientModule;

            VersionCheck(clientModule.Assembly);
            VersionCheckAlt(serverModule.Assembly);

            var options = new DecompilationOptions {
                FullDecompilation      = true,
                CancellationToken      = taskInterface.CancellationToken(),
                SaveAsProjectDirectory = FullSrcDir
            };

            var clientSources   = GetCodeFiles(clientModule, options).ToList();
            var serverSources   = GetCodeFiles(serverModule, options).ToList();
            var clientResources = GetResourceFiles(clientModule, options).ToList();
            var serverResources = GetResourceFiles(serverModule, options).ToList();

            var sources   = CombineFiles(clientSources, serverSources, src => src.Key);
            var resources = CombineFiles(clientResources, serverResources, res => res.Item1);

            var items = new List <WorkItem>();

            items.AddRange(sources.Select(src => new WorkItem(
                                              "Decompiling: " + src.Key, () => DecompileSourceFile(src, options))));

            items.AddRange(resources.Select(res => new WorkItem(
                                                "Extracting: " + res.Item1, () => ExtractResource(res, options))));

            items.Add(new WorkItem("Writing Assembly Info",
                                   () => WriteAssemblyInfo(clientModule, options)));

            items.Add(new WorkItem("Writing Terraria" + lang.ProjectFileExtension,
                                   () => WriteProjectFile(clientModule, clientGuid, clientSources, clientResources, options)));

            items.Add(new WorkItem("Writing TerrariaServer" + lang.ProjectFileExtension,
                                   () => WriteProjectFile(serverModule, serverGuid, serverSources, serverResources, options)));

            items.Add(new WorkItem("Writing Terraria" + lang.ProjectFileExtension + ".user",
                                   () => WriteProjectUserFile(clientModule, SteamDir.Get(), options)));

            items.Add(new WorkItem("Writing TerrariaServer" + lang.ProjectFileExtension + ".user",
                                   () => WriteProjectUserFile(serverModule, SteamDir.Get(), options)));

            ExecuteParallel(items, maxDegree: SingleDecompileThread.Get() ? 1 : 0);
        }