|
12 | 12 | using System.Text; |
13 | 13 | using System.Threading; |
14 | 14 | using System.Threading.Tasks; |
| 15 | +using Underanalyzer.Decompiler; |
15 | 16 | using UndertaleModLib; |
16 | 17 | using UndertaleModLib.Compiler; |
| 18 | +using UndertaleModLib.Decompiler; |
17 | 19 | using UndertaleModLib.Models; |
18 | 20 | using UndertaleModLib.Project; |
19 | 21 | using UndertaleModLib.Scripting; |
@@ -499,15 +501,30 @@ private static int Dump(DumpOptions options) |
499 | 501 | // If user provided code to dump, dump code |
500 | 502 | if ((options.Code?.Length > 0) && (program.Data.Code?.Count > 0)) |
501 | 503 | { |
| 504 | + GlobalDecompileContext globalDecompileContext = new(program.Data); |
| 505 | + IDecompileSettings decompilerSettings = program.Data.ToolInfo.DecompilerSettings; |
| 506 | + |
502 | 507 | // If user wanted to dump everything, do that, otherwise only dump what user provided |
503 | | - string[] codeArray; |
504 | 508 | if (options.Code.Contains(UMT_DUMP_ALL)) |
505 | | - codeArray = program.Data.Code.Select(c => c.Name.Content).ToArray(); |
| 509 | + { |
| 510 | + int totalCores = Environment.ProcessorCount; |
| 511 | + int outerLimit = Math.Max(1, totalCores / 4); |
| 512 | + Parallel.ForEach(program.Data.Code, new ParallelOptions { MaxDegreeOfParallelism = outerLimit }, code => |
| 513 | + { |
| 514 | + if (code.ParentEntry is not null) |
| 515 | + { |
| 516 | + return; |
| 517 | + } |
| 518 | + program.DumpCodeEntry(code, globalDecompileContext, decompilerSettings); |
| 519 | + }); |
| 520 | + } |
506 | 521 | else |
507 | | - codeArray = options.Code; |
508 | | - |
509 | | - foreach (string code in codeArray) |
510 | | - program.DumpCodeEntry(code); |
| 522 | + { |
| 523 | + foreach (string code in options.Code) |
| 524 | + { |
| 525 | + program.DumpCodeEntry(code, globalDecompileContext, decompilerSettings); |
| 526 | + } |
| 527 | + } |
511 | 528 | } |
512 | 529 |
|
513 | 530 | // If user wanted to dump strings, dump all of them in a text file |
@@ -817,32 +834,44 @@ private void CliQuickInfo() |
817 | 834 | /// <summary> |
818 | 835 | /// Dumps a code entry from a data file. |
819 | 836 | /// </summary> |
820 | | - /// <param name="codeEntry">The code entry that should get dumped</param> |
821 | | - private void DumpCodeEntry(string codeEntry) |
| 837 | + /// <param name="codeEntryName">The code entry name that should get dumped</param> |
| 838 | + /// <param name="context">Decompile context to use when dumping</param> |
| 839 | + /// <param name="settings">Settings to use for the decompiler</param> |
| 840 | + private void DumpCodeEntry(string codeEntryName, GlobalDecompileContext context, IDecompileSettings settings) |
822 | 841 | { |
823 | | - UndertaleCode code = Data.Code.ByName(codeEntry); |
824 | | - |
| 842 | + UndertaleCode code = Data.Code.ByName(codeEntryName); |
825 | 843 |
|
826 | 844 | if (code == null) |
827 | 845 | { |
828 | | - Console.Error.WriteLine($"Data file does not contain a code entry named {codeEntry}!"); |
| 846 | + Console.Error.WriteLine($"Data file does not contain a code entry named {codeEntryName}!"); |
829 | 847 | return; |
830 | 848 | } |
831 | 849 |
|
| 850 | + DumpCodeEntry(code, context, settings); |
| 851 | + } |
| 852 | + |
| 853 | + /// <summary> |
| 854 | + /// Dumps a code entry from a data file. |
| 855 | + /// </summary> |
| 856 | + /// <param name="code">The code entry that should get dumped</param> |
| 857 | + /// <param name="context">Decompile context to use when dumping</param> |
| 858 | + /// <param name="settings">Settings to use for the decompiler</param> |
| 859 | + private void DumpCodeEntry(UndertaleCode code, GlobalDecompileContext context, IDecompileSettings settings) |
| 860 | + { |
832 | 861 | string directory = Path.Join(Output.FullName, "CodeEntries"); |
833 | 862 |
|
834 | 863 | Directory.CreateDirectory(directory); |
835 | 864 |
|
836 | 865 | if (Verbose) |
837 | | - Console.WriteLine($"Dumping {codeEntry}"); |
| 866 | + Console.WriteLine($"Dumping {code.Name?.Content}"); |
838 | 867 |
|
839 | | - string dest = Paths.TryJoinVerifyWithinDirectory(directory, $"{codeEntry}.gml"); |
| 868 | + string dest = Paths.TryJoinVerifyWithinDirectory(directory, $"{code.Name?.Content}.gml"); |
840 | 869 | if (dest is null) |
841 | 870 | { |
842 | | - Console.Error.WriteLine($"Failed to export code entry with name {codeEntry}"); |
| 871 | + Console.Error.WriteLine($"Failed to export code entry with name {code.Name?.Content}"); |
843 | 872 | return; |
844 | 873 | } |
845 | | - File.WriteAllText(dest, GetDecompiledText(code)); |
| 874 | + File.WriteAllText(dest, GetDecompiledText(code, context, settings)); |
846 | 875 | } |
847 | 876 |
|
848 | 877 | /// <summary> |
|
0 commit comments