Skip to content

Commit

Permalink
Fix #1320
Browse files Browse the repository at this point in the history
The locals list used for syntax highlighting is reset upon changing to the disassembly tab, and previously was only re-populated on the decompiled tab if the code was newly-decompiled. This now re-populates when switching to the decompiled tab, every time.
  • Loading branch information
colinator27 committed Jul 22, 2024
1 parent d4f6431 commit 6ffdecb
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public partial class UndertaleCodeEditor : DataUserControl

public UndertaleCode CurrentDisassembled = null;
public UndertaleCode CurrentDecompiled = null;
public List<string> CurrentLocals = null;
public List<string> CurrentLocals = new();
public string ProfileHash = mainWindow.ProfileHash;
public string MainPath = Path.Combine(Settings.ProfilesFolder, mainWindow.ProfileHash, "Main");
public string TempPath = Path.Combine(Settings.ProfilesFolder, mainWindow.ProfileHash, "Temp");
Expand Down Expand Up @@ -249,6 +249,11 @@ private void FillInCodeViewer(bool overrideFirst = false)
else
_ = DecompileCode(code, true);
}
if (DecompiledTab.IsSelected)
{
// Re-populate local variables when in decompiled code, fixing #1320
PopulateCurrentLocals(mainWindow.Data, code);
}
}

private async void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down Expand Up @@ -525,7 +530,7 @@ private void DisassembleCode(UndertaleCode code, bool first)
var data = mainWindow.Data;
text = code.Disassemble(data.Variables, data.CodeLocals.For(code));

CurrentLocals = new List<string>();
CurrentLocals.Clear();
}
catch (Exception ex)
{
Expand Down Expand Up @@ -784,14 +789,7 @@ private async Task DecompileCode(UndertaleCode code, bool first, LoaderDialog ex
else if (decompiled != null)
{
DecompiledEditor.Document.Text = decompiled;
CurrentLocals = new List<string>();

var locals = dataa.CodeLocals.ByName(code.Name.Content);
if (locals != null)
{
foreach (var local in locals.Locals)
CurrentLocals.Add(local.Name.Content);
}
PopulateCurrentLocals(dataa, code);

RestoreCaretPosition(DecompiledEditor, currLine, currColumn, scrollPos);

Expand Down Expand Up @@ -825,6 +823,19 @@ private async Task DecompileCode(UndertaleCode code, bool first, LoaderDialog ex
}
}

private void PopulateCurrentLocals(UndertaleData data, UndertaleCode code)
{
CurrentLocals.Clear();

// Look up locals for given code entry's name, for syntax highlighting
var locals = data.CodeLocals.ByName(code.Name.Content);
if (locals != null)
{
foreach (var local in locals.Locals)
CurrentLocals.Add(local.Name.Content);
}
}

private void DecompiledEditor_GotFocus(object sender, RoutedEventArgs e)
{
if (DecompiledEditor.IsReadOnly)
Expand Down

0 comments on commit 6ffdecb

Please sign in to comment.