diff options
Diffstat (limited to 'src/SMAPI/Metadata/InstructionMetadata.cs')
-rw-r--r-- | src/SMAPI/Metadata/InstructionMetadata.cs | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index ff8d54e3..7c840b2f 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -24,51 +24,55 @@ namespace StardewModdingAPI.Metadata ** Public methods *********/ /// <summary>Get rewriters which detect or fix incompatible CIL instructions in mod assemblies.</summary> - public IEnumerable<IInstructionHandler> GetHandlers() + /// <param name="paranoidMode">Whether to detect paranoid mode issues.</param> + public IEnumerable<IInstructionHandler> 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 + yield return new StaticFieldToConstantRewriter<int>(typeof(Game1), "tileSize", Game1.tileSize); - // rewrite for Stardew Valley 1.3 - new StaticFieldToConstantRewriter<int>(typeof(Game1), "tileSize", Game1.tileSize), + /**** + ** detect mod issues + ****/ + // detect broken code + yield return new ReferenceToMissingMemberFinder(this.ValidateReferencesToAssemblies); + yield return new ReferenceToMemberWithUnexpectedTypeFinder(this.ValidateReferencesToAssemblies); - /**** - ** detect mod issues - ****/ - // detect broken code - new ReferenceToMissingMemberFinder(this.ValidateReferencesToAssemblies), - new ReferenceToMemberWithUnexpectedTypeFinder(this.ValidateReferencesToAssemblies), + /**** + ** 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 + yield return new EventFinder(typeof(SpecialisedEvents).FullName, nameof(SpecialisedEvents.UnvalidatedUpdateTick), InstructionHandleResult.DetectedUnvalidatedUpdateTick); +#endif - /**** - ** 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 EventFinder(typeof(SpecialisedEvents).FullName, nameof(SpecialisedEvents.UnvalidatedUpdateTick), InstructionHandleResult.DetectedUnvalidatedUpdateTick), - - /**** - ** 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); + } } } } |