Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of GraphViz functionality #965

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions UndertaleModTool/Editors/UndertaleCodeEditor.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<local:DataUserControl x:Class="UndertaleModTool.UndertaleCodeEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:UndertaleModTool"
xmlns:undertale="clr-namespace:UndertaleModLib.Models;assembly=UndertaleModLib"
mc:Ignorable="d"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance undertale:UndertaleCode}" DataContextChanged="UserControl_DataContextChanged">
<UserControl.CommandBindings>
<CommandBinding Command="{x:Static local:UndertaleCodeEditor.Compile}" Executed="Command_Compile" />
Expand Down Expand Up @@ -44,7 +44,7 @@
<avalonEdit:TextEditor
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
FontFamily="Consolas"
Name="DecompiledEditor"
Name="DecompiledEditor"
IsReadOnly="True"
Background="#222222"
LineNumbersForeground="#DBDBDB"
Expand All @@ -62,7 +62,7 @@
<avalonEdit:TextEditor
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
FontFamily="Consolas"
Name="DisassemblyEditor"
Name="DisassemblyEditor"
IsReadOnly="True"
Background="#222222"
Foreground="#C0C0C0"
Expand All @@ -73,11 +73,6 @@
Padding="4"/>
</Grid>
</TabItem>
<TabItem Header="Graph view" Name="GraphTab">
<Viewbox Stretch="UniformToFill" StretchDirection="DownOnly">
<Image Name="GraphView"/>
</Viewbox>
</TabItem>
</TabControl>
</Grid>
</local:DataUserControl>
76 changes: 1 addition & 75 deletions UndertaleModTool/Editors/UndertaleCodeEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using GraphVizWrapper;
using GraphVizWrapper.Commands;
using GraphVizWrapper.Queries;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Folding;
Expand Down Expand Up @@ -50,7 +47,6 @@ public partial class UndertaleCodeEditor : DataUserControl
public UndertaleCode CurrentDisassembled = null;
public UndertaleCode CurrentDecompiled = null;
public List<string> CurrentLocals = null;
public UndertaleCode CurrentGraphed = null;
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 @@ -199,10 +195,6 @@ private async void TabControl_SelectionChanged(object sender, SelectionChangedEv
_ = DecompileCode(code, !DecompiledYet);
DecompiledYet = true;
}
if (GraphTab.IsSelected && code != CurrentGraphed)
{
GraphCode(code);
}
}

private async void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
Expand Down Expand Up @@ -259,10 +251,6 @@ private async void UserControl_DataContextChanged(object sender, DependencyPrope
{
_ = DecompileCode(code, true);
}
if (GraphTab.IsSelected && code != CurrentGraphed)
{
GraphCode(code);
}
}
}

Expand Down Expand Up @@ -556,66 +544,6 @@ private async Task DecompileCode(UndertaleCode code, bool first, LoaderDialog ex
}
}

private async void GraphCode(UndertaleCode code)
{
if (code.ParentEntry != null)
{
GraphView.Source = null;
CurrentGraphed = code;
return;
}

LoaderDialog dialog = new LoaderDialog("Generating graph", "Generating graph, please wait...");
dialog.Owner = Window.GetWindow(this);
Task t = Task.Run(() =>
{
ImageSource image = null;
try
{
code.UpdateAddresses();
List<uint> entryPoints = new List<uint>();
entryPoints.Add(0);
foreach (UndertaleCode duplicate in code.ChildEntries)
entryPoints.Add(duplicate.Offset / 4);
var blocks = Decompiler.DecompileFlowGraph(code, entryPoints);
string dot = Decompiler.ExportFlowGraph(blocks);

try
{
var getStartProcessQuery = new GetStartProcessQuery();
var getProcessStartInfoQuery = new GetProcessStartInfoQuery();
var registerLayoutPluginCommand = new RegisterLayoutPluginCommand(getProcessStartInfoQuery, getStartProcessQuery);
var wrapper = new GraphGeneration(getStartProcessQuery, getProcessStartInfoQuery, registerLayoutPluginCommand);
wrapper.GraphvizPath = Settings.Instance.GraphVizPath;

byte[] output = wrapper.GenerateGraph(dot, Enums.GraphReturnType.Png); // TODO: Use SVG instead

image = new ImageSourceConverter().ConvertFrom(output) as ImageSource;
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
if (mainWindow.ShowQuestion("Unable to execute GraphViz: " + e.Message + "\nMake sure you have downloaded it and set the path in settings.\nDo you want to open the download page now?", MessageBoxImage.Error) == MessageBoxResult.Yes)
MainWindow.OpenBrowser("https://graphviz.gitlab.io/_pages/Download/Download_windows.html");
}
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
mainWindow.ShowError(e.Message, "Graph generation failed");
}

Dispatcher.Invoke(() =>
{
GraphView.Source = image;
CurrentGraphed = code;
dialog.Hide();
});
});
dialog.ShowDialog();
await t;
}

