From f71cd04ec749bc430292750d317df1516ba7520f Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 19 Dec 2020 20:45:24 +0100 Subject: [PATCH] Plugins: Define IPlugin and IPluginOption interfaces --- .../Plugins/API/V100/Hooks.cs | 16 ++ .../Plugins/API/V100/IPlugin.cs | 47 ++++++ .../Plugins/API/V100/IPluginOption.cs | 154 ++++++++++++++++++ .../Plugins/API/V101/Adapter.cs | 30 ++++ .../Plugins/API/V101/IPlugin.cs | 25 +++ 5 files changed, 272 insertions(+) create mode 100644 Il2CppInspector.Common/Plugins/API/V100/Hooks.cs create mode 100644 Il2CppInspector.Common/Plugins/API/V100/IPlugin.cs create mode 100644 Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs create mode 100644 Il2CppInspector.Common/Plugins/API/V101/Adapter.cs create mode 100644 Il2CppInspector.Common/Plugins/API/V101/IPlugin.cs diff --git a/Il2CppInspector.Common/Plugins/API/V100/Hooks.cs b/Il2CppInspector.Common/Plugins/API/V100/Hooks.cs new file mode 100644 index 0000000..6f90881 --- /dev/null +++ b/Il2CppInspector.Common/Plugins/API/V100/Hooks.cs @@ -0,0 +1,16 @@ +/* + Copyright 2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty + + All rights reserved. +*/ + +namespace Il2CppInspector.PluginAPI.V100 +{ + /// + /// Process global-metadata.dat after it has been loaded into a Metadata object + /// + public interface IPostProcessMetadata + { + void PostProcessMetadata(Metadata metadata); + } +} diff --git a/Il2CppInspector.Common/Plugins/API/V100/IPlugin.cs b/Il2CppInspector.Common/Plugins/API/V100/IPlugin.cs new file mode 100644 index 0000000..1a03028 --- /dev/null +++ b/Il2CppInspector.Common/Plugins/API/V100/IPlugin.cs @@ -0,0 +1,47 @@ +/* + Copyright 2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty + + All rights reserved. +*/ + +using System.Collections.Generic; + +namespace Il2CppInspector.PluginAPI.V100 +{ + /// + /// Core interface that all plugins must implement + /// + public interface IPlugin + { + /// + /// Plugin name for CLI and unique ID + /// + public string Id { get; } + + /// + /// Human-readable plugin name + /// + public string Name { get; } + + /// + /// Nickname of the plugiin author + /// + public string Author { get; } + + /// + /// Human-readable version string for the plugin + /// Always use lexical order: version string may be used for updates + /// + public string Version { get; } + + /// + /// Description of the plugin + /// + public string Description { get; } + + /// + /// Plugin options + /// + public List Options { get; } + } +} diff --git a/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs b/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs new file mode 100644 index 0000000..9df088c --- /dev/null +++ b/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs @@ -0,0 +1,154 @@ +/* + Copyright 2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty + + All rights reserved. +*/ + +using System.Collections.Generic; + +namespace Il2CppInspector.PluginAPI.V100 +{ + /// + /// Interface representing a plugin option + /// + public interface IPluginOption + { + /// + /// Option name for CLI and unique ID + /// + public string Name { get; set; } + + /// + /// Option description for GUI + /// + public string Description { get; set; } + + /// + /// True if the setting is required for the plugin to function, false if optional + /// Optional by default + /// + public bool Required { get; set; } + + /// + /// The default value of the option, if any + /// Becomes the current value of the option when supplied by the user + /// + public object Value { get; set; } + } + + /// + /// Defines how to display lists of choices in the GUI + /// Dropdown for a dropdown box, List for a list of radio buttons + /// + public enum PluginOptionChoiceStyle + { + Dropdown, + List + } + + /// + /// Defines how to display and parse numbers in the CLI and GUI + /// Decimal for regular numbers, Hex for hexadecimal strings + /// + public enum PluginOptionNumberStyle + { + Decimal, + Hex + } + + /// + /// The base option from which all other options are derived + /// + public abstract class PluginOption : IPluginOption + { + /// + /// The name of the option as it will be supplied in an argument on the command-line + /// + public string Name { get; set; } + + /// + /// A description of what the option does + /// + public string Description { get; set; } + + /// + /// True if the option must be specified, false if optional + /// + public bool Required { get; set; } + + /// + /// When created, the default value of the option + /// During plugin execution, the current value of the option + /// + object IPluginOption.Value { get => Value; set => Value = (T) value; } + public T Value { get; set; } + } + + /// + /// Numeric type option (for internal use only) + /// + public interface IPluginOptionNumber + { + /// + /// The style of the number + /// + public PluginOptionNumberStyle Style { get; set; } + + /// + /// The value of the number + /// + object Value { get; set; } + } + + /// + /// Option representing a text string + /// + public class PluginOptionText : PluginOption { } + + /// + /// Option representing a file path + /// + public class PluginOptionFilePath : PluginOption { } + + /// + /// And option representing boolean true or false (yes/no, on/off etc.) + /// + public class PluginOptionBoolean : PluginOption { } + + /// + /// Option representing a number + /// + /// The type of the number + public class PluginOptionNumber : PluginOption, IPluginOptionNumber where T : struct + { + /// + /// Decimal for normal numbers + /// Hex to display and parse numbers as hex in the CLI and GUI + /// + public PluginOptionNumberStyle Style { get; set; } + + /// + /// The value of the number + /// + object IPluginOptionNumber.Value { get => Value; set => Value = (T) value; } + } + + /// + /// Option representing a single choice from a list of choices + /// + public class PluginOptionChoice : PluginOption + { + /// + /// List of items to choose from + /// The Keys are the actual values and those supplied via the CLI + /// The Values are descriptions of each value shown in the GUI + /// + public Dictionary Choices { get; set; } + + /// + /// Dropdown to display the list as a drop-down box in the GUI + /// List to display the list as a set of grouped radio buttons in the GUI + /// + public PluginOptionChoiceStyle Style { get; set; } + } +} \ No newline at end of file diff --git a/Il2CppInspector.Common/Plugins/API/V101/Adapter.cs b/Il2CppInspector.Common/Plugins/API/V101/Adapter.cs new file mode 100644 index 0000000..f71404f --- /dev/null +++ b/Il2CppInspector.Common/Plugins/API/V101/Adapter.cs @@ -0,0 +1,30 @@ +/* + Copyright 2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty + + All rights reserved. +*/ + +/// This is an example for future use of how to enable backwards-compatibility +/// by allowing newer versions of Il2CppInspector to load plugins made with older API versions + +using System.Collections.Generic; +/* +namespace Il2CppInspector.PluginAPI.V101 +{ + /// + /// Converts a V100 plugin to a V101 plugin + /// + public class Adapter : IPlugin + { + private V100.IPlugin plugin; + public Adapter(V100.IPlugin plugin) => this.plugin = plugin; + + // Fill in missing interface contract + public string Id => plugin.Id; + public string Name => plugin.Name; + public string Version => plugin.Version; + public string Description => plugin.Description; + public List Options => plugin.Options; + } +} +*/ \ No newline at end of file diff --git a/Il2CppInspector.Common/Plugins/API/V101/IPlugin.cs b/Il2CppInspector.Common/Plugins/API/V101/IPlugin.cs new file mode 100644 index 0000000..29d62a3 --- /dev/null +++ b/Il2CppInspector.Common/Plugins/API/V101/IPlugin.cs @@ -0,0 +1,25 @@ +/* + Copyright 2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty + + All rights reserved. +*/ + +/// This is an example for future use of how to create a new backwards-compatible API version + +using System.Collections.Generic; +/* +namespace Il2CppInspector.PluginAPI.V101 +{ + /// + /// Core interface that all plugins must implement + /// + public interface IPlugin : V100.IPlugin + { + /// + /// Human-readable version string + /// Used for plugin selection and updates + /// + public string SoneNewProperty { get; } + } +} +*/ \ No newline at end of file