diff --git a/IPA.Loader/Loader/PluginLoader.cs b/IPA.Loader/Loader/PluginLoader.cs index bab9cfba..d2735b21 100644 --- a/IPA.Loader/Loader/PluginLoader.cs +++ b/IPA.Loader/Loader/PluginLoader.cs @@ -132,6 +132,7 @@ namespace IPA.Loader string pluginNs = ""; + PluginManifest? pluginManifest = null; foreach (var resource in pluginModule.Resources) { const string manifestSuffix = ".manifest.json"; @@ -144,11 +145,11 @@ namespace IPA.Loader using (var manifestReader = new StreamReader(embedded.GetResourceStream())) manifest = manifestReader.ReadToEnd(); - metadata.Manifest = JsonConvert.DeserializeObject(manifest); + pluginManifest = JsonConvert.DeserializeObject(manifest); break; } - if (metadata.Manifest == null) + if (pluginManifest == null) { #if DIRE_LOADER_WARNINGS Logger.loader.Error($"Could not find manifest.json for {Path.GetFileName(plugin)}"); @@ -158,6 +159,8 @@ namespace IPA.Loader continue; } + metadata.Manifest = pluginManifest; + void TryGetNamespacedPluginType(string ns, PluginMetadata meta) { foreach (var type in pluginModule.Types) @@ -277,7 +280,8 @@ namespace IPA.Loader string description; if (!meta.IsSelf) { - var resc = meta.PluginType.Module.Resources.Select(r => r as EmbeddedResource) + // plugin type must be non-null for non-self plugins + var resc = meta.PluginType!.Module.Resources.Select(r => r as EmbeddedResource) .NonNull() .FirstOrDefault(r => r.Name == name); if (resc == null) @@ -747,7 +751,7 @@ namespace IPA.Loader { if (feature.TryGetDefiningPlugin(out var plugin)) { - if (plugin != meta) + if (plugin != meta && plugin != null) { // if the feature is not applied to the defining feature _ = meta.LoadsAfter.Add(plugin); } @@ -777,7 +781,7 @@ namespace IPA.Loader { // clean them up so we can still use the metadata for updates m.InternalFeatures.Clear(); m.PluginType = null; - m.Assembly = null; + m.Assembly = null!; } } PluginsMetadata = new List(); diff --git a/IPA.Loader/Loader/PluginMetadata.cs b/IPA.Loader/Loader/PluginMetadata.cs index 5ff7b92b..10c13394 100644 --- a/IPA.Loader/Loader/PluginMetadata.cs +++ b/IPA.Loader/Loader/PluginMetadata.cs @@ -1,4 +1,5 @@ -using IPA.Loader.Features; +#nullable enable +using IPA.Loader.Features; using IPA.Utilities; using Mono.Cecil; using System; @@ -23,13 +24,13 @@ namespace IPA.Loader /// The assembly the plugin was loaded from. /// /// the loaded Assembly that contains the plugin main type - public Assembly Assembly { get; internal set; } + public Assembly Assembly { get; internal set; } = null!; /// /// The TypeDefinition for the main type of the plugin. /// /// the Cecil definition for the plugin main type - public TypeDefinition PluginType { get; internal set; } + public TypeDefinition? PluginType { get; internal set; } /// /// The human readable name of the plugin. @@ -65,7 +66,7 @@ namespace IPA.Loader /// The file the plugin was loaded from. /// /// the file the plugin was loaded from - public FileInfo File { get; internal set; } + public FileInfo File { get; internal set; } = null!; // ReSharper disable once UnusedAutoPropertyAccessor.Global /// @@ -74,11 +75,11 @@ namespace IPA.Loader /// the list of features requested by the plugin public IReadOnlyList Features => InternalFeatures; - internal readonly List InternalFeatures = new List(); + internal readonly List InternalFeatures = new(); - internal readonly HashSet UnloadedFeatures = new HashSet(); + internal readonly HashSet UnloadedFeatures = new(); - internal readonly List CreateFeaturesWhenLoaded = new List(); + internal readonly List CreateFeaturesWhenLoaded = new(); /// /// A list of files (that aren't ) that are associated with this plugin. @@ -96,18 +97,18 @@ namespace IPA.Loader /// A link to this plugin's home page, if any. /// /// the of the plugin's home page - public Uri PluginHomeLink => manifest.Links?.ProjectHome; + public Uri? PluginHomeLink => manifest.Links?.ProjectHome; /// /// A link to this plugin's source code, if avaliable. /// /// the of the plugin's source code - public Uri PluginSourceLink => manifest.Links?.ProjectSource; + public Uri? PluginSourceLink => manifest.Links?.ProjectSource; /// /// A link to a donate page for the author of this plugin, if avaliable. /// /// the of the author's donate page - public Uri DonateLink => manifest.Links?.Donate; + public Uri? DonateLink => manifest.Links?.Donate; internal bool IsSelf; @@ -117,10 +118,10 @@ namespace IPA.Loader /// if it is bare, otherwise public bool IsBare { get; internal set; } - private PluginManifest manifest; + private PluginManifest manifest = null!; - internal HashSet Dependencies { get; } = new HashSet(); - internal HashSet LoadsAfter { get; } = new HashSet(); + internal HashSet Dependencies { get; } = new(); + internal HashSet LoadsAfter { get; } = new(); internal PluginManifest Manifest {