Browse Source

Added NoRuntimeEnableFeature to allow for opt-out of runtime loading

4.0.0-beta
Anairkoen Schno 5 years ago
parent
commit
0857bd5989
9 changed files with 75 additions and 67 deletions
  1. +1
    -1
      IPA.Loader/IPA.Loader.csproj
  2. +0
    -27
      IPA.Loader/Loader/Features/AddInFeature.cs
  3. +1
    -1
      IPA.Loader/Loader/Features/ConfigProviderFeature.cs
  4. +29
    -0
      IPA.Loader/Loader/Features/NoRuntimeEnableFeature.cs
  5. +11
    -12
      IPA.Loader/Loader/PluginLoader.cs
  6. +2
    -0
      IPA.Loader/Loader/PluginManager.cs
  7. +26
    -25
      IPA.Loader/Loader/manifest.json
  8. +1
    -1
      IPA.Loader/PluginInterfaces/BeatSaber/IDisablablePlugin.cs
  9. +4
    -0
      IPA.Loader/PluginInterfaces/BeatSaber/IPlugin.cs

+ 1
- 1
IPA.Loader/IPA.Loader.csproj View File

@ -92,10 +92,10 @@
<Compile Include="JsonConverters\MultilineStringConverter.cs" />
<Compile Include="Loader\Composite\CompositeBSPlugin.cs" />
<Compile Include="Loader\DisabledConfig.cs" />
<Compile Include="Loader\Features\AddInFeature.cs" />
<Compile Include="Loader\Features\ConfigProviderFeature.cs" />
<Compile Include="Loader\Features\DefineFeature.cs" />
<Compile Include="Loader\Features\InitInjectorFeature.cs" />
<Compile Include="Loader\Features\NoRuntimeEnableFeature.cs" />
<Compile Include="Loader\Features\NoUpdateFeature.cs" />
<Compile Include="Loader\Features\PrintFeature.cs" />
<Compile Include="Loader\HarmonyProtector.cs" />


+ 0
- 27
IPA.Loader/Loader/Features/AddInFeature.cs View File

@ -1,27 +0,0 @@
namespace IPA.Loader.Features
{
internal class AddInFeature : Feature
{
private PluginLoader.PluginMetadata selfMeta;
public override bool Initialize(PluginLoader.PluginMetadata meta, string[] parameters)
{
selfMeta = meta;
RequireLoaded(meta);
return true;
}
public override bool BeforeLoad(PluginLoader.PluginMetadata plugin)
{
return plugin != selfMeta;
}
public override string InvalidMessage
{
get => "Plugin is an add-in for some other mod, therefore should not be loaded.";
protected set { }
}
}
}

+ 1
- 1
IPA.Loader/Loader/Features/ConfigProviderFeature.cs View File

@ -39,7 +39,7 @@ namespace IPA.Loader.Features
goto hasFilename;
case BadImageFormatException bi:
filename = bi.FileName;
hasFilename:
hasFilename:
InvalidMessage = $"Could not find {filename} while loading type";
break;
default:


+ 29
- 0
IPA.Loader/Loader/Features/NoRuntimeEnableFeature.cs View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IPA.Loader.Features
{
internal class NoRuntimeEnableFeature : Feature
{
internal static bool HaveLoadedPlugins = false;
public override bool Initialize(PluginLoader.PluginMetadata meta, string[] parameters)
{
return parameters.Length == 0;
}
public override bool BeforeLoad(PluginLoader.PluginMetadata plugin)
{
return !HaveLoadedPlugins;
}
public override string InvalidMessage
{
get => "Plugin requested to not be loaded after initial plugin load";
protected set { }
}
}
}

+ 11
- 12
IPA.Loader/Loader/PluginLoader.cs View File

