using System.Text; using System; using System.IO; using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; using UndertaleModLib.Util; EnsureDataLoaded(); if (Data.IsYYC()) { ScriptError("The opened game uses YYC: no code is available."); return; } string codeFolder = PromptChooseDirectory(); if (codeFolder is null) { return; } GlobalDecompileContext globalDecompileContext = new(Data); Underanalyzer.Decompiler.IDecompileSettings decompilerSettings = Data.ToolInfo.DecompilerSettings; List toDump = Data.Code.Where(c => c.ParentEntry is null).ToList(); SetProgressBar(null, "Code Entries", 0, toDump.Count); StartProgressBarUpdater(); await DumpCode(); await StopProgressBarUpdater(); HideProgressBar(); async Task DumpCode() { await Task.Run(() => Parallel.ForEach(toDump, DumpCode)); } void DumpCode(UndertaleCode code) { if (code is not null) { string path = Paths.JoinVerifyWithinDirectory(codeFolder, code.Name.Content + ".gml"); try { File.WriteAllText(path, (code != null ? new Underanalyzer.Decompiler.DecompileContext(globalDecompileContext, code, decompilerSettings).DecompileToString() : "")); } catch (Exception e) { File.WriteAllText(path, "/*\nDECOMPILER FAILED!\n\n" + e.ToString() + "\n*/"); } } IncrementProgressParallel(); }