private void DecompiledEditor_GotFocus(object sender, RoutedEventArgs e)
{
if (DecompiledEditor.IsReadOnly)
Expand Down Expand Up @@ -744,7 +672,6 @@ private async Task DecompiledLostFocusBody(object sender, RoutedEventArgs e)
// Show new code, decompiled.
CurrentDisassembled = null;
CurrentDecompiled = null;
CurrentGraphed = null;

// Tab switch
if (e == null)
Expand Down Expand Up @@ -822,7 +749,6 @@ private void DisassemblyEditor_LostFocus(object sender, RoutedEventArgs e)
// Get rid of old code
CurrentDisassembled = null;
CurrentDecompiled = null;
CurrentGraphed = null;

// Tab switch
if (e == null)
Expand Down
3 changes: 1 addition & 2 deletions UndertaleModTool/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class Settings
public static string ProfilesFolder = Path.Combine(AppDataFolder, "Profiles");

public string Version { get; set; } = MainWindow.Version;
public string GraphVizPath { get; set; } = ".\\graphviz\\bin";
public string GameMakerStudioPath { get; set; } = "%appdata%\\GameMaker-Studio";
public string GameMakerStudio2RuntimesPath { get; set; } = "%systemdrive%\\ProgramData\\GameMakerStudio2\\Cache\\runtimes"; /* Using %systemdrive% here fixes the runtimes not being found when the system drive is not C:\\ */
public bool AssetOrderSwappingEnabled { get; set; } = false;
Expand All @@ -37,7 +36,7 @@ public class Settings
// old backups only after 20 is reached (in the family tree, other unrelated mod families don't count)
// starting with the oldest, with which one to clear determined from a parenting ledger file
// (whose implementation does not exist yet).
//
//
// This comment should be cleared in the event that the remedies described are implemented.

public bool DeleteOldProfileOnSave { get; set; } = false;
Expand Down
1 change: 0 additions & 1 deletion UndertaleModTool/UndertaleModTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3551,7 +3551,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="GraphViz.NET" Version="1.0.0" />
<PackageReference Include="log4net" Version="2.0.12" />
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell">
<Version>1.1.4</Version>
Expand Down
3 changes: 0 additions & 3 deletions UndertaleModTool/Windows/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Grid.Column="0" Margin="3" Text="GraphViz path" ToolTip="Required if you want code decompile graphs"/>
<TextBox Grid.Row="0" Grid.Column="1" Margin="3" Text="{Binding GraphVizPath}"/>

<TextBlock Grid.Row="1" Grid.Column="0" Margin="3" Text="Game Maker: Studio 1.4 path" ToolTip="Required only if you want to use the Studio runner rather than the .exe or run the game under debugger."/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="3" Text="{Binding GameMakerStudioPath}"/>

Expand Down
10 changes: 0 additions & 10 deletions UndertaleModTool/Windows/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ namespace UndertaleModTool
/// </summary>
public partial class SettingsWindow : Window
{
public static string GraphVizPath
{
get => Settings.Instance.GraphVizPath;
set
{
Settings.Instance.GraphVizPath = value;
Settings.Save();
}
}

public static string GameMakerStudioPath
{
get => Settings.Instance.GameMakerStudioPath;
Expand Down