From 3744e2f1e5505c9d15fb3bc985ad147a33621048 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 3 Dec 2018 02:39:20 -0500 Subject: add SMAPI 3.0 compatibility strict mode (#606) --- src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs | 2 +- src/SMAPI/Framework/ModLoading/ModWarning.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs b/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs index f3555c2d..6592760e 100644 --- a/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs +++ b/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs @@ -23,7 +23,7 @@ namespace StardewModdingAPI.Framework.ModLoading /// The instruction is compatible, but uses the dynamic keyword which won't work on Linux/Mac. DetectedDynamic, - /// The instruction is compatible, but references which may impact stability. + /// The instruction is compatible, but references or which may impact stability. DetectedUnvalidatedUpdateTick, /// The instruction accesses the filesystem directly. diff --git a/src/SMAPI/Framework/ModLoading/ModWarning.cs b/src/SMAPI/Framework/ModLoading/ModWarning.cs index c62199b2..e643cb05 100644 --- a/src/SMAPI/Framework/ModLoading/ModWarning.cs +++ b/src/SMAPI/Framework/ModLoading/ModWarning.cs @@ -22,7 +22,7 @@ namespace StardewModdingAPI.Framework.ModLoading /// The mod uses the dynamic keyword which won't work on Linux/Mac. UsesDynamic = 8, - /// The mod references which may impact stability. + /// The mod references or which may impact stability. UsesUnvalidatedUpdateTick = 16, /// The mod has no update keys set. -- cgit From 2b97b9f701452bbcdc7bfb5c433b9906c595b195 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 6 Dec 2018 18:27:44 -0500 Subject: disable paranoid detection if paranoid warnings are disabled --- docs/release-notes.md | 2 + src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 9 ++- src/SMAPI/Framework/SCore.cs | 2 +- src/SMAPI/Metadata/InstructionMetadata.cs | 79 ++++++++++++------------ 4 files changed, 50 insertions(+), 42 deletions(-) (limited to 'src/SMAPI/Framework/ModLoading') diff --git a/docs/release-notes.md b/docs/release-notes.md index 5ac702b1..cb9d0392 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -6,6 +6,7 @@ * Fixed cryptic error when running the installer from inside a zip file on Windows. * Fixed error when leaving and rejoining a multiplayer server in the same session. * Fixed Console Commands' handling of tool upgrade levels for item commands. + * Fixed empty "mods with warnings" list in some cases due to hidden warnings. * For modders: * Added ModDrop update keys (see [docs](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Manifest#Update_checks)). @@ -13,6 +14,7 @@ * Added `helper.CreateTemporaryContentPack` to support permanent use cases for mods using the deprecated `helper.CreateTransitionalContentPack`. * Reloading a map asset will now update affected locations. * Reloading the `Data\NPCDispositions` asset will now update affected NPCs. + * Disabled `TRACE` messages related to paranoid mode when it's disabled. * Fixed world events (like `ObjectListChanged`) not working in the mines. * Fixed some map tilesheets not editable if not playing in English. * Fixed newlines in most manifest fields not being ignored. diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index fdbfdd8d..7292cf3f 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -20,6 +20,9 @@ namespace StardewModdingAPI.Framework.ModLoading /// Encapsulates monitoring and logging. private readonly IMonitor Monitor; + /// Whether to detect paranoid mode issues. + private readonly bool ParanoidMode; + /// Metadata for mapping assemblies to the current platform. private readonly PlatformAssemblyMap AssemblyMap; @@ -39,9 +42,11 @@ namespace StardewModdingAPI.Framework.ModLoading /// Construct an instance. /// The current game platform. /// Encapsulates monitoring and logging. - public AssemblyLoader(Platform targetPlatform, IMonitor monitor) + /// Whether to detect paranoid mode issues. + public AssemblyLoader(Platform targetPlatform, IMonitor monitor, bool paranoidMode) { this.Monitor = monitor; + this.ParanoidMode = paranoidMode; this.AssemblyMap = this.TrackForDisposal(Constants.GetAssemblyMap(targetPlatform)); this.AssemblyDefinitionResolver = this.TrackForDisposal(new AssemblyDefinitionResolver()); this.AssemblyDefinitionResolver.AddSearchDirectory(Constants.ExecutionPath); @@ -275,7 +280,7 @@ namespace StardewModdingAPI.Framework.ModLoading // find (and optionally rewrite) incompatible instructions bool anyRewritten = false; - IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers().ToArray(); + IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers(this.ParanoidMode).ToArray(); foreach (MethodDefinition method in this.GetMethods(module)) { // check method definition diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 53704bcf..800b9c09 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -726,7 +726,7 @@ namespace StardewModdingAPI.Framework // load mods IDictionary> skippedMods = new Dictionary>(); - using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor)) + using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.ParanoidWarnings)) { // init HashSet suppressUpdateChecks = new HashSet(this.Settings.SuppressUpdateChecks, StringComparer.InvariantCultureIgnoreCase); diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index c4ddf807..7c840b2f 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -24,54 +24,55 @@ namespace StardewModdingAPI.Metadata ** Public methods *********/ /// Get rewriters which detect or fix incompatible CIL instructions in mod assemblies. - public IEnumerable GetHandlers() + /// Whether to detect paranoid mode issues. + public IEnumerable GetHandlers(bool paranoidMode) { - return new IInstructionHandler[] - { - /**** - ** rewrite CIL to fix incompatible code - ****/ - // rewrite for crossplatform compatibility - new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchMethods), onlyIfPlatformChanged: true), + /**** + ** rewrite CIL to fix incompatible code + ****/ + // rewrite for crossplatform compatibility + yield return new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchMethods), onlyIfPlatformChanged: true); - // rewrite for Stardew Valley 1.3 - new StaticFieldToConstantRewriter(typeof(Game1), "tileSize", Game1.tileSize), + // rewrite for Stardew Valley 1.3 + yield return new StaticFieldToConstantRewriter(typeof(Game1), "tileSize", Game1.tileSize); - /**** - ** detect mod issues - ****/ - // detect broken code - new ReferenceToMissingMemberFinder(this.ValidateReferencesToAssemblies), - new ReferenceToMemberWithUnexpectedTypeFinder(this.ValidateReferencesToAssemblies), + /**** + ** detect mod issues + ****/ + // detect broken code + yield return new ReferenceToMissingMemberFinder(this.ValidateReferencesToAssemblies); + yield return new ReferenceToMemberWithUnexpectedTypeFinder(this.ValidateReferencesToAssemblies); - /**** - ** detect code which may impact game stability - ****/ - new TypeFinder("Harmony.HarmonyInstance", InstructionHandleResult.DetectedGamePatch), - new TypeFinder("System.Runtime.CompilerServices.CallSite", InstructionHandleResult.DetectedDynamic), - new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.serializer), InstructionHandleResult.DetectedSaveSerialiser), - new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.farmerSerializer), InstructionHandleResult.DetectedSaveSerialiser), - new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.locationSerializer), InstructionHandleResult.DetectedSaveSerialiser), - new TypeFinder(typeof(ISpecialisedEvents).FullName, InstructionHandleResult.DetectedUnvalidatedUpdateTick), + /**** + ** detect code which may impact game stability + ****/ + yield return new TypeFinder("Harmony.HarmonyInstance", InstructionHandleResult.DetectedGamePatch); + yield return new TypeFinder("System.Runtime.CompilerServices.CallSite", InstructionHandleResult.DetectedDynamic); + yield return new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.serializer), InstructionHandleResult.DetectedSaveSerialiser); + yield return new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.farmerSerializer), InstructionHandleResult.DetectedSaveSerialiser); + yield return new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.locationSerializer), InstructionHandleResult.DetectedSaveSerialiser); + yield return new TypeFinder(typeof(ISpecialisedEvents).FullName, InstructionHandleResult.DetectedUnvalidatedUpdateTick); #if !SMAPI_3_0_STRICT - new EventFinder(typeof(SpecialisedEvents).FullName, nameof(SpecialisedEvents.UnvalidatedUpdateTick), InstructionHandleResult.DetectedUnvalidatedUpdateTick), + yield return new EventFinder(typeof(SpecialisedEvents).FullName, nameof(SpecialisedEvents.UnvalidatedUpdateTick), InstructionHandleResult.DetectedUnvalidatedUpdateTick); #endif - - /**** - ** detect paranoid issues - ****/ + + /**** + ** detect paranoid issues + ****/ + if (paranoidMode) + { // filesystem access - new TypeFinder(typeof(System.IO.File).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.FileStream).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.FileInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.Directory).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.DirectoryInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.DriveInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.FileSystemWatcher).FullName, InstructionHandleResult.DetectedFilesystemAccess), + yield return new TypeFinder(typeof(System.IO.File).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.FileStream).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.FileInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.Directory).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.DirectoryInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.DriveInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.FileSystemWatcher).FullName, InstructionHandleResult.DetectedFilesystemAccess); // shell access - new TypeFinder(typeof(System.Diagnostics.Process).FullName, InstructionHandleResult.DetectedShellAccess) - }; + yield return new TypeFinder(typeof(System.Diagnostics.Process).FullName, InstructionHandleResult.DetectedShellAccess); + } } } } -- cgit