@ -666,24 +666,23 @@ namespace IPA.Loader
foreach (var feature in meta.Features)
try
{
// TODO: remove need for cast
feature.AfterInit(info, info.Plugin as IPlugin);
feature.AfterInit(info, info.Plugin);
}
catch (Exception e)
{
Logger.loader.Critical($"Feature errored in {nameof(Feature.AfterInit)}: {e}");
}
if (instance is IPlugin newPlugin) // TODO: remove this check, all plugins should be IPlugin
try // TODO: move this out to after all plugins have been inited
{
newPlugin.OnEnable();
}
catch (Exception e)
{
Logger.loader.Error($"Error occurred trying to enable {meta.Name}");
Logger.loader.Error(e);
}
try // TODO: move this out to after all plugins have been inited
{
instance.OnEnable();
}
catch (Exception e)
{
Logger.loader.Error($"Error occurred trying to enable {meta.Name}");
Logger.loader.Error(e);
return null; // is enable failure a full load failure?
}
}
catch (AmbiguousMatchException)
{


+ 2
- 0
IPA.Loader/Loader/PluginManager.cs View File

@ -13,6 +13,7 @@ using Mono.Cecil;
using UnityEngine;
using Logger = IPA.Logging.Logger;
using static IPA.Loader.PluginLoader;
using IPA.Loader.Features;
#if NET3
using Net3_Proxy;
using Path = Net3_Proxy.Path;
@ -323,6 +324,7 @@ namespace IPA.Loader
// initialize BSIPA plugins first
_bsPlugins.AddRange(PluginLoader.LoadPlugins());
NoRuntimeEnableFeature.HaveLoadedPlugins = true;
var metadataPaths = PluginsMetadata.Select(m => m.File.FullName).ToList();
var ignoredPaths = ignoredPlugins.Select(m => m.File.FullName).ToList();


+ 26
- 25
IPA.Loader/Loader/manifest.json View File

@ -1,27 +1,28 @@
{
"$schema": "https://raw.githubusercontent.com/beat-saber-modding-group/BSIPA-MetadataFileSchema/master/Schema.json",
"author": "DaNike",
"description": [
"#![IPA.Loader.description.md]",
"A mod loader specifically for Beat Saber."
],
"gameVersion": "1.3.0",
"id": "BSIPA",
"name": "Beat Saber IPA",
"version": "4.0.0-beta.1",
"icon": "IPA.icon_white.png",
"features": [
"define-feature(print, IPA.Loader.Features.PrintFeature)",
"define-feature(debug, IPA.Loader.Features.DebugFeature)",
"define-feature(warn, IPA.Loader.Features.WarnFeature)",
"define-feature(no-update, IPA.Loader.Features.NoUpdateFeature)",
"define-feature(add-in, IPA.Loader.Features.AddInFeature)",
"define-feature(init-injector, IPA.Loader.Features.InitInjectorFeature)",
"define-feature(config-provider, IPA.Loader.Features.ConfigProviderFeature)"
],
"links": {
"project-home": "https://beat-saber-modding-group.github.io/BeatSaber-IPA-Reloaded/index.html",
"project-source": "https://github.com/beat-saber-modding-group/BeatSaber-IPA-Reloaded",
"donate": "https://ko-fi.com/danike"
}
"$schema": "https://raw.githubusercontent.com/beat-saber-modding-group/BSIPA-MetadataFileSchema/master/Schema.json",
"author": "DaNike",
"description": [
"#![IPA.Loader.description.md]",
"A mod loader specifically for Beat Saber."
],
"gameVersion": "1.5.0",
"id": "BSIPA",
"name": "Beat Saber IPA",
"version": "4.0.0-beta.1",
"icon": "IPA.icon_white.png",
"features": [
"define-feature(print, IPA.Loader.Features.PrintFeature)",
"define-feature(debug, IPA.Loader.Features.DebugFeature)",
"define-feature(warn, IPA.Loader.Features.WarnFeature)",
"define-feature(no-update, IPA.Loader.Features.NoUpdateFeature)",
"define-feature(no-runtime-enable, IPA.Loader.Features.NoRuntimeEnableFeature)",
"define-feature(init-injector, IPA.Loader.Features.InitInjectorFeature)",
"define-feature(config-provider, IPA.Loader.Features.ConfigProviderFeature)",
""
],
"links": {
"project-home": "https://beat-saber-modding-group.github.io/BeatSaber-IPA-Reloaded/index.html",
"project-source": "https://github.com/beat-saber-modding-group/BeatSaber-IPA-Reloaded",
"donate": "https://ko-fi.com/danike"
}
}

+ 1
- 1
IPA.Loader/PluginInterfaces/BeatSaber/IDisablablePlugin.cs View File

@ -1,7 +1,7 @@
namespace IPA
{
/// <summary>
/// Provides methods to allow runtime enabling and disabling of a plugin.
/// Provides methods to allow runtime disabling of a plugin.
/// </summary>
public interface IDisablablePlugin
{


+ 4
- 0
IPA.Loader/PluginInterfaces/BeatSaber/IPlugin.cs View File

@ -6,6 +6,10 @@ namespace IPA
/// Interface for BSIPA plugins. Every class that implements this will be loaded if the DLL is placed at
/// &lt;install dir&gt;/Plugins.
/// </summary>
/// <remarks>
/// Mods implemented with this interface should handle being enabled at runtime properly, unless marked
/// with the "no-runtime-enable" feature.
/// </remarks>
public interface IPlugin
{
/// <summary>


Loading…
Cancel
Save