diff --git a/Il2CppInspector.CLI/PluginOptions.cs b/Il2CppInspector.CLI/PluginOptions.cs index 177f0a3..27901a2 100644 --- a/Il2CppInspector.CLI/PluginOptions.cs +++ b/Il2CppInspector.CLI/PluginOptions.cs @@ -181,10 +181,9 @@ namespace Il2CppInspector.CLI } } - // Enable plugin + // Enable plugin and inform of options PluginManager.AsInstance.ManagedPlugins.First(p => p.Plugin == plugin).Enabled = true; - - // TODO: Plugin hook OptionsChanged + PluginManager.OptionsChanged(plugin); } return true; } diff --git a/Il2CppInspector.Common/Plugins/API/V100/Hooks.cs b/Il2CppInspector.Common/Plugins/API/V100/Hooks.cs index da21d0f..d0765de 100644 --- a/Il2CppInspector.Common/Plugins/API/V100/Hooks.cs +++ b/Il2CppInspector.Common/Plugins/API/V100/Hooks.cs @@ -9,8 +9,20 @@ using System.IO; using NoisyCowStudios.Bin2Object; using Il2CppInspector.Reflection; +// Hooks we provide to plugins which can choose whether or not to provide implementations namespace Il2CppInspector.PluginAPI.V100 { + /// + /// Executes when the plugin's options are updated by the user + /// Not called on first load (with the default, possibly incomplete options provided by the plugin author) + /// Do not perform any long-running operations here + /// Implementation is optional - the default is to do nothing + /// + public partial interface IPlugin + { + void OptionsChanged(PluginOptionsChangedEventInfo e) { } + } + /// /// Process global-metadata.dat when it is first opened as a sequence of bytes /// Seek cursor will be at the start of the file diff --git a/Il2CppInspector.Common/Plugins/API/V100/IPlugin.cs b/Il2CppInspector.Common/Plugins/API/V100/IPlugin.cs index 1a03028..0f08b07 100644 --- a/Il2CppInspector.Common/Plugins/API/V100/IPlugin.cs +++ b/Il2CppInspector.Common/Plugins/API/V100/IPlugin.cs @@ -11,7 +11,7 @@ namespace Il2CppInspector.PluginAPI.V100 /// /// Core interface that all plugins must implement /// - public interface IPlugin + public partial interface IPlugin { /// /// Plugin name for CLI and unique ID diff --git a/Il2CppInspector.Common/Plugins/API/V100/PluginEventInfo.cs b/Il2CppInspector.Common/Plugins/API/V100/PluginEventInfo.cs index d3b2861..a9eeb1d 100644 --- a/Il2CppInspector.Common/Plugins/API/V100/PluginEventInfo.cs +++ b/Il2CppInspector.Common/Plugins/API/V100/PluginEventInfo.cs @@ -61,6 +61,11 @@ namespace Il2CppInspector.PluginAPI.V100 public bool SkipValidation { get; set; } } + /// + /// Event info for OptionsChanged + /// + public class PluginOptionsChangedEventInfo : PluginEventInfo { } + /// /// Event info for PostProcessMetadata /// diff --git a/Il2CppInspector.Common/Plugins/PluginHooks.cs b/Il2CppInspector.Common/Plugins/PluginHooks.cs index 78a1544..38388fc 100644 --- a/Il2CppInspector.Common/Plugins/PluginHooks.cs +++ b/Il2CppInspector.Common/Plugins/PluginHooks.cs @@ -12,7 +12,8 @@ using Il2CppInspector.Reflection; namespace Il2CppInspector { - // Hooks we provide to plugins which can choose whether or not to provide implementations + // Internal helpers to call the same hook on every plugin + // Does not include hooks that should be called individually, eg. OptionsChanged internal static class PluginHooks { public static PluginPreProcessMetadataEventInfo PreProcessMetadata(BinaryObjectStream stream) diff --git a/Il2CppInspector.Common/Plugins/PluginManager.cs b/Il2CppInspector.Common/Plugins/PluginManager.cs index 44c2463..3d15bcf 100644 --- a/Il2CppInspector.Common/Plugins/PluginManager.cs +++ b/Il2CppInspector.Common/Plugins/PluginManager.cs @@ -220,6 +220,21 @@ namespace Il2CppInspector } } + // Commit options change for the specified plugin + public static PluginOptionsChangedEventInfo OptionsChanged(IPlugin plugin) { + var eventInfo = new PluginOptionsChangedEventInfo(); + + try { + plugin.OptionsChanged(eventInfo); + } + catch (Exception ex) { + eventInfo.Error = new PluginErrorEventArgs { Plugin = plugin, Exception = ex, Operation = "options update" }; + ErrorHandler?.Invoke(AsInstance, eventInfo.Error); + } + + return eventInfo; + } + // Try to cast each enabled plugin to a specific interface type, and for those supporting the interface, execute the supplied delegate // Errors will be forwarded to the error handler internal static E Try(Action action) where E : PluginEventInfo, new() diff --git a/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs b/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs index efe25e6..cf3593c 100644 --- a/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs +++ b/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs @@ -24,6 +24,7 @@ using System.Text.RegularExpressions; using System.Linq; using Il2CppInspector.PluginAPI.V100; using Il2CppInspector.Reflection; +using Il2CppInspector; namespace Il2CppInspectorGUI { @@ -126,8 +127,6 @@ namespace Il2CppInspectorGUI private void okButton_Click(object sender, RoutedEventArgs e) { // Close dialog box but call OnClosing first to validate all the options DialogResult = true; - - // TODO: Plugin hook OptionsChanged (and make sure it works when clicking close icon as well) } // Select a file path @@ -168,6 +167,7 @@ namespace Il2CppInspectorGUI MessageBox.Show("One or more options are invalid.", "Il2CppInspector Plugin Configuration"); e.Cancel = true; } + PluginManager.OptionsChanged(Plugin); } } } diff --git a/Il2CppInspector.GUI/PluginManagerDialog.xaml.cs b/Il2CppInspector.GUI/PluginManagerDialog.xaml.cs index bef4fda..8a9eccc 100644 --- a/Il2CppInspector.GUI/PluginManagerDialog.xaml.cs +++ b/Il2CppInspector.GUI/PluginManagerDialog.xaml.cs @@ -107,6 +107,5 @@ namespace Il2CppInspector.GUI private void getPluginsButton_Click(object sender, RoutedEventArgs e) { Process.Start(new ProcessStartInfo { FileName = @"https://github.com/djkaty/Il2CppInspectorPlugins", UseShellExecute = true }); } - } } diff --git a/Il2CppTests/TestRunner.cs b/Il2CppTests/TestRunner.cs index bc01dfe..15c549b 100644 --- a/Il2CppTests/TestRunner.cs +++ b/Il2CppTests/TestRunner.cs @@ -107,8 +107,8 @@ namespace Il2CppInspector ourPlugin[key] = Convert.ChangeType(value, targetType); } } - // TODO: Plugin hook OptionsChanged } + PluginManager.OptionsChanged(plugin); } List inspectors;