diff --git a/SkyEditor.ROMEditor.Windows/MysteryDungeon/PSMD/Projects/PsmdLuaProject.vb b/SkyEditor.ROMEditor.Windows/MysteryDungeon/PSMD/Projects/PsmdLuaProject.vb index 2e5501a..4f6df88 100644 --- a/SkyEditor.ROMEditor.Windows/MysteryDungeon/PSMD/Projects/PsmdLuaProject.vb +++ b/SkyEditor.ROMEditor.Windows/MysteryDungeon/PSMD/Projects/PsmdLuaProject.vb @@ -341,7 +341,7 @@ Namespace MysteryDungeon.PSMD.Projects Me.Message = My.Resources.Language.LoadingDecompilingScripts Me.Progress = 0 - Dim scriptSource As String = Path.Combine(Me.GetRawFilesDir, "romfs", "script") + Dim scriptSourceDir As String = Path.Combine(Me.GetRawFilesDir, "romfs", "script") Dim scriptDestination As String = Path.Combine(Me.GetRootDirectory, "script") Dim filesToOpen As New ConcurrentBag(Of String) @@ -352,15 +352,15 @@ Namespace MysteryDungeon.PSMD.Projects f.BatchSize = Environment.ProcessorCount * 2 - Await f.RunForEach(Directory.GetFiles(scriptSource, "*.lua", SearchOption.AllDirectories), - Sub(item As String) - Dim dest = item.Replace(scriptSource, scriptDestination) + Await f.RunForEach(Directory.GetFiles(scriptSourceDir, "*.lua", SearchOption.AllDirectories), + Sub(scriptSource As String) + Dim dest = scriptSource.Replace(scriptSourceDir, scriptDestination) If Not Directory.Exists(Path.GetDirectoryName(dest)) Then Directory.CreateDirectory(Path.GetDirectoryName(dest)) End If Dim decompiledScript = LuaDecompiler.DecompileScript(File.ReadAllBytes(scriptSource)) - File.WriteAllText(scriptDestination, decompiledScript) + File.WriteAllText(dest, decompiledScript) File.Copy(dest, dest & ".original") filesToOpen.Add(dest) diff --git a/SkyEditor.RomEditor.CSharp/Utilities/LuaDecompiler.cs b/SkyEditor.RomEditor.CSharp/Utilities/LuaDecompiler.cs index 9867405..5d0a191 100644 --- a/SkyEditor.RomEditor.CSharp/Utilities/LuaDecompiler.cs +++ b/SkyEditor.RomEditor.CSharp/Utilities/LuaDecompiler.cs @@ -15,10 +15,21 @@ public static string DecompileScript(byte[] compiledScript) var decompiler = new Decompiler(function); decompiler.decompile(); - var output = new StringOutput(); - decompiler.print(output); + try + { + var output = new StringOutput(); + decompiler.print(output); - return output.GetOutput(); + return output.GetOutput(); + } + catch (Exception ex) + { + Console.Error.WriteLine(ex.ToString()); + return $"--[=====[\n" + + $"Encountered exception in LuaDecompiler.DecompileScript:" + + $"{ex}\n" + + $"--]=====]"; + } } private static LFunction LoadScript(byte[] compiledScript)