Skip to content

Commit

Permalink
Fixed functions duplications
Browse files Browse the repository at this point in the history
(I hope)
  • Loading branch information
zxopink committed Apr 24, 2023
1 parent e40525a commit 51dd87f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions UndertaleModLib/Decompiler/Decompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3801,8 +3801,16 @@ public static string Decompile(UndertaleCode code, GlobalDecompileContext global
DoTypePropagation(context, blocks);
context.Statements = new Dictionary<uint, List<Statement>>();
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;
Expand Down
12 changes: 10 additions & 2 deletions UndertaleModLib/Decompiler/Disassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ public static string Disassemble(this UndertaleCode code, IList<UndertaleVariabl
sb.Append(code.GenerateLocalVarDefinitions(vars, locals));

Dictionary<uint, string> fragments = new Dictionary<uint, string>();
foreach (var dup in code.ChildEntries)
fragments.Add(dup.Offset / 4, (dup.Name?.Content ?? "<null>") + $" (locals={dup.LocalsCount}, argc={dup.ArgumentsCount})");
try
{
foreach (var dup in code.ChildEntries)
fragments.Add(dup.Offset / 4, (dup.Name?.Content ?? "<null>") + $" (locals={dup.LocalsCount}, argc={dup.ArgumentsCount})");
}
catch (ArgumentException)
{
// This is a duplicate function, ignore it.
}

List<uint> blocks = FindBlockAddresses(code);

foreach (var inst in code.Instructions)
Expand Down

0 comments on commit 51dd87f

Please sign in to comment.