diff --git a/UndertaleModLib/Decompiler/Decompiler.cs b/UndertaleModLib/Decompiler/Decompiler.cs index 333032e78..6dfc6c87d 100644 --- a/UndertaleModLib/Decompiler/Decompiler.cs +++ b/UndertaleModLib/Decompiler/Decompiler.cs @@ -3801,8 +3801,16 @@ public static string Decompile(UndertaleCode code, GlobalDecompileContext global DoTypePropagation(context, blocks); context.Statements = new Dictionary>(); context.Statements.Add(0, HLDecompile(context, blocks, blocks[0], blocks[code.Length / 4])); - foreach (UndertaleCode duplicate in code.ChildEntries) - context.Statements.Add(duplicate.Offset / 4, HLDecompile(context, blocks, blocks[duplicate.Offset / 4], blocks[code.Length / 4])); + try + { + foreach (UndertaleCode duplicate in code.ChildEntries) + context.Statements.Add(duplicate.Offset / 4, HLDecompile(context, blocks, blocks[duplicate.Offset / 4], blocks[code.Length / 4])); + } + catch (ArgumentException) + { + // This is a duplicate function, ignore it. + } + // Write code. context.IndentationLevel = 0; diff --git a/UndertaleModLib/Decompiler/Disassembler.cs b/UndertaleModLib/Decompiler/Disassembler.cs index 480f3caff..7ad84f297 100644 --- a/UndertaleModLib/Decompiler/Disassembler.cs +++ b/UndertaleModLib/Decompiler/Disassembler.cs @@ -44,8 +44,16 @@ public static string Disassemble(this UndertaleCode code, IList fragments = new Dictionary(); - foreach (var dup in code.ChildEntries) - fragments.Add(dup.Offset / 4, (dup.Name?.Content ?? "") + $" (locals={dup.LocalsCount}, argc={dup.ArgumentsCount})"); + try + { + foreach (var dup in code.ChildEntries) + fragments.Add(dup.Offset / 4, (dup.Name?.Content ?? "") + $" (locals={dup.LocalsCount}, argc={dup.ArgumentsCount})"); + } + catch (ArgumentException) + { + // This is a duplicate function, ignore it. + } + List blocks = FindBlockAddresses(code); foreach (var inst in code.Instructions)