GUI: Unity path selection and auto-detect behaviour

This commit is contained in:
Katy Coe
2020-02-10 02:01:41 +01:00
parent bab8a8f6fd
commit d88eb6ce2c
3 changed files with 83 additions and 16 deletions

View File

@@ -30,6 +30,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\Il2CppInspector.CLI\Utils.cs" Link="Utils.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Ookii.Dialogs.Wpf.NETCore" Version="2.0.0" />
<PackageReference Include="XamlAnimatedGif" Version="1.2.2" /> <PackageReference Include="XamlAnimatedGif" Version="1.2.2" />
</ItemGroup> </ItemGroup>

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:Il2CppInspectorGUI" xmlns:local="clr-namespace:Il2CppInspectorGUI"
xmlns:gif="https://github.com/XamlAnimatedGif/XamlAnimatedGif" xmlns:gif="https://github.com/XamlAnimatedGif/XamlAnimatedGif"
mc:Ignorable="d" mc:Ignorable="d"
Title="Il2CppInspector" Height="630" Width="970" Background="White"> Title="Il2CppInspector" Height="630" Width="990" Background="White">
<Window.Resources> <Window.Resources>
<!-- Our favourite colours --> <!-- Our favourite colours -->
<SolidColorBrush x:Key="MicrosoftBlue" Color="#00A2ED"/> <SolidColorBrush x:Key="MicrosoftBlue" Color="#00A2ED"/>
@@ -100,7 +100,7 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="300"></ColumnDefinition> <ColumnDefinition Width="300"></ColumnDefinition>
<ColumnDefinition Width="15"></ColumnDefinition> <ColumnDefinition Width="25"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition> <ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<DockPanel DockPanel.Dock="Left"> <DockPanel DockPanel.Dock="Left">
@@ -159,7 +159,7 @@
<Label Grid.Row="8" Grid.Column="1" Content="{Binding Path=Binary.RegistrationFunctionPointer}" ContentStringFormat="0x{0:x8}"></Label> <Label Grid.Row="8" Grid.Column="1" Content="{Binding Path=Binary.RegistrationFunctionPointer}" ContentStringFormat="0x{0:x8}"></Label>
</Grid> </Grid>
</DockPanel> </DockPanel>
<Separator Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Margin="5"> <Separator Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Margin="5,5,10,5">
<Separator.LayoutTransform> <Separator.LayoutTransform>
<RotateTransform Angle="90"></RotateTransform> <RotateTransform Angle="90"></RotateTransform>
</Separator.LayoutTransform> </Separator.LayoutTransform>
@@ -201,13 +201,14 @@
<!-- List of namespaces to export --> <!-- List of namespaces to export -->
<DockPanel DockPanel.Dock="Right"> <DockPanel DockPanel.Dock="Right">
<Label DockPanel.Dock="Top" Foreground="{StaticResource WindowsBlue}" FontSize="18">Namespaces</Label> <Label DockPanel.Dock="Top" Foreground="{StaticResource WindowsBlue}" FontSize="18">Namespaces</Label>
<TreeView DockPanel.Dock="Bottom" Name="trvNamespaces" ItemTemplate="{StaticResource NamespaceTreeItemTemplate}" Width="220" Margin="5"></TreeView> <TreeView DockPanel.Dock="Bottom" Name="trvNamespaces" ItemTemplate="{StaticResource NamespaceTreeItemTemplate}" Width="220" Margin="10,5,5,5"></TreeView>
</DockPanel> </DockPanel>
<!-- Settings --> <!-- Settings -->
<StackPanel DockPanel.Dock="Left"> <StackPanel DockPanel.Dock="Left">
<Label Foreground="{StaticResource WindowsBlue}" FontSize="18">Configure output</Label> <Label Foreground="{StaticResource WindowsBlue}" FontSize="18">Configure output</Label>
<!-- C# code stubs output -->
<RadioButton GroupName="grpOutputType" IsChecked="True" VerticalContentAlignment="Center" FontSize="18" Foreground="{StaticResource MicrosoftGreen}">C# prototypes</RadioButton> <RadioButton GroupName="grpOutputType" IsChecked="True" VerticalContentAlignment="Center" FontSize="18" Foreground="{StaticResource MicrosoftGreen}">C# prototypes</RadioButton>
<GroupBox Header="Layout" Margin="5" Padding="5"> <GroupBox Header="Layout" Margin="5" Padding="5">
<StackPanel> <StackPanel>
@@ -226,22 +227,28 @@
</StackPanel> </StackPanel>
</GroupBox> </GroupBox>
<CheckBox Margin="2">Suppress pointer, offset and index metadata comments</CheckBox> <CheckBox Margin="2">Suppress pointer, offset and index metadata comments</CheckBox>
<CheckBox Margin="2">Attempt to generate code that compiles</CheckBox> <CheckBox Margin="2">Attempt to generate output that compiles</CheckBox>
<CheckBox IsChecked="True" Margin="2">Place assembly-level attributes in separate files</CheckBox> <CheckBox IsChecked="True" Margin="2">Place assembly-level attributes in separate files</CheckBox>
<Separator Margin="5"/>
<Separator Margin="5,15,5,15"/>
<!-- Visual Studio solution -->
<RadioButton GroupName="grpOutputType" VerticalContentAlignment="Center" FontSize="18" Foreground="{StaticResource MicrosoftGreen}">Visual Studio solution</RadioButton> <RadioButton GroupName="grpOutputType" VerticalContentAlignment="Center" FontSize="18" Foreground="{StaticResource MicrosoftGreen}">Visual Studio solution</RadioButton>
<TextBlock TextWrapping="WrapWithOverflow">Uses the settings above but forces tree layout, compilable output and separate assembly attributes</TextBlock> <TextBlock TextWrapping="WrapWithOverflow">Uses the settings above but forces tree layout, compilable output and separate assembly attributes</TextBlock>
<DockPanel> <DockPanel>
<Button DockPanel.Dock="Right" Width="70" Margin="2">Browse</Button> <Button Name="btnUnityPath" DockPanel.Dock="Right" Width="70" Margin="4" Click="BtnUnityPath_OnClick">Browse</Button>
<Label DockPanel.Dock="Left" Width="160">Unity editor path:</Label> <Label DockPanel.Dock="Left" Width="170">Unity editor path:</Label>
<Label DockPanel.Dock="Left">&lt;not set></Label> <TextBlock Name="txtUnityPath" DockPanel.Dock="Left" VerticalAlignment="Center" FlowDirection="RightToLeft" HorizontalAlignment="Right" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
</DockPanel> </DockPanel>
<DockPanel> <DockPanel>
<Button DockPanel.Dock="Right" Width="70" Margin="2">Browse</Button> <Button Name="btnUnityScriptPath" DockPanel.Dock="Right" Width="70" Margin="4" Click="BtnUnityScriptPath_OnClick">Browse</Button>
<Label DockPanel.Dock="Left" Width="160">Unity script assemblies path:</Label> <Label DockPanel.Dock="Left" Width="170">Unity script assemblies path:</Label>
<Label DockPanel.Dock="Left">&lt;not set></Label> <TextBlock Name="txtUnityScriptPath" DockPanel.Dock="Left" VerticalAlignment="Center" FlowDirection="RightToLeft" HorizontalAlignment="Right" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
</DockPanel> </DockPanel>
<Separator Margin="5"/>
<Separator Margin="5,15,5,15"/>
<!-- IDAPython script -->
<RadioButton GroupName="grpOutputType" VerticalContentAlignment="Center" FontSize="18" Foreground="{StaticResource MicrosoftGreen}">IDAPython script</RadioButton> <RadioButton GroupName="grpOutputType" VerticalContentAlignment="Center" FontSize="18" Foreground="{StaticResource MicrosoftGreen}">IDAPython script</RadioButton>
<TextBlock TextWrapping="WrapWithOverflow">No configuration required for IDA script output</TextBlock> <TextBlock TextWrapping="WrapWithOverflow">No configuration required for IDA script output</TextBlock>
</StackPanel> </StackPanel>

