diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-12-12 01:33:11 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-12-12 01:33:11 -0500 |
commit | e00424068f3da7c4f91187872e96c90fa61e47db (patch) | |
tree | 636aae12d29c6f23936abdc06309867108e7a359 | |
parent | 59a25a12ffdb90c5a9a3db90be933ca4e76eb64f (diff) | |
download | SMAPI-e00424068f3da7c4f91187872e96c90fa61e47db.tar.gz SMAPI-e00424068f3da7c4f91187872e96c90fa61e47db.tar.bz2 SMAPI-e00424068f3da7c4f91187872e96c90fa61e47db.zip |
block access to mod-provided APIs until all mods are initialised (#409)
-rw-r--r-- | src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs | 5 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModRegistry.cs | 3 | ||||
-rw-r--r-- | src/SMAPI/Program.cs | 3 |
3 files changed, 11 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs b/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs index d39c885c..9574a632 100644 --- a/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs @@ -70,6 +70,11 @@ namespace StardewModdingAPI.Framework.ModHelpers public TInterface GetApi<TInterface>(string uniqueID) where TInterface : class { // validate + if (!this.Registry.AreAllModsInitialised) + { + this.Monitor.Log("Tried to access a mod-provided API before all mods were initialised.", LogLevel.Error); + return null; + } if (!typeof(TInterface).IsInterface) { this.Monitor.Log("Tried to map a mod-provided API to a class; must be a public interface.", LogLevel.Error); diff --git a/src/SMAPI/Framework/ModRegistry.cs b/src/SMAPI/Framework/ModRegistry.cs index 4dbc3541..453d2868 100644 --- a/src/SMAPI/Framework/ModRegistry.cs +++ b/src/SMAPI/Framework/ModRegistry.cs @@ -18,6 +18,9 @@ namespace StardewModdingAPI.Framework /// <summary>An assembly full name => mod lookup.</summary> private readonly IDictionary<string, IModMetadata> ModNamesByAssembly = new Dictionary<string, IModMetadata>(); + /// <summary>Whether all mods have been initialised and their <see cref="IMod.Entry"/> method called.</summary> + public bool AreAllModsInitialised { get; set; } + /********* ** Public methods diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 17fe2f36..786549fe 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -842,6 +842,9 @@ namespace StardewModdingAPI this.Monitor.Log("Invalidating cached assets for new editors & loaders...", LogLevel.Trace); this.ContentManager.InvalidateCacheFor(editors, loaders); } + + // unlock mod integrations + this.ModRegistry.AreAllModsInitialised = true; } /// <summary>Load a mod's entry class.</summary> |