fix: NRE when loading devPlugins without a manifest

This commit is contained in:
goaaats 2021-12-20 21:54:38 +01:00
parent ebdf641e3c
commit 25fbfd5cc1
No known key found for this signature in database
GPG key ID: F18F057873895461
3 changed files with 14 additions and 14 deletions

View file

@ -21,8 +21,8 @@ namespace Dalamud.Plugin.Internal
// Ref to Dalamud.Configuration.DevPluginSettings
private readonly DevPluginSettings devSettings;
private FileSystemWatcher fileWatcher;
private CancellationTokenSource fileWatcherTokenSource;
private FileSystemWatcher? fileWatcher;
private CancellationTokenSource fileWatcherTokenSource = new();
private int reloadCounter;
/// <summary>
@ -125,7 +125,7 @@ namespace Dalamud.Plugin.Internal
var current = Interlocked.Increment(ref this.reloadCounter);
Task.Delay(500).ContinueWith(
task =>
_ =>
{
if (this.fileWatcherTokenSource.IsCancellationRequested)
{

View file

@ -112,6 +112,9 @@ namespace Dalamud.Plugin.Internal
else
{
this.Manifest = manifest;
if (!manifest.CheckSanity())
throw new InvalidOperationException("Plugin manifest is not sane.");
}
// This converts from the ".disabled" file feature to the manifest instead.

View file

@ -74,12 +74,12 @@ namespace Dalamud.Plugin.Internal
/// <summary>
/// An event that fires when the installed plugins have changed.
/// </summary>
public event Action OnInstalledPluginsChanged;
public event Action? OnInstalledPluginsChanged;
/// <summary>
/// An event that fires when the available plugins have changed.
/// </summary>
public event Action OnAvailablePluginsChanged;
public event Action? OnAvailablePluginsChanged;
/// <summary>
/// Gets a list of all loaded plugins.
@ -512,16 +512,13 @@ namespace Dalamud.Plugin.Internal
/// <param name="isBoot">If this plugin is being loaded at boot.</param>
/// <param name="doNotLoad">Don't load the plugin, just don't do it.</param>
/// <returns>The loaded plugin.</returns>
public LocalPlugin LoadPlugin(FileInfo dllFile, LocalPluginManifest manifest, PluginLoadReason reason, bool isDev = false, bool isBoot = false, bool doNotLoad = false)
public LocalPlugin LoadPlugin(FileInfo dllFile, LocalPluginManifest? manifest, PluginLoadReason reason, bool isDev = false, bool isBoot = false, bool doNotLoad = false)
{
var name = manifest?.Name ?? dllFile.Name;
var loadPlugin = !doNotLoad;
LocalPlugin plugin;
if (!manifest.CheckSanity())
throw new InvalidOperationException("Plugin manifest is not sane.");
if (isDev)
{
Log.Information($"Loading dev plugin {name}");
@ -1045,7 +1042,7 @@ namespace Dalamud.Plugin.Internal
private struct PluginDef
{
public PluginDef(FileInfo dllFile, LocalPluginManifest manifest, bool isDev)
public PluginDef(FileInfo dllFile, LocalPluginManifest? manifest, bool isDev)
{
this.DllFile = dllFile;
this.Manifest = manifest;
@ -1054,7 +1051,7 @@ namespace Dalamud.Plugin.Internal
public FileInfo DllFile { get; init; }
public LocalPluginManifest Manifest { get; init; }
public LocalPluginManifest? Manifest { get; init; }
public bool IsDev { get; init; }
@ -1086,8 +1083,8 @@ namespace Dalamud.Plugin.Internal
/// </summary>
internal static readonly Dictionary<string, PluginPatchData> PluginLocations = new();
private MonoMod.RuntimeDetour.Hook assemblyLocationMonoHook;
private MonoMod.RuntimeDetour.Hook assemblyCodeBaseMonoHook;
private MonoMod.RuntimeDetour.Hook? assemblyLocationMonoHook;
private MonoMod.RuntimeDetour.Hook? assemblyCodeBaseMonoHook;
/// <summary>
/// Patch method for internal class RuntimeAssembly.Location, also known as Assembly.Location.
@ -1168,7 +1165,7 @@ namespace Dalamud.Plugin.Internal
{
var targetType = typeof(PluginManager).Assembly.GetType();
var locationTarget = targetType.GetProperty(nameof(Assembly.Location)).GetGetMethod();
var locationTarget = targetType.GetProperty(nameof(Assembly.Location))!.GetGetMethod();
var locationPatch = typeof(PluginManager).GetMethod(nameof(PluginManager.AssemblyLocationPatch), BindingFlags.NonPublic | BindingFlags.Static);
this.assemblyLocationMonoHook = new MonoMod.RuntimeDetour.Hook(locationTarget, locationPatch);