View File

@@ -24,6 +24,8 @@ using System.Windows.Shapes;
using Microsoft.Win32; using Microsoft.Win32;
using Il2CppInspector; using Il2CppInspector;
using Il2CppInspector.Reflection; using Il2CppInspector.Reflection;
using Ookii.Dialogs.Wpf;
using Path = System.IO.Path;
namespace Il2CppInspectorGUI namespace Il2CppInspectorGUI
{ {
@@ -37,10 +39,25 @@ namespace Il2CppInspectorGUI
// Subscribe to status update events // Subscribe to status update events
((App) Application.Current).OnStatusUpdate += OnStatusUpdate; ((App) Application.Current).OnStatusUpdate += OnStatusUpdate;
// Find Unity paths
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
txtUnityPath.Text = Utils.FindPath($@"{programFiles}\Unity\Hub\Editor\*") ?? "<not set>";
txtUnityScriptPath.Text = Utils.FindPath($@"{programFiles}\Unity\Hub\Editor\*\Editor\Data\Resources\PackageManager\ProjectTemplates\libcache\com.unity.template.3d-*\ScriptAssemblies") ?? "<not set>";
} }
/// <summary>
/// Update the busy indicator message
/// </summary>
private void OnStatusUpdate(object sender, string e) => txtBusyStatus.Dispatcher.Invoke(() => txtBusyStatus.Text = e + "..."); private void OnStatusUpdate(object sender, string e) => txtBusyStatus.Dispatcher.Invoke(() => txtBusyStatus.Text = e + "...");
/// <summary>
/// User clicked on a link
/// </summary>
private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e) {
Process.Start(new ProcessStartInfo {FileName = e.Uri.ToString(), UseShellExecute = true});
}
/// <summary> /// <summary>
/// Select global metadata file /// Select global metadata file
/// </summary> /// </summary>
@@ -163,10 +180,48 @@ namespace Il2CppInspectorGUI
} }
/// <summary> /// <summary>
/// User clicked on a link /// Select Unity editor path
/// </summary> /// </summary>
private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e) { private void BtnUnityPath_OnClick(object sender, RoutedEventArgs e) {
Process.Start(new ProcessStartInfo {FileName = e.Uri.ToString(), UseShellExecute = true}); var openFolderDialog = new VistaFolderBrowserDialog();
if (txtUnityPath.Text != "<not set>")
openFolderDialog.SelectedPath = txtUnityPath.Text;
else {
openFolderDialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
}
openFolderDialog.Description = "Select Unity editor path";
openFolderDialog.UseDescriptionForTitle = true;
while (openFolderDialog.ShowDialog() == true) {
if (!File.Exists(openFolderDialog.SelectedPath + @"\Editor\Data\Managed\UnityEditor.dll"))
MessageBox.Show(this, "Could not find Unity installation in this folder. Ensure the 'Editor' folder is a child of the selected folder and try again.", "Unity installation not found", MessageBoxButton.OK, MessageBoxImage.Error);
else {
txtUnityPath.Text = openFolderDialog.SelectedPath;
break;
}
}
}
/// <summary>
/// Select Unity script assemblies path
/// </summary>
private void BtnUnityScriptPath_OnClick(object sender, RoutedEventArgs e) {
var openFolderDialog = new VistaFolderBrowserDialog();
if (txtUnityScriptPath.Text != "<not set>")
openFolderDialog.SelectedPath = txtUnityScriptPath.Text;
openFolderDialog.Description = "Select Unity script assemblies path";
openFolderDialog.UseDescriptionForTitle = true;
while (openFolderDialog.ShowDialog() == true) {
if (!File.Exists(openFolderDialog.SelectedPath + @"\UnityEngine.UI.dll"))
MessageBox.Show(this, "Could not find Unity assemblies in this folder. Ensure the selected folder contains UnityEngine.UI.dll and try again.", "Unity assemblies not found", MessageBoxButton.OK, MessageBoxImage.Error);
else {
txtUnityScriptPath.Text = openFolderDialog.SelectedPath;
break;
}
}
} }
} }