diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-10-03 12:08:22 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-10-03 12:08:22 -0400 |
commit | 175ebf907134e1e32992f62637a5d7e43bfc6a20 (patch) | |
tree | 181bc49154a5139efa11e09f2618d4dc47d8321e /src | |
parent | 15cd316ce44fb1ca43b29f6087243cc3af2f78fb (diff) | |
download | SMAPI-175ebf907134e1e32992f62637a5d7e43bfc6a20.tar.gz SMAPI-175ebf907134e1e32992f62637a5d7e43bfc6a20.tar.bz2 SMAPI-175ebf907134e1e32992f62637a5d7e43bfc6a20.zip |
fix non-generic GetAPI not checking that all mods are loaded (#662)
Diffstat (limited to 'src')
-rw-r--r-- | src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs b/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs index 24bed3bb..f42cb085 100644 --- a/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using StardewModdingAPI.Framework.Reflection; namespace StardewModdingAPI.Framework.ModHelpers @@ -63,6 +62,14 @@ namespace StardewModdingAPI.Framework.ModHelpers /// <summary>Get the API provided by a mod, or <c>null</c> if it has none. This signature requires using the <see cref="IModHelper.Reflection"/> API to access the API's properties and methods.</summary> public object GetApi(string uniqueID) { + // validate ready + if (!this.Registry.AreAllModsInitialized) + { + this.Monitor.Log("Tried to access a mod-provided API before all mods were initialized.", LogLevel.Error); + return null; + } + + // get raw API IModMetadata mod = this.Registry.Get(uniqueID); if (mod?.Api != null && this.AccessedModApis.Add(mod.Manifest.UniqueID)) this.Monitor.Log($"Accessed mod-provided API for {mod.DisplayName}.", LogLevel.Trace); @@ -74,12 +81,12 @@ namespace StardewModdingAPI.Framework.ModHelpers /// <param name="uniqueID">The mod's unique ID.</param> public TInterface GetApi<TInterface>(string uniqueID) where TInterface : class { - // validate - if (!this.Registry.AreAllModsInitialized) - { - this.Monitor.Log("Tried to access a mod-provided API before all mods were initialized.", LogLevel.Error); + // get raw API + object api = this.GetApi(uniqueID); + if (api == null) return null; - } + + // validate mapping if (!typeof(TInterface).IsInterface) { this.Monitor.Log($"Tried to map a mod-provided API to class '{typeof(TInterface).FullName}'; must be a public interface.", LogLevel.Error); @@ -91,11 +98,6 @@ namespace StardewModdingAPI.Framework.ModHelpers return null; } - // get raw API - object api = this.GetApi(uniqueID); - if (api == null) - return null; - // get API of type if (api is TInterface castApi) return castApi; |