Skip to content
Open
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
17 changes: 17 additions & 0 deletions Cpp2IL.Core.Tests/Cpp2IlApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,21 @@ public void UnityVersionIsCorrectlyDeterminedFromGlobalGameManagers()
var version = Cpp2IlApi.DetermineUnityVersion(null, Paths.Simple2019Game.DataDirectory);
Assert.That(version.Equals(2019, 4, 34));
}

[Test]
public void RelativePluginDirectoryIsResolvedFromApplicationBaseDirectory()
{
var resolved = Cpp2IlApi.ResolvePluginDirectory("Plugins");
var expected = System.IO.Path.GetFullPath(System.IO.Path.Combine(System.AppContext.BaseDirectory, "Plugins"));

Assert.That(resolved, Is.EqualTo(expected));
}

[Test]
public void AbsolutePluginDirectoryIsUsedAsProvided()
{
var pluginDirectory = System.IO.Path.GetFullPath(System.IO.Path.Combine(System.IO.Path.GetTempPath(), "Cpp2ILPlugins"));

Assert.That(Cpp2IlApi.ResolvePluginDirectory(pluginDirectory), Is.EqualTo(pluginDirectory));
}
}
18 changes: 16 additions & 2 deletions Cpp2IL.Core/Cpp2IlApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,26 @@ public static class Cpp2IlApi
internal static bool LowMemoryMode => RuntimeOptions?.LowMemoryMode ?? false;

[RequiresUnreferencedCode("Plugins are loaded dynamically.")]
public static void Init(string pluginsDir = "Plugins")
public static void Init(string pluginsDir = "Plugins", bool loadExternalPlugins = true)
{
Cpp2IlPluginManager.LoadFromDirectory(Path.Combine(Environment.CurrentDirectory, pluginsDir));
if (loadExternalPlugins)
Cpp2IlPluginManager.LoadFromDirectory(ResolvePluginDirectory(pluginsDir));
else
Logger.InfoNewline("External plugin loading disabled.", "Plugins");

Cpp2IlPluginManager.InitAll();
}

internal static string ResolvePluginDirectory(string pluginsDir)
{
if (string.IsNullOrWhiteSpace(pluginsDir))
pluginsDir = "Plugins";

return Path.GetFullPath(Path.IsPathRooted(pluginsDir)
? pluginsDir
: Path.Combine(AppContext.BaseDirectory, pluginsDir));
}

public static UnityVersion DetermineUnityVersion(string? unityPlayerPath, string? gameDataPath)
=> LibCpp2IlMain.DetermineUnityVersion(unityPlayerPath, gameDataPath);

Expand Down
8 changes: 8 additions & 0 deletions Cpp2IL/CommandLineArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public class CommandLineArgs
[Option("force-unity-version", HelpText = "Override the unity version detection. Don't use unless you know what you're doing, and use in conjunction with the other force options.")]
public string? ForcedUnityVersion { get; set; }

//Plugin options

[Option("plugins-dir", HelpText = "Specify a directory to load external Cpp2IL plugins from. Relative paths are resolved from the Cpp2IL application directory.")]
public string? PluginsDir { get; set; }

[Option("no-plugins", HelpText = "Disable loading external Cpp2IL plugins. Built-in plugins are still initialized.")]
public bool NoPlugins { get; set; }

//Processor options

[Option("list-processors", HelpText = "List the available processing layers and exit.")]
Expand Down
5 changes: 4 additions & 1 deletion Cpp2IL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,11 @@ private static Cpp2IlRuntimeArgs GetRuntimeOptionsFromCommandLine(string[] comma

ConsoleLogger.ShowVerbose = options.Verbose;

if (options.NoPlugins && !string.IsNullOrWhiteSpace(options.PluginsDir))
throw new SoftException("--plugins-dir cannot be used together with --no-plugins");

#pragma warning disable IL2026 // RequiresUnreferencedCode
Cpp2IlApi.Init();
Cpp2IlApi.Init(options.PluginsDir ?? "Plugins", !options.NoPlugins);
#pragma warning restore IL2026

if (options.ListProcessors)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ same argument as above but pass in the path to the APK, and cpp2il will extract
| --game-path | C:\Path\To\Game | Specify the path to the game folder. Required. |
| --exe-name | TestGame | Specify the name of the game's exe file in case auto detection fails (because there are other exe files in the game directory) |
| --verbose | <None> | Log more information about what we are doing |
| --plugins-dir | C:\Path\To\Plugins | Specify a directory to load external Cpp2IL plugins from. Relative paths are resolved from the Cpp2IL application directory. Defaults to the Plugins directory there. |
| --no-plugins | <None> | Disable loading external Cpp2IL plugins. Built-in plugins are still initialized. |
| --list-processors | <None> | List available processing layers, then exit. |
| --use-processor | attributeinjector | Select a processing layer to use, which can change the raw data prior to outputting. This option can appear multiple times. |
| --processor-config | key=value | Provide configuration options to the selected processing layers. These will be documented by the plugin which adds the processing layer. |
Expand Down